libspdm_get_scratch_buffer_secure_message_capacity:
   17|    456|uint32_t libspdm_get_scratch_buffer_secure_message_capacity(libspdm_context_t *spdm_context) {
   18|    456|    return spdm_context->local_context.capability.max_spdm_msg_size +
   19|    456|           spdm_context->local_context.capability.transport_header_size +
   20|    456|           spdm_context->local_context.capability.transport_tail_size;
   21|    456|}
libspdm_get_scratch_buffer_large_message_capacity:
   28|    456|uint32_t libspdm_get_scratch_buffer_large_message_capacity(libspdm_context_t *spdm_context) {
   29|    456|    return spdm_context->local_context.capability.max_spdm_msg_size;
   30|    456|}
libspdm_get_scratch_buffer_sender_receiver_capacity:
   43|    456|uint32_t libspdm_get_scratch_buffer_sender_receiver_capacity(libspdm_context_t *spdm_context) {
   44|    456|    return spdm_context->local_context.capability.max_spdm_msg_size +
   45|    456|           spdm_context->local_context.capability.transport_header_size +
   46|    456|           spdm_context->local_context.capability.transport_tail_size;
   47|    456|}
libspdm_get_scratch_buffer_large_sender_receiver_capacity:
   58|    456|{
   59|    456|    return spdm_context->local_context.capability.max_spdm_msg_size +
   60|    456|           spdm_context->local_context.capability.transport_header_size +
   61|    456|           spdm_context->local_context.capability.transport_tail_size;
   62|    456|}
libspdm_get_scratch_buffer_last_spdm_request_offset:
   66|    152|uint32_t libspdm_get_scratch_buffer_last_spdm_request_offset(libspdm_context_t *spdm_context) {
   67|    152|    return 0 +
   68|    152|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
   69|    152|           libspdm_get_scratch_buffer_secure_message_capacity(spdm_context) +
   70|    152|           libspdm_get_scratch_buffer_large_message_capacity(spdm_context) +
   71|    152|#endif
   72|    152|           libspdm_get_scratch_buffer_sender_receiver_capacity(spdm_context) +
   73|    152|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
   74|    152|           libspdm_get_scratch_buffer_large_sender_receiver_capacity(spdm_context) +
   75|    152|#endif
   76|    152|           0;
   77|    152|}
libspdm_get_scratch_buffer_last_spdm_request_capacity:
   79|    304|uint32_t libspdm_get_scratch_buffer_last_spdm_request_capacity(libspdm_context_t *spdm_context) {
   80|    304|    return spdm_context->local_context.capability.max_spdm_msg_size;
   81|    304|}
libspdm_get_scratch_buffer_cache_spdm_request_offset:
   85|    152|uint32_t libspdm_get_scratch_buffer_cache_spdm_request_offset(libspdm_context_t *spdm_context) {
   86|    152|    return 0 +
   87|    152|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
   88|    152|           libspdm_get_scratch_buffer_secure_message_capacity(spdm_context) +
   89|    152|           libspdm_get_scratch_buffer_large_message_capacity(spdm_context) +
   90|    152|#endif
   91|    152|           libspdm_get_scratch_buffer_sender_receiver_capacity(spdm_context) +
   92|    152|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
   93|    152|           libspdm_get_scratch_buffer_large_sender_receiver_capacity(spdm_context) +
   94|    152|#endif
   95|    152|           libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context) +
   96|    152|           0;
   97|    152|}
libspdm_get_scratch_buffer_cache_spdm_request_capacity:
   99|    152|uint32_t libspdm_get_scratch_buffer_cache_spdm_request_capacity(libspdm_context_t *spdm_context) {
  100|    152|    return spdm_context->local_context.capability.max_spdm_msg_size;
  101|    152|}
libspdm_get_scratch_buffer_capacity:
  105|    152|uint32_t libspdm_get_scratch_buffer_capacity(libspdm_context_t *spdm_context) {
  106|    152|    return 0 +
  107|    152|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
  108|    152|           libspdm_get_scratch_buffer_secure_message_capacity(spdm_context) +
  109|    152|           libspdm_get_scratch_buffer_large_message_capacity(spdm_context) +
  110|    152|#endif
  111|    152|           libspdm_get_scratch_buffer_sender_receiver_capacity(spdm_context) +
  112|    152|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
  113|    152|           libspdm_get_scratch_buffer_large_sender_receiver_capacity(spdm_context) +
  114|    152|#endif
  115|    152|           libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context) +
  116|    152|#if LIBSPDM_RESPOND_IF_READY_SUPPORT
  117|    152|           libspdm_get_scratch_buffer_cache_spdm_request_capacity(spdm_context) +
  118|    152|#endif
  119|    152|           0;
  120|    152|}
libspdm_reset_message_b:
 1280|     18|{
 1281|       |#if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
 1282|       |    libspdm_reset_managed_buffer(&spdm_context->transcript.message_b);
 1283|       |#else
 1284|     18|    if (spdm_context->transcript.digest_context_m1m2 != NULL) {
  ------------------
  |  Branch (1284:9): [True: 0, False: 18]
  ------------------
 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|     18|#endif
 1290|     18|}
libspdm_reset_message_c:
 1298|     17|{
 1299|       |#if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
 1300|       |    libspdm_reset_managed_buffer(&spdm_context->transcript.message_c);
 1301|       |#else
 1302|     17|    if (spdm_context->transcript.digest_context_m1m2 != NULL) {
  ------------------
  |  Branch (1302:9): [True: 0, False: 17]
  ------------------
 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|     17|#endif
 1308|     17|}
libspdm_reset_message_mut_b:
 1316|     16|{
 1317|       |#if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
 1318|       |    libspdm_reset_managed_buffer(&spdm_context->transcript.message_mut_b);
 1319|       |#else
 1320|     16|    if (spdm_context->transcript.digest_context_mut_m1m2 != NULL) {
  ------------------
  |  Branch (1320:9): [True: 0, False: 16]
  ------------------
 1321|      0|        libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
 1322|      0|                           spdm_context->transcript.digest_context_mut_m1m2);
 1323|      0|        spdm_context->transcript.digest_context_mut_m1m2 = NULL;
 1324|      0|    }
 1325|     16|#endif
 1326|     16|}
libspdm_reset_message_mut_c:
 1334|     16|{
 1335|       |#if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
 1336|       |    libspdm_reset_managed_buffer(&spdm_context->transcript.message_mut_c);
 1337|       |#else
 1338|     16|    if (spdm_context->transcript.digest_context_mut_m1m2 != NULL) {
  ------------------
  |  Branch (1338:9): [True: 0, False: 16]
  ------------------
 1339|      0|        libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
 1340|      0|                           spdm_context->transcript.digest_context_mut_m1m2);
 1341|      0|        spdm_context->transcript.digest_context_mut_m1m2 = NULL;
 1342|      0|    }
 1343|     16|#endif
 1344|     16|}
libspdm_reset_message_m:
 1355|     43|{
 1356|     43|    libspdm_session_info_t *spdm_session_info;
 1357|       |
 1358|     43|    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|     43|    if (spdm_session_info == NULL) {
  ------------------
  |  Branch (1366:9): [True: 43, False: 0]
  ------------------
 1367|     43|        if (spdm_context->transcript.digest_context_l1l2 != NULL) {
  ------------------
  |  Branch (1367:13): [True: 0, False: 43]
  ------------------
 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|     43|    } 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|     43|#endif
 1380|     43|}
libspdm_reset_message_e:
 1461|      2|{
 1462|      2|    libspdm_session_info_t *spdm_session_info;
 1463|       |
 1464|      2|    spdm_session_info = session_info;
 1465|       |#if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
 1466|       |    if (spdm_session_info == NULL) {
 1467|       |        libspdm_reset_managed_buffer(&spdm_context->transcript.message_e);
 1468|       |    } else {
 1469|       |        libspdm_reset_managed_buffer(&spdm_session_info->session_transcript.message_e);
 1470|       |    }
 1471|       |#else
 1472|      2|    if (spdm_session_info == NULL) {
  ------------------
  |  Branch (1472:9): [True: 2, False: 0]
  ------------------
 1473|      2|        if (spdm_context->transcript.digest_context_il1il2 != NULL) {
  ------------------
  |  Branch (1473:13): [True: 0, False: 2]
  ------------------
 1474|      0|            libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
 1475|      0|                               spdm_context->transcript.digest_context_il1il2);
 1476|      0|            spdm_context->transcript.digest_context_il1il2 = NULL;
 1477|      0|        }
 1478|      2|    } else {
 1479|      0|        if (spdm_session_info->session_transcript.digest_context_il1il2 != NULL) {
  ------------------
  |  Branch (1479:13): [True: 0, False: 0]
  ------------------
 1480|      0|            libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
 1481|      0|                               spdm_session_info->session_transcript.digest_context_il1il2);
 1482|      0|            spdm_session_info->session_transcript.digest_context_il1il2 = NULL;
 1483|      0|        }
 1484|      0|    }
 1485|      2|#endif
 1486|      2|}
