libspdm_get_scratch_buffer_secure_message_capacity:
   17|    309|uint32_t libspdm_get_scratch_buffer_secure_message_capacity(libspdm_context_t *spdm_context) {
   18|    309|    return spdm_context->local_context.capability.max_spdm_msg_size +
   19|    309|           spdm_context->local_context.capability.transport_header_size +
   20|    309|           spdm_context->local_context.capability.transport_tail_size;
   21|    309|}
libspdm_get_scratch_buffer_large_message_capacity:
   28|    309|uint32_t libspdm_get_scratch_buffer_large_message_capacity(libspdm_context_t *spdm_context) {
   29|    309|    return spdm_context->local_context.capability.max_spdm_msg_size;
   30|    309|}
libspdm_get_scratch_buffer_sender_receiver_capacity:
   43|    309|uint32_t libspdm_get_scratch_buffer_sender_receiver_capacity(libspdm_context_t *spdm_context) {
   44|    309|    return spdm_context->local_context.capability.max_spdm_msg_size +
   45|    309|           spdm_context->local_context.capability.transport_header_size +
   46|    309|           spdm_context->local_context.capability.transport_tail_size;
   47|    309|}
libspdm_get_scratch_buffer_large_sender_receiver_capacity:
   58|    309|{
   59|    309|    return spdm_context->local_context.capability.max_spdm_msg_size +
   60|    309|           spdm_context->local_context.capability.transport_header_size +
   61|    309|           spdm_context->local_context.capability.transport_tail_size;
   62|    309|}
libspdm_get_scratch_buffer_last_spdm_request_offset:
   66|    103|uint32_t libspdm_get_scratch_buffer_last_spdm_request_offset(libspdm_context_t *spdm_context) {
   67|    103|    return 0 +
   68|    103|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
   69|    103|           libspdm_get_scratch_buffer_secure_message_capacity(spdm_context) +
   70|    103|           libspdm_get_scratch_buffer_large_message_capacity(spdm_context) +
   71|    103|#endif
   72|    103|           libspdm_get_scratch_buffer_sender_receiver_capacity(spdm_context) +
   73|    103|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
   74|    103|           libspdm_get_scratch_buffer_large_sender_receiver_capacity(spdm_context) +
   75|    103|#endif
   76|    103|           0;
   77|    103|}
libspdm_get_scratch_buffer_last_spdm_request_capacity:
   79|    206|uint32_t libspdm_get_scratch_buffer_last_spdm_request_capacity(libspdm_context_t *spdm_context) {
   80|    206|    return spdm_context->local_context.capability.max_spdm_msg_size;
   81|    206|}
libspdm_get_scratch_buffer_cache_spdm_request_offset:
   85|    103|uint32_t libspdm_get_scratch_buffer_cache_spdm_request_offset(libspdm_context_t *spdm_context) {
   86|    103|    return 0 +
   87|    103|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
   88|    103|           libspdm_get_scratch_buffer_secure_message_capacity(spdm_context) +
   89|    103|           libspdm_get_scratch_buffer_large_message_capacity(spdm_context) +
   90|    103|#endif
   91|    103|           libspdm_get_scratch_buffer_sender_receiver_capacity(spdm_context) +
   92|    103|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
   93|    103|           libspdm_get_scratch_buffer_large_sender_receiver_capacity(spdm_context) +
   94|    103|#endif
   95|    103|           libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context) +
   96|    103|           0;
   97|    103|}
libspdm_get_scratch_buffer_cache_spdm_request_capacity:
   99|    103|uint32_t libspdm_get_scratch_buffer_cache_spdm_request_capacity(libspdm_context_t *spdm_context) {
  100|    103|    return spdm_context->local_context.capability.max_spdm_msg_size;
  101|    103|}
libspdm_get_scratch_buffer_capacity:
  105|    103|uint32_t libspdm_get_scratch_buffer_capacity(libspdm_context_t *spdm_context) {
  106|    103|    return 0 +
  107|    103|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
  108|    103|           libspdm_get_scratch_buffer_secure_message_capacity(spdm_context) +
  109|    103|           libspdm_get_scratch_buffer_large_message_capacity(spdm_context) +
  110|    103|#endif
  111|    103|           libspdm_get_scratch_buffer_sender_receiver_capacity(spdm_context) +
  112|    103|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
  113|    103|           libspdm_get_scratch_buffer_large_sender_receiver_capacity(spdm_context) +
  114|    103|#endif
  115|    103|           libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context) +
  116|    103|#if LIBSPDM_RESPOND_IF_READY_SUPPORT
  117|    103|           libspdm_get_scratch_buffer_cache_spdm_request_capacity(spdm_context) +
  118|    103|#endif
  119|    103|           0;
  120|    103|}
libspdm_reset_message_a:
 1260|      9|{
 1261|      9|    libspdm_reset_managed_buffer(&spdm_context->transcript.message_a);
 1262|      9|}
libspdm_reset_message_d:
 1270|      9|{
 1271|      9|    libspdm_reset_managed_buffer(&spdm_context->transcript.message_d);
 1272|      9|}
libspdm_reset_message_b:
 1280|      9|{
 1281|       |#if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
 1282|       |    libspdm_reset_managed_buffer(&spdm_context->transcript.message_b);
 1283|       |#else
 1284|      9|    if (spdm_context->transcript.digest_context_m1m2 != NULL) {
  ------------------
  |  Branch (1284:9): [True: 0, False: 9]
  ------------------
 1285|      0|        libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
 1286|      0|                           spdm_context->transcript.digest_context_m1m2);
 1287|      0|        spdm_context->transcript.digest_context_m1m2 = NULL;
 1288|      0|    }
 1289|      9|#endif
 1290|      9|}
libspdm_reset_message_c:
 1298|      9|{
 1299|       |#if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
 1300|       |    libspdm_reset_managed_buffer(&spdm_context->transcript.message_c);
 1301|       |#else
 1302|      9|    if (spdm_context->transcript.digest_context_m1m2 != NULL) {
  ------------------
  |  Branch (1302:9): [True: 0, False: 9]
  ------------------
 1303|      0|        libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
 1304|      0|                           spdm_context->transcript.digest_context_m1m2);
 1305|      0|        spdm_context->transcript.digest_context_m1m2 = NULL;
 1306|      0|    }
 1307|      9|#endif
 1308|      9|}
libspdm_reset_message_m:
 1355|      9|{
 1356|      9|    libspdm_session_info_t *spdm_session_info;
 1357|       |
 1358|      9|    spdm_session_info = session_info;
 1359|       |#if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
 1360|       |    if (spdm_session_info == NULL) {
 1361|       |        libspdm_reset_managed_buffer(&spdm_context->transcript.message_m);
 1362|       |    } else {
 1363|       |        libspdm_reset_managed_buffer(&spdm_session_info->session_transcript.message_m);
 1364|       |    }
 1365|       |#else
 1366|      9|    if (spdm_session_info == NULL) {
  ------------------
  |  Branch (1366:9): [True: 9, False: 0]
  ------------------
 1367|      9|        if (spdm_context->transcript.digest_context_l1l2 != NULL) {
  ------------------
  |  Branch (1367:13): [True: 0, False: 9]
  ------------------
 1368|      0|            libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
 1369|      0|                               spdm_context->transcript.digest_context_l1l2);
 1370|      0|            spdm_context->transcript.digest_context_l1l2 = NULL;
 1371|      0|        }
 1372|      9|    } else {
 1373|      0|        if (spdm_session_info->session_transcript.digest_context_l1l2 != NULL) {
  ------------------
  |  Branch (1373:13): [True: 0, False: 0]
  ------------------
 1374|      0|            libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
 1375|      0|                               spdm_session_info->session_transcript.digest_context_l1l2);
 1376|      0|            spdm_session_info->session_transcript.digest_context_l1l2 = NULL;
 1377|      0|        }
 1378|      0|    }
 1379|      9|#endif
 1380|      9|}