libspdm_reset_message_encap_e:
 1497|      2|{
 1498|      2|    libspdm_session_info_t *spdm_session_info;
 1499|       |
 1500|      2|    spdm_session_info = session_info;
 1501|       |#if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
 1502|       |    if (spdm_session_info == NULL) {
 1503|       |        libspdm_reset_managed_buffer(&spdm_context->transcript.message_encap_e);
 1504|       |    } else {
 1505|       |        libspdm_reset_managed_buffer(&spdm_session_info->session_transcript.message_encap_e);
 1506|       |    }
 1507|       |#else
 1508|      2|    if (spdm_session_info == NULL) {
  ------------------
  |  Branch (1508:9): [True: 2, False: 0]
  ------------------
 1509|      2|        if (spdm_context->transcript.digest_context_encap_il1il2 != NULL) {
  ------------------
  |  Branch (1509:13): [True: 0, False: 2]
  ------------------
 1510|      0|            libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
 1511|      0|                               spdm_context->transcript.digest_context_encap_il1il2);
 1512|      0|            spdm_context->transcript.digest_context_encap_il1il2 = NULL;
 1513|      0|        }
 1514|      2|    } else {
 1515|      0|        if (spdm_session_info->session_transcript.digest_context_encap_il1il2 != NULL) {
  ------------------
  |  Branch (1515:13): [True: 0, False: 0]
  ------------------
 1516|      0|            libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
 1517|      0|                               spdm_session_info->session_transcript.digest_context_encap_il1il2);
 1518|      0|            spdm_session_info->session_transcript.digest_context_encap_il1il2 = NULL;
 1519|      0|        }
 1520|      0|    }
 1521|      2|#endif
 1522|      2|}
libspdm_reset_message_buffer_via_request_code:
 1533|     46|{
 1534|     46|    libspdm_context_t *spdm_context;
 1535|       |
 1536|     46|    spdm_context = context;
 1537|       |    /**
 1538|       |     * Any request other than SPDM_GET_MEASUREMENTS resets L1/L2
 1539|       |     */
 1540|     46|    if (request_code != SPDM_GET_MEASUREMENTS) {
  ------------------
  |  |   70|     46|#define SPDM_GET_MEASUREMENTS 0xE0
  ------------------
  |  Branch (1540:9): [True: 43, False: 3]
  ------------------
 1541|     43|        libspdm_reset_message_m(spdm_context, session_info);
 1542|     43|    }
 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|     46|    switch (request_code)
 1549|     46|    {
 1550|      2|    case SPDM_KEY_EXCHANGE:
  ------------------
  |  |   77|      2|#define SPDM_KEY_EXCHANGE 0xE4
  ------------------
  |  Branch (1550:5): [True: 2, False: 44]
  ------------------
 1551|      5|    case SPDM_GET_MEASUREMENTS:
  ------------------
  |  |   70|      5|#define SPDM_GET_MEASUREMENTS 0xE0
  ------------------
  |  Branch (1551:5): [True: 3, False: 43]
  ------------------
 1552|      6|    case SPDM_FINISH:
  ------------------
  |  |   78|      6|#define SPDM_FINISH 0xE5
  ------------------
  |  Branch (1552:5): [True: 1, False: 45]
  ------------------
 1553|      7|    case SPDM_PSK_EXCHANGE:
  ------------------
  |  |   79|      7|#define SPDM_PSK_EXCHANGE 0xE6
  ------------------
  |  Branch (1553:5): [True: 1, False: 45]
  ------------------
 1554|      9|    case SPDM_PSK_FINISH:
  ------------------
  |  |   80|      9|#define SPDM_PSK_FINISH 0xE7
  ------------------
  |  Branch (1554:5): [True: 2, False: 44]
  ------------------
 1555|     10|    case SPDM_KEY_UPDATE:
  ------------------
  |  |   82|     10|#define SPDM_KEY_UPDATE 0xE9
  ------------------
  |  Branch (1555:5): [True: 1, False: 45]
  ------------------
 1556|     13|    case SPDM_HEARTBEAT:
  ------------------
  |  |   81|     13|#define SPDM_HEARTBEAT 0xE8
  ------------------
  |  Branch (1556:5): [True: 3, False: 43]
  ------------------
 1557|     14|    case SPDM_GET_ENCAPSULATED_REQUEST:
  ------------------
  |  |   83|     14|#define SPDM_GET_ENCAPSULATED_REQUEST 0xEA
  ------------------
  |  Branch (1557:5): [True: 1, False: 45]
  ------------------
 1558|     15|    case SPDM_END_SESSION:
  ------------------
  |  |   85|     15|#define SPDM_END_SESSION 0xEC
  ------------------
  |  Branch (1558:5): [True: 1, False: 45]
  ------------------
 1559|     16|    case SPDM_GET_MEASUREMENT_EXTENSION_LOG:
  ------------------
  |  |   98|     16|#define SPDM_GET_MEASUREMENT_EXTENSION_LOG 0xEF
  ------------------
  |  Branch (1559:5): [True: 1, False: 45]
  ------------------
 1560|     16|        if (spdm_context->connection_info.connection_state <
  ------------------
  |  Branch (1560:13): [True: 16, False: 0]
  ------------------
 1561|     16|            LIBSPDM_CONNECTION_STATE_AUTHENTICATED) {
 1562|     16|            libspdm_reset_message_b(spdm_context);
 1563|     16|            libspdm_reset_message_c(spdm_context);
 1564|     16|            libspdm_reset_message_mut_b(spdm_context);
 1565|     16|            libspdm_reset_message_mut_c(spdm_context);
 1566|     16|        }
 1567|     16|        break;
 1568|      1|    case SPDM_DELIVER_ENCAPSULATED_RESPONSE:
  ------------------
  |  |   84|      1|#define SPDM_DELIVER_ENCAPSULATED_RESPONSE 0xEB
  ------------------
  |  Branch (1568:5): [True: 1, False: 45]
  ------------------
 1569|      1|        if (spdm_context->connection_info.connection_state <
  ------------------
  |  Branch (1569:13): [True: 1, False: 0]
  ------------------
 1570|      1|            LIBSPDM_CONNECTION_STATE_AUTHENTICATED) {
 1571|      1|            libspdm_reset_message_b(spdm_context);
 1572|      1|            libspdm_reset_message_c(spdm_context);
 1573|      1|        }
 1574|      1|        break;
 1575|      1|    case SPDM_GET_DIGESTS:
  ------------------
  |  |   66|      1|#define SPDM_GET_DIGESTS 0x81
  ------------------
  |  Branch (1575:5): [True: 1, False: 45]
  ------------------
 1576|      1|        libspdm_reset_message_b(spdm_context);
 1577|      1|        break;
 1578|      2|    case SPDM_GET_ENDPOINT_INFO:
  ------------------
  |  |   94|      2|#define SPDM_GET_ENDPOINT_INFO 0x87
  ------------------
  |  Branch (1578:5): [True: 2, False: 44]
  ------------------
 1579|      2|        libspdm_reset_message_e(spdm_context, session_info);
 1580|      2|        libspdm_reset_message_encap_e(spdm_context, session_info);
 1581|      2|        break;
 1582|     26|    default:
  ------------------
  |  Branch (1582:5): [True: 26, False: 20]
  ------------------
 1583|     26|        break;
 1584|     46|    }
 1585|     46|}
libspdm_get_connection_version:
 2632|    258|{
 2633|    258|    return (uint8_t)(spdm_context->connection_info.version >> SPDM_VERSION_NUMBER_SHIFT_BIT);
  ------------------
  |  |  140|    258|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 2634|    258|}
libspdm_register_device_io_func:
 2720|    152|{
 2721|    152|    libspdm_context_t *context;
 2722|       |
 2723|    152|    context = spdm_context;
 2724|    152|    context->send_message = send_message;
 2725|    152|    context->receive_message = receive_message;
 2726|    152|}
libspdm_register_device_buffer_func:
 2779|    152|{
 2780|    152|    libspdm_context_t *context;
 2781|       |
 2782|    152|    context = spdm_context;
 2783|    152|    context->sender_buffer_size = sender_buffer_size;
 2784|    152|    context->receiver_buffer_size = receiver_buffer_size;
 2785|    152|    context->acquire_sender_buffer = acquire_sender_buffer;
 2786|    152|    context->release_sender_buffer = release_sender_buffer;
 2787|    152|    context->acquire_receiver_buffer = acquire_receiver_buffer;
 2788|    152|    context->release_receiver_buffer = release_receiver_buffer;
 2789|       |
 2790|    152|    LIBSPDM_ASSERT (sender_buffer_size >=
 2791|    152|                    context->local_context.capability.transport_header_size +
 2792|    152|                    context->local_context.capability.transport_tail_size);
 2793|    152|    sender_buffer_size -= (context->local_context.capability.transport_header_size +
 2794|    152|                           context->local_context.capability.transport_tail_size);
 2795|    152|    LIBSPDM_ASSERT (sender_buffer_size >= SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12);
 2796|    152|    context->local_context.capability.sender_data_transfer_size = sender_buffer_size;
 2797|       |
 2798|    152|    LIBSPDM_ASSERT(receiver_buffer_size >=
 2799|    152|                   context->local_context.capability.transport_header_size +
 2800|    152|                   context->local_context.capability.transport_tail_size);
 2801|    152|    receiver_buffer_size -= (context->local_context.capability.transport_header_size +
 2802|    152|                             context->local_context.capability.transport_tail_size);
 2803|    152|    LIBSPDM_ASSERT (receiver_buffer_size >= SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12);
 2804|    152|    context->local_context.capability.data_transfer_size = receiver_buffer_size;
 2805|    152|}