libspdm_reset_message_buffer_via_request_code:
 1533|      9|{
 1534|      9|    libspdm_context_t *spdm_context;
 1535|       |
 1536|      9|    spdm_context = context;
 1537|       |    /**
 1538|       |     * Any request other than SPDM_GET_MEASUREMENTS resets L1/L2
 1539|       |     */
 1540|      9|    if (request_code != SPDM_GET_MEASUREMENTS) {
  ------------------
  |  |   70|      9|#define SPDM_GET_MEASUREMENTS 0xE0
  ------------------
  |  Branch (1540:9): [True: 9, False: 0]
  ------------------
 1541|      9|        libspdm_reset_message_m(spdm_context, session_info);
 1542|      9|    }
 1543|       |    /**
 1544|       |     * If the Requester issued GET_MEASUREMENTS or KEY_EXCHANGE or FINISH or PSK_EXCHANGE
 1545|       |     * or PSK_FINISH or KEY_UPDATE or HEARTBEAT or GET_ENCAPSULATED_REQUEST or DELIVER_ENCAPSULATED_RESPONSE
 1546|       |     * or END_SESSION request(s) or SPDM_GET_MEASUREMENT_EXTENSION_LOG and skipped CHALLENGE completion, M1 and M2 are reset to null.
 1547|       |     */
 1548|      9|    switch (request_code)
 1549|      9|    {
 1550|      0|    case SPDM_KEY_EXCHANGE:
  ------------------
  |  |   77|      0|#define SPDM_KEY_EXCHANGE 0xE4
  ------------------
  |  Branch (1550:5): [True: 0, False: 9]
  ------------------
 1551|      0|    case SPDM_GET_MEASUREMENTS:
  ------------------
  |  |   70|      0|#define SPDM_GET_MEASUREMENTS 0xE0
  ------------------
  |  Branch (1551:5): [True: 0, False: 9]
  ------------------
 1552|      0|    case SPDM_FINISH:
  ------------------
  |  |   78|      0|#define SPDM_FINISH 0xE5
  ------------------
  |  Branch (1552:5): [True: 0, False: 9]
  ------------------
 1553|      0|    case SPDM_PSK_EXCHANGE:
  ------------------
  |  |   79|      0|#define SPDM_PSK_EXCHANGE 0xE6
  ------------------
  |  Branch (1553:5): [True: 0, False: 9]
  ------------------
 1554|      0|    case SPDM_PSK_FINISH:
  ------------------
  |  |   80|      0|#define SPDM_PSK_FINISH 0xE7
  ------------------
  |  Branch (1554:5): [True: 0, False: 9]
  ------------------
 1555|      0|    case SPDM_KEY_UPDATE:
  ------------------
  |  |   82|      0|#define SPDM_KEY_UPDATE 0xE9
  ------------------
  |  Branch (1555:5): [True: 0, False: 9]
  ------------------
 1556|      0|    case SPDM_HEARTBEAT:
  ------------------
  |  |   81|      0|#define SPDM_HEARTBEAT 0xE8
  ------------------
  |  Branch (1556:5): [True: 0, False: 9]
  ------------------
 1557|      0|    case SPDM_GET_ENCAPSULATED_REQUEST:
  ------------------
  |  |   83|      0|#define SPDM_GET_ENCAPSULATED_REQUEST 0xEA
  ------------------
  |  Branch (1557:5): [True: 0, False: 9]
  ------------------
 1558|      0|    case SPDM_END_SESSION:
  ------------------
  |  |   85|      0|#define SPDM_END_SESSION 0xEC
  ------------------
  |  Branch (1558:5): [True: 0, False: 9]
  ------------------
 1559|      0|    case SPDM_GET_MEASUREMENT_EXTENSION_LOG:
  ------------------
  |  |   98|      0|#define SPDM_GET_MEASUREMENT_EXTENSION_LOG 0xEF
  ------------------
  |  Branch (1559:5): [True: 0, False: 9]
  ------------------
 1560|      0|        if (spdm_context->connection_info.connection_state <
  ------------------
  |  Branch (1560:13): [True: 0, False: 0]
  ------------------
 1561|      0|            LIBSPDM_CONNECTION_STATE_AUTHENTICATED) {
 1562|      0|            libspdm_reset_message_b(spdm_context);
 1563|      0|            libspdm_reset_message_c(spdm_context);
 1564|      0|            libspdm_reset_message_mut_b(spdm_context);
 1565|      0|            libspdm_reset_message_mut_c(spdm_context);
 1566|      0|        }
 1567|      0|        break;
 1568|      0|    case SPDM_DELIVER_ENCAPSULATED_RESPONSE:
  ------------------
  |  |   84|      0|#define SPDM_DELIVER_ENCAPSULATED_RESPONSE 0xEB
  ------------------
  |  Branch (1568:5): [True: 0, False: 9]
  ------------------
 1569|      0|        if (spdm_context->connection_info.connection_state <
  ------------------
  |  Branch (1569:13): [True: 0, False: 0]
  ------------------
 1570|      0|            LIBSPDM_CONNECTION_STATE_AUTHENTICATED) {
 1571|      0|            libspdm_reset_message_b(spdm_context);
 1572|      0|            libspdm_reset_message_c(spdm_context);
 1573|      0|        }
 1574|      0|        break;
 1575|      0|    case SPDM_GET_DIGESTS:
  ------------------
  |  |   66|      0|#define SPDM_GET_DIGESTS 0x81
  ------------------
  |  Branch (1575:5): [True: 0, False: 9]
  ------------------
 1576|      0|        libspdm_reset_message_b(spdm_context);
 1577|      0|        break;
 1578|      0|    case SPDM_GET_ENDPOINT_INFO:
  ------------------
  |  |   94|      0|#define SPDM_GET_ENDPOINT_INFO 0x87
  ------------------
  |  Branch (1578:5): [True: 0, False: 9]
  ------------------
 1579|      0|        libspdm_reset_message_e(spdm_context, session_info);
 1580|      0|        libspdm_reset_message_encap_e(spdm_context, session_info);
 1581|      0|        break;
 1582|      9|    default:
  ------------------
  |  Branch (1582:5): [True: 9, False: 0]
  ------------------
 1583|      9|        break;
 1584|      9|    }
 1585|      9|}
libspdm_append_message_a:
 1598|     18|{
 1599|     18|    return libspdm_append_managed_buffer(&spdm_context->transcript.message_a,
 1600|     18|                                         message, message_size);
 1601|     18|}
libspdm_register_device_io_func:
 2720|    103|{
 2721|    103|    libspdm_context_t *context;
 2722|       |
 2723|    103|    context = spdm_context;
 2724|    103|    context->send_message = send_message;
 2725|    103|    context->receive_message = receive_message;
 2726|    103|}
libspdm_register_device_buffer_func:
 2779|    103|{
 2780|    103|    libspdm_context_t *context;
 2781|       |
 2782|    103|    context = spdm_context;
 2783|    103|    context->sender_buffer_size = sender_buffer_size;
 2784|    103|    context->receiver_buffer_size = receiver_buffer_size;
 2785|    103|    context->acquire_sender_buffer = acquire_sender_buffer;
 2786|    103|    context->release_sender_buffer = release_sender_buffer;
 2787|    103|    context->acquire_receiver_buffer = acquire_receiver_buffer;
 2788|    103|    context->release_receiver_buffer = release_receiver_buffer;
 2789|       |
 2790|    103|    LIBSPDM_ASSERT (sender_buffer_size >=
 2791|    103|                    context->local_context.capability.transport_header_size +
 2792|    103|                    context->local_context.capability.transport_tail_size);
 2793|    103|    sender_buffer_size -= (context->local_context.capability.transport_header_size +
 2794|    103|                           context->local_context.capability.transport_tail_size);
 2795|    103|    LIBSPDM_ASSERT (sender_buffer_size >= SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12);
 2796|    103|    context->local_context.capability.sender_data_transfer_size = sender_buffer_size;
 2797|       |
 2798|    103|    LIBSPDM_ASSERT(receiver_buffer_size >=
 2799|    103|                   context->local_context.capability.transport_header_size +
 2800|    103|                   context->local_context.capability.transport_tail_size);
 2801|    103|    receiver_buffer_size -= (context->local_context.capability.transport_header_size +
 2802|    103|                             context->local_context.capability.transport_tail_size);
 2803|    103|    LIBSPDM_ASSERT (receiver_buffer_size >= SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12);
 2804|    103|    context->local_context.capability.data_transfer_size = receiver_buffer_size;
 2805|    103|}
libspdm_register_transport_layer_func:
 2823|    103|{
 2824|    103|    libspdm_context_t *context;
 2825|       |
 2826|    103|    context = spdm_context;
 2827|       |
 2828|       |    /* fix the data_transfer_size if it is set before */
 2829|    103|    if ((context->local_context.capability.data_transfer_size != 0) &&
  ------------------
  |  Branch (2829:9): [True: 0, False: 103]
  ------------------
 2830|    103|        (context->local_context.capability.data_transfer_size ==
  ------------------
  |  Branch (2830:9): [True: 0, False: 0]
  ------------------
 2831|      0|         context->receiver_buffer_size)) {
 2832|      0|        context->local_context.capability.data_transfer_size =
 2833|      0|            (uint32_t)(context->receiver_buffer_size -
 2834|      0|                       (transport_header_size + transport_tail_size));
 2835|      0|    }
 2836|    103|    if ((context->local_context.capability.sender_data_transfer_size != 0) &&
  ------------------
  |  Branch (2836:9): [True: 0, False: 103]
  ------------------
 2837|    103|        (context->local_context.capability.sender_data_transfer_size ==
  ------------------
  |  Branch (2837:9): [True: 0, False: 0]
  ------------------
 2838|      0|         context->sender_buffer_size)) {
 2839|      0|        context->local_context.capability.sender_data_transfer_size =
 2840|      0|            (uint32_t)(context->sender_buffer_size -
 2841|      0|                       (transport_header_size + transport_tail_size));
 2842|      0|    }
 2843|       |
 2844|    103|    context->local_context.capability.max_spdm_msg_size = max_spdm_msg_size;
 2845|    103|    context->local_context.capability.transport_header_size = transport_header_size;
 2846|    103|    context->local_context.capability.transport_tail_size = transport_tail_size;
 2847|    103|    context->transport_encode_message = transport_encode_message;
 2848|    103|    context->transport_decode_message = transport_decode_message;
 2849|    103|}
libspdm_get_sizeof_required_scratch_buffer:
 2886|    103|{
 2887|    103|    libspdm_context_t *context;
 2888|    103|    size_t scratch_buffer_size;
 2889|       |
 2890|    103|    context = spdm_context;
 2891|    103|    LIBSPDM_ASSERT (context->local_context.capability.max_spdm_msg_size != 0);
 2892|       |
 2893|    103|    scratch_buffer_size = libspdm_get_scratch_buffer_capacity(context);
 2894|    103|    return scratch_buffer_size;
 2895|    103|}
libspdm_set_scratch_buffer:
 2911|    103|{
 2912|    103|    libspdm_context_t *context;
 2913|       |
 2914|    103|    context = spdm_context;
 2915|    103|    LIBSPDM_ASSERT (context->local_context.capability.max_spdm_msg_size != 0);
 2916|    103|    LIBSPDM_ASSERT (scratch_buffer_size >= libspdm_get_scratch_buffer_capacity(spdm_context));
 2917|    103|    context->scratch_buffer = scratch_buffer;
 2918|    103|    context->scratch_buffer_size = scratch_buffer_size;
 2919|    103|    context->last_spdm_request = (uint8_t *)scratch_buffer +
 2920|    103|                                 libspdm_get_scratch_buffer_last_spdm_request_offset(spdm_context);
 2921|    103|#if LIBSPDM_RESPOND_IF_READY_SUPPORT
 2922|    103|    context->cache_spdm_request = (uint8_t *)scratch_buffer +
 2923|    103|                                  libspdm_get_scratch_buffer_cache_spdm_request_offset(spdm_context);
 2924|    103|#endif
 2925|    103|}