libspdm_register_transport_layer_func:
 2823|    152|{
 2824|    152|    libspdm_context_t *context;
 2825|       |
 2826|    152|    context = spdm_context;
 2827|       |
 2828|       |    /* fix the data_transfer_size if it is set before */
 2829|    152|    if ((context->local_context.capability.data_transfer_size != 0) &&
  ------------------
  |  Branch (2829:9): [True: 0, False: 152]
  ------------------
 2830|    152|        (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|    152|    if ((context->local_context.capability.sender_data_transfer_size != 0) &&
  ------------------
  |  Branch (2836:9): [True: 0, False: 152]
  ------------------
 2837|    152|        (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|    152|    context->local_context.capability.max_spdm_msg_size = max_spdm_msg_size;
 2845|    152|    context->local_context.capability.transport_header_size = transport_header_size;
 2846|    152|    context->local_context.capability.transport_tail_size = transport_tail_size;
 2847|    152|    context->transport_encode_message = transport_encode_message;
 2848|    152|    context->transport_decode_message = transport_decode_message;
 2849|    152|}
libspdm_get_sizeof_required_scratch_buffer:
 2886|    152|{
 2887|    152|    libspdm_context_t *context;
 2888|    152|    size_t scratch_buffer_size;
 2889|       |
 2890|    152|    context = spdm_context;
 2891|    152|    LIBSPDM_ASSERT (context->local_context.capability.max_spdm_msg_size != 0);
 2892|       |
 2893|    152|    scratch_buffer_size = libspdm_get_scratch_buffer_capacity(context);
 2894|    152|    return scratch_buffer_size;
 2895|    152|}
libspdm_set_scratch_buffer:
 2911|    152|{
 2912|    152|    libspdm_context_t *context;
 2913|       |
 2914|    152|    context = spdm_context;
 2915|    152|    LIBSPDM_ASSERT (context->local_context.capability.max_spdm_msg_size != 0);
 2916|    152|    LIBSPDM_ASSERT (scratch_buffer_size >= libspdm_get_scratch_buffer_capacity(spdm_context));
 2917|    152|    context->scratch_buffer = scratch_buffer;
 2918|    152|    context->scratch_buffer_size = scratch_buffer_size;
 2919|    152|    context->last_spdm_request = (uint8_t *)scratch_buffer +
 2920|    152|                                 libspdm_get_scratch_buffer_last_spdm_request_offset(spdm_context);
 2921|    152|#if LIBSPDM_RESPOND_IF_READY_SUPPORT
 2922|    152|    context->cache_spdm_request = (uint8_t *)scratch_buffer +
 2923|    152|                                  libspdm_get_scratch_buffer_cache_spdm_request_offset(spdm_context);
 2924|    152|#endif
 2925|    152|}
libspdm_init_context_with_secured_context:
 3240|    152|{
 3241|    152|    libspdm_context_t *context;
 3242|    152|    size_t index;
 3243|       |
 3244|    152|    LIBSPDM_ASSERT(spdm_context != NULL);
 3245|    152|    LIBSPDM_ASSERT(secured_contexts != NULL);
 3246|    152|    LIBSPDM_ASSERT(num_secured_contexts == LIBSPDM_MAX_SESSION_COUNT);
 3247|       |
 3248|    152|    context = spdm_context;
 3249|    152|    libspdm_zero_mem(context, sizeof(libspdm_context_t));
 3250|    152|    context->version = LIBSPDM_CONTEXT_STRUCT_VERSION;
  ------------------
  |  |  527|    152|#define LIBSPDM_CONTEXT_STRUCT_VERSION 0x3
  ------------------
 3251|    152|    context->transcript.message_a.max_buffer_size =
 3252|    152|        sizeof(context->transcript.message_a.buffer);
 3253|    152|    context->transcript.message_d.max_buffer_size =
 3254|    152|        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|    152|    context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
 3272|    152|    context->local_context.version.spdm_version_count = SPDM_MAX_VERSION_COUNT;
  ------------------
  |  |   17|    152|#define SPDM_MAX_VERSION_COUNT 4
  ------------------
 3273|    152|    context->local_context.version.spdm_version[0] = SPDM_MESSAGE_VERSION_10 <<
  ------------------
  |  |  110|    152|#define SPDM_MESSAGE_VERSION_10 0x10
  ------------------
 3274|    152|                                                     SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    152|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3275|    152|    context->local_context.version.spdm_version[1] = SPDM_MESSAGE_VERSION_11 <<
  ------------------
  |  |  111|    152|#define SPDM_MESSAGE_VERSION_11 0x11
  ------------------
 3276|    152|                                                     SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    152|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3277|    152|    context->local_context.version.spdm_version[2] = SPDM_MESSAGE_VERSION_12 <<
  ------------------
  |  |  112|    152|#define SPDM_MESSAGE_VERSION_12 0x12
  ------------------
 3278|    152|                                                     SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    152|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3279|    152|    context->local_context.version.spdm_version[3] = SPDM_MESSAGE_VERSION_13 <<
  ------------------
  |  |  113|    152|#define SPDM_MESSAGE_VERSION_13 0x13
  ------------------
 3280|    152|                                                     SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    152|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3281|    152|    context->local_context.secured_message_version.spdm_version_count =
 3282|    152|        SECURED_SPDM_MAX_VERSION_COUNT;
  ------------------
  |  |   55|    152|#define SECURED_SPDM_MAX_VERSION_COUNT 3
  ------------------
 3283|    152|    context->local_context.secured_message_version.spdm_version[0] =
 3284|    152|        SECURED_SPDM_VERSION_10 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |   57|    152|#define SECURED_SPDM_VERSION_10 0x10
  ------------------
                      SECURED_SPDM_VERSION_10 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    152|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3285|    152|    context->local_context.secured_message_version.spdm_version[1] =
 3286|    152|        SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |   58|    152|#define SECURED_SPDM_VERSION_11 0x11
  ------------------
                      SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    152|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3287|    152|    context->local_context.secured_message_version.spdm_version[2] =
 3288|    152|        SECURED_SPDM_VERSION_12 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |   59|    152|#define SECURED_SPDM_VERSION_12 0x12
  ------------------
                      SECURED_SPDM_VERSION_12 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    152|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3289|    152|    context->local_context.capability.st1 = SPDM_ST1_VALUE_US;
  ------------------
  |  | 1514|    152|#define SPDM_ST1_VALUE_US 100000
  ------------------
 3290|       |
 3291|    152|    context->mut_auth_cert_chain_buffer_size = 0;
 3292|       |
 3293|    152|    context->max_spdm_session_sequence_number = LIBSPDM_MAX_SPDM_SESSION_SEQUENCE_NUMBER;
  ------------------
  |  |   39|    152|#define LIBSPDM_MAX_SPDM_SESSION_SEQUENCE_NUMBER 0xFFFFFFFFFFFFFFFFull
  ------------------
 3294|       |
 3295|    152|    context->latest_session_id = INVALID_SESSION_ID;
  ------------------
  |  |   28|    152|#define INVALID_SESSION_ID 0
  ------------------
 3296|    152|    context->last_spdm_request_session_id = INVALID_SESSION_ID;
  ------------------
  |  |   28|    152|#define INVALID_SESSION_ID 0
  ------------------
 3297|    152|    context->last_spdm_request_session_id_valid = false;
 3298|    152|    context->last_spdm_request_size = 0;
 3299|       |
 3300|       |    /* To be updated in libspdm_register_device_buffer_func */
 3301|    152|    context->local_context.capability.data_transfer_size = 0;
 3302|    152|    context->local_context.capability.sender_data_transfer_size = 0;
 3303|    152|    context->local_context.capability.max_spdm_msg_size = 0;
 3304|       |
 3305|    760|    for (index = 0; index < num_secured_contexts; index++) {
  ------------------
  |  Branch (3305:21): [True: 608, False: 152]
  ------------------
 3306|    608|        if (secured_contexts[index] == NULL) {
  ------------------
  |  Branch (3306:13): [True: 0, False: 608]
  ------------------
 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|    608|        context->session_info[index].secured_message_context = secured_contexts[index];
 3311|    608|        libspdm_secured_message_init_context(
 3312|    608|            context->session_info[index].secured_message_context);
 3313|    608|    }
 3314|       |
 3315|    152|    return LIBSPDM_STATUS_SUCCESS;
  ------------------
  |  |   59|    152|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_SUCCESS, LIBSPDM_SOURCE_SUCCESS, 0x0000)
  |  |  ------------------
  |  |  |  |   55|    152|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
 3316|    152|}
libspdm_init_context:
 3331|    152|{
 3332|    152|    libspdm_context_t *context;
 3333|    152|    void *secured_context;
 3334|    152|    void *secured_contexts[LIBSPDM_MAX_SESSION_COUNT];
 3335|    152|    size_t secured_context_size;
 3336|    152|    size_t index;
 3337|       |
 3338|    152|    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|    152|    context = spdm_context;
 3343|    152|    secured_context = (void *)((size_t)(context + 1));
 3344|    152|    secured_context_size = libspdm_secured_message_get_context_size();
 3345|       |
 3346|    760|    for (index = 0; index < LIBSPDM_MAX_SESSION_COUNT; index++)
  ------------------
  |  |  198|    760|#define LIBSPDM_MAX_SESSION_COUNT 4
  ------------------
  |  Branch (3346:21): [True: 608, False: 152]
  ------------------
 3347|    608|    {
 3348|    608|        secured_contexts[index] = (uint8_t *)secured_context + secured_context_size * index;
 3349|    608|    }
 3350|       |
 3351|    152|    return libspdm_init_context_with_secured_context(spdm_context,
 3352|    152|                                                     secured_contexts,
 3353|    152|                                                     LIBSPDM_MAX_SESSION_COUNT);
  ------------------
  |  |  198|    152|#define LIBSPDM_MAX_SESSION_COUNT 4
  ------------------
 3354|    152|}
libspdm_get_context_size:
 3467|    152|{
 3468|    152|    size_t size;
 3469|       |
 3470|    152|    size = sizeof(libspdm_context_t) +
 3471|    152|           libspdm_secured_message_get_context_size() * LIBSPDM_MAX_SESSION_COUNT;
  ------------------
  |  |  198|    152|#define LIBSPDM_MAX_SESSION_COUNT 4
  ------------------
 3472|    152|    LIBSPDM_ASSERT (size == LIBSPDM_CONTEXT_SIZE_ALL);
 3473|    152|    return size;
 3474|    152|}

libspdm_session_info_init:
   18|    152|{
   19|    152|    libspdm_session_type_t session_type;
   20|    152|    uint32_t capabilities_flag;
   21|       |
   22|    152|    if (session_id != INVALID_SESSION_ID) {
  ------------------
  |  |   28|    152|#define INVALID_SESSION_ID 0
  ------------------
  |  Branch (22:9): [True: 152, False: 0]
  ------------------
   23|    152|        if (use_psk) {
  ------------------
  |  Branch (23:13): [True: 152, False: 0]
  ------------------
   24|    152|            LIBSPDM_ASSERT((spdm_context->max_psk_session_count == 0) ||
   25|    152|                           (spdm_context->current_psk_session_count <
   26|    152|                            spdm_context->max_psk_session_count));
   27|    152|            spdm_context->current_psk_session_count++;
   28|    152|        } 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|    152|    } else {
   35|      0|        if (use_psk) {
  ------------------
  |  Branch (35:13): [True: 0, False: 0]
  ------------------
   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|      0|        } else {
   40|      0|            if (spdm_context->current_dhe_session_count > 0) {
  ------------------
  |  Branch (40:17): [True: 0, False: 0]
  ------------------
   41|      0|                spdm_context->current_dhe_session_count--;
   42|      0|            }
   43|      0|        }
   44|      0|    }
   45|       |
   46|    152|    capabilities_flag = spdm_context->connection_info.capability.flags &
   47|    152|                        spdm_context->local_context.capability.flags;
   48|    152|    switch (capabilities_flag &
   49|    152|            (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP |
  ------------------
  |  |  187|    152|#define SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP 0x00000040
  ------------------
   50|    152|             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP)) {
  ------------------
  |  |  188|    152|#define SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP 0x00000080
  ------------------
   51|    152|    case 0:
  ------------------
  |  Branch (51:5): [True: 152, False: 0]
  ------------------
   52|    152|        session_type = LIBSPDM_SESSION_TYPE_NONE;
   53|    152|        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: 152]
  ------------------
   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: 152]
  ------------------
   59|      0|        session_type = LIBSPDM_SESSION_TYPE_MAC_ONLY;
   60|      0|        break;
   61|      0|    default:
  ------------------
  |  Branch (61:5): [True: 0, False: 152]
  ------------------
   62|      0|        LIBSPDM_ASSERT(false);
   63|      0|        session_type = LIBSPDM_SESSION_TYPE_MAX;
   64|      0|        break;
   65|    152|    }
   66|       |
   67|    152|#if !(LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT)
   68|    152|    if (session_info->session_transcript.digest_context_th != NULL) {
  ------------------
  |  Branch (68:9): [True: 0, False: 152]
  ------------------
   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|    152|    if (session_info->session_transcript.digest_context_th_backup != NULL) {
  ------------------
  |  Branch (73:9): [True: 0, False: 152]
  ------------------
   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|    152|#endif
   79|       |
   80|    152|    libspdm_zero_mem (&(session_info->last_key_update_request), sizeof(spdm_key_update_request_t));
   81|    152|    libspdm_zero_mem(session_info, offsetof(libspdm_session_info_t, secured_message_context));
   82|    152|    libspdm_secured_message_init_context(session_info->secured_message_context);
   83|    152|    session_info->session_id = session_id;
   84|    152|    session_info->use_psk = use_psk;
   85|    152|    libspdm_secured_message_set_use_psk(session_info->secured_message_context, use_psk);
   86|    152|    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|    152|    if ((spdm_context->connection_info.secured_message_version >> SPDM_VERSION_NUMBER_SHIFT_BIT) >=
  ------------------
  |  |  140|    152|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
  |  Branch (90:9): [True: 0, False: 152]
  ------------------
   91|    152|        SECURED_SPDM_VERSION_12) {
  ------------------
  |  |   59|    152|#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|    152|    } else {
   96|    152|        libspdm_secured_message_set_sequence_number_endian(session_info->secured_message_context,
   97|    152|                                                           spdm_context->sequence_number_endian);
   98|    152|    }
   99|       |
  100|    152|    libspdm_secured_message_set_max_spdm_session_sequence_number(
  101|    152|        session_info->secured_message_context, spdm_context->max_spdm_session_sequence_number);
  102|    152|    libspdm_secured_message_set_algorithms(
  103|    152|        session_info->secured_message_context,
  104|    152|        spdm_context->connection_info.version,
  105|    152|        spdm_context->connection_info.secured_message_version,
  106|    152|        spdm_context->connection_info.algorithm.base_hash_algo,
  107|    152|        spdm_context->connection_info.algorithm.dhe_named_group,
  108|    152|        spdm_context->connection_info.algorithm.aead_cipher_suite,
  109|    152|        spdm_context->connection_info.algorithm.key_schedule);
  110|    152|    session_info->session_transcript.message_encap_d.max_buffer_size =
  111|    152|        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|    152|}
libspdm_get_session_info_via_session_id:
  147|    152|{
  148|    152|    libspdm_context_t *context;
  149|    152|    libspdm_session_info_t *session_info;
  150|    152|    size_t index;
  151|       |
  152|    152|    if (session_id == INVALID_SESSION_ID) {
  ------------------
  |  |   28|    152|#define INVALID_SESSION_ID 0
  ------------------
  |  Branch (152:9): [True: 0, False: 152]
  ------------------
  153|      0|        LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR,
  154|      0|                       "libspdm_get_session_info_via_session_id - Invalid session_id\n"));
  155|      0|        LIBSPDM_ASSERT(false);
  156|      0|        return NULL;
  157|      0|    }
  158|       |
  159|    152|    context = spdm_context;
  160|       |
  161|    152|    session_info = (libspdm_session_info_t *)context->session_info;
  162|    152|    for (index = 0; index < LIBSPDM_MAX_SESSION_COUNT; index++) {
  ------------------
  |  |  198|    152|#define LIBSPDM_MAX_SESSION_COUNT 4
  ------------------
  |  Branch (162:21): [True: 152, False: 0]
  ------------------
  163|    152|        if (session_info[index].session_id == session_id) {
  ------------------
  |  Branch (163:13): [True: 152, False: 0]
  ------------------
  164|    152|            return &session_info[index];
  165|    152|        }
  166|    152|    }
  167|       |
  168|      0|    LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR,
  169|      0|                   "libspdm_get_session_info_via_session_id - not found session_id\n"));
  170|      0|    return NULL;
  171|    152|}