libspdm_init_context_with_secured_context:
 3240|    103|{
 3241|    103|    libspdm_context_t *context;
 3242|    103|    size_t index;
 3243|       |
 3244|    103|    LIBSPDM_ASSERT(spdm_context != NULL);
 3245|    103|    LIBSPDM_ASSERT(secured_contexts != NULL);
 3246|    103|    LIBSPDM_ASSERT(num_secured_contexts == LIBSPDM_MAX_SESSION_COUNT);
 3247|       |
 3248|    103|    context = spdm_context;
 3249|    103|    libspdm_zero_mem(context, sizeof(libspdm_context_t));
 3250|    103|    context->version = LIBSPDM_CONTEXT_STRUCT_VERSION;
  ------------------
  |  |  527|    103|#define LIBSPDM_CONTEXT_STRUCT_VERSION 0x3
  ------------------
 3251|    103|    context->transcript.message_a.max_buffer_size =
 3252|    103|        sizeof(context->transcript.message_a.buffer);
 3253|    103|    context->transcript.message_d.max_buffer_size =
 3254|    103|        sizeof(context->transcript.message_d.buffer);
 3255|       |#if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
 3256|       |    context->transcript.message_b.max_buffer_size =
 3257|       |        sizeof(context->transcript.message_b.buffer);
 3258|       |    context->transcript.message_c.max_buffer_size =
 3259|       |        sizeof(context->transcript.message_c.buffer);
 3260|       |    context->transcript.message_mut_b.max_buffer_size =
 3261|       |        sizeof(context->transcript.message_mut_b.buffer);
 3262|       |    context->transcript.message_mut_c.max_buffer_size =
 3263|       |        sizeof(context->transcript.message_mut_c.buffer);
 3264|       |    context->transcript.message_m.max_buffer_size =
 3265|       |        sizeof(context->transcript.message_m.buffer);
 3266|       |    context->transcript.message_e.max_buffer_size =
 3267|       |        sizeof(context->transcript.message_e.buffer);
 3268|       |    context->transcript.message_encap_e.max_buffer_size =
 3269|       |        sizeof(context->transcript.message_encap_e.buffer);
 3270|       |#endif
 3271|    103|    context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
 3272|    103|    context->local_context.version.spdm_version_count = SPDM_MAX_VERSION_COUNT;
  ------------------
  |  |   17|    103|#define SPDM_MAX_VERSION_COUNT 4
  ------------------
 3273|    103|    context->local_context.version.spdm_version[0] = SPDM_MESSAGE_VERSION_10 <<
  ------------------
  |  |  110|    103|#define SPDM_MESSAGE_VERSION_10 0x10
  ------------------
 3274|    103|                                                     SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    103|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3275|    103|    context->local_context.version.spdm_version[1] = SPDM_MESSAGE_VERSION_11 <<
  ------------------
  |  |  111|    103|#define SPDM_MESSAGE_VERSION_11 0x11
  ------------------
 3276|    103|                                                     SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    103|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3277|    103|    context->local_context.version.spdm_version[2] = SPDM_MESSAGE_VERSION_12 <<
  ------------------
  |  |  112|    103|#define SPDM_MESSAGE_VERSION_12 0x12
  ------------------
 3278|    103|                                                     SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    103|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3279|    103|    context->local_context.version.spdm_version[3] = SPDM_MESSAGE_VERSION_13 <<
  ------------------
  |  |  113|    103|#define SPDM_MESSAGE_VERSION_13 0x13
  ------------------
 3280|    103|                                                     SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    103|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3281|    103|    context->local_context.secured_message_version.spdm_version_count =
 3282|    103|        SECURED_SPDM_MAX_VERSION_COUNT;
  ------------------
  |  |   55|    103|#define SECURED_SPDM_MAX_VERSION_COUNT 3
  ------------------
 3283|    103|    context->local_context.secured_message_version.spdm_version[0] =
 3284|    103|        SECURED_SPDM_VERSION_10 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |   57|    103|#define SECURED_SPDM_VERSION_10 0x10
  ------------------
                      SECURED_SPDM_VERSION_10 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    103|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3285|    103|    context->local_context.secured_message_version.spdm_version[1] =
 3286|    103|        SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |   58|    103|#define SECURED_SPDM_VERSION_11 0x11
  ------------------
                      SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    103|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3287|    103|    context->local_context.secured_message_version.spdm_version[2] =
 3288|    103|        SECURED_SPDM_VERSION_12 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |   59|    103|#define SECURED_SPDM_VERSION_12 0x12
  ------------------
                      SECURED_SPDM_VERSION_12 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    103|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3289|    103|    context->local_context.capability.st1 = SPDM_ST1_VALUE_US;
  ------------------
  |  | 1514|    103|#define SPDM_ST1_VALUE_US 100000
  ------------------
 3290|       |
 3291|    103|    context->mut_auth_cert_chain_buffer_size = 0;
 3292|       |
 3293|    103|    context->max_spdm_session_sequence_number = LIBSPDM_MAX_SPDM_SESSION_SEQUENCE_NUMBER;
  ------------------
  |  |   39|    103|#define LIBSPDM_MAX_SPDM_SESSION_SEQUENCE_NUMBER 0xFFFFFFFFFFFFFFFFull
  ------------------
 3294|       |
 3295|    103|    context->latest_session_id = INVALID_SESSION_ID;
  ------------------
  |  |   28|    103|#define INVALID_SESSION_ID 0
  ------------------
 3296|    103|    context->last_spdm_request_session_id = INVALID_SESSION_ID;
  ------------------
  |  |   28|    103|#define INVALID_SESSION_ID 0
  ------------------
 3297|    103|    context->last_spdm_request_session_id_valid = false;
 3298|    103|    context->last_spdm_request_size = 0;
 3299|       |
 3300|       |    /* To be updated in libspdm_register_device_buffer_func */
 3301|    103|    context->local_context.capability.data_transfer_size = 0;
 3302|    103|    context->local_context.capability.sender_data_transfer_size = 0;
 3303|    103|    context->local_context.capability.max_spdm_msg_size = 0;
 3304|       |
 3305|    515|    for (index = 0; index < num_secured_contexts; index++) {
  ------------------
  |  Branch (3305:21): [True: 412, False: 103]
  ------------------
 3306|    412|        if (secured_contexts[index] == NULL) {
  ------------------
  |  Branch (3306:13): [True: 0, False: 412]
  ------------------
 3307|      0|            return LIBSPDM_STATUS_INVALID_PARAMETER;
  ------------------
  |  |   73|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0001)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
 3308|      0|        }
 3309|       |
 3310|    412|        context->session_info[index].secured_message_context = secured_contexts[index];
 3311|    412|        libspdm_secured_message_init_context(
 3312|    412|            context->session_info[index].secured_message_context);
 3313|    412|    }
 3314|       |
 3315|    103|    return LIBSPDM_STATUS_SUCCESS;
  ------------------
  |  |   59|    103|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_SUCCESS, LIBSPDM_SOURCE_SUCCESS, 0x0000)
  |  |  ------------------
  |  |  |  |   55|    103|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
 3316|    103|}
libspdm_init_context:
 3331|    103|{
 3332|    103|    libspdm_context_t *context;
 3333|    103|    void *secured_context;
 3334|    103|    void *secured_contexts[LIBSPDM_MAX_SESSION_COUNT];
 3335|    103|    size_t secured_context_size;
 3336|    103|    size_t index;
 3337|       |
 3338|    103|    LIBSPDM_ASSERT(spdm_context != NULL);
 3339|       |
 3340|       |    /* libspdm_get_context_size() allocates space for all secured message
 3341|       |     * contexts. They are appended to the general SPDM context. */
 3342|    103|    context = spdm_context;
 3343|    103|    secured_context = (void *)((size_t)(context + 1));
 3344|    103|    secured_context_size = libspdm_secured_message_get_context_size();
 3345|       |
 3346|    515|    for (index = 0; index < LIBSPDM_MAX_SESSION_COUNT; index++)
  ------------------
  |  |  198|    515|#define LIBSPDM_MAX_SESSION_COUNT 4
  ------------------
  |  Branch (3346:21): [True: 412, False: 103]
  ------------------
 3347|    412|    {
 3348|    412|        secured_contexts[index] = (uint8_t *)secured_context + secured_context_size * index;
 3349|    412|    }
 3350|       |
 3351|    103|    return libspdm_init_context_with_secured_context(spdm_context,
 3352|    103|                                                     secured_contexts,
 3353|    103|                                                     LIBSPDM_MAX_SESSION_COUNT);
  ------------------
  |  |  198|    103|#define LIBSPDM_MAX_SESSION_COUNT 4
  ------------------
 3354|    103|}
libspdm_reset_context:
 3357|      9|{
 3358|      9|    libspdm_context_t *context;
 3359|      9|    size_t index;
 3360|       |
 3361|      9|    context = spdm_context;
 3362|       |
 3363|       |    /*Clear all info about last connection*/
 3364|       |
 3365|       |    /*need clear session info to free context before algo is zeroed.*/
 3366|     45|    for (index = 0; index < LIBSPDM_MAX_SESSION_COUNT; index++)
  ------------------
  |  |  198|     45|#define LIBSPDM_MAX_SESSION_COUNT 4
  ------------------
  |  Branch (3366:21): [True: 36, False: 9]
  ------------------
 3367|     36|    {
 3368|     36|        libspdm_session_info_init(context,
 3369|     36|                                  &context->session_info[index],
 3370|     36|                                  INVALID_SESSION_ID,
  ------------------
  |  |   28|     36|#define INVALID_SESSION_ID 0
  ------------------
 3371|     36|                                  false);
 3372|     36|    }
 3373|       |
 3374|      9|    context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NOT_STARTED;
 3375|      9|    libspdm_zero_mem(&context->connection_info.version, sizeof(spdm_version_number_t));
 3376|      9|    libspdm_zero_mem(&context->connection_info.capability,
 3377|      9|                     sizeof(libspdm_device_capability_t));
 3378|      9|    libspdm_zero_mem(&context->connection_info.algorithm, sizeof(libspdm_device_algorithm_t));
 3379|      9|    libspdm_zero_mem(&context->last_spdm_error, sizeof(libspdm_error_struct_t));
 3380|      9|    libspdm_zero_mem(&context->encap_context, sizeof(libspdm_encap_context_t));
 3381|      9|    context->connection_info.local_used_cert_chain_buffer_size = 0;
 3382|      9|    context->connection_info.local_used_cert_chain_buffer = NULL;
 3383|      9|    context->connection_info.multi_key_conn_req = false;
 3384|      9|    context->connection_info.multi_key_conn_rsp = false;
 3385|      9|#if LIBSPDM_RESPOND_IF_READY_SUPPORT
 3386|      9|    context->cache_spdm_request_size = 0;
 3387|      9|#endif
 3388|      9|    context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
 3389|      9|    context->current_token = 0;
 3390|      9|    context->latest_session_id = INVALID_SESSION_ID;
  ------------------
  |  |   28|      9|#define INVALID_SESSION_ID 0
  ------------------
 3391|      9|    context->last_spdm_request_session_id = INVALID_SESSION_ID;
  ------------------
  |  |   28|      9|#define INVALID_SESSION_ID 0
  ------------------
 3392|      9|    context->last_spdm_request_session_id_valid = false;
 3393|      9|    context->last_spdm_request_size = 0;
 3394|      9|    context->mut_auth_cert_chain_buffer_size = 0;
 3395|      9|    context->current_dhe_session_count = 0;
 3396|      9|    context->current_psk_session_count = 0;
 3397|      9|}
libspdm_get_context_size:
 3467|    103|{
 3468|    103|    size_t size;
 3469|       |
 3470|    103|    size = sizeof(libspdm_context_t) +
 3471|    103|           libspdm_secured_message_get_context_size() * LIBSPDM_MAX_SESSION_COUNT;
  ------------------
  |  |  198|    103|#define LIBSPDM_MAX_SESSION_COUNT 4
  ------------------
 3472|    103|    LIBSPDM_ASSERT (size == LIBSPDM_CONTEXT_SIZE_ALL);
 3473|    103|    return size;
 3474|    103|}

libspdm_session_info_init:
   18|     36|{
   19|     36|    libspdm_session_type_t session_type;
   20|     36|    uint32_t capabilities_flag;
   21|       |
   22|     36|    if (session_id != INVALID_SESSION_ID) {
  ------------------
  |  |   28|     36|#define INVALID_SESSION_ID 0
  ------------------
  |  Branch (22:9): [True: 0, False: 36]
  ------------------
   23|      0|        if (use_psk) {
  ------------------
  |  Branch (23:13): [True: 0, False: 0]
  ------------------
   24|      0|            LIBSPDM_ASSERT((spdm_context->max_psk_session_count == 0) ||
   25|      0|                           (spdm_context->current_psk_session_count <
   26|      0|                            spdm_context->max_psk_session_count));
   27|      0|            spdm_context->current_psk_session_count++;
   28|      0|        } else {
   29|      0|            LIBSPDM_ASSERT((spdm_context->max_dhe_session_count == 0) ||
   30|      0|                           (spdm_context->current_dhe_session_count <
   31|      0|                            spdm_context->max_dhe_session_count));
   32|      0|            spdm_context->current_dhe_session_count++;
   33|      0|        }
   34|     36|    } else {
   35|     36|        if (use_psk) {
  ------------------
  |  Branch (35:13): [True: 0, False: 36]
  ------------------
   36|      0|            if (spdm_context->current_psk_session_count > 0) {
  ------------------
  |  Branch (36:17): [True: 0, False: 0]
  ------------------
   37|      0|                spdm_context->current_psk_session_count--;
   38|      0|            }
   39|     36|        } else {
   40|     36|            if (spdm_context->current_dhe_session_count > 0) {
  ------------------
  |  Branch (40:17): [True: 0, False: 36]
  ------------------
   41|      0|                spdm_context->current_dhe_session_count--;
   42|      0|            }
   43|     36|        }
   44|     36|    }
   45|       |
   46|     36|    capabilities_flag = spdm_context->connection_info.capability.flags &
   47|     36|                        spdm_context->local_context.capability.flags;
   48|     36|    switch (capabilities_flag &
   49|     36|            (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP |
  ------------------
  |  |  187|     36|#define SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP 0x00000040
  ------------------
   50|     36|             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP)) {
  ------------------
  |  |  188|     36|#define SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP 0x00000080
  ------------------
   51|     36|    case 0:
  ------------------
  |  Branch (51:5): [True: 36, False: 0]
  ------------------
   52|     36|        session_type = LIBSPDM_SESSION_TYPE_NONE;
   53|     36|        break;
   54|      0|    case (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP |
  ------------------
  |  |  187|      0|#define SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP 0x00000040
  ------------------
  |  Branch (54:5): [True: 0, False: 36]
  ------------------
   55|      0|          SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP):
  ------------------
  |  |  188|      0|#define SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP 0x00000080
  ------------------
   56|      0|        session_type = LIBSPDM_SESSION_TYPE_ENC_MAC;
   57|      0|        break;
   58|      0|    case SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP:
  ------------------
  |  |  188|      0|#define SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP 0x00000080
  ------------------
  |  Branch (58:5): [True: 0, False: 36]
  ------------------
   59|      0|        session_type = LIBSPDM_SESSION_TYPE_MAC_ONLY;
   60|      0|        break;
   61|      0|    default:
  ------------------
  |  Branch (61:5): [True: 0, False: 36]
  ------------------
   62|      0|        LIBSPDM_ASSERT(false);
   63|      0|        session_type = LIBSPDM_SESSION_TYPE_MAX;
   64|      0|        break;
   65|     36|    }
   66|       |
   67|     36|#if !(LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT)
   68|     36|    if (session_info->session_transcript.digest_context_th != NULL) {
  ------------------
  |  Branch (68:9): [True: 0, False: 36]
  ------------------
   69|      0|        libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
   70|      0|                           session_info->session_transcript.digest_context_th);
   71|      0|        session_info->session_transcript.digest_context_th = NULL;
   72|      0|    }
   73|     36|    if (session_info->session_transcript.digest_context_th_backup != NULL) {
  ------------------
  |  Branch (73:9): [True: 0, False: 36]
  ------------------
   74|      0|        libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
   75|      0|                           session_info->session_transcript.digest_context_th_backup);
   76|      0|        session_info->session_transcript.digest_context_th_backup = NULL;
   77|      0|    }
   78|     36|#endif
   79|       |
   80|     36|    libspdm_zero_mem (&(session_info->last_key_update_request), sizeof(spdm_key_update_request_t));
   81|     36|    libspdm_zero_mem(session_info, offsetof(libspdm_session_info_t, secured_message_context));
   82|     36|    libspdm_secured_message_init_context(session_info->secured_message_context);
   83|     36|    session_info->session_id = session_id;
   84|     36|    session_info->use_psk = use_psk;
   85|     36|    libspdm_secured_message_set_use_psk(session_info->secured_message_context, use_psk);
   86|     36|    libspdm_secured_message_set_session_type(session_info->secured_message_context, session_type);
   87|       |
   88|       |    /* DSP0277 1.2 explicitly specifies a little-endian sequence number. 1.0 and 1.1 leave it up to
   89|       |     * the Integrator to specify. */
   90|     36|    if ((spdm_context->connection_info.secured_message_version >> SPDM_VERSION_NUMBER_SHIFT_BIT) >=
  ------------------
  |  |  140|     36|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
  |  Branch (90:9): [True: 0, False: 36]
  ------------------
   91|     36|        SECURED_SPDM_VERSION_12) {
  ------------------
  |  |   59|     36|#define SECURED_SPDM_VERSION_12 0x12
  ------------------
   92|      0|        libspdm_secured_message_set_sequence_number_endian(
   93|      0|            session_info->secured_message_context,
   94|      0|            LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_LITTLE_DEC_LITTLE);
  ------------------
  |  |  251|      0|#define LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_LITTLE_DEC_LITTLE 0
  ------------------
   95|     36|    } else {
   96|     36|        libspdm_secured_message_set_sequence_number_endian(session_info->secured_message_context,
   97|     36|                                                           spdm_context->sequence_number_endian);
   98|     36|    }
   99|       |
  100|     36|    libspdm_secured_message_set_max_spdm_session_sequence_number(
  101|     36|        session_info->secured_message_context, spdm_context->max_spdm_session_sequence_number);
  102|     36|    libspdm_secured_message_set_algorithms(
  103|     36|        session_info->secured_message_context,
  104|     36|        spdm_context->connection_info.version,
  105|     36|        spdm_context->connection_info.secured_message_version,
  106|     36|        spdm_context->connection_info.algorithm.base_hash_algo,
  107|     36|        spdm_context->connection_info.algorithm.dhe_named_group,
  108|     36|        spdm_context->connection_info.algorithm.aead_cipher_suite,
  109|     36|        spdm_context->connection_info.algorithm.key_schedule);
  110|     36|    session_info->session_transcript.message_encap_d.max_buffer_size =
  111|     36|        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|       |    session_info->session_transcript.message_e.max_buffer_size =
  120|       |        sizeof(session_info->session_transcript.message_e.buffer);
  121|       |    session_info->session_transcript.message_encap_e.max_buffer_size =
  122|       |        sizeof(session_info->session_transcript.message_encap_e.buffer);
  123|       |#endif
  124|     36|}

libspdm_append_managed_buffer:
  251|     18|{
  252|     18|    libspdm_managed_buffer_t *managed_buffer;
  253|       |
  254|     18|    LIBSPDM_ASSERT(buffer != NULL);
  255|       |
  256|     18|    if (buffer_size == 0) {
  ------------------
  |  Branch (256:9): [True: 0, False: 18]
  ------------------
  257|      0|        return LIBSPDM_STATUS_SUCCESS;
  ------------------
  |  |   59|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_SUCCESS, LIBSPDM_SOURCE_SUCCESS, 0x0000)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  258|      0|    }
  259|       |
  260|     18|    managed_buffer = m_buffer;
  261|       |
  262|     18|    LIBSPDM_ASSERT(buffer_size != 0);
  263|     18|    LIBSPDM_ASSERT(managed_buffer->max_buffer_size >= managed_buffer->buffer_size);
  264|       |
  265|     18|    if (buffer_size > managed_buffer->max_buffer_size - managed_buffer->buffer_size) {
  ------------------
  |  Branch (265:9): [True: 0, False: 18]
  ------------------
  266|       |        /* Do not LIBSPDM_ASSERT here, because command processor will append message from external.*/
  267|      0|        LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR,
  268|      0|                       "libspdm_append_managed_buffer 0x%x fail, rest 0x%x only\n",
  269|      0|                       (uint32_t)buffer_size,
  270|      0|                       (uint32_t)(managed_buffer->max_buffer_size - managed_buffer->buffer_size)));
  271|      0|        return LIBSPDM_STATUS_BUFFER_FULL;
  ------------------
  |  |  118|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x000c)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  272|      0|    }
  273|     18|    LIBSPDM_ASSERT(buffer_size <= managed_buffer->max_buffer_size - managed_buffer->buffer_size);
  274|       |
  275|     18|    libspdm_copy_mem((uint8_t *)(managed_buffer + 1) + managed_buffer->buffer_size,
  276|     18|                     buffer_size, buffer, buffer_size);
  277|     18|    managed_buffer->buffer_size += buffer_size;
  278|       |
  279|     18|    return LIBSPDM_STATUS_SUCCESS;
  ------------------
  |  |   59|     18|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_SUCCESS, LIBSPDM_SOURCE_SUCCESS, 0x0000)
  |  |  ------------------
  |  |  |  |   55|     18|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  280|     18|}