libspdm_get_aead_key_size:
   10|    152|{
   11|    152|    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: 152]
  ------------------
   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: 152]
  ------------------
   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: 152]
  ------------------
   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: 152]
  ------------------
   31|       |#if LIBSPDM_AEAD_SM4_128_GCM_SUPPORT
   32|       |        return 16;
   33|       |#else
   34|      0|        return 0;
   35|      0|#endif
   36|    152|    default:
  ------------------
  |  Branch (36:5): [True: 152, False: 0]
  ------------------
   37|    152|        return 0;
   38|    152|    }
   39|    152|}
libspdm_get_aead_iv_size:
   42|    152|{
   43|    152|    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: 152]
  ------------------
   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: 152]
  ------------------
   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: 152]
  ------------------
   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: 152]
  ------------------
   63|       |#if LIBSPDM_AEAD_SM4_128_GCM_SUPPORT
   64|       |        return 12;
   65|       |#else
   66|      0|        return 0;
   67|      0|#endif
   68|    152|    default:
  ------------------
  |  Branch (68:5): [True: 152, False: 0]
  ------------------
   69|    152|        return 0;
   70|    152|    }
   71|    152|}
libspdm_get_aead_tag_size:
   74|    152|{
   75|    152|    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: 152]
  ------------------
   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: 152]
  ------------------
   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: 152]
  ------------------
   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: 152]
  ------------------
   95|       |#if LIBSPDM_AEAD_SM4_128_GCM_SUPPORT
   96|       |        return 16;
   97|       |#else
   98|      0|        return 0;
   99|      0|#endif
  100|    152|    default:
  ------------------
  |  Branch (100:5): [True: 152, False: 0]
  ------------------
  101|    152|        return 0;
  102|    152|    }
  103|    152|}

libspdm_get_dhe_pub_key_size:
   17|    152|{
   18|    152|    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: 152]
  ------------------
   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: 152]
  ------------------
   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: 152]
  ------------------
   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: 152]
  ------------------
   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: 152]
  ------------------
   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: 152]
  ------------------
   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: 152]
  ------------------
   56|       |#if LIBSPDM_SM2_KEY_EXCHANGE_P256_SUPPORT
   57|       |        return 32 * 2;
   58|       |#else
   59|      0|        return 0;
   60|      0|#endif
   61|    152|    default:
  ------------------
  |  Branch (61:5): [True: 152, False: 0]
  ------------------
   62|    152|        return 0;
   63|    152|    }
   64|    152|}

libspdm_get_hash_size:
   10|    152|{
   11|    152|    switch (base_hash_algo) {
   12|    152|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
  ------------------
  |  |  391|    152|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256 0x00000001
  ------------------
  |  Branch (12:5): [True: 152, False: 0]
  ------------------
   13|    152|#if LIBSPDM_SHA256_SUPPORT
   14|    152|        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: 152]
  ------------------
   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: 152]
  ------------------
   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: 152]
  ------------------
   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: 152]
  ------------------
   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: 152]
  ------------------
   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: 152]
  ------------------
   49|       |#if LIBSPDM_SM3_256_SUPPORT
   50|       |        return 32;
   51|       |#else
   52|      0|        return 0;
   53|      0|#endif
   54|      0|    default:
  ------------------
  |  Branch (54:5): [True: 0, False: 152]
  ------------------
   55|      0|        return 0;
   56|    152|    }
   57|    152|}

libspdm_generate_error_response:
   14|    106|{
   15|    106|    spdm_error_response_t *spdm_response;
   16|       |
   17|    106|    LIBSPDM_ASSERT(*response_size >= sizeof(spdm_error_response_t));
   18|    106|    *response_size = sizeof(spdm_error_response_t);
   19|    106|    spdm_response = response;
   20|       |
   21|    106|    spdm_response->header.spdm_version = libspdm_get_connection_version (spdm_context);
   22|    106|    if (spdm_response->header.spdm_version == 0) {
  ------------------
  |  Branch (22:9): [True: 0, False: 106]
  ------------------
   23|       |        /* if version is not negotiated, then use default version 1.0 */
   24|      0|        spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
  ------------------
  |  |  110|      0|#define SPDM_MESSAGE_VERSION_10 0x10
  ------------------
   25|      0|    }
   26|    106|    spdm_response->header.request_response_code = SPDM_ERROR;
  ------------------
  |  |   37|    106|#define SPDM_ERROR 0x7F
  ------------------
   27|    106|    spdm_response->header.param1 = error_code;
   28|    106|    spdm_response->header.param2 = error_data;
   29|       |
   30|    106|    if (spdm_response->header.spdm_version <= SPDM_MESSAGE_VERSION_11) {
  ------------------
  |  |  111|    106|#define SPDM_MESSAGE_VERSION_11 0x11
  ------------------
  |  Branch (30:9): [True: 106, False: 0]
  ------------------
   31|    106|        LIBSPDM_ASSERT ((error_code != SPDM_ERROR_CODE_RESPONSE_TOO_LARGE) &&
   32|    106|                        (error_code != SPDM_ERROR_CODE_LARGE_RESPONSE));
   33|    106|    }
   34|       |
   35|    106|    return LIBSPDM_STATUS_SUCCESS;
  ------------------
  |  |   59|    106|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_SUCCESS, LIBSPDM_SOURCE_SUCCESS, 0x0000)
  |  |  ------------------
  |  |  |  |   55|    106|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
   36|    106|}

libspdm_register_vendor_get_id_callback_func:
   16|    152|{
   17|       |
   18|    152|    libspdm_context_t *context = (libspdm_context_t *)spdm_context;
   19|    152|    context->vendor_response_get_id = resp_callback;
   20|    152|    return LIBSPDM_STATUS_SUCCESS;
  ------------------
  |  |   59|    152|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_SUCCESS, LIBSPDM_SOURCE_SUCCESS, 0x0000)
  |  |  ------------------
  |  |  |  |   55|    152|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
   21|    152|}
libspdm_register_vendor_callback_func:
   25|    152|{
   26|       |
   27|    152|    libspdm_context_t *context = (libspdm_context_t *)spdm_context;
   28|    152|    context->vendor_response_callback = resp_callback;
   29|    152|    return LIBSPDM_STATUS_SUCCESS;
  ------------------
  |  |   59|    152|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_SUCCESS, LIBSPDM_SOURCE_SUCCESS, 0x0000)
  |  |  ------------------
  |  |  |  |   55|    152|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
   30|    152|}
libspdm_get_vendor_defined_response:
   37|    152|{
   38|    152|    const spdm_vendor_defined_request_msg_t *spdm_request;
   39|    152|    spdm_vendor_defined_response_msg_t *spdm_response;
   40|    152|    uint16_t header_length;
   41|    152|    size_t response_capacity = 0;
   42|    152|    libspdm_return_t status = LIBSPDM_STATUS_SUCCESS;
  ------------------
  |  |   59|    152|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_SUCCESS, LIBSPDM_SOURCE_SUCCESS, 0x0000)
  |  |  ------------------
  |  |  |  |   55|    152|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
   43|       |
   44|    152|    libspdm_session_info_t *session_info = NULL;
   45|    152|    libspdm_session_state_t session_state = 0;
   46|    152|    const uint32_t *session_id = NULL;
   47|    152|    uint8_t *resp_data = NULL;
   48|    152|    const uint8_t *req_vendor_id;
   49|    152|    const uint8_t *req_data;
   50|    152|    uint16_t resp_size = 0;
   51|    152|    uint16_t req_size = 0;
   52|       |
   53|       |    /* -=[Check Parameters Phase]=- */
   54|    152|    if (request == NULL ||
  ------------------
  |  Branch (54:9): [True: 0, False: 152]
  ------------------
   55|    152|        response == NULL ||
  ------------------
  |  Branch (55:9): [True: 0, False: 152]
  ------------------
   56|    152|        response_size == NULL) {
  ------------------
  |  Branch (56:9): [True: 0, False: 152]
  ------------------
   57|      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)))
  |  |  ------------------
  ------------------
   58|      0|    }
   59|       |
   60|    152|    if (spdm_context->last_spdm_request_session_id_valid) {
  ------------------
  |  Branch (60:9): [True: 152, False: 0]
  ------------------
   61|    152|        session_info = libspdm_get_session_info_via_session_id(
   62|    152|            spdm_context,
   63|    152|            spdm_context->last_spdm_request_session_id);
   64|    152|        if (session_info == NULL) {
  ------------------
  |  Branch (64:13): [True: 0, False: 152]
  ------------------
   65|      0|            return libspdm_generate_error_response(
   66|      0|                spdm_context,
   67|      0|                SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
  ------------------
  |  |  857|      0|#define SPDM_ERROR_CODE_UNEXPECTED_REQUEST 0x04
  ------------------
   68|      0|                response_size, response);
   69|      0|        }
   70|    152|        session_state = libspdm_secured_message_get_session_state(
   71|    152|            session_info->secured_message_context);
   72|    152|        if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) {
  ------------------
  |  Branch (72:13): [True: 0, False: 152]
  ------------------
   73|      0|            return libspdm_generate_error_response(
   74|      0|                spdm_context,
   75|      0|                SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
  ------------------
  |  |  857|      0|#define SPDM_ERROR_CODE_UNEXPECTED_REQUEST 0x04
  ------------------
   76|      0|                response_size, response);
   77|      0|        }
   78|    152|        session_id = &session_info->session_id;
   79|    152|    }
   80|       |
   81|       |    /* Check if caller is using the old Vendor Defined API. */
   82|    152|    if ((spdm_context->vendor_response_callback == NULL ||
  ------------------
  |  Branch (82:10): [True: 0, False: 152]
  ------------------
   83|    152|         spdm_context->vendor_response_get_id == NULL)) {
  ------------------
  |  Branch (83:10): [True: 0, False: 152]
  ------------------
   84|      0|        if (spdm_context->get_response_func != NULL) {
  ------------------
  |  Branch (84:13): [True: 0, False: 0]
  ------------------
   85|      0|            return ((libspdm_get_response_func)spdm_context->get_response_func)(
   86|      0|                spdm_context,
   87|      0|                session_id,
   88|      0|                false,
   89|      0|                request_size,
   90|      0|                request,
   91|      0|                response_size,
   92|      0|                response);
   93|      0|        } else
   94|      0|            return libspdm_generate_error_response(spdm_context,
   95|      0|                                                   SPDM_ERROR_CODE_UNSUPPORTED_REQUEST,
  ------------------
  |  |  859|      0|#define SPDM_ERROR_CODE_UNSUPPORTED_REQUEST 0x07
  ------------------
   96|      0|                                                   SPDM_VENDOR_DEFINED_REQUEST,
  ------------------
  |  |   73|      0|#define SPDM_VENDOR_DEFINED_REQUEST 0xFE
  ------------------
   97|      0|                                                   response_size, response);
   98|      0|    }
   99|       |
  100|    152|    spdm_request = request;
  101|       |
  102|    152|    if (spdm_request->header.spdm_version != libspdm_get_connection_version(spdm_context)) {
  ------------------
  |  Branch (102:9): [True: 63, False: 89]
  ------------------
  103|     63|        return libspdm_generate_error_response(spdm_context,
  104|     63|                                               SPDM_ERROR_CODE_VERSION_MISMATCH, 0,
  ------------------
  |  |  860|     63|#define SPDM_ERROR_CODE_VERSION_MISMATCH 0x41
  ------------------
  105|     63|                                               response_size, response);
  106|     63|    }
  107|     89|    if (spdm_context->response_state != LIBSPDM_RESPONSE_STATE_NORMAL) {
  ------------------
  |  Branch (107:9): [True: 0, False: 89]
  ------------------
  108|      0|        return libspdm_responder_handle_response_state(
  109|      0|            spdm_context,
  110|      0|            spdm_request->header.request_response_code,
  111|      0|            response_size, response);
  112|      0|    }
  113|     89|    if (spdm_context->connection_info.connection_state < LIBSPDM_CONNECTION_STATE_NEGOTIATED) {
  ------------------
  |  Branch (113:9): [True: 0, False: 89]
  ------------------
  114|      0|        return libspdm_generate_error_response(spdm_context,
  115|      0|                                               SPDM_ERROR_CODE_UNEXPECTED_REQUEST,
  ------------------
  |  |  857|      0|#define SPDM_ERROR_CODE_UNEXPECTED_REQUEST 0x04
  ------------------
  116|      0|                                               0, response_size, response);
  117|      0|    }
  118|       |
  119|     89|    if (request_size < sizeof(spdm_vendor_defined_request_msg_t)) {
  ------------------
  |  Branch (119:9): [True: 1, False: 88]
  ------------------
  120|      1|        return libspdm_generate_error_response(spdm_context,
  121|      1|                                               SPDM_ERROR_CODE_INVALID_REQUEST, 0,
  ------------------
  |  |  855|      1|#define SPDM_ERROR_CODE_INVALID_REQUEST 0x01
  ------------------
  122|      1|                                               response_size, response);
  123|      1|    }
  124|     88|    if (request_size < sizeof(spdm_vendor_defined_request_msg_t) +
  ------------------
  |  Branch (124:9): [True: 11, False: 77]
  ------------------
  125|     88|        spdm_request->len + sizeof(uint16_t)) {
  126|     11|        return libspdm_generate_error_response(spdm_context,
  127|     11|                                               SPDM_ERROR_CODE_INVALID_REQUEST, 0,
  ------------------
  |  |  855|     11|#define SPDM_ERROR_CODE_INVALID_REQUEST 0x01
  ------------------
  128|     11|                                               response_size, response);
  129|     11|    }
  130|       |
  131|     77|    req_vendor_id = ((const uint8_t *)request) + sizeof(spdm_vendor_defined_request_msg_t);
  132|     77|    req_size = *(const uint16_t *)(req_vendor_id + spdm_request->len);
  133|       |
  134|     77|    if (request_size < sizeof(spdm_vendor_defined_request_msg_t) +
  ------------------
  |  Branch (134:9): [True: 31, False: 46]
  ------------------
  135|     77|        spdm_request->len + sizeof(uint16_t) + req_size) {
  136|     31|        return libspdm_generate_error_response(spdm_context,
  137|     31|                                               SPDM_ERROR_CODE_INVALID_REQUEST, 0,
  ------------------
  |  |  855|     31|#define SPDM_ERROR_CODE_INVALID_REQUEST 0x01
  ------------------
  138|     31|                                               response_size, response);
  139|     31|    }
  140|       |
  141|     46|    libspdm_reset_message_buffer_via_request_code(spdm_context, NULL,
  142|     46|                                                  spdm_request->header.request_response_code);
  143|       |
  144|       |    /* length of spdm request/response header before payload start */
  145|     46|    header_length = sizeof(spdm_vendor_defined_response_msg_t) + spdm_request->len +
  146|     46|                    sizeof(uint16_t);
  147|       |
  148|     46|    LIBSPDM_ASSERT(*response_size >= header_length);
  149|     46|    LIBSPDM_ASSERT(
  150|     46|        sizeof(spdm_vendor_defined_response_msg_t) == SPDM_VENDOR_DEFINED_FIXED_HEADER_LEN);
  151|     46|    response_capacity = *response_size - header_length;
  152|     46|    libspdm_zero_mem(response, header_length);
  153|     46|    spdm_response = response;
  154|       |
  155|     46|    spdm_response->header.spdm_version = spdm_request->header.spdm_version;
  156|     46|    spdm_response->header.request_response_code = SPDM_VENDOR_DEFINED_RESPONSE;
  ------------------
  |  |   36|     46|#define SPDM_VENDOR_DEFINED_RESPONSE 0x7E
  ------------------
  157|     46|    spdm_response->header.param1 = 0;
  158|     46|    spdm_response->header.param2 = 0;
  159|       |
  160|       |    /* SPDM Response format
  161|       |     *  1 byte SPDMVersion
  162|       |     *  1 byte RequestResponseCode
  163|       |     *  2 bytes Reserved
  164|       |     *  2 bytes StandardID
  165|       |     *  1 bytes VendorID Length Len1, based on StandardID
  166|       |     *  Len1 bytes VendorID
  167|       |     *  2 bytes Response Length Len2
  168|       |     *  Len2 bytes Response Payload
  169|       |     */
  170|       |
  171|       |    /* replace capacity with size */
  172|     46|    spdm_response->len = SPDM_MAX_VENDOR_ID_LENGTH;
  ------------------
  |  |  923|     46|#define SPDM_MAX_VENDOR_ID_LENGTH 255
  ------------------
  173|     46|    resp_data = ((uint8_t *)response) + sizeof(spdm_vendor_defined_response_msg_t);
  174|       |
  175|     46|    req_data = ((const uint8_t *)request) +
  176|     46|               sizeof(spdm_vendor_defined_request_msg_t) +
  177|     46|               ((const spdm_vendor_defined_request_msg_t*)request)->len +
  178|     46|               sizeof(uint16_t);
  179|       |
  180|     46|    status = spdm_context->vendor_response_get_id(
  181|     46|        spdm_context,
  182|       |#if LIBSPDM_PASS_SESSION_ID
  183|       |        session_id,
  184|       |#endif
  185|     46|        &spdm_response->standard_id,
  186|     46|        &spdm_response->len,
  187|     46|        resp_data);
  188|       |
  189|       |    /* move pointer and adjust buffer size */
  190|     46|    resp_data += spdm_response->len + sizeof(uint16_t);
  191|     46|    response_capacity -= spdm_response->len + sizeof(uint16_t);
  192|     46|    resp_size = (uint16_t)response_capacity;
  193|       |
  194|     46|    status = spdm_context->vendor_response_callback(spdm_context,
  195|       |                                                #if LIBSPDM_PASS_SESSION_ID
  196|       |                                                    session_id,
  197|       |                                                #endif
  198|     46|                                                    spdm_request->standard_id,
  199|     46|                                                    spdm_request->len,
  200|     46|                                                    req_vendor_id, req_size, req_data,
  201|     46|                                                    &resp_size,
  202|     46|                                                    resp_data);
  203|       |
  204|       |    /* store back the response payload size */
  205|     46|    *((uint16_t*)(resp_data - sizeof(uint16_t))) = resp_size;
  206|     46|    *response_size = resp_size + (size_t)header_length;
  207|       |
  208|     46|    LIBSPDM_ASSERT(sizeof(spdm_vendor_defined_request_msg_t) ==
  209|     46|                   SPDM_VENDOR_DEFINED_FIXED_HEADER_LEN);
  210|       |
  211|     46|    return status;
  212|     77|}