libspdm_reset_managed_buffer:
  283|     18|{
  284|     18|    libspdm_managed_buffer_t *managed_buffer;
  285|       |
  286|     18|    managed_buffer = m_buffer;
  287|     18|    managed_buffer->buffer_size = 0;
  288|       |
  289|     18|    libspdm_zero_mem(managed_buffer + 1, managed_buffer->max_buffer_size);
  290|     18|}

libspdm_get_aead_key_size:
   10|     36|{
   11|     36|    switch (aead_cipher_suite) {
   12|      0|    case SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_128_GCM:
  ------------------
  |  |  417|      0|#define SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_128_GCM 0x00000001
  ------------------
  |  Branch (12:5): [True: 0, False: 36]
  ------------------
   13|      0|#if LIBSPDM_AEAD_AES_128_GCM_SUPPORT
   14|      0|        return 16;
   15|       |#else
   16|       |        return 0;
   17|       |#endif
   18|      0|    case SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_256_GCM:
  ------------------
  |  |  418|      0|#define SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_256_GCM 0x00000002
  ------------------
  |  Branch (18:5): [True: 0, False: 36]
  ------------------
   19|      0|#if LIBSPDM_AEAD_AES_256_GCM_SUPPORT
   20|      0|        return 32;
   21|       |#else
   22|       |        return 0;
   23|       |#endif
   24|      0|    case SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_CHACHA20_POLY1305:
  ------------------
  |  |  419|      0|#define SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_CHACHA20_POLY1305 0x00000004
  ------------------
  |  Branch (24:5): [True: 0, False: 36]
  ------------------
   25|      0|#if LIBSPDM_AEAD_CHACHA20_POLY1305_SUPPORT
   26|      0|        return 32;
   27|       |#else
   28|       |        return 0;
   29|       |#endif
   30|      0|    case SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AEAD_SM4_GCM:
  ------------------
  |  |  422|      0|#define SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AEAD_SM4_GCM 0x00000008
  ------------------
  |  Branch (30:5): [True: 0, False: 36]
  ------------------
   31|       |#if LIBSPDM_AEAD_SM4_128_GCM_SUPPORT
   32|       |        return 16;
   33|       |#else
   34|      0|        return 0;
   35|      0|#endif
   36|     36|    default:
  ------------------
  |  Branch (36:5): [True: 36, False: 0]
  ------------------
   37|     36|        return 0;
   38|     36|    }
   39|     36|}
libspdm_get_aead_iv_size:
   42|     36|{
   43|     36|    switch (aead_cipher_suite) {
   44|      0|    case SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_128_GCM:
  ------------------
  |  |  417|      0|#define SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_128_GCM 0x00000001
  ------------------
  |  Branch (44:5): [True: 0, False: 36]
  ------------------
   45|      0|#if LIBSPDM_AEAD_AES_128_GCM_SUPPORT
   46|      0|        return 12;
   47|       |#else
   48|       |        return 0;
   49|       |#endif
   50|      0|    case SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_256_GCM:
  ------------------
  |  |  418|      0|#define SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_256_GCM 0x00000002
  ------------------
  |  Branch (50:5): [True: 0, False: 36]
  ------------------
   51|      0|#if LIBSPDM_AEAD_AES_256_GCM_SUPPORT
   52|      0|        return 12;
   53|       |#else
   54|       |        return 0;
   55|       |#endif
   56|      0|    case SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_CHACHA20_POLY1305:
  ------------------
  |  |  419|      0|#define SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_CHACHA20_POLY1305 0x00000004
  ------------------
  |  Branch (56:5): [True: 0, False: 36]
  ------------------
   57|      0|#if LIBSPDM_AEAD_CHACHA20_POLY1305_SUPPORT
   58|      0|        return 12;
   59|       |#else
   60|       |        return 0;
   61|       |#endif
   62|      0|    case SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AEAD_SM4_GCM:
  ------------------
  |  |  422|      0|#define SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AEAD_SM4_GCM 0x00000008
  ------------------
  |  Branch (62:5): [True: 0, False: 36]
  ------------------
   63|       |#if LIBSPDM_AEAD_SM4_128_GCM_SUPPORT
   64|       |        return 12;
   65|       |#else
   66|      0|        return 0;
   67|      0|#endif
   68|     36|    default:
  ------------------
  |  Branch (68:5): [True: 36, False: 0]
  ------------------
   69|     36|        return 0;
   70|     36|    }
   71|     36|}
libspdm_get_aead_tag_size:
   74|     36|{
   75|     36|    switch (aead_cipher_suite) {
   76|      0|    case SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_128_GCM:
  ------------------
  |  |  417|      0|#define SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_128_GCM 0x00000001
  ------------------
  |  Branch (76:5): [True: 0, False: 36]
  ------------------
   77|      0|#if LIBSPDM_AEAD_AES_128_GCM_SUPPORT
   78|      0|        return 16;
   79|       |#else
   80|       |        return 0;
   81|       |#endif
   82|      0|    case SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_256_GCM:
  ------------------
  |  |  418|      0|#define SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_256_GCM 0x00000002
  ------------------
  |  Branch (82:5): [True: 0, False: 36]
  ------------------
   83|      0|#if LIBSPDM_AEAD_AES_256_GCM_SUPPORT
   84|      0|        return 16;
   85|       |#else
   86|       |        return 0;
   87|       |#endif
   88|      0|    case SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_CHACHA20_POLY1305:
  ------------------
  |  |  419|      0|#define SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_CHACHA20_POLY1305 0x00000004
  ------------------
  |  Branch (88:5): [True: 0, False: 36]
  ------------------
   89|      0|#if LIBSPDM_AEAD_CHACHA20_POLY1305_SUPPORT
   90|      0|        return 16;
   91|       |#else
   92|       |        return 0;
   93|       |#endif
   94|      0|    case SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AEAD_SM4_GCM:
  ------------------
  |  |  422|      0|#define SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AEAD_SM4_GCM 0x00000008
  ------------------
  |  Branch (94:5): [True: 0, False: 36]
  ------------------
   95|       |#if LIBSPDM_AEAD_SM4_128_GCM_SUPPORT
   96|       |        return 16;
   97|       |#else
   98|      0|        return 0;
   99|      0|#endif
  100|     36|    default:
  ------------------
  |  Branch (100:5): [True: 36, False: 0]
  ------------------
  101|     36|        return 0;
  102|     36|    }
  103|     36|}

libspdm_get_dhe_pub_key_size:
   17|     36|{
   18|     36|    switch (dhe_named_group) {
   19|      0|    case SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_2048:
  ------------------
  |  |  406|      0|#define SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_2048 0x00000001
  ------------------
  |  Branch (19:5): [True: 0, False: 36]
  ------------------
   20|      0|#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:
  ------------------
  |  |  407|      0|#define SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_3072 0x00000002
  ------------------
  |  Branch (25:5): [True: 0, False: 36]
  ------------------
   26|      0|#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:
  ------------------
  |  |  408|      0|#define SPDM_ALGORITHMS_DHE_NAMED_GROUP_FFDHE_4096 0x00000004
  ------------------
  |  Branch (31:5): [True: 0, False: 36]
  ------------------
   32|      0|#if LIBSPDM_FFDHE_4096_SUPPORT
   33|      0|        return 512;
   34|       |#else
   35|       |        return 0;
   36|       |#endif
   37|      0|    case SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1:
  ------------------
  |  |  409|      0|#define SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1 0x00000008
  ------------------
  |  Branch (37:5): [True: 0, False: 36]
  ------------------
   38|      0|#if LIBSPDM_ECDHE_P256_SUPPORT
   39|      0|        return 32 * 2;
   40|       |#else
   41|       |        return 0;
   42|       |#endif
   43|      0|    case SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_384_R1:
  ------------------
  |  |  410|      0|#define SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_384_R1 0x00000010
  ------------------
  |  Branch (43:5): [True: 0, False: 36]
  ------------------
   44|      0|#if LIBSPDM_ECDHE_P384_SUPPORT
   45|      0|        return 48 * 2;
   46|       |#else
   47|       |        return 0;
   48|       |#endif
   49|      0|    case SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_521_R1:
  ------------------
  |  |  411|      0|#define SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_521_R1 0x00000020
  ------------------
  |  Branch (49:5): [True: 0, False: 36]
  ------------------
   50|      0|#if LIBSPDM_ECDHE_P521_SUPPORT
   51|      0|        return 66 * 2;
   52|       |#else
   53|       |        return 0;
   54|       |#endif
   55|      0|    case SPDM_ALGORITHMS_DHE_NAMED_GROUP_SM2_P256:
  ------------------
  |  |  414|      0|#define SPDM_ALGORITHMS_DHE_NAMED_GROUP_SM2_P256 0x00000040
  ------------------
  |  Branch (55:5): [True: 0, False: 36]
  ------------------
   56|       |#if LIBSPDM_SM2_KEY_EXCHANGE_P256_SUPPORT
   57|       |        return 32 * 2;
   58|       |#else
   59|      0|        return 0;
   60|      0|#endif
   61|     36|    default:
  ------------------
  |  Branch (61:5): [True: 36, False: 0]
  ------------------
   62|     36|        return 0;
   63|     36|    }
   64|     36|}

libspdm_get_hash_size:
   10|     36|{
   11|     36|    switch (base_hash_algo) {
   12|      0|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
  ------------------
  |  |  391|      0|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256 0x00000001
  ------------------
  |  Branch (12:5): [True: 0, False: 36]
  ------------------
   13|      0|#if LIBSPDM_SHA256_SUPPORT
   14|      0|        return 32;
   15|       |#else
   16|       |        return 0;
   17|       |#endif
   18|      0|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_256:
  ------------------
  |  |  394|      0|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_256 0x00000008
  ------------------
  |  Branch (18:5): [True: 0, False: 36]
  ------------------
   19|      0|#if LIBSPDM_SHA3_256_SUPPORT
   20|      0|        return 32;
   21|       |#else
   22|       |        return 0;
   23|       |#endif
   24|      0|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384:
  ------------------
  |  |  392|      0|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384 0x00000002
  ------------------
  |  Branch (24:5): [True: 0, False: 36]
  ------------------
   25|      0|#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:
  ------------------
  |  |  395|      0|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_384 0x00000010
  ------------------
  |  Branch (30:5): [True: 0, False: 36]
  ------------------
   31|      0|#if LIBSPDM_SHA3_384_SUPPORT
   32|      0|        return 48;
   33|       |#else
   34|       |        return 0;
   35|       |#endif
   36|      0|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512:
  ------------------
  |  |  393|      0|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512 0x00000004
  ------------------
  |  Branch (36:5): [True: 0, False: 36]
  ------------------
   37|      0|#if LIBSPDM_SHA512_SUPPORT
   38|      0|        return 64;
   39|       |#else
   40|       |        return 0;
   41|       |#endif
   42|      0|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_512:
  ------------------
  |  |  396|      0|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_512 0x00000020
  ------------------
  |  Branch (42:5): [True: 0, False: 36]
  ------------------
   43|      0|#if LIBSPDM_SHA3_512_SUPPORT
   44|      0|        return 64;
   45|       |#else
   46|       |        return 0;
   47|       |#endif
   48|      0|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SM3_256:
  ------------------
  |  |  401|      0|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SM3_256 0x00000040
  ------------------
  |  Branch (48:5): [True: 0, False: 36]
  ------------------
   49|       |#if LIBSPDM_SM3_256_SUPPORT
   50|       |        return 32;
   51|       |#else
   52|      0|        return 0;
   53|      0|#endif
   54|     36|    default:
  ------------------
  |  Branch (54:5): [True: 36, False: 0]
  ------------------
   55|     36|        return 0;
   56|     36|    }
   57|     36|}

libspdm_set_connection_state:
  392|     18|{
  393|     18|    if (spdm_context->connection_info.connection_state != connection_state) {
  ------------------
  |  Branch (393:9): [True: 9, False: 9]
  ------------------
  394|      9|        spdm_context->connection_info.connection_state = connection_state;
  395|      9|        libspdm_trigger_connection_state_callback(spdm_context, connection_state);
  396|      9|    }
  397|     18|}
libspdm_rsp_receive_send.c:libspdm_trigger_connection_state_callback:
  377|      9|{
  378|      9|    if (spdm_context->spdm_connection_state_callback != NULL) {
  ------------------
  |  Branch (378:9): [True: 0, False: 9]
  ------------------
  379|      0|        ((libspdm_connection_state_callback_func)
  380|      0|         spdm_context->spdm_connection_state_callback)(spdm_context, connection_state);
  381|      0|    }
  382|      9|}

libspdm_get_response_version:
   37|    103|{
   38|    103|    const spdm_get_version_request_t *spdm_request;
   39|    103|    libspdm_version_response_mine_t *spdm_response;
   40|    103|    libspdm_return_t status;
   41|       |
   42|    103|    spdm_request = request;
   43|       |
   44|       |    /* -=[Check Parameters Phase]=- */
   45|    103|    LIBSPDM_ASSERT(spdm_request->header.request_response_code == SPDM_GET_VERSION);
   46|       |
   47|       |    /* -=[Validate Request Phase]=- */
   48|    103|    if (request_size < sizeof(spdm_get_version_request_t)) {
  ------------------
  |  Branch (48:9): [True: 0, False: 103]
  ------------------
   49|      0|        return libspdm_generate_error_response(spdm_context,
   50|      0|                                               SPDM_ERROR_CODE_INVALID_REQUEST, 0,
  ------------------
  |  |  855|      0|#define SPDM_ERROR_CODE_INVALID_REQUEST 0x01
  ------------------
   51|      0|                                               response_size, response);
   52|      0|    }
   53|       |
   54|    103|    if (spdm_context->last_spdm_request_session_id_valid) {
  ------------------
  |  Branch (54:9): [True: 0, False: 103]
  ------------------
   55|      0|        return libspdm_generate_error_response(spdm_context,
   56|      0|                                               SPDM_ERROR_CODE_UNEXPECTED_REQUEST,
  ------------------
  |  |  857|      0|#define SPDM_ERROR_CODE_UNEXPECTED_REQUEST 0x04
  ------------------
   57|      0|                                               0, response_size, response);
   58|      0|    }
   59|       |
   60|    103|    if (spdm_request->header.spdm_version != SPDM_MESSAGE_VERSION_10) {
  ------------------
  |  |  110|    103|#define SPDM_MESSAGE_VERSION_10 0x10
  ------------------
  |  Branch (60:9): [True: 94, False: 9]
  ------------------
   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|     94|        return generate_invalid_version_error(response_size, response);
   64|     94|    }
   65|       |
   66|      9|    libspdm_set_connection_state(spdm_context, LIBSPDM_CONNECTION_STATE_NOT_STARTED);
   67|       |
   68|      9|    if ((spdm_context->response_state == LIBSPDM_RESPONSE_STATE_NEED_RESYNC) ||
  ------------------
  |  Branch (68:9): [True: 0, False: 9]
  ------------------
   69|      9|        (spdm_context->response_state == LIBSPDM_RESPONSE_STATE_PROCESSING_ENCAP)) {
  ------------------
  |  Branch (69:9): [True: 0, False: 9]
  ------------------
   70|       |        /* receiving a GET_VERSION resets a need to resynchronization*/
   71|      0|        spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
   72|      0|    }
   73|      9|    if (spdm_context->response_state != LIBSPDM_RESPONSE_STATE_NORMAL) {
  ------------------
  |  Branch (73:9): [True: 0, False: 9]
  ------------------
   74|      0|        return libspdm_responder_handle_response_state(
   75|      0|            spdm_context,
   76|      0|            spdm_request->header.request_response_code,
   77|      0|            response_size, response);
   78|      0|    }
   79|       |
   80|       |    /* -=[Process Request Phase]=- */
   81|      9|    libspdm_reset_message_buffer_via_request_code(spdm_context, NULL,
   82|      9|                                                  spdm_request->header.request_response_code);
   83|       |
   84|      9|    libspdm_reset_message_a(spdm_context);
   85|      9|    libspdm_reset_message_d(spdm_context);
   86|      9|    libspdm_reset_message_b(spdm_context);
   87|      9|    libspdm_reset_message_c(spdm_context);
   88|       |
   89|      9|    request_size = sizeof(spdm_get_version_request_t);
   90|      9|    status = libspdm_append_message_a(spdm_context, spdm_request, request_size);
   91|      9|    if (LIBSPDM_STATUS_IS_ERROR(status)) {
  ------------------
  |  |   30|      9|    (LIBSPDM_STATUS_SEVERITY(status) == LIBSPDM_SEVERITY_ERROR)
  |  |  ------------------
  |  |  |  |   37|      9|#define LIBSPDM_STATUS_SEVERITY(status) (((status) >> 28) & 0xf)
  |  |  ------------------
  |  |                   (LIBSPDM_STATUS_SEVERITY(status) == LIBSPDM_SEVERITY_ERROR)
  |  |  ------------------
  |  |  |  |   44|      9|#define LIBSPDM_SEVERITY_ERROR 0x8
  |  |  ------------------
  |  |  |  Branch (30:5): [True: 0, False: 9]
  |  |  ------------------
  ------------------
   92|      0|        return libspdm_generate_error_response(spdm_context,
   93|      0|                                               SPDM_ERROR_CODE_UNSPECIFIED, 0,
  ------------------
  |  |  858|      0|#define SPDM_ERROR_CODE_UNSPECIFIED 0x05
  ------------------
   94|      0|                                               response_size, response);
   95|      0|    }
   96|       |
   97|      9|    libspdm_reset_context(spdm_context);
   98|       |
   99|       |    /* -=[Construct Response Phase]=- */
  100|      9|    LIBSPDM_ASSERT(*response_size >= sizeof(libspdm_version_response_mine_t));
  101|      9|    *response_size =
  102|      9|        sizeof(spdm_version_response_t) +
  103|      9|        spdm_context->local_context.version.spdm_version_count *
  104|      9|        sizeof(spdm_version_number_t);
  105|      9|    libspdm_zero_mem(response, *response_size);
  106|      9|    spdm_response = response;
  107|       |
  108|      9|    spdm_response->header.spdm_version = spdm_request->header.spdm_version;
  109|      9|    spdm_response->header.request_response_code = SPDM_VERSION;
  ------------------
  |  |   32|      9|#define SPDM_VERSION 0x04
  ------------------
  110|      9|    spdm_response->header.param1 = 0;
  111|      9|    spdm_response->header.param2 = 0;
  112|      9|    spdm_response->version_number_entry_count =
  113|      9|        spdm_context->local_context.version.spdm_version_count;
  114|      9|    libspdm_copy_mem(spdm_response->version_number_entry,
  115|      9|                     sizeof(spdm_response->version_number_entry),
  116|      9|                     spdm_context->local_context.version.spdm_version,
  117|      9|                     sizeof(spdm_version_number_t) *
  118|      9|                     spdm_context->local_context.version.spdm_version_count);
  119|       |
  120|      9|    status = libspdm_append_message_a(spdm_context, spdm_response, *response_size);
  121|      9|    if (LIBSPDM_STATUS_IS_ERROR(status)) {
  ------------------
  |  |   30|      9|    (LIBSPDM_STATUS_SEVERITY(status) == LIBSPDM_SEVERITY_ERROR)
  |  |  ------------------
  |  |  |  |   37|      9|#define LIBSPDM_STATUS_SEVERITY(status) (((status) >> 28) & 0xf)
  |  |  ------------------
  |  |                   (LIBSPDM_STATUS_SEVERITY(status) == LIBSPDM_SEVERITY_ERROR)
  |  |  ------------------
  |  |  |  |   44|      9|#define LIBSPDM_SEVERITY_ERROR 0x8
  |  |  ------------------
  |  |  |  Branch (30:5): [True: 0, False: 9]
  |  |  ------------------
  ------------------
  122|      0|        libspdm_reset_message_a(spdm_context);
  123|      0|        return libspdm_generate_error_response(spdm_context,
  124|      0|                                               SPDM_ERROR_CODE_UNSPECIFIED, 0,
  ------------------
  |  |  858|      0|#define SPDM_ERROR_CODE_UNSPECIFIED 0x05
  ------------------
  125|      0|                                               response_size, response);
  126|      0|    }
  127|       |
  128|       |    /* -=[Update State Phase]=- */
  129|      9|    libspdm_set_connection_state(spdm_context, LIBSPDM_CONNECTION_STATE_AFTER_VERSION);
  130|       |
  131|       |    /*Set the role of device*/
  132|      9|    spdm_context->local_context.is_requester = false;
  133|       |
  134|      9|    return LIBSPDM_STATUS_SUCCESS;
  ------------------
  |  |   59|      9|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_SUCCESS, LIBSPDM_SOURCE_SUCCESS, 0x0000)
  |  |  ------------------
  |  |  |  |   55|      9|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  135|      9|}