libspdm_secured_message_get_context_size:
   15|    304|{
   16|    304|    return sizeof(libspdm_secured_message_context_t);
   17|    304|}
libspdm_secured_message_init_context:
   27|    760|{
   28|    760|    libspdm_secured_message_context_t *secured_message_context;
   29|       |
   30|    760|    secured_message_context = spdm_secured_message_context;
   31|    760|    libspdm_zero_mem(secured_message_context, sizeof(libspdm_secured_message_context_t));
   32|    760|}
libspdm_secured_message_set_use_psk:
   41|    152|{
   42|    152|    libspdm_secured_message_context_t *secured_message_context;
   43|       |
   44|    152|    secured_message_context = spdm_secured_message_context;
   45|    152|    secured_message_context->use_psk = use_psk;
   46|    152|}
libspdm_secured_message_set_session_state:
   57|    152|{
   58|    152|    libspdm_secured_message_context_t *secured_message_context;
   59|       |
   60|    152|    secured_message_context = spdm_secured_message_context;
   61|    152|    secured_message_context->session_state = session_state;
   62|       |
   63|    152|    if (session_state == LIBSPDM_SESSION_STATE_ESTABLISHED) {
  ------------------
  |  Branch (63:9): [True: 152, False: 0]
  ------------------
   64|       |        /* session handshake key should be zeroized after handshake phase. */
   65|    152|        libspdm_clear_handshake_secret(secured_message_context);
   66|    152|        libspdm_clear_master_secret(secured_message_context);
   67|    152|    }
   68|    152|}
libspdm_secured_message_get_session_state:
   79|    152|{
   80|    152|    libspdm_secured_message_context_t *secured_message_context;
   81|       |
   82|    152|    secured_message_context = spdm_secured_message_context;
   83|    152|    return secured_message_context->session_state;
   84|    152|}
libspdm_secured_message_set_session_type:
   94|    152|{
   95|    152|    libspdm_secured_message_context_t *secured_message_context;
   96|       |
   97|    152|    secured_message_context = spdm_secured_message_context;
   98|    152|    secured_message_context->session_type = session_type;
   99|    152|}
libspdm_secured_message_set_algorithms:
  117|    152|{
  118|    152|    libspdm_secured_message_context_t *secured_message_context;
  119|       |
  120|    152|    secured_message_context = spdm_secured_message_context;
  121|    152|    secured_message_context->version = version;
  122|    152|    secured_message_context->secured_message_version = secured_message_version;
  123|    152|    secured_message_context->base_hash_algo = base_hash_algo;
  124|    152|    secured_message_context->dhe_named_group = dhe_named_group;
  125|    152|    secured_message_context->aead_cipher_suite = aead_cipher_suite;
  126|    152|    secured_message_context->key_schedule = key_schedule;
  127|       |
  128|    152|    secured_message_context->hash_size =
  129|    152|        libspdm_get_hash_size(secured_message_context->base_hash_algo);
  130|    152|    secured_message_context->dhe_key_size = libspdm_get_dhe_pub_key_size(
  131|    152|        secured_message_context->dhe_named_group);
  132|    152|    secured_message_context->aead_key_size = libspdm_get_aead_key_size(
  133|    152|        secured_message_context->aead_cipher_suite);
  134|    152|    secured_message_context->aead_iv_size = libspdm_get_aead_iv_size(
  135|    152|        secured_message_context->aead_cipher_suite);
  136|    152|    secured_message_context->aead_tag_size = libspdm_get_aead_tag_size(
  137|    152|        secured_message_context->aead_cipher_suite);
  138|    152|}
libspdm_secured_message_set_max_spdm_session_sequence_number:
  167|    152|{
  168|    152|    libspdm_secured_message_context_t *secured_message_context;
  169|       |
  170|    152|    secured_message_context = spdm_secured_message_context;
  171|    152|    secured_message_context->max_spdm_session_sequence_number = max_spdm_session_sequence_number;
  172|    152|}