libspdm_rsp_version.c:generate_invalid_version_error:
   19|     94|{
   20|     94|    spdm_error_response_t *spdm_response;
   21|       |
   22|     94|    spdm_response = response;
   23|     94|    *response_size = sizeof(spdm_error_response_t);
   24|       |
   25|     94|    spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
  ------------------
  |  |  110|     94|#define SPDM_MESSAGE_VERSION_10 0x10
  ------------------
   26|     94|    spdm_response->header.request_response_code = SPDM_ERROR;
  ------------------
  |  |   37|     94|#define SPDM_ERROR 0x7F
  ------------------
   27|     94|    spdm_response->header.param1 = SPDM_ERROR_CODE_VERSION_MISMATCH;
  ------------------
  |  |  860|     94|#define SPDM_ERROR_CODE_VERSION_MISMATCH 0x41
  ------------------
   28|     94|    spdm_response->header.param2 = 0;
   29|       |
   30|     94|    return LIBSPDM_STATUS_SUCCESS;
  ------------------
  |  |   59|     94|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_SUCCESS, LIBSPDM_SOURCE_SUCCESS, 0x0000)
  |  |  ------------------
  |  |  |  |   55|     94|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
   31|     94|}

libspdm_secured_message_get_context_size:
   15|    206|{
   16|    206|    return sizeof(libspdm_secured_message_context_t);
   17|    206|}
libspdm_secured_message_init_context:
   27|    448|{
   28|    448|    libspdm_secured_message_context_t *secured_message_context;
   29|       |
   30|    448|    secured_message_context = spdm_secured_message_context;
   31|    448|    libspdm_zero_mem(secured_message_context, sizeof(libspdm_secured_message_context_t));
   32|    448|}
libspdm_secured_message_set_use_psk:
   41|     36|{
   42|     36|    libspdm_secured_message_context_t *secured_message_context;
   43|       |
   44|     36|    secured_message_context = spdm_secured_message_context;
   45|     36|    secured_message_context->use_psk = use_psk;
   46|     36|}
libspdm_secured_message_set_session_type:
   94|     36|{
   95|     36|    libspdm_secured_message_context_t *secured_message_context;
   96|       |
   97|     36|    secured_message_context = spdm_secured_message_context;
   98|     36|    secured_message_context->session_type = session_type;
   99|     36|}
libspdm_secured_message_set_algorithms:
  117|     36|{
  118|     36|    libspdm_secured_message_context_t *secured_message_context;
  119|       |
  120|     36|    secured_message_context = spdm_secured_message_context;
  121|     36|    secured_message_context->version = version;
  122|     36|    secured_message_context->secured_message_version = secured_message_version;
  123|     36|    secured_message_context->base_hash_algo = base_hash_algo;
  124|     36|    secured_message_context->dhe_named_group = dhe_named_group;
  125|     36|    secured_message_context->aead_cipher_suite = aead_cipher_suite;
  126|     36|    secured_message_context->key_schedule = key_schedule;
  127|       |
  128|     36|    secured_message_context->hash_size =
  129|     36|        libspdm_get_hash_size(secured_message_context->base_hash_algo);
  130|     36|    secured_message_context->dhe_key_size = libspdm_get_dhe_pub_key_size(
  131|     36|        secured_message_context->dhe_named_group);
  132|     36|    secured_message_context->aead_key_size = libspdm_get_aead_key_size(
  133|     36|        secured_message_context->aead_cipher_suite);
  134|     36|    secured_message_context->aead_iv_size = libspdm_get_aead_iv_size(
  135|     36|        secured_message_context->aead_cipher_suite);
  136|     36|    secured_message_context->aead_tag_size = libspdm_get_aead_tag_size(
  137|     36|        secured_message_context->aead_cipher_suite);
  138|     36|}
libspdm_secured_message_set_max_spdm_session_sequence_number:
  167|     36|{
  168|     36|    libspdm_secured_message_context_t *secured_message_context;
  169|       |
  170|     36|    secured_message_context = spdm_secured_message_context;
  171|     36|    secured_message_context->max_spdm_session_sequence_number = max_spdm_session_sequence_number;
  172|     36|}
libspdm_secured_message_set_sequence_number_endian:
  177|     36|{
  178|     36|    libspdm_secured_message_context_t *secured_message_context;
  179|       |
  180|     36|    secured_message_context = spdm_secured_message_context;
  181|     36|    secured_message_context->sequence_number_endian = endian_value;
  182|     36|}

allocate_zero_pool:
   20|    103|{
   21|    103|    void *buffer;
   22|    103|    buffer = malloc(AllocationSize);
   23|    103|    if (buffer == NULL) {
  ------------------
  |  Branch (23:9): [True: 0, False: 103]
  ------------------
   24|      0|        return NULL;
   25|      0|    }
   26|    103|    memset(buffer, 0, AllocationSize);
   27|    103|    return buffer;
   28|    103|}

libspdm_copy_mem:
   12|     90|{
   13|     90|    volatile uint8_t* dst;
   14|     90|    const volatile uint8_t* src;
   15|       |
   16|     90|    dst = (volatile uint8_t*) dst_buf;
   17|     90|    src = (const volatile uint8_t*) src_buf;
   18|       |
   19|     90|    if ((dst == NULL) || (src == NULL)) {
  ------------------
  |  Branch (19:9): [True: 0, False: 90]
  |  Branch (19:26): [True: 0, False: 90]
  ------------------
   20|      0|        LIBSPDM_ASSERT(0);
   21|      0|    }
   22|     90|    if (((src < dst) && ((src + src_len) > dst)) || ((dst < src) && ((dst + src_len) > src))) {
  ------------------
  |  Branch (22:10): [True: 80, False: 10]
  |  Branch (22:25): [True: 0, False: 80]
  |  Branch (22:54): [True: 10, False: 80]
  |  Branch (22:69): [True: 0, False: 10]
  ------------------
   23|      0|        LIBSPDM_ASSERT(0);
   24|      0|    }
   25|     90|    if (src_len > dst_len) {
  ------------------
  |  Branch (25:9): [True: 0, False: 90]
  ------------------
   26|      0|        LIBSPDM_ASSERT(0);
   27|      0|    }
   28|       |
   29|  52.5k|    while (src_len-- != 0) {
  ------------------
  |  Branch (29:12): [True: 52.4k, False: 90]
  ------------------
   30|  52.4k|        *(dst++) = *(src++);
   31|  52.4k|    }
   32|     90|}

libspdm_zero_mem:
   17|    695|{
   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|    695|    volatile uint8_t *pointer;
   27|       |
   28|    695|    pointer = (uint8_t *)buffer;
   29|  1.38M|    while (length-- != 0) {
  ------------------
  |  Branch (29:12): [True: 1.38M, False: 695]
  ------------------
   30|  1.38M|        *(pointer++) = 0;
   31|  1.38M|    }
   32|       |
   33|       |#if defined(_MSC_VER) && (_MSC_VER > 1200) && !defined(__clang__)
   34|       |    _ReadWriteBarrier();
   35|       |#elif defined(__GNUC__)
   36|       |    __asm__ __volatile__ ("" : : : "memory");
   37|    695|#endif
   38|       |
   39|    695|#endif
   40|    695|}

libspdm_setup_test_context:
   59|    103|{
   60|    103|    m_libspdm_test_context = spdm_test_context;
   61|    103|}