libspdm_secured_message_set_sequence_number_endian:
  177|    152|{
  178|    152|    libspdm_secured_message_context_t *secured_message_context;
  179|       |
  180|    152|    secured_message_context = spdm_secured_message_context;
  181|    152|    secured_message_context->sequence_number_endian = endian_value;
  182|    152|}

libspdm_clear_handshake_secret:
  708|    152|{
  709|    152|    libspdm_secured_message_context_t *secured_message_context;
  710|       |
  711|    152|    secured_message_context = spdm_secured_message_context;
  712|       |
  713|    152|    libspdm_zero_mem(secured_message_context->master_secret.handshake_secret,
  714|    152|                     LIBSPDM_MAX_HASH_SIZE);
  ------------------
  |  |   65|    152|#define LIBSPDM_MAX_HASH_SIZE 64
  ------------------
  715|    152|    libspdm_zero_mem(&(secured_message_context->handshake_secret),
  716|    152|                     sizeof(libspdm_session_info_struct_handshake_secret_t));
  717|       |
  718|    152|    secured_message_context->requester_backup_valid = false;
  719|    152|    secured_message_context->responder_backup_valid = false;
  720|    152|}
libspdm_clear_master_secret:
  723|    152|{
  724|    152|    libspdm_secured_message_context_t *secured_message_context;
  725|       |
  726|    152|    secured_message_context = spdm_secured_message_context;
  727|       |
  728|    152|    libspdm_zero_mem(secured_message_context->master_secret.master_secret, LIBSPDM_MAX_HASH_SIZE);
  ------------------
  |  |   65|    152|#define LIBSPDM_MAX_HASH_SIZE 64
  ------------------
  729|    152|}

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

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

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

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

libspdm_alignment_size:
   21|    152|{
   22|    152|    size_t alignment;
   23|    152|    size_t max_buffer_size;
   24|       |
   25|    152|    alignment = LIBSPDM_TEST_ALIGNMENT;
  ------------------
  |  |   15|    152|#define LIBSPDM_TEST_ALIGNMENT 4
  ------------------
   26|    152|    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|    152|    if ((size > max_buffer_size - alignment) && (size & (alignment - 1)) != 0) {
  ------------------
  |  Branch (29:9): [True: 38, False: 114]
  |  Branch (29:49): [True: 3, False: 35]
  ------------------
   30|      3|        size -= alignment;
   31|      3|    }
   32|       |
   33|    152|    if (((size) & (alignment - 1)) == 3) {
  ------------------
  |  Branch (33:9): [True: 23, False: 129]
  ------------------
   34|     23|        size += 1;
   35|     23|    }
   36|    152|    if (((size) & (alignment - 1)) == 2) {
  ------------------
  |  Branch (36:9): [True: 2, False: 150]
  ------------------
   37|      2|        size += 2;
   38|      2|    }
   39|    152|    if (((size) & (alignment - 1)) == 1) {
  ------------------
  |  Branch (39:9): [True: 79, False: 73]
  ------------------
   40|     79|        size += 3;
   41|     79|    }
   42|    152|    return size;
   43|    152|}
LLVMFuzzerTestOneInput:
  112|    152|{
  113|    152|    void *test_buffer;
  114|    152|    size_t max_buffer_size;
  115|       |
  116|       |    /* 1. Initialize test_buffer*/
  117|    152|    max_buffer_size = libspdm_get_max_buffer_size();
  118|    152|    test_buffer = allocate_zero_pool(max_buffer_size);
  119|    152|    if (test_buffer == NULL) {
  ------------------
  |  Branch (119:9): [True: 0, False: 152]
  ------------------
  120|      0|        return 0;
  121|      0|    }
  122|    152|    if (size == 0) {
  ------------------
  |  Branch (122:9): [True: 0, False: 152]
  ------------------
  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|    152|    if (size > max_buffer_size) {
  ------------------
  |  Branch (127:9): [True: 34, False: 118]
  ------------------
  128|     34|        size = max_buffer_size;
  129|    118|    } else {
  130|    118|        libspdm_copy_mem(test_buffer, max_buffer_size, data, size);
  131|    118|    }
  132|    152|    size = libspdm_alignment_size(size);
  133|       |    /* 2. Run test*/
  134|    152|    libspdm_run_test_harness(test_buffer, size);
  135|       |    /* 3. Clean up*/
  136|    152|    free(test_buffer);
  137|    152|    return 0;
  138|    152|}

libspdm_get_max_buffer_size:
   14|    304|{
   15|    304|    return LIBSPDM_MAX_SPDM_MSG_SIZE;
  ------------------
  |  |  101|    304|#define LIBSPDM_MAX_SPDM_MSG_SIZE 0x1200
  ------------------
   16|    304|}
libspdm_vendor_get_id_func_test:
   26|     46|{
   27|     46|    return LIBSPDM_STATUS_SUCCESS;
  ------------------
  |  |   59|     46|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_SUCCESS, LIBSPDM_SOURCE_SUCCESS, 0x0000)
  |  |  ------------------
  |  |  |  |   55|     46|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
   28|     46|}
libspdm_vendor_response_func_test:
   42|     46|{
   43|     46|    return LIBSPDM_STATUS_SUCCESS;
  ------------------
  |  |   59|     46|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_SUCCESS, LIBSPDM_SOURCE_SUCCESS, 0x0000)
  |  |  ------------------
  |  |  |  |   55|     46|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
   44|     46|}
libspdm_test_responder_vendor_cmds_case1:
   47|    152|{
   48|    152|    libspdm_test_context_t *spdm_test_context;
   49|    152|    libspdm_context_t *spdm_context;
   50|    152|    size_t response_size;
   51|    152|    uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
   52|    152|    libspdm_session_info_t *session_info;
   53|    152|    uint32_t session_id;
   54|       |
   55|    152|    spdm_test_context = *State;
   56|    152|    spdm_context = spdm_test_context->spdm_context;
   57|    152|    spdm_context->connection_info.algorithm.base_hash_algo =
   58|    152|        SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256;
  ------------------
  |  |  391|    152|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256 0x00000001
  ------------------
   59|       |
   60|    152|    spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
  ------------------
  |  |  110|    152|#define SPDM_MESSAGE_VERSION_10 0x10
  ------------------
   61|    152|                                            SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    152|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
   62|    152|    spdm_context->connection_info.connection_state =
   63|    152|        LIBSPDM_CONNECTION_STATE_NEGOTIATED;
   64|    152|    spdm_context->local_context.is_requester = true;
   65|       |
   66|    152|    libspdm_register_vendor_get_id_callback_func(spdm_context,
   67|    152|                                                 libspdm_vendor_get_id_func_test);
   68|    152|    libspdm_register_vendor_callback_func(spdm_context,
   69|    152|                                          libspdm_vendor_response_func_test);
   70|       |
   71|    152|    session_id = 0xFFFFFFFF;
   72|    152|    spdm_context->latest_session_id = session_id;
   73|    152|    spdm_context->last_spdm_request_session_id_valid = true;
   74|    152|    spdm_context->last_spdm_request_session_id = session_id;
   75|    152|    session_info = &spdm_context->session_info[0];
   76|    152|    libspdm_session_info_init(spdm_context, session_info, session_id, true);
   77|    152|    libspdm_secured_message_set_session_state(
   78|    152|        session_info->secured_message_context,
   79|    152|        LIBSPDM_SESSION_STATE_ESTABLISHED);
   80|       |
   81|    152|    response_size = sizeof(response);
   82|    152|    libspdm_get_vendor_defined_response(spdm_context,
   83|    152|                                        spdm_test_context->test_buffer_size,
   84|    152|                                        spdm_test_context->test_buffer,
   85|    152|                                        &response_size, response);
   86|    152|}
libspdm_run_test_harness:
   94|    152|{
   95|    152|    void *State;
   96|    152|    libspdm_setup_test_context(&m_libspdm_responder_vendor_cmds_test_context);
   97|       |
   98|    152|    m_libspdm_responder_vendor_cmds_test_context.test_buffer = test_buffer;
   99|    152|    m_libspdm_responder_vendor_cmds_test_context.test_buffer_size =
  100|    152|        test_buffer_size;
  101|       |
  102|       |    /* Success Case*/
  103|    152|    libspdm_unit_test_group_setup(&State);
  104|    152|    libspdm_test_responder_vendor_cmds_case1(&State);
  105|    152|    libspdm_unit_test_group_teardown(&State);
  106|    152|}