libspdm_unit_test_group_setup:
   64|    103|{
   65|    103|    libspdm_test_context_t *spdm_test_context;
   66|    103|    void *spdm_context;
   67|       |
   68|    103|    spdm_test_context = m_libspdm_test_context;
   69|    103|    spdm_test_context->spdm_context =
   70|    103|        (void *)malloc(libspdm_get_context_size());
   71|    103|    if (spdm_test_context->spdm_context == NULL) {
  ------------------
  |  Branch (71:9): [True: 0, False: 103]
  ------------------
   72|      0|        return (size_t)-1;
   73|      0|    }
   74|    103|    spdm_context = spdm_test_context->spdm_context;
   75|       |
   76|    103|    libspdm_init_context(spdm_context);
   77|       |
   78|    103|    libspdm_register_device_io_func(spdm_context,
   79|    103|                                    spdm_test_context->send_message,
   80|    103|                                    spdm_test_context->receive_message);
   81|    103|    libspdm_register_transport_layer_func(spdm_context,
   82|    103|                                          LIBSPDM_MAX_SPDM_MSG_SIZE,
  ------------------
  |  |  101|    103|#define LIBSPDM_MAX_SPDM_MSG_SIZE 0x1200
  ------------------
   83|    103|                                          LIBSPDM_TEST_TRANSPORT_HEADER_SIZE,
  ------------------
  |  |   27|    103|#define LIBSPDM_TEST_TRANSPORT_HEADER_SIZE  (2 + 8 + \
  |  |   28|    103|                                             LIBSPDM_TEST_SEQUENCE_NUMBER_COUNT)
  |  |  ------------------
  |  |  |  |   16|    103|#define LIBSPDM_TEST_SEQUENCE_NUMBER_COUNT 2
  |  |  ------------------
  ------------------
   84|    103|                                          LIBSPDM_TEST_TRANSPORT_TAIL_SIZE,
  ------------------
  |  |   30|    103|#define LIBSPDM_TEST_TRANSPORT_TAIL_SIZE    (LIBSPDM_TEST_MAX_RANDOM_NUMBER_COUNT + \
  |  |  ------------------
  |  |  |  |   17|    103|#define LIBSPDM_TEST_MAX_RANDOM_NUMBER_COUNT 32
  |  |  ------------------
  |  |   31|    103|                                             LIBSPDM_MAX_AEAD_TAG_SIZE + \
  |  |  ------------------
  |  |  |  |   75|    103|#define LIBSPDM_MAX_AEAD_TAG_SIZE 16
  |  |  ------------------
  |  |   32|    103|                                             (LIBSPDM_TEST_ALIGNMENT - 1))
  |  |  ------------------
  |  |  |  |   15|    103|#define LIBSPDM_TEST_ALIGNMENT 4
  |  |  ------------------
  ------------------
   85|    103|                                          libspdm_transport_test_encode_message,
   86|    103|                                          libspdm_transport_test_decode_message);
   87|    103|    libspdm_register_device_buffer_func(spdm_context,
   88|    103|                                        LIBSPDM_MAX_SENDER_RECEIVER_BUFFER_SIZE,
  ------------------
  |  |   93|    103|#define LIBSPDM_MAX_SENDER_RECEIVER_BUFFER_SIZE LIBSPDM_RECEIVER_BUFFER_SIZE
  |  |  ------------------
  |  |  |  |   78|    103|#define LIBSPDM_RECEIVER_BUFFER_SIZE (0x1200 + \
  |  |  |  |   79|    103|                                      LIBSPDM_TRANSPORT_ADDITIONAL_SIZE)
  |  |  |  |  ------------------
  |  |  |  |  |  |   70|    103|#define LIBSPDM_TRANSPORT_ADDITIONAL_SIZE    (LIBSPDM_TEST_TRANSPORT_HEADER_SIZE + \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   27|    103|#define LIBSPDM_TEST_TRANSPORT_HEADER_SIZE  (2 + 8 + \
  |  |  |  |  |  |  |  |   28|    103|                                             LIBSPDM_TEST_SEQUENCE_NUMBER_COUNT)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   16|    103|#define LIBSPDM_TEST_SEQUENCE_NUMBER_COUNT 2
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |   71|    103|                                              LIBSPDM_TEST_TRANSPORT_TAIL_SIZE)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   30|    103|#define LIBSPDM_TEST_TRANSPORT_TAIL_SIZE    (LIBSPDM_TEST_MAX_RANDOM_NUMBER_COUNT + \
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   17|    103|#define LIBSPDM_TEST_MAX_RANDOM_NUMBER_COUNT 32
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|    103|                                             LIBSPDM_MAX_AEAD_TAG_SIZE + \
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   75|    103|#define LIBSPDM_MAX_AEAD_TAG_SIZE 16
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   32|    103|                                             (LIBSPDM_TEST_ALIGNMENT - 1))
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   15|    103|#define LIBSPDM_TEST_ALIGNMENT 4
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   89|    103|                                        LIBSPDM_MAX_SENDER_RECEIVER_BUFFER_SIZE,
  ------------------
  |  |   93|    103|#define LIBSPDM_MAX_SENDER_RECEIVER_BUFFER_SIZE LIBSPDM_RECEIVER_BUFFER_SIZE
  |  |  ------------------
  |  |  |  |   78|    103|#define LIBSPDM_RECEIVER_BUFFER_SIZE (0x1200 + \
  |  |  |  |   79|    103|                                      LIBSPDM_TRANSPORT_ADDITIONAL_SIZE)
  |  |  |  |  ------------------
  |  |  |  |  |  |   70|    103|#define LIBSPDM_TRANSPORT_ADDITIONAL_SIZE    (LIBSPDM_TEST_TRANSPORT_HEADER_SIZE + \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   27|    103|#define LIBSPDM_TEST_TRANSPORT_HEADER_SIZE  (2 + 8 + \
  |  |  |  |  |  |  |  |   28|    103|                                             LIBSPDM_TEST_SEQUENCE_NUMBER_COUNT)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   16|    103|#define LIBSPDM_TEST_SEQUENCE_NUMBER_COUNT 2
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |   71|    103|                                              LIBSPDM_TEST_TRANSPORT_TAIL_SIZE)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   30|    103|#define LIBSPDM_TEST_TRANSPORT_TAIL_SIZE    (LIBSPDM_TEST_MAX_RANDOM_NUMBER_COUNT + \
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   17|    103|#define LIBSPDM_TEST_MAX_RANDOM_NUMBER_COUNT 32
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|    103|                                             LIBSPDM_MAX_AEAD_TAG_SIZE + \
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   75|    103|#define LIBSPDM_MAX_AEAD_TAG_SIZE 16
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   32|    103|                                             (LIBSPDM_TEST_ALIGNMENT - 1))
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   15|    103|#define LIBSPDM_TEST_ALIGNMENT 4
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   90|    103|                                        spdm_device_acquire_sender_buffer,
   91|    103|                                        spdm_device_release_sender_buffer,
   92|    103|                                        spdm_device_acquire_receiver_buffer,
   93|    103|                                        spdm_device_release_receiver_buffer);
   94|       |
   95|    103|    spdm_test_context->scratch_buffer_size =
   96|    103|        libspdm_get_sizeof_required_scratch_buffer(spdm_context);
   97|    103|    spdm_test_context->scratch_buffer = (void *)malloc(spdm_test_context->scratch_buffer_size);
   98|    103|    libspdm_set_scratch_buffer (spdm_context,
   99|    103|                                spdm_test_context->scratch_buffer,
  100|    103|                                spdm_test_context->scratch_buffer_size);
  101|       |
  102|    103|    *State = spdm_test_context;
  103|    103|    return 0;
  104|    103|}
libspdm_unit_test_group_teardown:
  107|    103|{
  108|    103|    libspdm_test_context_t *spdm_test_context;
  109|       |
  110|    103|    spdm_test_context = *State;
  111|    103|    free(spdm_test_context->spdm_context);
  112|    103|    free(spdm_test_context->scratch_buffer);
  113|    103|    spdm_test_context->spdm_context = NULL;
  114|    103|    return 0;
  115|    103|}

libspdm_alignment_size:
   21|    103|{
   22|    103|    size_t alignment;
   23|    103|    size_t max_buffer_size;
   24|       |
   25|    103|    alignment = LIBSPDM_TEST_ALIGNMENT;
  ------------------
  |  |   15|    103|#define LIBSPDM_TEST_ALIGNMENT 4
  ------------------
   26|    103|    max_buffer_size = libspdm_get_max_buffer_size();
   27|       |
   28|       |    /* In the situation where max_buffer_size is not four-byte aligned, reserve sufficient size for the buffer_size */
   29|    103|    if ((size > max_buffer_size - alignment) && (size & (alignment - 1)) != 0) {
  ------------------
  |  Branch (29:9): [True: 44, False: 59]
  |  Branch (29:49): [True: 3, False: 41]
  ------------------
   30|      3|        size -= alignment;
   31|      3|    }
   32|       |
   33|    103|    if (((size) & (alignment - 1)) == 3) {
  ------------------
  |  Branch (33:9): [True: 17, False: 86]
  ------------------
   34|     17|        size += 1;
   35|     17|    }
   36|    103|    if (((size) & (alignment - 1)) == 2) {
  ------------------
  |  Branch (36:9): [True: 13, False: 90]
  ------------------
   37|     13|        size += 2;
   38|     13|    }
   39|    103|    if (((size) & (alignment - 1)) == 1) {
  ------------------
  |  Branch (39:9): [True: 22, False: 81]
  ------------------
   40|     22|        size += 3;
   41|     22|    }
   42|    103|    return size;
   43|    103|}
LLVMFuzzerTestOneInput:
  112|    103|{
  113|    103|    void *test_buffer;
  114|    103|    size_t max_buffer_size;
  115|       |
  116|       |    /* 1. Initialize test_buffer*/
  117|    103|    max_buffer_size = libspdm_get_max_buffer_size();
  118|    103|    test_buffer = allocate_zero_pool(max_buffer_size);
  119|    103|    if (test_buffer == NULL) {
  ------------------
  |  Branch (119:9): [True: 0, False: 103]
  ------------------
  120|      0|        return 0;
  121|      0|    }
  122|    103|    if (size == 0) {
  ------------------
  |  Branch (122:9): [True: 0, False: 103]
  ------------------
  123|      0|        printf("\033[1;33m file_size of the seed file is 0, so exit.\033[0m \n");
  124|      0|        free(test_buffer);
  125|      0|        return 0;
  126|      0|    }
  127|    103|    if (size > max_buffer_size) {
  ------------------
  |  Branch (127:9): [True: 40, False: 63]
  ------------------
  128|     40|        size = max_buffer_size;
  129|     63|    } else {
  130|     63|        libspdm_copy_mem(test_buffer, max_buffer_size, data, size);
  131|     63|    }
  132|    103|    size = libspdm_alignment_size(size);
  133|       |    /* 2. Run test*/
  134|    103|    libspdm_run_test_harness(test_buffer, size);
  135|       |    /* 3. Clean up*/
  136|    103|    free(test_buffer);
  137|    103|    return 0;
  138|    103|}

libspdm_get_max_buffer_size:
   12|    206|{
   13|    206|    return LIBSPDM_MAX_SPDM_MSG_SIZE;
  ------------------
  |  |  101|    206|#define LIBSPDM_MAX_SPDM_MSG_SIZE 0x1200
  ------------------
   14|    206|}
libspdm_test_responder_version:
   17|    103|{
   18|    103|    libspdm_test_context_t *spdm_test_context;
   19|    103|    libspdm_context_t *spdm_context;
   20|    103|    size_t response_size;
   21|    103|    uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
   22|       |
   23|    103|    spdm_test_context = *State;
   24|    103|    spdm_context = spdm_test_context->spdm_context;
   25|       |
   26|    103|    response_size = sizeof(response);
   27|    103|    libspdm_get_response_version(spdm_context,
   28|    103|                                 spdm_test_context->test_buffer_size,
   29|    103|                                 spdm_test_context->test_buffer,
   30|    103|                                 &response_size, response);
   31|    103|}
libspdm_run_test_harness:
   39|    103|{
   40|    103|    void *State;
   41|    103|    spdm_message_header_t *spdm_request_header;
   42|    103|    libspdm_setup_test_context(&m_libspdm_responder_version_test_context);
   43|       |
   44|    103|    spdm_request_header = (spdm_message_header_t*)test_buffer;
   45|       |
   46|    103|    if (spdm_request_header->request_response_code != SPDM_GET_VERSION) {
  ------------------
  |  |   69|    103|#define SPDM_GET_VERSION 0x84
  ------------------
  |  Branch (46:9): [True: 102, False: 1]
  ------------------
   47|    102|        spdm_request_header->request_response_code = SPDM_GET_VERSION;
  ------------------
  |  |   69|    102|#define SPDM_GET_VERSION 0x84
  ------------------
   48|    102|    }
   49|       |
   50|    103|    m_libspdm_responder_version_test_context.test_buffer = test_buffer;
   51|    103|    m_libspdm_responder_version_test_context.test_buffer_size =
   52|    103|        test_buffer_size;
   53|       |
   54|    103|    libspdm_unit_test_group_setup(&State);
   55|       |
   56|       |    /* Success Case*/
   57|    103|    libspdm_test_responder_version(&State);
   58|       |
   59|    103|    libspdm_unit_test_group_teardown(&State);
   60|    103|}

