libspdm_get_scratch_buffer_secure_message_capacity:
   17|    942|uint32_t libspdm_get_scratch_buffer_secure_message_capacity(libspdm_context_t *spdm_context) {
   18|    942|    return spdm_context->local_context.capability.max_spdm_msg_size +
   19|    942|           spdm_context->local_context.capability.transport_header_size +
   20|    942|           spdm_context->local_context.capability.transport_tail_size;
   21|    942|}
libspdm_get_scratch_buffer_large_message_capacity:
   28|    942|uint32_t libspdm_get_scratch_buffer_large_message_capacity(libspdm_context_t *spdm_context) {
   29|    942|    return spdm_context->local_context.capability.max_spdm_msg_size;
   30|    942|}
libspdm_get_scratch_buffer_sender_receiver_capacity:
   43|    942|uint32_t libspdm_get_scratch_buffer_sender_receiver_capacity(libspdm_context_t *spdm_context) {
   44|    942|    return spdm_context->local_context.capability.max_spdm_msg_size +
   45|    942|           spdm_context->local_context.capability.transport_header_size +
   46|    942|           spdm_context->local_context.capability.transport_tail_size;
   47|    942|}
libspdm_get_scratch_buffer_large_sender_receiver_capacity:
   58|    942|{
   59|    942|    return spdm_context->local_context.capability.max_spdm_msg_size +
   60|    942|           spdm_context->local_context.capability.transport_header_size +
   61|    942|           spdm_context->local_context.capability.transport_tail_size;
   62|    942|}
libspdm_get_scratch_buffer_last_spdm_request_offset:
   66|    314|uint32_t libspdm_get_scratch_buffer_last_spdm_request_offset(libspdm_context_t *spdm_context) {
   67|    314|    return 0 +
   68|    314|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
   69|    314|           libspdm_get_scratch_buffer_secure_message_capacity(spdm_context) +
   70|    314|           libspdm_get_scratch_buffer_large_message_capacity(spdm_context) +
   71|    314|#endif
   72|    314|           libspdm_get_scratch_buffer_sender_receiver_capacity(spdm_context) +
   73|    314|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
   74|    314|           libspdm_get_scratch_buffer_large_sender_receiver_capacity(spdm_context) +
   75|    314|#endif
   76|    314|           0;
   77|    314|}
libspdm_get_scratch_buffer_last_spdm_request_capacity:
   79|    628|uint32_t libspdm_get_scratch_buffer_last_spdm_request_capacity(libspdm_context_t *spdm_context) {
   80|    628|    return spdm_context->local_context.capability.max_spdm_msg_size;
   81|    628|}
libspdm_get_scratch_buffer_cache_spdm_request_offset:
   85|    314|uint32_t libspdm_get_scratch_buffer_cache_spdm_request_offset(libspdm_context_t *spdm_context) {
   86|    314|    return 0 +
   87|    314|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
   88|    314|           libspdm_get_scratch_buffer_secure_message_capacity(spdm_context) +
   89|    314|           libspdm_get_scratch_buffer_large_message_capacity(spdm_context) +
   90|    314|#endif
   91|    314|           libspdm_get_scratch_buffer_sender_receiver_capacity(spdm_context) +
   92|    314|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
   93|    314|           libspdm_get_scratch_buffer_large_sender_receiver_capacity(spdm_context) +
   94|    314|#endif
   95|    314|           libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context) +
   96|    314|           0;
   97|    314|}
libspdm_get_scratch_buffer_cache_spdm_request_capacity:
   99|    314|uint32_t libspdm_get_scratch_buffer_cache_spdm_request_capacity(libspdm_context_t *spdm_context) {
  100|    314|    return spdm_context->local_context.capability.max_spdm_msg_size;
  101|    314|}
libspdm_get_scratch_buffer_capacity:
  105|    314|uint32_t libspdm_get_scratch_buffer_capacity(libspdm_context_t *spdm_context) {
  106|    314|    return 0 +
  107|    314|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
  108|    314|           libspdm_get_scratch_buffer_secure_message_capacity(spdm_context) +
  109|    314|           libspdm_get_scratch_buffer_large_message_capacity(spdm_context) +
  110|    314|#endif
  111|    314|           libspdm_get_scratch_buffer_sender_receiver_capacity(spdm_context) +
  112|    314|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
  113|    314|           libspdm_get_scratch_buffer_large_sender_receiver_capacity(spdm_context) +
  114|    314|#endif
  115|    314|           libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context) +
  116|    314|#if LIBSPDM_RESPOND_IF_READY_SUPPORT
  117|    314|           libspdm_get_scratch_buffer_cache_spdm_request_capacity(spdm_context) +
  118|    314|#endif
  119|    314|           0;
  120|    314|}
libspdm_reset_message_b:
 1280|    157|{
 1281|       |#if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
 1282|       |    libspdm_reset_managed_buffer(&spdm_context->transcript.message_b);
 1283|       |#else
 1284|    157|    if (spdm_context->transcript.digest_context_m1m2 != NULL) {
  ------------------
  |  Branch (1284:9): [True: 0, False: 157]
  ------------------
 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|    157|#endif
 1290|    157|}
libspdm_reset_message_mut_c:
 1334|    314|{
 1335|       |#if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
 1336|       |    libspdm_reset_managed_buffer(&spdm_context->transcript.message_mut_c);
 1337|       |#else
 1338|    314|    if (spdm_context->transcript.digest_context_mut_m1m2 != NULL) {
  ------------------
  |  Branch (1338:9): [True: 199, False: 115]
  ------------------
 1339|    199|        libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
 1340|    199|                           spdm_context->transcript.digest_context_mut_m1m2);
 1341|    199|        spdm_context->transcript.digest_context_mut_m1m2 = NULL;
 1342|    199|    }
 1343|    314|#endif
 1344|    314|}
libspdm_reset_message_m:
 1355|    157|{
 1356|    157|    libspdm_session_info_t *spdm_session_info;
 1357|       |
 1358|    157|    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|    157|    if (spdm_session_info == NULL) {
  ------------------
  |  Branch (1366:9): [True: 157, False: 0]
  ------------------
 1367|    157|        if (spdm_context->transcript.digest_context_l1l2 != NULL) {
  ------------------
  |  Branch (1367:13): [True: 0, False: 157]
  ------------------
 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|    157|    } 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|    157|#endif
 1380|    157|}
libspdm_reset_message_buffer_via_request_code:
 1533|    157|{
 1534|    157|    libspdm_context_t *spdm_context;
 1535|       |
 1536|    157|    spdm_context = context;
 1537|       |    /**
 1538|       |     * Any request other than SPDM_GET_MEASUREMENTS resets L1/L2
 1539|       |     */
 1540|    157|    if (request_code != SPDM_GET_MEASUREMENTS) {
  ------------------
  |  |   70|    157|#define SPDM_GET_MEASUREMENTS 0xE0
  ------------------
  |  Branch (1540:9): [True: 157, False: 0]
  ------------------
 1541|    157|        libspdm_reset_message_m(spdm_context, session_info);
 1542|    157|    }
 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|    157|    switch (request_code)
 1549|    157|    {
 1550|      0|    case SPDM_KEY_EXCHANGE:
  ------------------
  |  |   77|      0|#define SPDM_KEY_EXCHANGE 0xE4
  ------------------
  |  Branch (1550:5): [True: 0, False: 157]
  ------------------
 1551|      0|    case SPDM_GET_MEASUREMENTS:
  ------------------
  |  |   70|      0|#define SPDM_GET_MEASUREMENTS 0xE0
  ------------------
  |  Branch (1551:5): [True: 0, False: 157]
  ------------------
 1552|      0|    case SPDM_FINISH:
  ------------------
  |  |   78|      0|#define SPDM_FINISH 0xE5
  ------------------
  |  Branch (1552:5): [True: 0, False: 157]
  ------------------
 1553|      0|    case SPDM_PSK_EXCHANGE:
  ------------------
  |  |   79|      0|#define SPDM_PSK_EXCHANGE 0xE6
  ------------------
  |  Branch (1553:5): [True: 0, False: 157]
  ------------------
 1554|      0|    case SPDM_PSK_FINISH:
  ------------------
  |  |   80|      0|#define SPDM_PSK_FINISH 0xE7
  ------------------
  |  Branch (1554:5): [True: 0, False: 157]
  ------------------
 1555|      0|    case SPDM_KEY_UPDATE:
  ------------------
  |  |   82|      0|#define SPDM_KEY_UPDATE 0xE9
  ------------------
  |  Branch (1555:5): [True: 0, False: 157]
  ------------------
 1556|      0|    case SPDM_HEARTBEAT:
  ------------------
  |  |   81|      0|#define SPDM_HEARTBEAT 0xE8
  ------------------
  |  Branch (1556:5): [True: 0, False: 157]
  ------------------
 1557|      0|    case SPDM_GET_ENCAPSULATED_REQUEST:
  ------------------
  |  |   83|      0|#define SPDM_GET_ENCAPSULATED_REQUEST 0xEA
  ------------------
  |  Branch (1557:5): [True: 0, False: 157]
  ------------------
 1558|      0|    case SPDM_END_SESSION:
  ------------------
  |  |   85|      0|#define SPDM_END_SESSION 0xEC
  ------------------
  |  Branch (1558:5): [True: 0, False: 157]
  ------------------
 1559|      0|    case SPDM_GET_MEASUREMENT_EXTENSION_LOG:
  ------------------
  |  |   98|      0|#define SPDM_GET_MEASUREMENT_EXTENSION_LOG 0xEF
  ------------------
  |  Branch (1559:5): [True: 0, False: 157]
  ------------------
 1560|      0|        if (spdm_context->connection_info.connection_state <
  ------------------
  |  Branch (1560:13): [True: 0, False: 0]
  ------------------
 1561|      0|            LIBSPDM_CONNECTION_STATE_AUTHENTICATED) {
 1562|      0|            libspdm_reset_message_b(spdm_context);
 1563|      0|            libspdm_reset_message_c(spdm_context);
 1564|      0|            libspdm_reset_message_mut_b(spdm_context);
 1565|      0|            libspdm_reset_message_mut_c(spdm_context);
 1566|      0|        }
 1567|      0|        break;
 1568|      0|    case SPDM_DELIVER_ENCAPSULATED_RESPONSE:
  ------------------
  |  |   84|      0|#define SPDM_DELIVER_ENCAPSULATED_RESPONSE 0xEB
  ------------------
  |  Branch (1568:5): [True: 0, False: 157]
  ------------------
 1569|      0|        if (spdm_context->connection_info.connection_state <
  ------------------
  |  Branch (1569:13): [True: 0, False: 0]
  ------------------
 1570|      0|            LIBSPDM_CONNECTION_STATE_AUTHENTICATED) {
 1571|      0|            libspdm_reset_message_b(spdm_context);
 1572|      0|            libspdm_reset_message_c(spdm_context);
 1573|      0|        }
 1574|      0|        break;
 1575|      0|    case SPDM_GET_DIGESTS:
  ------------------
  |  |   66|      0|#define SPDM_GET_DIGESTS 0x81
  ------------------
  |  Branch (1575:5): [True: 0, False: 157]
  ------------------
 1576|      0|        libspdm_reset_message_b(spdm_context);
 1577|      0|        break;
 1578|      0|    case SPDM_GET_ENDPOINT_INFO:
  ------------------
  |  |   94|      0|#define SPDM_GET_ENDPOINT_INFO 0x87
  ------------------
  |  Branch (1578:5): [True: 0, False: 157]
  ------------------
 1579|      0|        libspdm_reset_message_e(spdm_context, session_info);
 1580|      0|        libspdm_reset_message_encap_e(spdm_context, session_info);
 1581|      0|        break;
 1582|    157|    default:
  ------------------
  |  Branch (1582:5): [True: 157, False: 0]
  ------------------
 1583|    157|        break;
 1584|    157|    }
 1585|    157|}
libspdm_append_message_mut_b:
 1762|    199|{
 1763|       |#if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
 1764|       |    return libspdm_append_managed_buffer(&spdm_context->transcript.message_mut_b,
 1765|       |                                         message, message_size);
 1766|       |#else
 1767|    199|    {
 1768|    199|        bool result;
 1769|       |
 1770|    199|        if (spdm_context->transcript.digest_context_mut_m1m2 == NULL) {
  ------------------
  |  Branch (1770:13): [True: 199, False: 0]
  ------------------
 1771|    199|            spdm_context->transcript.digest_context_mut_m1m2 = libspdm_hash_new (
 1772|    199|                spdm_context->connection_info.algorithm.base_hash_algo);
 1773|    199|            if (spdm_context->transcript.digest_context_mut_m1m2 == NULL) {
  ------------------
  |  Branch (1773:17): [True: 0, False: 199]
  ------------------
 1774|      0|                return LIBSPDM_STATUS_CRYPTO_ERROR;
  ------------------
  |  |  156|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CRYPTO, 0x0000)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
 1775|      0|            }
 1776|    199|            result = libspdm_hash_init (spdm_context->connection_info.algorithm.base_hash_algo,
 1777|    199|                                        spdm_context->transcript.digest_context_mut_m1m2);
 1778|    199|            if (!result) {
  ------------------
  |  Branch (1778:17): [True: 0, False: 199]
  ------------------
 1779|      0|                libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
 1780|      0|                                   spdm_context->transcript.digest_context_mut_m1m2);
 1781|      0|                spdm_context->transcript.digest_context_mut_m1m2 = NULL;
 1782|      0|                return LIBSPDM_STATUS_CRYPTO_ERROR;
  ------------------
  |  |  156|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CRYPTO, 0x0000)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
 1783|      0|            }
 1784|    199|            if ((spdm_context->connection_info.version >> SPDM_VERSION_NUMBER_SHIFT_BIT) >
  ------------------
  |  |  140|    199|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
  |  Branch (1784:17): [True: 0, False: 199]
  ------------------
 1785|    199|                SPDM_MESSAGE_VERSION_11) {
  ------------------
  |  |  111|    199|#define SPDM_MESSAGE_VERSION_11 0x11
  ------------------
 1786|       |
 1787|       |                /* Need append VCA since 1.2 script */
 1788|      0|                result = libspdm_hash_update (
 1789|      0|                    spdm_context->connection_info.algorithm.base_hash_algo,
 1790|      0|                    spdm_context->transcript.digest_context_mut_m1m2,
 1791|      0|                    libspdm_get_managed_buffer(&spdm_context->transcript.message_a),
 1792|      0|                    libspdm_get_managed_buffer_size(&spdm_context->transcript.
 1793|      0|                                                    message_a));
 1794|      0|                if (!result) {
  ------------------
  |  Branch (1794:21): [True: 0, False: 0]
  ------------------
 1795|      0|                    libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
 1796|      0|                                       spdm_context->transcript.digest_context_mut_m1m2);
 1797|      0|                    spdm_context->transcript.digest_context_mut_m1m2 = NULL;
 1798|      0|                    return LIBSPDM_STATUS_CRYPTO_ERROR;
  ------------------
  |  |  156|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CRYPTO, 0x0000)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
 1799|      0|                }
 1800|      0|            }
 1801|    199|        }
 1802|       |
 1803|    199|        result = libspdm_hash_update (spdm_context->connection_info.algorithm.base_hash_algo,
 1804|    199|                                      spdm_context->transcript.digest_context_mut_m1m2, message,
 1805|    199|                                      message_size);
 1806|    199|        if (!result) {
  ------------------
  |  Branch (1806:13): [True: 0, False: 199]
  ------------------
 1807|      0|            libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
 1808|      0|                               spdm_context->transcript.digest_context_mut_m1m2);
 1809|      0|            spdm_context->transcript.digest_context_mut_m1m2 = NULL;
 1810|      0|            return LIBSPDM_STATUS_CRYPTO_ERROR;
  ------------------
  |  |  156|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CRYPTO, 0x0000)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
 1811|      0|        }
 1812|       |
 1813|    199|        return LIBSPDM_STATUS_SUCCESS;
  ------------------
  |  |   59|    199|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_SUCCESS, LIBSPDM_SOURCE_SUCCESS, 0x0000)
  |  |  ------------------
  |  |  |  |   55|    199|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
 1814|    199|    }
 1815|    199|#endif
 1816|    199|}
libspdm_get_connection_version:
 2632|    471|{
 2633|    471|    return (uint8_t)(spdm_context->connection_info.version >> SPDM_VERSION_NUMBER_SHIFT_BIT);
  ------------------
  |  |  140|    471|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 2634|    471|}
libspdm_is_capabilities_flag_supported:
 2651|    157|{
 2652|    157|    uint32_t negotiated_requester_capabilities_flag;
 2653|    157|    uint32_t negotiated_responder_capabilities_flag;
 2654|       |
 2655|    157|    if (is_requester) {
  ------------------
  |  Branch (2655:9): [True: 0, False: 157]
  ------------------
 2656|      0|        negotiated_requester_capabilities_flag = spdm_context->local_context.capability.flags;
 2657|      0|        negotiated_responder_capabilities_flag = spdm_context->connection_info.capability.flags;
 2658|    157|    } else {
 2659|    157|        negotiated_requester_capabilities_flag = spdm_context->connection_info.capability.flags;
 2660|    157|        negotiated_responder_capabilities_flag = spdm_context->local_context.capability.flags;
 2661|    157|    }
 2662|       |
 2663|    157|    if (((requester_capabilities_flag == 0) ||
  ------------------
  |  Branch (2663:10): [True: 0, False: 157]
  ------------------
 2664|    157|         ((negotiated_requester_capabilities_flag &
  ------------------
  |  Branch (2664:10): [True: 157, False: 0]
  ------------------
 2665|    157|           requester_capabilities_flag) != 0)) &&
 2666|    157|        ((responder_capabilities_flag == 0) ||
  ------------------
  |  Branch (2666:10): [True: 157, False: 0]
  ------------------
 2667|    157|         ((negotiated_responder_capabilities_flag &
  ------------------
  |  Branch (2667:10): [True: 0, False: 0]
  ------------------
 2668|    157|           responder_capabilities_flag) != 0))) {
 2669|    157|        return true;
 2670|    157|    } else {
 2671|      0|        return false;
 2672|      0|    }
 2673|    157|}
libspdm_register_device_io_func:
 2720|    314|{
 2721|    314|    libspdm_context_t *context;
 2722|       |
 2723|    314|    context = spdm_context;
 2724|    314|    context->send_message = send_message;
 2725|    314|    context->receive_message = receive_message;
 2726|    314|}
libspdm_register_device_buffer_func:
 2779|    314|{
 2780|    314|    libspdm_context_t *context;
 2781|       |
 2782|    314|    context = spdm_context;
 2783|    314|    context->sender_buffer_size = sender_buffer_size;
 2784|    314|    context->receiver_buffer_size = receiver_buffer_size;
 2785|    314|    context->acquire_sender_buffer = acquire_sender_buffer;
 2786|    314|    context->release_sender_buffer = release_sender_buffer;
 2787|    314|    context->acquire_receiver_buffer = acquire_receiver_buffer;
 2788|    314|    context->release_receiver_buffer = release_receiver_buffer;
 2789|       |
 2790|    314|    LIBSPDM_ASSERT (sender_buffer_size >=
 2791|    314|                    context->local_context.capability.transport_header_size +
 2792|    314|                    context->local_context.capability.transport_tail_size);
 2793|    314|    sender_buffer_size -= (context->local_context.capability.transport_header_size +
 2794|    314|                           context->local_context.capability.transport_tail_size);
 2795|    314|    LIBSPDM_ASSERT (sender_buffer_size >= SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12);
 2796|    314|    context->local_context.capability.sender_data_transfer_size = sender_buffer_size;
 2797|       |
 2798|    314|    LIBSPDM_ASSERT(receiver_buffer_size >=
 2799|    314|                   context->local_context.capability.transport_header_size +
 2800|    314|                   context->local_context.capability.transport_tail_size);
 2801|    314|    receiver_buffer_size -= (context->local_context.capability.transport_header_size +
 2802|    314|                             context->local_context.capability.transport_tail_size);
 2803|    314|    LIBSPDM_ASSERT (receiver_buffer_size >= SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12);
 2804|    314|    context->local_context.capability.data_transfer_size = receiver_buffer_size;
 2805|    314|}
libspdm_register_transport_layer_func:
 2823|    314|{
 2824|    314|    libspdm_context_t *context;
 2825|       |
 2826|    314|    context = spdm_context;
 2827|       |
 2828|       |    /* fix the data_transfer_size if it is set before */
 2829|    314|    if ((context->local_context.capability.data_transfer_size != 0) &&
  ------------------
  |  Branch (2829:9): [True: 0, False: 314]
  ------------------
 2830|    314|        (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|    314|    if ((context->local_context.capability.sender_data_transfer_size != 0) &&
  ------------------
  |  Branch (2836:9): [True: 0, False: 314]
  ------------------
 2837|    314|        (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|    314|    context->local_context.capability.max_spdm_msg_size = max_spdm_msg_size;
 2845|    314|    context->local_context.capability.transport_header_size = transport_header_size;
 2846|    314|    context->local_context.capability.transport_tail_size = transport_tail_size;
 2847|    314|    context->transport_encode_message = transport_encode_message;
 2848|    314|    context->transport_decode_message = transport_decode_message;
 2849|    314|}
libspdm_get_sizeof_required_scratch_buffer:
 2886|    314|{
 2887|    314|    libspdm_context_t *context;
 2888|    314|    size_t scratch_buffer_size;
 2889|       |
 2890|    314|    context = spdm_context;
 2891|    314|    LIBSPDM_ASSERT (context->local_context.capability.max_spdm_msg_size != 0);
 2892|       |
 2893|    314|    scratch_buffer_size = libspdm_get_scratch_buffer_capacity(context);
 2894|    314|    return scratch_buffer_size;
 2895|    314|}
libspdm_set_scratch_buffer:
 2911|    314|{
 2912|    314|    libspdm_context_t *context;
 2913|       |
 2914|    314|    context = spdm_context;
 2915|    314|    LIBSPDM_ASSERT (context->local_context.capability.max_spdm_msg_size != 0);
 2916|    314|    LIBSPDM_ASSERT (scratch_buffer_size >= libspdm_get_scratch_buffer_capacity(spdm_context));
 2917|    314|    context->scratch_buffer = scratch_buffer;
 2918|    314|    context->scratch_buffer_size = scratch_buffer_size;
 2919|    314|    context->last_spdm_request = (uint8_t *)scratch_buffer +
 2920|    314|                                 libspdm_get_scratch_buffer_last_spdm_request_offset(spdm_context);
 2921|    314|#if LIBSPDM_RESPOND_IF_READY_SUPPORT
 2922|    314|    context->cache_spdm_request = (uint8_t *)scratch_buffer +
 2923|    314|                                  libspdm_get_scratch_buffer_cache_spdm_request_offset(spdm_context);
 2924|    314|#endif
 2925|    314|}
libspdm_init_context_with_secured_context:
 3240|    314|{
 3241|    314|    libspdm_context_t *context;
 3242|    314|    size_t index;
 3243|       |
 3244|    314|    LIBSPDM_ASSERT(spdm_context != NULL);
 3245|    314|    LIBSPDM_ASSERT(secured_contexts != NULL);
 3246|    314|    LIBSPDM_ASSERT(num_secured_contexts == LIBSPDM_MAX_SESSION_COUNT);
 3247|       |
 3248|    314|    context = spdm_context;
 3249|    314|    libspdm_zero_mem(context, sizeof(libspdm_context_t));
 3250|    314|    context->version = LIBSPDM_CONTEXT_STRUCT_VERSION;
  ------------------
  |  |  527|    314|#define LIBSPDM_CONTEXT_STRUCT_VERSION 0x3
  ------------------
 3251|    314|    context->transcript.message_a.max_buffer_size =
 3252|    314|        sizeof(context->transcript.message_a.buffer);
 3253|    314|    context->transcript.message_d.max_buffer_size =
 3254|    314|        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|    314|    context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
 3272|    314|    context->local_context.version.spdm_version_count = SPDM_MAX_VERSION_COUNT;
  ------------------
  |  |   17|    314|#define SPDM_MAX_VERSION_COUNT 4
  ------------------
 3273|    314|    context->local_context.version.spdm_version[0] = SPDM_MESSAGE_VERSION_10 <<
  ------------------
  |  |  110|    314|#define SPDM_MESSAGE_VERSION_10 0x10
  ------------------
 3274|    314|                                                     SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    314|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3275|    314|    context->local_context.version.spdm_version[1] = SPDM_MESSAGE_VERSION_11 <<
  ------------------
  |  |  111|    314|#define SPDM_MESSAGE_VERSION_11 0x11
  ------------------
 3276|    314|                                                     SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    314|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3277|    314|    context->local_context.version.spdm_version[2] = SPDM_MESSAGE_VERSION_12 <<
  ------------------
  |  |  112|    314|#define SPDM_MESSAGE_VERSION_12 0x12
  ------------------
 3278|    314|                                                     SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    314|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3279|    314|    context->local_context.version.spdm_version[3] = SPDM_MESSAGE_VERSION_13 <<
  ------------------
  |  |  113|    314|#define SPDM_MESSAGE_VERSION_13 0x13
  ------------------
 3280|    314|                                                     SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    314|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3281|    314|    context->local_context.secured_message_version.spdm_version_count =
 3282|    314|        SECURED_SPDM_MAX_VERSION_COUNT;
  ------------------
  |  |   55|    314|#define SECURED_SPDM_MAX_VERSION_COUNT 3
  ------------------
 3283|    314|    context->local_context.secured_message_version.spdm_version[0] =
 3284|    314|        SECURED_SPDM_VERSION_10 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |   57|    314|#define SECURED_SPDM_VERSION_10 0x10
  ------------------
                      SECURED_SPDM_VERSION_10 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    314|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3285|    314|    context->local_context.secured_message_version.spdm_version[1] =
 3286|    314|        SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |   58|    314|#define SECURED_SPDM_VERSION_11 0x11
  ------------------
                      SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    314|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3287|    314|    context->local_context.secured_message_version.spdm_version[2] =
 3288|    314|        SECURED_SPDM_VERSION_12 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |   59|    314|#define SECURED_SPDM_VERSION_12 0x12
  ------------------
                      SECURED_SPDM_VERSION_12 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    314|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3289|    314|    context->local_context.capability.st1 = SPDM_ST1_VALUE_US;
  ------------------
  |  | 1514|    314|#define SPDM_ST1_VALUE_US 100000
  ------------------
 3290|       |
 3291|    314|    context->mut_auth_cert_chain_buffer_size = 0;
 3292|       |
 3293|    314|    context->max_spdm_session_sequence_number = LIBSPDM_MAX_SPDM_SESSION_SEQUENCE_NUMBER;
  ------------------
  |  |   39|    314|#define LIBSPDM_MAX_SPDM_SESSION_SEQUENCE_NUMBER 0xFFFFFFFFFFFFFFFFull
  ------------------
 3294|       |
 3295|    314|    context->latest_session_id = INVALID_SESSION_ID;
  ------------------
  |  |   28|    314|#define INVALID_SESSION_ID 0
  ------------------
 3296|    314|    context->last_spdm_request_session_id = INVALID_SESSION_ID;
  ------------------
  |  |   28|    314|#define INVALID_SESSION_ID 0
  ------------------
 3297|    314|    context->last_spdm_request_session_id_valid = false;
 3298|    314|    context->last_spdm_request_size = 0;
 3299|       |
 3300|       |    /* To be updated in libspdm_register_device_buffer_func */
 3301|    314|    context->local_context.capability.data_transfer_size = 0;
 3302|    314|    context->local_context.capability.sender_data_transfer_size = 0;
 3303|    314|    context->local_context.capability.max_spdm_msg_size = 0;
 3304|       |
 3305|  1.57k|    for (index = 0; index < num_secured_contexts; index++) {
  ------------------
  |  Branch (3305:21): [True: 1.25k, False: 314]
  ------------------
 3306|  1.25k|        if (secured_contexts[index] == NULL) {
  ------------------
  |  Branch (3306:13): [True: 0, False: 1.25k]
  ------------------
 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|  1.25k|        context->session_info[index].secured_message_context = secured_contexts[index];
 3311|  1.25k|        libspdm_secured_message_init_context(
 3312|  1.25k|            context->session_info[index].secured_message_context);
 3313|  1.25k|    }
 3314|       |
 3315|    314|    return LIBSPDM_STATUS_SUCCESS;
  ------------------
  |  |   59|    314|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_SUCCESS, LIBSPDM_SOURCE_SUCCESS, 0x0000)
  |  |  ------------------
  |  |  |  |   55|    314|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
 3316|    314|}
libspdm_init_context:
 3331|    314|{
 3332|    314|    libspdm_context_t *context;
 3333|    314|    void *secured_context;
 3334|    314|    void *secured_contexts[LIBSPDM_MAX_SESSION_COUNT];
 3335|    314|    size_t secured_context_size;
 3336|    314|    size_t index;
 3337|       |
 3338|    314|    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|    314|    context = spdm_context;
 3343|    314|    secured_context = (void *)((size_t)(context + 1));
 3344|    314|    secured_context_size = libspdm_secured_message_get_context_size();
 3345|       |
 3346|  1.57k|    for (index = 0; index < LIBSPDM_MAX_SESSION_COUNT; index++)
  ------------------
  |  |  198|  1.57k|#define LIBSPDM_MAX_SESSION_COUNT 4
  ------------------
  |  Branch (3346:21): [True: 1.25k, False: 314]
  ------------------
 3347|  1.25k|    {
 3348|  1.25k|        secured_contexts[index] = (uint8_t *)secured_context + secured_context_size * index;
 3349|  1.25k|    }
 3350|       |
 3351|    314|    return libspdm_init_context_with_secured_context(spdm_context,
 3352|    314|                                                     secured_contexts,
 3353|    314|                                                     LIBSPDM_MAX_SESSION_COUNT);
  ------------------
  |  |  198|    314|#define LIBSPDM_MAX_SESSION_COUNT 4
  ------------------
 3354|    314|}
libspdm_get_context_size:
 3467|    314|{
 3468|    314|    size_t size;
 3469|       |
 3470|    314|    size = sizeof(libspdm_context_t) +
 3471|    314|           libspdm_secured_message_get_context_size() * LIBSPDM_MAX_SESSION_COUNT;
  ------------------
  |  |  198|    314|#define LIBSPDM_MAX_SESSION_COUNT 4
  ------------------
 3472|    314|    LIBSPDM_ASSERT (size == LIBSPDM_CONTEXT_SIZE_ALL);
 3473|    314|    return size;
 3474|    314|}

libspdm_asym_free:
  362|    157|{
  363|    157|    if (context == NULL) {
  ------------------
  |  Branch (363:9): [True: 0, False: 157]
  ------------------
  364|      0|        return;
  365|      0|    }
  366|    157|    switch (base_asym_algo) {
  367|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
  ------------------
  |  |  371|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048 0x00000001
  ------------------
  |  Branch (367:5): [True: 0, False: 157]
  ------------------
  368|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
  ------------------
  |  |  373|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072 0x00000004
  ------------------
  |  Branch (368:5): [True: 0, False: 157]
  ------------------
  369|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
  ------------------
  |  |  376|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096 0x00000020
  ------------------
  |  Branch (369:5): [True: 0, False: 157]
  ------------------
  370|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
  ------------------
  |  |  372|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048 0x00000002
  ------------------
  |  Branch (370:5): [True: 0, False: 157]
  ------------------
  371|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
  ------------------
  |  |  374|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072 0x00000008
  ------------------
  |  Branch (371:5): [True: 0, False: 157]
  ------------------
  372|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
  ------------------
  |  |  377|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096 0x00000040
  ------------------
  |  Branch (372:5): [True: 0, False: 157]
  ------------------
  373|      0|#if (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT)
  374|      0|        libspdm_rsa_free(context);
  375|       |#else
  376|       |        LIBSPDM_ASSERT(false);
  377|       |#endif
  378|      0|        break;
  379|    157|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
  ------------------
  |  |  375|    157|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256 0x00000010
  ------------------
  |  Branch (379:5): [True: 157, False: 0]
  ------------------
  380|    157|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
  ------------------
  |  |  378|    157|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384 0x00000080
  ------------------
  |  Branch (380:5): [True: 0, False: 157]
  ------------------
  381|    157|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
  ------------------
  |  |  379|    157|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521 0x00000100
  ------------------
  |  Branch (381:5): [True: 0, False: 157]
  ------------------
  382|    157|#if LIBSPDM_ECDSA_SUPPORT
  383|    157|        libspdm_ec_free(context);
  384|       |#else
  385|       |        LIBSPDM_ASSERT(false);
  386|       |#endif
  387|    157|        break;
  388|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
  ------------------
  |  |  385|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519 0x00000400
  ------------------
  |  Branch (388:5): [True: 0, False: 157]
  ------------------
  389|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
  ------------------
  |  |  386|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448 0x00000800
  ------------------
  |  Branch (389:5): [True: 0, False: 157]
  ------------------
  390|       |#if (LIBSPDM_EDDSA_ED25519_SUPPORT) || (LIBSPDM_EDDSA_ED448_SUPPORT)
  391|       |        libspdm_ecd_free(context);
  392|       |#else
  393|      0|        LIBSPDM_ASSERT(false);
  394|      0|#endif
  395|      0|        break;
  396|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
  ------------------
  |  |  384|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256 0x00000200
  ------------------
  |  Branch (396:5): [True: 0, False: 157]
  ------------------
  397|       |#if LIBSPDM_SM2_DSA_SUPPORT
  398|       |        libspdm_sm2_dsa_free(context);
  399|       |#else
  400|      0|        LIBSPDM_ASSERT(false);
  401|      0|#endif
  402|      0|        break;
  403|      0|    default:
  ------------------
  |  Branch (403:5): [True: 0, False: 157]
  ------------------
  404|      0|        LIBSPDM_ASSERT(false);
  405|      0|        break;
  406|    157|    }
  407|    157|}

libspdm_asym_get_public_key_from_x509:
  220|    157|{
  221|    157|    libspdm_asym_get_public_key_from_x509_func get_public_key_from_x509_function;
  222|    157|    get_public_key_from_x509_function = libspdm_get_asym_get_public_key_from_x509(base_asym_algo);
  223|    157|    if (get_public_key_from_x509_function == NULL) {
  ------------------
  |  Branch (223:9): [True: 0, False: 157]
  ------------------
  224|      0|        return false;
  225|      0|    }
  226|    157|    return get_public_key_from_x509_function(cert, cert_size, context);
  227|    157|}
libspdm_x509_common_certificate_check:
 1071|    157|{
 1072|    157|    uint8_t end_cert_from[64];
 1073|    157|    size_t end_cert_from_len;
 1074|    157|    uint8_t end_cert_to[64];
 1075|    157|    size_t end_cert_to_len;
 1076|    157|    size_t asn1_buffer_len;
 1077|    157|    bool status;
 1078|    157|    size_t cert_version;
 1079|    157|    void *context;
 1080|       |#if LIBSPDM_ADDITIONAL_CHECK_CERT
 1081|       |    size_t signature_algo_oid_size;
 1082|       |#endif /* LIBSPDM_ADDITIONAL_CHECK_CERT */
 1083|       |
 1084|    157|    if (cert == NULL || cert_size == 0) {
  ------------------
  |  Branch (1084:9): [True: 0, False: 157]
  |  Branch (1084:25): [True: 0, False: 157]
  ------------------
 1085|      0|        return false;
 1086|      0|    }
 1087|       |
 1088|    157|    status = true;
 1089|    157|    context = NULL;
 1090|    157|    end_cert_from_len = 64;
 1091|    157|    end_cert_to_len = 64;
 1092|       |
 1093|       |    /* 1. version*/
 1094|    157|    cert_version = 0;
 1095|    157|    status = libspdm_x509_get_version(cert, cert_size, &cert_version);
 1096|    157|    if (!status) {
  ------------------
  |  Branch (1096:9): [True: 0, False: 157]
  ------------------
 1097|      0|        goto cleanup;
 1098|      0|    }
 1099|    157|    if (cert_version != 2) {
  ------------------
  |  Branch (1099:9): [True: 0, False: 157]
  ------------------
 1100|      0|        status = false;
 1101|      0|        goto cleanup;
 1102|      0|    }
 1103|       |
 1104|       |    /* 2. serial_number*/
 1105|    157|    asn1_buffer_len = 0;
 1106|    157|    status = libspdm_x509_get_serial_number(cert, cert_size, NULL, &asn1_buffer_len);
 1107|    157|    if (asn1_buffer_len == 0) {
  ------------------
  |  Branch (1107:9): [True: 0, False: 157]
  ------------------
 1108|      0|        status = false;
 1109|      0|        goto cleanup;
 1110|      0|    }
 1111|       |
 1112|       |#if LIBSPDM_ADDITIONAL_CHECK_CERT
 1113|       |    /* 3. Verify signature algorithm. */
 1114|       |    signature_algo_oid_size = 0;
 1115|       |    status = libspdm_x509_get_signature_algorithm(cert, cert_size, NULL, &signature_algo_oid_size);
 1116|       |    if (status) {
 1117|       |        if ((signature_algo_oid_size == 0) &&
 1118|       |            (cert_model != SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT)) {
 1119|       |            status = false;
 1120|       |            goto cleanup;
 1121|       |        }
 1122|       |    } else {
 1123|       |        if (signature_algo_oid_size == 0) {
 1124|       |            status = false;
 1125|       |            goto cleanup;
 1126|       |        }
 1127|       |    }
 1128|       |#endif /* LIBSPDM_ADDITIONAL_CHECK_CERT */
 1129|       |
 1130|       |    /* 4. Verify public key algorithm.
 1131|       |     *    If this is a SET_CERTIFICATE operation and the endpoint uses the AliasCert model then the
 1132|       |     *    check should be skipped as the Device Certificate CA's public key does not have to use
 1133|       |     *    the same algorithms as the connection's negotiated algorithms. */
 1134|    157|    if (!set_cert || (cert_model != SPDM_CERTIFICATE_INFO_CERT_MODEL_ALIAS_CERT)) {
  ------------------
  |  |  599|      0|#define SPDM_CERTIFICATE_INFO_CERT_MODEL_ALIAS_CERT 0x2
  ------------------
  |  Branch (1134:9): [True: 157, False: 0]
  |  Branch (1134:22): [True: 0, False: 0]
  ------------------
 1135|    157|        status = libspdm_verify_cert_subject_public_key_info(cert, cert_size, base_asym_algo);
 1136|    157|        if (!status) {
  ------------------
  |  Branch (1136:13): [True: 0, False: 157]
  ------------------
 1137|      0|            goto cleanup;
 1138|      0|        }
 1139|    157|    }
 1140|       |
 1141|       |    /* 5. issuer_name*/
 1142|    157|    asn1_buffer_len = 0;
 1143|    157|    status = libspdm_x509_get_issuer_name(cert, cert_size, NULL, &asn1_buffer_len);
 1144|    157|    if (status) {
  ------------------
  |  Branch (1144:9): [True: 0, False: 157]
  ------------------
 1145|      0|        if ((asn1_buffer_len == 0) &&
  ------------------
  |  Branch (1145:13): [True: 0, False: 0]
  ------------------
 1146|      0|            (cert_model != SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT)) {
  ------------------
  |  |  600|      0|#define SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT 0x3
  ------------------
  |  Branch (1146:13): [True: 0, False: 0]
  ------------------
 1147|      0|            status = false;
 1148|      0|            goto cleanup;
 1149|      0|        }
 1150|    157|    } else {
 1151|    157|        if (asn1_buffer_len == 0) {
  ------------------
  |  Branch (1151:13): [True: 0, False: 157]
  ------------------
 1152|      0|            status = false;
 1153|      0|            goto cleanup;
 1154|      0|        }
 1155|    157|    }
 1156|       |
 1157|       |    /* 6. subject_name*/
 1158|    157|    asn1_buffer_len = 0;
 1159|    157|    status = libspdm_x509_get_subject_name(cert, cert_size, NULL, &asn1_buffer_len);
 1160|    157|    if (status) {
  ------------------
  |  Branch (1160:9): [True: 0, False: 157]
  ------------------
 1161|      0|        if ((asn1_buffer_len == 0) &&
  ------------------
  |  Branch (1161:13): [True: 0, False: 0]
  ------------------
 1162|      0|            (cert_model != SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT)) {
  ------------------
  |  |  600|      0|#define SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT 0x3
  ------------------
  |  Branch (1162:13): [True: 0, False: 0]
  ------------------
 1163|      0|            status = false;
 1164|      0|            goto cleanup;
 1165|      0|        }
 1166|    157|    } else {
 1167|    157|        if (asn1_buffer_len == 0) {
  ------------------
  |  Branch (1167:13): [True: 0, False: 157]
  ------------------
 1168|      0|            status = false;
 1169|      0|            goto cleanup;
 1170|      0|        }
 1171|    157|    }
 1172|       |
 1173|       |    /* 7. validity*/
 1174|    157|    status = libspdm_x509_get_validity(cert, cert_size, end_cert_from,
 1175|    157|                                       &end_cert_from_len, end_cert_to,
 1176|    157|                                       &end_cert_to_len);
 1177|    157|    if (status) {
  ------------------
  |  Branch (1177:9): [True: 157, False: 0]
  ------------------
 1178|    157|        if ((end_cert_from_len == 0) &&
  ------------------
  |  Branch (1178:13): [True: 0, False: 157]
  ------------------
 1179|    157|            (cert_model != SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT)) {
  ------------------
  |  |  600|      0|#define SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT 0x3
  ------------------
  |  Branch (1179:13): [True: 0, False: 0]
  ------------------
 1180|      0|            status = false;
 1181|      0|            goto cleanup;
 1182|      0|        }
 1183|    157|    } else {
 1184|      0|        if (end_cert_from_len == 0) {
  ------------------
  |  Branch (1184:13): [True: 0, False: 0]
  ------------------
 1185|      0|            status = false;
 1186|      0|            goto cleanup;
 1187|      0|        }
 1188|      0|    }
 1189|       |
 1190|    157|    if (end_cert_from_len != 0) {
  ------------------
  |  Branch (1190:9): [True: 157, False: 0]
  ------------------
 1191|    157|        status = libspdm_internal_x509_date_time_check(
 1192|    157|            end_cert_from, end_cert_from_len, end_cert_to, end_cert_to_len);
 1193|    157|        if (!status) {
  ------------------
  |  Branch (1193:13): [True: 0, False: 157]
  ------------------
 1194|      0|            goto cleanup;
 1195|      0|        }
 1196|    157|    }
 1197|       |
 1198|       |    /* 8. subject_public_key*/
 1199|    157|    status = libspdm_asym_get_public_key_from_x509(base_asym_algo, cert, cert_size, &context);
 1200|    157|    if (!status) {
  ------------------
  |  Branch (1200:9): [True: 0, False: 157]
  ------------------
 1201|      0|        goto cleanup;
 1202|      0|    }
 1203|       |
 1204|       |    /* 9. key_usage
 1205|       |     *    If this is a SET_CERTIFICATE operation and the endpoint uses the AliasCert model then the
 1206|       |     *    check should be skipped as the SPDM specification does not specify the presence or absence
 1207|       |     *    of the Device Certificate CA's keyUsage field. */
 1208|    157|    if (!set_cert || (cert_model != SPDM_CERTIFICATE_INFO_CERT_MODEL_ALIAS_CERT)) {
  ------------------
  |  |  599|      0|#define SPDM_CERTIFICATE_INFO_CERT_MODEL_ALIAS_CERT 0x2
  ------------------
  |  Branch (1208:9): [True: 157, False: 0]
  |  Branch (1208:22): [True: 0, False: 0]
  ------------------
 1209|    157|        size_t value = 0;
 1210|       |
 1211|    157|        status = libspdm_x509_get_key_usage(cert, cert_size, &value);
 1212|    157|        if (!status) {
  ------------------
  |  Branch (1212:13): [True: 0, False: 157]
  ------------------
 1213|      0|            goto cleanup;
 1214|    157|        } else {
 1215|    157|            if (value == 0) {
  ------------------
  |  Branch (1215:17): [True: 0, False: 157]
  ------------------
 1216|      0|                if (cert_model != SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT) {
  ------------------
  |  |  600|      0|#define SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT 0x3
  ------------------
  |  Branch (1216:21): [True: 0, False: 0]
  ------------------
 1217|      0|                    status = false;
 1218|      0|                    goto cleanup;
 1219|      0|                }
 1220|    157|            } else {
 1221|    157|                if ((LIBSPDM_CRYPTO_X509_KU_DIGITAL_SIGNATURE & value) == 0) {
  ------------------
  |  |   62|    157|#define LIBSPDM_CRYPTO_X509_KU_DIGITAL_SIGNATURE 0x80
  ------------------
  |  Branch (1221:21): [True: 0, False: 157]
  ------------------
 1222|      0|                    status = false;
 1223|      0|                    goto cleanup;
 1224|      0|                }
 1225|    157|            }
 1226|    157|        }
 1227|    157|    }
 1228|       |
 1229|       |    /* 10. verify spdm defined extended key usage*/
 1230|    157|    status = libspdm_verify_leaf_cert_spdm_eku(cert, cert_size, is_requester_cert);
 1231|    157|    if (!status) {
  ------------------
  |  Branch (1231:9): [True: 0, False: 157]
  ------------------
 1232|      0|        goto cleanup;
 1233|      0|    }
 1234|       |
 1235|    157|    if ((!set_cert) || (cert_model == SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT)) {
  ------------------
  |  |  598|      0|#define SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT 0x1
  ------------------
  |  Branch (1235:9): [True: 157, False: 0]
  |  Branch (1235:24): [True: 0, False: 0]
  ------------------
 1236|       |        /* 11. verify spdm defined extension*/
 1237|    157|        status = libspdm_verify_leaf_cert_spdm_extension(cert, cert_size,
 1238|    157|                                                         is_requester_cert, cert_model);
 1239|    157|        if (!status) {
  ------------------
  |  Branch (1239:13): [True: 0, False: 157]
  ------------------
 1240|      0|            goto cleanup;
 1241|      0|        }
 1242|    157|    }
 1243|       |
 1244|    157|cleanup:
 1245|    157|    libspdm_asym_free(base_asym_algo, context);
 1246|    157|    return status;
 1247|    157|}
libspdm_x509_certificate_check:
 1268|    157|{
 1269|    157|    bool status;
 1270|    157|    uint8_t cert_model;
 1271|       |
 1272|    157|    if (is_device_cert_model) {
  ------------------
  |  Branch (1272:9): [True: 157, False: 0]
  ------------------
 1273|    157|        cert_model = SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT;
  ------------------
  |  |  598|    157|#define SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT 0x1
  ------------------
 1274|    157|    } else {
 1275|      0|        cert_model = SPDM_CERTIFICATE_INFO_CERT_MODEL_ALIAS_CERT;
  ------------------
  |  |  599|      0|#define SPDM_CERTIFICATE_INFO_CERT_MODEL_ALIAS_CERT 0x2
  ------------------
 1276|      0|    }
 1277|       |
 1278|    157|    status = libspdm_x509_common_certificate_check(cert, cert_size, base_asym_algo,
 1279|    157|                                                   base_hash_algo, is_requester,
 1280|    157|                                                   cert_model, false);
 1281|    157|    if (!status) {
  ------------------
  |  Branch (1281:9): [True: 0, False: 157]
  ------------------
 1282|      0|        return false;
 1283|      0|    }
 1284|       |
 1285|       |    /* verify basic constraints: the leaf cert always is ca:false in get_cert*/
 1286|    157|    status = libspdm_verify_leaf_cert_basic_constraints(cert, cert_size, false);
 1287|    157|    return status;
 1288|    157|}
libspdm_verify_cert_chain_data:
 1669|    157|{
 1670|    157|    const uint8_t *root_cert_buffer;
 1671|    157|    size_t root_cert_buffer_size;
 1672|    157|    const uint8_t *leaf_cert_buffer;
 1673|    157|    size_t leaf_cert_buffer_size;
 1674|       |
 1675|    157|    if (cert_chain_data_size >
  ------------------
  |  Branch (1675:9): [True: 0, False: 157]
  ------------------
 1676|    157|        0xFFFF - (sizeof(spdm_cert_chain_t) + LIBSPDM_MAX_HASH_SIZE)) {
  ------------------
  |  |   65|    157|#define LIBSPDM_MAX_HASH_SIZE 64
  ------------------
 1677|      0|        LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
 1678|      0|                       "!!! VerifyCertificateChainData - FAIL (chain size too large) !!!\n"));
 1679|      0|        return false;
 1680|      0|    }
 1681|       |
 1682|    157|    if (!libspdm_x509_get_cert_from_cert_chain(
  ------------------
  |  Branch (1682:9): [True: 0, False: 157]
  ------------------
 1683|    157|            cert_chain_data, cert_chain_data_size, 0, &root_cert_buffer,
 1684|    157|            &root_cert_buffer_size)) {
 1685|      0|        LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
 1686|      0|                       "!!! VerifyCertificateChainData - FAIL (get root certificate failed)!!!\n"));
 1687|      0|        return false;
 1688|      0|    }
 1689|       |
 1690|    157|    if (!libspdm_x509_verify_cert_chain(root_cert_buffer, root_cert_buffer_size,
  ------------------
  |  Branch (1690:9): [True: 0, False: 157]
  ------------------
 1691|    157|                                        cert_chain_data, cert_chain_data_size)) {
 1692|      0|        LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
 1693|      0|                       "!!! VerifyCertificateChainData - FAIL (cert chain verify failed)!!!\n"));
 1694|      0|        return false;
 1695|      0|    }
 1696|       |
 1697|    157|    if (!libspdm_x509_get_cert_from_cert_chain(
  ------------------
  |  Branch (1697:9): [True: 0, False: 157]
  ------------------
 1698|    157|            cert_chain_data, cert_chain_data_size, -1,
 1699|    157|            &leaf_cert_buffer, &leaf_cert_buffer_size)) {
 1700|      0|        LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
 1701|      0|                       "!!! VerifyCertificateChainData - FAIL (get leaf certificate failed)!!!\n"));
 1702|      0|        return false;
 1703|      0|    }
 1704|       |
 1705|    157|    if (!libspdm_x509_certificate_check(leaf_cert_buffer, leaf_cert_buffer_size,
  ------------------
  |  Branch (1705:9): [True: 0, False: 157]
  ------------------
 1706|    157|                                        base_asym_algo, base_hash_algo,
 1707|    157|                                        is_requester_cert, is_device_cert_model)) {
 1708|      0|        LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
 1709|      0|                       "!!! VerifyCertificateChainData - FAIL (leaf certificate check failed)!!!\n"));
 1710|      0|        return false;
 1711|      0|    }
 1712|       |
 1713|    157|    return true;
 1714|    157|}
libspdm_crypt_cert.c:libspdm_get_asym_get_public_key_from_x509:
  124|    157|{
  125|    157|    switch (base_asym_algo) {
  126|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
  ------------------
  |  |  371|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048 0x00000001
  ------------------
  |  Branch (126:5): [True: 0, False: 157]
  ------------------
  127|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
  ------------------
  |  |  373|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072 0x00000004
  ------------------
  |  Branch (127:5): [True: 0, False: 157]
  ------------------
  128|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
  ------------------
  |  |  376|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096 0x00000020
  ------------------
  |  Branch (128:5): [True: 0, False: 157]
  ------------------
  129|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
  ------------------
  |  |  372|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048 0x00000002
  ------------------
  |  Branch (129:5): [True: 0, False: 157]
  ------------------
  130|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
  ------------------
  |  |  374|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072 0x00000008
  ------------------
  |  Branch (130:5): [True: 0, False: 157]
  ------------------
  131|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
  ------------------
  |  |  377|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096 0x00000040
  ------------------
  |  Branch (131:5): [True: 0, False: 157]
  ------------------
  132|      0|#if (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT)
  133|       |#if !LIBSPDM_RSA_SSA_2048_SUPPORT
  134|       |        LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048);
  135|       |#endif
  136|       |#if !LIBSPDM_RSA_SSA_3072_SUPPORT
  137|       |        LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072);
  138|       |#endif
  139|       |#if !LIBSPDM_RSA_SSA_4096_SUPPORT
  140|       |        LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096);
  141|       |#endif
  142|       |#if !LIBSPDM_RSA_PSS_2048_SUPPORT
  143|       |        LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048);
  144|       |#endif
  145|       |#if !LIBSPDM_RSA_PSS_3072_SUPPORT
  146|       |        LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072);
  147|       |#endif
  148|       |#if !LIBSPDM_RSA_PSS_4096_SUPPORT
  149|       |        LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096);
  150|       |#endif
  151|      0|        return libspdm_rsa_get_public_key_from_x509;
  152|       |#else
  153|       |        LIBSPDM_ASSERT(false);
  154|       |        break;
  155|       |#endif
  156|    157|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
  ------------------
  |  |  375|    157|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256 0x00000010
  ------------------
  |  Branch (156:5): [True: 157, False: 0]
  ------------------
  157|    157|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
  ------------------
  |  |  378|    157|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384 0x00000080
  ------------------
  |  Branch (157:5): [True: 0, False: 157]
  ------------------
  158|    157|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
  ------------------
  |  |  379|    157|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521 0x00000100
  ------------------
  |  Branch (158:5): [True: 0, False: 157]
  ------------------
  159|    157|#if LIBSPDM_ECDSA_SUPPORT
  160|       |#if !LIBSPDM_ECDSA_P256_SUPPORT
  161|       |        LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256);
  162|       |#endif
  163|       |#if !LIBSPDM_ECDSA_P384_SUPPORT
  164|       |        LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384);
  165|       |#endif
  166|       |#if !LIBSPDM_ECDSA_P521_SUPPORT
  167|       |        LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521);
  168|       |#endif
  169|    157|        return libspdm_ec_get_public_key_from_x509;
  170|       |#else
  171|       |        LIBSPDM_ASSERT(false);
  172|       |        break;
  173|       |#endif
  174|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
  ------------------
  |  |  385|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519 0x00000400
  ------------------
  |  Branch (174:5): [True: 0, False: 157]
  ------------------
  175|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
  ------------------
  |  |  386|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448 0x00000800
  ------------------
  |  Branch (175:5): [True: 0, False: 157]
  ------------------
  176|       |#if (LIBSPDM_EDDSA_ED25519_SUPPORT) || (LIBSPDM_EDDSA_ED448_SUPPORT)
  177|       |#if !LIBSPDM_EDDSA_ED25519_SUPPORT
  178|       |        LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519);
  179|       |#endif
  180|       |#if !LIBSPDM_EDDSA_ED448_SUPPORT
  181|       |        LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448);
  182|       |#endif
  183|       |        return libspdm_ecd_get_public_key_from_x509;
  184|       |#else
  185|      0|        LIBSPDM_ASSERT(false);
  186|      0|        break;
  187|      0|#endif
  188|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
  ------------------
  |  |  384|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256 0x00000200
  ------------------
  |  Branch (188:5): [True: 0, False: 157]
  ------------------
  189|       |#if LIBSPDM_SM2_DSA_SUPPORT
  190|       |        return libspdm_sm2_get_public_key_from_x509;
  191|       |#else
  192|      0|        LIBSPDM_ASSERT(false);
  193|      0|        break;
  194|      0|#endif
  195|      0|    default:
  ------------------
  |  Branch (195:5): [True: 0, False: 157]
  ------------------
  196|      0|        LIBSPDM_ASSERT(false);
  197|      0|        break;
  198|    157|    }
  199|       |
  200|      0|    return NULL;
  201|    157|}
libspdm_crypt_cert.c:libspdm_verify_cert_subject_public_key_info:
  693|    157|{
  694|    157|    size_t oid_len;
  695|    157|    bool status;
  696|       |
  697|       |    /*public key encrypt algo OID from cert*/
  698|    157|    uint8_t cert_public_key_crypt_algo_oid[LIBSPDM_MAX_ENCRYPTION_ALGO_OID_LEN];
  699|       |    /*public key encrypt algo OID from libspdm stored*/
  700|    157|    uint8_t libspdm_public_key_crypt_algo_oid[LIBSPDM_MAX_ENCRYPTION_ALGO_OID_LEN];
  701|    157|    uint8_t libspdm_public_key_crypt_algo_oid_other[LIBSPDM_MAX_ENCRYPTION_ALGO_OID_LEN];
  702|       |
  703|    157|    libspdm_zero_mem(libspdm_public_key_crypt_algo_oid, LIBSPDM_MAX_ENCRYPTION_ALGO_OID_LEN);
  ------------------
  |  |   32|    157|#define LIBSPDM_MAX_ENCRYPTION_ALGO_OID_LEN 10
  ------------------
  704|    157|    libspdm_zero_mem(libspdm_public_key_crypt_algo_oid_other, LIBSPDM_MAX_ENCRYPTION_ALGO_OID_LEN);
  ------------------
  |  |   32|    157|#define LIBSPDM_MAX_ENCRYPTION_ALGO_OID_LEN 10
  ------------------
  705|       |
  706|       |    /*work around: skip the sm2*/
  707|    157|    if (base_asym_algo == SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256) {
  ------------------
  |  |  384|    157|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256 0x00000200
  ------------------
  |  Branch (707:9): [True: 0, False: 157]
  ------------------
  708|      0|        return true;
  709|      0|    }
  710|       |
  711|    157|    oid_len = libspdm_get_public_key_algo_OID_len(base_asym_algo);
  712|    157|    if(oid_len == 0) {
  ------------------
  |  Branch (712:8): [True: 0, False: 157]
  ------------------
  713|      0|        return false;
  714|      0|    }
  715|       |    /*get public key encrypt algo OID from libspdm stored*/
  716|    157|    status = libspdm_get_public_key_algo_OID(base_asym_algo,
  717|    157|                                             libspdm_public_key_crypt_algo_oid,
  718|    157|                                             libspdm_public_key_crypt_algo_oid_other);
  719|    157|    if (!status) {
  ------------------
  |  Branch (719:9): [True: 0, False: 157]
  ------------------
  720|      0|        return status;
  721|      0|    }
  722|       |
  723|       |    /*get public key encrypt algo OID from cert*/
  724|    157|    status = libspdm_get_public_key_oid(cert, cert_size, cert_public_key_crypt_algo_oid, oid_len,
  725|    157|                                        base_asym_algo);
  726|    157|    if (!status || (!libspdm_consttime_is_mem_equal(cert_public_key_crypt_algo_oid,
  ------------------
  |  Branch (726:9): [True: 0, False: 157]
  |  Branch (726:21): [True: 0, False: 157]
  ------------------
  727|    157|                                                    libspdm_public_key_crypt_algo_oid, oid_len) &&
  728|    157|                    !libspdm_consttime_is_mem_equal(cert_public_key_crypt_algo_oid,
  ------------------
  |  Branch (728:21): [True: 0, False: 0]
  ------------------
  729|      0|                                                    libspdm_public_key_crypt_algo_oid_other,
  730|      0|                                                    oid_len))) {
  731|      0|        return false;
  732|      0|    }
  733|       |
  734|    157|    return status;
  735|    157|}
libspdm_crypt_cert.c:libspdm_get_public_key_algo_OID_len:
  329|    314|{
  330|    314|    switch (base_asym_algo) {
  331|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
  ------------------
  |  |  371|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048 0x00000001
  ------------------
  |  Branch (331:5): [True: 0, False: 314]
  ------------------
  332|      0|#if LIBSPDM_RSA_SSA_2048_SUPPORT
  333|      0|        return 4;
  334|       |#else
  335|       |        return 0;
  336|       |#endif
  337|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
  ------------------
  |  |  372|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048 0x00000002
  ------------------
  |  Branch (337:5): [True: 0, False: 314]
  ------------------
  338|      0|#if LIBSPDM_RSA_PSS_2048_SUPPORT
  339|      0|        return 4;
  340|       |#else
  341|       |        return 0;
  342|       |#endif
  343|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
  ------------------
  |  |  373|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072 0x00000004
  ------------------
  |  Branch (343:5): [True: 0, False: 314]
  ------------------
  344|      0|#if LIBSPDM_RSA_SSA_3072_SUPPORT
  345|      0|        return 4;
  346|       |#else
  347|       |        return 0;
  348|       |#endif
  349|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
  ------------------
  |  |  374|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072 0x00000008
  ------------------
  |  Branch (349:5): [True: 0, False: 314]
  ------------------
  350|      0|#if LIBSPDM_RSA_PSS_3072_SUPPORT
  351|      0|        return 4;
  352|       |#else
  353|       |        return 0;
  354|       |#endif
  355|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
  ------------------
  |  |  376|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096 0x00000020
  ------------------
  |  Branch (355:5): [True: 0, False: 314]
  ------------------
  356|      0|#if LIBSPDM_RSA_SSA_4096_SUPPORT
  357|      0|        return 4;
  358|       |#else
  359|       |        return 0;
  360|       |#endif
  361|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
  ------------------
  |  |  377|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096 0x00000040
  ------------------
  |  Branch (361:5): [True: 0, False: 314]
  ------------------
  362|      0|#if LIBSPDM_RSA_PSS_4096_SUPPORT
  363|      0|        return 4;
  364|       |#else
  365|       |        return 0;
  366|       |#endif
  367|    314|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
  ------------------
  |  |  375|    314|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256 0x00000010
  ------------------
  |  Branch (367:5): [True: 314, False: 0]
  ------------------
  368|    314|#if LIBSPDM_ECDSA_P256_SUPPORT
  369|    314|        return 8;
  370|       |#else
  371|       |        return 0;
  372|       |#endif
  373|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
  ------------------
  |  |  378|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384 0x00000080
  ------------------
  |  Branch (373:5): [True: 0, False: 314]
  ------------------
  374|      0|#if LIBSPDM_ECDSA_P384_SUPPORT
  375|      0|        return 5;
  376|       |#else
  377|       |        return 0;
  378|       |#endif
  379|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
  ------------------
  |  |  379|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521 0x00000100
  ------------------
  |  Branch (379:5): [True: 0, False: 314]
  ------------------
  380|      0|#if LIBSPDM_ECDSA_P521_SUPPORT
  381|      0|        return 5;
  382|       |#else
  383|       |        return 0;
  384|       |#endif
  385|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
  ------------------
  |  |  385|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519 0x00000400
  ------------------
  |  Branch (385:5): [True: 0, False: 314]
  ------------------
  386|       |#if LIBSPDM_EDDSA_ED25519_SUPPORT
  387|       |        return 3;
  388|       |#else
  389|      0|        return 0;
  390|      0|#endif
  391|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
  ------------------
  |  |  386|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448 0x00000800
  ------------------
  |  Branch (391:5): [True: 0, False: 314]
  ------------------
  392|       |#if LIBSPDM_EDDSA_ED448_SUPPORT
  393|       |        return 3;
  394|       |#else
  395|      0|        return 0;
  396|      0|#endif
  397|      0|    default:
  ------------------
  |  Branch (397:5): [True: 0, False: 314]
  ------------------
  398|      0|        LIBSPDM_ASSERT(false);
  399|      0|        return 0;
  400|    314|    }
  401|    314|}
libspdm_crypt_cert.c:libspdm_get_public_key_algo_OID:
  416|    157|{
  417|    157|    uint32_t oid_len;
  418|    157|    oid_len = libspdm_get_public_key_algo_OID_len(base_asym_algo);
  419|    157|    if(oid_len == 0) {
  ------------------
  |  Branch (419:8): [True: 0, False: 157]
  ------------------
  420|      0|        return false;
  421|      0|    }
  422|       |
  423|    157|    switch (base_asym_algo) {
  424|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
  ------------------
  |  |  371|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048 0x00000001
  ------------------
  |  Branch (424:5): [True: 0, False: 157]
  ------------------
  425|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048: {
  ------------------
  |  |  372|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048 0x00000002
  ------------------
  |  Branch (425:5): [True: 0, False: 157]
  ------------------
  426|      0|#if (LIBSPDM_RSA_SSA_2048_SUPPORT) || (LIBSPDM_RSA_PSS_2048_SUPPORT)
  427|      0|        uint8_t encry_algo_oid_rsa2048[] = KEY_ENCRY_ALGO_RSA2048_FLAG;
  ------------------
  |  |   46|      0|#define KEY_ENCRY_ALGO_RSA2048_FLAG {0x02, 0x82, 0x01, 0x01}
  ------------------
  428|      0|        uint8_t encry_algo_oid_rsa2048_ohter[] = KEY_ENCRY_ALGO_RSA2048_FLAG_OTHER;
  ------------------
  |  |   48|      0|#define KEY_ENCRY_ALGO_RSA2048_FLAG_OTHER {0x02, 0x82, 0x01, 0x00}
  ------------------
  429|      0|        libspdm_copy_mem(oid, oid_len, encry_algo_oid_rsa2048, oid_len);
  430|      0|        libspdm_copy_mem(oid_other, oid_len, encry_algo_oid_rsa2048_ohter, oid_len);
  431|      0|        return true;
  432|       |#else
  433|       |        return false;
  434|       |#endif
  435|      0|    }
  436|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
  ------------------
  |  |  373|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072 0x00000004
  ------------------
  |  Branch (436:5): [True: 0, False: 157]
  ------------------
  437|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072: {
  ------------------
  |  |  374|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072 0x00000008
  ------------------
  |  Branch (437:5): [True: 0, False: 157]
  ------------------
  438|      0|#if (LIBSPDM_RSA_SSA_3072_SUPPORT) || (LIBSPDM_RSA_PSS_3072_SUPPORT)
  439|      0|        uint8_t encry_algo_oid_rsa3072[] = KEY_ENCRY_ALGO_RSA3072_FLAG;
  ------------------
  |  |   51|      0|#define KEY_ENCRY_ALGO_RSA3072_FLAG {0x02, 0x82, 0x01, 0x81}
  ------------------
  440|      0|        uint8_t encry_algo_oid_rsa3072_ohter[] = KEY_ENCRY_ALGO_RSA3072_FLAG_OTHER;
  ------------------
  |  |   53|      0|#define KEY_ENCRY_ALGO_RSA3072_FLAG_OTHER {0x02, 0x82, 0x01, 0x80}
  ------------------
  441|      0|        libspdm_copy_mem(oid, oid_len, encry_algo_oid_rsa3072, oid_len);
  442|      0|        libspdm_copy_mem(oid_other, oid_len, encry_algo_oid_rsa3072_ohter, oid_len);
  443|      0|        return true;
  444|       |#else
  445|       |        return false;
  446|       |#endif
  447|      0|    }
  448|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
  ------------------
  |  |  376|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096 0x00000020
  ------------------
  |  Branch (448:5): [True: 0, False: 157]
  ------------------
  449|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096: {
  ------------------
  |  |  377|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096 0x00000040
  ------------------
  |  Branch (449:5): [True: 0, False: 157]
  ------------------
  450|      0|#if (LIBSPDM_RSA_SSA_4096_SUPPORT) || (LIBSPDM_RSA_PSS_4096_SUPPORT)
  451|      0|        uint8_t encry_algo_oid_rsa4096[] = KEY_ENCRY_ALGO_RSA4096_FLAG;
  ------------------
  |  |   56|      0|#define KEY_ENCRY_ALGO_RSA4096_FLAG {0x02, 0x82, 0x02, 0x01}
  ------------------
  452|      0|        uint8_t encry_algo_oid_rsa4096_ohter[] = KEY_ENCRY_ALGO_RSA4096_FLAG_OTHER;
  ------------------
  |  |   58|      0|#define KEY_ENCRY_ALGO_RSA4096_FLAG_OTHER {0x02, 0x82, 0x02, 0x00}
  ------------------
  453|      0|        libspdm_copy_mem(oid, oid_len, encry_algo_oid_rsa4096, oid_len);
  454|      0|        libspdm_copy_mem(oid_other, oid_len, encry_algo_oid_rsa4096_ohter, oid_len);
  455|      0|        return true;
  456|       |#else
  457|       |        return false;
  458|       |#endif
  459|      0|    }
  460|       |
  461|    157|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256: {
  ------------------
  |  |  375|    157|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256 0x00000010
  ------------------
  |  Branch (461:5): [True: 157, False: 0]
  ------------------
  462|    157|#if LIBSPDM_ECDSA_P256_SUPPORT
  463|    157|        uint8_t encry_algo_oid_ecc256[] = KEY_ENCRY_ALGO_ECC256_OID;
  ------------------
  |  |   70|    157|#define KEY_ENCRY_ALGO_ECC256_OID {0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07}
  ------------------
  464|    157|        libspdm_copy_mem(oid, oid_len, encry_algo_oid_ecc256, oid_len);
  465|    157|        return true;
  466|       |#else
  467|       |        return false;
  468|       |#endif
  469|      0|    }
  470|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384: {
  ------------------
  |  |  378|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384 0x00000080
  ------------------
  |  Branch (470:5): [True: 0, False: 157]
  ------------------
  471|      0|#if LIBSPDM_ECDSA_P384_SUPPORT
  472|      0|        uint8_t encry_algo_oid_ecc384[] = KEY_ENCRY_ALGO_ECC384_OID;
  ------------------
  |  |   73|      0|#define KEY_ENCRY_ALGO_ECC384_OID {0x2B, 0x81, 0x04, 0x00, 0x22}
  ------------------
  473|      0|        libspdm_copy_mem(oid, oid_len, encry_algo_oid_ecc384, oid_len);
  474|      0|        return true;
  475|       |#else
  476|       |        return false;
  477|       |#endif
  478|      0|    }
  479|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521: {
  ------------------
  |  |  379|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521 0x00000100
  ------------------
  |  Branch (479:5): [True: 0, False: 157]
  ------------------
  480|      0|#if LIBSPDM_ECDSA_P521_SUPPORT
  481|      0|        uint8_t encry_algo_oid_ecc521[] = KEY_ENCRY_ALGO_ECC521_OID;
  ------------------
  |  |   76|      0|#define KEY_ENCRY_ALGO_ECC521_OID {0x2B, 0x81, 0x04, 0x00, 0x23}
  ------------------
  482|      0|        libspdm_copy_mem(oid, oid_len, encry_algo_oid_ecc521, oid_len);
  483|      0|        return true;
  484|       |#else
  485|       |        return false;
  486|       |#endif
  487|      0|    }
  488|       |
  489|       |    /*sm2 oid  TBD*/
  490|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
  ------------------
  |  |  384|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256 0x00000200
  ------------------
  |  Branch (490:5): [True: 0, False: 157]
  ------------------
  491|      0|        return true;
  492|       |
  493|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519: {
  ------------------
  |  |  385|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519 0x00000400
  ------------------
  |  Branch (493:5): [True: 0, False: 157]
  ------------------
  494|       |#if LIBSPDM_EDDSA_ED25519_SUPPORT
  495|       |        uint8_t encry_algo_oid_ed25519[] = ENCRY_ALGO_ED25519_OID;
  496|       |        libspdm_copy_mem(oid, oid_len, encry_algo_oid_ed25519, oid_len);
  497|       |        return true;
  498|       |#else
  499|      0|        return false;
  500|      0|#endif
  501|      0|        break;
  502|      0|    }
  503|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448: {
  ------------------
  |  |  386|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448 0x00000800
  ------------------
  |  Branch (503:5): [True: 0, False: 157]
  ------------------
  504|       |#if LIBSPDM_EDDSA_ED448_SUPPORT
  505|       |        uint8_t encry_algo_oid_ed448[] = ENCRY_ALGO_ED448_OID;
  506|       |        libspdm_copy_mem(oid, oid_len, encry_algo_oid_ed448, oid_len);
  507|       |        return true;
  508|       |#else
  509|      0|        return false;
  510|      0|#endif
  511|      0|        break;
  512|      0|    }
  513|       |
  514|      0|    default:
  ------------------
  |  Branch (514:5): [True: 0, False: 157]
  ------------------
  515|      0|        LIBSPDM_ASSERT(false);
  516|      0|        return false;
  517|    157|    }
  518|    157|}
libspdm_crypt_cert.c:libspdm_get_public_key_oid:
  534|    157|{
  535|    157|    bool ret;
  536|    157|    uint8_t *ptr;
  537|    157|    int32_t length;
  538|    157|    size_t obj_len;
  539|    157|    uint8_t *end;
  540|    157|    uint8_t index;
  541|    157|    uint8_t sequence_time;
  542|       |
  543|    157|    length = (int32_t)cert_size;
  544|    157|    ptr = (uint8_t*)(size_t)cert;
  545|    157|    obj_len = 0;
  546|    157|    end = ptr + length;
  547|    157|    ret = true;
  548|       |
  549|       |    /* TBSCertificate have 5 sequence before subjectPublicKeyInfo*/
  550|    157|    sequence_time = 5;
  551|       |
  552|       |    /*all cert sequence*/
  553|    157|    ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
  554|    157|                               LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   80|    157|#define LIBSPDM_CRYPTO_ASN1_SEQUENCE 0x10
  ------------------
                                             LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   90|    157|#define LIBSPDM_CRYPTO_ASN1_CONSTRUCTED 0x20
  ------------------
  555|    157|    if (!ret) {
  ------------------
  |  Branch (555:9): [True: 0, False: 157]
  ------------------
  556|      0|        return false;
  557|      0|    }
  558|       |
  559|       |    /*TBSCertificate sequence*/
  560|    157|    ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
  561|    157|                               LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   80|    157|#define LIBSPDM_CRYPTO_ASN1_SEQUENCE 0x10
  ------------------
                                             LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   90|    157|#define LIBSPDM_CRYPTO_ASN1_CONSTRUCTED 0x20
  ------------------
  562|    157|    if (!ret) {
  ------------------
  |  Branch (562:9): [True: 0, False: 157]
  ------------------
  563|      0|        return false;
  564|      0|    }
  565|       |
  566|    157|    end = ptr + obj_len;
  567|       |    /*version*/
  568|    157|    ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
  569|    157|                               LIBSPDM_CRYPTO_ASN1_CONTEXT_SPECIFIC |
  ------------------
  |  |   91|    157|#define LIBSPDM_CRYPTO_ASN1_CONTEXT_SPECIFIC 0x80
  ------------------
  570|    157|                               LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   90|    157|#define LIBSPDM_CRYPTO_ASN1_CONSTRUCTED 0x20
  ------------------
  571|    157|    if (!ret) {
  ------------------
  |  Branch (571:9): [True: 0, False: 157]
  ------------------
  572|      0|        return false;
  573|      0|    }
  574|       |
  575|    157|    ptr += obj_len;
  576|       |    /*serialNumber*/
  577|    157|    ret = libspdm_asn1_get_tag(&ptr, end, &obj_len, LIBSPDM_CRYPTO_ASN1_INTEGER);
  ------------------
  |  |   74|    157|#define LIBSPDM_CRYPTO_ASN1_INTEGER 0x02
  ------------------
  578|    157|    if (!ret) {
  ------------------
  |  Branch (578:9): [True: 0, False: 157]
  ------------------
  579|      0|        return false;
  580|      0|    }
  581|       |
  582|       |    /**
  583|       |     * signature AlgorithmIdentifier,
  584|       |     * issuer Name,
  585|       |     * validity Validity,
  586|       |     * subject Name,
  587|       |     * subjectPublicKeyInfo
  588|       |     **/
  589|    942|    for (index = 0; index < sequence_time; index++) {
  ------------------
  |  Branch (589:21): [True: 785, False: 157]
  ------------------
  590|    785|        ptr += obj_len;
  591|    785|        ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
  592|    785|                                   LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   80|    785|#define LIBSPDM_CRYPTO_ASN1_SEQUENCE 0x10
  ------------------
                                                 LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   90|    785|#define LIBSPDM_CRYPTO_ASN1_CONSTRUCTED 0x20
  ------------------
  593|    785|        if (!ret) {
  ------------------
  |  Branch (593:13): [True: 0, False: 785]
  ------------------
  594|      0|            return false;
  595|      0|        }
  596|    785|    }
  597|       |
  598|    157|    switch (base_asym_algo)
  599|    157|    {
  600|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
  ------------------
  |  |  371|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048 0x00000001
  ------------------
  |  Branch (600:5): [True: 0, False: 157]
  ------------------
  601|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
  ------------------
  |  |  372|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048 0x00000002
  ------------------
  |  Branch (601:5): [True: 0, False: 157]
  ------------------
  602|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
  ------------------
  |  |  373|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072 0x00000004
  ------------------
  |  Branch (602:5): [True: 0, False: 157]
  ------------------
  603|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
  ------------------
  |  |  374|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072 0x00000008
  ------------------
  |  Branch (603:5): [True: 0, False: 157]
  ------------------
  604|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
  ------------------
  |  |  376|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096 0x00000020
  ------------------
  |  Branch (604:5): [True: 0, False: 157]
  ------------------
  605|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
  ------------------
  |  |  377|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096 0x00000040
  ------------------
  |  Branch (605:5): [True: 0, False: 157]
  ------------------
  606|      0|        ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
  607|      0|                                   LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   80|      0|#define LIBSPDM_CRYPTO_ASN1_SEQUENCE 0x10
  ------------------
                                                 LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   90|      0|#define LIBSPDM_CRYPTO_ASN1_CONSTRUCTED 0x20
  ------------------
  608|      0|        if (!ret) {
  ------------------
  |  Branch (608:13): [True: 0, False: 0]
  ------------------
  609|      0|            return false;
  610|      0|        }
  611|       |
  612|      0|        ptr += obj_len;
  613|      0|        ret = libspdm_asn1_get_tag(&ptr, end, &obj_len, LIBSPDM_CRYPTO_ASN1_BIT_STRING);
  ------------------
  |  |   75|      0|#define LIBSPDM_CRYPTO_ASN1_BIT_STRING 0x03
  ------------------
  614|      0|        if (!ret) {
  ------------------
  |  Branch (614:13): [True: 0, False: 0]
  ------------------
  615|      0|            return false;
  616|      0|        }
  617|       |
  618|       |        /*get rsa key len*/
  619|      0|        ptr++;
  620|      0|        ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
  621|      0|                                   LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   80|      0|#define LIBSPDM_CRYPTO_ASN1_SEQUENCE 0x10
  ------------------
                                                 LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   90|      0|#define LIBSPDM_CRYPTO_ASN1_CONSTRUCTED 0x20
  ------------------
  622|      0|        if (!ret) {
  ------------------
  |  Branch (622:13): [True: 0, False: 0]
  ------------------
  623|      0|            return false;
  624|      0|        }
  625|      0|        libspdm_copy_mem(oid, oid_size, ptr, oid_size);
  626|      0|        break;
  627|    157|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
  ------------------
  |  |  375|    157|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256 0x00000010
  ------------------
  |  Branch (627:5): [True: 157, False: 0]
  ------------------
  628|    157|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
  ------------------
  |  |  378|    157|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384 0x00000080
  ------------------
  |  Branch (628:5): [True: 0, False: 157]
  ------------------
  629|    157|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
  ------------------
  |  |  379|    157|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521 0x00000100
  ------------------
  |  Branch (629:5): [True: 0, False: 157]
  ------------------
  630|    157|        ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
  631|    157|                                   LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   80|    157|#define LIBSPDM_CRYPTO_ASN1_SEQUENCE 0x10
  ------------------
                                                 LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   90|    157|#define LIBSPDM_CRYPTO_ASN1_CONSTRUCTED 0x20
  ------------------
  632|    157|        if (!ret) {
  ------------------
  |  Branch (632:13): [True: 0, False: 157]
  ------------------
  633|      0|            return false;
  634|      0|        }
  635|    157|        ret = libspdm_asn1_get_tag(&ptr, end, &obj_len, LIBSPDM_CRYPTO_ASN1_OID);
  ------------------
  |  |   78|    157|#define LIBSPDM_CRYPTO_ASN1_OID 0x06
  ------------------
  636|    157|        if (!ret) {
  ------------------
  |  Branch (636:13): [True: 0, False: 157]
  ------------------
  637|      0|            return false;
  638|      0|        }
  639|       |
  640|       |        /*get ecc second oid*/
  641|    157|        ptr +=obj_len;
  642|    157|        ret = libspdm_asn1_get_tag(&ptr, end, &obj_len, LIBSPDM_CRYPTO_ASN1_OID);
  ------------------
  |  |   78|    157|#define LIBSPDM_CRYPTO_ASN1_OID 0x06
  ------------------
  643|    157|        if (!ret) {
  ------------------
  |  Branch (643:13): [True: 0, False: 157]
  ------------------
  644|      0|            return false;
  645|      0|        }
  646|       |
  647|    157|        if (oid_size != obj_len) {
  ------------------
  |  Branch (647:13): [True: 0, False: 157]
  ------------------
  648|      0|            return false;
  649|      0|        }
  650|       |
  651|    157|        libspdm_copy_mem(oid, oid_size, ptr, obj_len);
  652|    157|        break;
  653|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
  ------------------
  |  |  385|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519 0x00000400
  ------------------
  |  Branch (653:5): [True: 0, False: 157]
  ------------------
  654|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
  ------------------
  |  |  386|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448 0x00000800
  ------------------
  |  Branch (654:5): [True: 0, False: 157]
  ------------------
  655|      0|        ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
  656|      0|                                   LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   80|      0|#define LIBSPDM_CRYPTO_ASN1_SEQUENCE 0x10
  ------------------
                                                 LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   90|      0|#define LIBSPDM_CRYPTO_ASN1_CONSTRUCTED 0x20
  ------------------
  657|      0|        if (!ret) {
  ------------------
  |  Branch (657:13): [True: 0, False: 0]
  ------------------
  658|      0|            return false;
  659|      0|        }
  660|       |
  661|       |        /*get eddsa oid*/
  662|      0|        ret = libspdm_asn1_get_tag(&ptr, end, &obj_len, LIBSPDM_CRYPTO_ASN1_OID);
  ------------------
  |  |   78|      0|#define LIBSPDM_CRYPTO_ASN1_OID 0x06
  ------------------
  663|      0|        if (!ret) {
  ------------------
  |  Branch (663:13): [True: 0, False: 0]
  ------------------
  664|      0|            return false;
  665|      0|        }
  666|       |
  667|      0|        if (oid_size != obj_len) {
  ------------------
  |  Branch (667:13): [True: 0, False: 0]
  ------------------
  668|      0|            return false;
  669|      0|        }
  670|       |
  671|      0|        libspdm_copy_mem(oid, oid_size, ptr, obj_len);
  672|      0|        break;
  673|      0|    default:
  ------------------
  |  Branch (673:5): [True: 0, False: 157]
  ------------------
  674|      0|        LIBSPDM_ASSERT(false);
  675|      0|        return false;
  676|    157|    }
  677|       |
  678|    157|    return true;
  679|    157|}
libspdm_crypt_cert.c:libspdm_internal_x509_date_time_check:
  285|    157|{
  286|    157|    int32_t ret;
  287|    157|    bool status;
  288|    157|    uint8_t f0[64];
  289|    157|    uint8_t t0[64];
  290|    157|    size_t f0_size;
  291|    157|    size_t t0_size;
  292|       |
  293|    157|    f0_size = 64;
  294|    157|    t0_size = 64;
  295|       |
  296|    157|    status = libspdm_x509_set_date_time("19700101000000Z", f0, &f0_size);
  297|    157|    if (!status) {
  ------------------
  |  Branch (297:9): [True: 0, False: 157]
  ------------------
  298|      0|        return false;
  299|      0|    }
  300|       |
  301|    157|    status = libspdm_x509_set_date_time("99991231235959Z", t0, &t0_size);
  302|    157|    if (!status) {
  ------------------
  |  Branch (302:9): [True: 0, False: 157]
  ------------------
  303|      0|        return false;
  304|      0|    }
  305|       |
  306|       |    /* from >= f0*/
  307|    157|    ret = libspdm_x509_compare_date_time(from, f0);
  308|    157|    if (ret < 0) {
  ------------------
  |  Branch (308:9): [True: 0, False: 157]
  ------------------
  309|      0|        return false;
  310|      0|    }
  311|       |
  312|       |    /* to <= t0*/
  313|    157|    ret = libspdm_x509_compare_date_time(t0, to);
  314|    157|    if (ret < 0) {
  ------------------
  |  Branch (314:9): [True: 0, False: 157]
  ------------------
  315|      0|        return false;
  316|      0|    }
  317|       |
  318|    157|    return true;
  319|    157|}
libspdm_crypt_cert.c:libspdm_verify_leaf_cert_spdm_eku:
  887|    157|{
  888|    157|    bool status;
  889|    157|    uint8_t eku[256];
  890|    157|    size_t eku_size;
  891|    157|    bool req_auth_oid_find_success;
  892|    157|    bool rsp_auth_oid_find_success;
  893|    157|    uint8_t *ptr;
  894|    157|    size_t obj_len;
  895|       |
  896|       |    /* SPDM defined OID */
  897|    157|    uint8_t eku_requester_auth_oid[] = SPDM_OID_DMTF_EKU_REQUESTER_AUTH;
  ------------------
  |  | 1533|    157|    { /*0x06, 0x0A,*/ 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1C, 0x82, 0x12, 0x04 }
  ------------------
  898|    157|    uint8_t eku_responder_auth_oid[] = SPDM_OID_DMTF_EKU_RESPONDER_AUTH;
  ------------------
  |  | 1530|    157|    { /*0x06, 0x0A,*/ 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1C, 0x82, 0x12, 0x03 }
  ------------------
  899|       |
  900|    157|    eku_size = sizeof(eku);
  901|    157|    status = libspdm_x509_get_extended_key_usage(cert, cert_size, eku, &eku_size);
  902|    157|    if (!status) {
  ------------------
  |  Branch (902:9): [True: 0, False: 157]
  ------------------
  903|      0|        return false;
  904|    157|    } else if (eku_size == 0) {
  ------------------
  |  Branch (904:16): [True: 0, False: 157]
  ------------------
  905|       |        /* eku is not present in cert */
  906|      0|        return true;
  907|      0|    }
  908|       |
  909|    157|    ptr = eku;
  910|    157|    obj_len = 0;
  911|    157|    req_auth_oid_find_success = false;
  912|    157|    rsp_auth_oid_find_success = false;
  913|       |
  914|    157|    status = libspdm_asn1_get_tag(&ptr, eku + eku_size, &obj_len,
  915|    157|                                  LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   80|    157|#define LIBSPDM_CRYPTO_ASN1_SEQUENCE 0x10
  ------------------
                                                LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   90|    157|#define LIBSPDM_CRYPTO_ASN1_CONSTRUCTED 0x20
  ------------------
  916|    157|    if (!status) {
  ------------------
  |  Branch (916:9): [True: 0, False: 157]
  ------------------
  917|      0|        return false;
  918|      0|    }
  919|       |
  920|    628|    while(ptr < eku + eku_size) {
  ------------------
  |  Branch (920:11): [True: 471, False: 157]
  ------------------
  921|    471|        status = libspdm_asn1_get_tag(&ptr, eku + eku_size, &obj_len, LIBSPDM_CRYPTO_ASN1_OID);
  ------------------
  |  |   78|    471|#define LIBSPDM_CRYPTO_ASN1_OID 0x06
  ------------------
  922|    471|        if (!status) {
  ------------------
  |  Branch (922:13): [True: 0, False: 471]
  ------------------
  923|      0|            return false;
  924|      0|        }
  925|       |
  926|    471|        if ((obj_len == sizeof(eku_requester_auth_oid)) &&
  ------------------
  |  Branch (926:13): [True: 0, False: 471]
  ------------------
  927|    471|            (libspdm_consttime_is_mem_equal(ptr, eku_requester_auth_oid,
  ------------------
  |  Branch (927:13): [True: 0, False: 0]
  ------------------
  928|      0|                                            sizeof(eku_requester_auth_oid)))) {
  929|      0|            req_auth_oid_find_success = true;
  930|      0|        }
  931|    471|        if ((obj_len == sizeof(eku_responder_auth_oid)) &&
  ------------------
  |  Branch (931:13): [True: 0, False: 471]
  ------------------
  932|    471|            (libspdm_consttime_is_mem_equal(ptr, eku_responder_auth_oid,
  ------------------
  |  Branch (932:13): [True: 0, False: 0]
  ------------------
  933|      0|                                            sizeof(eku_responder_auth_oid)))) {
  934|      0|            rsp_auth_oid_find_success = true;
  935|      0|        }
  936|       |
  937|    471|        ptr += obj_len;
  938|    471|    }
  939|       |
  940|    157|    if (ptr != eku + eku_size) {
  ------------------
  |  Branch (940:9): [True: 0, False: 157]
  ------------------
  941|      0|        return false;
  942|      0|    }
  943|       |
  944|    157|    if (is_requester_cert) {
  ------------------
  |  Branch (944:9): [True: 0, False: 157]
  ------------------
  945|       |        /* it should not only contain responder auth oid */
  946|      0|        if (!req_auth_oid_find_success && rsp_auth_oid_find_success) {
  ------------------
  |  Branch (946:13): [True: 0, False: 0]
  |  Branch (946:43): [True: 0, False: 0]
  ------------------
  947|      0|            return false;
  948|      0|        }
  949|    157|    } else {
  950|       |        /* it should not only contain requester auth oid */
  951|    157|        if (req_auth_oid_find_success && !rsp_auth_oid_find_success) {
  ------------------
  |  Branch (951:13): [True: 0, False: 157]
  |  Branch (951:42): [True: 0, False: 0]
  ------------------
  952|      0|            return false;
  953|      0|        }
  954|    157|    }
  955|       |
  956|    157|    return true;
  957|    157|}
libspdm_crypt_cert.c:libspdm_verify_leaf_cert_spdm_extension:
  973|    157|{
  974|    157|    bool status;
  975|    157|    bool find_sucessful;
  976|    157|    uint8_t spdm_extension[LIBSPDM_MAX_EXTENSION_LEN];
  977|    157|    size_t len;
  978|    157|    uint8_t *ptr;
  979|    157|    uint8_t *temptr;
  980|    157|    size_t obj_len;
  981|       |
  982|       |    /* SPDM defined OID */
  983|    157|    uint8_t oid_spdm_extension[] = SPDM_OID_DMTF_SPDM_EXTENSION;
  ------------------
  |  | 1539|    157|    { /*0x06, 0x0A,*/ 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1C, 0x82, 0x12, 0x06 }
  ------------------
  984|    157|    uint8_t hardware_identity_oid[] = SPDM_OID_DMTF_HARDWARE_IDENTITY;
  ------------------
  |  | 1527|    157|    { /*0x06, 0x0A,*/ 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1C, 0x82, 0x12, 0x02 }
  ------------------
  985|       |
  986|    157|    len = LIBSPDM_MAX_EXTENSION_LEN;
  ------------------
  |  |   23|    157|#define LIBSPDM_MAX_EXTENSION_LEN 30
  ------------------
  987|       |
  988|    157|    if (cert == NULL || cert_size == 0) {
  ------------------
  |  Branch (988:9): [True: 0, False: 157]
  |  Branch (988:25): [True: 0, False: 157]
  ------------------
  989|      0|        return false;
  990|      0|    }
  991|       |
  992|    157|    status = libspdm_x509_get_extension_data(cert, cert_size,
  993|    157|                                             (const uint8_t *)oid_spdm_extension,
  994|    157|                                             sizeof(oid_spdm_extension),
  995|    157|                                             spdm_extension,
  996|    157|                                             &len);
  997|    157|    if (!status) {
  ------------------
  |  Branch (997:9): [True: 0, False: 157]
  ------------------
  998|      0|        return false;
  999|    157|    } else if(len == 0) {
  ------------------
  |  Branch (999:15): [True: 0, False: 157]
  ------------------
 1000|      0|        return true;
 1001|      0|    }
 1002|       |
 1003|       |    /*find the spdm hardware identity OID*/
 1004|    157|    find_sucessful = false;
 1005|    157|    ptr = spdm_extension;
 1006|    157|    obj_len = 0;
 1007|       |
 1008|       |    /*id-spdm-cert-oids ::= SEQUENCE SIZE (1..MAX) OF id-spdm-cert-oid*/
 1009|    157|    status = libspdm_asn1_get_tag(
 1010|    157|        &ptr, spdm_extension + len, &obj_len,
 1011|    157|        LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   80|    157|#define LIBSPDM_CRYPTO_ASN1_SEQUENCE 0x10
  ------------------
                      LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   90|    157|#define LIBSPDM_CRYPTO_ASN1_CONSTRUCTED 0x20
  ------------------
 1012|    157|    if (!status) {
  ------------------
  |  Branch (1012:9): [True: 0, False: 157]
  ------------------
 1013|      0|        return false;
 1014|      0|    }
 1015|       |
 1016|    314|    while(ptr < spdm_extension + len) {
  ------------------
  |  Branch (1016:11): [True: 157, False: 157]
  ------------------
 1017|    157|        status = libspdm_asn1_get_tag(
 1018|    157|            &ptr, spdm_extension + len, &obj_len,
 1019|    157|            LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   80|    157|#define LIBSPDM_CRYPTO_ASN1_SEQUENCE 0x10
  ------------------
                          LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   90|    157|#define LIBSPDM_CRYPTO_ASN1_CONSTRUCTED 0x20
  ------------------
 1020|    157|        if (!status) {
  ------------------
  |  Branch (1020:13): [True: 0, False: 157]
  ------------------
 1021|      0|            return false;
 1022|      0|        }
 1023|       |
 1024|    157|        temptr = ptr + obj_len;
 1025|    157|        status = libspdm_asn1_get_tag(
 1026|    157|            &ptr, spdm_extension + len, &obj_len, LIBSPDM_CRYPTO_ASN1_OID);
  ------------------
  |  |   78|    157|#define LIBSPDM_CRYPTO_ASN1_OID 0x06
  ------------------
 1027|    157|        if (!status) {
  ------------------
  |  Branch (1027:13): [True: 0, False: 157]
  ------------------
 1028|      0|            return false;
 1029|      0|        }
 1030|    157|        if ((obj_len == sizeof(hardware_identity_oid)) &&
  ------------------
  |  Branch (1030:13): [True: 157, False: 0]
  ------------------
 1031|    157|            (libspdm_consttime_is_mem_equal(ptr, hardware_identity_oid,
  ------------------
  |  Branch (1031:13): [True: 157, False: 0]
  ------------------
 1032|    157|                                            sizeof(hardware_identity_oid)))) {
 1033|    157|            find_sucessful = true;
 1034|    157|        }
 1035|    157|        ptr = temptr;
 1036|    157|    }
 1037|       |
 1038|    157|    if (ptr != spdm_extension + len) {
  ------------------
  |  Branch (1038:9): [True: 0, False: 157]
  ------------------
 1039|      0|        return false;
 1040|      0|    }
 1041|       |
 1042|       |    /* Responder does not determine Requester's certificate model */
 1043|    157|    if (!is_requester_cert) {
  ------------------
  |  Branch (1043:9): [True: 157, False: 0]
  ------------------
 1044|    157|        if ((find_sucessful) && (cert_model == SPDM_CERTIFICATE_INFO_CERT_MODEL_ALIAS_CERT)) {
  ------------------
  |  |  599|    157|#define SPDM_CERTIFICATE_INFO_CERT_MODEL_ALIAS_CERT 0x2
  ------------------
  |  Branch (1044:13): [True: 157, False: 0]
  |  Branch (1044:33): [True: 0, False: 157]
  ------------------
 1045|       |            /* Hardware_identity_OID is found in alias cert model */
 1046|      0|            return false;
 1047|      0|        }
 1048|    157|    }
 1049|       |
 1050|    157|    return true;
 1051|    157|}
libspdm_crypt_cert.c:libspdm_verify_leaf_cert_basic_constraints:
  750|    157|{
  751|    157|    bool status;
  752|       |    /*basic_constraints from cert*/
  753|    157|    uint8_t cert_basic_constraints[LIBSPDM_MAX_BASIC_CONSTRAINTS_CA_LEN];
  754|    157|    size_t len;
  755|       |
  756|    157|    uint8_t basic_constraints_false_case1[] = BASIC_CONSTRAINTS_STRING_FALSE_CASE1;
  ------------------
  |  |   92|    157|#define BASIC_CONSTRAINTS_STRING_FALSE_CASE1 {0x30, 0x00}
  ------------------
  757|    157|    uint8_t basic_constraints_false_case2[] = BASIC_CONSTRAINTS_STRING_FALSE_CASE2;
  ------------------
  |  |   95|    157|#define BASIC_CONSTRAINTS_STRING_FALSE_CASE2 {0x30, 0x03, 0x01, 0x01, 0x00}
  ------------------
  758|       |
  759|    157|    len = LIBSPDM_MAX_BASIC_CONSTRAINTS_CA_LEN;
  ------------------
  |  |   37|    157|#define LIBSPDM_MAX_BASIC_CONSTRAINTS_CA_LEN 10
  ------------------
  760|       |
  761|    157|    status = libspdm_x509_get_extended_basic_constraints(cert, cert_size,
  762|    157|                                                         cert_basic_constraints, &len);
  763|    157|    if (!status) {
  ------------------
  |  Branch (763:9): [True: 0, False: 157]
  ------------------
  764|      0|        return false;
  765|    157|    } else if (len == 0) {
  ------------------
  |  Branch (765:16): [True: 0, False: 157]
  ------------------
  766|       |        /* basic constraints is not present in cert */
  767|      0|        if (need_basic_constraints) {
  ------------------
  |  Branch (767:13): [True: 0, False: 0]
  ------------------
  768|      0|            return false;
  769|      0|        } else {
  770|      0|            return true;
  771|      0|        }
  772|      0|    }
  773|       |
  774|    157|    if ((len == sizeof(basic_constraints_false_case1)) &&
  ------------------
  |  Branch (774:9): [True: 157, False: 0]
  ------------------
  775|    157|        (libspdm_consttime_is_mem_equal(cert_basic_constraints,
  ------------------
  |  Branch (775:9): [True: 157, False: 0]
  ------------------
  776|    157|                                        basic_constraints_false_case1,
  777|    157|                                        sizeof(basic_constraints_false_case1)))) {
  778|    157|        return true;
  779|    157|    }
  780|       |
  781|      0|    if ((len == sizeof(basic_constraints_false_case2)) &&
  ------------------
  |  Branch (781:9): [True: 0, False: 0]
  ------------------
  782|      0|        (libspdm_consttime_is_mem_equal(cert_basic_constraints,
  ------------------
  |  Branch (782:9): [True: 0, False: 0]
  ------------------
  783|      0|                                        basic_constraints_false_case2,
  784|      0|                                        sizeof(basic_constraints_false_case2)))) {
  785|      0|        return true;
  786|      0|    }
  787|       |
  788|      0|    return false;
  789|      0|}

libspdm_get_hash_size:
   10|    220|{
   11|    220|    switch (base_hash_algo) {
   12|    220|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
  ------------------
  |  |  391|    220|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256 0x00000001
  ------------------
  |  Branch (12:5): [True: 220, False: 0]
  ------------------
   13|    220|#if LIBSPDM_SHA256_SUPPORT
   14|    220|        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: 220]
  ------------------
   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: 220]
  ------------------
   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: 220]
  ------------------
   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: 220]
  ------------------
   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: 220]
  ------------------
   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: 220]
  ------------------
   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: 220]
  ------------------
   55|      0|        return 0;
   56|    220|    }
   57|    220|}
libspdm_hash_new:
   82|    199|{
   83|    199|    switch (base_hash_algo) {
   84|    199|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
  ------------------
  |  |  391|    199|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256 0x00000001
  ------------------
  |  Branch (84:5): [True: 199, False: 0]
  ------------------
   85|    199|#if LIBSPDM_SHA256_SUPPORT
   86|    199|        return libspdm_sha256_new();
   87|       |#else
   88|       |        LIBSPDM_ASSERT(false);
   89|       |        return NULL;
   90|       |#endif
   91|      0|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384:
  ------------------
  |  |  392|      0|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384 0x00000002
  ------------------
  |  Branch (91:5): [True: 0, False: 199]
  ------------------
   92|      0|#if LIBSPDM_SHA384_SUPPORT
   93|      0|        return libspdm_sha384_new();
   94|       |#else
   95|       |        LIBSPDM_ASSERT(false);
   96|       |        return NULL;
   97|       |#endif
   98|      0|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512:
  ------------------
  |  |  393|      0|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512 0x00000004
  ------------------
  |  Branch (98:5): [True: 0, False: 199]
  ------------------
   99|      0|#if LIBSPDM_SHA512_SUPPORT
  100|      0|        return libspdm_sha512_new();
  101|       |#else
  102|       |        LIBSPDM_ASSERT(false);
  103|       |        return NULL;
  104|       |#endif
  105|      0|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_256:
  ------------------
  |  |  394|      0|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_256 0x00000008
  ------------------
  |  Branch (105:5): [True: 0, False: 199]
  ------------------
  106|      0|#if LIBSPDM_SHA3_256_SUPPORT
  107|      0|        return libspdm_sha3_256_new();
  108|       |#else
  109|       |        LIBSPDM_ASSERT(false);
  110|       |        return NULL;
  111|       |#endif
  112|      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 (112:5): [True: 0, False: 199]
  ------------------
  113|      0|#if LIBSPDM_SHA3_384_SUPPORT
  114|      0|        return libspdm_sha3_384_new();
  115|       |#else
  116|       |        LIBSPDM_ASSERT(false);
  117|       |        return NULL;
  118|       |#endif
  119|      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 (119:5): [True: 0, False: 199]
  ------------------
  120|      0|#if LIBSPDM_SHA3_512_SUPPORT
  121|      0|        return libspdm_sha3_512_new();
  122|       |#else
  123|       |        LIBSPDM_ASSERT(false);
  124|       |        return NULL;
  125|       |#endif
  126|      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 (126:5): [True: 0, False: 199]
  ------------------
  127|       |#if LIBSPDM_SM3_256_SUPPORT
  128|       |        return libspdm_sm3_256_new();
  129|       |#else
  130|      0|        LIBSPDM_ASSERT(false);
  131|      0|        return NULL;
  132|      0|#endif
  133|      0|    default:
  ------------------
  |  Branch (133:5): [True: 0, False: 199]
  ------------------
  134|      0|        LIBSPDM_ASSERT(false);
  135|      0|        return NULL;
  136|    199|    }
  137|    199|}
libspdm_hash_free:
  140|    199|{
  141|    199|    if (hash_context == NULL) {
  ------------------
  |  Branch (141:9): [True: 0, False: 199]
  ------------------
  142|      0|        return;
  143|      0|    }
  144|    199|    switch (base_hash_algo) {
  145|    199|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
  ------------------
  |  |  391|    199|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256 0x00000001
  ------------------
  |  Branch (145:5): [True: 199, False: 0]
  ------------------
  146|    199|#if LIBSPDM_SHA256_SUPPORT
  147|    199|        libspdm_sha256_free(hash_context);
  148|       |#else
  149|       |        LIBSPDM_ASSERT(false);
  150|       |#endif
  151|    199|        break;
  152|      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 (152:5): [True: 0, False: 199]
  ------------------
  153|      0|#if LIBSPDM_SHA384_SUPPORT
  154|      0|        libspdm_sha384_free(hash_context);
  155|       |#else
  156|       |        LIBSPDM_ASSERT(false);
  157|       |#endif
  158|      0|        break;
  159|      0|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512:
  ------------------
  |  |  393|      0|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512 0x00000004
  ------------------
  |  Branch (159:5): [True: 0, False: 199]
  ------------------
  160|      0|#if LIBSPDM_SHA512_SUPPORT
  161|      0|        libspdm_sha512_free(hash_context);
  162|       |#else
  163|       |        LIBSPDM_ASSERT(false);
  164|       |#endif
  165|      0|        break;
  166|      0|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_256:
  ------------------
  |  |  394|      0|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_256 0x00000008
  ------------------
  |  Branch (166:5): [True: 0, False: 199]
  ------------------
  167|      0|#if LIBSPDM_SHA3_256_SUPPORT
  168|      0|        libspdm_sha3_256_free(hash_context);
  169|       |#else
  170|       |        LIBSPDM_ASSERT(false);
  171|       |#endif
  172|      0|        break;
  173|      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 (173:5): [True: 0, False: 199]
  ------------------
  174|      0|#if LIBSPDM_SHA3_384_SUPPORT
  175|      0|        libspdm_sha3_384_free(hash_context);
  176|       |#else
  177|       |        LIBSPDM_ASSERT(false);
  178|       |#endif
  179|      0|        break;
  180|      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 (180:5): [True: 0, False: 199]
  ------------------
  181|      0|#if LIBSPDM_SHA3_512_SUPPORT
  182|      0|        libspdm_sha3_512_free(hash_context);
  183|       |#else
  184|       |        LIBSPDM_ASSERT(false);
  185|       |#endif
  186|      0|        break;
  187|      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 (187:5): [True: 0, False: 199]
  ------------------
  188|       |#if LIBSPDM_SM3_256_SUPPORT
  189|       |        libspdm_sm3_256_free(hash_context);
  190|       |#else
  191|      0|        LIBSPDM_ASSERT(false);
  192|      0|#endif
  193|      0|        break;
  194|      0|    default:
  ------------------
  |  Branch (194:5): [True: 0, False: 199]
  ------------------
  195|      0|        LIBSPDM_ASSERT(false);
  196|      0|        break;
  197|    199|    }
  198|    199|}
libspdm_hash_init:
  201|    199|{
  202|    199|    switch (base_hash_algo) {
  203|    199|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
  ------------------
  |  |  391|    199|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256 0x00000001
  ------------------
  |  Branch (203:5): [True: 199, False: 0]
  ------------------
  204|    199|#if LIBSPDM_SHA256_SUPPORT
  205|    199|        return libspdm_sha256_init(hash_context);
  206|       |#else
  207|       |        LIBSPDM_ASSERT(false);
  208|       |        return false;
  209|       |#endif
  210|      0|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384:
  ------------------
  |  |  392|      0|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384 0x00000002
  ------------------
  |  Branch (210:5): [True: 0, False: 199]
  ------------------
  211|      0|#if LIBSPDM_SHA384_SUPPORT
  212|      0|        return libspdm_sha384_init(hash_context);
  213|       |#else
  214|       |        LIBSPDM_ASSERT(false);
  215|       |        return false;
  216|       |#endif
  217|      0|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512:
  ------------------
  |  |  393|      0|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512 0x00000004
  ------------------
  |  Branch (217:5): [True: 0, False: 199]
  ------------------
  218|      0|#if LIBSPDM_SHA512_SUPPORT
  219|      0|        return libspdm_sha512_init(hash_context);
  220|       |#else
  221|       |        LIBSPDM_ASSERT(false);
  222|       |        return false;
  223|       |#endif
  224|      0|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_256:
  ------------------
  |  |  394|      0|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_256 0x00000008
  ------------------
  |  Branch (224:5): [True: 0, False: 199]
  ------------------
  225|      0|#if LIBSPDM_SHA3_256_SUPPORT
  226|      0|        return libspdm_sha3_256_init(hash_context);
  227|       |#else
  228|       |        LIBSPDM_ASSERT(false);
  229|       |        return false;
  230|       |#endif
  231|      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 (231:5): [True: 0, False: 199]
  ------------------
  232|      0|#if LIBSPDM_SHA3_384_SUPPORT
  233|      0|        return libspdm_sha3_384_init(hash_context);
  234|       |#else
  235|       |        LIBSPDM_ASSERT(false);
  236|       |        return false;
  237|       |#endif
  238|      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 (238:5): [True: 0, False: 199]
  ------------------
  239|      0|#if LIBSPDM_SHA3_512_SUPPORT
  240|      0|        return libspdm_sha3_512_init(hash_context);
  241|       |#else
  242|       |        LIBSPDM_ASSERT(false);
  243|       |        return false;
  244|       |#endif
  245|      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 (245:5): [True: 0, False: 199]
  ------------------
  246|       |#if LIBSPDM_SM3_256_SUPPORT
  247|       |        return libspdm_sm3_256_init(hash_context);
  248|       |#else
  249|      0|        LIBSPDM_ASSERT(false);
  250|      0|        return false;
  251|      0|#endif
  252|      0|    default:
  ------------------
  |  Branch (252:5): [True: 0, False: 199]
  ------------------
  253|      0|        LIBSPDM_ASSERT(false);
  254|      0|        return false;
  255|    199|    }
  256|    199|}
libspdm_hash_update:
  318|    199|{
  319|    199|    switch (base_hash_algo) {
  320|    199|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
  ------------------
  |  |  391|    199|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256 0x00000001
  ------------------
  |  Branch (320:5): [True: 199, False: 0]
  ------------------
  321|    199|#if LIBSPDM_SHA256_SUPPORT
  322|    199|        return libspdm_sha256_update(hash_context, data, data_size);
  323|       |#else
  324|       |        LIBSPDM_ASSERT(false);
  325|       |        return false;
  326|       |#endif
  327|      0|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384:
  ------------------
  |  |  392|      0|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384 0x00000002
  ------------------
  |  Branch (327:5): [True: 0, False: 199]
  ------------------
  328|      0|#if LIBSPDM_SHA384_SUPPORT
  329|      0|        return libspdm_sha384_update(hash_context, data, data_size);
  330|       |#else
  331|       |        LIBSPDM_ASSERT(false);
  332|       |        return false;
  333|       |#endif
  334|      0|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512:
  ------------------
  |  |  393|      0|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512 0x00000004
  ------------------
  |  Branch (334:5): [True: 0, False: 199]
  ------------------
  335|      0|#if LIBSPDM_SHA512_SUPPORT
  336|      0|        return libspdm_sha512_update(hash_context, data, data_size);
  337|       |#else
  338|       |        LIBSPDM_ASSERT(false);
  339|       |        return false;
  340|       |#endif
  341|      0|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_256:
  ------------------
  |  |  394|      0|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_256 0x00000008
  ------------------
  |  Branch (341:5): [True: 0, False: 199]
  ------------------
  342|      0|#if LIBSPDM_SHA3_256_SUPPORT
  343|      0|        return libspdm_sha3_256_update(hash_context, data, data_size);
  344|       |#else
  345|       |        LIBSPDM_ASSERT(false);
  346|       |        return false;
  347|       |#endif
  348|      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 (348:5): [True: 0, False: 199]
  ------------------
  349|      0|#if LIBSPDM_SHA3_384_SUPPORT
  350|      0|        return libspdm_sha3_384_update(hash_context, data, data_size);
  351|       |#else
  352|       |        LIBSPDM_ASSERT(false);
  353|       |        return false;
  354|       |#endif
  355|      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 (355:5): [True: 0, False: 199]
  ------------------
  356|      0|#if LIBSPDM_SHA3_512_SUPPORT
  357|      0|        return libspdm_sha3_512_update(hash_context, data, data_size);
  358|       |#else
  359|       |        LIBSPDM_ASSERT(false);
  360|       |        return false;
  361|       |#endif
  362|      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 (362:5): [True: 0, False: 199]
  ------------------
  363|       |#if LIBSPDM_SM3_256_SUPPORT
  364|       |        return libspdm_sm3_256_update(hash_context, data, data_size);
  365|       |#else
  366|      0|        LIBSPDM_ASSERT(false);
  367|      0|        return false;
  368|      0|#endif
  369|      0|    default:
  ------------------
  |  Branch (369:5): [True: 0, False: 199]
  ------------------
  370|      0|        LIBSPDM_ASSERT(false);
  371|      0|        return false;
  372|    199|    }
  373|    199|}
libspdm_hash_all:
  435|    157|{
  436|    157|    switch (base_hash_algo) {
  437|    157|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
  ------------------
  |  |  391|    157|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256 0x00000001
  ------------------
  |  Branch (437:5): [True: 157, False: 0]
  ------------------
  438|    157|#if LIBSPDM_SHA256_SUPPORT
  439|    157|        return libspdm_sha256_hash_all(data, data_size, hash_value);
  440|       |#else
  441|       |        LIBSPDM_ASSERT(false);
  442|       |        return false;
  443|       |#endif
  444|      0|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384:
  ------------------
  |  |  392|      0|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384 0x00000002
  ------------------
  |  Branch (444:5): [True: 0, False: 157]
  ------------------
  445|      0|#if LIBSPDM_SHA384_SUPPORT
  446|      0|        return libspdm_sha384_hash_all(data, data_size, hash_value);
  447|       |#else
  448|       |        LIBSPDM_ASSERT(false);
  449|       |        return false;
  450|       |#endif
  451|      0|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512:
  ------------------
  |  |  393|      0|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512 0x00000004
  ------------------
  |  Branch (451:5): [True: 0, False: 157]
  ------------------
  452|      0|#if LIBSPDM_SHA512_SUPPORT
  453|      0|        return libspdm_sha512_hash_all(data, data_size, hash_value);
  454|       |#else
  455|       |        LIBSPDM_ASSERT(false);
  456|       |        return false;
  457|       |#endif
  458|      0|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_256:
  ------------------
  |  |  394|      0|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_256 0x00000008
  ------------------
  |  Branch (458:5): [True: 0, False: 157]
  ------------------
  459|      0|#if LIBSPDM_SHA3_256_SUPPORT
  460|      0|        return libspdm_sha3_256_hash_all(data, data_size, hash_value);
  461|       |#else
  462|       |        LIBSPDM_ASSERT(false);
  463|       |        return false;
  464|       |#endif
  465|      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 (465:5): [True: 0, False: 157]
  ------------------
  466|      0|#if LIBSPDM_SHA3_384_SUPPORT
  467|      0|        return libspdm_sha3_384_hash_all(data, data_size, hash_value);
  468|       |#else
  469|       |        LIBSPDM_ASSERT(false);
  470|       |        return false;
  471|       |#endif
  472|      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 (472:5): [True: 0, False: 157]
  ------------------
  473|      0|#if LIBSPDM_SHA3_512_SUPPORT
  474|      0|        return libspdm_sha3_512_hash_all(data, data_size, hash_value);
  475|       |#else
  476|       |        LIBSPDM_ASSERT(false);
  477|       |        return false;
  478|       |#endif
  479|      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 (479:5): [True: 0, False: 157]
  ------------------
  480|       |#if LIBSPDM_SM3_256_SUPPORT
  481|       |        return libspdm_sm3_256_hash_all(data, data_size, hash_value);
  482|       |#else
  483|      0|        LIBSPDM_ASSERT(false);
  484|      0|        return false;
  485|      0|#endif
  486|      0|    default:
  ------------------
  |  Branch (486:5): [True: 0, False: 157]
  ------------------
  487|      0|        LIBSPDM_ASSERT(false);
  488|      0|        return false;
  489|    157|    }
  490|    157|}

libspdm_get_encap_request_get_digest:
   15|    157|{
   16|    157|    spdm_get_digest_request_t *spdm_request;
   17|    157|    libspdm_return_t status;
   18|       |
   19|    157|    spdm_context->encap_context.last_encap_request_size = 0;
   20|       |
   21|    157|    if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_11) {
  ------------------
  |  |  111|    157|#define SPDM_MESSAGE_VERSION_11 0x11
  ------------------
  |  Branch (21:9): [True: 0, False: 157]
  ------------------
   22|      0|        return LIBSPDM_STATUS_UNSUPPORTED_CAP;
  ------------------
  |  |   78|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0002)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
   23|      0|    }
   24|       |
   25|    157|    if (!libspdm_is_capabilities_flag_supported(
  ------------------
  |  Branch (25:9): [True: 0, False: 157]
  ------------------
   26|    157|            spdm_context, false,
   27|    157|            SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP, 0)) {
  ------------------
  |  |  185|    157|#define SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP 0x00000002
  ------------------
   28|      0|        return LIBSPDM_STATUS_UNSUPPORTED_CAP;
  ------------------
  |  |   78|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0002)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
   29|      0|    }
   30|       |
   31|    157|    LIBSPDM_ASSERT(*encap_request_size >= sizeof(spdm_get_digest_request_t));
   32|    157|    *encap_request_size = sizeof(spdm_get_digest_request_t);
   33|       |
   34|    157|    spdm_request = encap_request;
   35|       |
   36|    157|    libspdm_reset_message_buffer_via_request_code(spdm_context, NULL,
   37|    157|                                                  spdm_request->header.request_response_code);
   38|       |
   39|    157|    spdm_request->header.spdm_version = libspdm_get_connection_version (spdm_context);
   40|    157|    spdm_request->header.request_response_code = SPDM_GET_DIGESTS;
  ------------------
  |  |   66|    157|#define SPDM_GET_DIGESTS 0x81
  ------------------
   41|    157|    spdm_request->header.param1 = 0;
   42|    157|    spdm_request->header.param2 = 0;
   43|       |
   44|       |
   45|       |    /* Cache data*/
   46|       |
   47|    157|    status = libspdm_append_message_mut_b(spdm_context, spdm_request,
   48|    157|                                          *encap_request_size);
   49|    157|    if (LIBSPDM_STATUS_IS_ERROR(status)) {
  ------------------
  |  |   30|    157|    (LIBSPDM_STATUS_SEVERITY(status) == LIBSPDM_SEVERITY_ERROR)
  |  |  ------------------
  |  |  |  |   37|    157|#define LIBSPDM_STATUS_SEVERITY(status) (((status) >> 28) & 0xf)
  |  |  ------------------
  |  |                   (LIBSPDM_STATUS_SEVERITY(status) == LIBSPDM_SEVERITY_ERROR)
  |  |  ------------------
  |  |  |  |   44|    157|#define LIBSPDM_SEVERITY_ERROR 0x8
  |  |  ------------------
  |  |  |  Branch (30:5): [True: 0, False: 157]
  |  |  ------------------
  ------------------
   50|      0|        return LIBSPDM_STATUS_BUFFER_FULL;
  ------------------
  |  |  118|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x000c)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
   51|      0|    }
   52|       |
   53|    157|    libspdm_copy_mem(&spdm_context->encap_context.last_encap_request_header,
   54|    157|                     sizeof(spdm_context->encap_context.last_encap_request_header),
   55|    157|                     &spdm_request->header, sizeof(spdm_message_header_t));
   56|    157|    spdm_context->encap_context.last_encap_request_size =
   57|    157|        *encap_request_size;
   58|       |
   59|    157|    return LIBSPDM_STATUS_SUCCESS;
  ------------------
  |  |   59|    157|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_SUCCESS, LIBSPDM_SOURCE_SUCCESS, 0x0000)
  |  |  ------------------
  |  |  |  |   55|    157|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
   60|    157|}
libspdm_process_encap_response_digest:
   65|    157|{
   66|    157|    const spdm_digest_response_t *spdm_response;
   67|    157|    size_t spdm_response_size;
   68|    157|    size_t digest_size;
   69|    157|    size_t digest_count;
   70|    157|    size_t index;
   71|    157|    libspdm_return_t status;
   72|    157|    uint32_t session_id;
   73|    157|    libspdm_session_info_t *session_info;
   74|    157|    size_t additional_size;
   75|    157|    spdm_key_pair_id_t *key_pair_id;
   76|    157|    spdm_certificate_info_t *cert_info;
   77|    157|    spdm_key_usage_bit_mask_t *key_usage_bit_mask;
   78|    157|    size_t slot_index;
   79|    157|    uint8_t cert_model;
   80|    157|    uint8_t zero_digest[LIBSPDM_MAX_HASH_SIZE] = {0};
   81|       |
   82|    157|    spdm_response = encap_response;
   83|    157|    spdm_response_size = encap_response_size;
   84|       |
   85|    157|    if (spdm_response_size < sizeof(spdm_message_header_t)) {
  ------------------
  |  Branch (85:9): [True: 0, False: 157]
  ------------------
   86|      0|        return LIBSPDM_STATUS_INVALID_MSG_SIZE;
  ------------------
  |  |   94|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0006)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
   87|      0|    }
   88|    157|    if (spdm_response->header.spdm_version != libspdm_get_connection_version (spdm_context)) {
  ------------------
  |  Branch (88:9): [True: 61, False: 96]
  ------------------
   89|     61|        return LIBSPDM_STATUS_INVALID_MSG_FIELD;
  ------------------
  |  |   90|     61|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0005)
  |  |  ------------------
  |  |  |  |   55|     61|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
   90|     61|    }
   91|     96|    if (spdm_response->header.request_response_code == SPDM_ERROR) {
  ------------------
  |  |   37|     96|#define SPDM_ERROR 0x7F
  ------------------
  |  Branch (91:9): [True: 16, False: 80]
  ------------------
   92|     16|        status = libspdm_handle_encap_error_response_main(
   93|     16|            spdm_context,
   94|     16|            spdm_response->header.param1);
   95|     16|        if (LIBSPDM_STATUS_IS_ERROR(status)) {
  ------------------
  |  |   30|     16|    (LIBSPDM_STATUS_SEVERITY(status) == LIBSPDM_SEVERITY_ERROR)
  |  |  ------------------
  |  |  |  |   37|     16|#define LIBSPDM_STATUS_SEVERITY(status) (((status) >> 28) & 0xf)
  |  |  ------------------
  |  |                   (LIBSPDM_STATUS_SEVERITY(status) == LIBSPDM_SEVERITY_ERROR)
  |  |  ------------------
  |  |  |  |   44|     16|#define LIBSPDM_SEVERITY_ERROR 0x8
  |  |  ------------------
  |  |  |  Branch (30:5): [True: 16, False: 0]
  |  |  ------------------
  ------------------
   96|     16|            return status;
   97|     16|        }
   98|     80|    } else if (spdm_response->header.request_response_code !=
  ------------------
  |  Branch (98:16): [True: 17, False: 63]
  ------------------
   99|     80|               SPDM_DIGESTS) {
  ------------------
  |  |   29|     80|#define SPDM_DIGESTS 0x01
  ------------------
  100|     17|        return LIBSPDM_STATUS_INVALID_MSG_FIELD;
  ------------------
  |  |   90|     17|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0005)
  |  |  ------------------
  |  |  |  |   55|     17|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  101|     17|    }
  102|     63|    if (spdm_response_size < sizeof(spdm_digest_response_t)) {
  ------------------
  |  Branch (102:9): [True: 0, False: 63]
  ------------------
  103|      0|        return LIBSPDM_STATUS_INVALID_MSG_SIZE;
  ------------------
  |  |   94|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0006)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  104|      0|    }
  105|       |
  106|     63|    LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "provisioned_slot_mask - 0x%02x\n",
  107|     63|                   spdm_response->header.param2));
  108|     63|    if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
  ------------------
  |  |  113|     63|#define SPDM_MESSAGE_VERSION_13 0x13
  ------------------
  |  Branch (108:9): [True: 0, False: 63]
  ------------------
  109|      0|        LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "supported_slot_mask - 0x%02x\n",
  110|      0|                       spdm_response->header.param1));
  111|      0|        if ((spdm_response->header.param1 & spdm_response->header.param2) !=
  ------------------
  |  Branch (111:13): [True: 0, False: 0]
  ------------------
  112|      0|            spdm_response->header.param2) {
  113|      0|            return LIBSPDM_STATUS_INVALID_MSG_FIELD;
  ------------------
  |  |   90|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0005)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  114|      0|        }
  115|      0|    }
  116|       |
  117|     63|    digest_size = libspdm_get_hash_size(
  118|     63|        spdm_context->connection_info.algorithm.base_hash_algo);
  119|     63|    digest_count = 0;
  120|    567|    for (index = 0; index < SPDM_MAX_SLOT_COUNT; index++) {
  ------------------
  |  |   18|    567|#define SPDM_MAX_SLOT_COUNT 8
  ------------------
  |  Branch (120:21): [True: 504, False: 63]
  ------------------
  121|    504|        if (spdm_response->header.param2 & (1 << index)) {
  ------------------
  |  Branch (121:13): [True: 260, False: 244]
  ------------------
  122|    260|            digest_count++;
  123|    260|        }
  124|    504|    }
  125|     63|    if (digest_count == 0) {
  ------------------
  |  Branch (125:9): [True: 1, False: 62]
  ------------------
  126|      1|        return LIBSPDM_STATUS_INVALID_MSG_FIELD;
  ------------------
  |  |   90|      1|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0005)
  |  |  ------------------
  |  |  |  |   55|      1|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  127|      1|    }
  128|       |
  129|     62|    additional_size = 0;
  130|     62|    if ((spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_13) &&
  ------------------
  |  |  113|     62|#define SPDM_MESSAGE_VERSION_13 0x13
  ------------------
  |  Branch (130:9): [True: 0, False: 62]
  ------------------
  131|     62|        spdm_context->connection_info.multi_key_conn_req) {
  ------------------
  |  Branch (131:9): [True: 0, False: 0]
  ------------------
  132|      0|        additional_size = sizeof(spdm_key_pair_id_t) + sizeof(spdm_certificate_info_t) +
  133|      0|                          sizeof(spdm_key_usage_bit_mask_t);
  134|      0|    }
  135|     62|    if (spdm_response_size <
  ------------------
  |  Branch (135:9): [True: 20, False: 42]
  ------------------
  136|     62|        sizeof(spdm_digest_response_t) + digest_count * (digest_size + additional_size)) {
  137|     20|        return LIBSPDM_STATUS_INVALID_MSG_SIZE;
  ------------------
  |  |   94|     20|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0006)
  |  |  ------------------
  |  |  |  |   55|     20|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  138|     20|    }
  139|     42|    spdm_response_size =
  140|     42|        sizeof(spdm_digest_response_t) + digest_count * (digest_size + additional_size);
  141|       |
  142|       |    /* Cache data*/
  143|       |
  144|     42|    status = libspdm_append_message_mut_b(spdm_context, spdm_response,
  145|     42|                                          spdm_response_size);
  146|     42|    if (LIBSPDM_STATUS_IS_ERROR(status)) {
  ------------------
  |  |   30|     42|    (LIBSPDM_STATUS_SEVERITY(status) == LIBSPDM_SEVERITY_ERROR)
  |  |  ------------------
  |  |  |  |   37|     42|#define LIBSPDM_STATUS_SEVERITY(status) (((status) >> 28) & 0xf)
  |  |  ------------------
  |  |                   (LIBSPDM_STATUS_SEVERITY(status) == LIBSPDM_SEVERITY_ERROR)
  |  |  ------------------
  |  |  |  |   44|     42|#define LIBSPDM_SEVERITY_ERROR 0x8
  |  |  ------------------
  |  |  |  Branch (30:5): [True: 0, False: 42]
  |  |  ------------------
  ------------------
  147|      0|        return LIBSPDM_STATUS_BUFFER_FULL;
  ------------------
  |  |  118|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x000c)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  148|      0|    }
  149|       |
  150|     42|    if (spdm_context->last_spdm_request_session_id_valid) {
  ------------------
  |  Branch (150:9): [True: 0, False: 42]
  ------------------
  151|      0|        session_id = spdm_context->last_spdm_request_session_id;
  152|     42|    } else {
  153|     42|        session_id = spdm_context->latest_session_id;
  154|     42|    }
  155|     42|    if (session_id != INVALID_SESSION_ID) {
  ------------------
  |  |   28|     42|#define INVALID_SESSION_ID 0
  ------------------
  |  Branch (155:9): [True: 0, False: 42]
  ------------------
  156|      0|        session_info = libspdm_get_session_info_via_session_id(spdm_context, session_id);
  157|     42|    } else {
  158|     42|        session_info = NULL;
  159|     42|    }
  160|     42|    if (session_info != NULL) {
  ------------------
  |  Branch (160:9): [True: 0, False: 42]
  ------------------
  161|      0|        if (spdm_context->connection_info.multi_key_conn_req) {
  ------------------
  |  Branch (161:13): [True: 0, False: 0]
  ------------------
  162|      0|            status = libspdm_append_message_encap_d(spdm_context, session_info, false,
  163|      0|                                                    spdm_response, spdm_response_size);
  164|      0|            if (LIBSPDM_STATUS_IS_ERROR(status)) {
  ------------------
  |  |   30|      0|    (LIBSPDM_STATUS_SEVERITY(status) == LIBSPDM_SEVERITY_ERROR)
  |  |  ------------------
  |  |  |  |   37|      0|#define LIBSPDM_STATUS_SEVERITY(status) (((status) >> 28) & 0xf)
  |  |  ------------------
  |  |                   (LIBSPDM_STATUS_SEVERITY(status) == LIBSPDM_SEVERITY_ERROR)
  |  |  ------------------
  |  |  |  |   44|      0|#define LIBSPDM_SEVERITY_ERROR 0x8
  |  |  ------------------
  |  |  |  Branch (30:5): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  165|      0|                return LIBSPDM_STATUS_BUFFER_FULL;
  ------------------
  |  |  118|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x000c)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  166|      0|            }
  167|      0|        }
  168|      0|    }
  169|       |
  170|     42|    key_pair_id =
  171|     42|        (spdm_key_pair_id_t *)((size_t)(spdm_response + 1) + digest_size * digest_count);
  172|     42|    cert_info =
  173|     42|        (spdm_certificate_info_t *)((uint8_t *)key_pair_id + sizeof(spdm_key_pair_id_t) *
  174|     42|                                    digest_count);
  175|     42|    key_usage_bit_mask =
  176|     42|        (spdm_key_usage_bit_mask_t *)((uint8_t *)cert_info + sizeof(spdm_certificate_info_t) *
  177|     42|                                      digest_count);
  178|    201|    for (index = 0; index < digest_count; index++) {
  ------------------
  |  Branch (178:21): [True: 159, False: 42]
  ------------------
  179|    159|        LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "digest (0x%zx) - ", index));
  180|    159|        LIBSPDM_INTERNAL_DUMP_DATA(
  181|    159|            (const uint8_t *)(spdm_response + 1) + (digest_size * index), digest_size);
  182|    159|        LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
  183|    159|    }
  184|     42|    if ((spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_13) &&
  ------------------
  |  |  113|     42|#define SPDM_MESSAGE_VERSION_13 0x13
  ------------------
  |  Branch (184:9): [True: 0, False: 42]
  ------------------
  185|     42|        spdm_context->connection_info.multi_key_conn_req) {
  ------------------
  |  Branch (185:9): [True: 0, False: 0]
  ------------------
  186|      0|        for (index = 0; index < digest_count; index++) {
  ------------------
  |  Branch (186:25): [True: 0, False: 0]
  ------------------
  187|      0|            LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "key_pair_id (0x%zx) - 0x%02x\n", index,
  188|      0|                           key_pair_id[index]));
  189|      0|        }
  190|      0|        for (index = 0; index < digest_count; index++) {
  ------------------
  |  Branch (190:25): [True: 0, False: 0]
  ------------------
  191|      0|            LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "cert_info (0x%zx) - 0x%02x\n", index,
  192|      0|                           cert_info[index]));
  193|      0|        }
  194|      0|        for (index = 0; index < digest_count; index++) {
  ------------------
  |  Branch (194:25): [True: 0, False: 0]
  ------------------
  195|      0|            LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "key_usage_bit_mask (0x%zx) - 0x%04x\n", index,
  196|      0|                           key_usage_bit_mask[index]));
  197|      0|        }
  198|      0|    }
  199|       |
  200|     42|    spdm_context->connection_info.peer_provisioned_slot_mask = spdm_response->header.param2;
  201|     42|    if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
  ------------------
  |  |  113|     42|#define SPDM_MESSAGE_VERSION_13 0x13
  ------------------
  |  Branch (201:9): [True: 0, False: 42]
  ------------------
  202|      0|        spdm_context->connection_info.peer_supported_slot_mask = spdm_response->header.param1;
  203|     42|    } else {
  204|     42|        spdm_context->connection_info.peer_supported_slot_mask = spdm_response->header.param2;
  205|     42|    }
  206|     42|    libspdm_copy_mem(
  207|     42|        spdm_context->connection_info.peer_total_digest_buffer,
  208|     42|        sizeof(spdm_context->connection_info.peer_total_digest_buffer),
  209|     42|        spdm_response + 1, digest_size * digest_count);
  210|     42|    libspdm_zero_mem(spdm_context->connection_info.peer_key_pair_id,
  211|     42|                     sizeof(spdm_context->connection_info.peer_key_pair_id));
  212|     42|    libspdm_zero_mem(spdm_context->connection_info.peer_cert_info,
  213|     42|                     sizeof(spdm_context->connection_info.peer_cert_info));
  214|     42|    libspdm_zero_mem(spdm_context->connection_info.peer_key_usage_bit_mask,
  215|     42|                     sizeof(spdm_context->connection_info.peer_key_usage_bit_mask));
  216|     42|    if ((spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_13) &&
  ------------------
  |  |  113|     42|#define SPDM_MESSAGE_VERSION_13 0x13
  ------------------
  |  Branch (216:9): [True: 0, False: 42]
  ------------------
  217|     42|        spdm_context->connection_info.multi_key_conn_req) {
  ------------------
  |  Branch (217:9): [True: 0, False: 0]
  ------------------
  218|      0|        slot_index = 0;
  219|      0|        for (index = 0; index < SPDM_MAX_SLOT_COUNT; index++) {
  ------------------
  |  |   18|      0|#define SPDM_MAX_SLOT_COUNT 8
  ------------------
  |  Branch (219:25): [True: 0, False: 0]
  ------------------
  220|      0|            if (spdm_response->header.param2 & (1 << index)) {
  ------------------
  |  Branch (220:17): [True: 0, False: 0]
  ------------------
  221|      0|                spdm_context->connection_info.peer_key_pair_id[index] = key_pair_id[slot_index];
  222|      0|                cert_model = cert_info[slot_index] & SPDM_CERTIFICATE_INFO_CERT_MODEL_MASK;
  ------------------
  |  |  596|      0|#define SPDM_CERTIFICATE_INFO_CERT_MODEL_MASK 0x7
  ------------------
  223|      0|                if (cert_model > SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT) {
  ------------------
  |  |  600|      0|#define SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT 0x3
  ------------------
  |  Branch (223:21): [True: 0, False: 0]
  ------------------
  224|      0|                    return LIBSPDM_STATUS_INVALID_MSG_FIELD;
  ------------------
  |  |   90|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0005)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  225|      0|                }
  226|      0|                if (index == 0) {
  ------------------
  |  Branch (226:21): [True: 0, False: 0]
  ------------------
  227|      0|                    if (cert_model == SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT) {
  ------------------
  |  |  600|      0|#define SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT 0x3
  ------------------
  |  Branch (227:25): [True: 0, False: 0]
  ------------------
  228|      0|                        return LIBSPDM_STATUS_INVALID_MSG_FIELD;
  ------------------
  |  |   90|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0005)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  229|      0|                    }
  230|      0|                    if ((key_usage_bit_mask[slot_index] &
  ------------------
  |  Branch (230:25): [True: 0, False: 0]
  ------------------
  231|      0|                         (SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE |
  ------------------
  |  |  603|      0|#define SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE 0x0001
  ------------------
  232|      0|                          SPDM_KEY_USAGE_BIT_MASK_CHALLENGE_USE |
  ------------------
  |  |  604|      0|#define SPDM_KEY_USAGE_BIT_MASK_CHALLENGE_USE 0x0002
  ------------------
  233|      0|                          SPDM_KEY_USAGE_BIT_MASK_MEASUREMENT_USE |
  ------------------
  |  |  605|      0|#define SPDM_KEY_USAGE_BIT_MASK_MEASUREMENT_USE 0x0004
  ------------------
  234|      0|                          SPDM_KEY_USAGE_BIT_MASK_ENDPOINT_INFO_USE)) == 0) {
  ------------------
  |  |  606|      0|#define SPDM_KEY_USAGE_BIT_MASK_ENDPOINT_INFO_USE 0x0008
  ------------------
  235|      0|                        return LIBSPDM_STATUS_INVALID_MSG_FIELD;
  ------------------
  |  |   90|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0005)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  236|      0|                    }
  237|      0|                }
  238|      0|                if ((cert_model == SPDM_CERTIFICATE_INFO_CERT_MODEL_NONE) &&
  ------------------
  |  |  597|      0|#define SPDM_CERTIFICATE_INFO_CERT_MODEL_NONE 0x0
  ------------------
  |  Branch (238:21): [True: 0, False: 0]
  ------------------
  239|      0|                    (!libspdm_consttime_is_mem_equal(
  ------------------
  |  Branch (239:21): [True: 0, False: 0]
  ------------------
  240|      0|                         (const uint8_t *)(spdm_response + 1) + digest_size * slot_index,
  241|      0|                         zero_digest,
  242|      0|                         digest_size))) {
  243|      0|                    return LIBSPDM_STATUS_INVALID_MSG_FIELD;
  ------------------
  |  |   90|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0005)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  244|      0|                }
  245|      0|                spdm_context->connection_info.peer_cert_info[index] = cert_model;
  246|      0|                spdm_context->connection_info.peer_key_usage_bit_mask[index] =
  247|      0|                    key_usage_bit_mask[slot_index];
  248|      0|                slot_index++;
  249|      0|            }
  250|      0|        }
  251|      0|    }
  252|       |
  253|     42|    *need_continue = false;
  254|       |
  255|     42|    return LIBSPDM_STATUS_SUCCESS;
  ------------------
  |  |   59|     42|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_SUCCESS, LIBSPDM_SOURCE_SUCCESS, 0x0000)
  |  |  ------------------
  |  |  |  |   55|     42|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  256|     42|}

libspdm_handle_encap_error_response_main:
  429|     16|{
  430|     16|    if (error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) {
  ------------------
  |  |  861|     16|#define SPDM_ERROR_CODE_RESPONSE_NOT_READY 0x42
  ------------------
  |  Branch (430:9): [True: 1, False: 15]
  ------------------
  431|      1|        return LIBSPDM_STATUS_NOT_READY_PEER;
  ------------------
  |  |  106|      1|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0009)
  |  |  ------------------
  |  |  |  |   55|      1|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  432|      1|    }
  433|       |
  434|     15|    return LIBSPDM_STATUS_UNSUPPORTED_CAP;
  ------------------
  |  |   78|     15|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0002)
  |  |  ------------------
  |  |  |  |   55|     15|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  435|     16|}

libspdm_secured_message_get_context_size:
   15|    628|{
   16|    628|    return sizeof(libspdm_secured_message_context_t);
   17|    628|}
libspdm_secured_message_init_context:
   27|  1.25k|{
   28|  1.25k|    libspdm_secured_message_context_t *secured_message_context;
   29|       |
   30|  1.25k|    secured_message_context = spdm_secured_message_context;
   31|  1.25k|    libspdm_zero_mem(secured_message_context, sizeof(libspdm_secured_message_context_t));
   32|  1.25k|}

libspdm_sha256_new:
   23|    199|{
   24|    199|    void *hmac_md_ctx;
   25|       |
   26|    199|    hmac_md_ctx = allocate_zero_pool(sizeof(mbedtls_sha256_context));
   27|    199|    if (hmac_md_ctx == NULL) {
  ------------------
  |  Branch (27:9): [True: 0, False: 199]
  ------------------
   28|      0|        return NULL;
   29|      0|    }
   30|       |
   31|    199|    return hmac_md_ctx;
   32|    199|}
libspdm_sha256_free:
   41|    199|{
   42|    199|    mbedtls_sha256_free(sha256_ctx);
   43|    199|    free_pool (sha256_ctx);
   44|    199|}
libspdm_sha256_init:
   59|    199|{
   60|    199|    int ret;
   61|       |
   62|    199|    if (sha256_context == NULL) {
  ------------------
  |  Branch (62:9): [True: 0, False: 199]
  ------------------
   63|      0|        return false;
   64|      0|    }
   65|       |
   66|    199|    mbedtls_sha256_init(sha256_context);
   67|       |
   68|    199|    ret = mbedtls_sha256_starts(sha256_context, false);
   69|    199|    if (ret != 0) {
  ------------------
  |  Branch (69:9): [True: 0, False: 199]
  ------------------
   70|      0|        return false;
   71|      0|    }
   72|    199|    return true;
   73|    199|}
libspdm_sha256_update:
  120|    199|{
  121|    199|    int ret;
  122|       |
  123|    199|    if (sha256_context == NULL) {
  ------------------
  |  Branch (123:9): [True: 0, False: 199]
  ------------------
  124|      0|        return false;
  125|      0|    }
  126|       |
  127|    199|    if (data == NULL && data_size != 0) {
  ------------------
  |  Branch (127:9): [True: 0, False: 199]
  |  Branch (127:25): [True: 0, False: 0]
  ------------------
  128|      0|        return false;
  129|      0|    }
  130|    199|    if (data_size > INT_MAX) {
  ------------------
  |  Branch (130:9): [True: 0, False: 199]
  ------------------
  131|      0|        return false;
  132|      0|    }
  133|       |
  134|    199|    ret = mbedtls_sha256_update(sha256_context, data, data_size);
  135|    199|    if (ret != 0) {
  ------------------
  |  Branch (135:9): [True: 0, False: 199]
  ------------------
  136|      0|        return false;
  137|      0|    }
  138|    199|    return true;
  139|    199|}
libspdm_sha256_hash_all:
  197|    157|{
  198|    157|    int ret;
  199|       |
  200|    157|    if (hash_value == NULL) {
  ------------------
  |  Branch (200:9): [True: 0, False: 157]
  ------------------
  201|      0|        return false;
  202|      0|    }
  203|    157|    if (data == NULL && data_size != 0) {
  ------------------
  |  Branch (203:9): [True: 0, False: 157]
  |  Branch (203:25): [True: 0, False: 0]
  ------------------
  204|      0|        return false;
  205|      0|    }
  206|    157|    if (data_size > INT_MAX) {
  ------------------
  |  Branch (206:9): [True: 0, False: 157]
  ------------------
  207|      0|        return false;
  208|      0|    }
  209|       |
  210|    157|    ret = mbedtls_sha256(data, data_size, hash_value, false);
  211|    157|    if (ret != 0) {
  ------------------
  |  Branch (211:9): [True: 0, False: 157]
  ------------------
  212|      0|        return false;
  213|      0|    }
  214|    157|    return true;
  215|    157|}

libspdm_ec_free:
   75|    157|{
   76|    157|    mbedtls_ecdh_free(ec_context);
   77|    157|    free_pool(ec_context);
   78|    157|}

libspdm_asn1_get_tag:
  245|  2.98k|{
  246|  2.98k|    if (mbedtls_asn1_get_tag(ptr, end, length, (int32_t)tag) == 0) {
  ------------------
  |  Branch (246:9): [True: 2.98k, False: 0]
  ------------------
  247|  2.98k|        return true;
  248|  2.98k|    } else {
  249|      0|        return false;
  250|      0|    }
  251|  2.98k|}
libspdm_x509_get_subject_name:
  273|    157|{
  274|    157|    mbedtls_x509_crt crt;
  275|    157|    int ret;
  276|    157|    bool status;
  277|       |
  278|       |    /* Check input parameters.*/
  279|    157|    if (cert == NULL || cert == 0 || subject_size == NULL) {
  ------------------
  |  Branch (279:9): [True: 0, False: 157]
  |  Branch (279:25): [True: 0, False: 157]
  |  Branch (279:38): [True: 0, False: 157]
  ------------------
  280|      0|        if (subject_size != NULL) {
  ------------------
  |  Branch (280:13): [True: 0, False: 0]
  ------------------
  281|      0|            *subject_size = 0;
  282|      0|        }
  283|      0|        return false;
  284|      0|    }
  285|       |
  286|    157|    status = false;
  287|       |
  288|    157|    mbedtls_x509_crt_init(&crt);
  289|       |
  290|    157|    ret = mbedtls_x509_crt_parse_der(&crt, cert, cert_size);
  291|       |
  292|    157|    if (ret == 0) {
  ------------------
  |  Branch (292:9): [True: 157, False: 0]
  ------------------
  293|    157|        if (*subject_size < crt.subject_raw.len) {
  ------------------
  |  Branch (293:13): [True: 157, False: 0]
  ------------------
  294|    157|            *subject_size = crt.subject_raw.len;
  295|    157|            status = false;
  296|    157|            goto cleanup;
  297|    157|        }
  298|      0|        if (cert_subject != NULL) {
  ------------------
  |  Branch (298:13): [True: 0, False: 0]
  ------------------
  299|      0|            libspdm_copy_mem(cert_subject, *subject_size,
  300|      0|                             crt.subject_raw.p, crt.subject_raw.len);
  301|      0|        }
  302|      0|        *subject_size = crt.subject_raw.len;
  303|      0|        status = true;
  304|      0|    } else {
  305|      0|        *subject_size = 0;
  306|      0|    }
  307|       |
  308|    157|cleanup:
  309|    157|    mbedtls_x509_crt_free(&crt);
  310|       |
  311|    157|    return status;
  312|    157|}
libspdm_ec_get_public_key_from_x509:
  545|    157|{
  546|    157|    mbedtls_x509_crt crt;
  547|    157|    mbedtls_ecdh_context *ecdh;
  548|    157|    int ret;
  549|       |
  550|    157|    mbedtls_x509_crt_init(&crt);
  551|       |
  552|    157|    if (mbedtls_x509_crt_parse_der(&crt, cert, cert_size) != 0) {
  ------------------
  |  Branch (552:9): [True: 0, False: 157]
  ------------------
  553|      0|        return false;
  554|      0|    }
  555|       |
  556|    157|    if (mbedtls_pk_get_type(&crt.pk) != MBEDTLS_PK_ECKEY) {
  ------------------
  |  Branch (556:9): [True: 0, False: 157]
  ------------------
  557|      0|        mbedtls_x509_crt_free(&crt);
  558|      0|        return false;
  559|      0|    }
  560|       |
  561|    157|    ecdh = allocate_zero_pool(sizeof(mbedtls_ecdh_context));
  562|    157|    if (ecdh == NULL) {
  ------------------
  |  Branch (562:9): [True: 0, False: 157]
  ------------------
  563|      0|        mbedtls_x509_crt_free(&crt);
  564|      0|        return false;
  565|      0|    }
  566|    157|    mbedtls_ecdh_init(ecdh);
  567|       |
  568|    157|    ret = mbedtls_ecdh_get_params(ecdh, mbedtls_pk_ec(crt.pk),
  569|    157|                                  MBEDTLS_ECDH_OURS);
  570|    157|    if (ret != 0) {
  ------------------
  |  Branch (570:9): [True: 0, False: 157]
  ------------------
  571|      0|        mbedtls_ecdh_free(ecdh);
  572|      0|        free_pool(ecdh);
  573|      0|        mbedtls_x509_crt_free(&crt);
  574|      0|        return false;
  575|      0|    }
  576|    157|    mbedtls_x509_crt_free(&crt);
  577|       |
  578|    157|    *ec_context = ecdh;
  579|    157|    return true;
  580|    157|}
libspdm_x509_verify_cert:
  644|    471|{
  645|    471|    int ret;
  646|    471|    mbedtls_x509_crt ca, end;
  647|    471|    uint32_t v_flag = 0;
  648|    471|    mbedtls_x509_crt_profile profile = { 0 };
  649|       |
  650|    471|    if (cert == NULL || ca_cert == NULL) {
  ------------------
  |  Branch (650:9): [True: 0, False: 471]
  |  Branch (650:25): [True: 0, False: 471]
  ------------------
  651|      0|        return false;
  652|      0|    }
  653|       |
  654|    471|    libspdm_copy_mem(&profile, sizeof(profile),
  655|    471|                     &mbedtls_x509_crt_profile_default,
  656|    471|                     sizeof(mbedtls_x509_crt_profile));
  657|       |
  658|    471|    mbedtls_x509_crt_init(&ca);
  659|    471|    mbedtls_x509_crt_init(&end);
  660|       |
  661|    471|    ret = mbedtls_x509_crt_parse_der(&ca, ca_cert, ca_cert_size);
  662|       |
  663|    471|    if (ret == 0) {
  ------------------
  |  Branch (663:9): [True: 471, False: 0]
  ------------------
  664|    471|        ret = mbedtls_x509_crt_parse_der(&end, cert, cert_size);
  665|    471|    }
  666|       |
  667|    471|    if (ret == 0) {
  ------------------
  |  Branch (667:9): [True: 471, False: 0]
  ------------------
  668|    471|        ret = mbedtls_x509_crt_verify_with_profile(
  669|    471|            &end, &ca, NULL, &profile, NULL, &v_flag, NULL, NULL);
  670|    471|    }
  671|       |
  672|    471|    mbedtls_x509_crt_free(&ca);
  673|    471|    mbedtls_x509_crt_free(&end);
  674|       |
  675|    471|    return ret == 0;
  676|    471|}
libspdm_x509_verify_cert_chain:
  698|    157|{
  699|    157|    size_t asn1_len;
  700|    157|    size_t preceding_cert_len;
  701|    157|    const uint8_t *preceding_cert;
  702|    157|    size_t current_cert_len;
  703|    157|    const unsigned char *current_cert;
  704|    157|    const unsigned char *tmp_ptr;
  705|    157|    int ret;
  706|    157|    bool verify_flag;
  707|       |
  708|    157|    verify_flag = false;
  709|    157|    preceding_cert = root_cert;
  710|    157|    preceding_cert_len = root_cert_length;
  711|       |
  712|    157|    current_cert = (const unsigned char *)cert_chain;
  713|       |
  714|       |
  715|       |    /* Get Current certificate from certificates buffer and Verify with preceding cert*/
  716|       |
  717|    628|    do {
  718|    628|        tmp_ptr = current_cert;
  719|    628|        ret = mbedtls_asn1_get_tag(
  720|    628|            &tmp_ptr, cert_chain + cert_chain_length, &asn1_len,
  721|    628|            MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE);
  ------------------
  |  |   82|    628|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                          MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE);
  ------------------
  |  |   72|    628|#define MBEDTLS_ASN1_SEQUENCE                0x10
  ------------------
  722|    628|        if (ret != 0) {
  ------------------
  |  Branch (722:13): [True: 157, False: 471]
  ------------------
  723|    157|            if (current_cert < cert_chain + cert_chain_length) {
  ------------------
  |  Branch (723:17): [True: 0, False: 157]
  ------------------
  724|      0|                verify_flag = false;
  725|      0|            }
  726|    157|            break;
  727|    157|        }
  728|       |
  729|    471|        current_cert_len = asn1_len + (tmp_ptr - current_cert);
  730|       |
  731|    471|        if (current_cert + current_cert_len > cert_chain + cert_chain_length) {
  ------------------
  |  Branch (731:13): [True: 0, False: 471]
  ------------------
  732|      0|            verify_flag = false;
  733|      0|            break;
  734|      0|        }
  735|       |
  736|    471|        if (libspdm_x509_verify_cert(current_cert, current_cert_len,
  ------------------
  |  Branch (736:13): [True: 0, False: 471]
  ------------------
  737|    471|                                     preceding_cert,
  738|    471|                                     preceding_cert_len) == false) {
  739|      0|            verify_flag = false;
  740|      0|            break;
  741|    471|        } else {
  742|    471|            verify_flag = true;
  743|    471|        }
  744|       |
  745|       |
  746|       |        /* Save preceding certificate*/
  747|       |
  748|    471|        preceding_cert = current_cert;
  749|    471|        preceding_cert_len = current_cert_len;
  750|       |
  751|       |
  752|       |        /* Move current certificate to next;*/
  753|       |
  754|    471|        current_cert = current_cert + current_cert_len;
  755|    471|    } while (true);
  756|       |
  757|      0|    return verify_flag;
  758|    157|}
libspdm_x509_get_cert_from_cert_chain:
  782|    471|{
  783|    471|    size_t asn1_len;
  784|    471|    int32_t current_index;
  785|    471|    size_t current_cert_len;
  786|    471|    const unsigned char *current_cert;
  787|    471|    const unsigned char *tmp_ptr;
  788|    471|    int ret;
  789|       |
  790|    471|    current_cert_len = 0;
  791|       |
  792|       |    /* Check input parameters.*/
  793|       |
  794|    471|    if ((cert_chain == NULL) || (cert == NULL) || (cert_index < -1) ||
  ------------------
  |  Branch (794:9): [True: 0, False: 471]
  |  Branch (794:33): [True: 0, False: 471]
  |  Branch (794:51): [True: 0, False: 471]
  ------------------
  795|    471|        (cert_length == NULL)) {
  ------------------
  |  Branch (795:9): [True: 0, False: 471]
  ------------------
  796|      0|        return false;
  797|      0|    }
  798|       |
  799|    471|    current_cert = (const unsigned char *)cert_chain;
  800|    471|    current_index = -1;
  801|       |
  802|       |
  803|       |    /* Traverse the certificate chain*/
  804|       |
  805|    942|    while (true) {
  806|       |
  807|       |        /* Get asn1 tag len*/
  808|       |
  809|    942|        tmp_ptr = current_cert;
  810|    942|        ret = mbedtls_asn1_get_tag(
  811|    942|            &tmp_ptr, cert_chain + cert_chain_length, &asn1_len,
  812|    942|            MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE);
  ------------------
  |  |   82|    942|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                          MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE);
  ------------------
  |  |   72|    942|#define MBEDTLS_ASN1_SEQUENCE                0x10
  ------------------
  813|    942|        if (ret != 0) {
  ------------------
  |  Branch (813:13): [True: 157, False: 785]
  ------------------
  814|    157|            break;
  815|    157|        }
  816|       |
  817|    785|        current_cert_len = asn1_len + (tmp_ptr - current_cert);
  818|    785|        if (current_cert + current_cert_len > cert_chain + cert_chain_length) {
  ------------------
  |  Branch (818:13): [True: 0, False: 785]
  ------------------
  819|      0|            return false;
  820|      0|        }
  821|       |
  822|    785|        current_index++;
  823|       |
  824|    785|        if (current_index == cert_index) {
  ------------------
  |  Branch (824:13): [True: 314, False: 471]
  ------------------
  825|    314|            *cert = current_cert;
  826|    314|            *cert_length = current_cert_len;
  827|    314|            return true;
  828|    314|        }
  829|       |
  830|       |
  831|       |        /* Move to next*/
  832|       |
  833|    471|        current_cert = current_cert + current_cert_len;
  834|    471|    }
  835|       |
  836|       |
  837|       |    /* If cert_index is -1, Return the last certificate*/
  838|       |
  839|    157|    if (cert_index == -1 && current_index >= 0) {
  ------------------
  |  Branch (839:9): [True: 157, False: 0]
  |  Branch (839:29): [True: 157, False: 0]
  ------------------
  840|    157|        *cert = current_cert - current_cert_len;
  841|    157|        *cert_length = current_cert_len;
  842|    157|        return true;
  843|    157|    }
  844|       |
  845|      0|    return false;
  846|    157|}
libspdm_x509_get_version:
  888|    157|{
  889|    157|    mbedtls_x509_crt crt;
  890|    157|    int ret;
  891|    157|    bool status;
  892|       |
  893|    157|    if (cert == NULL) {
  ------------------
  |  Branch (893:9): [True: 0, False: 157]
  ------------------
  894|      0|        return false;
  895|      0|    }
  896|       |
  897|    157|    status = false;
  898|       |
  899|    157|    mbedtls_x509_crt_init(&crt);
  900|       |
  901|    157|    ret = mbedtls_x509_crt_parse_der(&crt, cert, cert_size);
  902|       |
  903|    157|    if (ret == 0) {
  ------------------
  |  Branch (903:9): [True: 157, False: 0]
  ------------------
  904|    157|        *version = crt.version - 1;
  905|    157|        status = true;
  906|    157|    }
  907|       |
  908|    157|    mbedtls_x509_crt_free(&crt);
  909|       |
  910|    157|    return status;
  911|    157|}
libspdm_x509_get_serial_number:
  939|    157|{
  940|    157|    mbedtls_x509_crt crt;
  941|    157|    int ret;
  942|    157|    bool status;
  943|       |
  944|    157|    if (cert == NULL) {
  ------------------
  |  Branch (944:9): [True: 0, False: 157]
  ------------------
  945|      0|        return false;
  946|      0|    }
  947|       |
  948|    157|    status = false;
  949|       |
  950|    157|    mbedtls_x509_crt_init(&crt);
  951|       |
  952|    157|    ret = mbedtls_x509_crt_parse_der(&crt, cert, cert_size);
  953|       |
  954|    157|    if (ret == 0) {
  ------------------
  |  Branch (954:9): [True: 157, False: 0]
  ------------------
  955|    157|        if (*serial_number_size <= crt.serial.len) {
  ------------------
  |  Branch (955:13): [True: 157, False: 0]
  ------------------
  956|    157|            *serial_number_size = crt.serial.len + 1;
  957|    157|            status = false;
  958|    157|            goto cleanup;
  959|    157|        }
  960|      0|        if (serial_number != NULL) {
  ------------------
  |  Branch (960:13): [True: 0, False: 0]
  ------------------
  961|      0|            libspdm_copy_mem(serial_number, *serial_number_size, crt.serial.p, crt.serial.len);
  962|      0|            serial_number[crt.serial.len] = '\0';
  963|      0|        }
  964|      0|        *serial_number_size = crt.serial.len + 1;
  965|      0|        status = true;
  966|      0|    }
  967|    157|cleanup:
  968|    157|    mbedtls_x509_crt_free(&crt);
  969|       |
  970|    157|    return status;
  971|    157|}
libspdm_x509_get_issuer_name:
  995|    157|{
  996|    157|    mbedtls_x509_crt crt;
  997|    157|    int ret;
  998|    157|    bool status;
  999|       |
 1000|       |    /* Check input parameters.*/
 1001|    157|    if (cert == NULL || cert_size == 0 || issuer_size == NULL) {
  ------------------
  |  Branch (1001:9): [True: 0, False: 157]
  |  Branch (1001:25): [True: 0, False: 157]
  |  Branch (1001:43): [True: 0, False: 157]
  ------------------
 1002|      0|        if (issuer_size != NULL) {
  ------------------
  |  Branch (1002:13): [True: 0, False: 0]
  ------------------
 1003|      0|            *issuer_size = 0;
 1004|      0|        }
 1005|      0|        return false;
 1006|      0|    }
 1007|       |
 1008|    157|    status = false;
 1009|       |
 1010|    157|    mbedtls_x509_crt_init(&crt);
 1011|       |
 1012|    157|    ret = mbedtls_x509_crt_parse_der(&crt, cert, cert_size);
 1013|       |
 1014|    157|    if (ret == 0) {
  ------------------
  |  Branch (1014:9): [True: 157, False: 0]
  ------------------
 1015|    157|        if (*issuer_size < crt.issuer_raw.len) {
  ------------------
  |  Branch (1015:13): [True: 157, False: 0]
  ------------------
 1016|    157|            *issuer_size = crt.issuer_raw.len;
 1017|    157|            status = false;
 1018|    157|            goto cleanup;
 1019|    157|        }
 1020|      0|        if (cert_issuer != NULL) {
  ------------------
  |  Branch (1020:13): [True: 0, False: 0]
  ------------------
 1021|      0|            libspdm_copy_mem(cert_issuer, *issuer_size, crt.issuer_raw.p, crt.issuer_raw.len);
 1022|      0|        }
 1023|      0|        *issuer_size = crt.issuer_raw.len;
 1024|      0|        status = true;
 1025|      0|    } else {
 1026|      0|        *issuer_size = 0;
 1027|      0|    }
 1028|       |
 1029|    157|cleanup:
 1030|    157|    mbedtls_x509_crt_free(&crt);
 1031|       |
 1032|    157|    return status;
 1033|    157|}
libspdm_x509_get_extension_data:
 1267|    471|{
 1268|    471|    mbedtls_x509_crt crt;
 1269|    471|    int ret;
 1270|    471|    bool status;
 1271|    471|    uint8_t *ptr;
 1272|    471|    uint8_t *end;
 1273|    471|    size_t obj_len;
 1274|       |
 1275|    471|    ptr = NULL;
 1276|    471|    end = NULL;
 1277|    471|    obj_len = 0;
 1278|       |
 1279|    471|    if (cert == NULL || cert_size == 0 || oid == NULL || oid_size == 0 ||
  ------------------
  |  Branch (1279:9): [True: 0, False: 471]
  |  Branch (1279:25): [True: 0, False: 471]
  |  Branch (1279:43): [True: 0, False: 471]
  |  Branch (1279:58): [True: 0, False: 471]
  ------------------
 1280|    471|        extension_data_size == NULL) {
  ------------------
  |  Branch (1280:9): [True: 0, False: 471]
  ------------------
 1281|      0|        if (extension_data_size != NULL) {
  ------------------
  |  Branch (1281:13): [True: 0, False: 0]
  ------------------
 1282|      0|            *extension_data_size = 0;
 1283|      0|        }
 1284|      0|        return false;
 1285|      0|    }
 1286|       |
 1287|    471|    status = false;
 1288|       |
 1289|    471|    mbedtls_x509_crt_init(&crt);
 1290|       |
 1291|    471|    ret = mbedtls_x509_crt_parse_der(&crt, cert, cert_size);
 1292|       |
 1293|    471|    if (ret == 0) {
  ------------------
  |  Branch (1293:9): [True: 471, False: 0]
  ------------------
 1294|    471|        ptr = crt.v3_ext.p;
 1295|    471|        end = crt.v3_ext.p + crt.v3_ext.len;
 1296|    471|        ret = mbedtls_asn1_get_tag(&ptr, end, &obj_len,
 1297|    471|                                   MBEDTLS_ASN1_CONSTRUCTED |
  ------------------
  |  |   82|    471|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
 1298|    471|                                   MBEDTLS_ASN1_SEQUENCE);
  ------------------
  |  |   72|    471|#define MBEDTLS_ASN1_SEQUENCE                0x10
  ------------------
 1299|    471|    }
 1300|       |
 1301|    471|    if (ret == 0) {
  ------------------
  |  Branch (1301:9): [True: 471, False: 0]
  ------------------
 1302|    471|        status = libspdm_internal_x509_find_extension_data(
 1303|    471|            ptr, end, oid, oid_size, &ptr, &obj_len);
 1304|    471|        if (!status) {
  ------------------
  |  Branch (1304:13): [True: 0, False: 471]
  ------------------
 1305|      0|            status = true;
 1306|      0|            *extension_data_size = 0;
 1307|      0|            goto cleanup;
 1308|      0|        }
 1309|    471|    }
 1310|       |
 1311|    471|    if (status) {
  ------------------
  |  Branch (1311:9): [True: 471, False: 0]
  ------------------
 1312|    471|        if (*extension_data_size < obj_len) {
  ------------------
  |  Branch (1312:13): [True: 0, False: 471]
  ------------------
 1313|      0|            *extension_data_size = obj_len;
 1314|      0|            status = false;
 1315|      0|            goto cleanup;
 1316|      0|        }
 1317|    471|        if (oid != NULL) {
  ------------------
  |  Branch (1317:13): [True: 471, False: 0]
  ------------------
 1318|    471|            libspdm_copy_mem(extension_data, *extension_data_size, ptr, obj_len);
 1319|    471|        }
 1320|    471|        *extension_data_size = obj_len;
 1321|    471|    } else {
 1322|      0|        *extension_data_size = 0;
 1323|      0|    }
 1324|       |
 1325|    471|cleanup:
 1326|    471|    mbedtls_x509_crt_free(&crt);
 1327|       |
 1328|    471|    return status;
 1329|    471|}
libspdm_x509_get_validity:
 1355|    157|{
 1356|    157|    mbedtls_x509_crt crt;
 1357|    157|    int ret;
 1358|    157|    bool status;
 1359|    157|    size_t t_size;
 1360|    157|    size_t f_size;
 1361|    157|    mbedtls_x509_time zero_time;
 1362|       |
 1363|       |    /* Check input parameters.*/
 1364|    157|    if (cert == NULL || from_size == NULL || to_size == NULL ||
  ------------------
  |  Branch (1364:9): [True: 0, False: 157]
  |  Branch (1364:25): [True: 0, False: 157]
  |  Branch (1364:46): [True: 0, False: 157]
  ------------------
 1365|    157|        cert_size == 0) {
  ------------------
  |  Branch (1365:9): [True: 0, False: 157]
  ------------------
 1366|      0|        if (from_size != NULL) {
  ------------------
  |  Branch (1366:13): [True: 0, False: 0]
  ------------------
 1367|      0|            *from_size = 0;
 1368|      0|        }
 1369|      0|        if (to_size != NULL) {
  ------------------
  |  Branch (1369:13): [True: 0, False: 0]
  ------------------
 1370|      0|            *to_size = 0;
 1371|      0|        }
 1372|      0|        return false;
 1373|      0|    }
 1374|       |
 1375|    157|    status = false;
 1376|       |
 1377|    157|    mbedtls_x509_crt_init(&crt);
 1378|    157|    libspdm_zero_mem(&zero_time, sizeof(mbedtls_x509_time));
 1379|       |
 1380|    157|    ret = mbedtls_x509_crt_parse_der(&crt, cert, cert_size);
 1381|       |
 1382|    157|    if (ret == 0) {
  ------------------
  |  Branch (1382:9): [True: 157, False: 0]
  ------------------
 1383|    157|        f_size = sizeof(mbedtls_x509_time);
 1384|    157|        if ((libspdm_consttime_is_mem_equal(&zero_time, &(crt.valid_from), f_size)) &&
  ------------------
  |  Branch (1384:13): [True: 0, False: 157]
  ------------------
 1385|    157|            (libspdm_consttime_is_mem_equal(&zero_time, &(crt.valid_to), f_size))) {
  ------------------
  |  Branch (1385:13): [True: 0, False: 0]
  ------------------
 1386|      0|            *from_size = 0;
 1387|      0|            *to_size = 0;
 1388|      0|            status = true;
 1389|      0|            goto done;
 1390|      0|        }
 1391|       |
 1392|    157|        if (*from_size < f_size) {
  ------------------
  |  Branch (1392:13): [True: 0, False: 157]
  ------------------
 1393|      0|            *from_size = f_size;
 1394|      0|            goto done;
 1395|      0|        }
 1396|    157|        if (from != NULL) {
  ------------------
  |  Branch (1396:13): [True: 157, False: 0]
  ------------------
 1397|    157|            libspdm_copy_mem(from, *from_size, &(crt.valid_from), f_size);
 1398|    157|        }
 1399|    157|        *from_size = f_size;
 1400|       |
 1401|    157|        t_size = sizeof(mbedtls_x509_time);
 1402|    157|        if (*to_size < t_size) {
  ------------------
  |  Branch (1402:13): [True: 0, False: 157]
  ------------------
 1403|      0|            *to_size = t_size;
 1404|      0|            goto done;
 1405|      0|        }
 1406|    157|        if (to != NULL) {
  ------------------
  |  Branch (1406:13): [True: 157, False: 0]
  ------------------
 1407|    157|            libspdm_copy_mem(to, *to_size, &(crt.valid_to),
 1408|    157|                             sizeof(mbedtls_x509_time));
 1409|    157|        }
 1410|    157|        *to_size = t_size;
 1411|    157|        status = true;
 1412|    157|    } else {
 1413|      0|        *from_size = 0;
 1414|      0|        *to_size = 0;
 1415|      0|    }
 1416|       |
 1417|    157|done:
 1418|    157|    mbedtls_x509_crt_free(&crt);
 1419|       |
 1420|    157|    return status;
 1421|    157|}
libspdm_x509_get_key_usage:
 1436|    157|{
 1437|    157|    mbedtls_x509_crt crt;
 1438|    157|    int ret;
 1439|    157|    bool status;
 1440|       |
 1441|       |    /* Check input parameters.*/
 1442|    157|    if (cert == NULL || cert_size == 0 || usage == NULL) {
  ------------------
  |  Branch (1442:9): [True: 0, False: 157]
  |  Branch (1442:25): [True: 0, False: 157]
  |  Branch (1442:43): [True: 0, False: 157]
  ------------------
 1443|      0|        if (usage != NULL) {
  ------------------
  |  Branch (1443:13): [True: 0, False: 0]
  ------------------
 1444|      0|            *usage = 0;
 1445|      0|        }
 1446|      0|        return false;
 1447|      0|    }
 1448|       |
 1449|    157|    status = false;
 1450|       |
 1451|    157|    mbedtls_x509_crt_init(&crt);
 1452|       |
 1453|    157|    ret = mbedtls_x509_crt_parse_der(&crt, cert, cert_size);
 1454|       |
 1455|    157|    if (ret == 0) {
  ------------------
  |  Branch (1455:9): [True: 157, False: 0]
  ------------------
 1456|    157|        *usage = crt.MBEDTLS_PRIVATE(key_usage);
  ------------------
  |  |   15|    157|#define MBEDTLS_PRIVATE(member) private_##member
  ------------------
 1457|    157|        status = true;
 1458|    157|    } else {
 1459|      0|        *usage = 0;
 1460|      0|    }
 1461|    157|    mbedtls_x509_crt_free(&crt);
 1462|       |
 1463|    157|    return status;
 1464|    157|}
libspdm_x509_get_extended_key_usage:
 1483|    157|{
 1484|    157|    bool status;
 1485|       |
 1486|    157|    if (cert == NULL || cert_size == 0 || usage_size == NULL) {
  ------------------
  |  Branch (1486:9): [True: 0, False: 157]
  |  Branch (1486:25): [True: 0, False: 157]
  |  Branch (1486:43): [True: 0, False: 157]
  ------------------
 1487|      0|        return false;
 1488|      0|    }
 1489|       |
 1490|    157|    status = libspdm_x509_get_extension_data(cert, cert_size,
 1491|    157|                                             m_libspdm_oid_ext_key_usage,
 1492|    157|                                             sizeof(m_libspdm_oid_ext_key_usage), usage,
 1493|    157|                                             usage_size);
 1494|       |
 1495|    157|    return status;
 1496|    157|}
libspdm_x509_get_extended_basic_constraints:
 1516|    157|{
 1517|    157|    bool status;
 1518|       |
 1519|    157|    if (cert == NULL || cert_size == 0 || basic_constraints_size == NULL) {
  ------------------
  |  Branch (1519:9): [True: 0, False: 157]
  |  Branch (1519:25): [True: 0, False: 157]
  |  Branch (1519:43): [True: 0, False: 157]
  ------------------
 1520|      0|        return false;
 1521|      0|    }
 1522|       |
 1523|    157|    status = libspdm_x509_get_extension_data(cert, cert_size,
 1524|    157|                                             m_libspdm_oid_basic_constraints,
 1525|    157|                                             sizeof(m_libspdm_oid_basic_constraints),
 1526|    157|                                             basic_constraints,
 1527|    157|                                             basic_constraints_size);
 1528|    157|    return status;
 1529|    157|}
libspdm_x509_set_date_time:
 1608|    314|{
 1609|    314|    mbedtls_x509_time dt;
 1610|       |
 1611|    314|    int32_t year;
 1612|    314|    int32_t month;
 1613|    314|    int32_t day;
 1614|    314|    int32_t hour;
 1615|    314|    int32_t minute;
 1616|    314|    int32_t second;
 1617|    314|    bool status;
 1618|    314|    const char *p;
 1619|       |
 1620|    314|    p = date_time_str;
 1621|       |
 1622|    314|    year = libspdm_internal_atoi(p, p + 4);
 1623|    314|    p += 4;
 1624|    314|    month = libspdm_internal_atoi(p, p + 2);
 1625|    314|    p += 2;
 1626|    314|    day = libspdm_internal_atoi(p, p + 2);
 1627|    314|    p += 2;
 1628|    314|    hour = libspdm_internal_atoi(p, p + 2);
 1629|    314|    p += 2;
 1630|    314|    minute = libspdm_internal_atoi(p, p + 2);
 1631|    314|    p += 2;
 1632|    314|    second = libspdm_internal_atoi(p, p + 2);
 1633|    314|    p += 2;
 1634|    314|    dt.year = (int)year;
 1635|    314|    dt.mon = (int)month;
 1636|    314|    dt.day = (int)day;
 1637|    314|    dt.hour = (int)hour;
 1638|    314|    dt.min = (int)minute;
 1639|    314|    dt.sec = (int)second;
 1640|       |
 1641|    314|    if (*date_time_size < sizeof(mbedtls_x509_time)) {
  ------------------
  |  Branch (1641:9): [True: 0, False: 314]
  ------------------
 1642|      0|        *date_time_size = sizeof(mbedtls_x509_time);
 1643|      0|        status = false;
 1644|      0|        goto cleanup;
 1645|      0|    }
 1646|    314|    if (date_time != NULL) {
  ------------------
  |  Branch (1646:9): [True: 314, False: 0]
  ------------------
 1647|    314|        libspdm_copy_mem(date_time, *date_time_size, &dt, sizeof(mbedtls_x509_time));
 1648|    314|    }
 1649|    314|    *date_time_size = sizeof(mbedtls_x509_time);
 1650|    314|    status = true;
 1651|    314|cleanup:
 1652|    314|    return status;
 1653|    314|}
libspdm_x509_compare_date_time:
 1672|    314|{
 1673|    314|    if (date_time1 == NULL || date_time2 == NULL) {
  ------------------
  |  Branch (1673:9): [True: 0, False: 314]
  |  Branch (1673:31): [True: 0, False: 314]
  ------------------
 1674|      0|        return -2;
 1675|      0|    }
 1676|    314|    if (libspdm_consttime_is_mem_equal(date_time2, date_time1, sizeof(mbedtls_x509_time))) {
  ------------------
  |  Branch (1676:9): [True: 0, False: 314]
  ------------------
 1677|      0|        return 0;
 1678|      0|    }
 1679|    314|    if (libspdm_internal_x509_check_time((const mbedtls_x509_time *)date_time1,
  ------------------
  |  Branch (1679:9): [True: 0, False: 314]
  ------------------
 1680|    314|                                         (const mbedtls_x509_time *)date_time2) == 0) {
 1681|      0|        return -1;
 1682|    314|    } else {
 1683|    314|        return 1;
 1684|    314|    }
 1685|    314|}
x509.c:libspdm_internal_x509_find_extension_data:
 1181|    471|{
 1182|    471|    uint8_t *ptr;
 1183|    471|    uint8_t *extension_ptr;
 1184|    471|    size_t obj_len;
 1185|    471|    int ret;
 1186|    471|    bool status;
 1187|    471|    size_t find_extension_len;
 1188|    471|    size_t header_len;
 1189|       |
 1190|       |    /*If no Extension entry match oid*/
 1191|    471|    status = false;
 1192|    471|    ptr = start;
 1193|       |
 1194|    471|    ret = 0;
 1195|       |
 1196|  1.88k|    while (true) {
 1197|       |        /*
 1198|       |         * Extension  ::=  SEQUENCE  {
 1199|       |         *      extnID      OBJECT IDENTIFIER,
 1200|       |         *      critical    bool DEFAULT false,
 1201|       |         *      extnValue   OCTET STRING  }
 1202|       |         */
 1203|  1.88k|        extension_ptr = ptr;
 1204|  1.88k|        ret = mbedtls_asn1_get_tag(&ptr, end, &obj_len,
 1205|  1.88k|                                   MBEDTLS_ASN1_CONSTRUCTED |
  ------------------
  |  |   82|  1.88k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
 1206|  1.88k|                                   MBEDTLS_ASN1_SEQUENCE);
  ------------------
  |  |   72|  1.88k|#define MBEDTLS_ASN1_SEQUENCE                0x10
  ------------------
 1207|  1.88k|        if (ret == 0) {
  ------------------
  |  Branch (1207:13): [True: 1.88k, False: 0]
  ------------------
 1208|  1.88k|            header_len = (size_t)(ptr - extension_ptr);
 1209|  1.88k|            find_extension_len = obj_len;
 1210|       |            /* Get Object Identifier*/
 1211|  1.88k|            ret = mbedtls_asn1_get_tag(&ptr, end, &obj_len,
 1212|  1.88k|                                       MBEDTLS_ASN1_OID);
  ------------------
  |  |   69|  1.88k|#define MBEDTLS_ASN1_OID                     0x06
  ------------------
 1213|  1.88k|        } else {
 1214|      0|            break;
 1215|      0|        }
 1216|       |
 1217|  1.88k|        if (ret == 0 && libspdm_consttime_is_mem_equal(ptr, oid, oid_size)) {
  ------------------
  |  Branch (1217:13): [True: 1.88k, False: 0]
  |  Branch (1217:25): [True: 471, False: 1.41k]
  ------------------
 1218|    471|            ptr += obj_len;
 1219|       |
 1220|    471|            ret = mbedtls_asn1_get_tag(&ptr, end, &obj_len,
 1221|    471|                                       MBEDTLS_ASN1_BOOLEAN);
  ------------------
  |  |   64|    471|#define MBEDTLS_ASN1_BOOLEAN                 0x01
  ------------------
 1222|    471|            if (ret == 0) {
  ------------------
  |  Branch (1222:17): [True: 314, False: 157]
  ------------------
 1223|    314|                ptr += obj_len;
 1224|    314|            }
 1225|       |
 1226|    471|            ret = mbedtls_asn1_get_tag(&ptr, end, &obj_len,
 1227|    471|                                       MBEDTLS_ASN1_OCTET_STRING);
  ------------------
  |  |   67|    471|#define MBEDTLS_ASN1_OCTET_STRING            0x04
  ------------------
 1228|  1.41k|        } else {
 1229|  1.41k|            ret = 1;
 1230|  1.41k|        }
 1231|       |
 1232|  1.88k|        if (ret == 0) {
  ------------------
  |  Branch (1232:13): [True: 471, False: 1.41k]
  ------------------
 1233|    471|            *find_extension_data = ptr;
 1234|    471|            *find_extension_data_len = obj_len;
 1235|    471|            status = true;
 1236|    471|            break;
 1237|    471|        }
 1238|       |
 1239|       |        /* move to next*/
 1240|  1.41k|        ptr = extension_ptr + header_len + find_extension_len;
 1241|  1.41k|        ret = 0;
 1242|  1.41k|    }
 1243|       |
 1244|    471|    return status;
 1245|    471|}
x509.c:libspdm_internal_atoi:
 1571|  1.88k|{
 1572|  1.88k|    const char *p = p_start;
 1573|  1.88k|    int32_t k = 0;
 1574|  6.28k|    while (p < p_end) {
  ------------------
  |  Branch (1574:12): [True: 4.39k, False: 1.88k]
  ------------------
 1575|       |
 1576|       |        /* k = k * 2³ + k * 2¹ = k * 8 + k * 2 = k * 10*/
 1577|       |
 1578|  4.39k|        k = (k << 3) + (k << 1) + (*p) - '0';
 1579|  4.39k|        p++;
 1580|  4.39k|    }
 1581|  1.88k|    return k;
 1582|  1.88k|}
x509.c:libspdm_internal_x509_check_time:
 1536|    314|{
 1537|    314|    if (before->year > after->year) {
  ------------------
  |  Branch (1537:9): [True: 314, False: 0]
  ------------------
 1538|    314|        return (1);
 1539|    314|    }
 1540|       |
 1541|      0|    if (before->year == after->year && before->mon > after->mon) {
  ------------------
  |  Branch (1541:9): [True: 0, False: 0]
  |  Branch (1541:40): [True: 0, False: 0]
  ------------------
 1542|      0|        return (1);
 1543|      0|    }
 1544|       |
 1545|      0|    if (before->year == after->year && before->mon == after->mon &&
  ------------------
  |  Branch (1545:9): [True: 0, False: 0]
  |  Branch (1545:40): [True: 0, False: 0]
  ------------------
 1546|      0|        before->day > after->day) {
  ------------------
  |  Branch (1546:9): [True: 0, False: 0]
  ------------------
 1547|      0|        return (1);
 1548|      0|    }
 1549|       |
 1550|      0|    if (before->year == after->year && before->mon == after->mon &&
  ------------------
  |  Branch (1550:9): [True: 0, False: 0]
  |  Branch (1550:40): [True: 0, False: 0]
  ------------------
 1551|      0|        before->day == after->day && before->hour > after->hour) {
  ------------------
  |  Branch (1551:9): [True: 0, False: 0]
  |  Branch (1551:38): [True: 0, False: 0]
  ------------------
 1552|      0|        return (1);
 1553|      0|    }
 1554|       |
 1555|      0|    if (before->year == after->year && before->mon == after->mon &&
  ------------------
  |  Branch (1555:9): [True: 0, False: 0]
  |  Branch (1555:40): [True: 0, False: 0]
  ------------------
 1556|      0|        before->day == after->day && before->hour == after->hour &&
  ------------------
  |  Branch (1556:9): [True: 0, False: 0]
  |  Branch (1556:38): [True: 0, False: 0]
  ------------------
 1557|      0|        before->min > after->min) {
  ------------------
  |  Branch (1557:9): [True: 0, False: 0]
  ------------------
 1558|      0|        return (1);
 1559|      0|    }
 1560|       |
 1561|      0|    if (before->year == after->year && before->mon == after->mon &&
  ------------------
  |  Branch (1561:9): [True: 0, False: 0]
  |  Branch (1561:40): [True: 0, False: 0]
  ------------------
 1562|      0|        before->day == after->day && before->hour == after->hour &&
  ------------------
  |  Branch (1562:9): [True: 0, False: 0]
  |  Branch (1562:38): [True: 0, False: 0]
  ------------------
 1563|      0|        before->min == after->min && before->sec > after->sec) {
  ------------------
  |  Branch (1563:9): [True: 0, False: 0]
  |  Branch (1563:38): [True: 0, False: 0]
  ------------------
 1564|      0|        return (1);
 1565|      0|    }
 1566|       |
 1567|      0|    return (0);
 1568|      0|}

mbedtls_platform_zeroize:
   29|   530k|{
   30|   530k|    libspdm_zero_mem(buf, len);
   31|   530k|}

my_calloc:
   34|   517k|{
   35|   517k|    CRYPTMEM_HEAD *pool_hdr;
   36|   517k|    size_t new_size;
   37|   517k|    void *data;
   38|       |
   39|       |
   40|       |    /* Adjust the size by the buffer header overhead*/
   41|       |
   42|   517k|    new_size = (size_t)(size * num) + CRYPTMEM_OVERHEAD;
  ------------------
  |  |   26|   517k|#define CRYPTMEM_OVERHEAD sizeof(CRYPTMEM_HEAD)
  ------------------
   43|       |
   44|   517k|    data = allocate_zero_pool(new_size);
   45|   517k|    if (data != NULL) {
  ------------------
  |  Branch (45:9): [True: 517k, False: 0]
  ------------------
   46|   517k|        pool_hdr = (CRYPTMEM_HEAD *)data;
   47|       |
   48|       |        /* Record the memory brief information*/
   49|       |
   50|   517k|        pool_hdr->version = CRYPTMEM_HEAD_VERSION;
  ------------------
  |  |   19|   517k|#define CRYPTMEM_HEAD_VERSION 0x1
  ------------------
   51|   517k|        pool_hdr->size = size;
   52|       |
   53|   517k|        return (void *)(pool_hdr + 1);
   54|   517k|    } else {
   55|       |
   56|       |        /* The buffer allocation failed.*/
   57|       |
   58|      0|        return NULL;
   59|      0|    }
   60|   517k|}
my_free:
   64|   520k|{
   65|   520k|    CRYPTMEM_HEAD *pool_hdr;
   66|       |
   67|       |
   68|       |    /* In Standard C, free() handles a null pointer argument transparently. This
   69|       |     * is not true of free_pool() below, so protect it.*/
   70|       |
   71|   520k|    if (ptr != NULL) {
  ------------------
  |  Branch (71:9): [True: 517k, False: 2.82k]
  ------------------
   72|   517k|        pool_hdr = (CRYPTMEM_HEAD *)ptr - 1;
   73|   517k|        LIBSPDM_ASSERT(pool_hdr->version == CRYPTMEM_HEAD_VERSION);
   74|   517k|        free_pool(pool_hdr);
   75|   517k|    }
   76|   520k|}

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

ecp.c:mbedtls_ecp_group_a_is_minus_3:
 1023|  99.8k|{
 1024|  99.8k|    return grp->A.MBEDTLS_PRIVATE(p) == NULL;
  ------------------
  |  |   17|  99.8k|#define MBEDTLS_PRIVATE(member) member
  ------------------
 1025|  99.8k|}

x509.c:mbedtls_pk_ec:
 1061|    157|{
 1062|    157|    switch (mbedtls_pk_get_type(&pk)) {
 1063|    157|        case MBEDTLS_PK_ECKEY:
  ------------------
  |  Branch (1063:9): [True: 157, False: 0]
  ------------------
 1064|    157|        case MBEDTLS_PK_ECKEY_DH:
  ------------------
  |  Branch (1064:9): [True: 0, False: 157]
  ------------------
 1065|    157|        case MBEDTLS_PK_ECDSA:
  ------------------
  |  Branch (1065:9): [True: 0, False: 157]
  ------------------
 1066|    157|            return (mbedtls_ecp_keypair *) (pk).MBEDTLS_PRIVATE(pk_ctx);
  ------------------
  |  |   15|    157|#define MBEDTLS_PRIVATE(member) private_##member
  ------------------
 1067|      0|        default:
  ------------------
  |  Branch (1067:9): [True: 0, False: 157]
  ------------------
 1068|      0|            return NULL;
 1069|    157|    }
 1070|    157|}

sha256.c:mbedtls_get_unaligned_uint32:
  168|  51.2k|{
  169|  51.2k|    uint32_t r;
  170|       |#if defined(UINT_UNALIGNED)
  171|       |    mbedtls_uint32_unaligned_t *p32 = (mbedtls_uint32_unaligned_t *) p;
  172|       |    r = *p32;
  173|       |#elif defined(UINT_UNALIGNED_STRUCT)
  174|       |    mbedtls_uint32_unaligned_t *p32 = (mbedtls_uint32_unaligned_t *) p;
  175|       |    r = p32->x;
  176|       |#else
  177|  51.2k|    memcpy(&r, p, sizeof(r));
  178|  51.2k|#endif
  179|  51.2k|    return r;
  180|  51.2k|}
sha256.c:mbedtls_put_unaligned_uint32:
  195|  4.71k|{
  196|       |#if defined(UINT_UNALIGNED)
  197|       |    mbedtls_uint32_unaligned_t *p32 = (mbedtls_uint32_unaligned_t *) p;
  198|       |    *p32 = x;
  199|       |#elif defined(UINT_UNALIGNED_STRUCT)
  200|       |    mbedtls_uint32_unaligned_t *p32 = (mbedtls_uint32_unaligned_t *) p;
  201|       |    p32->x = x;
  202|       |#else
  203|  4.71k|    memcpy(p, &x, sizeof(x));
  204|  4.71k|#endif
  205|  4.71k|}

mbedtls_asn1_get_len:
   31|   150k|{
   32|   150k|    if ((end - *p) < 1) {
  ------------------
  |  Branch (32:9): [True: 0, False: 150k]
  ------------------
   33|      0|        return MBEDTLS_ERR_ASN1_OUT_OF_DATA;
  ------------------
  |  |   37|      0|#define MBEDTLS_ERR_ASN1_OUT_OF_DATA                      -0x0060
  ------------------
   34|      0|    }
   35|       |
   36|   150k|    if ((**p & 0x80) == 0) {
  ------------------
  |  Branch (36:9): [True: 140k, False: 10.5k]
  ------------------
   37|   140k|        *len = *(*p)++;
   38|   140k|    } else {
   39|  10.5k|        int n = (**p) & 0x7F;
   40|  10.5k|        if (n == 0 || n > 4) {
  ------------------
  |  Branch (40:13): [True: 0, False: 10.5k]
  |  Branch (40:23): [True: 0, False: 10.5k]
  ------------------
   41|      0|            return MBEDTLS_ERR_ASN1_INVALID_LENGTH;
  ------------------
  |  |   41|      0|#define MBEDTLS_ERR_ASN1_INVALID_LENGTH                   -0x0064
  ------------------
   42|      0|        }
   43|  10.5k|        if ((end - *p) <= n) {
  ------------------
  |  Branch (43:13): [True: 0, False: 10.5k]
  ------------------
   44|      0|            return MBEDTLS_ERR_ASN1_OUT_OF_DATA;
  ------------------
  |  |   37|      0|#define MBEDTLS_ERR_ASN1_OUT_OF_DATA                      -0x0060
  ------------------
   45|      0|        }
   46|  10.5k|        *len = 0;
   47|  10.5k|        (*p)++;
   48|  27.6k|        while (n--) {
  ------------------
  |  Branch (48:16): [True: 17.1k, False: 10.5k]
  ------------------
   49|  17.1k|            *len = (*len << 8) | **p;
   50|  17.1k|            (*p)++;
   51|  17.1k|        }
   52|  10.5k|    }
   53|       |
   54|   150k|    if (*len > (size_t) (end - *p)) {
  ------------------
  |  Branch (54:9): [True: 0, False: 150k]
  ------------------
   55|      0|        return MBEDTLS_ERR_ASN1_OUT_OF_DATA;
  ------------------
  |  |   37|      0|#define MBEDTLS_ERR_ASN1_OUT_OF_DATA                      -0x0060
  ------------------
   56|      0|    }
   57|       |
   58|   150k|    return 0;
   59|   150k|}
mbedtls_asn1_get_tag:
   64|   142k|{
   65|   142k|    if ((end - *p) < 1) {
  ------------------
  |  Branch (65:9): [True: 314, False: 142k]
  ------------------
   66|    314|        return MBEDTLS_ERR_ASN1_OUT_OF_DATA;
  ------------------
  |  |   37|    314|#define MBEDTLS_ERR_ASN1_OUT_OF_DATA                      -0x0060
  ------------------
   67|    314|    }
   68|       |
   69|   142k|    if (**p != tag) {
  ------------------
  |  Branch (69:9): [True: 13.9k, False: 128k]
  ------------------
   70|  13.9k|        return MBEDTLS_ERR_ASN1_UNEXPECTED_TAG;
  ------------------
  |  |   39|  13.9k|#define MBEDTLS_ERR_ASN1_UNEXPECTED_TAG                   -0x0062
  ------------------
   71|  13.9k|    }
   72|       |
   73|   128k|    (*p)++;
   74|       |
   75|   128k|    return mbedtls_asn1_get_len(p, end, len);
   76|   142k|}
mbedtls_asn1_get_bool:
   83|  13.8k|{
   84|  13.8k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  13.8k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
   85|  13.8k|    size_t len;
   86|       |
   87|  13.8k|    if ((ret = mbedtls_asn1_get_tag(p, end, &len, MBEDTLS_ASN1_BOOLEAN)) != 0) {
  ------------------
  |  |   64|  13.8k|#define MBEDTLS_ASN1_BOOLEAN                 0x01
  ------------------
  |  Branch (87:9): [True: 8.79k, False: 5.02k]
  ------------------
   88|  8.79k|        return ret;
   89|  8.79k|    }
   90|       |
   91|  5.02k|    if (len != 1) {
  ------------------
  |  Branch (91:9): [True: 0, False: 5.02k]
  ------------------
   92|      0|        return MBEDTLS_ERR_ASN1_INVALID_LENGTH;
  ------------------
  |  |   41|      0|#define MBEDTLS_ERR_ASN1_INVALID_LENGTH                   -0x0064
  ------------------
   93|      0|    }
   94|       |
   95|  5.02k|    *val = (**p != 0) ? 1 : 0;
  ------------------
  |  Branch (95:12): [True: 5.02k, False: 0]
  ------------------
   96|  5.02k|    (*p)++;
   97|       |
   98|  5.02k|    return 0;
   99|  5.02k|}
mbedtls_asn1_get_int:
  151|  2.51k|{
  152|  2.51k|    return asn1_get_tagged_int(p, end, MBEDTLS_ASN1_INTEGER, val);
  ------------------
  |  |   65|  2.51k|#define MBEDTLS_ASN1_INTEGER                 0x02
  ------------------
  153|  2.51k|}
mbedtls_asn1_get_mpi:
  166|    628|{
  167|    628|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|    628|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  168|    628|    size_t len;
  169|       |
  170|    628|    if ((ret = mbedtls_asn1_get_tag(p, end, &len, MBEDTLS_ASN1_INTEGER)) != 0) {
  ------------------
  |  |   65|    628|#define MBEDTLS_ASN1_INTEGER                 0x02
  ------------------
  |  Branch (170:9): [True: 0, False: 628]
  ------------------
  171|      0|        return ret;
  172|      0|    }
  173|       |
  174|    628|    ret = mbedtls_mpi_read_binary(X, *p, len);
  175|       |
  176|    628|    *p += len;
  177|       |
  178|    628|    return ret;
  179|    628|}
mbedtls_asn1_get_bitstring:
  184|  2.04k|{
  185|  2.04k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  2.04k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  186|       |
  187|       |    /* Certificate type is a single byte bitstring */
  188|  2.04k|    if ((ret = mbedtls_asn1_get_tag(p, end, &bs->len, MBEDTLS_ASN1_BIT_STRING)) != 0) {
  ------------------
  |  |   66|  2.04k|#define MBEDTLS_ASN1_BIT_STRING              0x03
  ------------------
  |  Branch (188:9): [True: 0, False: 2.04k]
  ------------------
  189|      0|        return ret;
  190|      0|    }
  191|       |
  192|       |    /* Check length, subtract one for actual bit string length */
  193|  2.04k|    if (bs->len < 1) {
  ------------------
  |  Branch (193:9): [True: 0, False: 2.04k]
  ------------------
  194|      0|        return MBEDTLS_ERR_ASN1_OUT_OF_DATA;
  ------------------
  |  |   37|      0|#define MBEDTLS_ERR_ASN1_OUT_OF_DATA                      -0x0060
  ------------------
  195|      0|    }
  196|  2.04k|    bs->len -= 1;
  197|       |
  198|       |    /* Get number of unused bits, ensure unused bits <= 7 */
  199|  2.04k|    bs->unused_bits = **p;
  200|  2.04k|    if (bs->unused_bits > 7) {
  ------------------
  |  Branch (200:9): [True: 0, False: 2.04k]
  ------------------
  201|      0|        return MBEDTLS_ERR_ASN1_INVALID_LENGTH;
  ------------------
  |  |   41|      0|#define MBEDTLS_ERR_ASN1_INVALID_LENGTH                   -0x0064
  ------------------
  202|      0|    }
  203|  2.04k|    (*p)++;
  204|       |
  205|       |    /* Get actual bitstring */
  206|  2.04k|    bs->p = *p;
  207|  2.04k|    *p += bs->len;
  208|       |
  209|  2.04k|    if (*p != end) {
  ------------------
  |  Branch (209:9): [True: 0, False: 2.04k]
  ------------------
  210|      0|        return MBEDTLS_ERR_ASN1_LENGTH_MISMATCH;
  ------------------
  |  |   43|      0|#define MBEDTLS_ERR_ASN1_LENGTH_MISMATCH                  -0x0066
  ------------------
  211|      0|    }
  212|       |
  213|  2.04k|    return 0;
  214|  2.04k|}
mbedtls_asn1_traverse_sequence_of:
  228|  2.04k|{
  229|  2.04k|    int ret;
  230|  2.04k|    size_t len;
  231|       |
  232|       |    /* Get main sequence tag */
  233|  2.04k|    if ((ret = mbedtls_asn1_get_tag(p, end, &len,
  ------------------
  |  Branch (233:9): [True: 0, False: 2.04k]
  ------------------
  234|  2.04k|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|  2.04k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|  2.04k|#define MBEDTLS_ASN1_SEQUENCE                0x10
  ------------------
  235|      0|        return ret;
  236|      0|    }
  237|       |
  238|  2.04k|    if (*p + len != end) {
  ------------------
  |  Branch (238:9): [True: 0, False: 2.04k]
  ------------------
  239|      0|        return MBEDTLS_ERR_ASN1_LENGTH_MISMATCH;
  ------------------
  |  |   43|      0|#define MBEDTLS_ERR_ASN1_LENGTH_MISMATCH                  -0x0066
  ------------------
  240|      0|    }
  241|       |
  242|  7.85k|    while (*p < end) {
  ------------------
  |  Branch (242:12): [True: 5.80k, False: 2.04k]
  ------------------
  243|  5.80k|        unsigned char const tag = *(*p)++;
  244|       |
  245|  5.80k|        if ((tag & tag_must_mask) != tag_must_val) {
  ------------------
  |  Branch (245:13): [True: 0, False: 5.80k]
  ------------------
  246|      0|            return MBEDTLS_ERR_ASN1_UNEXPECTED_TAG;
  ------------------
  |  |   39|      0|#define MBEDTLS_ERR_ASN1_UNEXPECTED_TAG                   -0x0062
  ------------------
  247|      0|        }
  248|       |
  249|  5.80k|        if ((ret = mbedtls_asn1_get_len(p, end, &len)) != 0) {
  ------------------
  |  Branch (249:13): [True: 0, False: 5.80k]
  ------------------
  250|      0|            return ret;
  251|      0|        }
  252|       |
  253|  5.80k|        if ((tag & tag_may_mask) == tag_may_val) {
  ------------------
  |  Branch (253:13): [True: 5.80k, False: 0]
  ------------------
  254|  5.80k|            if (cb != NULL) {
  ------------------
  |  Branch (254:17): [True: 5.80k, False: 0]
  ------------------
  255|  5.80k|                ret = cb(ctx, tag, *p, len);
  256|  5.80k|                if (ret != 0) {
  ------------------
  |  Branch (256:21): [True: 0, False: 5.80k]
  ------------------
  257|      0|                    return ret;
  258|      0|                }
  259|  5.80k|            }
  260|  5.80k|        }
  261|       |
  262|  5.80k|        *p += len;
  263|  5.80k|    }
  264|       |
  265|  2.04k|    return 0;
  266|  2.04k|}
mbedtls_asn1_get_bitstring_null:
  273|  5.02k|{
  274|  5.02k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  5.02k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  275|       |
  276|  5.02k|    if ((ret = mbedtls_asn1_get_tag(p, end, len, MBEDTLS_ASN1_BIT_STRING)) != 0) {
  ------------------
  |  |   66|  5.02k|#define MBEDTLS_ASN1_BIT_STRING              0x03
  ------------------
  |  Branch (276:9): [True: 0, False: 5.02k]
  ------------------
  277|      0|        return ret;
  278|      0|    }
  279|       |
  280|  5.02k|    if (*len == 0) {
  ------------------
  |  Branch (280:9): [True: 0, False: 5.02k]
  ------------------
  281|      0|        return MBEDTLS_ERR_ASN1_INVALID_DATA;
  ------------------
  |  |   45|      0|#define MBEDTLS_ERR_ASN1_INVALID_DATA                     -0x0068
  ------------------
  282|      0|    }
  283|  5.02k|    --(*len);
  284|       |
  285|  5.02k|    if (**p != 0) {
  ------------------
  |  Branch (285:9): [True: 0, False: 5.02k]
  ------------------
  286|      0|        return MBEDTLS_ERR_ASN1_INVALID_DATA;
  ------------------
  |  |   45|      0|#define MBEDTLS_ERR_ASN1_INVALID_DATA                     -0x0068
  ------------------
  287|      0|    }
  288|  5.02k|    ++(*p);
  289|       |
  290|  5.02k|    return 0;
  291|  5.02k|}
mbedtls_asn1_sequence_free:
  294|  10.0k|{
  295|  13.8k|    while (seq != NULL) {
  ------------------
  |  Branch (295:12): [True: 3.76k, False: 10.0k]
  ------------------
  296|  3.76k|        mbedtls_asn1_sequence *next = seq->next;
  297|  3.76k|        mbedtls_free(seq);
  ------------------
  |  |  143|  3.76k|#define mbedtls_free       MBEDTLS_PLATFORM_FREE_MACRO
  |  |  ------------------
  |  |  |  | 4095|  3.76k|#define MBEDTLS_PLATFORM_FREE_MACRO            my_free
  |  |  ------------------
  ------------------
  298|  3.76k|        seq = next;
  299|  3.76k|    }
  300|  10.0k|}
mbedtls_asn1_get_sequence_of:
  343|  2.04k|{
  344|  2.04k|    asn1_get_sequence_of_cb_ctx_t cb_ctx = { tag, cur };
  345|  2.04k|    memset(cur, 0, sizeof(mbedtls_asn1_sequence));
  346|  2.04k|    return mbedtls_asn1_traverse_sequence_of(
  347|  2.04k|        p, end, 0xFF, tag, 0, 0,
  348|  2.04k|        asn1_get_sequence_of_cb, &cb_ctx);
  349|  2.04k|}
mbedtls_asn1_get_alg:
  354|  7.53k|{
  355|  7.53k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  7.53k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  356|  7.53k|    size_t len;
  357|       |
  358|  7.53k|    if ((ret = mbedtls_asn1_get_tag(p, end, &len,
  ------------------
  |  Branch (358:9): [True: 0, False: 7.53k]
  ------------------
  359|  7.53k|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|  7.53k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|  7.53k|#define MBEDTLS_ASN1_SEQUENCE                0x10
  ------------------
  360|      0|        return ret;
  361|      0|    }
  362|       |
  363|  7.53k|    if ((end - *p) < 1) {
  ------------------
  |  Branch (363:9): [True: 0, False: 7.53k]
  ------------------
  364|      0|        return MBEDTLS_ERR_ASN1_OUT_OF_DATA;
  ------------------
  |  |   37|      0|#define MBEDTLS_ERR_ASN1_OUT_OF_DATA                      -0x0060
  ------------------
  365|      0|    }
  366|       |
  367|  7.53k|    alg->tag = **p;
  368|  7.53k|    end = *p + len;
  369|       |
  370|  7.53k|    if ((ret = mbedtls_asn1_get_tag(p, end, &alg->len, MBEDTLS_ASN1_OID)) != 0) {
  ------------------
  |  |   69|  7.53k|#define MBEDTLS_ASN1_OID                     0x06
  ------------------
  |  Branch (370:9): [True: 0, False: 7.53k]
  ------------------
  371|      0|        return ret;
  372|      0|    }
  373|       |
  374|  7.53k|    alg->p = *p;
  375|  7.53k|    *p += alg->len;
  376|       |
  377|  7.53k|    if (*p == end) {
  ------------------
  |  Branch (377:9): [True: 5.02k, False: 2.51k]
  ------------------
  378|  5.02k|        mbedtls_platform_zeroize(params, sizeof(mbedtls_asn1_buf));
  379|  5.02k|        return 0;
  380|  5.02k|    }
  381|       |
  382|  2.51k|    params->tag = **p;
  383|  2.51k|    (*p)++;
  384|       |
  385|  2.51k|    if ((ret = mbedtls_asn1_get_len(p, end, &params->len)) != 0) {
  ------------------
  |  Branch (385:9): [True: 0, False: 2.51k]
  ------------------
  386|      0|        return ret;
  387|      0|    }
  388|       |
  389|  2.51k|    params->p = *p;
  390|  2.51k|    *p += params->len;
  391|       |
  392|  2.51k|    if (*p != end) {
  ------------------
  |  Branch (392:9): [True: 0, False: 2.51k]
  ------------------
  393|      0|        return MBEDTLS_ERR_ASN1_LENGTH_MISMATCH;
  ------------------
  |  |   43|      0|#define MBEDTLS_ERR_ASN1_LENGTH_MISMATCH                  -0x0066
  ------------------
  394|      0|    }
  395|       |
  396|  2.51k|    return 0;
  397|  2.51k|}
mbedtls_asn1_free_named_data_list_shallow:
  446|  5.02k|{
  447|  5.02k|    for (mbedtls_asn1_named_data *next; name != NULL; name = next) {
  ------------------
  |  Branch (447:41): [True: 0, False: 5.02k]
  ------------------
  448|      0|        next = name->next;
  449|      0|        mbedtls_free(name);
  ------------------
  |  |  143|      0|#define mbedtls_free       MBEDTLS_PLATFORM_FREE_MACRO
  |  |  ------------------
  |  |  |  | 4095|      0|#define MBEDTLS_PLATFORM_FREE_MACRO            my_free
  |  |  ------------------
  ------------------
  450|      0|    }
  451|  5.02k|}
asn1parse.c:asn1_get_tagged_int:
  104|  2.51k|{
  105|  2.51k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  2.51k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  106|  2.51k|    size_t len;
  107|       |
  108|  2.51k|    if ((ret = mbedtls_asn1_get_tag(p, end, &len, tag)) != 0) {
  ------------------
  |  Branch (108:9): [True: 0, False: 2.51k]
  ------------------
  109|      0|        return ret;
  110|      0|    }
  111|       |
  112|       |    /*
  113|       |     * len==0 is malformed (0 must be represented as 020100 for INTEGER,
  114|       |     * or 0A0100 for ENUMERATED tags
  115|       |     */
  116|  2.51k|    if (len == 0) {
  ------------------
  |  Branch (116:9): [True: 0, False: 2.51k]
  ------------------
  117|      0|        return MBEDTLS_ERR_ASN1_INVALID_LENGTH;
  ------------------
  |  |   41|      0|#define MBEDTLS_ERR_ASN1_INVALID_LENGTH                   -0x0064
  ------------------
  118|      0|    }
  119|       |    /* This is a cryptography library. Reject negative integers. */
  120|  2.51k|    if ((**p & 0x80) != 0) {
  ------------------
  |  Branch (120:9): [True: 0, False: 2.51k]
  ------------------
  121|      0|        return MBEDTLS_ERR_ASN1_INVALID_LENGTH;
  ------------------
  |  |   41|      0|#define MBEDTLS_ERR_ASN1_INVALID_LENGTH                   -0x0064
  ------------------
  122|      0|    }
  123|       |
  124|       |    /* Skip leading zeros. */
  125|  2.51k|    while (len > 0 && **p == 0) {
  ------------------
  |  Branch (125:12): [True: 2.51k, False: 0]
  |  Branch (125:23): [True: 0, False: 2.51k]
  ------------------
  126|      0|        ++(*p);
  127|      0|        --len;
  128|      0|    }
  129|       |
  130|       |    /* Reject integers that don't fit in an int. This code assumes that
  131|       |     * the int type has no padding bit. */
  132|  2.51k|    if (len > sizeof(int)) {
  ------------------
  |  Branch (132:9): [True: 0, False: 2.51k]
  ------------------
  133|      0|        return MBEDTLS_ERR_ASN1_INVALID_LENGTH;
  ------------------
  |  |   41|      0|#define MBEDTLS_ERR_ASN1_INVALID_LENGTH                   -0x0064
  ------------------
  134|      0|    }
  135|  2.51k|    if (len == sizeof(int) && (**p & 0x80) != 0) {
  ------------------
  |  Branch (135:9): [True: 0, False: 2.51k]
  |  Branch (135:31): [True: 0, False: 0]
  ------------------
  136|      0|        return MBEDTLS_ERR_ASN1_INVALID_LENGTH;
  ------------------
  |  |   41|      0|#define MBEDTLS_ERR_ASN1_INVALID_LENGTH                   -0x0064
  ------------------
  137|      0|    }
  138|       |
  139|  2.51k|    *val = 0;
  140|  5.02k|    while (len-- > 0) {
  ------------------
  |  Branch (140:12): [True: 2.51k, False: 2.51k]
  ------------------
  141|  2.51k|        *val = (*val << 8) | **p;
  142|  2.51k|        (*p)++;
  143|  2.51k|    }
  144|       |
  145|  2.51k|    return 0;
  146|  2.51k|}
asn1parse.c:asn1_get_sequence_of_cb:
  311|  5.80k|{
  312|  5.80k|    asn1_get_sequence_of_cb_ctx_t *cb_ctx =
  313|  5.80k|        (asn1_get_sequence_of_cb_ctx_t *) ctx;
  314|  5.80k|    mbedtls_asn1_sequence *cur =
  315|  5.80k|        cb_ctx->cur;
  316|       |
  317|  5.80k|    if (cur->buf.p != NULL) {
  ------------------
  |  Branch (317:9): [True: 3.76k, False: 2.04k]
  ------------------
  318|  3.76k|        cur->next =
  319|  3.76k|            mbedtls_calloc(1, sizeof(mbedtls_asn1_sequence));
  ------------------
  |  |  144|  3.76k|#define mbedtls_calloc     MBEDTLS_PLATFORM_CALLOC_MACRO
  |  |  ------------------
  |  |  |  | 4093|  3.76k|#define MBEDTLS_PLATFORM_CALLOC_MACRO        my_calloc
  |  |  ------------------
  ------------------
  320|       |
  321|  3.76k|        if (cur->next == NULL) {
  ------------------
  |  Branch (321:13): [True: 0, False: 3.76k]
  ------------------
  322|      0|            return MBEDTLS_ERR_ASN1_ALLOC_FAILED;
  ------------------
  |  |   47|      0|#define MBEDTLS_ERR_ASN1_ALLOC_FAILED                     -0x006A
  ------------------
  323|      0|        }
  324|       |
  325|  3.76k|        cur = cur->next;
  326|  3.76k|    }
  327|       |
  328|  5.80k|    cur->buf.p = start;
  329|  5.80k|    cur->buf.len = len;
  330|  5.80k|    cur->buf.tag = tag;
  331|       |
  332|  5.80k|    cb_ctx->cur = cur;
  333|  5.80k|    return 0;
  334|  5.80k|}

mbedtls_mpi_safe_cond_assign:
  121|   897k|{
  122|   897k|    int ret = 0;
  123|       |
  124|   897k|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, Y->n));
  ------------------
  |  |   41|   897k|    do                           \
  |  |   42|   897k|    {                            \
  |  |   43|   897k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 897k]
  |  |  ------------------
  |  |   44|   897k|        goto cleanup;        \
  |  |   45|   897k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  125|       |
  126|   897k|    {
  127|   897k|        mbedtls_ct_condition_t do_assign = mbedtls_ct_bool(assign);
  128|       |
  129|   897k|        X->s = mbedtls_ct_mpi_sign_if(do_assign, Y->s, X->s);
  130|       |
  131|   897k|        mbedtls_mpi_core_cond_assign(X->p, Y->p, Y->n, do_assign);
  132|       |
  133|   897k|        mbedtls_ct_condition_t do_not_assign = mbedtls_ct_bool_not(do_assign);
  134|   900k|        for (size_t i = Y->n; i < X->n; i++) {
  ------------------
  |  Branch (134:31): [True: 3.14k, False: 897k]
  ------------------
  135|  3.14k|            X->p[i] = mbedtls_ct_mpi_uint_if_else_0(do_not_assign, X->p[i]);
  136|  3.14k|        }
  137|   897k|    }
  138|       |
  139|   897k|cleanup:
  140|   897k|    return ret;
  141|   897k|}
mbedtls_mpi_init:
  182|  2.62M|{
  183|  2.62M|    X->s = 1;
  184|  2.62M|    X->n = 0;
  185|  2.62M|    X->p = NULL;
  186|  2.62M|}
mbedtls_mpi_free:
  192|  2.60M|{
  193|  2.60M|    if (X == NULL) {
  ------------------
  |  Branch (193:9): [True: 0, False: 2.60M]
  ------------------
  194|      0|        return;
  195|      0|    }
  196|       |
  197|  2.60M|    if (X->p != NULL) {
  ------------------
  |  Branch (197:9): [True: 450k, False: 2.15M]
  ------------------
  198|   450k|        mbedtls_mpi_zeroize_and_free(X->p, X->n);
  ------------------
  |  |  176|   450k|#define mbedtls_mpi_zeroize_and_free(v, n) mbedtls_zeroize_and_free(v, ciL * (n))
  |  |  ------------------
  |  |  |  |   79|   450k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  199|   450k|    }
  200|       |
  201|  2.60M|    X->s = 1;
  202|  2.60M|    X->n = 0;
  203|  2.60M|    X->p = NULL;
  204|  2.60M|}
mbedtls_mpi_grow:
  210|  9.88M|{
  211|  9.88M|    mbedtls_mpi_uint *p;
  212|       |
  213|  9.88M|    if (nblimbs > MBEDTLS_MPI_MAX_LIMBS) {
  ------------------
  |  |   50|  9.88M|#define MBEDTLS_MPI_MAX_LIMBS                             10000
  ------------------
  |  Branch (213:9): [True: 0, False: 9.88M]
  ------------------
  214|      0|        return MBEDTLS_ERR_MPI_ALLOC_FAILED;
  ------------------
  |  |   38|      0|#define MBEDTLS_ERR_MPI_ALLOC_FAILED                      -0x0010
  ------------------
  215|      0|    }
  216|       |
  217|  9.88M|    if (X->n < nblimbs) {
  ------------------
  |  Branch (217:9): [True: 501k, False: 9.38M]
  ------------------
  218|   501k|        if ((p = (mbedtls_mpi_uint *) mbedtls_calloc(nblimbs, ciL)) == NULL) {
  ------------------
  |  |  144|   501k|#define mbedtls_calloc     MBEDTLS_PLATFORM_CALLOC_MACRO
  |  |  ------------------
  |  |  |  | 4093|   501k|#define MBEDTLS_PLATFORM_CALLOC_MACRO        my_calloc
  |  |  ------------------
  ------------------
                      if ((p = (mbedtls_mpi_uint *) mbedtls_calloc(nblimbs, ciL)) == NULL) {
  ------------------
  |  |   79|   501k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  |  Branch (218:13): [True: 0, False: 501k]
  ------------------
  219|      0|            return MBEDTLS_ERR_MPI_ALLOC_FAILED;
  ------------------
  |  |   38|      0|#define MBEDTLS_ERR_MPI_ALLOC_FAILED                      -0x0010
  ------------------
  220|      0|        }
  221|       |
  222|   501k|        if (X->p != NULL) {
  ------------------
  |  Branch (222:13): [True: 50.5k, False: 450k]
  ------------------
  223|  50.5k|            memcpy(p, X->p, X->n * ciL);
  ------------------
  |  |   79|  50.5k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  224|  50.5k|            mbedtls_mpi_zeroize_and_free(X->p, X->n);
  ------------------
  |  |  176|  50.5k|#define mbedtls_mpi_zeroize_and_free(v, n) mbedtls_zeroize_and_free(v, ciL * (n))
  |  |  ------------------
  |  |  |  |   79|  50.5k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  225|  50.5k|        }
  226|       |
  227|       |        /* nblimbs fits in n because we ensure that MBEDTLS_MPI_MAX_LIMBS
  228|       |         * fits, and we've checked that nblimbs <= MBEDTLS_MPI_MAX_LIMBS. */
  229|   501k|        X->n = (unsigned short) nblimbs;
  230|   501k|        X->p = p;
  231|   501k|    }
  232|       |
  233|  9.88M|    return 0;
  234|  9.88M|}
mbedtls_mpi_shrink:
  241|  6.28k|{
  242|  6.28k|    mbedtls_mpi_uint *p;
  243|  6.28k|    size_t i;
  244|       |
  245|  6.28k|    if (nblimbs > MBEDTLS_MPI_MAX_LIMBS) {
  ------------------
  |  |   50|  6.28k|#define MBEDTLS_MPI_MAX_LIMBS                             10000
  ------------------
  |  Branch (245:9): [True: 0, False: 6.28k]
  ------------------
  246|      0|        return MBEDTLS_ERR_MPI_ALLOC_FAILED;
  ------------------
  |  |   38|      0|#define MBEDTLS_ERR_MPI_ALLOC_FAILED                      -0x0010
  ------------------
  247|      0|    }
  248|       |
  249|       |    /* Actually resize up if there are currently fewer than nblimbs limbs. */
  250|  6.28k|    if (X->n <= nblimbs) {
  ------------------
  |  Branch (250:9): [True: 0, False: 6.28k]
  ------------------
  251|      0|        return mbedtls_mpi_grow(X, nblimbs);
  252|      0|    }
  253|       |    /* After this point, then X->n > nblimbs and in particular X->n > 0. */
  254|       |
  255|  37.6k|    for (i = X->n - 1; i > 0; i--) {
  ------------------
  |  Branch (255:24): [True: 37.6k, False: 0]
  ------------------
  256|  37.6k|        if (X->p[i] != 0) {
  ------------------
  |  Branch (256:13): [True: 6.28k, False: 31.4k]
  ------------------
  257|  6.28k|            break;
  258|  6.28k|        }
  259|  37.6k|    }
  260|  6.28k|    i++;
  261|       |
  262|  6.28k|    if (i < nblimbs) {
  ------------------
  |  Branch (262:9): [True: 0, False: 6.28k]
  ------------------
  263|      0|        i = nblimbs;
  264|      0|    }
  265|       |
  266|  6.28k|    if ((p = (mbedtls_mpi_uint *) mbedtls_calloc(i, ciL)) == NULL) {
  ------------------
  |  |  144|  6.28k|#define mbedtls_calloc     MBEDTLS_PLATFORM_CALLOC_MACRO
  |  |  ------------------
  |  |  |  | 4093|  6.28k|#define MBEDTLS_PLATFORM_CALLOC_MACRO        my_calloc
  |  |  ------------------
  ------------------
                  if ((p = (mbedtls_mpi_uint *) mbedtls_calloc(i, ciL)) == NULL) {
  ------------------
  |  |   79|  6.28k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  |  Branch (266:9): [True: 0, False: 6.28k]
  ------------------
  267|      0|        return MBEDTLS_ERR_MPI_ALLOC_FAILED;
  ------------------
  |  |   38|      0|#define MBEDTLS_ERR_MPI_ALLOC_FAILED                      -0x0010
  ------------------
  268|      0|    }
  269|       |
  270|  6.28k|    if (X->p != NULL) {
  ------------------
  |  Branch (270:9): [True: 6.28k, False: 0]
  ------------------
  271|  6.28k|        memcpy(p, X->p, i * ciL);
  ------------------
  |  |   79|  6.28k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  272|  6.28k|        mbedtls_mpi_zeroize_and_free(X->p, X->n);
  ------------------
  |  |  176|  6.28k|#define mbedtls_mpi_zeroize_and_free(v, n) mbedtls_zeroize_and_free(v, ciL * (n))
  |  |  ------------------
  |  |  |  |   79|  6.28k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  273|  6.28k|    }
  274|       |
  275|       |    /* i fits in n because we ensure that MBEDTLS_MPI_MAX_LIMBS
  276|       |     * fits, and we've checked that i <= nblimbs <= MBEDTLS_MPI_MAX_LIMBS. */
  277|  6.28k|    X->n = (unsigned short) i;
  278|  6.28k|    X->p = p;
  279|       |
  280|  6.28k|    return 0;
  281|  6.28k|}
mbedtls_mpi_copy:
  308|   903k|{
  309|   903k|    int ret = 0;
  310|   903k|    size_t i;
  311|       |
  312|   903k|    if (X == Y) {
  ------------------
  |  Branch (312:9): [True: 4.08k, False: 899k]
  ------------------
  313|  4.08k|        return 0;
  314|  4.08k|    }
  315|       |
  316|   899k|    if (Y->n == 0) {
  ------------------
  |  Branch (316:9): [True: 157, False: 899k]
  ------------------
  317|    157|        if (X->n != 0) {
  ------------------
  |  Branch (317:13): [True: 0, False: 157]
  ------------------
  318|      0|            X->s = 1;
  319|      0|            memset(X->p, 0, X->n * ciL);
  ------------------
  |  |   79|      0|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  320|      0|        }
  321|    157|        return 0;
  322|    157|    }
  323|       |
  324|  4.99M|    for (i = Y->n - 1; i > 0; i--) {
  ------------------
  |  Branch (324:24): [True: 4.98M, False: 5.18k]
  ------------------
  325|  4.98M|        if (Y->p[i] != 0) {
  ------------------
  |  Branch (325:13): [True: 894k, False: 4.09M]
  ------------------
  326|   894k|            break;
  327|   894k|        }
  328|  4.98M|    }
  329|   899k|    i++;
  330|       |
  331|   899k|    X->s = Y->s;
  332|       |
  333|   899k|    if (X->n < i) {
  ------------------
  |  Branch (333:9): [True: 374k, False: 525k]
  ------------------
  334|   374k|        MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, i));
  ------------------
  |  |   41|   374k|    do                           \
  |  |   42|   374k|    {                            \
  |  |   43|   374k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 374k]
  |  |  ------------------
  |  |   44|   374k|        goto cleanup;        \
  |  |   45|   374k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  335|   525k|    } else {
  336|   525k|        memset(X->p + i, 0, (X->n - i) * ciL);
  ------------------
  |  |   79|   525k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  337|   525k|    }
  338|       |
  339|   899k|    memcpy(X->p, Y->p, i * ciL);
  ------------------
  |  |   79|   899k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  340|       |
  341|   899k|cleanup:
  342|       |
  343|   899k|    return ret;
  344|   899k|}
mbedtls_mpi_lset:
  378|  1.29M|{
  379|  1.29M|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  1.29M|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  380|       |
  381|  1.29M|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, 1));
  ------------------
  |  |   41|  1.29M|    do                           \
  |  |   42|  1.29M|    {                            \
  |  |   43|  1.29M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.29M]
  |  |  ------------------
  |  |   44|  1.29M|        goto cleanup;        \
  |  |   45|  1.29M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  382|  1.29M|    memset(X->p, 0, X->n * ciL);
  ------------------
  |  |   79|  1.29M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  383|       |
  384|  1.29M|    X->p[0] = mpi_sint_abs(z);
  385|  1.29M|    X->s    = TO_SIGN(z);
  ------------------
  |  |  372|  1.29M|#define TO_SIGN(x) ((mbedtls_mpi_sint) (((mbedtls_mpi_uint) x) >> (biL - 1)) * -2 + 1)
  |  |  ------------------
  |  |  |  |   80|  1.29M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  |  |  ------------------
  |  |  |  |  |  |   79|  1.29M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  386|       |
  387|  1.29M|cleanup:
  388|       |
  389|  1.29M|    return ret;
  390|  1.29M|}
mbedtls_mpi_get_bit:
  396|   165k|{
  397|   165k|    if (X->n * biL <= pos) {
  ------------------
  |  |   80|   165k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|   165k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  |  Branch (397:9): [True: 1.25k, False: 163k]
  ------------------
  398|  1.25k|        return 0;
  399|  1.25k|    }
  400|       |
  401|   163k|    return (X->p[pos / biL] >> (pos % biL)) & 0x01;
  ------------------
  |  |   80|   163k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|   163k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
                  return (X->p[pos / biL] >> (pos % biL)) & 0x01;
  ------------------
  |  |   80|   163k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|   163k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  402|   165k|}
mbedtls_mpi_lsb:
  437|   684k|{
  438|   684k|    size_t i;
  439|       |
  440|   684k|#if defined(__has_builtin)
  441|       |#if (MBEDTLS_MPI_UINT_MAX == UINT_MAX) && __has_builtin(__builtin_ctz)
  442|       |    #define mbedtls_mpi_uint_ctz __builtin_ctz
  443|       |#elif (MBEDTLS_MPI_UINT_MAX == ULONG_MAX) && __has_builtin(__builtin_ctzl)
  444|       |    #define mbedtls_mpi_uint_ctz __builtin_ctzl
  445|       |#elif (MBEDTLS_MPI_UINT_MAX == ULLONG_MAX) && __has_builtin(__builtin_ctzll)
  446|       |    #define mbedtls_mpi_uint_ctz __builtin_ctzll
  447|       |#endif
  448|   684k|#endif
  449|       |
  450|   684k|#if defined(mbedtls_mpi_uint_ctz)
  451|   684k|    for (i = 0; i < X->n; i++) {
  ------------------
  |  Branch (451:17): [True: 684k, False: 0]
  ------------------
  452|   684k|        if (X->p[i] != 0) {
  ------------------
  |  Branch (452:13): [True: 684k, False: 0]
  ------------------
  453|   684k|            return i * biL + mbedtls_mpi_uint_ctz(X->p[i]);
  ------------------
  |  |   80|   684k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|   684k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
                          return i * biL + mbedtls_mpi_uint_ctz(X->p[i]);
  ------------------
  |  |  444|   684k|    #define mbedtls_mpi_uint_ctz __builtin_ctzl
  ------------------
  454|   684k|        }
  455|   684k|    }
  456|       |#else
  457|       |    size_t count = 0;
  458|       |    for (i = 0; i < X->n; i++) {
  459|       |        for (size_t j = 0; j < biL; j++, count++) {
  460|       |            if (((X->p[i] >> j) & 1) != 0) {
  461|       |                return count;
  462|       |            }
  463|       |        }
  464|       |    }
  465|       |#endif
  466|       |
  467|      0|    return 0;
  468|   684k|}
mbedtls_mpi_bitlen:
  474|  1.67M|{
  475|  1.67M|    return mbedtls_mpi_core_bitlen(X->p, X->n);
  476|  1.67M|}
mbedtls_mpi_size:
  482|  2.51k|{
  483|  2.51k|    return (mbedtls_mpi_bitlen(X) + 7) >> 3;
  484|  2.51k|}
mbedtls_mpi_read_binary:
  821|  5.96k|{
  822|  5.96k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  5.96k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  823|  5.96k|    const size_t limbs = CHARS_TO_LIMBS(buflen);
  ------------------
  |  |   88|  5.96k|#define CHARS_TO_LIMBS(i) ((i) / ciL + ((i) % ciL != 0))
  |  |  ------------------
  |  |  |  |   79|  5.96k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  |  |               #define CHARS_TO_LIMBS(i) ((i) / ciL + ((i) % ciL != 0))
  |  |  ------------------
  |  |  |  |   79|  5.96k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  824|       |
  825|       |    /* Ensure that target MPI has exactly the necessary number of limbs */
  826|  5.96k|    MBEDTLS_MPI_CHK(mbedtls_mpi_resize_clear(X, limbs));
  ------------------
  |  |   41|  5.96k|    do                           \
  |  |   42|  5.96k|    {                            \
  |  |   43|  5.96k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 5.96k]
  |  |  ------------------
  |  |   44|  5.96k|        goto cleanup;        \
  |  |   45|  5.96k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  827|       |
  828|  5.96k|    MBEDTLS_MPI_CHK(mbedtls_mpi_core_read_be(X->p, X->n, buf, buflen));
  ------------------
  |  |   41|  5.96k|    do                           \
  |  |   42|  5.96k|    {                            \
  |  |   43|  5.96k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 5.96k]
  |  |  ------------------
  |  |   44|  5.96k|        goto cleanup;        \
  |  |   45|  5.96k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  829|       |
  830|  5.96k|cleanup:
  831|       |
  832|       |    /*
  833|       |     * This function is also used to import keys. However, wiping the buffers
  834|       |     * upon failure is not necessary because failure only can happen before any
  835|       |     * input is copied.
  836|       |     */
  837|  5.96k|    return ret;
  838|  5.96k|}
mbedtls_mpi_shift_l:
  862|   432k|{
  863|   432k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|   432k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  864|   432k|    size_t i;
  865|       |
  866|   432k|    i = mbedtls_mpi_bitlen(X) + count;
  867|       |
  868|   432k|    if (X->n * biL < i) {
  ------------------
  |  |   80|   432k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|   432k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  |  Branch (868:9): [True: 1.88k, False: 430k]
  ------------------
  869|  1.88k|        MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, BITS_TO_LIMBS(i)));
  ------------------
  |  |   41|  1.88k|    do                           \
  |  |   42|  1.88k|    {                            \
  |  |   43|  1.88k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.88k]
  |  |  ------------------
  |  |   44|  1.88k|        goto cleanup;        \
  |  |   45|  1.88k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  870|  1.88k|    }
  871|       |
  872|   432k|    ret = 0;
  873|       |
  874|   432k|    mbedtls_mpi_core_shift_l(X->p, X->n, count);
  875|   432k|cleanup:
  876|       |
  877|   432k|    return ret;
  878|   432k|}
mbedtls_mpi_shift_r:
  884|  3.05M|{
  885|  3.05M|    if (X->n != 0) {
  ------------------
  |  Branch (885:9): [True: 3.05M, False: 0]
  ------------------
  886|  3.05M|        mbedtls_mpi_core_shift_r(X->p, X->n, count);
  887|  3.05M|    }
  888|  3.05M|    return 0;
  889|  3.05M|}
mbedtls_mpi_cmp_abs:
  895|  3.05M|{
  896|  3.05M|    size_t i, j;
  897|       |
  898|  13.8M|    for (i = X->n; i > 0; i--) {
  ------------------
  |  Branch (898:20): [True: 13.8M, False: 2.98k]
  ------------------
  899|  13.8M|        if (X->p[i - 1] != 0) {
  ------------------
  |  Branch (899:13): [True: 3.05M, False: 10.8M]
  ------------------
  900|  3.05M|            break;
  901|  3.05M|        }
  902|  13.8M|    }
  903|       |
  904|  7.48M|    for (j = Y->n; j > 0; j--) {
  ------------------
  |  Branch (904:20): [True: 7.48M, False: 785]
  ------------------
  905|  7.48M|        if (Y->p[j - 1] != 0) {
  ------------------
  |  Branch (905:13): [True: 3.05M, False: 4.42M]
  ------------------
  906|  3.05M|            break;
  907|  3.05M|        }
  908|  7.48M|    }
  909|       |
  910|       |    /* If i == j == 0, i.e. abs(X) == abs(Y),
  911|       |     * we end up returning 0 at the end of the function. */
  912|       |
  913|  3.05M|    if (i > j) {
  ------------------
  |  Branch (913:9): [True: 313k, False: 2.74M]
  ------------------
  914|   313k|        return 1;
  915|   313k|    }
  916|  2.74M|    if (j > i) {
  ------------------
  |  Branch (916:9): [True: 5.49k, False: 2.74M]
  ------------------
  917|  5.49k|        return -1;
  918|  5.49k|    }
  919|       |
  920|  2.75M|    for (; i > 0; i--) {
  ------------------
  |  Branch (920:12): [True: 2.75M, False: 4.39k]
  ------------------
  921|  2.75M|        if (X->p[i - 1] > Y->p[i - 1]) {
  ------------------
  |  Branch (921:13): [True: 915k, False: 1.83M]
  ------------------
  922|   915k|            return 1;
  923|   915k|        }
  924|  1.83M|        if (X->p[i - 1] < Y->p[i - 1]) {
  ------------------
  |  Branch (924:13): [True: 1.82M, False: 14.9k]
  ------------------
  925|  1.82M|            return -1;
  926|  1.82M|        }
  927|  1.83M|    }
  928|       |
  929|  4.39k|    return 0;
  930|  2.74M|}
mbedtls_mpi_cmp_mpi:
  936|  5.39M|{
  937|  5.39M|    size_t i, j;
  938|       |
  939|  25.5M|    for (i = X->n; i > 0; i--) {
  ------------------
  |  Branch (939:20): [True: 25.5M, False: 3.76k]
  ------------------
  940|  25.5M|        if (X->p[i - 1] != 0) {
  ------------------
  |  Branch (940:13): [True: 5.39M, False: 20.1M]
  ------------------
  941|  5.39M|            break;
  942|  5.39M|        }
  943|  25.5M|    }
  944|       |
  945|  8.66M|    for (j = Y->n; j > 0; j--) {
  ------------------
  |  Branch (945:20): [True: 6.45M, False: 2.21M]
  ------------------
  946|  6.45M|        if (Y->p[j - 1] != 0) {
  ------------------
  |  Branch (946:13): [True: 3.18M, False: 3.26M]
  ------------------
  947|  3.18M|            break;
  948|  3.18M|        }
  949|  6.45M|    }
  950|       |
  951|  5.39M|    if (i == 0 && j == 0) {
  ------------------
  |  Branch (951:9): [True: 3.76k, False: 5.39M]
  |  Branch (951:19): [True: 3.76k, False: 0]
  ------------------
  952|  3.76k|        return 0;
  953|  3.76k|    }
  954|       |
  955|  5.39M|    if (i > j) {
  ------------------
  |  Branch (955:9): [True: 2.80M, False: 2.59M]
  ------------------
  956|  2.80M|        return X->s;
  957|  2.80M|    }
  958|  2.59M|    if (j > i) {
  ------------------
  |  Branch (958:9): [True: 13.5k, False: 2.58M]
  ------------------
  959|  13.5k|        return -Y->s;
  960|  13.5k|    }
  961|       |
  962|  2.58M|    if (X->s > 0 && Y->s < 0) {
  ------------------
  |  Branch (962:9): [True: 2.58M, False: 0]
  |  Branch (962:21): [True: 0, False: 2.58M]
  ------------------
  963|      0|        return 1;
  964|      0|    }
  965|  2.58M|    if (Y->s > 0 && X->s < 0) {
  ------------------
  |  Branch (965:9): [True: 2.58M, False: 0]
  |  Branch (965:21): [True: 0, False: 2.58M]
  ------------------
  966|      0|        return -1;
  967|      0|    }
  968|       |
  969|  2.65M|    for (; i > 0; i--) {
  ------------------
  |  Branch (969:12): [True: 2.59M, False: 51.8k]
  ------------------
  970|  2.59M|        if (X->p[i - 1] > Y->p[i - 1]) {
  ------------------
  |  Branch (970:13): [True: 337k, False: 2.26M]
  ------------------
  971|   337k|            return X->s;
  972|   337k|        }
  973|  2.26M|        if (X->p[i - 1] < Y->p[i - 1]) {
  ------------------
  |  Branch (973:13): [True: 2.19M, False: 69.0k]
  ------------------
  974|  2.19M|            return -X->s;
  975|  2.19M|        }
  976|  2.26M|    }
  977|       |
  978|  51.8k|    return 0;
  979|  2.58M|}
mbedtls_mpi_cmp_int:
  985|  2.26M|{
  986|  2.26M|    mbedtls_mpi Y;
  987|  2.26M|    mbedtls_mpi_uint p[1];
  988|       |
  989|  2.26M|    *p  = mpi_sint_abs(z);
  990|  2.26M|    Y.s = TO_SIGN(z);
  ------------------
  |  |  372|  2.26M|#define TO_SIGN(x) ((mbedtls_mpi_sint) (((mbedtls_mpi_uint) x) >> (biL - 1)) * -2 + 1)
  |  |  ------------------
  |  |  |  |   80|  2.26M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  |  |  ------------------
  |  |  |  |  |  |   79|  2.26M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  991|  2.26M|    Y.n = 1;
  992|  2.26M|    Y.p = p;
  993|       |
  994|  2.26M|    return mbedtls_mpi_cmp_mpi(X, &Y);
  995|  2.26M|}
mbedtls_mpi_add_abs:
 1001|   765k|{
 1002|   765k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|   765k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1003|   765k|    size_t j;
 1004|   765k|    mbedtls_mpi_uint *p;
 1005|   765k|    mbedtls_mpi_uint c;
 1006|       |
 1007|   765k|    if (X == B) {
  ------------------
  |  Branch (1007:9): [True: 0, False: 765k]
  ------------------
 1008|      0|        const mbedtls_mpi *T = A; A = X; B = T;
 1009|      0|    }
 1010|       |
 1011|   765k|    if (X != A) {
  ------------------
  |  Branch (1011:9): [True: 96.7k, False: 668k]
  ------------------
 1012|  96.7k|        MBEDTLS_MPI_CHK(mbedtls_mpi_copy(X, A));
  ------------------
  |  |   41|  96.7k|    do                           \
  |  |   42|  96.7k|    {                            \
  |  |   43|  96.7k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 96.7k]
  |  |  ------------------
  |  |   44|  96.7k|        goto cleanup;        \
  |  |   45|  96.7k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1013|  96.7k|    }
 1014|       |
 1015|       |    /*
 1016|       |     * X must always be positive as a result of unsigned additions.
 1017|       |     */
 1018|   765k|    X->s = 1;
 1019|       |
 1020|  1.41M|    for (j = B->n; j > 0; j--) {
  ------------------
  |  Branch (1020:20): [True: 1.41M, False: 157]
  ------------------
 1021|  1.41M|        if (B->p[j - 1] != 0) {
  ------------------
  |  Branch (1021:13): [True: 765k, False: 647k]
  ------------------
 1022|   765k|            break;
 1023|   765k|        }
 1024|  1.41M|    }
 1025|       |
 1026|       |    /* Exit early to avoid undefined behavior on NULL+0 when X->n == 0
 1027|       |     * and B is 0 (of any size). */
 1028|   765k|    if (j == 0) {
  ------------------
  |  Branch (1028:9): [True: 157, False: 765k]
  ------------------
 1029|    157|        return 0;
 1030|    157|    }
 1031|       |
 1032|   765k|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, j));
  ------------------
  |  |   41|   765k|    do                           \
  |  |   42|   765k|    {                            \
  |  |   43|   765k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 765k]
  |  |  ------------------
  |  |   44|   765k|        goto cleanup;        \
  |  |   45|   765k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1033|       |
 1034|       |    /* j is the number of non-zero limbs of B. Add those to X. */
 1035|       |
 1036|   765k|    p = X->p;
 1037|       |
 1038|   765k|    c = mbedtls_mpi_core_add(p, p, B->p, j);
 1039|       |
 1040|   765k|    p += j;
 1041|       |
 1042|       |    /* Now propagate any carry */
 1043|       |
 1044|  1.10M|    while (c != 0) {
  ------------------
  |  Branch (1044:12): [True: 336k, False: 765k]
  ------------------
 1045|   336k|        if (j >= X->n) {
  ------------------
  |  Branch (1045:13): [True: 3.61k, False: 333k]
  ------------------
 1046|  3.61k|            MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, j + 1));
  ------------------
  |  |   41|  3.61k|    do                           \
  |  |   42|  3.61k|    {                            \
  |  |   43|  3.61k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3.61k]
  |  |  ------------------
  |  |   44|  3.61k|        goto cleanup;        \
  |  |   45|  3.61k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1047|  3.61k|            p = X->p + j;
 1048|  3.61k|        }
 1049|       |
 1050|   336k|        *p += c; c = (*p < c); j++; p++;
 1051|   336k|    }
 1052|       |
 1053|   765k|cleanup:
 1054|       |
 1055|   765k|    return ret;
 1056|   765k|}
mbedtls_mpi_sub_abs:
 1062|  3.97M|{
 1063|  3.97M|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  3.97M|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1064|  3.97M|    size_t n;
 1065|  3.97M|    mbedtls_mpi_uint carry;
 1066|       |
 1067|  14.2M|    for (n = B->n; n > 0; n--) {
  ------------------
  |  Branch (1067:20): [True: 14.2M, False: 3.76k]
  ------------------
 1068|  14.2M|        if (B->p[n - 1] != 0) {
  ------------------
  |  Branch (1068:13): [True: 3.96M, False: 10.3M]
  ------------------
 1069|  3.96M|            break;
 1070|  3.96M|        }
 1071|  14.2M|    }
 1072|  3.97M|    if (n > A->n) {
  ------------------
  |  Branch (1072:9): [True: 0, False: 3.97M]
  ------------------
 1073|       |        /* B >= (2^ciL)^n > A */
 1074|      0|        ret = MBEDTLS_ERR_MPI_NEGATIVE_VALUE;
  ------------------
  |  |   32|      0|#define MBEDTLS_ERR_MPI_NEGATIVE_VALUE                    -0x000A
  ------------------
 1075|      0|        goto cleanup;
 1076|      0|    }
 1077|       |
 1078|  3.97M|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, A->n));
  ------------------
  |  |   41|  3.97M|    do                           \
  |  |   42|  3.97M|    {                            \
  |  |   43|  3.97M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3.97M]
  |  |  ------------------
  |  |   44|  3.97M|        goto cleanup;        \
  |  |   45|  3.97M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1079|       |
 1080|       |    /* Set the high limbs of X to match A. Don't touch the lower limbs
 1081|       |     * because X might be aliased to B, and we must not overwrite the
 1082|       |     * significant digits of B. */
 1083|  3.97M|    if (A->n > n && A != X) {
  ------------------
  |  Branch (1083:9): [True: 2.41M, False: 1.56M]
  |  Branch (1083:21): [True: 566k, False: 1.84M]
  ------------------
 1084|   566k|        memcpy(X->p + n, A->p + n, (A->n - n) * ciL);
  ------------------
  |  |   79|   566k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
 1085|   566k|    }
 1086|  3.97M|    if (X->n > A->n) {
  ------------------
  |  Branch (1086:9): [True: 1.26M, False: 2.71M]
  ------------------
 1087|  1.26M|        memset(X->p + A->n, 0, (X->n - A->n) * ciL);
  ------------------
  |  |   79|  1.26M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
 1088|  1.26M|    }
 1089|       |
 1090|  3.97M|    carry = mbedtls_mpi_core_sub(X->p, A->p, B->p, n);
 1091|  3.97M|    if (carry != 0) {
  ------------------
  |  Branch (1091:9): [True: 882k, False: 3.09M]
  ------------------
 1092|       |        /* Propagate the carry through the rest of X. */
 1093|   882k|        carry = mbedtls_mpi_core_sub_int(X->p + n, X->p + n, carry, X->n - n);
 1094|       |
 1095|       |        /* If we have further carry/borrow, the result is negative. */
 1096|   882k|        if (carry != 0) {
  ------------------
  |  Branch (1096:13): [True: 0, False: 882k]
  ------------------
 1097|      0|            ret = MBEDTLS_ERR_MPI_NEGATIVE_VALUE;
  ------------------
  |  |   32|      0|#define MBEDTLS_ERR_MPI_NEGATIVE_VALUE                    -0x000A
  ------------------
 1098|      0|            goto cleanup;
 1099|      0|        }
 1100|   882k|    }
 1101|       |
 1102|       |    /* X should always be positive as a result of unsigned subtractions. */
 1103|  3.97M|    X->s = 1;
 1104|       |
 1105|  3.97M|cleanup:
 1106|  3.97M|    return ret;
 1107|  3.97M|}
mbedtls_mpi_add_mpi:
 1146|  1.74M|{
 1147|  1.74M|    return add_sub_mpi(X, A, B, 1);
 1148|  1.74M|}
mbedtls_mpi_sub_mpi:
 1154|  2.07M|{
 1155|  2.07M|    return add_sub_mpi(X, A, B, -1);
 1156|  2.07M|}
mbedtls_mpi_sub_int:
 1178|  3.14k|{
 1179|  3.14k|    mbedtls_mpi B;
 1180|  3.14k|    mbedtls_mpi_uint p[1];
 1181|       |
 1182|  3.14k|    p[0] = mpi_sint_abs(b);
 1183|  3.14k|    B.s = TO_SIGN(b);
  ------------------
  |  |  372|  3.14k|#define TO_SIGN(x) ((mbedtls_mpi_sint) (((mbedtls_mpi_uint) x) >> (biL - 1)) * -2 + 1)
  |  |  ------------------
  |  |  |  |   80|  3.14k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  |  |  ------------------
  |  |  |  |  |  |   79|  3.14k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1184|  3.14k|    B.n = 1;
 1185|  3.14k|    B.p = p;
 1186|       |
 1187|  3.14k|    return mbedtls_mpi_sub_mpi(X, A, &B);
 1188|  3.14k|}
mbedtls_mpi_mul_mpi:
 1194|  1.23M|{
 1195|  1.23M|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  1.23M|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1196|  1.23M|    size_t i, j;
 1197|  1.23M|    mbedtls_mpi TA, TB;
 1198|  1.23M|    int result_is_zero = 0;
 1199|       |
 1200|  1.23M|    mbedtls_mpi_init(&TA);
 1201|  1.23M|    mbedtls_mpi_init(&TB);
 1202|       |
 1203|  1.23M|    if (X == A) {
  ------------------
  |  Branch (1203:9): [True: 347k, False: 888k]
  ------------------
 1204|   347k|        MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TA, A)); A = &TA;
  ------------------
  |  |   41|   347k|    do                           \
  |  |   42|   347k|    {                            \
  |  |   43|   347k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 347k]
  |  |  ------------------
  |  |   44|   347k|        goto cleanup;        \
  |  |   45|   347k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1205|   347k|    }
 1206|  1.23M|    if (X == B) {
  ------------------
  |  Branch (1206:9): [True: 4.08k, False: 1.23M]
  ------------------
 1207|  4.08k|        MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TB, B)); B = &TB;
  ------------------
  |  |   41|  4.08k|    do                           \
  |  |   42|  4.08k|    {                            \
  |  |   43|  4.08k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.08k]
  |  |  ------------------
  |  |   44|  4.08k|        goto cleanup;        \
  |  |   45|  4.08k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1208|  4.08k|    }
 1209|       |
 1210|  4.16M|    for (i = A->n; i > 0; i--) {
  ------------------
  |  Branch (1210:20): [True: 4.16M, False: 0]
  ------------------
 1211|  4.16M|        if (A->p[i - 1] != 0) {
  ------------------
  |  Branch (1211:13): [True: 1.23M, False: 2.93M]
  ------------------
 1212|  1.23M|            break;
 1213|  1.23M|        }
 1214|  4.16M|    }
 1215|  1.23M|    if (i == 0) {
  ------------------
  |  Branch (1215:9): [True: 0, False: 1.23M]
  ------------------
 1216|      0|        result_is_zero = 1;
 1217|      0|    }
 1218|       |
 1219|  5.50M|    for (j = B->n; j > 0; j--) {
  ------------------
  |  Branch (1219:20): [True: 5.50M, False: 0]
  ------------------
 1220|  5.50M|        if (B->p[j - 1] != 0) {
  ------------------
  |  Branch (1220:13): [True: 1.23M, False: 4.27M]
  ------------------
 1221|  1.23M|            break;
 1222|  1.23M|        }
 1223|  5.50M|    }
 1224|  1.23M|    if (j == 0) {
  ------------------
  |  Branch (1224:9): [True: 0, False: 1.23M]
  ------------------
 1225|      0|        result_is_zero = 1;
 1226|      0|    }
 1227|       |
 1228|  1.23M|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, i + j));
  ------------------
  |  |   41|  1.23M|    do                           \
  |  |   42|  1.23M|    {                            \
  |  |   43|  1.23M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.23M]
  |  |  ------------------
  |  |   44|  1.23M|        goto cleanup;        \
  |  |   45|  1.23M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1229|  1.23M|    MBEDTLS_MPI_CHK(mbedtls_mpi_lset(X, 0));
  ------------------
  |  |   41|  1.23M|    do                           \
  |  |   42|  1.23M|    {                            \
  |  |   43|  1.23M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.23M]
  |  |  ------------------
  |  |   44|  1.23M|        goto cleanup;        \
  |  |   45|  1.23M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1230|       |
 1231|  1.23M|    mbedtls_mpi_core_mul(X->p, A->p, i, B->p, j);
 1232|       |
 1233|       |    /* If the result is 0, we don't shortcut the operation, which reduces
 1234|       |     * but does not eliminate side channels leaking the zero-ness. We do
 1235|       |     * need to take care to set the sign bit properly since the library does
 1236|       |     * not fully support an MPI object with a value of 0 and s == -1. */
 1237|  1.23M|    if (result_is_zero) {
  ------------------
  |  Branch (1237:9): [True: 0, False: 1.23M]
  ------------------
 1238|      0|        X->s = 1;
 1239|  1.23M|    } else {
 1240|  1.23M|        X->s = A->s * B->s;
 1241|  1.23M|    }
 1242|       |
 1243|  1.23M|cleanup:
 1244|       |
 1245|  1.23M|    mbedtls_mpi_free(&TB); mbedtls_mpi_free(&TA);
 1246|       |
 1247|  1.23M|    return ret;
 1248|  1.23M|}
mbedtls_mpi_mul_int:
 1254|   102k|{
 1255|   102k|    size_t n = A->n;
 1256|   626k|    while (n > 0 && A->p[n - 1] == 0) {
  ------------------
  |  Branch (1256:12): [True: 626k, False: 0]
  |  Branch (1256:21): [True: 523k, False: 102k]
  ------------------
 1257|   523k|        --n;
 1258|   523k|    }
 1259|       |
 1260|       |    /* The general method below doesn't work if b==0. */
 1261|   102k|    if (b == 0 || n == 0) {
  ------------------
  |  Branch (1261:9): [True: 0, False: 102k]
  |  Branch (1261:19): [True: 0, False: 102k]
  ------------------
 1262|      0|        return mbedtls_mpi_lset(X, 0);
 1263|      0|    }
 1264|       |
 1265|       |    /* Calculate A*b as A + A*(b-1) to take advantage of mbedtls_mpi_core_mla */
 1266|   102k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|   102k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1267|       |    /* In general, A * b requires 1 limb more than b. If
 1268|       |     * A->p[n - 1] * b / b == A->p[n - 1], then A * b fits in the same
 1269|       |     * number of limbs as A and the call to grow() is not required since
 1270|       |     * copy() will take care of the growth if needed. However, experimentally,
 1271|       |     * making the call to grow() unconditional causes slightly fewer
 1272|       |     * calls to calloc() in ECP code, presumably because it reuses the
 1273|       |     * same mpi for a while and this way the mpi is more likely to directly
 1274|       |     * grow to its final size.
 1275|       |     *
 1276|       |     * Note that calculating A*b as 0 + A*b doesn't work as-is because
 1277|       |     * A,X can be the same. */
 1278|   102k|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, n + 1));
  ------------------
  |  |   41|   102k|    do                           \
  |  |   42|   102k|    {                            \
  |  |   43|   102k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 102k]
  |  |  ------------------
  |  |   44|   102k|        goto cleanup;        \
  |  |   45|   102k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1279|   102k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(X, A));
  ------------------
  |  |   41|   102k|    do                           \
  |  |   42|   102k|    {                            \
  |  |   43|   102k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 102k]
  |  |  ------------------
  |  |   44|   102k|        goto cleanup;        \
  |  |   45|   102k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1280|   102k|    mbedtls_mpi_core_mla(X->p, X->n, A->p, n, b - 1);
 1281|       |
 1282|   102k|cleanup:
 1283|   102k|    return ret;
 1284|   102k|}
mbedtls_mpi_div_mpi:
 1395|  2.82k|{
 1396|  2.82k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  2.82k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1397|  2.82k|    size_t i, n, t, k;
 1398|  2.82k|    mbedtls_mpi X, Y, Z, T1, T2;
 1399|  2.82k|    mbedtls_mpi_uint TP2[3];
 1400|       |
 1401|  2.82k|    if (mbedtls_mpi_cmp_int(B, 0) == 0) {
  ------------------
  |  Branch (1401:9): [True: 0, False: 2.82k]
  ------------------
 1402|      0|        return MBEDTLS_ERR_MPI_DIVISION_BY_ZERO;
  ------------------
  |  |   34|      0|#define MBEDTLS_ERR_MPI_DIVISION_BY_ZERO                  -0x000C
  ------------------
 1403|      0|    }
 1404|       |
 1405|  2.82k|    mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y); mbedtls_mpi_init(&Z);
 1406|  2.82k|    mbedtls_mpi_init(&T1);
 1407|       |    /*
 1408|       |     * Avoid dynamic memory allocations for constant-size T2.
 1409|       |     *
 1410|       |     * T2 is used for comparison only and the 3 limbs are assigned explicitly,
 1411|       |     * so nobody increase the size of the MPI and we're safe to use an on-stack
 1412|       |     * buffer.
 1413|       |     */
 1414|  2.82k|    T2.s = 1;
 1415|  2.82k|    T2.n = sizeof(TP2) / sizeof(*TP2);
 1416|  2.82k|    T2.p = TP2;
 1417|       |
 1418|  2.82k|    if (mbedtls_mpi_cmp_abs(A, B) < 0) {
  ------------------
  |  Branch (1418:9): [True: 2.19k, False: 628]
  ------------------
 1419|  2.19k|        if (Q != NULL) {
  ------------------
  |  Branch (1419:13): [True: 0, False: 2.19k]
  ------------------
 1420|      0|            MBEDTLS_MPI_CHK(mbedtls_mpi_lset(Q, 0));
  ------------------
  |  |   41|      0|    do                           \
  |  |   42|      0|    {                            \
  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  ------------------
  |  |   44|      0|        goto cleanup;        \
  |  |   45|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1421|      0|        }
 1422|  2.19k|        if (R != NULL) {
  ------------------
  |  Branch (1422:13): [True: 2.19k, False: 0]
  ------------------
 1423|  2.19k|            MBEDTLS_MPI_CHK(mbedtls_mpi_copy(R, A));
  ------------------
  |  |   41|  2.19k|    do                           \
  |  |   42|  2.19k|    {                            \
  |  |   43|  2.19k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.19k]
  |  |  ------------------
  |  |   44|  2.19k|        goto cleanup;        \
  |  |   45|  2.19k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1424|  2.19k|        }
 1425|  2.19k|        return 0;
 1426|  2.19k|    }
 1427|       |
 1428|    628|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&X, A));
  ------------------
  |  |   41|    628|    do                           \
  |  |   42|    628|    {                            \
  |  |   43|    628|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 628]
  |  |  ------------------
  |  |   44|    628|        goto cleanup;        \
  |  |   45|    628|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1429|    628|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&Y, B));
  ------------------
  |  |   41|    628|    do                           \
  |  |   42|    628|    {                            \
  |  |   43|    628|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 628]
  |  |  ------------------
  |  |   44|    628|        goto cleanup;        \
  |  |   45|    628|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1430|    628|    X.s = Y.s = 1;
 1431|       |
 1432|    628|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(&Z, A->n + 2));
  ------------------
  |  |   41|    628|    do                           \
  |  |   42|    628|    {                            \
  |  |   43|    628|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 628]
  |  |  ------------------
  |  |   44|    628|        goto cleanup;        \
  |  |   45|    628|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1433|    628|    MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&Z,  0));
  ------------------
  |  |   41|    628|    do                           \
  |  |   42|    628|    {                            \
  |  |   43|    628|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 628]
  |  |  ------------------
  |  |   44|    628|        goto cleanup;        \
  |  |   45|    628|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1434|    628|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(&T1, A->n + 2));
  ------------------
  |  |   41|    628|    do                           \
  |  |   42|    628|    {                            \
  |  |   43|    628|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 628]
  |  |  ------------------
  |  |   44|    628|        goto cleanup;        \
  |  |   45|    628|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1435|       |
 1436|    628|    k = mbedtls_mpi_bitlen(&Y) % biL;
  ------------------
  |  |   80|    628|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|    628|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
 1437|    628|    if (k < biL - 1) {
  ------------------
  |  |   80|    628|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|    628|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  |  Branch (1437:9): [True: 628, False: 0]
  ------------------
 1438|    628|        k = biL - 1 - k;
  ------------------
  |  |   80|    628|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|    628|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
 1439|    628|        MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&X, k));
  ------------------
  |  |   41|    628|    do                           \
  |  |   42|    628|    {                            \
  |  |   43|    628|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 628]
  |  |  ------------------
  |  |   44|    628|        goto cleanup;        \
  |  |   45|    628|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1440|    628|        MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&Y, k));
  ------------------
  |  |   41|    628|    do                           \
  |  |   42|    628|    {                            \
  |  |   43|    628|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 628]
  |  |  ------------------
  |  |   44|    628|        goto cleanup;        \
  |  |   45|    628|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1441|    628|    } else {
 1442|      0|        k = 0;
 1443|      0|    }
 1444|       |
 1445|    628|    n = X.n - 1;
 1446|    628|    t = Y.n - 1;
 1447|    628|    MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&Y, biL * (n - t)));
  ------------------
  |  |   41|    628|    do                           \
  |  |   42|    628|    {                            \
  |  |   43|    628|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 628]
  |  |  ------------------
  |  |   44|    628|        goto cleanup;        \
  |  |   45|    628|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1448|       |
 1449|    628|    while (mbedtls_mpi_cmp_mpi(&X, &Y) >= 0) {
  ------------------
  |  Branch (1449:12): [True: 0, False: 628]
  ------------------
 1450|      0|        Z.p[n - t]++;
 1451|      0|        MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&X, &X, &Y));
  ------------------
  |  |   41|      0|    do                           \
  |  |   42|      0|    {                            \
  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  ------------------
  |  |   44|      0|        goto cleanup;        \
  |  |   45|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1452|      0|    }
 1453|    628|    MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&Y, biL * (n - t)));
  ------------------
  |  |   41|    628|    do                           \
  |  |   42|    628|    {                            \
  |  |   43|    628|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 628]
  |  |  ------------------
  |  |   44|    628|        goto cleanup;        \
  |  |   45|    628|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1454|       |
 1455|  3.14k|    for (i = n; i > t; i--) {
  ------------------
  |  Branch (1455:17): [True: 2.51k, False: 628]
  ------------------
 1456|  2.51k|        if (X.p[i] >= Y.p[t]) {
  ------------------
  |  Branch (1456:13): [True: 0, False: 2.51k]
  ------------------
 1457|      0|            Z.p[i - t - 1] = ~(mbedtls_mpi_uint) 0u;
 1458|  2.51k|        } else {
 1459|  2.51k|            Z.p[i - t - 1] = mbedtls_int_div_int(X.p[i], X.p[i - 1],
 1460|  2.51k|                                                 Y.p[t], NULL);
 1461|  2.51k|        }
 1462|       |
 1463|  2.51k|        T2.p[0] = (i < 2) ? 0 : X.p[i - 2];
  ------------------
  |  Branch (1463:19): [True: 0, False: 2.51k]
  ------------------
 1464|  2.51k|        T2.p[1] = (i < 1) ? 0 : X.p[i - 1];
  ------------------
  |  Branch (1464:19): [True: 0, False: 2.51k]
  ------------------
 1465|  2.51k|        T2.p[2] = X.p[i];
 1466|       |
 1467|  2.51k|        Z.p[i - t - 1]++;
 1468|  3.76k|        do {
 1469|  3.76k|            Z.p[i - t - 1]--;
 1470|       |
 1471|  3.76k|            MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&T1, 0));
  ------------------
  |  |   41|  3.76k|    do                           \
  |  |   42|  3.76k|    {                            \
  |  |   43|  3.76k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3.76k]
  |  |  ------------------
  |  |   44|  3.76k|        goto cleanup;        \
  |  |   45|  3.76k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1472|  3.76k|            T1.p[0] = (t < 1) ? 0 : Y.p[t - 1];
  ------------------
  |  Branch (1472:23): [True: 0, False: 3.76k]
  ------------------
 1473|  3.76k|            T1.p[1] = Y.p[t];
 1474|  3.76k|            MBEDTLS_MPI_CHK(mbedtls_mpi_mul_int(&T1, &T1, Z.p[i - t - 1]));
  ------------------
  |  |   41|  3.76k|    do                           \
  |  |   42|  3.76k|    {                            \
  |  |   43|  3.76k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3.76k]
  |  |  ------------------
  |  |   44|  3.76k|        goto cleanup;        \
  |  |   45|  3.76k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1475|  3.76k|        } while (mbedtls_mpi_cmp_mpi(&T1, &T2) > 0);
  ------------------
  |  Branch (1475:18): [True: 1.25k, False: 2.51k]
  ------------------
 1476|       |
 1477|  2.51k|        MBEDTLS_MPI_CHK(mbedtls_mpi_mul_int(&T1, &Y, Z.p[i - t - 1]));
  ------------------
  |  |   41|  2.51k|    do                           \
  |  |   42|  2.51k|    {                            \
  |  |   43|  2.51k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.51k]
  |  |  ------------------
  |  |   44|  2.51k|        goto cleanup;        \
  |  |   45|  2.51k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1478|  2.51k|        MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&T1,  biL * (i - t - 1)));
  ------------------
  |  |   41|  2.51k|    do                           \
  |  |   42|  2.51k|    {                            \
  |  |   43|  2.51k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.51k]
  |  |  ------------------
  |  |   44|  2.51k|        goto cleanup;        \
  |  |   45|  2.51k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1479|  2.51k|        MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&X, &X, &T1));
  ------------------
  |  |   41|  2.51k|    do                           \
  |  |   42|  2.51k|    {                            \
  |  |   43|  2.51k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.51k]
  |  |  ------------------
  |  |   44|  2.51k|        goto cleanup;        \
  |  |   45|  2.51k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1480|       |
 1481|  2.51k|        if (mbedtls_mpi_cmp_int(&X, 0) < 0) {
  ------------------
  |  Branch (1481:13): [True: 0, False: 2.51k]
  ------------------
 1482|      0|            MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&T1, &Y));
  ------------------
  |  |   41|      0|    do                           \
  |  |   42|      0|    {                            \
  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  ------------------
  |  |   44|      0|        goto cleanup;        \
  |  |   45|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1483|      0|            MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&T1, biL * (i - t - 1)));
  ------------------
  |  |   41|      0|    do                           \
  |  |   42|      0|    {                            \
  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  ------------------
  |  |   44|      0|        goto cleanup;        \
  |  |   45|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1484|      0|            MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&X, &X, &T1));
  ------------------
  |  |   41|      0|    do                           \
  |  |   42|      0|    {                            \
  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  ------------------
  |  |   44|      0|        goto cleanup;        \
  |  |   45|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1485|      0|            Z.p[i - t - 1]--;
 1486|      0|        }
 1487|  2.51k|    }
 1488|       |
 1489|    628|    if (Q != NULL) {
  ------------------
  |  Branch (1489:9): [True: 0, False: 628]
  ------------------
 1490|      0|        MBEDTLS_MPI_CHK(mbedtls_mpi_copy(Q, &Z));
  ------------------
  |  |   41|      0|    do                           \
  |  |   42|      0|    {                            \
  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  ------------------
  |  |   44|      0|        goto cleanup;        \
  |  |   45|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1491|      0|        Q->s = A->s * B->s;
 1492|      0|    }
 1493|       |
 1494|    628|    if (R != NULL) {
  ------------------
  |  Branch (1494:9): [True: 628, False: 0]
  ------------------
 1495|    628|        MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&X, k));
  ------------------
  |  |   41|    628|    do                           \
  |  |   42|    628|    {                            \
  |  |   43|    628|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 628]
  |  |  ------------------
  |  |   44|    628|        goto cleanup;        \
  |  |   45|    628|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1496|    628|        X.s = A->s;
 1497|    628|        MBEDTLS_MPI_CHK(mbedtls_mpi_copy(R, &X));
  ------------------
  |  |   41|    628|    do                           \
  |  |   42|    628|    {                            \
  |  |   43|    628|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 628]
  |  |  ------------------
  |  |   44|    628|        goto cleanup;        \
  |  |   45|    628|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1498|       |
 1499|    628|        if (mbedtls_mpi_cmp_int(R, 0) == 0) {
  ------------------
  |  Branch (1499:13): [True: 0, False: 628]
  ------------------
 1500|      0|            R->s = 1;
 1501|      0|        }
 1502|    628|    }
 1503|       |
 1504|    628|cleanup:
 1505|       |
 1506|    628|    mbedtls_mpi_free(&X); mbedtls_mpi_free(&Y); mbedtls_mpi_free(&Z);
 1507|    628|    mbedtls_mpi_free(&T1);
 1508|    628|    mbedtls_platform_zeroize(TP2, sizeof(TP2));
 1509|       |
 1510|    628|    return ret;
 1511|    628|}
mbedtls_mpi_mod_mpi:
 1535|  2.82k|{
 1536|  2.82k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  2.82k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1537|       |
 1538|  2.82k|    if (mbedtls_mpi_cmp_int(B, 0) < 0) {
  ------------------
  |  Branch (1538:9): [True: 0, False: 2.82k]
  ------------------
 1539|      0|        return MBEDTLS_ERR_MPI_NEGATIVE_VALUE;
  ------------------
  |  |   32|      0|#define MBEDTLS_ERR_MPI_NEGATIVE_VALUE                    -0x000A
  ------------------
 1540|      0|    }
 1541|       |
 1542|  2.82k|    MBEDTLS_MPI_CHK(mbedtls_mpi_div_mpi(NULL, R, A, B));
  ------------------
  |  |   41|  2.82k|    do                           \
  |  |   42|  2.82k|    {                            \
  |  |   43|  2.82k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.82k]
  |  |  ------------------
  |  |   44|  2.82k|        goto cleanup;        \
  |  |   45|  2.82k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1543|       |
 1544|  2.82k|    while (mbedtls_mpi_cmp_int(R, 0) < 0) {
  ------------------
  |  Branch (1544:12): [True: 0, False: 2.82k]
  ------------------
 1545|      0|        MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(R, R, B));
  ------------------
  |  |   41|      0|    do                           \
  |  |   42|      0|    {                            \
  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  ------------------
  |  |   44|      0|        goto cleanup;        \
  |  |   45|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1546|      0|    }
 1547|       |
 1548|  2.82k|    while (mbedtls_mpi_cmp_mpi(R, B) >= 0) {
  ------------------
  |  Branch (1548:12): [True: 0, False: 2.82k]
  ------------------
 1549|      0|        MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(R, R, B));
  ------------------
  |  |   41|      0|    do                           \
  |  |   42|      0|    {                            \
  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  ------------------
  |  |   44|      0|        goto cleanup;        \
  |  |   45|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1550|      0|    }
 1551|       |
 1552|  2.82k|cleanup:
 1553|       |
 1554|  2.82k|    return ret;
 1555|  2.82k|}
mbedtls_mpi_gcd:
 1750|  1.88k|{
 1751|  1.88k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  1.88k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1752|  1.88k|    size_t lz, lzt;
 1753|  1.88k|    mbedtls_mpi TA, TB;
 1754|       |
 1755|  1.88k|    mbedtls_mpi_init(&TA); mbedtls_mpi_init(&TB);
 1756|       |
 1757|  1.88k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TA, A));
  ------------------
  |  |   41|  1.88k|    do                           \
  |  |   42|  1.88k|    {                            \
  |  |   43|  1.88k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.88k]
  |  |  ------------------
  |  |   44|  1.88k|        goto cleanup;        \
  |  |   45|  1.88k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1758|  1.88k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TB, B));
  ------------------
  |  |   41|  1.88k|    do                           \
  |  |   42|  1.88k|    {                            \
  |  |   43|  1.88k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.88k]
  |  |  ------------------
  |  |   44|  1.88k|        goto cleanup;        \
  |  |   45|  1.88k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1759|       |
 1760|  1.88k|    lz = mbedtls_mpi_lsb(&TA);
 1761|  1.88k|    lzt = mbedtls_mpi_lsb(&TB);
 1762|       |
 1763|       |    /* The loop below gives the correct result when A==0 but not when B==0.
 1764|       |     * So have a special case for B==0. Leverage the fact that we just
 1765|       |     * calculated the lsb and lsb(B)==0 iff B is odd or 0 to make the test
 1766|       |     * slightly more efficient than cmp_int(). */
 1767|  1.88k|    if (lzt == 0 && mbedtls_mpi_get_bit(&TB, 0) == 0) {
  ------------------
  |  Branch (1767:9): [True: 1.88k, False: 0]
  |  Branch (1767:21): [True: 0, False: 1.88k]
  ------------------
 1768|      0|        ret = mbedtls_mpi_copy(G, A);
 1769|      0|        goto cleanup;
 1770|      0|    }
 1771|       |
 1772|  1.88k|    if (lzt < lz) {
  ------------------
  |  Branch (1772:9): [True: 1.09k, False: 785]
  ------------------
 1773|  1.09k|        lz = lzt;
 1774|  1.09k|    }
 1775|       |
 1776|  1.88k|    TA.s = TB.s = 1;
 1777|       |
 1778|       |    /* We mostly follow the procedure described in HAC 14.54, but with some
 1779|       |     * minor differences:
 1780|       |     * - Sequences of multiplications or divisions by 2 are grouped into a
 1781|       |     *   single shift operation.
 1782|       |     * - The procedure in HAC assumes that 0 < TB <= TA.
 1783|       |     *     - The condition TB <= TA is not actually necessary for correctness.
 1784|       |     *       TA and TB have symmetric roles except for the loop termination
 1785|       |     *       condition, and the shifts at the beginning of the loop body
 1786|       |     *       remove any significance from the ordering of TA vs TB before
 1787|       |     *       the shifts.
 1788|       |     *     - If TA = 0, the loop goes through 0 iterations and the result is
 1789|       |     *       correctly TB.
 1790|       |     *     - The case TB = 0 was short-circuited above.
 1791|       |     *
 1792|       |     * For the correctness proof below, decompose the original values of
 1793|       |     * A and B as
 1794|       |     *   A = sa * 2^a * A' with A'=0 or A' odd, and sa = +-1
 1795|       |     *   B = sb * 2^b * B' with B'=0 or B' odd, and sb = +-1
 1796|       |     * Then gcd(A, B) = 2^{min(a,b)} * gcd(A',B'),
 1797|       |     * and gcd(A',B') is odd or 0.
 1798|       |     *
 1799|       |     * At the beginning, we have TA = |A| and TB = |B| so gcd(A,B) = gcd(TA,TB).
 1800|       |     * The code maintains the following invariant:
 1801|       |     *     gcd(A,B) = 2^k * gcd(TA,TB) for some k   (I)
 1802|       |     */
 1803|       |
 1804|       |    /* Proof that the loop terminates:
 1805|       |     * At each iteration, either the right-shift by 1 is made on a nonzero
 1806|       |     * value and the nonnegative integer bitlen(TA) + bitlen(TB) decreases
 1807|       |     * by at least 1, or the right-shift by 1 is made on zero and then
 1808|       |     * TA becomes 0 which ends the loop (TB cannot be 0 if it is right-shifted
 1809|       |     * since in that case TB is calculated from TB-TA with the condition TB>TA).
 1810|       |     */
 1811|   342k|    while (mbedtls_mpi_cmp_int(&TA, 0) != 0) {
  ------------------
  |  Branch (1811:12): [True: 340k, False: 1.88k]
  ------------------
 1812|       |        /* Divisions by 2 preserve the invariant (I). */
 1813|   340k|        MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TA, mbedtls_mpi_lsb(&TA)));
  ------------------
  |  |   41|   340k|    do                           \
  |  |   42|   340k|    {                            \
  |  |   43|   340k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 340k]
  |  |  ------------------
  |  |   44|   340k|        goto cleanup;        \
  |  |   45|   340k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1814|   340k|        MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TB, mbedtls_mpi_lsb(&TB)));
  ------------------
  |  |   41|   340k|    do                           \
  |  |   42|   340k|    {                            \
  |  |   43|   340k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 340k]
  |  |  ------------------
  |  |   44|   340k|        goto cleanup;        \
  |  |   45|   340k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1815|       |
 1816|       |        /* Set either TA or TB to |TA-TB|/2. Since TA and TB are both odd,
 1817|       |         * TA-TB is even so the division by 2 has an integer result.
 1818|       |         * Invariant (I) is preserved since any odd divisor of both TA and TB
 1819|       |         * also divides |TA-TB|/2, and any odd divisor of both TA and |TA-TB|/2
 1820|       |         * also divides TB, and any odd divisor of both TB and |TA-TB|/2 also
 1821|       |         * divides TA.
 1822|       |         */
 1823|   340k|        if (mbedtls_mpi_cmp_mpi(&TA, &TB) >= 0) {
  ------------------
  |  Branch (1823:13): [True: 174k, False: 165k]
  ------------------
 1824|   174k|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs(&TA, &TA, &TB));
  ------------------
  |  |   41|   174k|    do                           \
  |  |   42|   174k|    {                            \
  |  |   43|   174k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 174k]
  |  |  ------------------
  |  |   44|   174k|        goto cleanup;        \
  |  |   45|   174k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1825|   174k|            MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TA, 1));
  ------------------
  |  |   41|   174k|    do                           \
  |  |   42|   174k|    {                            \
  |  |   43|   174k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 174k]
  |  |  ------------------
  |  |   44|   174k|        goto cleanup;        \
  |  |   45|   174k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1826|   174k|        } else {
 1827|   165k|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs(&TB, &TB, &TA));
  ------------------
  |  |   41|   165k|    do                           \
  |  |   42|   165k|    {                            \
  |  |   43|   165k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 165k]
  |  |  ------------------
  |  |   44|   165k|        goto cleanup;        \
  |  |   45|   165k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1828|   165k|            MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TB, 1));
  ------------------
  |  |   41|   165k|    do                           \
  |  |   42|   165k|    {                            \
  |  |   43|   165k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 165k]
  |  |  ------------------
  |  |   44|   165k|        goto cleanup;        \
  |  |   45|   165k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1829|   165k|        }
 1830|       |        /* Note that one of TA or TB is still odd. */
 1831|   340k|    }
 1832|       |
 1833|       |    /* By invariant (I), gcd(A,B) = 2^k * gcd(TA,TB) for some k.
 1834|       |     * At the loop exit, TA = 0, so gcd(TA,TB) = TB.
 1835|       |     * - If there was at least one loop iteration, then one of TA or TB is odd,
 1836|       |     *   and TA = 0, so TB is odd and gcd(TA,TB) = gcd(A',B'). In this case,
 1837|       |     *   lz = min(a,b) so gcd(A,B) = 2^lz * TB.
 1838|       |     * - If there was no loop iteration, then A was 0, and gcd(A,B) = B.
 1839|       |     *   In this case, lz = 0 and B = TB so gcd(A,B) = B = 2^lz * TB as well.
 1840|       |     */
 1841|       |
 1842|  1.88k|    MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&TB, lz));
  ------------------
  |  |   41|  1.88k|    do                           \
  |  |   42|  1.88k|    {                            \
  |  |   43|  1.88k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.88k]
  |  |  ------------------
  |  |   44|  1.88k|        goto cleanup;        \
  |  |   45|  1.88k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1843|  1.88k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(G, &TB));
  ------------------
  |  |   41|  1.88k|    do                           \
  |  |   42|  1.88k|    {                            \
  |  |   43|  1.88k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.88k]
  |  |  ------------------
  |  |   44|  1.88k|        goto cleanup;        \
  |  |   45|  1.88k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1844|       |
 1845|  1.88k|cleanup:
 1846|       |
 1847|  1.88k|    mbedtls_mpi_free(&TA); mbedtls_mpi_free(&TB);
 1848|       |
 1849|  1.88k|    return ret;
 1850|  1.88k|}
mbedtls_mpi_inv_mod:
 1905|  1.88k|{
 1906|  1.88k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  1.88k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1907|  1.88k|    mbedtls_mpi G, TA, TU, U1, U2, TB, TV, V1, V2;
 1908|       |
 1909|  1.88k|    if (mbedtls_mpi_cmp_int(N, 1) <= 0) {
  ------------------
  |  Branch (1909:9): [True: 0, False: 1.88k]
  ------------------
 1910|      0|        return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MPI_BAD_INPUT_DATA                    -0x0004
  ------------------
 1911|      0|    }
 1912|       |
 1913|  1.88k|    mbedtls_mpi_init(&TA); mbedtls_mpi_init(&TU); mbedtls_mpi_init(&U1); mbedtls_mpi_init(&U2);
 1914|  1.88k|    mbedtls_mpi_init(&G); mbedtls_mpi_init(&TB); mbedtls_mpi_init(&TV);
 1915|  1.88k|    mbedtls_mpi_init(&V1); mbedtls_mpi_init(&V2);
 1916|       |
 1917|  1.88k|    MBEDTLS_MPI_CHK(mbedtls_mpi_gcd(&G, A, N));
  ------------------
  |  |   41|  1.88k|    do                           \
  |  |   42|  1.88k|    {                            \
  |  |   43|  1.88k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.88k]
  |  |  ------------------
  |  |   44|  1.88k|        goto cleanup;        \
  |  |   45|  1.88k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1918|       |
 1919|  1.88k|    if (mbedtls_mpi_cmp_int(&G, 1) != 0) {
  ------------------
  |  Branch (1919:9): [True: 0, False: 1.88k]
  ------------------
 1920|      0|        ret = MBEDTLS_ERR_MPI_NOT_ACCEPTABLE;
  ------------------
  |  |   36|      0|#define MBEDTLS_ERR_MPI_NOT_ACCEPTABLE                    -0x000E
  ------------------
 1921|      0|        goto cleanup;
 1922|      0|    }
 1923|       |
 1924|  1.88k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&TA, A, N));
  ------------------
  |  |   41|  1.88k|    do                           \
  |  |   42|  1.88k|    {                            \
  |  |   43|  1.88k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.88k]
  |  |  ------------------
  |  |   44|  1.88k|        goto cleanup;        \
  |  |   45|  1.88k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1925|  1.88k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TU, &TA));
  ------------------
  |  |   41|  1.88k|    do                           \
  |  |   42|  1.88k|    {                            \
  |  |   43|  1.88k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.88k]
  |  |  ------------------
  |  |   44|  1.88k|        goto cleanup;        \
  |  |   45|  1.88k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1926|  1.88k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TB, N));
  ------------------
  |  |   41|  1.88k|    do                           \
  |  |   42|  1.88k|    {                            \
  |  |   43|  1.88k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.88k]
  |  |  ------------------
  |  |   44|  1.88k|        goto cleanup;        \
  |  |   45|  1.88k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1927|  1.88k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TV, N));
  ------------------
  |  |   41|  1.88k|    do                           \
  |  |   42|  1.88k|    {                            \
  |  |   43|  1.88k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.88k]
  |  |  ------------------
  |  |   44|  1.88k|        goto cleanup;        \
  |  |   45|  1.88k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1928|       |
 1929|  1.88k|    MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&U1, 1));
  ------------------
  |  |   41|  1.88k|    do                           \
  |  |   42|  1.88k|    {                            \
  |  |   43|  1.88k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.88k]
  |  |  ------------------
  |  |   44|  1.88k|        goto cleanup;        \
  |  |   45|  1.88k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1930|  1.88k|    MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&U2, 0));
  ------------------
  |  |   41|  1.88k|    do                           \
  |  |   42|  1.88k|    {                            \
  |  |   43|  1.88k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.88k]
  |  |  ------------------
  |  |   44|  1.88k|        goto cleanup;        \
  |  |   45|  1.88k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1931|  1.88k|    MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&V1, 0));
  ------------------
  |  |   41|  1.88k|    do                           \
  |  |   42|  1.88k|    {                            \
  |  |   43|  1.88k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.88k]
  |  |  ------------------
  |  |   44|  1.88k|        goto cleanup;        \
  |  |   45|  1.88k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1932|  1.88k|    MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&V2, 1));
  ------------------
  |  |   41|  1.88k|    do                           \
  |  |   42|  1.88k|    {                            \
  |  |   43|  1.88k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.88k]
  |  |  ------------------
  |  |   44|  1.88k|        goto cleanup;        \
  |  |   45|  1.88k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1933|       |
 1934|   340k|    do {
 1935|   683k|        while ((TU.p[0] & 1) == 0) {
  ------------------
  |  Branch (1935:16): [True: 342k, False: 340k]
  ------------------
 1936|   342k|            MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TU, 1));
  ------------------
  |  |   41|   342k|    do                           \
  |  |   42|   342k|    {                            \
  |  |   43|   342k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 342k]
  |  |  ------------------
  |  |   44|   342k|        goto cleanup;        \
  |  |   45|   342k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1937|       |
 1938|   342k|            if ((U1.p[0] & 1) != 0 || (U2.p[0] & 1) != 0) {
  ------------------
  |  Branch (1938:17): [True: 141k, False: 200k]
  |  Branch (1938:39): [True: 0, False: 200k]
  ------------------
 1939|   141k|                MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&U1, &U1, &TB));
  ------------------
  |  |   41|   141k|    do                           \
  |  |   42|   141k|    {                            \
  |  |   43|   141k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 141k]
  |  |  ------------------
  |  |   44|   141k|        goto cleanup;        \
  |  |   45|   141k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1940|   141k|                MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&U2, &U2, &TA));
  ------------------
  |  |   41|   141k|    do                           \
  |  |   42|   141k|    {                            \
  |  |   43|   141k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 141k]
  |  |  ------------------
  |  |   44|   141k|        goto cleanup;        \
  |  |   45|   141k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1941|   141k|            }
 1942|       |
 1943|   342k|            MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&U1, 1));
  ------------------
  |  |   41|   342k|    do                           \
  |  |   42|   342k|    {                            \
  |  |   43|   342k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 342k]
  |  |  ------------------
  |  |   44|   342k|        goto cleanup;        \
  |  |   45|   342k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1944|   342k|            MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&U2, 1));
  ------------------
  |  |   41|   342k|    do                           \
  |  |   42|   342k|    {                            \
  |  |   43|   342k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 342k]
  |  |  ------------------
  |  |   44|   342k|        goto cleanup;        \
  |  |   45|   342k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1945|   342k|        }
 1946|       |
 1947|   675k|        while ((TV.p[0] & 1) == 0) {
  ------------------
  |  Branch (1947:16): [True: 335k, False: 340k]
  ------------------
 1948|   335k|            MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TV, 1));
  ------------------
  |  |   41|   335k|    do                           \
  |  |   42|   335k|    {                            \
  |  |   43|   335k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 335k]
  |  |  ------------------
  |  |   44|   335k|        goto cleanup;        \
  |  |   45|   335k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1949|       |
 1950|   335k|            if ((V1.p[0] & 1) != 0 || (V2.p[0] & 1) != 0) {
  ------------------
  |  Branch (1950:17): [True: 149k, False: 185k]
  |  Branch (1950:39): [True: 0, False: 185k]
  ------------------
 1951|   149k|                MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&V1, &V1, &TB));
  ------------------
  |  |   41|   149k|    do                           \
  |  |   42|   149k|    {                            \
  |  |   43|   149k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 149k]
  |  |  ------------------
  |  |   44|   149k|        goto cleanup;        \
  |  |   45|   149k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1952|   149k|                MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&V2, &V2, &TA));
  ------------------
  |  |   41|   149k|    do                           \
  |  |   42|   149k|    {                            \
  |  |   43|   149k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 149k]
  |  |  ------------------
  |  |   44|   149k|        goto cleanup;        \
  |  |   45|   149k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1953|   149k|            }
 1954|       |
 1955|   335k|            MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&V1, 1));
  ------------------
  |  |   41|   335k|    do                           \
  |  |   42|   335k|    {                            \
  |  |   43|   335k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 335k]
  |  |  ------------------
  |  |   44|   335k|        goto cleanup;        \
  |  |   45|   335k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1956|   335k|            MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&V2, 1));
  ------------------
  |  |   41|   335k|    do                           \
  |  |   42|   335k|    {                            \
  |  |   43|   335k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 335k]
  |  |  ------------------
  |  |   44|   335k|        goto cleanup;        \
  |  |   45|   335k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1957|   335k|        }
 1958|       |
 1959|   340k|        if (mbedtls_mpi_cmp_mpi(&TU, &TV) >= 0) {
  ------------------
  |  Branch (1959:13): [True: 174k, False: 165k]
  ------------------
 1960|   174k|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&TU, &TU, &TV));
  ------------------
  |  |   41|   174k|    do                           \
  |  |   42|   174k|    {                            \
  |  |   43|   174k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 174k]
  |  |  ------------------
  |  |   44|   174k|        goto cleanup;        \
  |  |   45|   174k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1961|   174k|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&U1, &U1, &V1));
  ------------------
  |  |   41|   174k|    do                           \
  |  |   42|   174k|    {                            \
  |  |   43|   174k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 174k]
  |  |  ------------------
  |  |   44|   174k|        goto cleanup;        \
  |  |   45|   174k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1962|   174k|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&U2, &U2, &V2));
  ------------------
  |  |   41|   174k|    do                           \
  |  |   42|   174k|    {                            \
  |  |   43|   174k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 174k]
  |  |  ------------------
  |  |   44|   174k|        goto cleanup;        \
  |  |   45|   174k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1963|   174k|        } else {
 1964|   165k|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&TV, &TV, &TU));
  ------------------
  |  |   41|   165k|    do                           \
  |  |   42|   165k|    {                            \
  |  |   43|   165k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 165k]
  |  |  ------------------
  |  |   44|   165k|        goto cleanup;        \
  |  |   45|   165k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1965|   165k|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&V1, &V1, &U1));
  ------------------
  |  |   41|   165k|    do                           \
  |  |   42|   165k|    {                            \
  |  |   43|   165k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 165k]
  |  |  ------------------
  |  |   44|   165k|        goto cleanup;        \
  |  |   45|   165k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1966|   165k|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&V2, &V2, &U2));
  ------------------
  |  |   41|   165k|    do                           \
  |  |   42|   165k|    {                            \
  |  |   43|   165k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 165k]
  |  |  ------------------
  |  |   44|   165k|        goto cleanup;        \
  |  |   45|   165k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1967|   165k|        }
 1968|   340k|    } while (mbedtls_mpi_cmp_int(&TU, 0) != 0);
  ------------------
  |  Branch (1968:14): [True: 338k, False: 1.88k]
  ------------------
 1969|       |
 1970|  2.04k|    while (mbedtls_mpi_cmp_int(&V1, 0) < 0) {
  ------------------
  |  Branch (1970:12): [True: 157, False: 1.88k]
  ------------------
 1971|    157|        MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&V1, &V1, N));
  ------------------
  |  |   41|    157|    do                           \
  |  |   42|    157|    {                            \
  |  |   43|    157|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 157]
  |  |  ------------------
  |  |   44|    157|        goto cleanup;        \
  |  |   45|    157|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1972|    157|    }
 1973|       |
 1974|  1.88k|    while (mbedtls_mpi_cmp_mpi(&V1, N) >= 0) {
  ------------------
  |  Branch (1974:12): [True: 0, False: 1.88k]
  ------------------
 1975|      0|        MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&V1, &V1, N));
  ------------------
  |  |   41|      0|    do                           \
  |  |   42|      0|    {                            \
  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  ------------------
  |  |   44|      0|        goto cleanup;        \
  |  |   45|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1976|      0|    }
 1977|       |
 1978|  1.88k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(X, &V1));
  ------------------
  |  |   41|  1.88k|    do                           \
  |  |   42|  1.88k|    {                            \
  |  |   43|  1.88k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.88k]
  |  |  ------------------
  |  |   44|  1.88k|        goto cleanup;        \
  |  |   45|  1.88k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1979|       |
 1980|  1.88k|cleanup:
 1981|       |
 1982|  1.88k|    mbedtls_mpi_free(&TA); mbedtls_mpi_free(&TU); mbedtls_mpi_free(&U1); mbedtls_mpi_free(&U2);
 1983|  1.88k|    mbedtls_mpi_free(&G); mbedtls_mpi_free(&TB); mbedtls_mpi_free(&TV);
 1984|  1.88k|    mbedtls_mpi_free(&V1); mbedtls_mpi_free(&V2);
 1985|       |
 1986|  1.88k|    return ret;
 1987|  1.88k|}
bignum.c:mbedtls_ct_mpi_sign_if:
   50|   897k|{
   51|   897k|    return (signed short) mbedtls_ct_uint_if(cond, sign1 + 1, sign2 + 1) - 1;
   52|   897k|}
bignum.c:mpi_sint_abs:
  359|  3.55M|{
  360|  3.55M|    if (z >= 0) {
  ------------------
  |  Branch (360:9): [True: 3.55M, False: 628]
  ------------------
  361|  3.55M|        return z;
  362|  3.55M|    }
  363|       |    /* Take care to handle the most negative value (-2^(biL-1)) correctly.
  364|       |     * A naive -z would have undefined behavior.
  365|       |     * Write this in a way that makes popular compilers happy (GCC, Clang,
  366|       |     * MSVC). */
  367|    628|    return (mbedtls_mpi_uint) 0 - (mbedtls_mpi_uint) z;
  368|  3.55M|}
bignum.c:mbedtls_mpi_resize_clear:
  285|  5.96k|{
  286|  5.96k|    if (limbs == 0) {
  ------------------
  |  Branch (286:9): [True: 0, False: 5.96k]
  ------------------
  287|      0|        mbedtls_mpi_free(X);
  288|      0|        return 0;
  289|  5.96k|    } else if (X->n == limbs) {
  ------------------
  |  Branch (289:16): [True: 0, False: 5.96k]
  ------------------
  290|      0|        memset(X->p, 0, limbs * ciL);
  ------------------
  |  |   79|      0|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  291|      0|        X->s = 1;
  292|      0|        return 0;
  293|  5.96k|    } else {
  294|  5.96k|        mbedtls_mpi_free(X);
  295|  5.96k|        return mbedtls_mpi_grow(X, limbs);
  296|  5.96k|    }
  297|  5.96k|}
bignum.c:add_sub_mpi:
 1115|  3.82M|{
 1116|  3.82M|    int ret, s;
 1117|       |
 1118|  3.82M|    s = A->s;
 1119|  3.82M|    if (A->s * B->s * flip_B < 0) {
  ------------------
  |  Branch (1119:9): [True: 3.05M, False: 765k]
  ------------------
 1120|  3.05M|        int cmp = mbedtls_mpi_cmp_abs(A, B);
 1121|  3.05M|        if (cmp >= 0) {
  ------------------
  |  Branch (1121:13): [True: 1.23M, False: 1.82M]
  ------------------
 1122|  1.23M|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs(X, A, B));
  ------------------
  |  |   41|  1.23M|    do                           \
  |  |   42|  1.23M|    {                            \
  |  |   43|  1.23M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.23M]
  |  |  ------------------
  |  |   44|  1.23M|        goto cleanup;        \
  |  |   45|  1.23M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1123|       |            /* If |A| = |B|, the result is 0 and we must set the sign bit
 1124|       |             * to +1 regardless of which of A or B was negative. Otherwise,
 1125|       |             * since |A| > |B|, the sign is the sign of A. */
 1126|  1.23M|            X->s = cmp == 0 ? 1 : s;
  ------------------
  |  Branch (1126:20): [True: 4.39k, False: 1.22M]
  ------------------
 1127|  1.82M|        } else {
 1128|  1.82M|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs(X, B, A));
  ------------------
  |  |   41|  1.82M|    do                           \
  |  |   42|  1.82M|    {                            \
  |  |   43|  1.82M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.82M]
  |  |  ------------------
  |  |   44|  1.82M|        goto cleanup;        \
  |  |   45|  1.82M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1129|       |            /* Since |A| < |B|, the sign is the opposite of A. */
 1130|  1.82M|            X->s = -s;
 1131|  1.82M|        }
 1132|  3.05M|    } else {
 1133|   765k|        MBEDTLS_MPI_CHK(mbedtls_mpi_add_abs(X, A, B));
  ------------------
  |  |   41|   765k|    do                           \
  |  |   42|   765k|    {                            \
  |  |   43|   765k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 765k]
  |  |  ------------------
  |  |   44|   765k|        goto cleanup;        \
  |  |   45|   765k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1134|   765k|        X->s = s;
 1135|   765k|    }
 1136|       |
 1137|  3.82M|cleanup:
 1138|       |
 1139|  3.82M|    return ret;
 1140|  3.82M|}
bignum.c:mbedtls_int_div_int:
 1294|  2.51k|{
 1295|  2.51k|#if defined(MBEDTLS_HAVE_UDBL)
 1296|  2.51k|    mbedtls_t_udbl dividend, quotient;
 1297|       |#else
 1298|       |    const mbedtls_mpi_uint radix = (mbedtls_mpi_uint) 1 << biH;
 1299|       |    const mbedtls_mpi_uint uint_halfword_mask = ((mbedtls_mpi_uint) 1 << biH) - 1;
 1300|       |    mbedtls_mpi_uint d0, d1, q0, q1, rAX, r0, quotient;
 1301|       |    mbedtls_mpi_uint u0_msw, u0_lsw;
 1302|       |    size_t s;
 1303|       |#endif
 1304|       |
 1305|       |    /*
 1306|       |     * Check for overflow
 1307|       |     */
 1308|  2.51k|    if (0 == d || u1 >= d) {
  ------------------
  |  Branch (1308:9): [True: 0, False: 2.51k]
  |  Branch (1308:19): [True: 0, False: 2.51k]
  ------------------
 1309|      0|        if (r != NULL) {
  ------------------
  |  Branch (1309:13): [True: 0, False: 0]
  ------------------
 1310|      0|            *r = ~(mbedtls_mpi_uint) 0u;
 1311|      0|        }
 1312|       |
 1313|      0|        return ~(mbedtls_mpi_uint) 0u;
 1314|      0|    }
 1315|       |
 1316|  2.51k|#if defined(MBEDTLS_HAVE_UDBL)
 1317|  2.51k|    dividend  = (mbedtls_t_udbl) u1 << biL;
  ------------------
  |  |   80|  2.51k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  2.51k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
 1318|  2.51k|    dividend |= (mbedtls_t_udbl) u0;
 1319|  2.51k|    quotient = dividend / d;
 1320|  2.51k|    if (quotient > ((mbedtls_t_udbl) 1 << biL) - 1) {
  ------------------
  |  |   80|  2.51k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  2.51k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  |  Branch (1320:9): [True: 0, False: 2.51k]
  ------------------
 1321|      0|        quotient = ((mbedtls_t_udbl) 1 << biL) - 1;
  ------------------
  |  |   80|      0|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|      0|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
 1322|      0|    }
 1323|       |
 1324|  2.51k|    if (r != NULL) {
  ------------------
  |  Branch (1324:9): [True: 0, False: 2.51k]
  ------------------
 1325|      0|        *r = (mbedtls_mpi_uint) (dividend - (quotient * d));
 1326|      0|    }
 1327|       |
 1328|  2.51k|    return (mbedtls_mpi_uint) quotient;
 1329|       |#else
 1330|       |
 1331|       |    /*
 1332|       |     * Algorithm D, Section 4.3.1 - The Art of Computer Programming
 1333|       |     *   Vol. 2 - Seminumerical Algorithms, Knuth
 1334|       |     */
 1335|       |
 1336|       |    /*
 1337|       |     * Normalize the divisor, d, and dividend, u0, u1
 1338|       |     */
 1339|       |    s = mbedtls_mpi_core_clz(d);
 1340|       |    d = d << s;
 1341|       |
 1342|       |    u1 = u1 << s;
 1343|       |    u1 |= (u0 >> (biL - s)) & (-(mbedtls_mpi_sint) s >> (biL - 1));
 1344|       |    u0 =  u0 << s;
 1345|       |
 1346|       |    d1 = d >> biH;
 1347|       |    d0 = d & uint_halfword_mask;
 1348|       |
 1349|       |    u0_msw = u0 >> biH;
 1350|       |    u0_lsw = u0 & uint_halfword_mask;
 1351|       |
 1352|       |    /*
 1353|       |     * Find the first quotient and remainder
 1354|       |     */
 1355|       |    q1 = u1 / d1;
 1356|       |    r0 = u1 - d1 * q1;
 1357|       |
 1358|       |    while (q1 >= radix || (q1 * d0 > radix * r0 + u0_msw)) {
 1359|       |        q1 -= 1;
 1360|       |        r0 += d1;
 1361|       |
 1362|       |        if (r0 >= radix) {
 1363|       |            break;
 1364|       |        }
 1365|       |    }
 1366|       |
 1367|       |    rAX = (u1 * radix) + (u0_msw - q1 * d);
 1368|       |    q0 = rAX / d1;
 1369|       |    r0 = rAX - q0 * d1;
 1370|       |
 1371|       |    while (q0 >= radix || (q0 * d0 > radix * r0 + u0_lsw)) {
 1372|       |        q0 -= 1;
 1373|       |        r0 += d1;
 1374|       |
 1375|       |        if (r0 >= radix) {
 1376|       |            break;
 1377|       |        }
 1378|       |    }
 1379|       |
 1380|       |    if (r != NULL) {
 1381|       |        *r = (rAX * radix + u0_lsw - q0 * d) >> s;
 1382|       |    }
 1383|       |
 1384|       |    quotient = q1 * radix + q0;
 1385|       |
 1386|       |    return quotient;
 1387|       |#endif
 1388|  2.51k|}

mbedtls_mpi_core_clz:
   25|  1.67M|{
   26|  1.67M|#if defined(__has_builtin)
   27|       |#if (MBEDTLS_MPI_UINT_MAX == UINT_MAX) && __has_builtin(__builtin_clz)
   28|       |    #define core_clz __builtin_clz
   29|       |#elif (MBEDTLS_MPI_UINT_MAX == ULONG_MAX) && __has_builtin(__builtin_clzl)
   30|       |    #define core_clz __builtin_clzl
   31|       |#elif (MBEDTLS_MPI_UINT_MAX == ULLONG_MAX) && __has_builtin(__builtin_clzll)
   32|       |    #define core_clz __builtin_clzll
   33|       |#endif
   34|  1.67M|#endif
   35|  1.67M|#if defined(core_clz)
   36|  1.67M|    return (size_t) core_clz(a);
  ------------------
  |  |   30|  1.67M|    #define core_clz __builtin_clzl
  ------------------
   37|       |#else
   38|       |    size_t j;
   39|       |    mbedtls_mpi_uint mask = (mbedtls_mpi_uint) 1 << (biL - 1);
   40|       |
   41|       |    for (j = 0; j < biL; j++) {
   42|       |        if (a & mask) {
   43|       |            break;
   44|       |        }
   45|       |
   46|       |        mask >>= 1;
   47|       |    }
   48|       |
   49|       |    return j;
   50|       |#endif
   51|  1.67M|}
mbedtls_mpi_core_bitlen:
   54|  1.67M|{
   55|  1.67M|    int i;
   56|  1.67M|    size_t j;
   57|       |
   58|  5.06M|    for (i = ((int) A_limbs) - 1; i >= 0; i--) {
  ------------------
  |  Branch (58:35): [True: 5.06M, False: 0]
  ------------------
   59|  5.06M|        if (A[i] != 0) {
  ------------------
  |  Branch (59:13): [True: 1.67M, False: 3.38M]
  ------------------
   60|  1.67M|            j = biL - mbedtls_mpi_core_clz(A[i]);
  ------------------
  |  |   80|  1.67M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  1.67M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
   61|  1.67M|            return (i * biL) + j;
  ------------------
  |  |   80|  1.67M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  1.67M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
   62|  1.67M|        }
   63|  5.06M|    }
   64|       |
   65|      0|    return 0;
   66|  1.67M|}
mbedtls_mpi_core_bigendian_to_host:
   84|  5.96k|{
   85|  5.96k|    mbedtls_mpi_uint *cur_limb_left;
   86|  5.96k|    mbedtls_mpi_uint *cur_limb_right;
   87|  5.96k|    if (A_limbs == 0) {
  ------------------
  |  Branch (87:9): [True: 0, False: 5.96k]
  ------------------
   88|      0|        return;
   89|      0|    }
   90|       |
   91|       |    /*
   92|       |     * Traverse limbs and
   93|       |     * - adapt byte-order in each limb
   94|       |     * - swap the limbs themselves.
   95|       |     * For that, simultaneously traverse the limbs from left to right
   96|       |     * and from right to left, as long as the left index is not bigger
   97|       |     * than the right index (it's not a problem if limbs is odd and the
   98|       |     * indices coincide in the last iteration).
   99|       |     */
  100|  5.96k|    for (cur_limb_left = A, cur_limb_right = A + (A_limbs - 1);
  101|  18.2k|         cur_limb_left <= cur_limb_right;
  ------------------
  |  Branch (101:10): [True: 12.2k, False: 5.96k]
  ------------------
  102|  12.2k|         cur_limb_left++, cur_limb_right--) {
  103|  12.2k|        mbedtls_mpi_uint tmp;
  104|       |        /* Note that if cur_limb_left == cur_limb_right,
  105|       |         * this code effectively swaps the bytes only once. */
  106|  12.2k|        tmp             = mpi_bigendian_to_host(*cur_limb_left);
  107|  12.2k|        *cur_limb_left  = mpi_bigendian_to_host(*cur_limb_right);
  108|  12.2k|        *cur_limb_right = tmp;
  109|  12.2k|    }
  110|  5.96k|}
mbedtls_mpi_core_cond_assign:
  172|   897k|{
  173|   897k|    if (X == A) {
  ------------------
  |  Branch (173:9): [True: 0, False: 897k]
  ------------------
  174|      0|        return;
  175|      0|    }
  176|       |
  177|       |    /* This function is very performance-sensitive for RSA. For this reason
  178|       |     * we have the loop below, instead of calling mbedtls_ct_memcpy_if
  179|       |     * (this is more optimal since here we don't have to handle the case where
  180|       |     * we copy awkwardly sized data).
  181|       |     */
  182|  4.48M|    for (size_t i = 0; i < limbs; i++) {
  ------------------
  |  Branch (182:24): [True: 3.58M, False: 897k]
  ------------------
  183|  3.58M|        X[i] = mbedtls_ct_mpi_uint_if(assign, A[i], X[i]);
  184|  3.58M|    }
  185|   897k|}
mbedtls_mpi_core_read_be:
  230|  5.96k|{
  231|  5.96k|    const size_t limbs = CHARS_TO_LIMBS(input_length);
  ------------------
  |  |   88|  5.96k|#define CHARS_TO_LIMBS(i) ((i) / ciL + ((i) % ciL != 0))
  |  |  ------------------
  |  |  |  |   79|  5.96k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  |  |               #define CHARS_TO_LIMBS(i) ((i) / ciL + ((i) % ciL != 0))
  |  |  ------------------
  |  |  |  |   79|  5.96k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  232|       |
  233|  5.96k|    if (X_limbs < limbs) {
  ------------------
  |  Branch (233:9): [True: 0, False: 5.96k]
  ------------------
  234|      0|        return MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL;
  ------------------
  |  |   30|      0|#define MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL                  -0x0008
  ------------------
  235|      0|    }
  236|       |
  237|       |    /* If X_limbs is 0, input_length must also be 0 (from previous test).
  238|       |     * Nothing to do. */
  239|  5.96k|    if (X_limbs == 0) {
  ------------------
  |  Branch (239:9): [True: 0, False: 5.96k]
  ------------------
  240|      0|        return 0;
  241|      0|    }
  242|       |
  243|  5.96k|    memset(X, 0, X_limbs * ciL);
  ------------------
  |  |   79|  5.96k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  244|       |
  245|       |    /* memcpy() with (NULL, 0) is undefined behaviour */
  246|  5.96k|    if (input_length != 0) {
  ------------------
  |  Branch (246:9): [True: 5.96k, False: 0]
  ------------------
  247|  5.96k|        size_t overhead = (X_limbs * ciL) - input_length;
  ------------------
  |  |   79|  5.96k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  248|  5.96k|        unsigned char *Xp = (unsigned char *) X;
  249|  5.96k|        memcpy(Xp + overhead, input, input_length);
  250|  5.96k|    }
  251|       |
  252|  5.96k|    mbedtls_mpi_core_bigendian_to_host(X, X_limbs);
  253|       |
  254|  5.96k|    return 0;
  255|  5.96k|}
mbedtls_mpi_core_shift_r:
  332|  3.05M|{
  333|  3.05M|    size_t i, v0, v1;
  334|  3.05M|    mbedtls_mpi_uint r0 = 0, r1;
  335|       |
  336|  3.05M|    v0 = count /  biL;
  ------------------
  |  |   80|  3.05M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  3.05M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  337|  3.05M|    v1 = count & (biL - 1);
  ------------------
  |  |   80|  3.05M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  3.05M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  338|       |
  339|  3.05M|    if (v0 > limbs || (v0 == limbs && v1 > 0)) {
  ------------------
  |  Branch (339:9): [True: 0, False: 3.05M]
  |  Branch (339:24): [True: 0, False: 3.05M]
  |  Branch (339:39): [True: 0, False: 0]
  ------------------
  340|      0|        memset(X, 0, limbs * ciL);
  ------------------
  |  |   79|      0|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  341|      0|        return;
  342|      0|    }
  343|       |
  344|       |    /*
  345|       |     * shift by count / limb_size
  346|       |     */
  347|  3.05M|    if (v0 > 0) {
  ------------------
  |  Branch (347:9): [True: 628, False: 3.05M]
  ------------------
  348|  3.76k|        for (i = 0; i < limbs - v0; i++) {
  ------------------
  |  Branch (348:21): [True: 3.14k, False: 628]
  ------------------
  349|  3.14k|            X[i] = X[i + v0];
  350|  3.14k|        }
  351|       |
  352|  3.14k|        for (; i < limbs; i++) {
  ------------------
  |  Branch (352:16): [True: 2.51k, False: 628]
  ------------------
  353|  2.51k|            X[i] = 0;
  354|  2.51k|        }
  355|    628|    }
  356|       |
  357|       |    /*
  358|       |     * shift by count % limb_size
  359|       |     */
  360|  3.05M|    if (v1 > 0) {
  ------------------
  |  Branch (360:9): [True: 2.54M, False: 511k]
  ------------------
  361|  13.6M|        for (i = limbs; i > 0; i--) {
  ------------------
  |  Branch (361:25): [True: 11.1M, False: 2.54M]
  ------------------
  362|  11.1M|            r1 = X[i - 1] << (biL - v1);
  ------------------
  |  |   80|  11.1M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  11.1M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  363|  11.1M|            X[i - 1] >>= v1;
  364|  11.1M|            X[i - 1] |= r0;
  365|  11.1M|            r0 = r1;
  366|  11.1M|        }
  367|  2.54M|    }
  368|  3.05M|}
mbedtls_mpi_core_shift_l:
  372|   432k|{
  373|   432k|    size_t i, v0, v1;
  374|   432k|    mbedtls_mpi_uint r0 = 0, r1;
  375|       |
  376|   432k|    v0 = count / (biL);
  ------------------
  |  |   80|   432k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|   432k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  377|   432k|    v1 = count & (biL - 1);
  ------------------
  |  |   80|   432k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|   432k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  378|       |
  379|       |    /*
  380|       |     * shift by count / limb_size
  381|       |     */
  382|   432k|    if (v0 > 0) {
  ------------------
  |  Branch (382:9): [True: 2.51k, False: 429k]
  ------------------
  383|  20.7k|        for (i = limbs; i > v0; i--) {
  ------------------
  |  Branch (383:25): [True: 18.2k, False: 2.51k]
  ------------------
  384|  18.2k|            X[i - 1] = X[i - v0 - 1];
  385|  18.2k|        }
  386|       |
  387|  8.79k|        for (; i > 0; i--) {
  ------------------
  |  Branch (387:16): [True: 6.28k, False: 2.51k]
  ------------------
  388|  6.28k|            X[i - 1] = 0;
  389|  6.28k|        }
  390|  2.51k|    }
  391|       |
  392|       |    /*
  393|       |     * shift by count % limb_size
  394|       |     */
  395|   432k|    if (v1 > 0) {
  ------------------
  |  Branch (395:9): [True: 427k, False: 5.02k]
  ------------------
  396|  4.26M|        for (i = v0; i < limbs; i++) {
  ------------------
  |  Branch (396:22): [True: 3.84M, False: 427k]
  ------------------
  397|  3.84M|            r1 = X[i] >> (biL - v1);
  ------------------
  |  |   80|  3.84M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  3.84M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  398|  3.84M|            X[i] <<= v1;
  399|  3.84M|            X[i] |= r0;
  400|  3.84M|            r0 = r1;
  401|  3.84M|        }
  402|   427k|    }
  403|   432k|}
mbedtls_mpi_core_add:
  409|   765k|{
  410|   765k|    mbedtls_mpi_uint c = 0;
  411|       |
  412|  3.82M|    for (size_t i = 0; i < limbs; i++) {
  ------------------
  |  Branch (412:24): [True: 3.06M, False: 765k]
  ------------------
  413|  3.06M|        mbedtls_mpi_uint t = c + A[i];
  414|  3.06M|        c = (t < A[i]);
  415|  3.06M|        t += B[i];
  416|  3.06M|        c += (t < B[i]);
  417|  3.06M|        X[i] = t;
  418|  3.06M|    }
  419|       |
  420|   765k|    return c;
  421|   765k|}
mbedtls_mpi_core_sub:
  448|  3.97M|{
  449|  3.97M|    mbedtls_mpi_uint c = 0;
  450|       |
  451|  18.7M|    for (size_t i = 0; i < limbs; i++) {
  ------------------
  |  Branch (451:24): [True: 14.8M, False: 3.97M]
  ------------------
  452|  14.8M|        mbedtls_mpi_uint z = (A[i] < c);
  453|  14.8M|        mbedtls_mpi_uint t = A[i] - c;
  454|  14.8M|        c = (t < B[i]) + z;
  455|  14.8M|        X[i] = t - B[i];
  456|  14.8M|    }
  457|       |
  458|  3.97M|    return c;
  459|  3.97M|}
mbedtls_mpi_core_mla:
  464|  5.03M|{
  465|  5.03M|    mbedtls_mpi_uint c = 0; /* carry */
  466|       |    /*
  467|       |     * It is a documented precondition of this function that d_len >= s_len.
  468|       |     * If that's not the case, we swap these round: this turns what would be
  469|       |     * a buffer overflow into an incorrect result.
  470|       |     */
  471|  5.03M|    if (d_len < s_len) {
  ------------------
  |  Branch (471:9): [True: 0, False: 5.03M]
  ------------------
  472|      0|        s_len = d_len;
  473|      0|    }
  474|  5.03M|    size_t excess_len = d_len - s_len;
  475|  5.03M|    size_t steps_x8 = s_len / 8;
  476|  5.03M|    size_t steps_x1 = s_len & 7;
  477|       |
  478|  5.03M|    while (steps_x8--) {
  ------------------
  |  Branch (478:12): [True: 0, False: 5.03M]
  ------------------
  479|      0|        MULADDC_X8_INIT
  ------------------
  |  | 1088|      0|#define MULADDC_X8_INIT MULADDC_X4_INIT
  |  |  ------------------
  |  |  |  | 1082|      0|#define MULADDC_X4_INIT MULADDC_X2_INIT
  |  |  |  |  ------------------
  |  |  |  |  |  | 1076|      0|#define MULADDC_X2_INIT MULADDC_X1_INIT
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  216|      0|    asm(                                    \
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  321|      0|#define asm __asm__
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  217|      0|        "xorq   %%r8, %%r8\n"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  480|      0|        MULADDC_X8_CORE
  481|      0|            MULADDC_X8_STOP
  ------------------
  |  | 1089|      0|#define MULADDC_X8_STOP MULADDC_X4_STOP
  |  |  ------------------
  |  |  |  | 1083|      0|#define MULADDC_X4_STOP MULADDC_X2_STOP
  |  |  |  |  ------------------
  |  |  |  |  |  | 1077|      0|#define MULADDC_X2_STOP MULADDC_X1_STOP
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  232|      0|        : "+c" (c), "+D" (d), "+S" (s), "+m" (*(uint64_t (*)[16]) d) \
  |  |  |  |  |  |  |  |  233|      0|        : "b" (b), "m" (*(const uint64_t (*)[16]) s)                 \
  |  |  |  |  |  |  |  |  234|      0|        : "rax", "rdx", "r8"                                         \
  |  |  |  |  |  |  |  |  235|      0|    );
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  482|      0|    }
  483|       |
  484|  25.1M|    while (steps_x1--) {
  ------------------
  |  Branch (484:12): [True: 20.0M, False: 5.03M]
  ------------------
  485|  20.0M|        MULADDC_X1_INIT
  ------------------
  |  |  216|  20.0M|    asm(                                    \
  |  |  ------------------
  |  |  |  |  321|  20.0M|#define asm __asm__
  |  |  ------------------
  |  |  217|  20.0M|        "xorq   %%r8, %%r8\n"
  ------------------
  486|  20.0M|        MULADDC_X1_CORE
  487|  20.0M|            MULADDC_X1_STOP
  ------------------
  |  |  232|  20.0M|        : "+c" (c), "+D" (d), "+S" (s), "+m" (*(uint64_t (*)[16]) d) \
  |  |  233|  20.0M|        : "b" (b), "m" (*(const uint64_t (*)[16]) s)                 \
  |  |  234|  20.0M|        : "rax", "rdx", "r8"                                         \
  |  |  235|  20.0M|    );
  ------------------
  488|  20.0M|    }
  489|       |
  490|  10.2M|    while (excess_len--) {
  ------------------
  |  Branch (490:12): [True: 5.21M, False: 5.03M]
  ------------------
  491|  5.21M|        *d += c;
  492|  5.21M|        c = (*d < c);
  493|  5.21M|        d++;
  494|  5.21M|    }
  495|       |
  496|  5.03M|    return c;
  497|  5.03M|}
mbedtls_mpi_core_mul:
  502|  1.23M|{
  503|  1.23M|    memset(X, 0, (A_limbs + B_limbs) * ciL);
  ------------------
  |  |   79|  1.23M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  504|       |
  505|  6.16M|    for (size_t i = 0; i < B_limbs; i++) {
  ------------------
  |  Branch (505:24): [True: 4.93M, False: 1.23M]
  ------------------
  506|  4.93M|        (void) mbedtls_mpi_core_mla(X + i, A_limbs + 1, A, A_limbs, B[i]);
  507|  4.93M|    }
  508|  1.23M|}
mbedtls_mpi_core_sub_int:
  973|   882k|{
  974|  4.97M|    for (size_t i = 0; i < limbs; i++) {
  ------------------
  |  Branch (974:24): [True: 4.09M, False: 882k]
  ------------------
  975|  4.09M|        mbedtls_mpi_uint s = A[i];
  976|  4.09M|        mbedtls_mpi_uint t = s - c;
  977|  4.09M|        c = (t > s);
  978|  4.09M|        X[i] = t;
  979|  4.09M|    }
  980|       |
  981|   882k|    return c;
  982|   882k|}
bignum_core.c:mpi_bigendian_to_host:
   69|  24.4k|{
   70|  24.4k|    if (MBEDTLS_IS_BIG_ENDIAN) {
  ------------------
  |  |  398|  24.4k|#define MBEDTLS_IS_BIG_ENDIAN 0
  |  |  ------------------
  |  |  |  Branch (398:31): [Folded - Ignored]
  |  |  ------------------
  ------------------
   71|       |        /* Nothing to do on bigendian systems. */
   72|      0|        return a;
   73|  24.4k|    } else {
   74|       |#if defined(MBEDTLS_HAVE_INT32)
   75|       |        return (mbedtls_mpi_uint) MBEDTLS_BSWAP32(a);
   76|       |#elif defined(MBEDTLS_HAVE_INT64)
   77|  24.4k|        return (mbedtls_mpi_uint) MBEDTLS_BSWAP64(a);
  ------------------
  |  |  301|  24.4k|#define MBEDTLS_BSWAP64 __builtin_bswap64
  ------------------
   78|  24.4k|#endif
   79|  24.4k|    }
   80|  24.4k|}

bignum.c:mbedtls_ct_bool:
  136|   897k|{
  137|       |    /*
  138|       |     * Define mask-generation code that, as far as possible, will not use branches or conditional instructions.
  139|       |     *
  140|       |     * For some platforms / type sizes, we define assembly to assure this.
  141|       |     *
  142|       |     * Otherwise, we define a plain C fallback which (in May 2023) does not get optimised into
  143|       |     * conditional instructions or branches by trunk clang, gcc, or MSVC v19.
  144|       |     */
  145|       |#if defined(MBEDTLS_CT_AARCH64_ASM) && (defined(MBEDTLS_CT_SIZE_32) || defined(MBEDTLS_CT_SIZE_64))
  146|       |    mbedtls_ct_uint_t s;
  147|       |    asm volatile ("neg %x[s], %x[x]                               \n\t"
  148|       |                  "orr %x[x], %x[s], %x[x]                        \n\t"
  149|       |                  "asr %x[x], %x[x], 63                           \n\t"
  150|       |                  :
  151|       |                  [s] "=&r" (s),
  152|       |                  [x] "+&r" (x)
  153|       |                  :
  154|       |                  :
  155|       |                  );
  156|       |    return (mbedtls_ct_condition_t) x;
  157|       |#elif defined(MBEDTLS_CT_ARM_ASM) && defined(MBEDTLS_CT_SIZE_32)
  158|       |    uint32_t s;
  159|       |    asm volatile (".syntax unified                                \n\t"
  160|       |                  "negs %[s], %[x]                                \n\t"
  161|       |                  "orrs %[x], %[x], %[s]                          \n\t"
  162|       |                  "asrs %[x], %[x], #31                           \n\t"
  163|       |                  RESTORE_ASM_SYNTAX
  164|       |                  :
  165|       |                  [s] "=&l" (s),
  166|       |                  [x] "+&l" (x)
  167|       |                  :
  168|       |                  :
  169|       |                  "cc" /* clobbers flag bits */
  170|       |                  );
  171|       |    return (mbedtls_ct_condition_t) x;
  172|       |#elif defined(MBEDTLS_CT_X86_64_ASM) && (defined(MBEDTLS_CT_SIZE_32) || defined(MBEDTLS_CT_SIZE_64))
  173|       |    uint64_t s;
  174|   897k|    asm volatile ("mov  %[x], %[s]                                \n\t"
  ------------------
  |  |  321|   897k|#define asm __asm__
  ------------------
  175|   897k|                  "neg  %[s]                                      \n\t"
  176|   897k|                  "or   %[x], %[s]                                \n\t"
  177|   897k|                  "sar  $63, %[s]                                 \n\t"
  178|   897k|                  :
  179|   897k|                  [s] "=&a" (s)
  180|   897k|                  :
  181|   897k|                  [x] "D" (x)
  182|   897k|                  :
  183|   897k|                  );
  184|   897k|    return (mbedtls_ct_condition_t) s;
  185|       |#elif defined(MBEDTLS_CT_X86_ASM) && defined(MBEDTLS_CT_SIZE_32)
  186|       |    uint32_t s;
  187|       |    asm volatile ("mov %[x], %[s]                                 \n\t"
  188|       |                  "neg %[s]                                       \n\t"
  189|       |                  "or %[s], %[x]                                  \n\t"
  190|       |                  "sar $31, %[x]                                  \n\t"
  191|       |                  :
  192|       |                  [s] "=&c" (s),
  193|       |                  [x] "+&a" (x)
  194|       |                  :
  195|       |                  :
  196|       |                  );
  197|       |    return (mbedtls_ct_condition_t) x;
  198|       |#else
  199|       |    const mbedtls_ct_uint_t xo = mbedtls_ct_compiler_opaque(x);
  200|       |#if defined(_MSC_VER)
  201|       |    /* MSVC has a warning about unary minus on unsigned, but this is
  202|       |     * well-defined and precisely what we want to do here */
  203|       |#pragma warning( push )
  204|       |#pragma warning( disable : 4146 )
  205|       |#endif
  206|       |    // y is negative (i.e., top bit set) iff x is non-zero
  207|       |    mbedtls_ct_int_t y = (-xo) | -(xo >> 1);
  208|       |
  209|       |    // extract only the sign bit of y so that y == 1 (if x is non-zero) or 0 (if x is zero)
  210|       |    y = (((mbedtls_ct_uint_t) y) >> (MBEDTLS_CT_SIZE - 1));
  211|       |
  212|       |    // -y has all bits set (if x is non-zero), or all bits clear (if x is zero)
  213|       |    return (mbedtls_ct_condition_t) (-y);
  214|       |#if defined(_MSC_VER)
  215|       |#pragma warning( pop )
  216|       |#endif
  217|       |#endif
  218|   897k|}
bignum.c:mbedtls_ct_bool_not:
  547|   897k|{
  548|   897k|    return (mbedtls_ct_condition_t) (~x);
  549|   897k|}
bignum.c:mbedtls_ct_uint_if:
  436|   897k|{
  437|   897k|    return (unsigned) mbedtls_ct_if(condition, (mbedtls_ct_uint_t) if1, (mbedtls_ct_uint_t) if0);
  438|   897k|}
bignum.c:mbedtls_ct_if:
  223|   897k|{
  224|       |#if defined(MBEDTLS_CT_AARCH64_ASM) && (defined(MBEDTLS_CT_SIZE_32) || defined(MBEDTLS_CT_SIZE_64))
  225|       |    asm volatile ("and %x[if1], %x[if1], %x[condition]            \n\t"
  226|       |                  "mvn %x[condition], %x[condition]               \n\t"
  227|       |                  "and %x[condition], %x[condition], %x[if0]      \n\t"
  228|       |                  "orr %x[condition], %x[if1], %x[condition]"
  229|       |                  :
  230|       |                  [condition] "+&r" (condition),
  231|       |                  [if1] "+&r" (if1)
  232|       |                  :
  233|       |                  [if0] "r" (if0)
  234|       |                  :
  235|       |                  );
  236|       |    return (mbedtls_ct_uint_t) condition;
  237|       |#elif defined(MBEDTLS_CT_ARM_ASM) && defined(MBEDTLS_CT_SIZE_32)
  238|       |    asm volatile (".syntax unified                                \n\t"
  239|       |                  "ands %[if1], %[if1], %[condition]              \n\t"
  240|       |                  "mvns %[condition], %[condition]                \n\t"
  241|       |                  "ands %[condition], %[condition], %[if0]        \n\t"
  242|       |                  "orrs %[condition], %[if1], %[condition]        \n\t"
  243|       |                  RESTORE_ASM_SYNTAX
  244|       |                  :
  245|       |                  [condition] "+&l" (condition),
  246|       |                  [if1] "+&l" (if1)
  247|       |                  :
  248|       |                  [if0] "l" (if0)
  249|       |                  :
  250|       |                  "cc"
  251|       |                  );
  252|       |    return (mbedtls_ct_uint_t) condition;
  253|       |#elif defined(MBEDTLS_CT_X86_64_ASM) && (defined(MBEDTLS_CT_SIZE_32) || defined(MBEDTLS_CT_SIZE_64))
  254|   897k|    asm volatile ("and  %[condition], %[if1]                      \n\t"
  ------------------
  |  |  321|   897k|#define asm __asm__
  ------------------
  255|   897k|                  "not  %[condition]                              \n\t"
  256|   897k|                  "and  %[condition], %[if0]                      \n\t"
  257|   897k|                  "or   %[if1], %[if0]                            \n\t"
  258|   897k|                  :
  259|   897k|                  [condition] "+&D" (condition),
  260|   897k|                  [if1] "+&S" (if1),
  261|   897k|                  [if0] "+&a" (if0)
  262|   897k|                  :
  263|   897k|                  :
  264|   897k|                  );
  265|   897k|    return if0;
  266|       |#elif defined(MBEDTLS_CT_X86_ASM) && defined(MBEDTLS_CT_SIZE_32)
  267|       |    asm volatile ("and %[condition], %[if1]                       \n\t"
  268|       |                  "not %[condition]                               \n\t"
  269|       |                  "and %[if0], %[condition]                       \n\t"
  270|       |                  "or %[condition], %[if1]                        \n\t"
  271|       |                  :
  272|       |                  [condition] "+&c" (condition),
  273|       |                  [if1] "+&a" (if1)
  274|       |                  :
  275|       |                  [if0] "b" (if0)
  276|       |                  :
  277|       |                  );
  278|       |    return if1;
  279|       |#else
  280|       |    mbedtls_ct_condition_t not_cond =
  281|       |        (mbedtls_ct_condition_t) (~mbedtls_ct_compiler_opaque(condition));
  282|       |    return (mbedtls_ct_uint_t) ((condition & if1) | (not_cond & if0));
  283|       |#endif
  284|   897k|}
bignum.c:mbedtls_ct_mpi_uint_if_else_0:
  481|  3.14k|{
  482|  3.14k|    return (mbedtls_mpi_uint) (condition & if1);
  483|  3.14k|}
bignum_core.c:mbedtls_ct_mpi_uint_if:
  453|  3.58M|{
  454|  3.58M|    return (mbedtls_mpi_uint) mbedtls_ct_if(condition,
  455|  3.58M|                                            (mbedtls_ct_uint_t) if1,
  456|  3.58M|                                            (mbedtls_ct_uint_t) if0);
  457|  3.58M|}
bignum_core.c:mbedtls_ct_if:
  223|  3.58M|{
  224|       |#if defined(MBEDTLS_CT_AARCH64_ASM) && (defined(MBEDTLS_CT_SIZE_32) || defined(MBEDTLS_CT_SIZE_64))
  225|       |    asm volatile ("and %x[if1], %x[if1], %x[condition]            \n\t"
  226|       |                  "mvn %x[condition], %x[condition]               \n\t"
  227|       |                  "and %x[condition], %x[condition], %x[if0]      \n\t"
  228|       |                  "orr %x[condition], %x[if1], %x[condition]"
  229|       |                  :
  230|       |                  [condition] "+&r" (condition),
  231|       |                  [if1] "+&r" (if1)
  232|       |                  :
  233|       |                  [if0] "r" (if0)
  234|       |                  :
  235|       |                  );
  236|       |    return (mbedtls_ct_uint_t) condition;
  237|       |#elif defined(MBEDTLS_CT_ARM_ASM) && defined(MBEDTLS_CT_SIZE_32)
  238|       |    asm volatile (".syntax unified                                \n\t"
  239|       |                  "ands %[if1], %[if1], %[condition]              \n\t"
  240|       |                  "mvns %[condition], %[condition]                \n\t"
  241|       |                  "ands %[condition], %[condition], %[if0]        \n\t"
  242|       |                  "orrs %[condition], %[if1], %[condition]        \n\t"
  243|       |                  RESTORE_ASM_SYNTAX
  244|       |                  :
  245|       |                  [condition] "+&l" (condition),
  246|       |                  [if1] "+&l" (if1)
  247|       |                  :
  248|       |                  [if0] "l" (if0)
  249|       |                  :
  250|       |                  "cc"
  251|       |                  );
  252|       |    return (mbedtls_ct_uint_t) condition;
  253|       |#elif defined(MBEDTLS_CT_X86_64_ASM) && (defined(MBEDTLS_CT_SIZE_32) || defined(MBEDTLS_CT_SIZE_64))
  254|  3.58M|    asm volatile ("and  %[condition], %[if1]                      \n\t"
  ------------------
  |  |  321|  3.58M|#define asm __asm__
  ------------------
  255|  3.58M|                  "not  %[condition]                              \n\t"
  256|  3.58M|                  "and  %[condition], %[if0]                      \n\t"
  257|  3.58M|                  "or   %[if1], %[if0]                            \n\t"
  258|  3.58M|                  :
  259|  3.58M|                  [condition] "+&D" (condition),
  260|  3.58M|                  [if1] "+&S" (if1),
  261|  3.58M|                  [if0] "+&a" (if0)
  262|  3.58M|                  :
  263|  3.58M|                  :
  264|  3.58M|                  );
  265|  3.58M|    return if0;
  266|       |#elif defined(MBEDTLS_CT_X86_ASM) && defined(MBEDTLS_CT_SIZE_32)
  267|       |    asm volatile ("and %[condition], %[if1]                       \n\t"
  268|       |                  "not %[condition]                               \n\t"
  269|       |                  "and %[if0], %[condition]                       \n\t"
  270|       |                  "or %[condition], %[if1]                        \n\t"
  271|       |                  :
  272|       |                  [condition] "+&c" (condition),
  273|       |                  [if1] "+&a" (if1)
  274|       |                  :
  275|       |                  [if0] "b" (if0)
  276|       |                  :
  277|       |                  );
  278|       |    return if1;
  279|       |#else
  280|       |    mbedtls_ct_condition_t not_cond =
  281|       |        (mbedtls_ct_condition_t) (~mbedtls_ct_compiler_opaque(condition));
  282|       |    return (mbedtls_ct_uint_t) ((condition & if1) | (not_cond & if0));
  283|       |#endif
  284|  3.58M|}

mbedtls_ecdh_init:
  160|    157|{
  161|    157|#if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
  162|    157|    ecdh_init_internal(ctx);
  163|    157|    mbedtls_ecp_point_init(&ctx->Vi);
  164|    157|    mbedtls_ecp_point_init(&ctx->Vf);
  165|    157|    mbedtls_mpi_init(&ctx->_d);
  166|       |#else
  167|       |    memset(ctx, 0, sizeof(mbedtls_ecdh_context));
  168|       |
  169|       |    ctx->var = MBEDTLS_ECDH_VARIANT_NONE;
  170|       |#endif
  171|    157|    ctx->point_format = MBEDTLS_ECP_PF_UNCOMPRESSED;
  ------------------
  |  |  439|    157|#define MBEDTLS_ECP_PF_UNCOMPRESSED    0
  ------------------
  172|    157|#if defined(MBEDTLS_ECP_RESTARTABLE)
  173|    157|    ctx->restart_enabled = 0;
  174|    157|#endif
  175|    157|}
mbedtls_ecdh_setup:
  194|    157|{
  195|    157|#if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
  196|    157|    return ecdh_setup_internal(ctx, grp_id);
  197|       |#else
  198|       |    switch (grp_id) {
  199|       |#if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
  200|       |        case MBEDTLS_ECP_DP_CURVE25519:
  201|       |            ctx->point_format = MBEDTLS_ECP_PF_COMPRESSED;
  202|       |            ctx->var = MBEDTLS_ECDH_VARIANT_EVEREST;
  203|       |            ctx->grp_id = grp_id;
  204|       |            return mbedtls_everest_setup(&ctx->ctx.everest_ecdh, grp_id);
  205|       |#endif
  206|       |        default:
  207|       |            ctx->point_format = MBEDTLS_ECP_PF_UNCOMPRESSED;
  208|       |            ctx->var = MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0;
  209|       |            ctx->grp_id = grp_id;
  210|       |            ecdh_init_internal(&ctx->ctx.mbed_ecdh);
  211|       |            return ecdh_setup_internal(&ctx->ctx.mbed_ecdh, grp_id);
  212|       |    }
  213|       |#endif
  214|    157|}
mbedtls_ecdh_free:
  243|    157|{
  244|    157|    if (ctx == NULL) {
  ------------------
  |  Branch (244:9): [True: 0, False: 157]
  ------------------
  245|      0|        return;
  246|      0|    }
  247|       |
  248|    157|#if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
  249|    157|    mbedtls_ecp_point_free(&ctx->Vi);
  250|    157|    mbedtls_ecp_point_free(&ctx->Vf);
  251|    157|    mbedtls_mpi_free(&ctx->_d);
  252|    157|    ecdh_free_internal(ctx);
  253|       |#else
  254|       |    switch (ctx->var) {
  255|       |#if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
  256|       |        case MBEDTLS_ECDH_VARIANT_EVEREST:
  257|       |            mbedtls_everest_free(&ctx->ctx.everest_ecdh);
  258|       |            break;
  259|       |#endif
  260|       |        case MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0:
  261|       |            ecdh_free_internal(&ctx->ctx.mbed_ecdh);
  262|       |            break;
  263|       |        default:
  264|       |            break;
  265|       |    }
  266|       |
  267|       |    ctx->point_format = MBEDTLS_ECP_PF_UNCOMPRESSED;
  268|       |    ctx->var = MBEDTLS_ECDH_VARIANT_NONE;
  269|       |    ctx->grp_id = MBEDTLS_ECP_DP_NONE;
  270|       |#endif
  271|    157|}
mbedtls_ecdh_get_params:
  448|    157|{
  449|    157|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|    157|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  450|    157|    if (side != MBEDTLS_ECDH_OURS && side != MBEDTLS_ECDH_THEIRS) {
  ------------------
  |  Branch (450:9): [True: 0, False: 157]
  |  Branch (450:38): [True: 0, False: 0]
  ------------------
  451|      0|        return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
  452|      0|    }
  453|       |
  454|    157|    if (mbedtls_ecdh_grp_id(ctx) == MBEDTLS_ECP_DP_NONE) {
  ------------------
  |  Branch (454:9): [True: 157, False: 0]
  ------------------
  455|       |        /* This is the first call to get_params(). Set up the context
  456|       |         * for use with the group. */
  457|    157|        if ((ret = mbedtls_ecdh_setup(ctx, key->grp.id)) != 0) {
  ------------------
  |  Branch (457:13): [True: 0, False: 157]
  ------------------
  458|      0|            return ret;
  459|      0|        }
  460|    157|    } else {
  461|       |        /* This is not the first call to get_params(). Check that the
  462|       |         * current key's group is the same as the context's, which was set
  463|       |         * from the first key's group. */
  464|      0|        if (mbedtls_ecdh_grp_id(ctx) != key->grp.id) {
  ------------------
  |  Branch (464:13): [True: 0, False: 0]
  ------------------
  465|      0|            return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
  466|      0|        }
  467|      0|    }
  468|       |
  469|    157|#if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
  470|    157|    return ecdh_get_params_internal(ctx, key, side);
  471|       |#else
  472|       |    switch (ctx->var) {
  473|       |#if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
  474|       |        case MBEDTLS_ECDH_VARIANT_EVEREST:
  475|       |        {
  476|       |            mbedtls_everest_ecdh_side s = side == MBEDTLS_ECDH_OURS ?
  477|       |                                          MBEDTLS_EVEREST_ECDH_OURS :
  478|       |                                          MBEDTLS_EVEREST_ECDH_THEIRS;
  479|       |            return mbedtls_everest_get_params(&ctx->ctx.everest_ecdh,
  480|       |                                              key, s);
  481|       |        }
  482|       |#endif
  483|       |        case MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0:
  484|       |            return ecdh_get_params_internal(&ctx->ctx.mbed_ecdh,
  485|       |                                            key, side);
  486|       |        default:
  487|       |            return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  488|       |    }
  489|       |#endif
  490|    157|}
ecdh.c:ecdh_init_internal:
  135|    157|{
  136|    157|    mbedtls_ecp_group_init(&ctx->grp);
  137|    157|    mbedtls_mpi_init(&ctx->d);
  138|    157|    mbedtls_ecp_point_init(&ctx->Q);
  139|    157|    mbedtls_ecp_point_init(&ctx->Qp);
  140|    157|    mbedtls_mpi_init(&ctx->z);
  141|       |
  142|    157|#if defined(MBEDTLS_ECP_RESTARTABLE)
  143|    157|    mbedtls_ecp_restart_init(&ctx->rs);
  144|    157|#endif
  145|    157|}
ecdh.c:ecdh_setup_internal:
  179|    157|{
  180|    157|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|    157|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  181|       |
  182|    157|    ret = mbedtls_ecp_group_load(&ctx->grp, grp_id);
  183|    157|    if (ret != 0) {
  ------------------
  |  Branch (183:9): [True: 0, False: 157]
  ------------------
  184|      0|        return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
  ------------------
  |  |   39|      0|#define MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE               -0x4E80
  ------------------
  185|      0|    }
  186|       |
  187|    157|    return 0;
  188|    157|}
ecdh.c:ecdh_free_internal:
  217|    157|{
  218|    157|    mbedtls_ecp_group_free(&ctx->grp);
  219|    157|    mbedtls_mpi_free(&ctx->d);
  220|    157|    mbedtls_ecp_point_free(&ctx->Q);
  221|    157|    mbedtls_ecp_point_free(&ctx->Qp);
  222|    157|    mbedtls_mpi_free(&ctx->z);
  223|       |
  224|    157|#if defined(MBEDTLS_ECP_RESTARTABLE)
  225|    157|    mbedtls_ecp_restart_free(&ctx->rs);
  226|    157|#endif
  227|    157|}
ecdh.c:mbedtls_ecdh_grp_id:
   31|    157|{
   32|    157|#if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
   33|    157|    return ctx->grp.id;
   34|       |#else
   35|       |    return ctx->grp_id;
   36|       |#endif
   37|    157|}
ecdh.c:ecdh_get_params_internal:
  421|    157|{
  422|    157|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|    157|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  423|       |
  424|       |    /* If it's not our key, just import the public part as Qp */
  425|    157|    if (side == MBEDTLS_ECDH_THEIRS) {
  ------------------
  |  Branch (425:9): [True: 0, False: 157]
  ------------------
  426|      0|        return mbedtls_ecp_copy(&ctx->Qp, &key->Q);
  427|      0|    }
  428|       |
  429|       |    /* Our key: import public (as Q) and private parts */
  430|    157|    if (side != MBEDTLS_ECDH_OURS) {
  ------------------
  |  Branch (430:9): [True: 0, False: 157]
  ------------------
  431|      0|        return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
  432|      0|    }
  433|       |
  434|    157|    if ((ret = mbedtls_ecp_copy(&ctx->Q, &key->Q)) != 0 ||
  ------------------
  |  Branch (434:9): [True: 0, False: 157]
  ------------------
  435|    157|        (ret = mbedtls_mpi_copy(&ctx->d, &key->d)) != 0) {
  ------------------
  |  Branch (435:9): [True: 0, False: 157]
  ------------------
  436|      0|        return ret;
  437|      0|    }
  438|       |
  439|    157|    return 0;
  440|    157|}

mbedtls_ecdsa_can_do:
  226|    314|{
  227|    314|    switch (gid) {
  228|      0|#ifdef MBEDTLS_ECP_DP_CURVE25519_ENABLED
  229|      0|        case MBEDTLS_ECP_DP_CURVE25519: return 0;
  ------------------
  |  Branch (229:9): [True: 0, False: 314]
  ------------------
  230|      0|#endif
  231|      0|#ifdef MBEDTLS_ECP_DP_CURVE448_ENABLED
  232|      0|        case MBEDTLS_ECP_DP_CURVE448: return 0;
  ------------------
  |  Branch (232:9): [True: 0, False: 314]
  ------------------
  233|      0|#endif
  234|    314|        default: return 1;
  ------------------
  |  Branch (234:9): [True: 314, False: 0]
  ------------------
  235|    314|    }
  236|    314|}
mbedtls_ecdsa_verify_restartable:
  494|    314|{
  495|    314|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|    314|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  496|    314|    mbedtls_mpi e, s_inv, u1, u2;
  497|    314|    mbedtls_ecp_point R;
  498|    314|    mbedtls_mpi *pu1 = &u1, *pu2 = &u2;
  499|       |
  500|    314|    mbedtls_ecp_point_init(&R);
  501|    314|    mbedtls_mpi_init(&e); mbedtls_mpi_init(&s_inv);
  502|    314|    mbedtls_mpi_init(&u1); mbedtls_mpi_init(&u2);
  503|       |
  504|       |    /* Fail cleanly on curves such as Curve25519 that can't be used for ECDSA */
  505|    314|    if (!mbedtls_ecdsa_can_do(grp->id) || grp->N.p == NULL) {
  ------------------
  |  Branch (505:9): [True: 0, False: 314]
  |  Branch (505:43): [True: 0, False: 314]
  ------------------
  506|      0|        return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
  507|      0|    }
  508|       |
  509|    314|    ECDSA_RS_ENTER(ver);
  ------------------
  |  |  153|    314|#define ECDSA_RS_ENTER(SUB)   do {                                 \
  |  |  154|    314|        /* reset ops count for this call if top-level */                 \
  |  |  155|    314|        if (rs_ctx != NULL && rs_ctx->ecp.depth++ == 0)                 \
  |  |  ------------------
  |  |  |  Branch (155:13): [True: 0, False: 314]
  |  |  |  Branch (155:31): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|    314|        rs_ctx->ecp.ops_done = 0;                                    \
  |  |  157|    314|                                                                     \
  |  |  158|    314|        /* set up our own sub-context if needed */                       \
  |  |  159|    314|        if (mbedtls_ecp_restart_is_enabled() &&                          \
  |  |  ------------------
  |  |  |  Branch (159:13): [True: 0, False: 314]
  |  |  ------------------
  |  |  160|    314|            rs_ctx != NULL && rs_ctx->SUB == NULL)                      \
  |  |  ------------------
  |  |  |  Branch (160:13): [True: 0, False: 0]
  |  |  |  Branch (160:31): [True: 0, False: 0]
  |  |  ------------------
  |  |  161|    314|        {                                                                \
  |  |  162|      0|            rs_ctx->SUB = mbedtls_calloc(1, sizeof(*rs_ctx->SUB));   \
  |  |  ------------------
  |  |  |  |  144|      0|#define mbedtls_calloc     MBEDTLS_PLATFORM_CALLOC_MACRO
  |  |  |  |  ------------------
  |  |  |  |  |  | 4093|      0|#define MBEDTLS_PLATFORM_CALLOC_MACRO        my_calloc
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  163|      0|            if (rs_ctx->SUB == NULL)                                    \
  |  |  ------------------
  |  |  |  Branch (163:17): [True: 0, False: 0]
  |  |  ------------------
  |  |  164|      0|            return MBEDTLS_ERR_ECP_ALLOC_FAILED;                  \
  |  |  ------------------
  |  |  |  |   43|      0|#define MBEDTLS_ERR_ECP_ALLOC_FAILED                      -0x4D80
  |  |  ------------------
  |  |  165|      0|                                                                   \
  |  |  166|      0|            ecdsa_restart_## SUB ##_init(rs_ctx->SUB);                 \
  |  |  167|      0|        }                                                                \
  |  |  168|    314|} while (0)
  |  |  ------------------
  |  |  |  Branch (168:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
  510|       |
  511|    314|#if defined(MBEDTLS_ECP_RESTARTABLE)
  512|    314|    if (rs_ctx != NULL && rs_ctx->ver != NULL) {
  ------------------
  |  Branch (512:9): [True: 0, False: 314]
  |  Branch (512:27): [True: 0, False: 0]
  ------------------
  513|       |        /* redirect to our context */
  514|      0|        pu1 = &rs_ctx->ver->u1;
  515|      0|        pu2 = &rs_ctx->ver->u2;
  516|       |
  517|       |        /* jump to current step */
  518|      0|        if (rs_ctx->ver->state == ecdsa_ver_muladd) {
  ------------------
  |  Branch (518:13): [True: 0, False: 0]
  ------------------
  519|      0|            goto muladd;
  520|      0|        }
  521|      0|    }
  522|    314|#endif /* MBEDTLS_ECP_RESTARTABLE */
  523|       |
  524|       |    /*
  525|       |     * Step 1: make sure r and s are in range 1..n-1
  526|       |     */
  527|    314|    if (mbedtls_mpi_cmp_int(r, 1) < 0 || mbedtls_mpi_cmp_mpi(r, &grp->N) >= 0 ||
  ------------------
  |  Branch (527:9): [True: 0, False: 314]
  |  Branch (527:42): [True: 0, False: 314]
  ------------------
  528|    314|        mbedtls_mpi_cmp_int(s, 1) < 0 || mbedtls_mpi_cmp_mpi(s, &grp->N) >= 0) {
  ------------------
  |  Branch (528:9): [True: 0, False: 314]
  |  Branch (528:42): [True: 0, False: 314]
  ------------------
  529|      0|        ret = MBEDTLS_ERR_ECP_VERIFY_FAILED;
  ------------------
  |  |   41|      0|#define MBEDTLS_ERR_ECP_VERIFY_FAILED                     -0x4E00
  ------------------
  530|      0|        goto cleanup;
  531|      0|    }
  532|       |
  533|       |    /*
  534|       |     * Step 3: derive MPI from hashed message
  535|       |     */
  536|    314|    MBEDTLS_MPI_CHK(derive_mpi(grp, &e, buf, blen));
  ------------------
  |  |   41|    314|    do                           \
  |  |   42|    314|    {                            \
  |  |   43|    314|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 314]
  |  |  ------------------
  |  |   44|    314|        goto cleanup;        \
  |  |   45|    314|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  537|       |
  538|       |    /*
  539|       |     * Step 4: u1 = e / s mod n, u2 = r / s mod n
  540|       |     */
  541|    314|    ECDSA_BUDGET(MBEDTLS_ECP_OPS_CHK + MBEDTLS_ECP_OPS_INV + 2);
  ------------------
  |  |  150|    314|    MBEDTLS_MPI_CHK(mbedtls_ecp_check_budget(grp, ECDSA_RS_ECP, ops));
  |  |  ------------------
  |  |  |  |   41|    314|    do                           \
  |  |  |  |   42|    314|    {                            \
  |  |  |  |   43|    628|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 314]
  |  |  |  |  |  Branch (43:21): [True: 314, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   44|    314|        goto cleanup;        \
  |  |  |  |   45|    314|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  542|       |
  543|    314|    MBEDTLS_MPI_CHK(mbedtls_mpi_inv_mod(&s_inv, s, &grp->N));
  ------------------
  |  |   41|    314|    do                           \
  |  |   42|    314|    {                            \
  |  |   43|    314|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 314]
  |  |  ------------------
  |  |   44|    314|        goto cleanup;        \
  |  |   45|    314|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  544|       |
  545|    314|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(pu1, &e, &s_inv));
  ------------------
  |  |   41|    314|    do                           \
  |  |   42|    314|    {                            \
  |  |   43|    314|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 314]
  |  |  ------------------
  |  |   44|    314|        goto cleanup;        \
  |  |   45|    314|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  546|    314|    MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(pu1, pu1, &grp->N));
  ------------------
  |  |   41|    314|    do                           \
  |  |   42|    314|    {                            \
  |  |   43|    314|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 314]
  |  |  ------------------
  |  |   44|    314|        goto cleanup;        \
  |  |   45|    314|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  547|       |
  548|    314|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(pu2, r, &s_inv));
  ------------------
  |  |   41|    314|    do                           \
  |  |   42|    314|    {                            \
  |  |   43|    314|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 314]
  |  |  ------------------
  |  |   44|    314|        goto cleanup;        \
  |  |   45|    314|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  549|    314|    MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(pu2, pu2, &grp->N));
  ------------------
  |  |   41|    314|    do                           \
  |  |   42|    314|    {                            \
  |  |   43|    314|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 314]
  |  |  ------------------
  |  |   44|    314|        goto cleanup;        \
  |  |   45|    314|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  550|       |
  551|    314|#if defined(MBEDTLS_ECP_RESTARTABLE)
  552|    314|    if (rs_ctx != NULL && rs_ctx->ver != NULL) {
  ------------------
  |  Branch (552:9): [True: 0, False: 314]
  |  Branch (552:27): [True: 0, False: 0]
  ------------------
  553|      0|        rs_ctx->ver->state = ecdsa_ver_muladd;
  554|      0|    }
  555|       |
  556|    314|muladd:
  557|    314|#endif
  558|       |    /*
  559|       |     * Step 5: R = u1 G + u2 Q
  560|       |     */
  561|    314|    MBEDTLS_MPI_CHK(mbedtls_ecp_muladd_restartable(grp,
  ------------------
  |  |   41|    314|    do                           \
  |  |   42|    314|    {                            \
  |  |   43|    628|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 314]
  |  |  |  Branch (43:21): [True: 314, False: 0]
  |  |  ------------------
  |  |   44|    314|        goto cleanup;        \
  |  |   45|    314|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  562|    314|                                                   &R, pu1, &grp->G, pu2, Q, ECDSA_RS_ECP));
  563|       |
  564|    314|    if (mbedtls_ecp_is_zero(&R)) {
  ------------------
  |  Branch (564:9): [True: 0, False: 314]
  ------------------
  565|      0|        ret = MBEDTLS_ERR_ECP_VERIFY_FAILED;
  ------------------
  |  |   41|      0|#define MBEDTLS_ERR_ECP_VERIFY_FAILED                     -0x4E00
  ------------------
  566|      0|        goto cleanup;
  567|      0|    }
  568|       |
  569|       |    /*
  570|       |     * Step 6: convert xR to an integer (no-op)
  571|       |     * Step 7: reduce xR mod n (gives v)
  572|       |     */
  573|    314|    MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&R.X, &R.X, &grp->N));
  ------------------
  |  |   41|    314|    do                           \
  |  |   42|    314|    {                            \
  |  |   43|    314|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 314]
  |  |  ------------------
  |  |   44|    314|        goto cleanup;        \
  |  |   45|    314|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  574|       |
  575|       |    /*
  576|       |     * Step 8: check if v (that is, R.X) is equal to r
  577|       |     */
  578|    314|    if (mbedtls_mpi_cmp_mpi(&R.X, r) != 0) {
  ------------------
  |  Branch (578:9): [True: 0, False: 314]
  ------------------
  579|      0|        ret = MBEDTLS_ERR_ECP_VERIFY_FAILED;
  ------------------
  |  |   41|      0|#define MBEDTLS_ERR_ECP_VERIFY_FAILED                     -0x4E00
  ------------------
  580|      0|        goto cleanup;
  581|      0|    }
  582|       |
  583|    314|cleanup:
  584|    314|    mbedtls_ecp_point_free(&R);
  585|    314|    mbedtls_mpi_free(&e); mbedtls_mpi_free(&s_inv);
  586|    314|    mbedtls_mpi_free(&u1); mbedtls_mpi_free(&u2);
  587|       |
  588|    314|    ECDSA_RS_LEAVE(ver);
  ------------------
  |  |  171|    314|#define ECDSA_RS_LEAVE(SUB)   do {                                 \
  |  |  172|    314|        /* clear our sub-context when not in progress (done or error) */ \
  |  |  173|    314|        if (rs_ctx != NULL && rs_ctx->SUB != NULL &&                     \
  |  |  ------------------
  |  |  |  Branch (173:13): [True: 0, False: 314]
  |  |  |  Branch (173:31): [True: 0, False: 0]
  |  |  ------------------
  |  |  174|    314|            ret != MBEDTLS_ERR_ECP_IN_PROGRESS)                         \
  |  |  ------------------
  |  |  |  |   51|      0|#define MBEDTLS_ERR_ECP_IN_PROGRESS                       -0x4B00
  |  |  ------------------
  |  |  |  Branch (174:13): [True: 0, False: 0]
  |  |  ------------------
  |  |  175|    314|        {                                                                \
  |  |  176|      0|            ecdsa_restart_## SUB ##_free(rs_ctx->SUB);                 \
  |  |  177|      0|            mbedtls_free(rs_ctx->SUB);                                 \
  |  |  ------------------
  |  |  |  |  143|      0|#define mbedtls_free       MBEDTLS_PLATFORM_FREE_MACRO
  |  |  |  |  ------------------
  |  |  |  |  |  | 4095|      0|#define MBEDTLS_PLATFORM_FREE_MACRO            my_free
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  178|      0|            rs_ctx->SUB = NULL;                                          \
  |  |  179|      0|        }                                                                \
  |  |  180|    314|                                                                     \
  |  |  181|    314|        if (rs_ctx != NULL)                                             \
  |  |  ------------------
  |  |  |  Branch (181:13): [True: 0, False: 314]
  |  |  ------------------
  |  |  182|    314|        rs_ctx->ecp.depth--;                                         \
  |  |  183|    314|} while (0)
  |  |  ------------------
  |  |  |  Branch (183:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
  589|       |
  590|    314|    return ret;
  591|    314|}
mbedtls_ecdsa_read_signature:
  706|    314|{
  707|    314|    return mbedtls_ecdsa_read_signature_restartable(
  708|    314|        ctx, hash, hlen, sig, slen, NULL);
  709|    314|}
mbedtls_ecdsa_read_signature_restartable:
  718|    314|{
  719|    314|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|    314|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  720|    314|    unsigned char *p = (unsigned char *) sig;
  721|    314|    const unsigned char *end = sig + slen;
  722|    314|    size_t len;
  723|    314|    mbedtls_mpi r, s;
  724|    314|    mbedtls_mpi_init(&r);
  725|    314|    mbedtls_mpi_init(&s);
  726|       |
  727|    314|    if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
  ------------------
  |  Branch (727:9): [True: 0, False: 314]
  ------------------
  728|    314|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|    314|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|    314|#define MBEDTLS_ASN1_SEQUENCE                0x10
  ------------------
  729|      0|        ret += MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
  730|      0|        goto cleanup;
  731|      0|    }
  732|       |
  733|    314|    if (p + len != end) {
  ------------------
  |  Branch (733:9): [True: 0, False: 314]
  ------------------
  734|      0|        ret = MBEDTLS_ERROR_ADD(MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  735|      0|                                MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
  736|      0|        goto cleanup;
  737|      0|    }
  738|       |
  739|    314|    if ((ret = mbedtls_asn1_get_mpi(&p, end, &r)) != 0 ||
  ------------------
  |  Branch (739:9): [True: 0, False: 314]
  ------------------
  740|    314|        (ret = mbedtls_asn1_get_mpi(&p, end, &s)) != 0) {
  ------------------
  |  Branch (740:9): [True: 0, False: 314]
  ------------------
  741|      0|        ret += MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
  742|      0|        goto cleanup;
  743|      0|    }
  744|       |#if defined(MBEDTLS_ECDSA_VERIFY_ALT)
  745|       |    (void) rs_ctx;
  746|       |
  747|       |    if ((ret = mbedtls_ecdsa_verify(&ctx->grp, hash, hlen,
  748|       |                                    &ctx->Q, &r, &s)) != 0) {
  749|       |        goto cleanup;
  750|       |    }
  751|       |#else
  752|    314|    if ((ret = mbedtls_ecdsa_verify_restartable(&ctx->grp, hash, hlen,
  ------------------
  |  Branch (752:9): [True: 0, False: 314]
  ------------------
  753|    314|                                                &ctx->Q, &r, &s, rs_ctx)) != 0) {
  754|      0|        goto cleanup;
  755|      0|    }
  756|    314|#endif /* MBEDTLS_ECDSA_VERIFY_ALT */
  757|       |
  758|       |    /* At this point we know that the buffer starts with a valid signature.
  759|       |     * Return 0 if the buffer just contains the signature, and a specific
  760|       |     * error code if the valid signature is followed by more data. */
  761|    314|    if (p != end) {
  ------------------
  |  Branch (761:9): [True: 0, False: 314]
  ------------------
  762|      0|        ret = MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH;
  ------------------
  |  |   49|      0|#define MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH                  -0x4C00
  ------------------
  763|      0|    }
  764|       |
  765|    314|cleanup:
  766|    314|    mbedtls_mpi_free(&r);
  767|    314|    mbedtls_mpi_free(&s);
  768|       |
  769|    314|    return ret;
  770|    314|}
ecdsa.c:derive_mpi:
  205|    314|{
  206|    314|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|    314|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  207|    314|    size_t n_size = (grp->nbits + 7) / 8;
  208|    314|    size_t use_size = blen > n_size ? n_size : blen;
  ------------------
  |  Branch (208:23): [True: 0, False: 314]
  ------------------
  209|       |
  210|    314|    MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(x, buf, use_size));
  ------------------
  |  |   41|    314|    do                           \
  |  |   42|    314|    {                            \
  |  |   43|    314|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 314]
  |  |  ------------------
  |  |   44|    314|        goto cleanup;        \
  |  |   45|    314|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  211|    314|    if (use_size * 8 > grp->nbits) {
  ------------------
  |  Branch (211:9): [True: 0, False: 314]
  ------------------
  212|      0|        MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(x, use_size * 8 - grp->nbits));
  ------------------
  |  |   41|      0|    do                           \
  |  |   42|      0|    {                            \
  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  ------------------
  |  |   44|      0|        goto cleanup;        \
  |  |   45|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  213|      0|    }
  214|       |
  215|       |    /* While at it, reduce modulo N */
  216|    314|    if (mbedtls_mpi_cmp_mpi(x, &grp->N) >= 0) {
  ------------------
  |  Branch (216:9): [True: 0, False: 314]
  ------------------
  217|      0|        MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(x, x, &grp->N));
  ------------------
  |  |   41|      0|    do                           \
  |  |   42|      0|    {                            \
  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  ------------------
  |  |   44|      0|        goto cleanup;        \
  |  |   45|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  218|      0|    }
  219|       |
  220|    314|cleanup:
  221|    314|    return ret;
  222|    314|}

mbedtls_ecp_restart_is_enabled:
  117|  1.25k|{
  118|  1.25k|    return ecp_max_ops != 0;
  119|  1.25k|}
mbedtls_ecp_restart_init:
  218|    314|{
  219|    314|    ctx->ops_done = 0;
  220|    314|    ctx->depth = 0;
  221|    314|    ctx->rsm = NULL;
  222|    314|    ctx->ma = NULL;
  223|    314|}
mbedtls_ecp_restart_free:
  229|    157|{
  230|    157|    if (ctx == NULL) {
  ------------------
  |  Branch (230:9): [True: 0, False: 157]
  ------------------
  231|      0|        return;
  232|      0|    }
  233|       |
  234|    157|    ecp_restart_rsm_free(ctx->rsm);
  235|    157|    mbedtls_free(ctx->rsm);
  ------------------
  |  |  143|    157|#define mbedtls_free       MBEDTLS_PLATFORM_FREE_MACRO
  |  |  ------------------
  |  |  |  | 4095|    157|#define MBEDTLS_PLATFORM_FREE_MACRO            my_free
  |  |  ------------------
  ------------------
  236|       |
  237|    157|    ecp_restart_ma_free(ctx->ma);
  238|    157|    mbedtls_free(ctx->ma);
  ------------------
  |  |  143|    157|#define mbedtls_free       MBEDTLS_PLATFORM_FREE_MACRO
  |  |  ------------------
  |  |  |  | 4095|    157|#define MBEDTLS_PLATFORM_FREE_MACRO            my_free
  |  |  ------------------
  ------------------
  239|       |
  240|    157|    mbedtls_ecp_restart_init(ctx);
  241|    157|}
mbedtls_ecp_check_budget:
  249|  99.8k|{
  250|  99.8k|    if (rs_ctx != NULL && ecp_max_ops != 0) {
  ------------------
  |  Branch (250:9): [True: 0, False: 99.8k]
  |  Branch (250:27): [True: 0, False: 0]
  ------------------
  251|       |        /* scale depending on curve size: the chosen reference is 256-bit,
  252|       |         * and multiplication is quadratic. Round to the closest integer. */
  253|      0|        if (grp->pbits >= 512) {
  ------------------
  |  Branch (253:13): [True: 0, False: 0]
  ------------------
  254|      0|            ops *= 4;
  255|      0|        } else if (grp->pbits >= 384) {
  ------------------
  |  Branch (255:20): [True: 0, False: 0]
  ------------------
  256|      0|            ops *= 2;
  257|      0|        }
  258|       |
  259|       |        /* Avoid infinite loops: always allow first step.
  260|       |         * Because of that, however, it's not generally true
  261|       |         * that ops_done <= ecp_max_ops, so the check
  262|       |         * ops_done > ecp_max_ops below is mandatory. */
  263|      0|        if ((rs_ctx->ops_done != 0) &&
  ------------------
  |  Branch (263:13): [True: 0, False: 0]
  ------------------
  264|      0|            (rs_ctx->ops_done > ecp_max_ops ||
  ------------------
  |  Branch (264:14): [True: 0, False: 0]
  ------------------
  265|      0|             ops > ecp_max_ops - rs_ctx->ops_done)) {
  ------------------
  |  Branch (265:14): [True: 0, False: 0]
  ------------------
  266|      0|            return MBEDTLS_ERR_ECP_IN_PROGRESS;
  ------------------
  |  |   51|      0|#define MBEDTLS_ERR_ECP_IN_PROGRESS                       -0x4B00
  ------------------
  267|      0|        }
  268|       |
  269|       |        /* update running count */
  270|      0|        rs_ctx->ops_done += ops;
  271|      0|    }
  272|       |
  273|  99.8k|    return 0;
  274|  99.8k|}
mbedtls_ecp_get_type:
  487|  14.1k|{
  488|  14.1k|    if (grp->G.X.p == NULL) {
  ------------------
  |  Branch (488:9): [True: 0, False: 14.1k]
  ------------------
  489|      0|        return MBEDTLS_ECP_TYPE_NONE;
  490|      0|    }
  491|       |
  492|  14.1k|    if (grp->G.Y.p == NULL) {
  ------------------
  |  Branch (492:9): [True: 0, False: 14.1k]
  ------------------
  493|      0|        return MBEDTLS_ECP_TYPE_MONTGOMERY;
  494|  14.1k|    } else {
  495|  14.1k|        return MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS;
  496|  14.1k|    }
  497|  14.1k|}
mbedtls_ecp_point_init:
  503|  12.2k|{
  504|  12.2k|    mbedtls_mpi_init(&pt->X);
  505|  12.2k|    mbedtls_mpi_init(&pt->Y);
  506|  12.2k|    mbedtls_mpi_init(&pt->Z);
  507|  12.2k|}
mbedtls_ecp_group_init:
  513|  5.33k|{
  514|  5.33k|    grp->id = MBEDTLS_ECP_DP_NONE;
  515|  5.33k|    mbedtls_mpi_init(&grp->P);
  516|  5.33k|    mbedtls_mpi_init(&grp->A);
  517|  5.33k|    mbedtls_mpi_init(&grp->B);
  518|  5.33k|    mbedtls_ecp_point_init(&grp->G);
  519|  5.33k|    mbedtls_mpi_init(&grp->N);
  520|  5.33k|    grp->pbits = 0;
  521|  5.33k|    grp->nbits = 0;
  522|  5.33k|    grp->h = 0;
  523|  5.33k|    grp->modp = NULL;
  524|  5.33k|    grp->t_pre = NULL;
  525|  5.33k|    grp->t_post = NULL;
  526|  5.33k|    grp->t_data = NULL;
  527|  5.33k|    grp->T = NULL;
  528|  5.33k|    grp->T_size = 0;
  529|  5.33k|}
mbedtls_ecp_keypair_init:
  535|  2.51k|{
  536|  2.51k|    mbedtls_ecp_group_init(&key->grp);
  537|  2.51k|    mbedtls_mpi_init(&key->d);
  538|  2.51k|    mbedtls_ecp_point_init(&key->Q);
  539|  2.51k|}
mbedtls_ecp_point_free:
  545|  9.57k|{
  546|  9.57k|    if (pt == NULL) {
  ------------------
  |  Branch (546:9): [True: 0, False: 9.57k]
  ------------------
  547|      0|        return;
  548|      0|    }
  549|       |
  550|  9.57k|    mbedtls_mpi_free(&(pt->X));
  551|  9.57k|    mbedtls_mpi_free(&(pt->Y));
  552|  9.57k|    mbedtls_mpi_free(&(pt->Z));
  553|  9.57k|}
mbedtls_ecp_group_free:
  572|  5.33k|{
  573|  5.33k|    size_t i;
  574|       |
  575|  5.33k|    if (grp == NULL) {
  ------------------
  |  Branch (575:9): [True: 0, False: 5.33k]
  ------------------
  576|      0|        return;
  577|      0|    }
  578|       |
  579|  5.33k|    if (grp->h != 1) {
  ------------------
  |  Branch (579:9): [True: 2.66k, False: 2.66k]
  ------------------
  580|  2.66k|        mbedtls_mpi_free(&grp->A);
  581|  2.66k|        mbedtls_mpi_free(&grp->B);
  582|  2.66k|        mbedtls_ecp_point_free(&grp->G);
  583|       |
  584|  2.66k|#if !defined(MBEDTLS_ECP_WITH_MPI_UINT)
  585|  2.66k|        mbedtls_mpi_free(&grp->N);
  586|  2.66k|        mbedtls_mpi_free(&grp->P);
  587|  2.66k|#endif
  588|  2.66k|    }
  589|       |
  590|  5.33k|    if (!ecp_group_is_static_comb_table(grp) && grp->T != NULL) {
  ------------------
  |  Branch (590:9): [True: 2.66k, False: 2.66k]
  |  Branch (590:49): [True: 0, False: 2.66k]
  ------------------
  591|      0|        for (i = 0; i < grp->T_size; i++) {
  ------------------
  |  Branch (591:21): [True: 0, False: 0]
  ------------------
  592|      0|            mbedtls_ecp_point_free(&grp->T[i]);
  593|      0|        }
  594|      0|        mbedtls_free(grp->T);
  ------------------
  |  |  143|      0|#define mbedtls_free       MBEDTLS_PLATFORM_FREE_MACRO
  |  |  ------------------
  |  |  |  | 4095|      0|#define MBEDTLS_PLATFORM_FREE_MACRO            my_free
  |  |  ------------------
  ------------------
  595|      0|    }
  596|       |
  597|  5.33k|    mbedtls_platform_zeroize(grp, sizeof(mbedtls_ecp_group));
  598|  5.33k|}
mbedtls_ecp_keypair_free:
  604|  2.51k|{
  605|  2.51k|    if (key == NULL) {
  ------------------
  |  Branch (605:9): [True: 0, False: 2.51k]
  ------------------
  606|      0|        return;
  607|      0|    }
  608|       |
  609|  2.51k|    mbedtls_ecp_group_free(&key->grp);
  610|  2.51k|    mbedtls_mpi_free(&key->d);
  611|  2.51k|    mbedtls_ecp_point_free(&key->Q);
  612|  2.51k|}
mbedtls_ecp_copy:
  618|  1.41k|{
  619|  1.41k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  1.41k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  620|  1.41k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&P->X, &Q->X));
  ------------------
  |  |   41|  1.41k|    do                           \
  |  |   42|  1.41k|    {                            \
  |  |   43|  1.41k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.41k]
  |  |  ------------------
  |  |   44|  1.41k|        goto cleanup;        \
  |  |   45|  1.41k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  621|  1.41k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&P->Y, &Q->Y));
  ------------------
  |  |   41|  1.41k|    do                           \
  |  |   42|  1.41k|    {                            \
  |  |   43|  1.41k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.41k]
  |  |  ------------------
  |  |   44|  1.41k|        goto cleanup;        \
  |  |   45|  1.41k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  622|  1.41k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&P->Z, &Q->Z));
  ------------------
  |  |   41|  1.41k|    do                           \
  |  |   42|  1.41k|    {                            \
  |  |   43|  1.41k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.41k]
  |  |  ------------------
  |  |   44|  1.41k|        goto cleanup;        \
  |  |   45|  1.41k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  623|       |
  624|  1.41k|cleanup:
  625|  1.41k|    return ret;
  626|  1.41k|}
mbedtls_ecp_is_zero:
  654|    314|{
  655|    314|    return mbedtls_mpi_cmp_int(&pt->Z, 0) == 0;
  656|    314|}
mbedtls_ecp_point_read_binary:
  772|  2.51k|{
  773|  2.51k|    int ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
  ------------------
  |  |   39|  2.51k|#define MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE               -0x4E80
  ------------------
  774|  2.51k|    size_t plen;
  775|  2.51k|    if (ilen < 1) {
  ------------------
  |  Branch (775:9): [True: 0, False: 2.51k]
  ------------------
  776|      0|        return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
  777|      0|    }
  778|       |
  779|  2.51k|    plen = mbedtls_mpi_size(&grp->P);
  780|       |
  781|  2.51k|#if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED)
  782|  2.51k|    if (mbedtls_ecp_get_type(grp) == MBEDTLS_ECP_TYPE_MONTGOMERY) {
  ------------------
  |  Branch (782:9): [True: 0, False: 2.51k]
  ------------------
  783|      0|        if (plen != ilen) {
  ------------------
  |  Branch (783:13): [True: 0, False: 0]
  ------------------
  784|      0|            return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
  785|      0|        }
  786|       |
  787|      0|        MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary_le(&pt->X, buf, plen));
  ------------------
  |  |   41|      0|    do                           \
  |  |   42|      0|    {                            \
  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  ------------------
  |  |   44|      0|        goto cleanup;        \
  |  |   45|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  788|      0|        mbedtls_mpi_free(&pt->Y);
  789|       |
  790|      0|        if (grp->id == MBEDTLS_ECP_DP_CURVE25519) {
  ------------------
  |  Branch (790:13): [True: 0, False: 0]
  ------------------
  791|       |            /* Set most significant bit to 0 as prescribed in RFC7748 §5 */
  792|      0|            MBEDTLS_MPI_CHK(mbedtls_mpi_set_bit(&pt->X, plen * 8 - 1, 0));
  ------------------
  |  |   41|      0|    do                           \
  |  |   42|      0|    {                            \
  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  ------------------
  |  |   44|      0|        goto cleanup;        \
  |  |   45|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  793|      0|        }
  794|       |
  795|      0|        MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&pt->Z, 1));
  ------------------
  |  |   41|      0|    do                           \
  |  |   42|      0|    {                            \
  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  ------------------
  |  |   44|      0|        goto cleanup;        \
  |  |   45|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  796|      0|    }
  797|  2.51k|#endif
  798|  2.51k|#if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
  799|  2.51k|    if (mbedtls_ecp_get_type(grp) == MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS) {
  ------------------
  |  Branch (799:9): [True: 2.51k, False: 0]
  ------------------
  800|  2.51k|        if (buf[0] == 0x00) {
  ------------------
  |  Branch (800:13): [True: 0, False: 2.51k]
  ------------------
  801|      0|            if (ilen == 1) {
  ------------------
  |  Branch (801:17): [True: 0, False: 0]
  ------------------
  802|      0|                return mbedtls_ecp_set_zero(pt);
  803|      0|            } else {
  804|      0|                return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
  805|      0|            }
  806|      0|        }
  807|       |
  808|  2.51k|        if (ilen < 1 + plen) {
  ------------------
  |  Branch (808:13): [True: 0, False: 2.51k]
  ------------------
  809|      0|            return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
  810|      0|        }
  811|       |
  812|  2.51k|        MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&pt->X, buf + 1, plen));
  ------------------
  |  |   41|  2.51k|    do                           \
  |  |   42|  2.51k|    {                            \
  |  |   43|  2.51k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.51k]
  |  |  ------------------
  |  |   44|  2.51k|        goto cleanup;        \
  |  |   45|  2.51k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  813|  2.51k|        MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&pt->Z, 1));
  ------------------
  |  |   41|  2.51k|    do                           \
  |  |   42|  2.51k|    {                            \
  |  |   43|  2.51k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.51k]
  |  |  ------------------
  |  |   44|  2.51k|        goto cleanup;        \
  |  |   45|  2.51k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  814|       |
  815|  2.51k|        if (buf[0] == 0x04) {
  ------------------
  |  Branch (815:13): [True: 2.51k, False: 0]
  ------------------
  816|       |            /* format == MBEDTLS_ECP_PF_UNCOMPRESSED */
  817|  2.51k|            if (ilen != 1 + plen * 2) {
  ------------------
  |  Branch (817:17): [True: 0, False: 2.51k]
  ------------------
  818|      0|                return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
  819|      0|            }
  820|  2.51k|            return mbedtls_mpi_read_binary(&pt->Y, buf + 1 + plen, plen);
  821|  2.51k|        } else if (buf[0] == 0x02 || buf[0] == 0x03) {
  ------------------
  |  Branch (821:20): [True: 0, False: 0]
  |  Branch (821:38): [True: 0, False: 0]
  ------------------
  822|       |            /* format == MBEDTLS_ECP_PF_COMPRESSED */
  823|      0|            if (ilen != 1 + plen) {
  ------------------
  |  Branch (823:17): [True: 0, False: 0]
  ------------------
  824|      0|                return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
  825|      0|            }
  826|      0|            return mbedtls_ecp_sw_derive_y(grp, &pt->X, &pt->Y,
  827|      0|                                           (buf[0] & 1));
  828|      0|        } else {
  829|      0|            return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
  830|      0|        }
  831|  2.51k|    }
  832|      0|#endif
  833|       |
  834|      0|cleanup:
  835|      0|    return ret;
  836|  2.51k|}
mbedtls_ecp_muladd_restartable:
 2805|    314|{
 2806|    314|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|    314|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 2807|    314|    mbedtls_ecp_point mP;
 2808|    314|    mbedtls_ecp_point *pmP = &mP;
 2809|    314|    mbedtls_ecp_point *pR = R;
 2810|    314|    mbedtls_mpi tmp[4];
 2811|       |#if defined(MBEDTLS_ECP_INTERNAL_ALT)
 2812|       |    char is_grp_capable = 0;
 2813|       |#endif
 2814|    314|    if (mbedtls_ecp_get_type(grp) != MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS) {
  ------------------
  |  Branch (2814:9): [True: 0, False: 314]
  ------------------
 2815|      0|        return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
  ------------------
  |  |   39|      0|#define MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE               -0x4E80
  ------------------
 2816|      0|    }
 2817|       |
 2818|    314|    mbedtls_ecp_point_init(&mP);
 2819|    314|    mpi_init_many(tmp, sizeof(tmp) / sizeof(mbedtls_mpi));
 2820|       |
 2821|    314|    ECP_RS_ENTER(ma);
  ------------------
  |  |  277|    314|#define ECP_RS_ENTER(SUB)   do {                                      \
  |  |  278|    314|        /* reset ops count for this call if top-level */                    \
  |  |  279|    314|        if (rs_ctx != NULL && rs_ctx->depth++ == 0)                        \
  |  |  ------------------
  |  |  |  Branch (279:13): [True: 0, False: 314]
  |  |  |  Branch (279:31): [True: 0, False: 0]
  |  |  ------------------
  |  |  280|    314|        rs_ctx->ops_done = 0;                                           \
  |  |  281|    314|                                                                        \
  |  |  282|    314|        /* set up our own sub-context if needed */                          \
  |  |  283|    314|        if (mbedtls_ecp_restart_is_enabled() &&                             \
  |  |  ------------------
  |  |  |  Branch (283:13): [True: 0, False: 314]
  |  |  ------------------
  |  |  284|    314|            rs_ctx != NULL && rs_ctx->SUB == NULL)                         \
  |  |  ------------------
  |  |  |  Branch (284:13): [True: 0, False: 0]
  |  |  |  Branch (284:31): [True: 0, False: 0]
  |  |  ------------------
  |  |  285|    314|        {                                                                   \
  |  |  286|      0|            rs_ctx->SUB = mbedtls_calloc(1, sizeof(*rs_ctx->SUB));      \
  |  |  ------------------
  |  |  |  |  144|      0|#define mbedtls_calloc     MBEDTLS_PLATFORM_CALLOC_MACRO
  |  |  |  |  ------------------
  |  |  |  |  |  | 4093|      0|#define MBEDTLS_PLATFORM_CALLOC_MACRO        my_calloc
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  287|      0|            if (rs_ctx->SUB == NULL)                                       \
  |  |  ------------------
  |  |  |  Branch (287:17): [True: 0, False: 0]
  |  |  ------------------
  |  |  288|      0|            return MBEDTLS_ERR_ECP_ALLOC_FAILED;                     \
  |  |  ------------------
  |  |  |  |   43|      0|#define MBEDTLS_ERR_ECP_ALLOC_FAILED                      -0x4D80
  |  |  ------------------
  |  |  289|      0|                                                                      \
  |  |  290|      0|            ecp_restart_## SUB ##_init(rs_ctx->SUB);                      \
  |  |  291|      0|        }                                                                   \
  |  |  292|    314|} while (0)
  |  |  ------------------
  |  |  |  Branch (292:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2822|       |
 2823|    314|#if defined(MBEDTLS_ECP_RESTARTABLE)
 2824|    314|    if (rs_ctx != NULL && rs_ctx->ma != NULL) {
  ------------------
  |  Branch (2824:9): [True: 0, False: 314]
  |  Branch (2824:27): [True: 0, False: 0]
  ------------------
 2825|       |        /* redirect intermediate results to restart context */
 2826|      0|        pmP = &rs_ctx->ma->mP;
 2827|      0|        pR  = &rs_ctx->ma->R;
 2828|       |
 2829|       |        /* jump to next operation */
 2830|      0|        if (rs_ctx->ma->state == ecp_rsma_mul2) {
  ------------------
  |  Branch (2830:13): [True: 0, False: 0]
  ------------------
 2831|      0|            goto mul2;
 2832|      0|        }
 2833|      0|        if (rs_ctx->ma->state == ecp_rsma_add) {
  ------------------
  |  Branch (2833:13): [True: 0, False: 0]
  ------------------
 2834|      0|            goto add;
 2835|      0|        }
 2836|      0|        if (rs_ctx->ma->state == ecp_rsma_norm) {
  ------------------
  |  Branch (2836:13): [True: 0, False: 0]
  ------------------
 2837|      0|            goto norm;
 2838|      0|        }
 2839|      0|    }
 2840|    314|#endif /* MBEDTLS_ECP_RESTARTABLE */
 2841|       |
 2842|    314|    MBEDTLS_MPI_CHK(mbedtls_ecp_mul_shortcuts(grp, pmP, m, P, rs_ctx));
  ------------------
  |  |   41|    314|    do                           \
  |  |   42|    314|    {                            \
  |  |   43|    314|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 314]
  |  |  ------------------
  |  |   44|    314|        goto cleanup;        \
  |  |   45|    314|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2843|    314|#if defined(MBEDTLS_ECP_RESTARTABLE)
 2844|    314|    if (rs_ctx != NULL && rs_ctx->ma != NULL) {
  ------------------
  |  Branch (2844:9): [True: 0, False: 314]
  |  Branch (2844:27): [True: 0, False: 0]
  ------------------
 2845|      0|        rs_ctx->ma->state = ecp_rsma_mul2;
 2846|      0|    }
 2847|       |
 2848|    314|mul2:
 2849|    314|#endif
 2850|    314|    MBEDTLS_MPI_CHK(mbedtls_ecp_mul_shortcuts(grp, pR,  n, Q, rs_ctx));
  ------------------
  |  |   41|    314|    do                           \
  |  |   42|    314|    {                            \
  |  |   43|    314|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 314]
  |  |  ------------------
  |  |   44|    314|        goto cleanup;        \
  |  |   45|    314|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2851|       |
 2852|       |#if defined(MBEDTLS_ECP_INTERNAL_ALT)
 2853|       |    if ((is_grp_capable = mbedtls_internal_ecp_grp_capable(grp))) {
 2854|       |        MBEDTLS_MPI_CHK(mbedtls_internal_ecp_init(grp));
 2855|       |    }
 2856|       |#endif /* MBEDTLS_ECP_INTERNAL_ALT */
 2857|       |
 2858|    314|#if defined(MBEDTLS_ECP_RESTARTABLE)
 2859|    314|    if (rs_ctx != NULL && rs_ctx->ma != NULL) {
  ------------------
  |  Branch (2859:9): [True: 0, False: 314]
  |  Branch (2859:27): [True: 0, False: 0]
  ------------------
 2860|      0|        rs_ctx->ma->state = ecp_rsma_add;
 2861|      0|    }
 2862|       |
 2863|    314|add:
 2864|    314|#endif
 2865|    314|    MBEDTLS_ECP_BUDGET(MBEDTLS_ECP_OPS_ADD);
  ------------------
  |  |  408|    314|    MBEDTLS_MPI_CHK(mbedtls_ecp_check_budget(grp, rs_ctx, \
  |  |  ------------------
  |  |  |  |   41|    314|    do                           \
  |  |  |  |   42|    314|    {                            \
  |  |  |  |   43|    314|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 314]
  |  |  |  |  ------------------
  |  |  |  |   44|    314|        goto cleanup;        \
  |  |  |  |   45|    314|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  409|    314|                                             (unsigned) (ops)));
  ------------------
 2866|    314|    MBEDTLS_MPI_CHK(ecp_add_mixed(grp, pR, pmP, pR, tmp));
  ------------------
  |  |   41|    314|    do                           \
  |  |   42|    314|    {                            \
  |  |   43|    314|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 314]
  |  |  ------------------
  |  |   44|    314|        goto cleanup;        \
  |  |   45|    314|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2867|    314|#if defined(MBEDTLS_ECP_RESTARTABLE)
 2868|    314|    if (rs_ctx != NULL && rs_ctx->ma != NULL) {
  ------------------
  |  Branch (2868:9): [True: 0, False: 314]
  |  Branch (2868:27): [True: 0, False: 0]
  ------------------
 2869|      0|        rs_ctx->ma->state = ecp_rsma_norm;
 2870|      0|    }
 2871|       |
 2872|    314|norm:
 2873|    314|#endif
 2874|    314|    MBEDTLS_ECP_BUDGET(MBEDTLS_ECP_OPS_INV);
  ------------------
  |  |  408|    314|    MBEDTLS_MPI_CHK(mbedtls_ecp_check_budget(grp, rs_ctx, \
  |  |  ------------------
  |  |  |  |   41|    314|    do                           \
  |  |  |  |   42|    314|    {                            \
  |  |  |  |   43|    314|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 314]
  |  |  |  |  ------------------
  |  |  |  |   44|    314|        goto cleanup;        \
  |  |  |  |   45|    314|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  409|    314|                                             (unsigned) (ops)));
  ------------------
 2875|    314|    MBEDTLS_MPI_CHK(ecp_normalize_jac(grp, pR));
  ------------------
  |  |   41|    314|    do                           \
  |  |   42|    314|    {                            \
  |  |   43|    314|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 314]
  |  |  ------------------
  |  |   44|    314|        goto cleanup;        \
  |  |   45|    314|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2876|       |
 2877|    314|#if defined(MBEDTLS_ECP_RESTARTABLE)
 2878|    314|    if (rs_ctx != NULL && rs_ctx->ma != NULL) {
  ------------------
  |  Branch (2878:9): [True: 0, False: 314]
  |  Branch (2878:27): [True: 0, False: 0]
  ------------------
 2879|      0|        MBEDTLS_MPI_CHK(mbedtls_ecp_copy(R, pR));
  ------------------
  |  |   41|      0|    do                           \
  |  |   42|      0|    {                            \
  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  ------------------
  |  |   44|      0|        goto cleanup;        \
  |  |   45|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2880|      0|    }
 2881|    314|#endif
 2882|       |
 2883|    314|cleanup:
 2884|       |
 2885|    314|    mpi_free_many(tmp, sizeof(tmp) / sizeof(mbedtls_mpi));
 2886|       |
 2887|       |#if defined(MBEDTLS_ECP_INTERNAL_ALT)
 2888|       |    if (is_grp_capable) {
 2889|       |        mbedtls_internal_ecp_free(grp);
 2890|       |    }
 2891|       |#endif /* MBEDTLS_ECP_INTERNAL_ALT */
 2892|       |
 2893|    314|    mbedtls_ecp_point_free(&mP);
 2894|       |
 2895|    314|    ECP_RS_LEAVE(ma);
  ------------------
  |  |  295|    314|#define ECP_RS_LEAVE(SUB)   do {                                      \
  |  |  296|    314|        /* clear our sub-context when not in progress (done or error) */    \
  |  |  297|    314|        if (rs_ctx != NULL && rs_ctx->SUB != NULL &&                        \
  |  |  ------------------
  |  |  |  Branch (297:13): [True: 0, False: 314]
  |  |  |  Branch (297:31): [True: 0, False: 0]
  |  |  ------------------
  |  |  298|    314|            ret != MBEDTLS_ERR_ECP_IN_PROGRESS)                            \
  |  |  ------------------
  |  |  |  |   51|      0|#define MBEDTLS_ERR_ECP_IN_PROGRESS                       -0x4B00
  |  |  ------------------
  |  |  |  Branch (298:13): [True: 0, False: 0]
  |  |  ------------------
  |  |  299|    314|        {                                                                   \
  |  |  300|      0|            ecp_restart_## SUB ##_free(rs_ctx->SUB);                      \
  |  |  301|      0|            mbedtls_free(rs_ctx->SUB);                                    \
  |  |  ------------------
  |  |  |  |  143|      0|#define mbedtls_free       MBEDTLS_PLATFORM_FREE_MACRO
  |  |  |  |  ------------------
  |  |  |  |  |  | 4095|      0|#define MBEDTLS_PLATFORM_FREE_MACRO            my_free
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  302|      0|            rs_ctx->SUB = NULL;                                             \
  |  |  303|      0|        }                                                                   \
  |  |  304|    314|                                                                        \
  |  |  305|    314|        if (rs_ctx != NULL)                                                \
  |  |  ------------------
  |  |  |  Branch (305:13): [True: 0, False: 314]
  |  |  ------------------
  |  |  306|    314|        rs_ctx->depth--;                                                \
  |  |  307|    314|} while (0)
  |  |  ------------------
  |  |  |  Branch (307:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2896|       |
 2897|    314|    return ret;
 2898|    314|}
mbedtls_ecp_check_pubkey:
 3029|  3.14k|{
 3030|       |    /* Must use affine coordinates */
 3031|  3.14k|    if (mbedtls_mpi_cmp_int(&pt->Z, 1) != 0) {
  ------------------
  |  Branch (3031:9): [True: 0, False: 3.14k]
  ------------------
 3032|      0|        return MBEDTLS_ERR_ECP_INVALID_KEY;
  ------------------
  |  |   47|      0|#define MBEDTLS_ERR_ECP_INVALID_KEY                       -0x4C80
  ------------------
 3033|      0|    }
 3034|       |
 3035|  3.14k|#if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED)
 3036|  3.14k|    if (mbedtls_ecp_get_type(grp) == MBEDTLS_ECP_TYPE_MONTGOMERY) {
  ------------------
  |  Branch (3036:9): [True: 0, False: 3.14k]
  ------------------
 3037|      0|        return ecp_check_pubkey_mx(grp, pt);
 3038|      0|    }
 3039|  3.14k|#endif
 3040|  3.14k|#if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
 3041|  3.14k|    if (mbedtls_ecp_get_type(grp) == MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS) {
  ------------------
  |  Branch (3041:9): [True: 3.14k, False: 0]
  ------------------
 3042|  3.14k|        return ecp_check_pubkey_sw(grp, pt);
 3043|  3.14k|    }
 3044|      0|#endif
 3045|      0|    return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
 3046|  3.14k|}
mbedtls_ecp_check_privkey:
 3053|    628|{
 3054|    628|#if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED)
 3055|    628|    if (mbedtls_ecp_get_type(grp) == MBEDTLS_ECP_TYPE_MONTGOMERY) {
  ------------------
  |  Branch (3055:9): [True: 0, False: 628]
  ------------------
 3056|       |        /* see RFC 7748 sec. 5 para. 5 */
 3057|      0|        if (mbedtls_mpi_get_bit(d, 0) != 0 ||
  ------------------
  |  Branch (3057:13): [True: 0, False: 0]
  ------------------
 3058|      0|            mbedtls_mpi_get_bit(d, 1) != 0 ||
  ------------------
  |  Branch (3058:13): [True: 0, False: 0]
  ------------------
 3059|      0|            mbedtls_mpi_bitlen(d) - 1 != grp->nbits) {  /* mbedtls_mpi_bitlen is one-based! */
  ------------------
  |  Branch (3059:13): [True: 0, False: 0]
  ------------------
 3060|      0|            return MBEDTLS_ERR_ECP_INVALID_KEY;
  ------------------
  |  |   47|      0|#define MBEDTLS_ERR_ECP_INVALID_KEY                       -0x4C80
  ------------------
 3061|      0|        }
 3062|       |
 3063|       |        /* see [Curve25519] page 5 */
 3064|      0|        if (grp->nbits == 254 && mbedtls_mpi_get_bit(d, 2) != 0) {
  ------------------
  |  Branch (3064:13): [True: 0, False: 0]
  |  Branch (3064:34): [True: 0, False: 0]
  ------------------
 3065|      0|            return MBEDTLS_ERR_ECP_INVALID_KEY;
  ------------------
  |  |   47|      0|#define MBEDTLS_ERR_ECP_INVALID_KEY                       -0x4C80
  ------------------
 3066|      0|        }
 3067|       |
 3068|      0|        return 0;
 3069|      0|    }
 3070|    628|#endif /* MBEDTLS_ECP_MONTGOMERY_ENABLED */
 3071|    628|#if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
 3072|    628|    if (mbedtls_ecp_get_type(grp) == MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS) {
  ------------------
  |  Branch (3072:9): [True: 628, False: 0]
  ------------------
 3073|       |        /* see SEC1 3.2 */
 3074|    628|        if (mbedtls_mpi_cmp_int(d, 1) < 0 ||
  ------------------
  |  Branch (3074:13): [True: 0, False: 628]
  ------------------
 3075|    628|            mbedtls_mpi_cmp_mpi(d, &grp->N) >= 0) {
  ------------------
  |  Branch (3075:13): [True: 0, False: 628]
  ------------------
 3076|      0|            return MBEDTLS_ERR_ECP_INVALID_KEY;
  ------------------
  |  |   47|      0|#define MBEDTLS_ERR_ECP_INVALID_KEY                       -0x4C80
  ------------------
 3077|    628|        } else {
 3078|    628|            return 0;
 3079|    628|        }
 3080|    628|    }
 3081|      0|#endif /* MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED */
 3082|       |
 3083|      0|    return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
 3084|    628|}
ecp.c:ecp_restart_rsm_free:
  156|    157|{
  157|    157|    unsigned char i;
  158|       |
  159|    157|    if (ctx == NULL) {
  ------------------
  |  Branch (159:9): [True: 157, False: 0]
  ------------------
  160|    157|        return;
  161|    157|    }
  162|       |
  163|      0|    mbedtls_ecp_point_free(&ctx->R);
  164|       |
  165|      0|    if (ctx->T != NULL) {
  ------------------
  |  Branch (165:9): [True: 0, False: 0]
  ------------------
  166|      0|        for (i = 0; i < ctx->T_size; i++) {
  ------------------
  |  Branch (166:21): [True: 0, False: 0]
  ------------------
  167|      0|            mbedtls_ecp_point_free(ctx->T + i);
  168|      0|        }
  169|      0|        mbedtls_free(ctx->T);
  ------------------
  |  |  143|      0|#define mbedtls_free       MBEDTLS_PLATFORM_FREE_MACRO
  |  |  ------------------
  |  |  |  | 4095|      0|#define MBEDTLS_PLATFORM_FREE_MACRO            my_free
  |  |  ------------------
  ------------------
  170|      0|    }
  171|       |
  172|      0|    ecp_restart_rsm_init(ctx);
  173|      0|}
ecp.c:ecp_restart_ma_free:
  203|    157|{
  204|    157|    if (ctx == NULL) {
  ------------------
  |  Branch (204:9): [True: 157, False: 0]
  ------------------
  205|    157|        return;
  206|    157|    }
  207|       |
  208|      0|    mbedtls_ecp_point_free(&ctx->mP);
  209|      0|    mbedtls_ecp_point_free(&ctx->R);
  210|       |
  211|      0|    ecp_restart_ma_init(ctx);
  212|      0|}
ecp.c:ecp_group_is_static_comb_table:
  559|  5.65k|{
  560|  5.65k|#if MBEDTLS_ECP_FIXED_POINT_OPTIM == 1
  561|  5.65k|    return grp->T != NULL && grp->T_size == 0;
  ------------------
  |  Branch (561:12): [True: 2.98k, False: 2.66k]
  |  Branch (561:30): [True: 2.98k, False: 0]
  ------------------
  562|       |#else
  563|       |    (void) grp;
  564|       |    return 0;
  565|       |#endif
  566|  5.65k|}
ecp.c:ecp_sw_rhs:
 1228|  3.14k|{
 1229|  3.14k|    int ret;
 1230|       |
 1231|       |    /* Compute X^3 + A X + B as X (X^2 + A) + B */
 1232|  3.14k|    MPI_ECP_SQR(rhs, X);
  ------------------
  |  | 1170|  3.14k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, A))
  |  |  ------------------
  |  |  |  |   41|  3.14k|    do                           \
  |  |  |  |   42|  3.14k|    {                            \
  |  |  |  |   43|  3.14k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 3.14k]
  |  |  |  |  ------------------
  |  |  |  |   44|  3.14k|        goto cleanup;        \
  |  |  |  |   45|  3.14k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1233|       |
 1234|       |    /* Special case for A = -3 */
 1235|  3.14k|    if (mbedtls_ecp_group_a_is_minus_3(grp)) {
  ------------------
  |  Branch (1235:9): [True: 3.14k, False: 0]
  ------------------
 1236|  3.14k|        MPI_ECP_SUB_INT(rhs, rhs, 3);
  ------------------
  |  | 1140|  3.14k|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int_mod(grp, X, A, c))
  |  |  ------------------
  |  |  |  |   41|  3.14k|    do                           \
  |  |  |  |   42|  3.14k|    {                            \
  |  |  |  |   43|  3.14k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 3.14k]
  |  |  |  |  ------------------
  |  |  |  |   44|  3.14k|        goto cleanup;        \
  |  |  |  |   45|  3.14k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1237|  3.14k|    } else {
 1238|      0|        MPI_ECP_ADD(rhs, rhs, &grp->A);
  ------------------
  |  | 1161|      0|    MBEDTLS_MPI_CHK(mbedtls_mpi_add_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|      0|    do                           \
  |  |  |  |   42|      0|    {                            \
  |  |  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   44|      0|        goto cleanup;        \
  |  |  |  |   45|      0|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1239|      0|    }
 1240|       |
 1241|  3.14k|    MPI_ECP_MUL(rhs, rhs, X);
  ------------------
  |  | 1167|  3.14k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  3.14k|    do                           \
  |  |  |  |   42|  3.14k|    {                            \
  |  |  |  |   43|  3.14k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 3.14k]
  |  |  |  |  ------------------
  |  |  |  |   44|  3.14k|        goto cleanup;        \
  |  |  |  |   45|  3.14k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1242|  3.14k|    MPI_ECP_ADD(rhs, rhs, &grp->B);
  ------------------
  |  | 1161|  3.14k|    MBEDTLS_MPI_CHK(mbedtls_mpi_add_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  3.14k|    do                           \
  |  |  |  |   42|  3.14k|    {                            \
  |  |  |  |   43|  3.14k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 3.14k]
  |  |  |  |  ------------------
  |  |  |  |   44|  3.14k|        goto cleanup;        \
  |  |  |  |   45|  3.14k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1243|       |
 1244|  3.14k|cleanup:
 1245|  3.14k|    return ret;
 1246|  3.14k|}
ecp.c:mbedtls_mpi_mul_mod:
 1059|  1.23M|{
 1060|  1.23M|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  1.23M|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1061|  1.23M|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(X, A, B));
  ------------------
  |  |   41|  1.23M|    do                           \
  |  |   42|  1.23M|    {                            \
  |  |   43|  1.23M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.23M]
  |  |  ------------------
  |  |   44|  1.23M|        goto cleanup;        \
  |  |   45|  1.23M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1062|  1.23M|    MOD_MUL(*X);
  ------------------
  |  | 1049|  1.23M|    do                                                                  \
  |  | 1050|  1.23M|    {                                                                   \
  |  | 1051|  1.23M|        MBEDTLS_MPI_CHK(ecp_modp(&(N), grp));                       \
  |  |  ------------------
  |  |  |  |   41|  1.23M|    do                           \
  |  |  |  |   42|  1.23M|    {                            \
  |  |  |  |   43|  1.23M|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 1.23M]
  |  |  |  |  ------------------
  |  |  |  |   44|  1.23M|        goto cleanup;        \
  |  |  |  |   45|  1.23M|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 1052|  1.23M|        INC_MUL_COUNT                                                   \
  |  |  ------------------
  |  |  |  | 1043|  1.23M|#define INC_MUL_COUNT   mul_count++;
  |  |  ------------------
  |  | 1053|  1.23M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (1053:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1063|  1.23M|cleanup:
 1064|  1.23M|    return ret;
 1065|  1.23M|}
ecp.c:ecp_modp:
 1000|  1.23M|{
 1001|  1.23M|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  1.23M|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1002|       |
 1003|  1.23M|    if (grp->modp == NULL) {
  ------------------
  |  Branch (1003:9): [True: 0, False: 1.23M]
  ------------------
 1004|      0|        return mbedtls_mpi_mod_mpi(N, N, &grp->P);
 1005|      0|    }
 1006|       |
 1007|       |    /* N->s < 0 is a much faster test, which fails only if N is 0 */
 1008|  1.23M|    if ((N->s < 0 && mbedtls_mpi_cmp_int(N, 0) != 0) ||
  ------------------
  |  Branch (1008:10): [True: 0, False: 1.23M]
  |  Branch (1008:22): [True: 0, False: 0]
  ------------------
 1009|  1.23M|        mbedtls_mpi_bitlen(N) > 2 * grp->pbits) {
  ------------------
  |  Branch (1009:9): [True: 0, False: 1.23M]
  ------------------
 1010|      0|        return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
 1011|      0|    }
 1012|       |
 1013|  1.23M|    MBEDTLS_MPI_CHK(grp->modp(N));
  ------------------
  |  |   41|  1.23M|    do                           \
  |  |   42|  1.23M|    {                            \
  |  |   43|  1.23M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.23M]
  |  |  ------------------
  |  |   44|  1.23M|        goto cleanup;        \
  |  |   45|  1.23M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1014|       |
 1015|       |    /* N->s < 0 is a much faster test, which fails only if N is 0 */
 1016|  2.23M|    while (N->s < 0 && mbedtls_mpi_cmp_int(N, 0) != 0) {
  ------------------
  |  Branch (1016:12): [True: 995k, False: 1.23M]
  |  Branch (1016:24): [True: 995k, False: 0]
  ------------------
 1017|   995k|        MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(N, N, &grp->P));
  ------------------
  |  |   41|   995k|    do                           \
  |  |   42|   995k|    {                            \
  |  |   43|   995k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 995k]
  |  |  ------------------
  |  |   44|   995k|        goto cleanup;        \
  |  |   45|   995k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1018|   995k|    }
 1019|       |
 1020|  1.45M|    while (mbedtls_mpi_cmp_mpi(N, &grp->P) >= 0) {
  ------------------
  |  Branch (1020:12): [True: 224k, False: 1.23M]
  ------------------
 1021|       |        /* we known P, N and the result are positive */
 1022|   224k|        MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs(N, N, &grp->P));
  ------------------
  |  |   41|   224k|    do                           \
  |  |   42|   224k|    {                            \
  |  |   43|   224k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 224k]
  |  |  ------------------
  |  |   44|   224k|        goto cleanup;        \
  |  |   45|   224k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1023|   224k|    }
 1024|       |
 1025|  1.23M|cleanup:
 1026|  1.23M|    return ret;
 1027|  1.23M|}
ecp.c:mbedtls_mpi_sub_int_mod:
 1130|  3.14k|{
 1131|  3.14k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  3.14k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1132|       |
 1133|  3.14k|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(X, A, c));
  ------------------
  |  |   41|  3.14k|    do                           \
  |  |   42|  3.14k|    {                            \
  |  |   43|  3.14k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3.14k]
  |  |  ------------------
  |  |   44|  3.14k|        goto cleanup;        \
  |  |   45|  3.14k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1134|  3.14k|    MOD_SUB(X);
  ------------------
  |  | 1072|  3.14k|    do {                                                                      \
  |  | 1073|  3.14k|        while ((N)->s < 0 && mbedtls_mpi_cmp_int((N), 0) != 0)             \
  |  |  ------------------
  |  |  |  Branch (1073:16): [True: 0, False: 3.14k]
  |  |  |  Branch (1073:30): [True: 0, False: 0]
  |  |  ------------------
  |  | 1074|  3.14k|        MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi((N), (N), &grp->P));      \
  |  |  ------------------
  |  |  |  |   41|      0|    do                           \
  |  |  |  |   42|      0|    {                            \
  |  |  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   44|      0|        goto cleanup;        \
  |  |  |  |   45|      0|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 1075|  3.14k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (1075:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1135|  3.14k|cleanup:
 1136|  3.14k|    return ret;
 1137|  3.14k|}
ecp.c:mbedtls_mpi_add_mod:
 1103|  99.8k|{
 1104|  99.8k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  99.8k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1105|  99.8k|    MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(X, A, B));
  ------------------
  |  |   41|  99.8k|    do                           \
  |  |   42|  99.8k|    {                            \
  |  |   43|  99.8k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 99.8k]
  |  |  ------------------
  |  |   44|  99.8k|        goto cleanup;        \
  |  |   45|  99.8k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1106|  99.8k|    MOD_ADD(X);
  ------------------
  |  | 1096|   147k|    while (mbedtls_mpi_cmp_mpi((N), &grp->P) >= 0)                  \
  |  |  ------------------
  |  |  |  Branch (1096:12): [True: 47.5k, False: 99.8k]
  |  |  ------------------
  |  | 1097|  99.8k|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs((N), (N), &grp->P))
  |  |  ------------------
  |  |  |  |   41|   147k|    do                           \
  |  |  |  |   42|   147k|    {                            \
  |  |  |  |   43|  47.5k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 47.5k]
  |  |  |  |  ------------------
  |  |  |  |   44|  47.5k|        goto cleanup;        \
  |  |  |  |   45|  47.5k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1107|  99.8k|cleanup:
 1108|  99.8k|    return ret;
 1109|  99.8k|}
ecp.c:ecp_mul_restartable_internal:
 2630|    628|{
 2631|    628|    int ret = MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|    628|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
 2632|       |#if defined(MBEDTLS_ECP_INTERNAL_ALT)
 2633|       |    char is_grp_capable = 0;
 2634|       |#endif
 2635|       |
 2636|    628|#if defined(MBEDTLS_ECP_RESTARTABLE)
 2637|       |    /* reset ops count for this call if top-level */
 2638|    628|    if (rs_ctx != NULL && rs_ctx->depth++ == 0) {
  ------------------
  |  Branch (2638:9): [True: 0, False: 628]
  |  Branch (2638:27): [True: 0, False: 0]
  ------------------
 2639|      0|        rs_ctx->ops_done = 0;
 2640|      0|    }
 2641|       |#else
 2642|       |    (void) rs_ctx;
 2643|       |#endif
 2644|       |
 2645|       |#if defined(MBEDTLS_ECP_INTERNAL_ALT)
 2646|       |    if ((is_grp_capable = mbedtls_internal_ecp_grp_capable(grp))) {
 2647|       |        MBEDTLS_MPI_CHK(mbedtls_internal_ecp_init(grp));
 2648|       |    }
 2649|       |#endif /* MBEDTLS_ECP_INTERNAL_ALT */
 2650|       |
 2651|    628|    int restarting = 0;
 2652|    628|#if defined(MBEDTLS_ECP_RESTARTABLE)
 2653|    628|    restarting = (rs_ctx != NULL && rs_ctx->rsm != NULL);
  ------------------
  |  Branch (2653:19): [True: 0, False: 628]
  |  Branch (2653:37): [True: 0, False: 0]
  ------------------
 2654|    628|#endif
 2655|       |    /* skip argument check when restarting */
 2656|    628|    if (!restarting) {
  ------------------
  |  Branch (2656:9): [True: 628, False: 0]
  ------------------
 2657|       |        /* check_privkey is free */
 2658|    628|        MBEDTLS_ECP_BUDGET(MBEDTLS_ECP_OPS_CHK);
  ------------------
  |  |  408|    628|    MBEDTLS_MPI_CHK(mbedtls_ecp_check_budget(grp, rs_ctx, \
  |  |  ------------------
  |  |  |  |   41|    628|    do                           \
  |  |  |  |   42|    628|    {                            \
  |  |  |  |   43|    628|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 628]
  |  |  |  |  ------------------
  |  |  |  |   44|    628|        goto cleanup;        \
  |  |  |  |   45|    628|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  409|    628|                                             (unsigned) (ops)));
  ------------------
 2659|       |
 2660|       |        /* Common sanity checks */
 2661|    628|        MBEDTLS_MPI_CHK(mbedtls_ecp_check_privkey(grp, m));
  ------------------
  |  |   41|    628|    do                           \
  |  |   42|    628|    {                            \
  |  |   43|    628|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 628]
  |  |  ------------------
  |  |   44|    628|        goto cleanup;        \
  |  |   45|    628|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2662|    628|        MBEDTLS_MPI_CHK(mbedtls_ecp_check_pubkey(grp, P));
  ------------------
  |  |   41|    628|    do                           \
  |  |   42|    628|    {                            \
  |  |   43|    628|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 628]
  |  |  ------------------
  |  |   44|    628|        goto cleanup;        \
  |  |   45|    628|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2663|    628|    }
 2664|       |
 2665|    628|    ret = MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|    628|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
 2666|    628|#if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED)
 2667|    628|    if (mbedtls_ecp_get_type(grp) == MBEDTLS_ECP_TYPE_MONTGOMERY) {
  ------------------
  |  Branch (2667:9): [True: 0, False: 628]
  ------------------
 2668|      0|        MBEDTLS_MPI_CHK(ecp_mul_mxz(grp, R, m, P, f_rng, p_rng));
  ------------------
  |  |   41|      0|    do                           \
  |  |   42|      0|    {                            \
  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  ------------------
  |  |   44|      0|        goto cleanup;        \
  |  |   45|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2669|      0|    }
 2670|    628|#endif
 2671|    628|#if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
 2672|    628|    if (mbedtls_ecp_get_type(grp) == MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS) {
  ------------------
  |  Branch (2672:9): [True: 628, False: 0]
  ------------------
 2673|    628|        MBEDTLS_MPI_CHK(ecp_mul_comb(grp, R, m, P, f_rng, p_rng, rs_ctx));
  ------------------
  |  |   41|    628|    do                           \
  |  |   42|    628|    {                            \
  |  |   43|    628|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 628]
  |  |  ------------------
  |  |   44|    628|        goto cleanup;        \
  |  |   45|    628|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2674|    628|    }
 2675|    628|#endif
 2676|       |
 2677|    628|cleanup:
 2678|       |
 2679|       |#if defined(MBEDTLS_ECP_INTERNAL_ALT)
 2680|       |    if (is_grp_capable) {
 2681|       |        mbedtls_internal_ecp_free(grp);
 2682|       |    }
 2683|       |#endif /* MBEDTLS_ECP_INTERNAL_ALT */
 2684|       |
 2685|    628|#if defined(MBEDTLS_ECP_RESTARTABLE)
 2686|    628|    if (rs_ctx != NULL) {
  ------------------
  |  Branch (2686:9): [True: 0, False: 628]
  ------------------
 2687|      0|        rs_ctx->depth--;
 2688|      0|    }
 2689|    628|#endif
 2690|       |
 2691|    628|    return ret;
 2692|    628|}
ecp.c:mbedtls_mpi_sub_mod:
 1082|   717k|{
 1083|   717k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|   717k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1084|   717k|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(X, A, B));
  ------------------
  |  |   41|   717k|    do                           \
  |  |   42|   717k|    {                            \
  |  |   43|   717k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 717k]
  |  |  ------------------
  |  |   44|   717k|        goto cleanup;        \
  |  |   45|   717k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1085|   717k|    MOD_SUB(X);
  ------------------
  |  | 1072|   717k|    do {                                                                      \
  |  | 1073|  1.07M|        while ((N)->s < 0 && mbedtls_mpi_cmp_int((N), 0) != 0)             \
  |  |  ------------------
  |  |  |  Branch (1073:16): [True: 360k, False: 717k]
  |  |  |  Branch (1073:30): [True: 360k, False: 0]
  |  |  ------------------
  |  | 1074|   717k|        MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi((N), (N), &grp->P));      \
  |  |  ------------------
  |  |  |  |   41|   360k|    do                           \
  |  |  |  |   42|   360k|    {                            \
  |  |  |  |   43|   360k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 360k]
  |  |  |  |  ------------------
  |  |  |  |   44|   360k|        goto cleanup;        \
  |  |  |  |   45|   360k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 1075|   717k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (1075:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1086|   717k|cleanup:
 1087|   717k|    return ret;
 1088|   717k|}
ecp.c:ecp_mul_comb:
 2294|    628|{
 2295|    628|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|    628|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 2296|    628|    unsigned char w, p_eq_g, i;
 2297|    628|    size_t d;
 2298|    628|    unsigned char T_size = 0, T_ok = 0;
 2299|    628|    mbedtls_ecp_point *T = NULL;
 2300|       |
 2301|    628|    ECP_RS_ENTER(rsm);
  ------------------
  |  |  277|    628|#define ECP_RS_ENTER(SUB)   do {                                      \
  |  |  278|    628|        /* reset ops count for this call if top-level */                    \
  |  |  279|    628|        if (rs_ctx != NULL && rs_ctx->depth++ == 0)                        \
  |  |  ------------------
  |  |  |  Branch (279:13): [True: 0, False: 628]
  |  |  |  Branch (279:31): [True: 0, False: 0]
  |  |  ------------------
  |  |  280|    628|        rs_ctx->ops_done = 0;                                           \
  |  |  281|    628|                                                                        \
  |  |  282|    628|        /* set up our own sub-context if needed */                          \
  |  |  283|    628|        if (mbedtls_ecp_restart_is_enabled() &&                             \
  |  |  ------------------
  |  |  |  Branch (283:13): [True: 0, False: 628]
  |  |  ------------------
  |  |  284|    628|            rs_ctx != NULL && rs_ctx->SUB == NULL)                         \
  |  |  ------------------
  |  |  |  Branch (284:13): [True: 0, False: 0]
  |  |  |  Branch (284:31): [True: 0, False: 0]
  |  |  ------------------
  |  |  285|    628|        {                                                                   \
  |  |  286|      0|            rs_ctx->SUB = mbedtls_calloc(1, sizeof(*rs_ctx->SUB));      \
  |  |  ------------------
  |  |  |  |  144|      0|#define mbedtls_calloc     MBEDTLS_PLATFORM_CALLOC_MACRO
  |  |  |  |  ------------------
  |  |  |  |  |  | 4093|      0|#define MBEDTLS_PLATFORM_CALLOC_MACRO        my_calloc
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  287|      0|            if (rs_ctx->SUB == NULL)                                       \
  |  |  ------------------
  |  |  |  Branch (287:17): [True: 0, False: 0]
  |  |  ------------------
  |  |  288|      0|            return MBEDTLS_ERR_ECP_ALLOC_FAILED;                     \
  |  |  ------------------
  |  |  |  |   43|      0|#define MBEDTLS_ERR_ECP_ALLOC_FAILED                      -0x4D80
  |  |  ------------------
  |  |  289|      0|                                                                      \
  |  |  290|      0|            ecp_restart_## SUB ##_init(rs_ctx->SUB);                      \
  |  |  291|      0|        }                                                                   \
  |  |  292|    628|} while (0)
  |  |  ------------------
  |  |  |  Branch (292:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2302|       |
 2303|       |    /* Is P the base point ? */
 2304|    628|#if MBEDTLS_ECP_FIXED_POINT_OPTIM == 1
 2305|    628|    p_eq_g = (MPI_ECP_CMP(&P->Y, &grp->G.Y) == 0 &&
  ------------------
  |  | 1191|    628|    mbedtls_mpi_cmp_mpi(X, Y)
  ------------------
  |  Branch (2305:15): [True: 314, False: 314]
  ------------------
 2306|    628|              MPI_ECP_CMP(&P->X, &grp->G.X) == 0);
  ------------------
  |  | 1191|    314|    mbedtls_mpi_cmp_mpi(X, Y)
  ------------------
  |  Branch (2306:15): [True: 314, False: 0]
  ------------------
 2307|       |#else
 2308|       |    p_eq_g = 0;
 2309|       |#endif
 2310|       |
 2311|       |    /* Pick window size and deduce related sizes */
 2312|    628|    w = ecp_pick_window_size(grp, p_eq_g);
 2313|    628|    T_size = 1U << (w - 1);
 2314|    628|    d = (grp->nbits + w - 1) / w;
 2315|       |
 2316|       |    /* Pre-computed table: do we have it already for the base point? */
 2317|    628|    if (p_eq_g && grp->T != NULL) {
  ------------------
  |  Branch (2317:9): [True: 314, False: 314]
  |  Branch (2317:19): [True: 314, False: 0]
  ------------------
 2318|       |        /* second pointer to the same table, will be deleted on exit */
 2319|    314|        T = grp->T;
 2320|    314|        T_ok = 1;
 2321|    314|    } else
 2322|    314|#if defined(MBEDTLS_ECP_RESTARTABLE)
 2323|       |    /* Pre-computed table: do we have one in progress? complete? */
 2324|    314|    if (rs_ctx != NULL && rs_ctx->rsm != NULL && rs_ctx->rsm->T != NULL) {
  ------------------
  |  Branch (2324:9): [True: 0, False: 314]
  |  Branch (2324:27): [True: 0, False: 0]
  |  Branch (2324:50): [True: 0, False: 0]
  ------------------
 2325|       |        /* transfer ownership of T from rsm to local function */
 2326|      0|        T = rs_ctx->rsm->T;
 2327|      0|        rs_ctx->rsm->T = NULL;
 2328|      0|        rs_ctx->rsm->T_size = 0;
 2329|       |
 2330|       |        /* This effectively jumps to the call to mul_comb_after_precomp() */
 2331|      0|        T_ok = rs_ctx->rsm->state >= ecp_rsm_comb_core;
 2332|      0|    } else
 2333|    314|#endif
 2334|       |    /* Allocate table if we didn't have any */
 2335|    314|    {
 2336|    314|        T = mbedtls_calloc(T_size, sizeof(mbedtls_ecp_point));
  ------------------
  |  |  144|    314|#define mbedtls_calloc     MBEDTLS_PLATFORM_CALLOC_MACRO
  |  |  ------------------
  |  |  |  | 4093|    314|#define MBEDTLS_PLATFORM_CALLOC_MACRO        my_calloc
  |  |  ------------------
  ------------------
 2337|    314|        if (T == NULL) {
  ------------------
  |  Branch (2337:13): [True: 0, False: 314]
  ------------------
 2338|      0|            ret = MBEDTLS_ERR_ECP_ALLOC_FAILED;
  ------------------
  |  |   43|      0|#define MBEDTLS_ERR_ECP_ALLOC_FAILED                      -0x4D80
  ------------------
 2339|      0|            goto cleanup;
 2340|      0|        }
 2341|       |
 2342|  2.82k|        for (i = 0; i < T_size; i++) {
  ------------------
  |  Branch (2342:21): [True: 2.51k, False: 314]
  ------------------
 2343|  2.51k|            mbedtls_ecp_point_init(&T[i]);
 2344|  2.51k|        }
 2345|       |
 2346|    314|        T_ok = 0;
 2347|    314|    }
 2348|       |
 2349|       |    /* Compute table (or finish computing it) if not done already */
 2350|    628|    if (!T_ok) {
  ------------------
  |  Branch (2350:9): [True: 314, False: 314]
  ------------------
 2351|    314|        MBEDTLS_MPI_CHK(ecp_precompute_comb(grp, T, P, w, d, rs_ctx));
  ------------------
  |  |   41|    314|    do                           \
  |  |   42|    314|    {                            \
  |  |   43|    314|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 314]
  |  |  ------------------
  |  |   44|    314|        goto cleanup;        \
  |  |   45|    314|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2352|       |
 2353|    314|        if (p_eq_g) {
  ------------------
  |  Branch (2353:13): [True: 0, False: 314]
  ------------------
 2354|       |            /* almost transfer ownership of T to the group, but keep a copy of
 2355|       |             * the pointer to use for calling the next function more easily */
 2356|      0|            grp->T = T;
 2357|      0|            grp->T_size = T_size;
 2358|      0|        }
 2359|    314|    }
 2360|       |
 2361|       |    /* Actual comb multiplication using precomputed points */
 2362|    628|    MBEDTLS_MPI_CHK(ecp_mul_comb_after_precomp(grp, R, m,
  ------------------
  |  |   41|    628|    do                           \
  |  |   42|    628|    {                            \
  |  |   43|    628|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 628]
  |  |  ------------------
  |  |   44|    628|        goto cleanup;        \
  |  |   45|    628|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2363|    628|                                               T, T_size, w, d,
 2364|    628|                                               f_rng, p_rng, rs_ctx));
 2365|       |
 2366|    628|cleanup:
 2367|       |
 2368|       |    /* does T belong to the group? */
 2369|    628|    if (T == grp->T) {
  ------------------
  |  Branch (2369:9): [True: 314, False: 314]
  ------------------
 2370|    314|        T = NULL;
 2371|    314|    }
 2372|       |
 2373|       |    /* does T belong to the restart context? */
 2374|    628|#if defined(MBEDTLS_ECP_RESTARTABLE)
 2375|    628|    if (rs_ctx != NULL && rs_ctx->rsm != NULL && ret == MBEDTLS_ERR_ECP_IN_PROGRESS && T != NULL) {
  ------------------
  |  |   51|    628|#define MBEDTLS_ERR_ECP_IN_PROGRESS                       -0x4B00
  ------------------
  |  Branch (2375:9): [True: 0, False: 628]
  |  Branch (2375:27): [True: 0, False: 0]
  |  Branch (2375:50): [True: 0, False: 0]
  |  Branch (2375:88): [True: 0, False: 0]
  ------------------
 2376|       |        /* transfer ownership of T from local function to rsm */
 2377|      0|        rs_ctx->rsm->T_size = T_size;
 2378|      0|        rs_ctx->rsm->T = T;
 2379|      0|        T = NULL;
 2380|      0|    }
 2381|    628|#endif
 2382|       |
 2383|       |    /* did T belong to us? then let's destroy it! */
 2384|    628|    if (T != NULL) {
  ------------------
  |  Branch (2384:9): [True: 314, False: 314]
  ------------------
 2385|  2.82k|        for (i = 0; i < T_size; i++) {
  ------------------
  |  Branch (2385:21): [True: 2.51k, False: 314]
  ------------------
 2386|  2.51k|            mbedtls_ecp_point_free(&T[i]);
 2387|  2.51k|        }
 2388|    314|        mbedtls_free(T);
  ------------------
  |  |  143|    314|#define mbedtls_free       MBEDTLS_PLATFORM_FREE_MACRO
  |  |  ------------------
  |  |  |  | 4095|    314|#define MBEDTLS_PLATFORM_FREE_MACRO            my_free
  |  |  ------------------
  ------------------
 2389|    314|    }
 2390|       |
 2391|       |    /* prevent caller from using invalid value */
 2392|    628|    int should_free_R = (ret != 0);
 2393|    628|#if defined(MBEDTLS_ECP_RESTARTABLE)
 2394|       |    /* don't free R while in progress in case R == P */
 2395|    628|    if (ret == MBEDTLS_ERR_ECP_IN_PROGRESS) {
  ------------------
  |  |   51|    628|#define MBEDTLS_ERR_ECP_IN_PROGRESS                       -0x4B00
  ------------------
  |  Branch (2395:9): [True: 0, False: 628]
  ------------------
 2396|      0|        should_free_R = 0;
 2397|      0|    }
 2398|    628|#endif
 2399|    628|    if (should_free_R) {
  ------------------
  |  Branch (2399:9): [True: 0, False: 628]
  ------------------
 2400|      0|        mbedtls_ecp_point_free(R);
 2401|      0|    }
 2402|       |
 2403|    628|    ECP_RS_LEAVE(rsm);
  ------------------
  |  |  295|    628|#define ECP_RS_LEAVE(SUB)   do {                                      \
  |  |  296|    628|        /* clear our sub-context when not in progress (done or error) */    \
  |  |  297|    628|        if (rs_ctx != NULL && rs_ctx->SUB != NULL &&                        \
  |  |  ------------------
  |  |  |  Branch (297:13): [True: 0, False: 628]
  |  |  |  Branch (297:31): [True: 0, False: 0]
  |  |  ------------------
  |  |  298|    628|            ret != MBEDTLS_ERR_ECP_IN_PROGRESS)                            \
  |  |  ------------------
  |  |  |  |   51|      0|#define MBEDTLS_ERR_ECP_IN_PROGRESS                       -0x4B00
  |  |  ------------------
  |  |  |  Branch (298:13): [True: 0, False: 0]
  |  |  ------------------
  |  |  299|    628|        {                                                                   \
  |  |  300|      0|            ecp_restart_## SUB ##_free(rs_ctx->SUB);                      \
  |  |  301|      0|            mbedtls_free(rs_ctx->SUB);                                    \
  |  |  ------------------
  |  |  |  |  143|      0|#define mbedtls_free       MBEDTLS_PLATFORM_FREE_MACRO
  |  |  |  |  ------------------
  |  |  |  |  |  | 4095|      0|#define MBEDTLS_PLATFORM_FREE_MACRO            my_free
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  302|      0|            rs_ctx->SUB = NULL;                                             \
  |  |  303|      0|        }                                                                   \
  |  |  304|    628|                                                                        \
  |  |  305|    628|        if (rs_ctx != NULL)                                                \
  |  |  ------------------
  |  |  |  Branch (305:13): [True: 0, False: 628]
  |  |  ------------------
  |  |  306|    628|        rs_ctx->depth--;                                                \
  |  |  307|    628|} while (0)
  |  |  ------------------
  |  |  |  Branch (307:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2404|       |
 2405|    628|    return ret;
 2406|    628|}
ecp.c:ecp_pick_window_size:
 2236|    628|{
 2237|    628|    unsigned char w;
 2238|       |
 2239|       |    /*
 2240|       |     * Minimize the number of multiplications, that is minimize
 2241|       |     * 10 * d * w + 18 * 2^(w-1) + 11 * d + 7 * w, with d = ceil( nbits / w )
 2242|       |     * (see costs of the various parts, with 1S = 1M)
 2243|       |     */
 2244|    628|    w = grp->nbits >= 384 ? 5 : 4;
  ------------------
  |  Branch (2244:9): [True: 0, False: 628]
  ------------------
 2245|       |
 2246|       |    /*
 2247|       |     * If P == G, pre-compute a bit more, since this may be re-used later.
 2248|       |     * Just adding one avoids upping the cost of the first mul too much,
 2249|       |     * and the memory cost too.
 2250|       |     */
 2251|    628|    if (p_eq_g) {
  ------------------
  |  Branch (2251:9): [True: 314, False: 314]
  ------------------
 2252|    314|        w++;
 2253|    314|    }
 2254|       |
 2255|       |    /*
 2256|       |     * If static comb table may not be used (!p_eq_g) or static comb table does
 2257|       |     * not exists, make sure w is within bounds.
 2258|       |     * (The last test is useful only for very small curves in the test suite.)
 2259|       |     *
 2260|       |     * The user reduces MBEDTLS_ECP_WINDOW_SIZE does not changes the size of
 2261|       |     * static comb table, because the size of static comb table is fixed when
 2262|       |     * it is generated.
 2263|       |     */
 2264|    628|#if (MBEDTLS_ECP_WINDOW_SIZE < 6)
 2265|    628|    if ((!p_eq_g || !ecp_group_is_static_comb_table(grp)) && w > MBEDTLS_ECP_WINDOW_SIZE) {
  ------------------
  |  |  291|    314|#define MBEDTLS_ECP_WINDOW_SIZE    4   /**< The maximum window size used. */
  ------------------
  |  Branch (2265:10): [True: 314, False: 314]
  |  Branch (2265:21): [True: 0, False: 314]
  |  Branch (2265:62): [True: 0, False: 314]
  ------------------
 2266|      0|        w = MBEDTLS_ECP_WINDOW_SIZE;
  ------------------
  |  |  291|      0|#define MBEDTLS_ECP_WINDOW_SIZE    4   /**< The maximum window size used. */
  ------------------
 2267|      0|    }
 2268|    628|#endif
 2269|    628|    if (w >= grp->nbits) {
  ------------------
  |  Branch (2269:9): [True: 0, False: 628]
  ------------------
 2270|      0|        w = 2;
 2271|      0|    }
 2272|       |
 2273|    628|    return w;
 2274|    628|}
ecp.c:ecp_precompute_comb:
 1853|    314|{
 1854|    314|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|    314|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1855|    314|    unsigned char i;
 1856|    314|    size_t j = 0;
 1857|    314|    const unsigned char T_size = 1U << (w - 1);
 1858|    314|    mbedtls_ecp_point *cur, *TT[COMB_MAX_PRE - 1] = { NULL };
 1859|       |
 1860|    314|    mbedtls_mpi tmp[4];
 1861|       |
 1862|    314|    mpi_init_many(tmp, sizeof(tmp) / sizeof(mbedtls_mpi));
 1863|       |
 1864|    314|#if defined(MBEDTLS_ECP_RESTARTABLE)
 1865|    314|    if (rs_ctx != NULL && rs_ctx->rsm != NULL) {
  ------------------
  |  Branch (1865:9): [True: 0, False: 314]
  |  Branch (1865:27): [True: 0, False: 0]
  ------------------
 1866|      0|        if (rs_ctx->rsm->state == ecp_rsm_pre_dbl) {
  ------------------
  |  Branch (1866:13): [True: 0, False: 0]
  ------------------
 1867|      0|            goto dbl;
 1868|      0|        }
 1869|      0|        if (rs_ctx->rsm->state == ecp_rsm_pre_norm_dbl) {
  ------------------
  |  Branch (1869:13): [True: 0, False: 0]
  ------------------
 1870|      0|            goto norm_dbl;
 1871|      0|        }
 1872|      0|        if (rs_ctx->rsm->state == ecp_rsm_pre_add) {
  ------------------
  |  Branch (1872:13): [True: 0, False: 0]
  ------------------
 1873|      0|            goto add;
 1874|      0|        }
 1875|      0|        if (rs_ctx->rsm->state == ecp_rsm_pre_norm_add) {
  ------------------
  |  Branch (1875:13): [True: 0, False: 0]
  ------------------
 1876|      0|            goto norm_add;
 1877|      0|        }
 1878|      0|    }
 1879|       |#else
 1880|       |    (void) rs_ctx;
 1881|       |#endif
 1882|       |
 1883|    314|#if defined(MBEDTLS_ECP_RESTARTABLE)
 1884|    314|    if (rs_ctx != NULL && rs_ctx->rsm != NULL) {
  ------------------
  |  Branch (1884:9): [True: 0, False: 314]
  |  Branch (1884:27): [True: 0, False: 0]
  ------------------
 1885|      0|        rs_ctx->rsm->state = ecp_rsm_pre_dbl;
 1886|       |
 1887|       |        /* initial state for the loop */
 1888|      0|        rs_ctx->rsm->i = 0;
 1889|      0|    }
 1890|       |
 1891|    314|dbl:
 1892|    314|#endif
 1893|       |    /*
 1894|       |     * Set T[0] = P and
 1895|       |     * T[2^{l-1}] = 2^{dl} P for l = 1 .. w-1 (this is not the final value)
 1896|       |     */
 1897|    314|    MBEDTLS_MPI_CHK(mbedtls_ecp_copy(&T[0], P));
  ------------------
  |  |   41|    314|    do                           \
  |  |   42|    314|    {                            \
  |  |   43|    314|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 314]
  |  |  ------------------
  |  |   44|    314|        goto cleanup;        \
  |  |   45|    314|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1898|       |
 1899|    314|#if defined(MBEDTLS_ECP_RESTARTABLE)
 1900|    314|    if (rs_ctx != NULL && rs_ctx->rsm != NULL && rs_ctx->rsm->i != 0) {
  ------------------
  |  Branch (1900:9): [True: 0, False: 314]
  |  Branch (1900:27): [True: 0, False: 0]
  |  Branch (1900:50): [True: 0, False: 0]
  ------------------
 1901|      0|        j = rs_ctx->rsm->i;
 1902|      0|    } else
 1903|    314|#endif
 1904|    314|    j = 0;
 1905|       |
 1906|  60.6k|    for (; j < d * (w - 1); j++) {
  ------------------
  |  Branch (1906:12): [True: 60.2k, False: 314]
  ------------------
 1907|  60.2k|        MBEDTLS_ECP_BUDGET(MBEDTLS_ECP_OPS_DBL);
  ------------------
  |  |  408|  60.2k|    MBEDTLS_MPI_CHK(mbedtls_ecp_check_budget(grp, rs_ctx, \
  |  |  ------------------
  |  |  |  |   41|  60.2k|    do                           \
  |  |  |  |   42|  60.2k|    {                            \
  |  |  |  |   43|  60.2k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 60.2k]
  |  |  |  |  ------------------
  |  |  |  |   44|  60.2k|        goto cleanup;        \
  |  |  |  |   45|  60.2k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  409|  60.2k|                                             (unsigned) (ops)));
  ------------------
 1908|       |
 1909|  60.2k|        i = 1U << (j / d);
 1910|  60.2k|        cur = T + i;
 1911|       |
 1912|  60.2k|        if (j % d == 0) {
  ------------------
  |  Branch (1912:13): [True: 942, False: 59.3k]
  ------------------
 1913|    942|            MBEDTLS_MPI_CHK(mbedtls_ecp_copy(cur, T + (i >> 1)));
  ------------------
  |  |   41|    942|    do                           \
  |  |   42|    942|    {                            \
  |  |   43|    942|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 942]
  |  |  ------------------
  |  |   44|    942|        goto cleanup;        \
  |  |   45|    942|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1914|    942|        }
 1915|       |
 1916|  60.2k|        MBEDTLS_MPI_CHK(ecp_double_jac(grp, cur, cur, tmp));
  ------------------
  |  |   41|  60.2k|    do                           \
  |  |   42|  60.2k|    {                            \
  |  |   43|  60.2k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 60.2k]
  |  |  ------------------
  |  |   44|  60.2k|        goto cleanup;        \
  |  |   45|  60.2k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1917|  60.2k|    }
 1918|       |
 1919|    314|#if defined(MBEDTLS_ECP_RESTARTABLE)
 1920|    314|    if (rs_ctx != NULL && rs_ctx->rsm != NULL) {
  ------------------
  |  Branch (1920:9): [True: 0, False: 314]
  |  Branch (1920:27): [True: 0, False: 0]
  ------------------
 1921|      0|        rs_ctx->rsm->state = ecp_rsm_pre_norm_dbl;
 1922|      0|    }
 1923|       |
 1924|    314|norm_dbl:
 1925|    314|#endif
 1926|       |    /*
 1927|       |     * Normalize current elements in T to allow them to be used in
 1928|       |     * ecp_add_mixed() below, which requires one normalized input.
 1929|       |     *
 1930|       |     * As T has holes, use an auxiliary array of pointers to elements in T.
 1931|       |     *
 1932|       |     */
 1933|    314|    j = 0;
 1934|  1.25k|    for (i = 1; i < T_size; i <<= 1) {
  ------------------
  |  Branch (1934:17): [True: 942, False: 314]
  ------------------
 1935|    942|        TT[j++] = T + i;
 1936|    942|    }
 1937|       |
 1938|    314|    MBEDTLS_ECP_BUDGET(MBEDTLS_ECP_OPS_INV + 6 * j - 2);
  ------------------
  |  |  408|    314|    MBEDTLS_MPI_CHK(mbedtls_ecp_check_budget(grp, rs_ctx, \
  |  |  ------------------
  |  |  |  |   41|    314|    do                           \
  |  |  |  |   42|    314|    {                            \
  |  |  |  |   43|    314|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 314]
  |  |  |  |  ------------------
  |  |  |  |   44|    314|        goto cleanup;        \
  |  |  |  |   45|    314|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  409|    314|                                             (unsigned) (ops)));
  ------------------
 1939|       |
 1940|    314|    MBEDTLS_MPI_CHK(ecp_normalize_jac_many(grp, TT, j));
  ------------------
  |  |   41|    314|    do                           \
  |  |   42|    314|    {                            \
  |  |   43|    314|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 314]
  |  |  ------------------
  |  |   44|    314|        goto cleanup;        \
  |  |   45|    314|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1941|       |
 1942|    314|#if defined(MBEDTLS_ECP_RESTARTABLE)
 1943|    314|    if (rs_ctx != NULL && rs_ctx->rsm != NULL) {
  ------------------
  |  Branch (1943:9): [True: 0, False: 314]
  |  Branch (1943:27): [True: 0, False: 0]
  ------------------
 1944|      0|        rs_ctx->rsm->state = ecp_rsm_pre_add;
 1945|      0|    }
 1946|       |
 1947|    314|add:
 1948|    314|#endif
 1949|       |    /*
 1950|       |     * Compute the remaining ones using the minimal number of additions
 1951|       |     * Be careful to update T[2^l] only after using it!
 1952|       |     */
 1953|    314|    MBEDTLS_ECP_BUDGET((T_size - 1) * MBEDTLS_ECP_OPS_ADD);
  ------------------
  |  |  408|    314|    MBEDTLS_MPI_CHK(mbedtls_ecp_check_budget(grp, rs_ctx, \
  |  |  ------------------
  |  |  |  |   41|    314|    do                           \
  |  |  |  |   42|    314|    {                            \
  |  |  |  |   43|    314|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 314]
  |  |  |  |  ------------------
  |  |  |  |   44|    314|        goto cleanup;        \
  |  |  |  |   45|    314|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  409|    314|                                             (unsigned) (ops)));
  ------------------
 1954|       |
 1955|  1.25k|    for (i = 1; i < T_size; i <<= 1) {
  ------------------
  |  Branch (1955:17): [True: 942, False: 314]
  ------------------
 1956|    942|        j = i;
 1957|  3.14k|        while (j--) {
  ------------------
  |  Branch (1957:16): [True: 2.19k, False: 942]
  ------------------
 1958|  2.19k|            MBEDTLS_MPI_CHK(ecp_add_mixed(grp, &T[i + j], &T[j], &T[i], tmp));
  ------------------
  |  |   41|  2.19k|    do                           \
  |  |   42|  2.19k|    {                            \
  |  |   43|  2.19k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.19k]
  |  |  ------------------
  |  |   44|  2.19k|        goto cleanup;        \
  |  |   45|  2.19k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1959|  2.19k|        }
 1960|    942|    }
 1961|       |
 1962|    314|#if defined(MBEDTLS_ECP_RESTARTABLE)
 1963|    314|    if (rs_ctx != NULL && rs_ctx->rsm != NULL) {
  ------------------
  |  Branch (1963:9): [True: 0, False: 314]
  |  Branch (1963:27): [True: 0, False: 0]
  ------------------
 1964|      0|        rs_ctx->rsm->state = ecp_rsm_pre_norm_add;
 1965|      0|    }
 1966|       |
 1967|    314|norm_add:
 1968|    314|#endif
 1969|       |    /*
 1970|       |     * Normalize final elements in T. Even though there are no holes now, we
 1971|       |     * still need the auxiliary array for homogeneity with the previous
 1972|       |     * call. Also, skip T[0] which is already normalised, being a copy of P.
 1973|       |     */
 1974|  2.51k|    for (j = 0; j + 1 < T_size; j++) {
  ------------------
  |  Branch (1974:17): [True: 2.19k, False: 314]
  ------------------
 1975|  2.19k|        TT[j] = T + j + 1;
 1976|  2.19k|    }
 1977|       |
 1978|    314|    MBEDTLS_ECP_BUDGET(MBEDTLS_ECP_OPS_INV + 6 * j - 2);
  ------------------
  |  |  408|    314|    MBEDTLS_MPI_CHK(mbedtls_ecp_check_budget(grp, rs_ctx, \
  |  |  ------------------
  |  |  |  |   41|    314|    do                           \
  |  |  |  |   42|    314|    {                            \
  |  |  |  |   43|    314|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 314]
  |  |  |  |  ------------------
  |  |  |  |   44|    314|        goto cleanup;        \
  |  |  |  |   45|    314|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  409|    314|                                             (unsigned) (ops)));
  ------------------
 1979|       |
 1980|    314|    MBEDTLS_MPI_CHK(ecp_normalize_jac_many(grp, TT, j));
  ------------------
  |  |   41|    314|    do                           \
  |  |   42|    314|    {                            \
  |  |   43|    314|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 314]
  |  |  ------------------
  |  |   44|    314|        goto cleanup;        \
  |  |   45|    314|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1981|       |
 1982|       |    /* Free Z coordinate (=1 after normalization) to save RAM.
 1983|       |     * This makes T[i] invalid as mbedtls_ecp_points, but this is OK
 1984|       |     * since from this point onwards, they are only accessed indirectly
 1985|       |     * via the getter function ecp_select_comb() which does set the
 1986|       |     * target's Z coordinate to 1. */
 1987|  2.82k|    for (i = 0; i < T_size; i++) {
  ------------------
  |  Branch (1987:17): [True: 2.51k, False: 314]
  ------------------
 1988|  2.51k|        mbedtls_mpi_free(&T[i].Z);
 1989|  2.51k|    }
 1990|       |
 1991|    314|cleanup:
 1992|       |
 1993|    314|    mpi_free_many(tmp, sizeof(tmp) / sizeof(mbedtls_mpi));
 1994|       |
 1995|    314|#if defined(MBEDTLS_ECP_RESTARTABLE)
 1996|    314|    if (rs_ctx != NULL && rs_ctx->rsm != NULL &&
  ------------------
  |  Branch (1996:9): [True: 0, False: 314]
  |  Branch (1996:27): [True: 0, False: 0]
  ------------------
 1997|    314|        ret == MBEDTLS_ERR_ECP_IN_PROGRESS) {
  ------------------
  |  |   51|      0|#define MBEDTLS_ERR_ECP_IN_PROGRESS                       -0x4B00
  ------------------
  |  Branch (1997:9): [True: 0, False: 0]
  ------------------
 1998|      0|        if (rs_ctx->rsm->state == ecp_rsm_pre_dbl) {
  ------------------
  |  Branch (1998:13): [True: 0, False: 0]
  ------------------
 1999|      0|            rs_ctx->rsm->i = j;
 2000|      0|        }
 2001|      0|    }
 2002|    314|#endif
 2003|       |
 2004|    314|    return ret;
 2005|    314|}
ecp.c:ecp_double_jac:
 1489|  96.7k|{
 1490|  96.7k|#if defined(MBEDTLS_SELF_TEST)
 1491|  96.7k|    dbl_count++;
 1492|  96.7k|#endif
 1493|       |
 1494|       |#if defined(MBEDTLS_ECP_DOUBLE_JAC_ALT)
 1495|       |    if (mbedtls_internal_ecp_grp_capable(grp)) {
 1496|       |        return mbedtls_internal_ecp_double_jac(grp, R, P);
 1497|       |    }
 1498|       |#endif /* MBEDTLS_ECP_DOUBLE_JAC_ALT */
 1499|       |
 1500|       |#if defined(MBEDTLS_ECP_NO_FALLBACK) && defined(MBEDTLS_ECP_DOUBLE_JAC_ALT)
 1501|       |    return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
 1502|       |#else
 1503|  96.7k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  96.7k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1504|       |
 1505|       |    /* Special case for A = -3 */
 1506|  96.7k|    if (mbedtls_ecp_group_a_is_minus_3(grp)) {
  ------------------
  |  Branch (1506:9): [True: 96.7k, False: 0]
  ------------------
 1507|       |        /* tmp[0] <- M = 3(X + Z^2)(X - Z^2) */
 1508|  96.7k|        MPI_ECP_SQR(&tmp[1],  &P->Z);
  ------------------
  |  | 1170|  96.7k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, A))
  |  |  ------------------
  |  |  |  |   41|  96.7k|    do                           \
  |  |  |  |   42|  96.7k|    {                            \
  |  |  |  |   43|  96.7k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 96.7k]
  |  |  |  |  ------------------
  |  |  |  |   44|  96.7k|        goto cleanup;        \
  |  |  |  |   45|  96.7k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1509|  96.7k|        MPI_ECP_ADD(&tmp[2],  &P->X,  &tmp[1]);
  ------------------
  |  | 1161|  96.7k|    MBEDTLS_MPI_CHK(mbedtls_mpi_add_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  96.7k|    do                           \
  |  |  |  |   42|  96.7k|    {                            \
  |  |  |  |   43|  96.7k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 96.7k]
  |  |  |  |  ------------------
  |  |  |  |   44|  96.7k|        goto cleanup;        \
  |  |  |  |   45|  96.7k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1510|  96.7k|        MPI_ECP_SUB(&tmp[3],  &P->X,  &tmp[1]);
  ------------------
  |  | 1164|  96.7k|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  96.7k|    do                           \
  |  |  |  |   42|  96.7k|    {                            \
  |  |  |  |   43|  96.7k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 96.7k]
  |  |  |  |  ------------------
  |  |  |  |   44|  96.7k|        goto cleanup;        \
  |  |  |  |   45|  96.7k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1511|  96.7k|        MPI_ECP_MUL(&tmp[1],  &tmp[2],     &tmp[3]);
  ------------------
  |  | 1167|  96.7k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  96.7k|    do                           \
  |  |  |  |   42|  96.7k|    {                            \
  |  |  |  |   43|  96.7k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 96.7k]
  |  |  |  |  ------------------
  |  |  |  |   44|  96.7k|        goto cleanup;        \
  |  |  |  |   45|  96.7k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1512|  96.7k|        MPI_ECP_MUL_INT(&tmp[0],  &tmp[1],     3);
  ------------------
  |  | 1173|  96.7k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_int_mod(grp, X, A, c))
  |  |  ------------------
  |  |  |  |   41|  96.7k|    do                           \
  |  |  |  |   42|  96.7k|    {                            \
  |  |  |  |   43|  96.7k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 96.7k]
  |  |  |  |  ------------------
  |  |  |  |   44|  96.7k|        goto cleanup;        \
  |  |  |  |   45|  96.7k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1513|  96.7k|    } else {
 1514|       |        /* tmp[0] <- M = 3.X^2 + A.Z^4 */
 1515|      0|        MPI_ECP_SQR(&tmp[1],  &P->X);
  ------------------
  |  | 1170|      0|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, A))
  |  |  ------------------
  |  |  |  |   41|      0|    do                           \
  |  |  |  |   42|      0|    {                            \
  |  |  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   44|      0|        goto cleanup;        \
  |  |  |  |   45|      0|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1516|      0|        MPI_ECP_MUL_INT(&tmp[0],  &tmp[1],  3);
  ------------------
  |  | 1173|      0|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_int_mod(grp, X, A, c))
  |  |  ------------------
  |  |  |  |   41|      0|    do                           \
  |  |  |  |   42|      0|    {                            \
  |  |  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   44|      0|        goto cleanup;        \
  |  |  |  |   45|      0|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1517|       |
 1518|       |        /* Optimize away for "koblitz" curves with A = 0 */
 1519|      0|        if (MPI_ECP_CMP_INT(&grp->A, 0) != 0) {
  ------------------
  |  | 1188|      0|    mbedtls_mpi_cmp_int(X, c)
  ------------------
  |  Branch (1519:13): [True: 0, False: 0]
  ------------------
 1520|       |            /* M += A.Z^4 */
 1521|      0|            MPI_ECP_SQR(&tmp[1],  &P->Z);
  ------------------
  |  | 1170|      0|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, A))
  |  |  ------------------
  |  |  |  |   41|      0|    do                           \
  |  |  |  |   42|      0|    {                            \
  |  |  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   44|      0|        goto cleanup;        \
  |  |  |  |   45|      0|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1522|      0|            MPI_ECP_SQR(&tmp[2],  &tmp[1]);
  ------------------
  |  | 1170|      0|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, A))
  |  |  ------------------
  |  |  |  |   41|      0|    do                           \
  |  |  |  |   42|      0|    {                            \
  |  |  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   44|      0|        goto cleanup;        \
  |  |  |  |   45|      0|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1523|      0|            MPI_ECP_MUL(&tmp[1],  &tmp[2],     &grp->A);
  ------------------
  |  | 1167|      0|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|      0|    do                           \
  |  |  |  |   42|      0|    {                            \
  |  |  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   44|      0|        goto cleanup;        \
  |  |  |  |   45|      0|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1524|      0|            MPI_ECP_ADD(&tmp[0],  &tmp[0],     &tmp[1]);
  ------------------
  |  | 1161|      0|    MBEDTLS_MPI_CHK(mbedtls_mpi_add_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|      0|    do                           \
  |  |  |  |   42|      0|    {                            \
  |  |  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   44|      0|        goto cleanup;        \
  |  |  |  |   45|      0|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1525|      0|        }
 1526|      0|    }
 1527|       |
 1528|       |    /* tmp[1] <- S = 4.X.Y^2 */
 1529|  96.7k|    MPI_ECP_SQR(&tmp[2],  &P->Y);
  ------------------
  |  | 1170|  96.7k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, A))
  |  |  ------------------
  |  |  |  |   41|  96.7k|    do                           \
  |  |  |  |   42|  96.7k|    {                            \
  |  |  |  |   43|  96.7k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 96.7k]
  |  |  |  |  ------------------
  |  |  |  |   44|  96.7k|        goto cleanup;        \
  |  |  |  |   45|  96.7k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1530|  96.7k|    MPI_ECP_SHIFT_L(&tmp[2],  1);
  ------------------
  |  | 1182|  96.7k|    MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l_mod(grp, X, count))
  |  |  ------------------
  |  |  |  |   41|  96.7k|    do                           \
  |  |  |  |   42|  96.7k|    {                            \
  |  |  |  |   43|  96.7k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 96.7k]
  |  |  |  |  ------------------
  |  |  |  |   44|  96.7k|        goto cleanup;        \
  |  |  |  |   45|  96.7k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1531|  96.7k|    MPI_ECP_MUL(&tmp[1],  &P->X, &tmp[2]);
  ------------------
  |  | 1167|  96.7k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  96.7k|    do                           \
  |  |  |  |   42|  96.7k|    {                            \
  |  |  |  |   43|  96.7k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 96.7k]
  |  |  |  |  ------------------
  |  |  |  |   44|  96.7k|        goto cleanup;        \
  |  |  |  |   45|  96.7k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1532|  96.7k|    MPI_ECP_SHIFT_L(&tmp[1],  1);
  ------------------
  |  | 1182|  96.7k|    MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l_mod(grp, X, count))
  |  |  ------------------
  |  |  |  |   41|  96.7k|    do                           \
  |  |  |  |   42|  96.7k|    {                            \
  |  |  |  |   43|  96.7k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 96.7k]
  |  |  |  |  ------------------
  |  |  |  |   44|  96.7k|        goto cleanup;        \
  |  |  |  |   45|  96.7k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1533|       |
 1534|       |    /* tmp[3] <- U = 8.Y^4 */
 1535|  96.7k|    MPI_ECP_SQR(&tmp[3],  &tmp[2]);
  ------------------
  |  | 1170|  96.7k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, A))
  |  |  ------------------
  |  |  |  |   41|  96.7k|    do                           \
  |  |  |  |   42|  96.7k|    {                            \
  |  |  |  |   43|  96.7k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 96.7k]
  |  |  |  |  ------------------
  |  |  |  |   44|  96.7k|        goto cleanup;        \
  |  |  |  |   45|  96.7k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1536|  96.7k|    MPI_ECP_SHIFT_L(&tmp[3],  1);
  ------------------
  |  | 1182|  96.7k|    MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l_mod(grp, X, count))
  |  |  ------------------
  |  |  |  |   41|  96.7k|    do                           \
  |  |  |  |   42|  96.7k|    {                            \
  |  |  |  |   43|  96.7k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 96.7k]
  |  |  |  |  ------------------
  |  |  |  |   44|  96.7k|        goto cleanup;        \
  |  |  |  |   45|  96.7k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1537|       |
 1538|       |    /* tmp[2] <- T = M^2 - 2.S */
 1539|  96.7k|    MPI_ECP_SQR(&tmp[2],  &tmp[0]);
  ------------------
  |  | 1170|  96.7k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, A))
  |  |  ------------------
  |  |  |  |   41|  96.7k|    do                           \
  |  |  |  |   42|  96.7k|    {                            \
  |  |  |  |   43|  96.7k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 96.7k]
  |  |  |  |  ------------------
  |  |  |  |   44|  96.7k|        goto cleanup;        \
  |  |  |  |   45|  96.7k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1540|  96.7k|    MPI_ECP_SUB(&tmp[2],  &tmp[2], &tmp[1]);
  ------------------
  |  | 1164|  96.7k|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  96.7k|    do                           \
  |  |  |  |   42|  96.7k|    {                            \
  |  |  |  |   43|  96.7k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 96.7k]
  |  |  |  |  ------------------
  |  |  |  |   44|  96.7k|        goto cleanup;        \
  |  |  |  |   45|  96.7k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1541|  96.7k|    MPI_ECP_SUB(&tmp[2],  &tmp[2], &tmp[1]);
  ------------------
  |  | 1164|  96.7k|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  96.7k|    do                           \
  |  |  |  |   42|  96.7k|    {                            \
  |  |  |  |   43|  96.7k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 96.7k]
  |  |  |  |  ------------------
  |  |  |  |   44|  96.7k|        goto cleanup;        \
  |  |  |  |   45|  96.7k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1542|       |
 1543|       |    /* tmp[1] <- S = M(S - T) - U */
 1544|  96.7k|    MPI_ECP_SUB(&tmp[1],  &tmp[1],     &tmp[2]);
  ------------------
  |  | 1164|  96.7k|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  96.7k|    do                           \
  |  |  |  |   42|  96.7k|    {                            \
  |  |  |  |   43|  96.7k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 96.7k]
  |  |  |  |  ------------------
  |  |  |  |   44|  96.7k|        goto cleanup;        \
  |  |  |  |   45|  96.7k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1545|  96.7k|    MPI_ECP_MUL(&tmp[1],  &tmp[1],     &tmp[0]);
  ------------------
  |  | 1167|  96.7k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  96.7k|    do                           \
  |  |  |  |   42|  96.7k|    {                            \
  |  |  |  |   43|  96.7k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 96.7k]
  |  |  |  |  ------------------
  |  |  |  |   44|  96.7k|        goto cleanup;        \
  |  |  |  |   45|  96.7k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1546|  96.7k|    MPI_ECP_SUB(&tmp[1],  &tmp[1],     &tmp[3]);
  ------------------
  |  | 1164|  96.7k|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  96.7k|    do                           \
  |  |  |  |   42|  96.7k|    {                            \
  |  |  |  |   43|  96.7k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 96.7k]
  |  |  |  |  ------------------
  |  |  |  |   44|  96.7k|        goto cleanup;        \
  |  |  |  |   45|  96.7k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1547|       |
 1548|       |    /* tmp[3] <- U = 2.Y.Z */
 1549|  96.7k|    MPI_ECP_MUL(&tmp[3],  &P->Y,  &P->Z);
  ------------------
  |  | 1167|  96.7k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  96.7k|    do                           \
  |  |  |  |   42|  96.7k|    {                            \
  |  |  |  |   43|  96.7k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 96.7k]
  |  |  |  |  ------------------
  |  |  |  |   44|  96.7k|        goto cleanup;        \
  |  |  |  |   45|  96.7k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1550|  96.7k|    MPI_ECP_SHIFT_L(&tmp[3],  1);
  ------------------
  |  | 1182|  96.7k|    MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l_mod(grp, X, count))
  |  |  ------------------
  |  |  |  |   41|  96.7k|    do                           \
  |  |  |  |   42|  96.7k|    {                            \
  |  |  |  |   43|  96.7k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 96.7k]
  |  |  |  |  ------------------
  |  |  |  |   44|  96.7k|        goto cleanup;        \
  |  |  |  |   45|  96.7k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1551|       |
 1552|       |    /* Store results */
 1553|  96.7k|    MPI_ECP_MOV(&R->X, &tmp[2]);
  ------------------
  |  | 1179|  96.7k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(X, A))
  |  |  ------------------
  |  |  |  |   41|  96.7k|    do                           \
  |  |  |  |   42|  96.7k|    {                            \
  |  |  |  |   43|  96.7k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 96.7k]
  |  |  |  |  ------------------
  |  |  |  |   44|  96.7k|        goto cleanup;        \
  |  |  |  |   45|  96.7k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1554|  96.7k|    MPI_ECP_MOV(&R->Y, &tmp[1]);
  ------------------
  |  | 1179|  96.7k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(X, A))
  |  |  ------------------
  |  |  |  |   41|  96.7k|    do                           \
  |  |  |  |   42|  96.7k|    {                            \
  |  |  |  |   43|  96.7k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 96.7k]
  |  |  |  |  ------------------
  |  |  |  |   44|  96.7k|        goto cleanup;        \
  |  |  |  |   45|  96.7k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1555|  96.7k|    MPI_ECP_MOV(&R->Z, &tmp[3]);
  ------------------
  |  | 1179|  96.7k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(X, A))
  |  |  ------------------
  |  |  |  |   41|  96.7k|    do                           \
  |  |  |  |   42|  96.7k|    {                            \
  |  |  |  |   43|  96.7k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 96.7k]
  |  |  |  |  ------------------
  |  |  |  |   44|  96.7k|        goto cleanup;        \
  |  |  |  |   45|  96.7k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1556|       |
 1557|  96.7k|cleanup:
 1558|       |
 1559|  96.7k|    return ret;
 1560|  96.7k|#endif /* !defined(MBEDTLS_ECP_NO_FALLBACK) || !defined(MBEDTLS_ECP_DOUBLE_JAC_ALT) */
 1561|  96.7k|}
ecp.c:mbedtls_mpi_mul_int_mod:
 1116|  96.7k|{
 1117|  96.7k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  96.7k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1118|       |
 1119|  96.7k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_int(X, A, c));
  ------------------
  |  |   41|  96.7k|    do                           \
  |  |   42|  96.7k|    {                            \
  |  |   43|  96.7k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 96.7k]
  |  |  ------------------
  |  |   44|  96.7k|        goto cleanup;        \
  |  |   45|  96.7k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1120|  96.7k|    MOD_ADD(X);
  ------------------
  |  | 1096|   191k|    while (mbedtls_mpi_cmp_mpi((N), &grp->P) >= 0)                  \
  |  |  ------------------
  |  |  |  Branch (1096:12): [True: 94.5k, False: 96.7k]
  |  |  ------------------
  |  | 1097|  96.7k|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs((N), (N), &grp->P))
  |  |  ------------------
  |  |  |  |   41|   191k|    do                           \
  |  |  |  |   42|   191k|    {                            \
  |  |  |  |   43|  94.5k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 94.5k]
  |  |  |  |  ------------------
  |  |  |  |   44|  94.5k|        goto cleanup;        \
  |  |  |  |   45|  94.5k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1121|  96.7k|cleanup:
 1122|  96.7k|    return ret;
 1123|  96.7k|}
ecp.c:mbedtls_mpi_shift_l_mod:
 1146|   425k|{
 1147|   425k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|   425k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1148|   425k|    MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(X, count));
  ------------------
  |  |   41|   425k|    do                           \
  |  |   42|   425k|    {                            \
  |  |   43|   425k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 425k]
  |  |  ------------------
  |  |   44|   425k|        goto cleanup;        \
  |  |   45|   425k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1149|   425k|    MOD_ADD(X);
  ------------------
  |  | 1096|   633k|    while (mbedtls_mpi_cmp_mpi((N), &grp->P) >= 0)                  \
  |  |  ------------------
  |  |  |  Branch (1096:12): [True: 208k, False: 425k]
  |  |  ------------------
  |  | 1097|   425k|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs((N), (N), &grp->P))
  |  |  ------------------
  |  |  |  |   41|   633k|    do                           \
  |  |  |  |   42|   633k|    {                            \
  |  |  |  |   43|   208k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 208k]
  |  |  |  |  ------------------
  |  |  |  |   44|   208k|        goto cleanup;        \
  |  |  |  |   45|   208k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1150|   425k|cleanup:
 1151|   425k|    return ret;
 1152|   425k|}
ecp.c:ecp_normalize_jac_many:
 1362|    628|{
 1363|    628|    if (T_size < 2) {
  ------------------
  |  Branch (1363:9): [True: 0, False: 628]
  ------------------
 1364|      0|        return ecp_normalize_jac(grp, *T);
 1365|      0|    }
 1366|       |
 1367|       |#if defined(MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT)
 1368|       |    if (mbedtls_internal_ecp_grp_capable(grp)) {
 1369|       |        return mbedtls_internal_ecp_normalize_jac_many(grp, T, T_size);
 1370|       |    }
 1371|       |#endif
 1372|       |
 1373|       |#if defined(MBEDTLS_ECP_NO_FALLBACK) && defined(MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT)
 1374|       |    return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
 1375|       |#else
 1376|    628|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|    628|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1377|    628|    size_t i;
 1378|    628|    mbedtls_mpi *c, t;
 1379|       |
 1380|    628|    if ((c = mbedtls_calloc(T_size, sizeof(mbedtls_mpi))) == NULL) {
  ------------------
  |  |  144|    628|#define mbedtls_calloc     MBEDTLS_PLATFORM_CALLOC_MACRO
  |  |  ------------------
  |  |  |  | 4093|    628|#define MBEDTLS_PLATFORM_CALLOC_MACRO        my_calloc
  |  |  ------------------
  ------------------
  |  Branch (1380:9): [True: 0, False: 628]
  ------------------
 1381|      0|        return MBEDTLS_ERR_ECP_ALLOC_FAILED;
  ------------------
  |  |   43|      0|#define MBEDTLS_ERR_ECP_ALLOC_FAILED                      -0x4D80
  ------------------
 1382|      0|    }
 1383|       |
 1384|    628|    mbedtls_mpi_init(&t);
 1385|       |
 1386|    628|    mpi_init_many(c, T_size);
 1387|       |    /*
 1388|       |     * c[i] = Z_0 * ... * Z_i,   i = 0,..,n := T_size-1
 1389|       |     */
 1390|    628|    MPI_ECP_MOV(&c[0], &T[0]->Z);
  ------------------
  |  | 1179|    628|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(X, A))
  |  |  ------------------
  |  |  |  |   41|    628|    do                           \
  |  |  |  |   42|    628|    {                            \
  |  |  |  |   43|    628|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 628]
  |  |  |  |  ------------------
  |  |  |  |   44|    628|        goto cleanup;        \
  |  |  |  |   45|    628|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1391|  3.14k|    for (i = 1; i < T_size; i++) {
  ------------------
  |  Branch (1391:17): [True: 2.51k, False: 628]
  ------------------
 1392|  2.51k|        MPI_ECP_MUL(&c[i], &c[i-1], &T[i]->Z);
  ------------------
  |  | 1167|  2.51k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  2.51k|    do                           \
  |  |  |  |   42|  2.51k|    {                            \
  |  |  |  |   43|  2.51k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 2.51k]
  |  |  |  |  ------------------
  |  |  |  |   44|  2.51k|        goto cleanup;        \
  |  |  |  |   45|  2.51k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1393|  2.51k|    }
 1394|       |
 1395|       |    /*
 1396|       |     * c[n] = 1 / (Z_0 * ... * Z_n) mod P
 1397|       |     */
 1398|    628|    MPI_ECP_INV(&c[T_size-1], &c[T_size-1]);
  ------------------
  |  | 1176|    628|    MBEDTLS_MPI_CHK(mbedtls_mpi_inv_mod((dst), (src), &grp->P))
  |  |  ------------------
  |  |  |  |   41|    628|    do                           \
  |  |  |  |   42|    628|    {                            \
  |  |  |  |   43|    628|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 628]
  |  |  |  |  ------------------
  |  |  |  |   44|    628|        goto cleanup;        \
  |  |  |  |   45|    628|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1399|       |
 1400|  3.14k|    for (i = T_size - 1;; i--) {
 1401|       |        /* At the start of iteration i (note that i decrements), we have
 1402|       |         * - c[j] = Z_0 * .... * Z_j        for j  < i,
 1403|       |         * - c[j] = 1 / (Z_0 * .... * Z_j)  for j == i,
 1404|       |         *
 1405|       |         * This is maintained via
 1406|       |         * - c[i-1] <- c[i] * Z_i
 1407|       |         *
 1408|       |         * We also derive 1/Z_i = c[i] * c[i-1] for i>0 and use that
 1409|       |         * to do the actual normalization. For i==0, we already have
 1410|       |         * c[0] = 1 / Z_0.
 1411|       |         */
 1412|       |
 1413|  3.14k|        if (i > 0) {
  ------------------
  |  Branch (1413:13): [True: 2.51k, False: 628]
  ------------------
 1414|       |            /* Compute 1/Z_i and establish invariant for the next iteration. */
 1415|  2.51k|            MPI_ECP_MUL(&t,      &c[i], &c[i-1]);
  ------------------
  |  | 1167|  2.51k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  2.51k|    do                           \
  |  |  |  |   42|  2.51k|    {                            \
  |  |  |  |   43|  2.51k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 2.51k]
  |  |  |  |  ------------------
  |  |  |  |   44|  2.51k|        goto cleanup;        \
  |  |  |  |   45|  2.51k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1416|  2.51k|            MPI_ECP_MUL(&c[i-1], &c[i], &T[i]->Z);
  ------------------
  |  | 1167|  2.51k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  2.51k|    do                           \
  |  |  |  |   42|  2.51k|    {                            \
  |  |  |  |   43|  2.51k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 2.51k]
  |  |  |  |  ------------------
  |  |  |  |   44|  2.51k|        goto cleanup;        \
  |  |  |  |   45|  2.51k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1417|  2.51k|        } else {
 1418|    628|            MPI_ECP_MOV(&t, &c[0]);
  ------------------
  |  | 1179|    628|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(X, A))
  |  |  ------------------
  |  |  |  |   41|    628|    do                           \
  |  |  |  |   42|    628|    {                            \
  |  |  |  |   43|    628|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 628]
  |  |  |  |  ------------------
  |  |  |  |   44|    628|        goto cleanup;        \
  |  |  |  |   45|    628|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1419|    628|        }
 1420|       |
 1421|       |        /* Now t holds 1 / Z_i; normalize as in ecp_normalize_jac() */
 1422|  3.14k|        MPI_ECP_MUL(&T[i]->Y, &T[i]->Y, &t);
  ------------------
  |  | 1167|  3.14k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  3.14k|    do                           \
  |  |  |  |   42|  3.14k|    {                            \
  |  |  |  |   43|  3.14k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 3.14k]
  |  |  |  |  ------------------
  |  |  |  |   44|  3.14k|        goto cleanup;        \
  |  |  |  |   45|  3.14k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1423|  3.14k|        MPI_ECP_SQR(&t,       &t);
  ------------------
  |  | 1170|  3.14k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, A))
  |  |  ------------------
  |  |  |  |   41|  3.14k|    do                           \
  |  |  |  |   42|  3.14k|    {                            \
  |  |  |  |   43|  3.14k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 3.14k]
  |  |  |  |  ------------------
  |  |  |  |   44|  3.14k|        goto cleanup;        \
  |  |  |  |   45|  3.14k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1424|  3.14k|        MPI_ECP_MUL(&T[i]->X, &T[i]->X, &t);
  ------------------
  |  | 1167|  3.14k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  3.14k|    do                           \
  |  |  |  |   42|  3.14k|    {                            \
  |  |  |  |   43|  3.14k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 3.14k]
  |  |  |  |  ------------------
  |  |  |  |   44|  3.14k|        goto cleanup;        \
  |  |  |  |   45|  3.14k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1425|  3.14k|        MPI_ECP_MUL(&T[i]->Y, &T[i]->Y, &t);
  ------------------
  |  | 1167|  3.14k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  3.14k|    do                           \
  |  |  |  |   42|  3.14k|    {                            \
  |  |  |  |   43|  3.14k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 3.14k]
  |  |  |  |  ------------------
  |  |  |  |   44|  3.14k|        goto cleanup;        \
  |  |  |  |   45|  3.14k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1426|       |
 1427|       |        /*
 1428|       |         * Post-precessing: reclaim some memory by shrinking coordinates
 1429|       |         * - not storing Z (always 1)
 1430|       |         * - shrinking other coordinates, but still keeping the same number of
 1431|       |         *   limbs as P, as otherwise it will too likely be regrown too fast.
 1432|       |         */
 1433|  3.14k|        MBEDTLS_MPI_CHK(mbedtls_mpi_shrink(&T[i]->X, grp->P.n));
  ------------------
  |  |   41|  3.14k|    do                           \
  |  |   42|  3.14k|    {                            \
  |  |   43|  3.14k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3.14k]
  |  |  ------------------
  |  |   44|  3.14k|        goto cleanup;        \
  |  |   45|  3.14k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1434|  3.14k|        MBEDTLS_MPI_CHK(mbedtls_mpi_shrink(&T[i]->Y, grp->P.n));
  ------------------
  |  |   41|  3.14k|    do                           \
  |  |   42|  3.14k|    {                            \
  |  |   43|  3.14k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3.14k]
  |  |  ------------------
  |  |   44|  3.14k|        goto cleanup;        \
  |  |   45|  3.14k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1435|       |
 1436|  3.14k|        MPI_ECP_LSET(&T[i]->Z, 1);
  ------------------
  |  | 1185|  3.14k|    MBEDTLS_MPI_CHK(mbedtls_mpi_lset(X, c))
  |  |  ------------------
  |  |  |  |   41|  3.14k|    do                           \
  |  |  |  |   42|  3.14k|    {                            \
  |  |  |  |   43|  3.14k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 3.14k]
  |  |  |  |  ------------------
  |  |  |  |   44|  3.14k|        goto cleanup;        \
  |  |  |  |   45|  3.14k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1437|       |
 1438|  3.14k|        if (i == 0) {
  ------------------
  |  Branch (1438:13): [True: 628, False: 2.51k]
  ------------------
 1439|    628|            break;
 1440|    628|        }
 1441|  3.14k|    }
 1442|       |
 1443|    628|cleanup:
 1444|       |
 1445|    628|    mbedtls_mpi_free(&t);
 1446|    628|    mpi_free_many(c, T_size);
 1447|    628|    mbedtls_free(c);
  ------------------
  |  |  143|    628|#define mbedtls_free       MBEDTLS_PLATFORM_FREE_MACRO
  |  |  ------------------
  |  |  |  | 4095|    628|#define MBEDTLS_PLATFORM_FREE_MACRO            my_free
  |  |  ------------------
  ------------------
 1448|       |
 1449|    628|    return ret;
 1450|    628|#endif /* !defined(MBEDTLS_ECP_NO_FALLBACK) || !defined(MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT) */
 1451|    628|}
ecp.c:ecp_mul_comb_after_precomp:
 2174|    628|{
 2175|    628|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|    628|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 2176|    628|    unsigned char parity_trick;
 2177|    628|    unsigned char k[COMB_MAX_D + 1];
 2178|    628|    mbedtls_ecp_point *RR = R;
 2179|       |
 2180|    628|#if defined(MBEDTLS_ECP_RESTARTABLE)
 2181|    628|    if (rs_ctx != NULL && rs_ctx->rsm != NULL) {
  ------------------
  |  Branch (2181:9): [True: 0, False: 628]
  |  Branch (2181:27): [True: 0, False: 0]
  ------------------
 2182|      0|        RR = &rs_ctx->rsm->R;
 2183|       |
 2184|      0|        if (rs_ctx->rsm->state == ecp_rsm_final_norm) {
  ------------------
  |  Branch (2184:13): [True: 0, False: 0]
  ------------------
 2185|      0|            goto final_norm;
 2186|      0|        }
 2187|      0|    }
 2188|    628|#endif
 2189|       |
 2190|    628|    MBEDTLS_MPI_CHK(ecp_comb_recode_scalar(grp, m, k, d, w,
  ------------------
  |  |   41|    628|    do                           \
  |  |   42|    628|    {                            \
  |  |   43|    628|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 628]
  |  |  ------------------
  |  |   44|    628|        goto cleanup;        \
  |  |   45|    628|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2191|    628|                                           &parity_trick));
 2192|    628|    MBEDTLS_MPI_CHK(ecp_mul_comb_core(grp, RR, T, T_size, k, d,
  ------------------
  |  |   41|    628|    do                           \
  |  |   42|    628|    {                            \
  |  |   43|    628|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 628]
  |  |  ------------------
  |  |   44|    628|        goto cleanup;        \
  |  |   45|    628|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2193|    628|                                      f_rng, p_rng, rs_ctx));
 2194|    628|    MBEDTLS_MPI_CHK(ecp_safe_invert_jac(grp, RR, parity_trick));
  ------------------
  |  |   41|    628|    do                           \
  |  |   42|    628|    {                            \
  |  |   43|    628|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 628]
  |  |  ------------------
  |  |   44|    628|        goto cleanup;        \
  |  |   45|    628|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2195|       |
 2196|    628|#if defined(MBEDTLS_ECP_RESTARTABLE)
 2197|    628|    if (rs_ctx != NULL && rs_ctx->rsm != NULL) {
  ------------------
  |  Branch (2197:9): [True: 0, False: 628]
  |  Branch (2197:27): [True: 0, False: 0]
  ------------------
 2198|      0|        rs_ctx->rsm->state = ecp_rsm_final_norm;
 2199|      0|    }
 2200|       |
 2201|    628|final_norm:
 2202|    628|    MBEDTLS_ECP_BUDGET(MBEDTLS_ECP_OPS_INV);
  ------------------
  |  |  408|    628|    MBEDTLS_MPI_CHK(mbedtls_ecp_check_budget(grp, rs_ctx, \
  |  |  ------------------
  |  |  |  |   41|    628|    do                           \
  |  |  |  |   42|    628|    {                            \
  |  |  |  |   43|    628|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 628]
  |  |  |  |  ------------------
  |  |  |  |   44|    628|        goto cleanup;        \
  |  |  |  |   45|    628|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  409|    628|                                             (unsigned) (ops)));
  ------------------
 2203|    628|#endif
 2204|       |    /*
 2205|       |     * Knowledge of the jacobian coordinates may leak the last few bits of the
 2206|       |     * scalar [1], and since our MPI implementation isn't constant-flow,
 2207|       |     * inversion (used for coordinate normalization) may leak the full value
 2208|       |     * of its input via side-channels [2].
 2209|       |     *
 2210|       |     * [1] https://eprint.iacr.org/2003/191
 2211|       |     * [2] https://eprint.iacr.org/2020/055
 2212|       |     *
 2213|       |     * Avoid the leak by randomizing coordinates before we normalize them.
 2214|       |     */
 2215|    628|    if (f_rng != 0) {
  ------------------
  |  Branch (2215:9): [True: 0, False: 628]
  ------------------
 2216|      0|        MBEDTLS_MPI_CHK(ecp_randomize_jac(grp, RR, f_rng, p_rng));
  ------------------
  |  |   41|      0|    do                           \
  |  |   42|      0|    {                            \
  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  ------------------
  |  |   44|      0|        goto cleanup;        \
  |  |   45|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2217|      0|    }
 2218|       |
 2219|    628|    MBEDTLS_MPI_CHK(ecp_normalize_jac(grp, RR));
  ------------------
  |  |   41|    628|    do                           \
  |  |   42|    628|    {                            \
  |  |   43|    628|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 628]
  |  |  ------------------
  |  |   44|    628|        goto cleanup;        \
  |  |   45|    628|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2220|       |
 2221|    628|#if defined(MBEDTLS_ECP_RESTARTABLE)
 2222|    628|    if (rs_ctx != NULL && rs_ctx->rsm != NULL) {
  ------------------
  |  Branch (2222:9): [True: 0, False: 628]
  |  Branch (2222:27): [True: 0, False: 0]
  ------------------
 2223|      0|        MBEDTLS_MPI_CHK(mbedtls_ecp_copy(R, RR));
  ------------------
  |  |   41|      0|    do                           \
  |  |   42|      0|    {                            \
  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  ------------------
  |  |   44|      0|        goto cleanup;        \
  |  |   45|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2224|      0|    }
 2225|    628|#endif
 2226|       |
 2227|    628|cleanup:
 2228|    628|    return ret;
 2229|    628|}
ecp.c:ecp_comb_recode_scalar:
 2127|    628|{
 2128|    628|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|    628|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 2129|    628|    mbedtls_mpi M, mm;
 2130|       |
 2131|    628|    mbedtls_mpi_init(&M);
 2132|    628|    mbedtls_mpi_init(&mm);
 2133|       |
 2134|       |    /* N is always odd (see above), just make extra sure */
 2135|    628|    if (mbedtls_mpi_get_bit(&grp->N, 0) != 1) {
  ------------------
  |  Branch (2135:9): [True: 0, False: 628]
  ------------------
 2136|      0|        return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
 2137|      0|    }
 2138|       |
 2139|       |    /* do we need the parity trick? */
 2140|    628|    *parity_trick = (mbedtls_mpi_get_bit(m, 0) == 0);
 2141|       |
 2142|       |    /* execute parity fix in constant time */
 2143|    628|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&M, m));
  ------------------
  |  |   41|    628|    do                           \
  |  |   42|    628|    {                            \
  |  |   43|    628|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 628]
  |  |  ------------------
  |  |   44|    628|        goto cleanup;        \
  |  |   45|    628|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2144|    628|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&mm, &grp->N, m));
  ------------------
  |  |   41|    628|    do                           \
  |  |   42|    628|    {                            \
  |  |   43|    628|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 628]
  |  |  ------------------
  |  |   44|    628|        goto cleanup;        \
  |  |   45|    628|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2145|    628|    MBEDTLS_MPI_CHK(mbedtls_mpi_safe_cond_assign(&M, &mm, *parity_trick));
  ------------------
  |  |   41|    628|    do                           \
  |  |   42|    628|    {                            \
  |  |   43|    628|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 628]
  |  |  ------------------
  |  |   44|    628|        goto cleanup;        \
  |  |   45|    628|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2146|       |
 2147|       |    /* actual scalar recoding */
 2148|    628|    ecp_comb_recode_core(k, d, w, &M);
 2149|       |
 2150|    628|cleanup:
 2151|    628|    mbedtls_mpi_free(&mm);
 2152|    628|    mbedtls_mpi_free(&M);
 2153|       |
 2154|    628|    return ret;
 2155|    628|}
ecp.c:ecp_comb_recode_core:
 1786|    628|{
 1787|    628|    size_t i, j;
 1788|    628|    unsigned char c, cc, adjust;
 1789|       |
 1790|    628|    memset(x, 0, d+1);
 1791|       |
 1792|       |    /* First get the classical comb values (except for x_d = 0) */
 1793|  37.0k|    for (i = 0; i < d; i++) {
  ------------------
  |  Branch (1793:17): [True: 36.4k, False: 628]
  ------------------
 1794|   198k|        for (j = 0; j < w; j++) {
  ------------------
  |  Branch (1794:21): [True: 162k, False: 36.4k]
  ------------------
 1795|   162k|            x[i] |= mbedtls_mpi_get_bit(m, i + d * j) << j;
 1796|   162k|        }
 1797|  36.4k|    }
 1798|       |
 1799|       |    /* Now make sure x_1 .. x_d are odd */
 1800|    628|    c = 0;
 1801|  37.0k|    for (i = 1; i <= d; i++) {
  ------------------
  |  Branch (1801:17): [True: 36.4k, False: 628]
  ------------------
 1802|       |        /* Add carry and update it */
 1803|  36.4k|        cc   = x[i] & c;
 1804|  36.4k|        x[i] = x[i] ^ c;
 1805|  36.4k|        c = cc;
 1806|       |
 1807|       |        /* Adjust if needed, avoiding branches */
 1808|  36.4k|        adjust = 1 - (x[i] & 0x01);
 1809|  36.4k|        c   |= x[i] & (x[i-1] * adjust);
 1810|  36.4k|        x[i] = x[i] ^ (x[i-1] * adjust);
 1811|  36.4k|        x[i-1] |= adjust << 7;
 1812|  36.4k|    }
 1813|    628|}
ecp.c:ecp_mul_comb_core:
 2049|    628|{
 2050|    628|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|    628|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 2051|    628|    mbedtls_ecp_point Txi;
 2052|    628|    mbedtls_mpi tmp[4];
 2053|    628|    size_t i;
 2054|       |
 2055|    628|    mbedtls_ecp_point_init(&Txi);
 2056|    628|    mpi_init_many(tmp, sizeof(tmp) / sizeof(mbedtls_mpi));
 2057|       |
 2058|       |#if !defined(MBEDTLS_ECP_RESTARTABLE)
 2059|       |    (void) rs_ctx;
 2060|       |#endif
 2061|       |
 2062|    628|#if defined(MBEDTLS_ECP_RESTARTABLE)
 2063|    628|    if (rs_ctx != NULL && rs_ctx->rsm != NULL &&
  ------------------
  |  Branch (2063:9): [True: 0, False: 628]
  |  Branch (2063:27): [True: 0, False: 0]
  ------------------
 2064|    628|        rs_ctx->rsm->state != ecp_rsm_comb_core) {
  ------------------
  |  Branch (2064:9): [True: 0, False: 0]
  ------------------
 2065|      0|        rs_ctx->rsm->i = 0;
 2066|      0|        rs_ctx->rsm->state = ecp_rsm_comb_core;
 2067|      0|    }
 2068|       |
 2069|       |    /* new 'if' instead of nested for the sake of the 'else' branch */
 2070|    628|    if (rs_ctx != NULL && rs_ctx->rsm != NULL && rs_ctx->rsm->i != 0) {
  ------------------
  |  Branch (2070:9): [True: 0, False: 628]
  |  Branch (2070:27): [True: 0, False: 0]
  |  Branch (2070:50): [True: 0, False: 0]
  ------------------
 2071|       |        /* restore current index (R already pointing to rs_ctx->rsm->R) */
 2072|      0|        i = rs_ctx->rsm->i;
 2073|      0|    } else
 2074|    628|#endif
 2075|    628|    {
 2076|       |        /* Start with a non-zero point and randomize its coordinates */
 2077|    628|        i = d;
 2078|    628|        MBEDTLS_MPI_CHK(ecp_select_comb(grp, R, T, T_size, x[i]));
  ------------------
  |  |   41|    628|    do                           \
  |  |   42|    628|    {                            \
  |  |   43|    628|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 628]
  |  |  ------------------
  |  |   44|    628|        goto cleanup;        \
  |  |   45|    628|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2079|    628|        if (f_rng != 0) {
  ------------------
  |  Branch (2079:13): [True: 0, False: 628]
  ------------------
 2080|      0|            MBEDTLS_MPI_CHK(ecp_randomize_jac(grp, R, f_rng, p_rng));
  ------------------
  |  |   41|      0|    do                           \
  |  |   42|      0|    {                            \
  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  ------------------
  |  |   44|      0|        goto cleanup;        \
  |  |   45|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2081|      0|        }
 2082|    628|    }
 2083|       |
 2084|  37.0k|    while (i != 0) {
  ------------------
  |  Branch (2084:12): [True: 36.4k, False: 628]
  ------------------
 2085|  36.4k|        MBEDTLS_ECP_BUDGET(MBEDTLS_ECP_OPS_DBL + MBEDTLS_ECP_OPS_ADD);
  ------------------
  |  |  408|  36.4k|    MBEDTLS_MPI_CHK(mbedtls_ecp_check_budget(grp, rs_ctx, \
  |  |  ------------------
  |  |  |  |   41|  36.4k|    do                           \
  |  |  |  |   42|  36.4k|    {                            \
  |  |  |  |   43|  36.4k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 36.4k]
  |  |  |  |  ------------------
  |  |  |  |   44|  36.4k|        goto cleanup;        \
  |  |  |  |   45|  36.4k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  409|  36.4k|                                             (unsigned) (ops)));
  ------------------
 2086|  36.4k|        --i;
 2087|       |
 2088|  36.4k|        MBEDTLS_MPI_CHK(ecp_double_jac(grp, R, R, tmp));
  ------------------
  |  |   41|  36.4k|    do                           \
  |  |   42|  36.4k|    {                            \
  |  |   43|  36.4k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 36.4k]
  |  |  ------------------
  |  |   44|  36.4k|        goto cleanup;        \
  |  |   45|  36.4k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2089|  36.4k|        MBEDTLS_MPI_CHK(ecp_select_comb(grp, &Txi, T, T_size, x[i]));
  ------------------
  |  |   41|  36.4k|    do                           \
  |  |   42|  36.4k|    {                            \
  |  |   43|  36.4k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 36.4k]
  |  |  ------------------
  |  |   44|  36.4k|        goto cleanup;        \
  |  |   45|  36.4k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2090|  36.4k|        MBEDTLS_MPI_CHK(ecp_add_mixed(grp, R, R, &Txi, tmp));
  ------------------
  |  |   41|  36.4k|    do                           \
  |  |   42|  36.4k|    {                            \
  |  |   43|  36.4k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 36.4k]
  |  |  ------------------
  |  |   44|  36.4k|        goto cleanup;        \
  |  |   45|  36.4k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2091|  36.4k|    }
 2092|       |
 2093|    628|cleanup:
 2094|       |
 2095|    628|    mbedtls_ecp_point_free(&Txi);
 2096|    628|    mpi_free_many(tmp, sizeof(tmp) / sizeof(mbedtls_mpi));
 2097|       |
 2098|    628|#if defined(MBEDTLS_ECP_RESTARTABLE)
 2099|    628|    if (rs_ctx != NULL && rs_ctx->rsm != NULL &&
  ------------------
  |  Branch (2099:9): [True: 0, False: 628]
  |  Branch (2099:27): [True: 0, False: 0]
  ------------------
 2100|    628|        ret == MBEDTLS_ERR_ECP_IN_PROGRESS) {
  ------------------
  |  |   51|      0|#define MBEDTLS_ERR_ECP_IN_PROGRESS                       -0x4B00
  ------------------
  |  Branch (2100:9): [True: 0, False: 0]
  ------------------
 2101|      0|        rs_ctx->rsm->i = i;
 2102|       |        /* no need to save R, already pointing to rs_ctx->rsm->R */
 2103|      0|    }
 2104|    628|#endif
 2105|       |
 2106|    628|    return ret;
 2107|    628|}
ecp.c:ecp_select_comb:
 2015|  37.0k|{
 2016|  37.0k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  37.0k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 2017|  37.0k|    unsigned char ii, j;
 2018|       |
 2019|       |    /* Ignore the "sign" bit and scale down */
 2020|  37.0k|    ii =  (i & 0x7Fu) >> 1;
 2021|       |
 2022|       |    /* Read the whole table to thwart cache-based timing attacks */
 2023|   466k|    for (j = 0; j < T_size; j++) {
  ------------------
  |  Branch (2023:17): [True: 429k, False: 37.0k]
  ------------------
 2024|   429k|        MPI_ECP_COND_ASSIGN(&R->X, &T[j].X, j == ii);
  ------------------
  |  | 1214|   429k|    MBEDTLS_MPI_CHK(mbedtls_mpi_safe_cond_assign((X), (Y), (cond)))
  |  |  ------------------
  |  |  |  |   41|   429k|    do                           \
  |  |  |  |   42|   429k|    {                            \
  |  |  |  |   43|   429k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 429k]
  |  |  |  |  ------------------
  |  |  |  |   44|   429k|        goto cleanup;        \
  |  |  |  |   45|   429k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2025|   429k|        MPI_ECP_COND_ASSIGN(&R->Y, &T[j].Y, j == ii);
  ------------------
  |  | 1214|   429k|    MBEDTLS_MPI_CHK(mbedtls_mpi_safe_cond_assign((X), (Y), (cond)))
  |  |  ------------------
  |  |  |  |   41|   429k|    do                           \
  |  |  |  |   42|   429k|    {                            \
  |  |  |  |   43|   429k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 429k]
  |  |  |  |  ------------------
  |  |  |  |   44|   429k|        goto cleanup;        \
  |  |  |  |   45|   429k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2026|   429k|    }
 2027|       |
 2028|       |    /* Safely invert result if i is "negative" */
 2029|  37.0k|    MBEDTLS_MPI_CHK(ecp_safe_invert_jac(grp, R, i >> 7));
  ------------------
  |  |   41|  37.0k|    do                           \
  |  |   42|  37.0k|    {                            \
  |  |   43|  37.0k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 37.0k]
  |  |  ------------------
  |  |   44|  37.0k|        goto cleanup;        \
  |  |   45|  37.0k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2030|       |
 2031|  37.0k|    MPI_ECP_LSET(&R->Z, 1);
  ------------------
  |  | 1185|  37.0k|    MBEDTLS_MPI_CHK(mbedtls_mpi_lset(X, c))
  |  |  ------------------
  |  |  |  |   41|  37.0k|    do                           \
  |  |  |  |   42|  37.0k|    {                            \
  |  |  |  |   43|  37.0k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 37.0k]
  |  |  |  |  ------------------
  |  |  |  |   44|  37.0k|        goto cleanup;        \
  |  |  |  |   45|  37.0k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2032|       |
 2033|  37.0k|cleanup:
 2034|  37.0k|    return ret;
 2035|  37.0k|}
ecp.c:ecp_safe_invert_jac:
 1460|  37.6k|{
 1461|  37.6k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  37.6k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1462|  37.6k|    mbedtls_mpi tmp;
 1463|  37.6k|    mbedtls_mpi_init(&tmp);
 1464|       |
 1465|  37.6k|    MPI_ECP_COND_NEG(&Q->Y, inv);
  ------------------
  |  | 1200|  37.6k|    do                                                                     \
  |  | 1201|  37.6k|    {                                                                      \
  |  | 1202|  37.6k|        unsigned char nonzero = mbedtls_mpi_cmp_int((X), 0) != 0;        \
  |  | 1203|  37.6k|        MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&tmp, &grp->P, (X)));      \
  |  |  ------------------
  |  |  |  |   41|  37.6k|    do                           \
  |  |  |  |   42|  37.6k|    {                            \
  |  |  |  |   43|  37.6k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 37.6k]
  |  |  |  |  ------------------
  |  |  |  |   44|  37.6k|        goto cleanup;        \
  |  |  |  |   45|  37.6k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 1204|  37.6k|        MBEDTLS_MPI_CHK(mbedtls_mpi_safe_cond_assign((X), &tmp,          \
  |  |  ------------------
  |  |  |  |   41|  37.6k|    do                           \
  |  |  |  |   42|  37.6k|    {                            \
  |  |  |  |   43|  37.6k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 37.6k]
  |  |  |  |  ------------------
  |  |  |  |   44|  37.6k|        goto cleanup;        \
  |  |  |  |   45|  37.6k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 1205|  37.6k|                                                     nonzero & cond)); \
  |  | 1206|  37.6k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (1206:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1466|       |
 1467|  37.6k|cleanup:
 1468|  37.6k|    mbedtls_mpi_free(&tmp);
 1469|  37.6k|    return ret;
 1470|  37.6k|}
ecp.c:mpi_init_many:
  318|  1.88k|{
  319|  10.0k|    while (size--) {
  ------------------
  |  Branch (319:12): [True: 8.16k, False: 1.88k]
  ------------------
  320|  8.16k|        mbedtls_mpi_init(arr++);
  321|  8.16k|    }
  322|  1.88k|}
ecp.c:mbedtls_ecp_mul_shortcuts:
 2770|    628|{
 2771|    628|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|    628|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 2772|    628|    mbedtls_mpi tmp;
 2773|    628|    mbedtls_mpi_init(&tmp);
 2774|       |
 2775|    628|    if (mbedtls_mpi_cmp_int(m, 0) == 0) {
  ------------------
  |  Branch (2775:9): [True: 0, False: 628]
  ------------------
 2776|      0|        MBEDTLS_MPI_CHK(mbedtls_ecp_check_pubkey(grp, P));
  ------------------
  |  |   41|      0|    do                           \
  |  |   42|      0|    {                            \
  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  ------------------
  |  |   44|      0|        goto cleanup;        \
  |  |   45|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2777|      0|        MBEDTLS_MPI_CHK(mbedtls_ecp_set_zero(R));
  ------------------
  |  |   41|      0|    do                           \
  |  |   42|      0|    {                            \
  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  ------------------
  |  |   44|      0|        goto cleanup;        \
  |  |   45|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2778|    628|    } else if (mbedtls_mpi_cmp_int(m, 1) == 0) {
  ------------------
  |  Branch (2778:16): [True: 0, False: 628]
  ------------------
 2779|      0|        MBEDTLS_MPI_CHK(mbedtls_ecp_check_pubkey(grp, P));
  ------------------
  |  |   41|      0|    do                           \
  |  |   42|      0|    {                            \
  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  ------------------
  |  |   44|      0|        goto cleanup;        \
  |  |   45|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2780|      0|        MBEDTLS_MPI_CHK(mbedtls_ecp_copy(R, P));
  ------------------
  |  |   41|      0|    do                           \
  |  |   42|      0|    {                            \
  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  ------------------
  |  |   44|      0|        goto cleanup;        \
  |  |   45|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2781|    628|    } else if (mbedtls_mpi_cmp_int(m, -1) == 0) {
  ------------------
  |  Branch (2781:16): [True: 0, False: 628]
  ------------------
 2782|      0|        MBEDTLS_MPI_CHK(mbedtls_ecp_check_pubkey(grp, P));
  ------------------
  |  |   41|      0|    do                           \
  |  |   42|      0|    {                            \
  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  ------------------
  |  |   44|      0|        goto cleanup;        \
  |  |   45|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2783|      0|        MBEDTLS_MPI_CHK(mbedtls_ecp_copy(R, P));
  ------------------
  |  |   41|      0|    do                           \
  |  |   42|      0|    {                            \
  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  ------------------
  |  |   44|      0|        goto cleanup;        \
  |  |   45|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2784|      0|        MPI_ECP_NEG(&R->Y);
  ------------------
  |  | 1208|      0|#define MPI_ECP_NEG(X) MPI_ECP_COND_NEG((X), 1)
  |  |  ------------------
  |  |  |  | 1200|      0|    do                                                                     \
  |  |  |  | 1201|      0|    {                                                                      \
  |  |  |  | 1202|      0|        unsigned char nonzero = mbedtls_mpi_cmp_int((X), 0) != 0;        \
  |  |  |  | 1203|      0|        MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&tmp, &grp->P, (X)));      \
  |  |  |  |  ------------------
  |  |  |  |  |  |   41|      0|    do                           \
  |  |  |  |  |  |   42|      0|    {                            \
  |  |  |  |  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|        goto cleanup;        \
  |  |  |  |  |  |   45|      0|    } while (0)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  | 1204|      0|        MBEDTLS_MPI_CHK(mbedtls_mpi_safe_cond_assign((X), &tmp,          \
  |  |  |  |  ------------------
  |  |  |  |  |  |   41|      0|    do                           \
  |  |  |  |  |  |   42|      0|    {                            \
  |  |  |  |  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|        goto cleanup;        \
  |  |  |  |  |  |   45|      0|    } while (0)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  | 1205|      0|                                                     nonzero & cond)); \
  |  |  |  | 1206|      0|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1206:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2785|    628|    } else {
 2786|    628|        MBEDTLS_MPI_CHK(ecp_mul_restartable_internal(grp, R, m, P,
  ------------------
  |  |   41|    628|    do                           \
  |  |   42|    628|    {                            \
  |  |   43|    628|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 628]
  |  |  ------------------
  |  |   44|    628|        goto cleanup;        \
  |  |   45|    628|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2787|    628|                                                     NULL, NULL, rs_ctx));
 2788|    628|    }
 2789|       |
 2790|    628|cleanup:
 2791|    628|    mbedtls_mpi_free(&tmp);
 2792|       |
 2793|    628|    return ret;
 2794|    628|}
ecp.c:ecp_add_mixed:
 1586|  38.9k|{
 1587|  38.9k|#if defined(MBEDTLS_SELF_TEST)
 1588|  38.9k|    add_count++;
 1589|  38.9k|#endif
 1590|       |
 1591|       |#if defined(MBEDTLS_ECP_ADD_MIXED_ALT)
 1592|       |    if (mbedtls_internal_ecp_grp_capable(grp)) {
 1593|       |        return mbedtls_internal_ecp_add_mixed(grp, R, P, Q);
 1594|       |    }
 1595|       |#endif /* MBEDTLS_ECP_ADD_MIXED_ALT */
 1596|       |
 1597|       |#if defined(MBEDTLS_ECP_NO_FALLBACK) && defined(MBEDTLS_ECP_ADD_MIXED_ALT)
 1598|       |    return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
 1599|       |#else
 1600|  38.9k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  38.9k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1601|       |
 1602|       |    /* NOTE: Aliasing between input and output is allowed, so one has to make
 1603|       |     *       sure that at the point X,Y,Z are written, {P,Q}->{X,Y,Z} are no
 1604|       |     *       longer read from. */
 1605|  38.9k|    mbedtls_mpi * const X = &R->X;
 1606|  38.9k|    mbedtls_mpi * const Y = &R->Y;
 1607|  38.9k|    mbedtls_mpi * const Z = &R->Z;
 1608|       |
 1609|  38.9k|    if (!MPI_ECP_VALID(&Q->Z)) {
  ------------------
  |  | 1211|  38.9k|    ((X)->p != NULL)
  ------------------
  |  Branch (1609:9): [True: 0, False: 38.9k]
  ------------------
 1610|      0|        return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
 1611|      0|    }
 1612|       |
 1613|       |    /*
 1614|       |     * Trivial cases: P == 0 or Q == 0 (case 1)
 1615|       |     */
 1616|  38.9k|    if (MPI_ECP_CMP_INT(&P->Z, 0) == 0) {
  ------------------
  |  | 1188|  38.9k|    mbedtls_mpi_cmp_int(X, c)
  ------------------
  |  Branch (1616:9): [True: 0, False: 38.9k]
  ------------------
 1617|      0|        return mbedtls_ecp_copy(R, Q);
 1618|      0|    }
 1619|       |
 1620|  38.9k|    if (MPI_ECP_CMP_INT(&Q->Z, 0) == 0) {
  ------------------
  |  | 1188|  38.9k|    mbedtls_mpi_cmp_int(X, c)
  ------------------
  |  Branch (1620:9): [True: 0, False: 38.9k]
  ------------------
 1621|      0|        return mbedtls_ecp_copy(R, P);
 1622|      0|    }
 1623|       |
 1624|       |    /*
 1625|       |     * Make sure Q coordinates are normalized
 1626|       |     */
 1627|  38.9k|    if (MPI_ECP_CMP_INT(&Q->Z, 1) != 0) {
  ------------------
  |  | 1188|  38.9k|    mbedtls_mpi_cmp_int(X, c)
  ------------------
  |  Branch (1627:9): [True: 0, False: 38.9k]
  ------------------
 1628|      0|        return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
 1629|      0|    }
 1630|       |
 1631|  38.9k|    MPI_ECP_SQR(&tmp[0], &P->Z);
  ------------------
  |  | 1170|  38.9k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, A))
  |  |  ------------------
  |  |  |  |   41|  38.9k|    do                           \
  |  |  |  |   42|  38.9k|    {                            \
  |  |  |  |   43|  38.9k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 38.9k]
  |  |  |  |  ------------------
  |  |  |  |   44|  38.9k|        goto cleanup;        \
  |  |  |  |   45|  38.9k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1632|  38.9k|    MPI_ECP_MUL(&tmp[1], &tmp[0], &P->Z);
  ------------------
  |  | 1167|  38.9k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  38.9k|    do                           \
  |  |  |  |   42|  38.9k|    {                            \
  |  |  |  |   43|  38.9k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 38.9k]
  |  |  |  |  ------------------
  |  |  |  |   44|  38.9k|        goto cleanup;        \
  |  |  |  |   45|  38.9k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1633|  38.9k|    MPI_ECP_MUL(&tmp[0], &tmp[0], &Q->X);
  ------------------
  |  | 1167|  38.9k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  38.9k|    do                           \
  |  |  |  |   42|  38.9k|    {                            \
  |  |  |  |   43|  38.9k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 38.9k]
  |  |  |  |  ------------------
  |  |  |  |   44|  38.9k|        goto cleanup;        \
  |  |  |  |   45|  38.9k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1634|  38.9k|    MPI_ECP_MUL(&tmp[1], &tmp[1], &Q->Y);
  ------------------
  |  | 1167|  38.9k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  38.9k|    do                           \
  |  |  |  |   42|  38.9k|    {                            \
  |  |  |  |   43|  38.9k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 38.9k]
  |  |  |  |  ------------------
  |  |  |  |   44|  38.9k|        goto cleanup;        \
  |  |  |  |   45|  38.9k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1635|  38.9k|    MPI_ECP_SUB(&tmp[0], &tmp[0], &P->X);
  ------------------
  |  | 1164|  38.9k|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  38.9k|    do                           \
  |  |  |  |   42|  38.9k|    {                            \
  |  |  |  |   43|  38.9k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 38.9k]
  |  |  |  |  ------------------
  |  |  |  |   44|  38.9k|        goto cleanup;        \
  |  |  |  |   45|  38.9k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1636|  38.9k|    MPI_ECP_SUB(&tmp[1], &tmp[1], &P->Y);
  ------------------
  |  | 1164|  38.9k|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  38.9k|    do                           \
  |  |  |  |   42|  38.9k|    {                            \
  |  |  |  |   43|  38.9k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 38.9k]
  |  |  |  |  ------------------
  |  |  |  |   44|  38.9k|        goto cleanup;        \
  |  |  |  |   45|  38.9k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1637|       |
 1638|       |    /* Special cases (2) and (3) */
 1639|  38.9k|    if (MPI_ECP_CMP_INT(&tmp[0], 0) == 0) {
  ------------------
  |  | 1188|  38.9k|    mbedtls_mpi_cmp_int(X, c)
  ------------------
  |  Branch (1639:9): [True: 0, False: 38.9k]
  ------------------
 1640|      0|        if (MPI_ECP_CMP_INT(&tmp[1], 0) == 0) {
  ------------------
  |  | 1188|      0|    mbedtls_mpi_cmp_int(X, c)
  ------------------
  |  Branch (1640:13): [True: 0, False: 0]
  ------------------
 1641|      0|            ret = ecp_double_jac(grp, R, P, tmp);
 1642|      0|            goto cleanup;
 1643|      0|        } else {
 1644|      0|            ret = mbedtls_ecp_set_zero(R);
 1645|      0|            goto cleanup;
 1646|      0|        }
 1647|      0|    }
 1648|       |
 1649|       |    /* {P,Q}->Z no longer used, so OK to write to Z even if there's aliasing. */
 1650|  38.9k|    MPI_ECP_MUL(Z,        &P->Z,    &tmp[0]);
  ------------------
  |  | 1167|  38.9k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  38.9k|    do                           \
  |  |  |  |   42|  38.9k|    {                            \
  |  |  |  |   43|  38.9k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 38.9k]
  |  |  |  |  ------------------
  |  |  |  |   44|  38.9k|        goto cleanup;        \
  |  |  |  |   45|  38.9k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1651|  38.9k|    MPI_ECP_SQR(&tmp[2],  &tmp[0]);
  ------------------
  |  | 1170|  38.9k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, A))
  |  |  ------------------
  |  |  |  |   41|  38.9k|    do                           \
  |  |  |  |   42|  38.9k|    {                            \
  |  |  |  |   43|  38.9k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 38.9k]
  |  |  |  |  ------------------
  |  |  |  |   44|  38.9k|        goto cleanup;        \
  |  |  |  |   45|  38.9k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1652|  38.9k|    MPI_ECP_MUL(&tmp[3],  &tmp[2],  &tmp[0]);
  ------------------
  |  | 1167|  38.9k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  38.9k|    do                           \
  |  |  |  |   42|  38.9k|    {                            \
  |  |  |  |   43|  38.9k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 38.9k]
  |  |  |  |  ------------------
  |  |  |  |   44|  38.9k|        goto cleanup;        \
  |  |  |  |   45|  38.9k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1653|  38.9k|    MPI_ECP_MUL(&tmp[2],  &tmp[2],  &P->X);
  ------------------
  |  | 1167|  38.9k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  38.9k|    do                           \
  |  |  |  |   42|  38.9k|    {                            \
  |  |  |  |   43|  38.9k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 38.9k]
  |  |  |  |  ------------------
  |  |  |  |   44|  38.9k|        goto cleanup;        \
  |  |  |  |   45|  38.9k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1654|       |
 1655|  38.9k|    MPI_ECP_MOV(&tmp[0], &tmp[2]);
  ------------------
  |  | 1179|  38.9k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(X, A))
  |  |  ------------------
  |  |  |  |   41|  38.9k|    do                           \
  |  |  |  |   42|  38.9k|    {                            \
  |  |  |  |   43|  38.9k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 38.9k]
  |  |  |  |  ------------------
  |  |  |  |   44|  38.9k|        goto cleanup;        \
  |  |  |  |   45|  38.9k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1656|  38.9k|    MPI_ECP_SHIFT_L(&tmp[0], 1);
  ------------------
  |  | 1182|  38.9k|    MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l_mod(grp, X, count))
  |  |  ------------------
  |  |  |  |   41|  38.9k|    do                           \
  |  |  |  |   42|  38.9k|    {                            \
  |  |  |  |   43|  38.9k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 38.9k]
  |  |  |  |  ------------------
  |  |  |  |   44|  38.9k|        goto cleanup;        \
  |  |  |  |   45|  38.9k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1657|       |
 1658|       |    /* {P,Q}->X no longer used, so OK to write to X even if there's aliasing. */
 1659|  38.9k|    MPI_ECP_SQR(X,        &tmp[1]);
  ------------------
  |  | 1170|  38.9k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, A))
  |  |  ------------------
  |  |  |  |   41|  38.9k|    do                           \
  |  |  |  |   42|  38.9k|    {                            \
  |  |  |  |   43|  38.9k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 38.9k]
  |  |  |  |  ------------------
  |  |  |  |   44|  38.9k|        goto cleanup;        \
  |  |  |  |   45|  38.9k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1660|  38.9k|    MPI_ECP_SUB(X,        X,        &tmp[0]);
  ------------------
  |  | 1164|  38.9k|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  38.9k|    do                           \
  |  |  |  |   42|  38.9k|    {                            \
  |  |  |  |   43|  38.9k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 38.9k]
  |  |  |  |  ------------------
  |  |  |  |   44|  38.9k|        goto cleanup;        \
  |  |  |  |   45|  38.9k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1661|  38.9k|    MPI_ECP_SUB(X,        X,        &tmp[3]);
  ------------------
  |  | 1164|  38.9k|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  38.9k|    do                           \
  |  |  |  |   42|  38.9k|    {                            \
  |  |  |  |   43|  38.9k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 38.9k]
  |  |  |  |  ------------------
  |  |  |  |   44|  38.9k|        goto cleanup;        \
  |  |  |  |   45|  38.9k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1662|  38.9k|    MPI_ECP_SUB(&tmp[2],  &tmp[2],  X);
  ------------------
  |  | 1164|  38.9k|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  38.9k|    do                           \
  |  |  |  |   42|  38.9k|    {                            \
  |  |  |  |   43|  38.9k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 38.9k]
  |  |  |  |  ------------------
  |  |  |  |   44|  38.9k|        goto cleanup;        \
  |  |  |  |   45|  38.9k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1663|  38.9k|    MPI_ECP_MUL(&tmp[2],  &tmp[2],  &tmp[1]);
  ------------------
  |  | 1167|  38.9k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  38.9k|    do                           \
  |  |  |  |   42|  38.9k|    {                            \
  |  |  |  |   43|  38.9k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 38.9k]
  |  |  |  |  ------------------
  |  |  |  |   44|  38.9k|        goto cleanup;        \
  |  |  |  |   45|  38.9k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1664|  38.9k|    MPI_ECP_MUL(&tmp[3],  &tmp[3],  &P->Y);
  ------------------
  |  | 1167|  38.9k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  38.9k|    do                           \
  |  |  |  |   42|  38.9k|    {                            \
  |  |  |  |   43|  38.9k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 38.9k]
  |  |  |  |  ------------------
  |  |  |  |   44|  38.9k|        goto cleanup;        \
  |  |  |  |   45|  38.9k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1665|       |    /* {P,Q}->Y no longer used, so OK to write to Y even if there's aliasing. */
 1666|  38.9k|    MPI_ECP_SUB(Y,     &tmp[2],     &tmp[3]);
  ------------------
  |  | 1164|  38.9k|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  38.9k|    do                           \
  |  |  |  |   42|  38.9k|    {                            \
  |  |  |  |   43|  38.9k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 38.9k]
  |  |  |  |  ------------------
  |  |  |  |   44|  38.9k|        goto cleanup;        \
  |  |  |  |   45|  38.9k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1667|       |
 1668|  38.9k|cleanup:
 1669|       |
 1670|  38.9k|    return ret;
 1671|  38.9k|#endif /* !defined(MBEDTLS_ECP_NO_FALLBACK) || !defined(MBEDTLS_ECP_ADD_MIXED_ALT) */
 1672|  38.9k|}
ecp.c:ecp_normalize_jac:
 1315|    942|{
 1316|    942|    if (MPI_ECP_CMP_INT(&pt->Z, 0) == 0) {
  ------------------
  |  | 1188|    942|    mbedtls_mpi_cmp_int(X, c)
  ------------------
  |  Branch (1316:9): [True: 0, False: 942]
  ------------------
 1317|      0|        return 0;
 1318|      0|    }
 1319|       |
 1320|       |#if defined(MBEDTLS_ECP_NORMALIZE_JAC_ALT)
 1321|       |    if (mbedtls_internal_ecp_grp_capable(grp)) {
 1322|       |        return mbedtls_internal_ecp_normalize_jac(grp, pt);
 1323|       |    }
 1324|       |#endif /* MBEDTLS_ECP_NORMALIZE_JAC_ALT */
 1325|       |
 1326|       |#if defined(MBEDTLS_ECP_NO_FALLBACK) && defined(MBEDTLS_ECP_NORMALIZE_JAC_ALT)
 1327|       |    return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
 1328|       |#else
 1329|    942|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|    942|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1330|    942|    mbedtls_mpi T;
 1331|    942|    mbedtls_mpi_init(&T);
 1332|       |
 1333|    942|    MPI_ECP_INV(&T,       &pt->Z);            /* T   <-          1 / Z   */
  ------------------
  |  | 1176|    942|    MBEDTLS_MPI_CHK(mbedtls_mpi_inv_mod((dst), (src), &grp->P))
  |  |  ------------------
  |  |  |  |   41|    942|    do                           \
  |  |  |  |   42|    942|    {                            \
  |  |  |  |   43|    942|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 942]
  |  |  |  |  ------------------
  |  |  |  |   44|    942|        goto cleanup;        \
  |  |  |  |   45|    942|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1334|    942|    MPI_ECP_MUL(&pt->Y,   &pt->Y,     &T);    /* Y'  <- Y*T    = Y / Z   */
  ------------------
  |  | 1167|    942|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|    942|    do                           \
  |  |  |  |   42|    942|    {                            \
  |  |  |  |   43|    942|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 942]
  |  |  |  |  ------------------
  |  |  |  |   44|    942|        goto cleanup;        \
  |  |  |  |   45|    942|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1335|    942|    MPI_ECP_SQR(&T,       &T);                /* T   <- T^2    = 1 / Z^2 */
  ------------------
  |  | 1170|    942|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, A))
  |  |  ------------------
  |  |  |  |   41|    942|    do                           \
  |  |  |  |   42|    942|    {                            \
  |  |  |  |   43|    942|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 942]
  |  |  |  |  ------------------
  |  |  |  |   44|    942|        goto cleanup;        \
  |  |  |  |   45|    942|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1336|    942|    MPI_ECP_MUL(&pt->X,   &pt->X,     &T);    /* X   <- X  * T = X / Z^2 */
  ------------------
  |  | 1167|    942|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|    942|    do                           \
  |  |  |  |   42|    942|    {                            \
  |  |  |  |   43|    942|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 942]
  |  |  |  |  ------------------
  |  |  |  |   44|    942|        goto cleanup;        \
  |  |  |  |   45|    942|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1337|    942|    MPI_ECP_MUL(&pt->Y,   &pt->Y,     &T);    /* Y'' <- Y' * T = Y / Z^3 */
  ------------------
  |  | 1167|    942|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|    942|    do                           \
  |  |  |  |   42|    942|    {                            \
  |  |  |  |   43|    942|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 942]
  |  |  |  |  ------------------
  |  |  |  |   44|    942|        goto cleanup;        \
  |  |  |  |   45|    942|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1338|       |
 1339|    942|    MPI_ECP_LSET(&pt->Z, 1);
  ------------------
  |  | 1185|    942|    MBEDTLS_MPI_CHK(mbedtls_mpi_lset(X, c))
  |  |  ------------------
  |  |  |  |   41|    942|    do                           \
  |  |  |  |   42|    942|    {                            \
  |  |  |  |   43|    942|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 942]
  |  |  |  |  ------------------
  |  |  |  |   44|    942|        goto cleanup;        \
  |  |  |  |   45|    942|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1340|       |
 1341|    942|cleanup:
 1342|       |
 1343|    942|    mbedtls_mpi_free(&T);
 1344|       |
 1345|    942|    return ret;
 1346|    942|#endif /* !defined(MBEDTLS_ECP_NO_FALLBACK) || !defined(MBEDTLS_ECP_NORMALIZE_JAC_ALT) */
 1347|    942|}
ecp.c:mpi_free_many:
  325|  1.88k|{
  326|  10.0k|    while (size--) {
  ------------------
  |  Branch (326:12): [True: 8.16k, False: 1.88k]
  ------------------
  327|  8.16k|        mbedtls_mpi_free(arr++);
  328|  8.16k|    }
  329|  1.88k|}
ecp.c:ecp_check_pubkey_sw:
 2726|  3.14k|{
 2727|  3.14k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  3.14k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 2728|  3.14k|    mbedtls_mpi YY, RHS;
 2729|       |
 2730|       |    /* pt coordinates must be normalized for our checks */
 2731|  3.14k|    if (mbedtls_mpi_cmp_int(&pt->X, 0) < 0 ||
  ------------------
  |  Branch (2731:9): [True: 0, False: 3.14k]
  ------------------
 2732|  3.14k|        mbedtls_mpi_cmp_int(&pt->Y, 0) < 0 ||
  ------------------
  |  Branch (2732:9): [True: 0, False: 3.14k]
  ------------------
 2733|  3.14k|        mbedtls_mpi_cmp_mpi(&pt->X, &grp->P) >= 0 ||
  ------------------
  |  Branch (2733:9): [True: 0, False: 3.14k]
  ------------------
 2734|  3.14k|        mbedtls_mpi_cmp_mpi(&pt->Y, &grp->P) >= 0) {
  ------------------
  |  Branch (2734:9): [True: 0, False: 3.14k]
  ------------------
 2735|      0|        return MBEDTLS_ERR_ECP_INVALID_KEY;
  ------------------
  |  |   47|      0|#define MBEDTLS_ERR_ECP_INVALID_KEY                       -0x4C80
  ------------------
 2736|      0|    }
 2737|       |
 2738|  3.14k|    mbedtls_mpi_init(&YY); mbedtls_mpi_init(&RHS);
 2739|       |
 2740|       |    /*
 2741|       |     * YY = Y^2
 2742|       |     * RHS = X^3 + A X + B
 2743|       |     */
 2744|  3.14k|    MPI_ECP_SQR(&YY,  &pt->Y);
  ------------------
  |  | 1170|  3.14k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, A))
  |  |  ------------------
  |  |  |  |   41|  3.14k|    do                           \
  |  |  |  |   42|  3.14k|    {                            \
  |  |  |  |   43|  3.14k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 3.14k]
  |  |  |  |  ------------------
  |  |  |  |   44|  3.14k|        goto cleanup;        \
  |  |  |  |   45|  3.14k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2745|  3.14k|    MBEDTLS_MPI_CHK(ecp_sw_rhs(grp, &RHS, &pt->X));
  ------------------
  |  |   41|  3.14k|    do                           \
  |  |   42|  3.14k|    {                            \
  |  |   43|  3.14k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3.14k]
  |  |  ------------------
  |  |   44|  3.14k|        goto cleanup;        \
  |  |   45|  3.14k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2746|       |
 2747|  3.14k|    if (MPI_ECP_CMP(&YY, &RHS) != 0) {
  ------------------
  |  | 1191|  3.14k|    mbedtls_mpi_cmp_mpi(X, Y)
  ------------------
  |  Branch (2747:9): [True: 0, False: 3.14k]
  ------------------
 2748|      0|        ret = MBEDTLS_ERR_ECP_INVALID_KEY;
  ------------------
  |  |   47|      0|#define MBEDTLS_ERR_ECP_INVALID_KEY                       -0x4C80
  ------------------
 2749|      0|    }
 2750|       |
 2751|  3.14k|cleanup:
 2752|       |
 2753|  3.14k|    mbedtls_mpi_free(&YY); mbedtls_mpi_free(&RHS);
 2754|       |
 2755|  3.14k|    return ret;
 2756|  3.14k|}

mbedtls_ecp_group_load:
 4718|  2.66k|{
 4719|  2.66k|    mbedtls_ecp_group_free(grp);
 4720|       |
 4721|  2.66k|    mbedtls_ecp_group_init(grp);
 4722|       |
 4723|  2.66k|    grp->id = id;
 4724|       |
 4725|  2.66k|    switch (id) {
 4726|       |#if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
 4727|       |        case MBEDTLS_ECP_DP_SECP192R1:
 4728|       |            NIST_MODP(p192);
 4729|       |            return LOAD_GROUP(secp192r1);
 4730|       |#endif /* MBEDTLS_ECP_DP_SECP192R1_ENABLED */
 4731|       |
 4732|       |#if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED)
 4733|       |        case MBEDTLS_ECP_DP_SECP224R1:
 4734|       |            NIST_MODP(p224);
 4735|       |            return LOAD_GROUP(secp224r1);
 4736|       |#endif /* MBEDTLS_ECP_DP_SECP224R1_ENABLED */
 4737|       |
 4738|      0|#if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED)
 4739|  2.66k|        case MBEDTLS_ECP_DP_SECP256R1:
  ------------------
  |  Branch (4739:9): [True: 2.66k, False: 0]
  ------------------
 4740|  2.66k|            NIST_MODP(p256);
  ------------------
  |  | 4567|  2.66k|#define NIST_MODP(P)      grp->modp = ecp_mod_ ## P;
  ------------------
 4741|  2.66k|            return LOAD_GROUP(secp256r1);
  ------------------
  |  | 4600|  2.66k|#define LOAD_GROUP(G)     ecp_group_load(grp,            \
  |  | 4601|  2.66k|                                         G ## _p,  sizeof(G ## _p),   \
  |  | 4602|  2.66k|                                         NULL,     0,                    \
  |  | 4603|  2.66k|                                         G ## _b,  sizeof(G ## _b),   \
  |  | 4604|  2.66k|                                         G ## _gx, sizeof(G ## _gx),   \
  |  | 4605|  2.66k|                                         G ## _gy, sizeof(G ## _gy),   \
  |  | 4606|  2.66k|                                         G ## _n,  sizeof(G ## _n),   \
  |  | 4607|  2.66k|                                         G ## _T                         \
  |  | 4608|  2.66k|                                         )
  ------------------
 4742|      0|#endif /* MBEDTLS_ECP_DP_SECP256R1_ENABLED */
 4743|       |
 4744|      0|#if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
 4745|      0|        case MBEDTLS_ECP_DP_SECP384R1:
  ------------------
  |  Branch (4745:9): [True: 0, False: 2.66k]
  ------------------
 4746|      0|            NIST_MODP(p384);
  ------------------
  |  | 4567|      0|#define NIST_MODP(P)      grp->modp = ecp_mod_ ## P;
  ------------------
 4747|      0|            return LOAD_GROUP(secp384r1);
  ------------------
  |  | 4600|      0|#define LOAD_GROUP(G)     ecp_group_load(grp,            \
  |  | 4601|      0|                                         G ## _p,  sizeof(G ## _p),   \
  |  | 4602|      0|                                         NULL,     0,                    \
  |  | 4603|      0|                                         G ## _b,  sizeof(G ## _b),   \
  |  | 4604|      0|                                         G ## _gx, sizeof(G ## _gx),   \
  |  | 4605|      0|                                         G ## _gy, sizeof(G ## _gy),   \
  |  | 4606|      0|                                         G ## _n,  sizeof(G ## _n),   \
  |  | 4607|      0|                                         G ## _T                         \
  |  | 4608|      0|                                         )
  ------------------
 4748|      0|#endif /* MBEDTLS_ECP_DP_SECP384R1_ENABLED */
 4749|       |
 4750|      0|#if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED)
 4751|      0|        case MBEDTLS_ECP_DP_SECP521R1:
  ------------------
  |  Branch (4751:9): [True: 0, False: 2.66k]
  ------------------
 4752|      0|            NIST_MODP(p521);
  ------------------
  |  | 4567|      0|#define NIST_MODP(P)      grp->modp = ecp_mod_ ## P;
  ------------------
 4753|      0|            return LOAD_GROUP(secp521r1);
  ------------------
  |  | 4600|      0|#define LOAD_GROUP(G)     ecp_group_load(grp,            \
  |  | 4601|      0|                                         G ## _p,  sizeof(G ## _p),   \
  |  | 4602|      0|                                         NULL,     0,                    \
  |  | 4603|      0|                                         G ## _b,  sizeof(G ## _b),   \
  |  | 4604|      0|                                         G ## _gx, sizeof(G ## _gx),   \
  |  | 4605|      0|                                         G ## _gy, sizeof(G ## _gy),   \
  |  | 4606|      0|                                         G ## _n,  sizeof(G ## _n),   \
  |  | 4607|      0|                                         G ## _T                         \
  |  | 4608|      0|                                         )
  ------------------
 4754|      0|#endif /* MBEDTLS_ECP_DP_SECP521R1_ENABLED */
 4755|       |
 4756|       |#if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED)
 4757|       |        case MBEDTLS_ECP_DP_SECP192K1:
 4758|       |            grp->modp = ecp_mod_p192k1;
 4759|       |            return LOAD_GROUP_A(secp192k1);
 4760|       |#endif /* MBEDTLS_ECP_DP_SECP192K1_ENABLED */
 4761|       |
 4762|       |#if defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED)
 4763|       |        case MBEDTLS_ECP_DP_SECP224K1:
 4764|       |            grp->modp = ecp_mod_p224k1;
 4765|       |            return LOAD_GROUP_A(secp224k1);
 4766|       |#endif /* MBEDTLS_ECP_DP_SECP224K1_ENABLED */
 4767|       |
 4768|       |#if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
 4769|       |        case MBEDTLS_ECP_DP_SECP256K1:
 4770|       |            grp->modp = ecp_mod_p256k1;
 4771|       |            return LOAD_GROUP_A(secp256k1);
 4772|       |#endif /* MBEDTLS_ECP_DP_SECP256K1_ENABLED */
 4773|       |
 4774|       |#if defined(MBEDTLS_ECP_DP_BP256R1_ENABLED)
 4775|       |        case MBEDTLS_ECP_DP_BP256R1:
 4776|       |            return LOAD_GROUP_A(brainpoolP256r1);
 4777|       |#endif /* MBEDTLS_ECP_DP_BP256R1_ENABLED */
 4778|       |
 4779|       |#if defined(MBEDTLS_ECP_DP_BP384R1_ENABLED)
 4780|       |        case MBEDTLS_ECP_DP_BP384R1:
 4781|       |            return LOAD_GROUP_A(brainpoolP384r1);
 4782|       |#endif /* MBEDTLS_ECP_DP_BP384R1_ENABLED */
 4783|       |
 4784|       |#if defined(MBEDTLS_ECP_DP_BP512R1_ENABLED)
 4785|       |        case MBEDTLS_ECP_DP_BP512R1:
 4786|       |            return LOAD_GROUP_A(brainpoolP512r1);
 4787|       |#endif /* MBEDTLS_ECP_DP_BP512R1_ENABLED */
 4788|       |
 4789|      0|#if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED)
 4790|      0|        case MBEDTLS_ECP_DP_CURVE25519:
  ------------------
  |  Branch (4790:9): [True: 0, False: 2.66k]
  ------------------
 4791|      0|            grp->modp = ecp_mod_p255;
 4792|      0|            return ecp_use_curve25519(grp);
 4793|      0|#endif /* MBEDTLS_ECP_DP_CURVE25519_ENABLED */
 4794|       |
 4795|      0|#if defined(MBEDTLS_ECP_DP_CURVE448_ENABLED)
 4796|      0|        case MBEDTLS_ECP_DP_CURVE448:
  ------------------
  |  Branch (4796:9): [True: 0, False: 2.66k]
  ------------------
 4797|      0|            grp->modp = ecp_mod_p448;
 4798|      0|            return ecp_use_curve448(grp);
 4799|      0|#endif /* MBEDTLS_ECP_DP_CURVE448_ENABLED */
 4800|       |
 4801|      0|        default:
  ------------------
  |  Branch (4801:9): [True: 0, False: 2.66k]
  ------------------
 4802|      0|            grp->id = MBEDTLS_ECP_DP_NONE;
 4803|      0|            return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
  ------------------
  |  |   39|      0|#define MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE               -0x4E80
  ------------------
 4804|  2.66k|    }
 4805|  2.66k|}
ecp_curves.c:ecp_group_load:
 4522|  2.66k|{
 4523|  2.66k|    ecp_mpi_load(&grp->P, p, plen);
 4524|  2.66k|    if (a != NULL) {
  ------------------
  |  Branch (4524:9): [True: 0, False: 2.66k]
  ------------------
 4525|      0|        ecp_mpi_load(&grp->A, a, alen);
 4526|      0|    }
 4527|  2.66k|    ecp_mpi_load(&grp->B, b, blen);
 4528|  2.66k|    ecp_mpi_load(&grp->N, n, nlen);
 4529|       |
 4530|  2.66k|    ecp_mpi_load(&grp->G.X, gx, gxlen);
 4531|  2.66k|    ecp_mpi_load(&grp->G.Y, gy, gylen);
 4532|  2.66k|    ecp_mpi_set1(&grp->G.Z);
 4533|       |
 4534|  2.66k|    grp->pbits = mbedtls_mpi_bitlen(&grp->P);
 4535|  2.66k|    grp->nbits = mbedtls_mpi_bitlen(&grp->N);
 4536|       |
 4537|  2.66k|    grp->h = 1;
 4538|       |
 4539|  2.66k|    grp->T = (mbedtls_ecp_point *) T;
 4540|       |    /*
 4541|       |     * Set T_size to 0 to prevent T free by mbedtls_ecp_group_free.
 4542|       |     */
 4543|  2.66k|    grp->T_size = 0;
 4544|       |
 4545|  2.66k|    return 0;
 4546|  2.66k|}
ecp_curves.c:ecp_mpi_load:
 4495|  13.3k|{
 4496|  13.3k|    X->s = 1;
 4497|  13.3k|    X->n = (unsigned short) (len / sizeof(mbedtls_mpi_uint));
 4498|  13.3k|    X->p = (mbedtls_mpi_uint *) p;
 4499|  13.3k|}
ecp_curves.c:ecp_mpi_set1:
 4505|  2.66k|{
 4506|  2.66k|    X->s = 1;
 4507|  2.66k|    X->n = 1;
 4508|  2.66k|    X->p = (mbedtls_mpi_uint *) mpi_one; /* X->p will not be modified so the cast is safe */
 4509|  2.66k|}
ecp_curves.c:ecp_mod_p256:
 5037|  1.23M|{
 5038|  1.23M|    INIT(256);
  ------------------
  |  | 4954|  1.23M|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;                    \
  |  |  ------------------
  |  |  |  |  100|  1.23M|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  |  |  ------------------
  |  | 4955|  1.23M|    signed char c = 0, cc;                                              \
  |  | 4956|  1.23M|    uint32_t cur;                                                       \
  |  | 4957|  1.23M|    size_t i = 0, bits = (b);                                           \
  |  | 4958|  1.23M|    /* N is the size of the product of two b-bit numbers, plus one */   \
  |  | 4959|  1.23M|    /* limb for fix_negative */                                         \
  |  | 4960|  1.23M|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(N, (b) * 2 / biL + 1));      \
  |  |  ------------------
  |  |  |  |   41|  1.23M|    do                           \
  |  |  |  |   42|  1.23M|    {                            \
  |  |  |  |   43|  1.23M|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 1.23M]
  |  |  |  |  ------------------
  |  |  |  |   44|  1.23M|        goto cleanup;        \
  |  |  |  |   45|  1.23M|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 4961|  1.23M|    LOAD32;
  |  |  ------------------
  |  |  |  | 4908|  1.23M|#define LOAD32      cur = A(i);
  |  |  |  |  ------------------
  |  |  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (4919:14): [True: 0, False: 1.23M]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5039|       |
 5040|  1.23M|    ADD(8); ADD(9);
  ------------------
  |  | 4947|  1.23M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(8); ADD(9);
  ------------------
  |  | 4947|  1.23M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
 5041|  1.23M|    SUB(11); SUB(12); SUB(13); SUB(14);             NEXT;         // A0
  ------------------
  |  | 4948|  1.23M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(11); SUB(12); SUB(13); SUB(14);             NEXT;         // A0
  ------------------
  |  | 4948|  1.23M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(11); SUB(12); SUB(13); SUB(14);             NEXT;         // A0
  ------------------
  |  | 4948|  1.23M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(11); SUB(12); SUB(13); SUB(14);             NEXT;         // A0
  ------------------
  |  | 4948|  1.23M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(11); SUB(12); SUB(13); SUB(14);             NEXT;         // A0
  ------------------
  |  | 4964|  1.23M|    STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4922|  1.23M|    if (i % 2) {                                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4922:9): [True: 0, False: 1.23M]
  |  |  |  |  ------------------
  |  |  |  | 4923|      0|        N->p[i/2] &= 0x00000000FFFFFFFF;          \
  |  |  |  | 4924|      0|        N->p[i/2] |= ((mbedtls_mpi_uint) cur) << 32;        \
  |  |  |  | 4925|  1.23M|    } else {                                      \
  |  |  |  | 4926|  1.23M|        N->p[i/2] &= 0xFFFFFFFF00000000;          \
  |  |  |  | 4927|  1.23M|        N->p[i/2] |= (mbedtls_mpi_uint) cur;                \
  |  |  |  | 4928|  1.23M|    }
  |  |  ------------------
  |  |                   STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4908|  1.23M|#define LOAD32      cur = A(i);
  |  |  |  |  ------------------
  |  |  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (4919:14): [True: 1.23M, False: 0]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 4965|  1.23M|    cc = c; c = 0;              \
  |  | 4966|  1.23M|    if (cc < 0)                \
  |  |  ------------------
  |  |  |  Branch (4966:9): [True: 919k, False: 316k]
  |  |  ------------------
  |  | 4967|  1.23M|    sub32(&cur, -cc, &c); \
  |  | 4968|  1.23M|    else                        \
  |  | 4969|  1.23M|    add32(&cur, cc, &c);  \
  ------------------
 5042|       |
 5043|  1.23M|    ADD(9); ADD(10);
  ------------------
  |  | 4947|  1.23M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(9); ADD(10);
  ------------------
  |  | 4947|  1.23M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
 5044|  1.23M|    SUB(12); SUB(13); SUB(14); SUB(15);             NEXT;         // A1
  ------------------
  |  | 4948|  1.23M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(12); SUB(13); SUB(14); SUB(15);             NEXT;         // A1
  ------------------
  |  | 4948|  1.23M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(12); SUB(13); SUB(14); SUB(15);             NEXT;         // A1
  ------------------
  |  | 4948|  1.23M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(12); SUB(13); SUB(14); SUB(15);             NEXT;         // A1
  ------------------
  |  | 4948|  1.23M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(12); SUB(13); SUB(14); SUB(15);             NEXT;         // A1
  ------------------
  |  | 4964|  1.23M|    STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4922|  1.23M|    if (i % 2) {                                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4922:9): [True: 1.23M, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 4923|  1.23M|        N->p[i/2] &= 0x00000000FFFFFFFF;          \
  |  |  |  | 4924|  1.23M|        N->p[i/2] |= ((mbedtls_mpi_uint) cur) << 32;        \
  |  |  |  | 4925|  1.23M|    } else {                                      \
  |  |  |  | 4926|      0|        N->p[i/2] &= 0xFFFFFFFF00000000;          \
  |  |  |  | 4927|      0|        N->p[i/2] |= (mbedtls_mpi_uint) cur;                \
  |  |  |  | 4928|      0|    }
  |  |  ------------------
  |  |                   STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4908|  1.23M|#define LOAD32      cur = A(i);
  |  |  |  |  ------------------
  |  |  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (4919:14): [True: 0, False: 1.23M]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 4965|  1.23M|    cc = c; c = 0;              \
  |  | 4966|  1.23M|    if (cc < 0)                \
  |  |  ------------------
  |  |  |  Branch (4966:9): [True: 789k, False: 446k]
  |  |  ------------------
  |  | 4967|  1.23M|    sub32(&cur, -cc, &c); \
  |  | 4968|  1.23M|    else                        \
  |  | 4969|  1.23M|    add32(&cur, cc, &c);  \
  ------------------
 5045|       |
 5046|  1.23M|    ADD(10); ADD(11);
  ------------------
  |  | 4947|  1.23M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(10); ADD(11);
  ------------------
  |  | 4947|  1.23M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
 5047|  1.23M|    SUB(13); SUB(14); SUB(15);                        NEXT;       // A2
  ------------------
  |  | 4948|  1.23M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(13); SUB(14); SUB(15);                        NEXT;       // A2
  ------------------
  |  | 4948|  1.23M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(13); SUB(14); SUB(15);                        NEXT;       // A2
  ------------------
  |  | 4948|  1.23M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(13); SUB(14); SUB(15);                        NEXT;       // A2
  ------------------
  |  | 4964|  1.23M|    STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4922|  1.23M|    if (i % 2) {                                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4922:9): [True: 0, False: 1.23M]
  |  |  |  |  ------------------
  |  |  |  | 4923|      0|        N->p[i/2] &= 0x00000000FFFFFFFF;          \
  |  |  |  | 4924|      0|        N->p[i/2] |= ((mbedtls_mpi_uint) cur) << 32;        \
  |  |  |  | 4925|  1.23M|    } else {                                      \
  |  |  |  | 4926|  1.23M|        N->p[i/2] &= 0xFFFFFFFF00000000;          \
  |  |  |  | 4927|  1.23M|        N->p[i/2] |= (mbedtls_mpi_uint) cur;                \
  |  |  |  | 4928|  1.23M|    }
  |  |  ------------------
  |  |                   STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4908|  1.23M|#define LOAD32      cur = A(i);
  |  |  |  |  ------------------
  |  |  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (4919:14): [True: 1.23M, False: 0]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 4965|  1.23M|    cc = c; c = 0;              \
  |  | 4966|  1.23M|    if (cc < 0)                \
  |  |  ------------------
  |  |  |  Branch (4966:9): [True: 478k, False: 756k]
  |  |  ------------------
  |  | 4967|  1.23M|    sub32(&cur, -cc, &c); \
  |  | 4968|  1.23M|    else                        \
  |  | 4969|  1.23M|    add32(&cur, cc, &c);  \
  ------------------
 5048|       |
 5049|  1.23M|    ADD(11); ADD(11); ADD(12); ADD(12); ADD(13);
  ------------------
  |  | 4947|  1.23M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(11); ADD(11); ADD(12); ADD(12); ADD(13);
  ------------------
  |  | 4947|  1.23M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(11); ADD(11); ADD(12); ADD(12); ADD(13);
  ------------------
  |  | 4947|  1.23M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(11); ADD(11); ADD(12); ADD(12); ADD(13);
  ------------------
  |  | 4947|  1.23M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(11); ADD(11); ADD(12); ADD(12); ADD(13);
  ------------------
  |  | 4947|  1.23M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
 5050|  1.23M|    SUB(15); SUB(8); SUB(9);                        NEXT;         // A3
  ------------------
  |  | 4948|  1.23M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(15); SUB(8); SUB(9);                        NEXT;         // A3
  ------------------
  |  | 4948|  1.23M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(15); SUB(8); SUB(9);                        NEXT;         // A3
  ------------------
  |  | 4948|  1.23M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(15); SUB(8); SUB(9);                        NEXT;         // A3
  ------------------
  |  | 4964|  1.23M|    STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4922|  1.23M|    if (i % 2) {                                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4922:9): [True: 1.23M, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 4923|  1.23M|        N->p[i/2] &= 0x00000000FFFFFFFF;          \
  |  |  |  | 4924|  1.23M|        N->p[i/2] |= ((mbedtls_mpi_uint) cur) << 32;        \
  |  |  |  | 4925|  1.23M|    } else {                                      \
  |  |  |  | 4926|      0|        N->p[i/2] &= 0xFFFFFFFF00000000;          \
  |  |  |  | 4927|      0|        N->p[i/2] |= (mbedtls_mpi_uint) cur;                \
  |  |  |  | 4928|      0|    }
  |  |  ------------------
  |  |                   STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4908|  1.23M|#define LOAD32      cur = A(i);
  |  |  |  |  ------------------
  |  |  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (4919:14): [True: 0, False: 1.23M]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 4965|  1.23M|    cc = c; c = 0;              \
  |  | 4966|  1.23M|    if (cc < 0)                \
  |  |  ------------------
  |  |  |  Branch (4966:9): [True: 61.2k, False: 1.17M]
  |  |  ------------------
  |  | 4967|  1.23M|    sub32(&cur, -cc, &c); \
  |  | 4968|  1.23M|    else                        \
  |  | 4969|  1.23M|    add32(&cur, cc, &c);  \
  ------------------
 5051|       |
 5052|  1.23M|    ADD(12); ADD(12); ADD(13); ADD(13); ADD(14);
  ------------------
  |  | 4947|  1.23M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(12); ADD(12); ADD(13); ADD(13); ADD(14);
  ------------------
  |  | 4947|  1.23M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(12); ADD(12); ADD(13); ADD(13); ADD(14);
  ------------------
  |  | 4947|  1.23M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(12); ADD(12); ADD(13); ADD(13); ADD(14);
  ------------------
  |  | 4947|  1.23M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(12); ADD(12); ADD(13); ADD(13); ADD(14);
  ------------------
  |  | 4947|  1.23M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
 5053|  1.23M|    SUB(9); SUB(10);                                   NEXT;      // A4
  ------------------
  |  | 4948|  1.23M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(9); SUB(10);                                   NEXT;      // A4
  ------------------
  |  | 4948|  1.23M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(9); SUB(10);                                   NEXT;      // A4
  ------------------
  |  | 4964|  1.23M|    STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4922|  1.23M|    if (i % 2) {                                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4922:9): [True: 0, False: 1.23M]
  |  |  |  |  ------------------
  |  |  |  | 4923|      0|        N->p[i/2] &= 0x00000000FFFFFFFF;          \
  |  |  |  | 4924|      0|        N->p[i/2] |= ((mbedtls_mpi_uint) cur) << 32;        \
  |  |  |  | 4925|  1.23M|    } else {                                      \
  |  |  |  | 4926|  1.23M|        N->p[i/2] &= 0xFFFFFFFF00000000;          \
  |  |  |  | 4927|  1.23M|        N->p[i/2] |= (mbedtls_mpi_uint) cur;                \
  |  |  |  | 4928|  1.23M|    }
  |  |  ------------------
  |  |                   STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4908|  1.23M|#define LOAD32      cur = A(i);
  |  |  |  |  ------------------
  |  |  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (4919:14): [True: 1.23M, False: 0]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 4965|  1.23M|    cc = c; c = 0;              \
  |  | 4966|  1.23M|    if (cc < 0)                \
  |  |  ------------------
  |  |  |  Branch (4966:9): [True: 25.1k, False: 1.21M]
  |  |  ------------------
  |  | 4967|  1.23M|    sub32(&cur, -cc, &c); \
  |  | 4968|  1.23M|    else                        \
  |  | 4969|  1.23M|    add32(&cur, cc, &c);  \
  ------------------
 5054|       |
 5055|  1.23M|    ADD(13); ADD(13); ADD(14); ADD(14); ADD(15);
  ------------------
  |  | 4947|  1.23M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(13); ADD(13); ADD(14); ADD(14); ADD(15);
  ------------------
  |  | 4947|  1.23M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(13); ADD(13); ADD(14); ADD(14); ADD(15);
  ------------------
  |  | 4947|  1.23M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(13); ADD(13); ADD(14); ADD(14); ADD(15);
  ------------------
  |  | 4947|  1.23M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(13); ADD(13); ADD(14); ADD(14); ADD(15);
  ------------------
  |  | 4947|  1.23M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
 5056|  1.23M|    SUB(10); SUB(11);                                   NEXT;     // A5
  ------------------
  |  | 4948|  1.23M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(10); SUB(11);                                   NEXT;     // A5
  ------------------
  |  | 4948|  1.23M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(10); SUB(11);                                   NEXT;     // A5
  ------------------
  |  | 4964|  1.23M|    STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4922|  1.23M|    if (i % 2) {                                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4922:9): [True: 1.23M, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 4923|  1.23M|        N->p[i/2] &= 0x00000000FFFFFFFF;          \
  |  |  |  | 4924|  1.23M|        N->p[i/2] |= ((mbedtls_mpi_uint) cur) << 32;        \
  |  |  |  | 4925|  1.23M|    } else {                                      \
  |  |  |  | 4926|      0|        N->p[i/2] &= 0xFFFFFFFF00000000;          \
  |  |  |  | 4927|      0|        N->p[i/2] |= (mbedtls_mpi_uint) cur;                \
  |  |  |  | 4928|      0|    }
  |  |  ------------------
  |  |                   STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4908|  1.23M|#define LOAD32      cur = A(i);
  |  |  |  |  ------------------
  |  |  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (4919:14): [True: 0, False: 1.23M]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 4965|  1.23M|    cc = c; c = 0;              \
  |  | 4966|  1.23M|    if (cc < 0)                \
  |  |  ------------------
  |  |  |  Branch (4966:9): [True: 42.3k, False: 1.19M]
  |  |  ------------------
  |  | 4967|  1.23M|    sub32(&cur, -cc, &c); \
  |  | 4968|  1.23M|    else                        \
  |  | 4969|  1.23M|    add32(&cur, cc, &c);  \
  ------------------
 5057|       |
 5058|  1.23M|    ADD(14); ADD(14); ADD(15); ADD(15); ADD(14); ADD(13);
  ------------------
  |  | 4947|  1.23M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(14); ADD(14); ADD(15); ADD(15); ADD(14); ADD(13);
  ------------------
  |  | 4947|  1.23M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(14); ADD(14); ADD(15); ADD(15); ADD(14); ADD(13);
  ------------------
  |  | 4947|  1.23M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(14); ADD(14); ADD(15); ADD(15); ADD(14); ADD(13);
  ------------------
  |  | 4947|  1.23M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(14); ADD(14); ADD(15); ADD(15); ADD(14); ADD(13);
  ------------------
  |  | 4947|  1.23M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(14); ADD(14); ADD(15); ADD(15); ADD(14); ADD(13);
  ------------------
  |  | 4947|  1.23M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
 5059|  1.23M|    SUB(8); SUB(9);                                   NEXT;       // A6
  ------------------
  |  | 4948|  1.23M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(8); SUB(9);                                   NEXT;       // A6
  ------------------
  |  | 4948|  1.23M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(8); SUB(9);                                   NEXT;       // A6
  ------------------
  |  | 4964|  1.23M|    STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4922|  1.23M|    if (i % 2) {                                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4922:9): [True: 0, False: 1.23M]
  |  |  |  |  ------------------
  |  |  |  | 4923|      0|        N->p[i/2] &= 0x00000000FFFFFFFF;          \
  |  |  |  | 4924|      0|        N->p[i/2] |= ((mbedtls_mpi_uint) cur) << 32;        \
  |  |  |  | 4925|  1.23M|    } else {                                      \
  |  |  |  | 4926|  1.23M|        N->p[i/2] &= 0xFFFFFFFF00000000;          \
  |  |  |  | 4927|  1.23M|        N->p[i/2] |= (mbedtls_mpi_uint) cur;                \
  |  |  |  | 4928|  1.23M|    }
  |  |  ------------------
  |  |                   STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4908|  1.23M|#define LOAD32      cur = A(i);
  |  |  |  |  ------------------
  |  |  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (4919:14): [True: 1.23M, False: 0]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 4965|  1.23M|    cc = c; c = 0;              \
  |  | 4966|  1.23M|    if (cc < 0)                \
  |  |  ------------------
  |  |  |  Branch (4966:9): [True: 36.5k, False: 1.19M]
  |  |  ------------------
  |  | 4967|  1.23M|    sub32(&cur, -cc, &c); \
  |  | 4968|  1.23M|    else                        \
  |  | 4969|  1.23M|    add32(&cur, cc, &c);  \
  ------------------
 5060|       |
 5061|  1.23M|    ADD(15); ADD(15); ADD(15); ADD(8);
  ------------------
  |  | 4947|  1.23M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(15); ADD(15); ADD(15); ADD(8);
  ------------------
  |  | 4947|  1.23M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(15); ADD(15); ADD(15); ADD(8);
  ------------------
  |  | 4947|  1.23M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(15); ADD(15); ADD(15); ADD(8);
  ------------------
  |  | 4947|  1.23M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
 5062|  1.23M|    SUB(10); SUB(11); SUB(12); SUB(13);             LAST;         // A7
  ------------------
  |  | 4948|  1.23M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(10); SUB(11); SUB(12); SUB(13);             LAST;         // A7
  ------------------
  |  | 4948|  1.23M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(10); SUB(11); SUB(12); SUB(13);             LAST;         // A7
  ------------------
  |  | 4948|  1.23M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(10); SUB(11); SUB(12); SUB(13);             LAST;         // A7
  ------------------
  |  | 4948|  1.23M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  1.23M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  1.23M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(10); SUB(11); SUB(12); SUB(13);             LAST;         // A7
  ------------------
  |  | 4972|  1.23M|    STORE32; i++;                               \
  |  |  ------------------
  |  |  |  | 4922|  1.23M|    if (i % 2) {                                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4922:9): [True: 1.23M, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 4923|  1.23M|        N->p[i/2] &= 0x00000000FFFFFFFF;          \
  |  |  |  | 4924|  1.23M|        N->p[i/2] |= ((mbedtls_mpi_uint) cur) << 32;        \
  |  |  |  | 4925|  1.23M|    } else {                                      \
  |  |  |  | 4926|      0|        N->p[i/2] &= 0xFFFFFFFF00000000;          \
  |  |  |  | 4927|      0|        N->p[i/2] |= (mbedtls_mpi_uint) cur;                \
  |  |  |  | 4928|      0|    }
  |  |  ------------------
  |  | 4973|  1.23M|    cur = c > 0 ? c : 0; STORE32;               \
  |  |  ------------------
  |  |  |  | 4922|  1.23M|    if (i % 2) {                                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4922:9): [True: 0, False: 1.23M]
  |  |  |  |  ------------------
  |  |  |  | 4923|      0|        N->p[i/2] &= 0x00000000FFFFFFFF;          \
  |  |  |  | 4924|      0|        N->p[i/2] |= ((mbedtls_mpi_uint) cur) << 32;        \
  |  |  |  | 4925|  1.23M|    } else {                                      \
  |  |  |  | 4926|  1.23M|        N->p[i/2] &= 0xFFFFFFFF00000000;          \
  |  |  |  | 4927|  1.23M|        N->p[i/2] |= (mbedtls_mpi_uint) cur;                \
  |  |  |  | 4928|  1.23M|    }
  |  |  ------------------
  |  |  |  Branch (4973:11): [True: 183k, False: 1.05M]
  |  |  ------------------
  |  | 4974|  12.3M|    cur = 0; while (++i < MAX32) { STORE32; }  \
  |  |  ------------------
  |  |  |  | 4918|  12.3M|#define MAX32       N->n * 2
  |  |  ------------------
  |  |                   cur = 0; while (++i < MAX32) { STORE32; }  \
  |  |  ------------------
  |  |  |  | 4922|  11.1M|    if (i % 2) {                                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4922:9): [True: 6.17M, False: 4.94M]
  |  |  |  |  ------------------
  |  |  |  | 4923|  6.17M|        N->p[i/2] &= 0x00000000FFFFFFFF;          \
  |  |  |  | 4924|  6.17M|        N->p[i/2] |= ((mbedtls_mpi_uint) cur) << 32;        \
  |  |  |  | 4925|  6.17M|    } else {                                      \
  |  |  |  | 4926|  4.94M|        N->p[i/2] &= 0xFFFFFFFF00000000;          \
  |  |  |  | 4927|  4.94M|        N->p[i/2] |= (mbedtls_mpi_uint) cur;                \
  |  |  |  | 4928|  4.94M|    }
  |  |  ------------------
  |  |  |  Branch (4974:21): [True: 11.1M, False: 1.23M]
  |  |  ------------------
  |  | 4975|  1.23M|    if (c < 0) mbedtls_ecp_fix_negative(N, c, bits);
  |  |  ------------------
  |  |  |  Branch (4975:9): [True: 708k, False: 527k]
  |  |  ------------------
  ------------------
 5063|       |
 5064|  1.23M|cleanup:
 5065|  1.23M|    return ret;
 5066|  1.23M|}
ecp_curves.c:add32:
 4936|  44.5M|{
 4937|  44.5M|    *dst += src;
 4938|  44.5M|    *carry += (*dst < src);
 4939|  44.5M|}
ecp_curves.c:sub32:
 4942|  31.9M|{
 4943|  31.9M|    *carry -= (*dst < src);
 4944|  31.9M|    *dst -= src;
 4945|  31.9M|}
ecp_curves.c:mbedtls_ecp_fix_negative:
 4982|   708k|{
 4983|   708k|    size_t i;
 4984|       |
 4985|       |    /* Set N := 2^bits - 1 - N. We know that 0 <= N < 2^bits, so
 4986|       |     * set the absolute value to 0xfff...fff - N. There is no carry
 4987|       |     * since we're subtracting from all-bits-one.  */
 4988|  4.24M|    for (i = 0; i <= bits / 8 / sizeof(mbedtls_mpi_uint); i++) {
  ------------------
  |  Branch (4988:17): [True: 3.54M, False: 708k]
  ------------------
 4989|  3.54M|        N->p[i] = ~(mbedtls_mpi_uint) 0 - N->p[i];
 4990|  3.54M|    }
 4991|       |    /* Add 1, taking care of the carry. */
 4992|   708k|    i = 0;
 4993|   708k|    do {
 4994|   708k|        ++N->p[i];
 4995|   708k|    } while (N->p[i++] == 0 && i <= bits / 8 / sizeof(mbedtls_mpi_uint));
  ------------------
  |  Branch (4995:14): [True: 0, False: 708k]
  |  Branch (4995:32): [True: 0, False: 0]
  ------------------
 4996|       |    /* Invert the sign.
 4997|       |     * Now N = N0 - 2^bits where N0 is the initial value of N. */
 4998|   708k|    N->s = -1;
 4999|       |
 5000|       |    /* Add |c| * 2^bits to the absolute value. Since c and N are
 5001|       |     * negative, this adds c * 2^bits. */
 5002|   708k|    mbedtls_mpi_uint msw = (mbedtls_mpi_uint) -c;
 5003|   708k|#if defined(MBEDTLS_HAVE_INT64)
 5004|   708k|    if (bits == 224) {
  ------------------
  |  Branch (5004:9): [True: 0, False: 708k]
  ------------------
 5005|      0|        msw <<= 32;
 5006|      0|    }
 5007|   708k|#endif
 5008|   708k|    N->p[bits / 8 / sizeof(mbedtls_mpi_uint)] += msw;
 5009|   708k|}

mbedtls_md_info_from_type:
  140|    314|{
  141|    314|    switch (md_type) {
  142|       |#if defined(MBEDTLS_MD_CAN_MD5)
  143|       |        case MBEDTLS_MD_MD5:
  144|       |            return &mbedtls_md5_info;
  145|       |#endif
  146|       |#if defined(MBEDTLS_MD_CAN_RIPEMD160)
  147|       |        case MBEDTLS_MD_RIPEMD160:
  148|       |            return &mbedtls_ripemd160_info;
  149|       |#endif
  150|       |#if defined(MBEDTLS_MD_CAN_SHA1)
  151|       |        case MBEDTLS_MD_SHA1:
  152|       |            return &mbedtls_sha1_info;
  153|       |#endif
  154|       |#if defined(MBEDTLS_MD_CAN_SHA224)
  155|       |        case MBEDTLS_MD_SHA224:
  156|       |            return &mbedtls_sha224_info;
  157|       |#endif
  158|      0|#if defined(MBEDTLS_MD_CAN_SHA256)
  159|    314|        case MBEDTLS_MD_SHA256:
  ------------------
  |  Branch (159:9): [True: 314, False: 0]
  ------------------
  160|    314|            return &mbedtls_sha256_info;
  161|      0|#endif
  162|      0|#if defined(MBEDTLS_MD_CAN_SHA384)
  163|      0|        case MBEDTLS_MD_SHA384:
  ------------------
  |  Branch (163:9): [True: 0, False: 314]
  ------------------
  164|      0|            return &mbedtls_sha384_info;
  165|      0|#endif
  166|      0|#if defined(MBEDTLS_MD_CAN_SHA512)
  167|      0|        case MBEDTLS_MD_SHA512:
  ------------------
  |  Branch (167:9): [True: 0, False: 314]
  ------------------
  168|      0|            return &mbedtls_sha512_info;
  169|      0|#endif
  170|      0|#if defined(MBEDTLS_MD_CAN_SHA3_224)
  171|      0|        case MBEDTLS_MD_SHA3_224:
  ------------------
  |  Branch (171:9): [True: 0, False: 314]
  ------------------
  172|      0|            return &mbedtls_sha3_224_info;
  173|      0|#endif
  174|      0|#if defined(MBEDTLS_MD_CAN_SHA3_256)
  175|      0|        case MBEDTLS_MD_SHA3_256:
  ------------------
  |  Branch (175:9): [True: 0, False: 314]
  ------------------
  176|      0|            return &mbedtls_sha3_256_info;
  177|      0|#endif
  178|      0|#if defined(MBEDTLS_MD_CAN_SHA3_384)
  179|      0|        case MBEDTLS_MD_SHA3_384:
  ------------------
  |  Branch (179:9): [True: 0, False: 314]
  ------------------
  180|      0|            return &mbedtls_sha3_384_info;
  181|      0|#endif
  182|      0|#if defined(MBEDTLS_MD_CAN_SHA3_512)
  183|      0|        case MBEDTLS_MD_SHA3_512:
  ------------------
  |  Branch (183:9): [True: 0, False: 314]
  ------------------
  184|      0|            return &mbedtls_sha3_512_info;
  185|      0|#endif
  186|      0|        default:
  ------------------
  |  Branch (186:9): [True: 0, False: 314]
  ------------------
  187|      0|            return NULL;
  188|    314|    }
  189|    314|}
mbedtls_md:
  687|    314|{
  688|    314|    if (md_info == NULL) {
  ------------------
  |  Branch (688:9): [True: 0, False: 314]
  ------------------
  689|      0|        return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MD_BAD_INPUT_DATA                     -0x5100
  ------------------
  690|      0|    }
  691|       |
  692|       |#if defined(MBEDTLS_MD_SOME_PSA)
  693|       |    if (md_can_use_psa(md_info)) {
  694|       |        size_t size = md_info->size;
  695|       |        psa_status_t status = psa_hash_compute(psa_alg_of_md(md_info),
  696|       |                                               input, ilen,
  697|       |                                               output, size, &size);
  698|       |        return mbedtls_md_error_from_psa(status);
  699|       |    }
  700|       |#endif
  701|       |
  702|    314|    switch (md_info->type) {
  703|       |#if defined(MBEDTLS_MD5_C)
  704|       |        case MBEDTLS_MD_MD5:
  705|       |            return mbedtls_md5(input, ilen, output);
  706|       |#endif
  707|       |#if defined(MBEDTLS_RIPEMD160_C)
  708|       |        case MBEDTLS_MD_RIPEMD160:
  709|       |            return mbedtls_ripemd160(input, ilen, output);
  710|       |#endif
  711|       |#if defined(MBEDTLS_SHA1_C)
  712|       |        case MBEDTLS_MD_SHA1:
  713|       |            return mbedtls_sha1(input, ilen, output);
  714|       |#endif
  715|       |#if defined(MBEDTLS_SHA224_C)
  716|       |        case MBEDTLS_MD_SHA224:
  717|       |            return mbedtls_sha256(input, ilen, output, 1);
  718|       |#endif
  719|      0|#if defined(MBEDTLS_SHA256_C)
  720|    314|        case MBEDTLS_MD_SHA256:
  ------------------
  |  Branch (720:9): [True: 314, False: 0]
  ------------------
  721|    314|            return mbedtls_sha256(input, ilen, output, 0);
  722|      0|#endif
  723|      0|#if defined(MBEDTLS_SHA384_C)
  724|      0|        case MBEDTLS_MD_SHA384:
  ------------------
  |  Branch (724:9): [True: 0, False: 314]
  ------------------
  725|      0|            return mbedtls_sha512(input, ilen, output, 1);
  726|      0|#endif
  727|      0|#if defined(MBEDTLS_SHA512_C)
  728|      0|        case MBEDTLS_MD_SHA512:
  ------------------
  |  Branch (728:9): [True: 0, False: 314]
  ------------------
  729|      0|            return mbedtls_sha512(input, ilen, output, 0);
  730|      0|#endif
  731|      0|#if defined(MBEDTLS_SHA3_C)
  732|      0|        case MBEDTLS_MD_SHA3_224:
  ------------------
  |  Branch (732:9): [True: 0, False: 314]
  ------------------
  733|      0|            return mbedtls_sha3(MBEDTLS_SHA3_224, input, ilen, output, md_info->size);
  734|      0|        case MBEDTLS_MD_SHA3_256:
  ------------------
  |  Branch (734:9): [True: 0, False: 314]
  ------------------
  735|      0|            return mbedtls_sha3(MBEDTLS_SHA3_256, input, ilen, output, md_info->size);
  736|      0|        case MBEDTLS_MD_SHA3_384:
  ------------------
  |  Branch (736:9): [True: 0, False: 314]
  ------------------
  737|      0|            return mbedtls_sha3(MBEDTLS_SHA3_384, input, ilen, output, md_info->size);
  738|      0|        case MBEDTLS_MD_SHA3_512:
  ------------------
  |  Branch (738:9): [True: 0, False: 314]
  ------------------
  739|      0|            return mbedtls_sha3(MBEDTLS_SHA3_512, input, ilen, output, md_info->size);
  740|      0|#endif
  741|      0|        default:
  ------------------
  |  Branch (741:9): [True: 0, False: 314]
  ------------------
  742|      0|            return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MD_BAD_INPUT_DATA                     -0x5100
  ------------------
  743|    314|    }
  744|    314|}
mbedtls_md_get_size:
  747|    314|{
  748|    314|    if (md_info == NULL) {
  ------------------
  |  Branch (748:9): [True: 0, False: 314]
  ------------------
  749|      0|        return 0;
  750|      0|    }
  751|       |
  752|    314|    return md_info->size;
  753|    314|}

mbedtls_oid_get_x509_ext_type:
   84|  13.0k|    {                                                                       \
   85|  13.0k|        const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1(oid);        \
   86|  13.0k|        if (data == NULL) return MBEDTLS_ERR_OID_NOT_FOUND;            \
  ------------------
  |  |   28|  1.72k|#define MBEDTLS_ERR_OID_NOT_FOUND                         -0x002E
  ------------------
  |  Branch (86:13): [True: 1.72k, False: 11.3k]
  ------------------
   87|  13.0k|        *ATTR1 = data->ATTR1;                                               \
   88|  11.3k|        return 0;                                                        \
   89|  13.0k|    }
mbedtls_oid_get_sig_alg:
   99|  2.51k|    {                                                                           \
  100|  2.51k|        const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1(oid);            \
  101|  2.51k|        if (data == NULL) return MBEDTLS_ERR_OID_NOT_FOUND;                 \
  ------------------
  |  |   28|      0|#define MBEDTLS_ERR_OID_NOT_FOUND                         -0x002E
  ------------------
  |  Branch (101:13): [True: 0, False: 2.51k]
  ------------------
  102|  2.51k|        *(ATTR1) = data->ATTR1;                                                 \
  103|  2.51k|        *(ATTR2) = data->ATTR2;                                                 \
  104|  2.51k|        return 0;                                                            \
  105|  2.51k|    }
mbedtls_oid_get_pk_alg:
   84|  2.51k|    {                                                                       \
   85|  2.51k|        const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1(oid);        \
   86|  2.51k|        if (data == NULL) return MBEDTLS_ERR_OID_NOT_FOUND;            \
  ------------------
  |  |   28|      0|#define MBEDTLS_ERR_OID_NOT_FOUND                         -0x002E
  ------------------
  |  Branch (86:13): [True: 0, False: 2.51k]
  ------------------
   87|  2.51k|        *ATTR1 = data->ATTR1;                                               \
   88|  2.51k|        return 0;                                                        \
   89|  2.51k|    }
mbedtls_oid_get_ec_grp:
   84|  2.51k|    {                                                                       \
   85|  2.51k|        const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1(oid);        \
   86|  2.51k|        if (data == NULL) return MBEDTLS_ERR_OID_NOT_FOUND;            \
  ------------------
  |  |   28|      0|#define MBEDTLS_ERR_OID_NOT_FOUND                         -0x002E
  ------------------
  |  Branch (86:13): [True: 0, False: 2.51k]
  ------------------
   87|  2.51k|        *ATTR1 = data->ATTR1;                                               \
   88|  2.51k|        return 0;                                                        \
   89|  2.51k|    }
oid.c:oid_x509_ext_from_asn1:
   47|  13.0k|    {                                                                   \
   48|  13.0k|        const TYPE_T *p = (LIST);                                       \
   49|  13.0k|        const mbedtls_oid_descriptor_t *cur =                           \
   50|  13.0k|            (const mbedtls_oid_descriptor_t *) p;                       \
   51|  13.0k|        if (p == NULL || oid == NULL) return NULL;                  \
  ------------------
  |  Branch (51:13): [True: 0, False: 13.0k]
  |  Branch (51:26): [True: 0, False: 13.0k]
  ------------------
   52|  56.5k|        while (cur->asn1 != NULL) {                                    \
  ------------------
  |  Branch (52:16): [True: 54.7k, False: 1.72k]
  ------------------
   53|  54.7k|            if (cur->asn1_len == oid->len &&                            \
  ------------------
  |  Branch (53:17): [True: 37.9k, False: 16.7k]
  ------------------
   54|  54.7k|                memcmp(cur->asn1, oid->p, oid->len) == 0) {          \
  ------------------
  |  Branch (54:17): [True: 11.3k, False: 26.6k]
  ------------------
   55|  11.3k|                return p;                                            \
   56|  11.3k|            }                                                           \
   57|  54.7k|            p++;                                                        \
   58|  43.4k|            cur = (const mbedtls_oid_descriptor_t *) p;                 \
   59|  43.4k|        }                                                               \
   60|  13.0k|        return NULL;                                                 \
   61|  13.0k|    }
oid.c:oid_sig_alg_from_asn1:
   47|  2.51k|    {                                                                   \
   48|  2.51k|        const TYPE_T *p = (LIST);                                       \
   49|  2.51k|        const mbedtls_oid_descriptor_t *cur =                           \
   50|  2.51k|            (const mbedtls_oid_descriptor_t *) p;                       \
   51|  2.51k|        if (p == NULL || oid == NULL) return NULL;                  \
  ------------------
  |  Branch (51:13): [True: 0, False: 2.51k]
  |  Branch (51:26): [True: 0, False: 2.51k]
  ------------------
   52|  10.0k|        while (cur->asn1 != NULL) {                                    \
  ------------------
  |  Branch (52:16): [True: 10.0k, False: 0]
  ------------------
   53|  10.0k|            if (cur->asn1_len == oid->len &&                            \
  ------------------
  |  Branch (53:17): [True: 2.51k, False: 7.53k]
  ------------------
   54|  10.0k|                memcmp(cur->asn1, oid->p, oid->len) == 0) {          \
  ------------------
  |  Branch (54:17): [True: 2.51k, False: 0]
  ------------------
   55|  2.51k|                return p;                                            \
   56|  2.51k|            }                                                           \
   57|  10.0k|            p++;                                                        \
   58|  7.53k|            cur = (const mbedtls_oid_descriptor_t *) p;                 \
   59|  7.53k|        }                                                               \
   60|  2.51k|        return NULL;                                                 \
   61|  2.51k|    }
oid.c:oid_pk_alg_from_asn1:
   47|  2.51k|    {                                                                   \
   48|  2.51k|        const TYPE_T *p = (LIST);                                       \
   49|  2.51k|        const mbedtls_oid_descriptor_t *cur =                           \
   50|  2.51k|            (const mbedtls_oid_descriptor_t *) p;                       \
   51|  2.51k|        if (p == NULL || oid == NULL) return NULL;                  \
  ------------------
  |  Branch (51:13): [True: 0, False: 2.51k]
  |  Branch (51:26): [True: 0, False: 2.51k]
  ------------------
   52|  5.02k|        while (cur->asn1 != NULL) {                                    \
  ------------------
  |  Branch (52:16): [True: 5.02k, False: 0]
  ------------------
   53|  5.02k|            if (cur->asn1_len == oid->len &&                            \
  ------------------
  |  Branch (53:17): [True: 2.51k, False: 2.51k]
  ------------------
   54|  5.02k|                memcmp(cur->asn1, oid->p, oid->len) == 0) {          \
  ------------------
  |  Branch (54:17): [True: 2.51k, False: 0]
  ------------------
   55|  2.51k|                return p;                                            \
   56|  2.51k|            }                                                           \
   57|  5.02k|            p++;                                                        \
   58|  2.51k|            cur = (const mbedtls_oid_descriptor_t *) p;                 \
   59|  2.51k|        }                                                               \
   60|  2.51k|        return NULL;                                                 \
   61|  2.51k|    }
oid.c:oid_grp_id_from_asn1:
   47|  2.51k|    {                                                                   \
   48|  2.51k|        const TYPE_T *p = (LIST);                                       \
   49|  2.51k|        const mbedtls_oid_descriptor_t *cur =                           \
   50|  2.51k|            (const mbedtls_oid_descriptor_t *) p;                       \
   51|  2.51k|        if (p == NULL || oid == NULL) return NULL;                  \
  ------------------
  |  Branch (51:13): [True: 0, False: 2.51k]
  |  Branch (51:26): [True: 0, False: 2.51k]
  ------------------
   52|  7.53k|        while (cur->asn1 != NULL) {                                    \
  ------------------
  |  Branch (52:16): [True: 7.53k, False: 0]
  ------------------
   53|  7.53k|            if (cur->asn1_len == oid->len &&                            \
  ------------------
  |  Branch (53:17): [True: 5.02k, False: 2.51k]
  ------------------
   54|  7.53k|                memcmp(cur->asn1, oid->p, oid->len) == 0) {          \
  ------------------
  |  Branch (54:17): [True: 2.51k, False: 2.51k]
  ------------------
   55|  2.51k|                return p;                                            \
   56|  2.51k|            }                                                           \
   57|  7.53k|            p++;                                                        \
   58|  5.02k|            cur = (const mbedtls_oid_descriptor_t *) p;                 \
   59|  5.02k|        }                                                               \
   60|  2.51k|        return NULL;                                                 \
   61|  2.51k|    }

mbedtls_pk_free:
   64|  2.51k|{
   65|  2.51k|    if (ctx == NULL) {
  ------------------
  |  Branch (65:9): [True: 0, False: 2.51k]
  ------------------
   66|      0|        return;
   67|      0|    }
   68|       |
   69|  2.51k|    if ((ctx->pk_info != NULL) && (ctx->pk_info->ctx_free_func != NULL)) {
  ------------------
  |  Branch (69:9): [True: 2.51k, False: 0]
  |  Branch (69:35): [True: 2.51k, False: 0]
  ------------------
   70|  2.51k|        ctx->pk_info->ctx_free_func(ctx->pk_ctx);
   71|  2.51k|    }
   72|       |
   73|       |#if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
   74|       |    /* The ownership of the priv_id key for opaque keys is external of the PK
   75|       |     * module. It's the user responsibility to clear it after use. */
   76|       |    if ((ctx->pk_info != NULL) && (ctx->pk_info->type != MBEDTLS_PK_OPAQUE)) {
   77|       |        psa_destroy_key(ctx->priv_id);
   78|       |    }
   79|       |#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
   80|       |
   81|  2.51k|    mbedtls_platform_zeroize(ctx, sizeof(mbedtls_pk_context));
   82|  2.51k|}
mbedtls_pk_info_from_type:
  115|  2.51k|{
  116|  2.51k|    switch (pk_type) {
  117|      0|#if defined(MBEDTLS_RSA_C)
  118|      0|        case MBEDTLS_PK_RSA:
  ------------------
  |  Branch (118:9): [True: 0, False: 2.51k]
  ------------------
  119|      0|            return &mbedtls_rsa_info;
  120|      0|#endif /* MBEDTLS_RSA_C */
  121|      0|#if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
  122|  2.51k|        case MBEDTLS_PK_ECKEY:
  ------------------
  |  Branch (122:9): [True: 2.51k, False: 0]
  ------------------
  123|  2.51k|            return &mbedtls_eckey_info;
  124|      0|        case MBEDTLS_PK_ECKEY_DH:
  ------------------
  |  Branch (124:9): [True: 0, False: 2.51k]
  ------------------
  125|      0|            return &mbedtls_eckeydh_info;
  126|      0|#endif /* MBEDTLS_PK_HAVE_ECC_KEYS */
  127|      0|#if defined(MBEDTLS_PK_CAN_ECDSA_SOME)
  128|      0|        case MBEDTLS_PK_ECDSA:
  ------------------
  |  Branch (128:9): [True: 0, False: 2.51k]
  ------------------
  129|      0|            return &mbedtls_ecdsa_info;
  130|      0|#endif /* MBEDTLS_PK_CAN_ECDSA_SOME */
  131|       |        /* MBEDTLS_PK_RSA_ALT omitted on purpose */
  132|      0|        default:
  ------------------
  |  Branch (132:9): [True: 0, False: 2.51k]
  ------------------
  133|      0|            return NULL;
  134|  2.51k|    }
  135|  2.51k|}
mbedtls_pk_setup:
  141|  2.51k|{
  142|  2.51k|    if (info == NULL || ctx->pk_info != NULL) {
  ------------------
  |  Branch (142:9): [True: 0, False: 2.51k]
  |  Branch (142:25): [True: 0, False: 2.51k]
  ------------------
  143|      0|        return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
  ------------------
  |  |   40|      0|#define MBEDTLS_ERR_PK_BAD_INPUT_DATA      -0x3E80
  ------------------
  144|      0|    }
  145|       |
  146|  2.51k|    if ((info->ctx_alloc_func != NULL) &&
  ------------------
  |  Branch (146:9): [True: 2.51k, False: 0]
  ------------------
  147|  2.51k|        ((ctx->pk_ctx = info->ctx_alloc_func()) == NULL)) {
  ------------------
  |  Branch (147:9): [True: 0, False: 2.51k]
  ------------------
  148|      0|        return MBEDTLS_ERR_PK_ALLOC_FAILED;
  ------------------
  |  |   36|      0|#define MBEDTLS_ERR_PK_ALLOC_FAILED        -0x3F80
  ------------------
  149|      0|    }
  150|       |
  151|  2.51k|    ctx->pk_info = info;
  152|       |
  153|  2.51k|    return 0;
  154|  2.51k|}
mbedtls_pk_can_do:
  232|    628|{
  233|       |    /* A context with null pk_info is not set up yet and can't do anything.
  234|       |     * For backward compatibility, also accept NULL instead of a context
  235|       |     * pointer. */
  236|    628|    if (ctx == NULL || ctx->pk_info == NULL) {
  ------------------
  |  Branch (236:9): [True: 0, False: 628]
  |  Branch (236:24): [True: 0, False: 628]
  ------------------
  237|      0|        return 0;
  238|      0|    }
  239|       |
  240|    628|    return ctx->pk_info->can_do(type);
  241|    628|}
mbedtls_pk_verify_restartable:
 1047|    314|{
 1048|    314|    if ((md_alg != MBEDTLS_MD_NONE || hash_len != 0) && hash == NULL) {
  ------------------
  |  Branch (1048:10): [True: 314, False: 0]
  |  Branch (1048:39): [True: 0, False: 0]
  |  Branch (1048:57): [True: 0, False: 314]
  ------------------
 1049|      0|        return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
  ------------------
  |  |   40|      0|#define MBEDTLS_ERR_PK_BAD_INPUT_DATA      -0x3E80
  ------------------
 1050|      0|    }
 1051|       |
 1052|    314|    if (ctx->pk_info == NULL ||
  ------------------
  |  Branch (1052:9): [True: 0, False: 314]
  ------------------
 1053|    314|        pk_hashlen_helper(md_alg, &hash_len) != 0) {
  ------------------
  |  Branch (1053:9): [True: 0, False: 314]
  ------------------
 1054|      0|        return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
  ------------------
  |  |   40|      0|#define MBEDTLS_ERR_PK_BAD_INPUT_DATA      -0x3E80
  ------------------
 1055|      0|    }
 1056|       |
 1057|    314|#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
 1058|       |    /* optimization: use non-restartable version if restart disabled */
 1059|    314|    if (rs_ctx != NULL &&
  ------------------
  |  Branch (1059:9): [True: 0, False: 314]
  ------------------
 1060|    314|        mbedtls_ecp_restart_is_enabled() &&
  ------------------
  |  Branch (1060:9): [True: 0, False: 0]
  ------------------
 1061|    314|        ctx->pk_info->verify_rs_func != NULL) {
  ------------------
  |  Branch (1061:9): [True: 0, False: 0]
  ------------------
 1062|      0|        int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|      0|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1063|       |
 1064|      0|        if ((ret = pk_restart_setup(rs_ctx, ctx->pk_info)) != 0) {
  ------------------
  |  Branch (1064:13): [True: 0, False: 0]
  ------------------
 1065|      0|            return ret;
 1066|      0|        }
 1067|       |
 1068|      0|        ret = ctx->pk_info->verify_rs_func(ctx,
 1069|      0|                                           md_alg, hash, hash_len, sig, sig_len, rs_ctx->rs_ctx);
 1070|       |
 1071|      0|        if (ret != MBEDTLS_ERR_ECP_IN_PROGRESS) {
  ------------------
  |  |   51|      0|#define MBEDTLS_ERR_ECP_IN_PROGRESS                       -0x4B00
  ------------------
  |  Branch (1071:13): [True: 0, False: 0]
  ------------------
 1072|      0|            mbedtls_pk_restart_free(rs_ctx);
 1073|      0|        }
 1074|       |
 1075|      0|        return ret;
 1076|      0|    }
 1077|       |#else /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
 1078|       |    (void) rs_ctx;
 1079|       |#endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
 1080|       |
 1081|    314|    if (ctx->pk_info->verify_func == NULL) {
  ------------------
  |  Branch (1081:9): [True: 0, False: 314]
  ------------------
 1082|      0|        return MBEDTLS_ERR_PK_TYPE_MISMATCH;
  ------------------
  |  |   38|      0|#define MBEDTLS_ERR_PK_TYPE_MISMATCH       -0x3F00
  ------------------
 1083|      0|    }
 1084|       |
 1085|    314|    return ctx->pk_info->verify_func(ctx, md_alg, hash, hash_len,
 1086|    314|                                     sig, sig_len);
 1087|    314|}
mbedtls_pk_verify:
 1095|    314|{
 1096|    314|    return mbedtls_pk_verify_restartable(ctx, md_alg, hash, hash_len,
 1097|    314|                                         sig, sig_len, NULL);
 1098|    314|}
mbedtls_pk_verify_ext:
 1107|    314|{
 1108|    314|    if ((md_alg != MBEDTLS_MD_NONE || hash_len != 0) && hash == NULL) {
  ------------------
  |  Branch (1108:10): [True: 314, False: 0]
  |  Branch (1108:39): [True: 0, False: 0]
  |  Branch (1108:57): [True: 0, False: 314]
  ------------------
 1109|      0|        return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
  ------------------
  |  |   40|      0|#define MBEDTLS_ERR_PK_BAD_INPUT_DATA      -0x3E80
  ------------------
 1110|      0|    }
 1111|       |
 1112|    314|    if (ctx->pk_info == NULL) {
  ------------------
  |  Branch (1112:9): [True: 0, False: 314]
  ------------------
 1113|      0|        return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
  ------------------
  |  |   40|      0|#define MBEDTLS_ERR_PK_BAD_INPUT_DATA      -0x3E80
  ------------------
 1114|      0|    }
 1115|       |
 1116|    314|    if (!mbedtls_pk_can_do(ctx, type)) {
  ------------------
  |  Branch (1116:9): [True: 0, False: 314]
  ------------------
 1117|      0|        return MBEDTLS_ERR_PK_TYPE_MISMATCH;
  ------------------
  |  |   38|      0|#define MBEDTLS_ERR_PK_TYPE_MISMATCH       -0x3F00
  ------------------
 1118|      0|    }
 1119|       |
 1120|    314|    if (type != MBEDTLS_PK_RSASSA_PSS) {
  ------------------
  |  Branch (1120:9): [True: 314, False: 0]
  ------------------
 1121|       |        /* General case: no options */
 1122|    314|        if (options != NULL) {
  ------------------
  |  Branch (1122:13): [True: 0, False: 314]
  ------------------
 1123|      0|            return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
  ------------------
  |  |   40|      0|#define MBEDTLS_ERR_PK_BAD_INPUT_DATA      -0x3E80
  ------------------
 1124|      0|        }
 1125|       |
 1126|    314|        return mbedtls_pk_verify(ctx, md_alg, hash, hash_len, sig, sig_len);
 1127|    314|    }
 1128|       |
 1129|       |    /* Ensure the PK context is of the right type otherwise mbedtls_pk_rsa()
 1130|       |     * below would return a NULL pointer. */
 1131|      0|    if (mbedtls_pk_get_type(ctx) != MBEDTLS_PK_RSA) {
  ------------------
  |  Branch (1131:9): [True: 0, False: 0]
  ------------------
 1132|      0|        return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE;
  ------------------
  |  |   60|      0|#define MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE -0x3980
  ------------------
 1133|      0|    }
 1134|       |
 1135|      0|#if defined(MBEDTLS_RSA_C) && defined(MBEDTLS_PKCS1_V21)
 1136|      0|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|      0|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1137|      0|    const mbedtls_pk_rsassa_pss_options *pss_opts;
 1138|       |
 1139|      0|#if SIZE_MAX > UINT_MAX
 1140|      0|    if (md_alg == MBEDTLS_MD_NONE && UINT_MAX < hash_len) {
  ------------------
  |  Branch (1140:9): [True: 0, False: 0]
  |  Branch (1140:38): [True: 0, False: 0]
  ------------------
 1141|      0|        return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
  ------------------
  |  |   40|      0|#define MBEDTLS_ERR_PK_BAD_INPUT_DATA      -0x3E80
  ------------------
 1142|      0|    }
 1143|      0|#endif
 1144|       |
 1145|      0|    if (options == NULL) {
  ------------------
  |  Branch (1145:9): [True: 0, False: 0]
  ------------------
 1146|      0|        return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
  ------------------
  |  |   40|      0|#define MBEDTLS_ERR_PK_BAD_INPUT_DATA      -0x3E80
  ------------------
 1147|      0|    }
 1148|       |
 1149|      0|    pss_opts = (const mbedtls_pk_rsassa_pss_options *) options;
 1150|       |
 1151|       |#if defined(MBEDTLS_USE_PSA_CRYPTO)
 1152|       |    if (pss_opts->mgf1_hash_id == md_alg) {
 1153|       |        unsigned char buf[MBEDTLS_PK_RSA_PUB_DER_MAX_BYTES];
 1154|       |        unsigned char *p;
 1155|       |        int key_len;
 1156|       |        size_t signature_length;
 1157|       |        psa_status_t status = PSA_ERROR_DATA_CORRUPT;
 1158|       |        psa_status_t destruction_status = PSA_ERROR_DATA_CORRUPT;
 1159|       |
 1160|       |        psa_algorithm_t psa_md_alg = mbedtls_md_psa_alg_from_type(md_alg);
 1161|       |        mbedtls_svc_key_id_t key_id = MBEDTLS_SVC_KEY_ID_INIT;
 1162|       |        psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
 1163|       |        psa_algorithm_t psa_sig_alg = PSA_ALG_RSA_PSS_ANY_SALT(psa_md_alg);
 1164|       |        p = buf + sizeof(buf);
 1165|       |        key_len = mbedtls_rsa_write_pubkey(mbedtls_pk_rsa(*ctx), buf, &p);
 1166|       |
 1167|       |        if (key_len < 0) {
 1168|       |            return key_len;
 1169|       |        }
 1170|       |
 1171|       |        psa_set_key_type(&attributes, PSA_KEY_TYPE_RSA_PUBLIC_KEY);
 1172|       |        psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_VERIFY_HASH);
 1173|       |        psa_set_key_algorithm(&attributes, psa_sig_alg);
 1174|       |
 1175|       |        status = psa_import_key(&attributes,
 1176|       |                                buf + sizeof(buf) - key_len, key_len,
 1177|       |                                &key_id);
 1178|       |        if (status != PSA_SUCCESS) {
 1179|       |            psa_destroy_key(key_id);
 1180|       |            return PSA_PK_TO_MBEDTLS_ERR(status);
 1181|       |        }
 1182|       |
 1183|       |        /* This function requires returning MBEDTLS_ERR_PK_SIG_LEN_MISMATCH
 1184|       |         * on a valid signature with trailing data in a buffer, but
 1185|       |         * mbedtls_psa_rsa_verify_hash requires the sig_len to be exact,
 1186|       |         * so for this reason the passed sig_len is overwritten. Smaller
 1187|       |         * signature lengths should not be accepted for verification. */
 1188|       |        signature_length = sig_len > mbedtls_pk_get_len(ctx) ?
 1189|       |                           mbedtls_pk_get_len(ctx) : sig_len;
 1190|       |        status = psa_verify_hash(key_id, psa_sig_alg, hash,
 1191|       |                                 hash_len, sig, signature_length);
 1192|       |        destruction_status = psa_destroy_key(key_id);
 1193|       |
 1194|       |        if (status == PSA_SUCCESS && sig_len > mbedtls_pk_get_len(ctx)) {
 1195|       |            return MBEDTLS_ERR_PK_SIG_LEN_MISMATCH;
 1196|       |        }
 1197|       |
 1198|       |        if (status == PSA_SUCCESS) {
 1199|       |            status = destruction_status;
 1200|       |        }
 1201|       |
 1202|       |        return PSA_PK_RSA_TO_MBEDTLS_ERR(status);
 1203|       |    } else
 1204|       |#endif /* MBEDTLS_USE_PSA_CRYPTO */
 1205|      0|    {
 1206|      0|        if (sig_len < mbedtls_pk_get_len(ctx)) {
  ------------------
  |  Branch (1206:13): [True: 0, False: 0]
  ------------------
 1207|      0|            return MBEDTLS_ERR_RSA_VERIFY_FAILED;
  ------------------
  |  |   45|      0|#define MBEDTLS_ERR_RSA_VERIFY_FAILED                     -0x4380
  ------------------
 1208|      0|        }
 1209|       |
 1210|      0|        ret = mbedtls_rsa_rsassa_pss_verify_ext(mbedtls_pk_rsa(*ctx),
 1211|      0|                                                md_alg, (unsigned int) hash_len, hash,
 1212|      0|                                                pss_opts->mgf1_hash_id,
 1213|      0|                                                pss_opts->expected_salt_len,
 1214|      0|                                                sig);
 1215|      0|        if (ret != 0) {
  ------------------
  |  Branch (1215:13): [True: 0, False: 0]
  ------------------
 1216|      0|            return ret;
 1217|      0|        }
 1218|       |
 1219|      0|        if (sig_len > mbedtls_pk_get_len(ctx)) {
  ------------------
  |  Branch (1219:13): [True: 0, False: 0]
  ------------------
 1220|      0|            return MBEDTLS_ERR_PK_SIG_LEN_MISMATCH;
  ------------------
  |  |   62|      0|#define MBEDTLS_ERR_PK_SIG_LEN_MISMATCH    -0x3900
  ------------------
 1221|      0|        }
 1222|       |
 1223|      0|        return 0;
 1224|      0|    }
 1225|       |#else
 1226|       |    return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE;
 1227|       |#endif /* MBEDTLS_RSA_C && MBEDTLS_PKCS1_V21 */
 1228|      0|}
mbedtls_pk_get_type:
 1499|  7.37k|{
 1500|  7.37k|    if (ctx == NULL || ctx->pk_info == NULL) {
  ------------------
  |  Branch (1500:9): [True: 0, False: 7.37k]
  |  Branch (1500:24): [True: 0, False: 7.37k]
  ------------------
 1501|      0|        return MBEDTLS_PK_NONE;
 1502|      0|    }
 1503|       |
 1504|  7.37k|    return ctx->pk_info->type;
 1505|  7.37k|}
pk.c:pk_hashlen_helper:
  998|    314|{
  999|    314|    if (*hash_len != 0) {
  ------------------
  |  Branch (999:9): [True: 314, False: 0]
  ------------------
 1000|    314|        return 0;
 1001|    314|    }
 1002|       |
 1003|      0|    *hash_len = mbedtls_md_get_size_from_type(md_alg);
 1004|       |
 1005|      0|    if (*hash_len == 0) {
  ------------------
  |  Branch (1005:9): [True: 0, False: 0]
  ------------------
 1006|      0|        return -1;
 1007|      0|    }
 1008|       |
 1009|      0|    return 0;
 1010|      0|}

mbedtls_pk_ecc_set_group:
   18|  2.51k|{
   19|       |#if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
   20|       |    size_t ec_bits;
   21|       |    psa_ecc_family_t ec_family = mbedtls_ecc_group_to_psa(grp_id, &ec_bits);
   22|       |
   23|       |    /* group may already be initialized; if so, make sure IDs match */
   24|       |    if ((pk->ec_family != 0 && pk->ec_family != ec_family) ||
   25|       |        (pk->ec_bits != 0 && pk->ec_bits != ec_bits)) {
   26|       |        return MBEDTLS_ERR_PK_KEY_INVALID_FORMAT;
   27|       |    }
   28|       |
   29|       |    /* set group */
   30|       |    pk->ec_family = ec_family;
   31|       |    pk->ec_bits = ec_bits;
   32|       |
   33|       |    return 0;
   34|       |#else /* MBEDTLS_PK_USE_PSA_EC_DATA */
   35|  2.51k|    mbedtls_ecp_keypair *ecp = mbedtls_pk_ec_rw(*pk);
   36|       |
   37|       |    /* grp may already be initialized; if so, make sure IDs match */
   38|  2.51k|    if (mbedtls_pk_ec_ro(*pk)->grp.id != MBEDTLS_ECP_DP_NONE &&
  ------------------
  |  Branch (38:9): [True: 0, False: 2.51k]
  ------------------
   39|  2.51k|        mbedtls_pk_ec_ro(*pk)->grp.id != grp_id) {
  ------------------
  |  Branch (39:9): [True: 0, False: 0]
  ------------------
   40|      0|        return MBEDTLS_ERR_PK_KEY_INVALID_FORMAT;
  ------------------
  |  |   46|      0|#define MBEDTLS_ERR_PK_KEY_INVALID_FORMAT  -0x3D00
  ------------------
   41|      0|    }
   42|       |
   43|       |    /* set group */
   44|  2.51k|    return mbedtls_ecp_group_load(&(ecp->grp), grp_id);
   45|  2.51k|#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
   46|  2.51k|}
mbedtls_pk_ecc_set_pubkey:
  205|  2.51k|{
  206|       |#if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
  207|       |
  208|       |    /* Load the key */
  209|       |    if (!PSA_ECC_FAMILY_IS_WEIERSTRASS(pk->ec_family) || *pub == 0x04) {
  210|       |        /* Format directly supported by PSA:
  211|       |         * - non-Weierstrass curves that only have one format;
  212|       |         * - uncompressed format for Weierstrass curves. */
  213|       |        if (pub_len > sizeof(pk->pub_raw)) {
  214|       |            return MBEDTLS_ERR_PK_BUFFER_TOO_SMALL;
  215|       |        }
  216|       |        memcpy(pk->pub_raw, pub, pub_len);
  217|       |        pk->pub_raw_len = pub_len;
  218|       |    } else {
  219|       |        /* Other format, try the fallback */
  220|       |        int ret = pk_ecc_set_pubkey_psa_ecp_fallback(pk, pub, pub_len);
  221|       |        if (ret != 0) {
  222|       |            return ret;
  223|       |        }
  224|       |    }
  225|       |
  226|       |    /* Validate the key by trying to import it */
  227|       |    mbedtls_svc_key_id_t key_id = MBEDTLS_SVC_KEY_ID_INIT;
  228|       |    psa_key_attributes_t key_attrs = PSA_KEY_ATTRIBUTES_INIT;
  229|       |
  230|       |    psa_set_key_usage_flags(&key_attrs, 0);
  231|       |    psa_set_key_type(&key_attrs, PSA_KEY_TYPE_ECC_PUBLIC_KEY(pk->ec_family));
  232|       |    psa_set_key_bits(&key_attrs, pk->ec_bits);
  233|       |
  234|       |    if ((psa_import_key(&key_attrs, pk->pub_raw, pk->pub_raw_len,
  235|       |                        &key_id) != PSA_SUCCESS) ||
  236|       |        (psa_destroy_key(key_id) != PSA_SUCCESS)) {
  237|       |        return MBEDTLS_ERR_PK_INVALID_PUBKEY;
  238|       |    }
  239|       |
  240|       |    return 0;
  241|       |
  242|       |#else /* MBEDTLS_PK_USE_PSA_EC_DATA */
  243|       |
  244|  2.51k|    int ret;
  245|  2.51k|    mbedtls_ecp_keypair *ec_key = (mbedtls_ecp_keypair *) pk->pk_ctx;
  246|  2.51k|    ret = mbedtls_ecp_point_read_binary(&ec_key->grp, &ec_key->Q, pub, pub_len);
  247|  2.51k|    if (ret != 0) {
  ------------------
  |  Branch (247:9): [True: 0, False: 2.51k]
  ------------------
  248|      0|        return ret;
  249|      0|    }
  250|  2.51k|    return mbedtls_ecp_check_pubkey(&ec_key->grp, &ec_key->Q);
  251|       |
  252|  2.51k|#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
  253|  2.51k|}

x509_crt.c:mbedtls_pk_get_ec_group_id:
   87|    785|{
   88|    785|    mbedtls_ecp_group_id id;
   89|       |
   90|       |#if defined(MBEDTLS_USE_PSA_CRYPTO)
   91|       |    if (mbedtls_pk_get_type(pk) == MBEDTLS_PK_OPAQUE) {
   92|       |        psa_key_attributes_t opaque_attrs = PSA_KEY_ATTRIBUTES_INIT;
   93|       |        psa_key_type_t opaque_key_type;
   94|       |        psa_ecc_family_t curve;
   95|       |
   96|       |        if (psa_get_key_attributes(pk->priv_id, &opaque_attrs) != PSA_SUCCESS) {
   97|       |            return MBEDTLS_ECP_DP_NONE;
   98|       |        }
   99|       |        opaque_key_type = psa_get_key_type(&opaque_attrs);
  100|       |        curve = PSA_KEY_TYPE_ECC_GET_FAMILY(opaque_key_type);
  101|       |        id = mbedtls_ecc_group_from_psa(curve, psa_get_key_bits(&opaque_attrs));
  102|       |        psa_reset_key_attributes(&opaque_attrs);
  103|       |    } else
  104|       |#endif /* MBEDTLS_USE_PSA_CRYPTO */
  105|    785|    {
  106|       |#if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
  107|       |        id = mbedtls_ecc_group_from_psa(pk->ec_family, pk->ec_bits);
  108|       |#else /* MBEDTLS_PK_USE_PSA_EC_DATA */
  109|    785|        id = mbedtls_pk_ec_ro(*pk)->grp.id;
  110|    785|#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
  111|    785|    }
  112|       |
  113|    785|    return id;
  114|    785|}
x509_crt.c:mbedtls_pk_ec_ro:
   61|    785|{
   62|    785|    switch (mbedtls_pk_get_type(&pk)) {
   63|    785|        case MBEDTLS_PK_ECKEY:
  ------------------
  |  Branch (63:9): [True: 785, False: 0]
  ------------------
   64|    785|        case MBEDTLS_PK_ECKEY_DH:
  ------------------
  |  Branch (64:9): [True: 0, False: 785]
  ------------------
   65|    785|        case MBEDTLS_PK_ECDSA:
  ------------------
  |  Branch (65:9): [True: 0, False: 785]
  ------------------
   66|    785|            return (const mbedtls_ecp_keypair *) (pk).MBEDTLS_PRIVATE(pk_ctx);
  ------------------
  |  |   17|    785|#define MBEDTLS_PRIVATE(member) member
  ------------------
   67|      0|        default:
  ------------------
  |  Branch (67:9): [True: 0, False: 785]
  ------------------
   68|      0|            return NULL;
   69|    785|    }
   70|    785|}
pk_ecc.c:mbedtls_pk_ec_rw:
   73|  2.51k|{
   74|  2.51k|    switch (mbedtls_pk_get_type(&pk)) {
   75|  2.51k|        case MBEDTLS_PK_ECKEY:
  ------------------
  |  Branch (75:9): [True: 2.51k, False: 0]
  ------------------
   76|  2.51k|        case MBEDTLS_PK_ECKEY_DH:
  ------------------
  |  Branch (76:9): [True: 0, False: 2.51k]
  ------------------
   77|  2.51k|        case MBEDTLS_PK_ECDSA:
  ------------------
  |  Branch (77:9): [True: 0, False: 2.51k]
  ------------------
   78|  2.51k|            return (mbedtls_ecp_keypair *) (pk).MBEDTLS_PRIVATE(pk_ctx);
  ------------------
  |  |   17|  2.51k|#define MBEDTLS_PRIVATE(member) member
  ------------------
   79|      0|        default:
  ------------------
  |  Branch (79:9): [True: 0, False: 2.51k]
  ------------------
   80|      0|            return NULL;
   81|  2.51k|    }
   82|  2.51k|}
pk_ecc.c:mbedtls_pk_ec_ro:
   61|  2.51k|{
   62|  2.51k|    switch (mbedtls_pk_get_type(&pk)) {
   63|  2.51k|        case MBEDTLS_PK_ECKEY:
  ------------------
  |  Branch (63:9): [True: 2.51k, False: 0]
  ------------------
   64|  2.51k|        case MBEDTLS_PK_ECKEY_DH:
  ------------------
  |  Branch (64:9): [True: 0, False: 2.51k]
  ------------------
   65|  2.51k|        case MBEDTLS_PK_ECDSA:
  ------------------
  |  Branch (65:9): [True: 0, False: 2.51k]
  ------------------
   66|  2.51k|            return (const mbedtls_ecp_keypair *) (pk).MBEDTLS_PRIVATE(pk_ctx);
  ------------------
  |  |   17|  2.51k|#define MBEDTLS_PRIVATE(member) member
  ------------------
   67|      0|        default:
  ------------------
  |  Branch (67:9): [True: 0, False: 2.51k]
  ------------------
   68|      0|            return NULL;
   69|  2.51k|    }
   70|  2.51k|}

pk_wrap.c:eckey_can_do:
  519|    628|{
  520|    628|    return type == MBEDTLS_PK_ECKEY ||
  ------------------
  |  Branch (520:12): [True: 0, False: 628]
  ------------------
  521|    628|           type == MBEDTLS_PK_ECKEY_DH ||
  ------------------
  |  Branch (521:12): [True: 0, False: 628]
  ------------------
  522|    628|           type == MBEDTLS_PK_ECDSA;
  ------------------
  |  Branch (522:12): [True: 628, False: 0]
  ------------------
  523|    628|}
pk_wrap.c:ecdsa_verify_wrap:
  674|    314|{
  675|    314|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|    314|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  676|    314|    ((void) md_alg);
  677|       |
  678|    314|    ret = mbedtls_ecdsa_read_signature((mbedtls_ecdsa_context *) pk->pk_ctx,
  679|    314|                                       hash, hash_len, sig, sig_len);
  680|       |
  681|    314|    if (ret == MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH) {
  ------------------
  |  |   49|    314|#define MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH                  -0x4C00
  ------------------
  |  Branch (681:9): [True: 0, False: 314]
  ------------------
  682|      0|        return MBEDTLS_ERR_PK_SIG_LEN_MISMATCH;
  ------------------
  |  |   62|      0|#define MBEDTLS_ERR_PK_SIG_LEN_MISMATCH    -0x3900
  ------------------
  683|      0|    }
  684|       |
  685|    314|    return ret;
  686|    314|}
pk_wrap.c:eckey_alloc_wrap:
 1082|  2.51k|{
 1083|  2.51k|    void *ctx = mbedtls_calloc(1, sizeof(mbedtls_ecp_keypair));
  ------------------
  |  |  144|  2.51k|#define mbedtls_calloc     MBEDTLS_PLATFORM_CALLOC_MACRO
  |  |  ------------------
  |  |  |  | 4093|  2.51k|#define MBEDTLS_PLATFORM_CALLOC_MACRO        my_calloc
  |  |  ------------------
  ------------------
 1084|       |
 1085|  2.51k|    if (ctx != NULL) {
  ------------------
  |  Branch (1085:9): [True: 2.51k, False: 0]
  ------------------
 1086|  2.51k|        mbedtls_ecp_keypair_init(ctx);
 1087|  2.51k|    }
 1088|       |
 1089|  2.51k|    return ctx;
 1090|  2.51k|}
pk_wrap.c:eckey_free_wrap:
 1093|  2.51k|{
 1094|  2.51k|    mbedtls_ecp_keypair_free((mbedtls_ecp_keypair *) ctx);
 1095|  2.51k|    mbedtls_free(ctx);
  ------------------
  |  |  143|  2.51k|#define mbedtls_free       MBEDTLS_PLATFORM_FREE_MACRO
  |  |  ------------------
  |  |  |  | 4095|  2.51k|#define MBEDTLS_PLATFORM_FREE_MACRO            my_free
  |  |  ------------------
  ------------------
 1096|  2.51k|}

mbedtls_pk_parse_subpubkey:
  519|  2.51k|{
  520|  2.51k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  2.51k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  521|  2.51k|    size_t len;
  522|  2.51k|    mbedtls_asn1_buf alg_params;
  523|  2.51k|    mbedtls_pk_type_t pk_alg = MBEDTLS_PK_NONE;
  524|  2.51k|    mbedtls_ecp_group_id ec_grp_id = MBEDTLS_ECP_DP_NONE;
  525|  2.51k|    const mbedtls_pk_info_t *pk_info;
  526|       |
  527|  2.51k|    if ((ret = mbedtls_asn1_get_tag(p, end, &len,
  ------------------
  |  Branch (527:9): [True: 0, False: 2.51k]
  ------------------
  528|  2.51k|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|  2.51k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|  2.51k|#define MBEDTLS_ASN1_SEQUENCE                0x10
  ------------------
  529|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  530|      0|    }
  531|       |
  532|  2.51k|    end = *p + len;
  533|       |
  534|  2.51k|    if ((ret = pk_get_pk_alg(p, end, &pk_alg, &alg_params, &ec_grp_id)) != 0) {
  ------------------
  |  Branch (534:9): [True: 0, False: 2.51k]
  ------------------
  535|      0|        return ret;
  536|      0|    }
  537|       |
  538|  2.51k|    if ((ret = mbedtls_asn1_get_bitstring_null(p, end, &len)) != 0) {
  ------------------
  |  Branch (538:9): [True: 0, False: 2.51k]
  ------------------
  539|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_INVALID_PUBKEY, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  540|      0|    }
  541|       |
  542|  2.51k|    if (*p + len != end) {
  ------------------
  |  Branch (542:9): [True: 0, False: 2.51k]
  ------------------
  543|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_INVALID_PUBKEY,
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  544|      0|                                 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
  545|      0|    }
  546|       |
  547|  2.51k|    if ((pk_info = mbedtls_pk_info_from_type(pk_alg)) == NULL) {
  ------------------
  |  Branch (547:9): [True: 0, False: 2.51k]
  ------------------
  548|      0|        return MBEDTLS_ERR_PK_UNKNOWN_PK_ALG;
  ------------------
  |  |   48|      0|#define MBEDTLS_ERR_PK_UNKNOWN_PK_ALG      -0x3C80
  ------------------
  549|      0|    }
  550|       |
  551|  2.51k|    if ((ret = mbedtls_pk_setup(pk, pk_info)) != 0) {
  ------------------
  |  Branch (551:9): [True: 0, False: 2.51k]
  ------------------
  552|      0|        return ret;
  553|      0|    }
  554|       |
  555|  2.51k|#if defined(MBEDTLS_RSA_C)
  556|  2.51k|    if (pk_alg == MBEDTLS_PK_RSA) {
  ------------------
  |  Branch (556:9): [True: 0, False: 2.51k]
  ------------------
  557|      0|        ret = mbedtls_rsa_parse_pubkey(mbedtls_pk_rsa(*pk), *p, (size_t) (end - *p));
  558|      0|        if (ret == 0) {
  ------------------
  |  Branch (558:13): [True: 0, False: 0]
  ------------------
  559|       |            /* On success all the input has been consumed by the parsing function. */
  560|      0|            *p += end - *p;
  561|      0|        } else if ((ret <= MBEDTLS_ERR_ASN1_OUT_OF_DATA) &&
  ------------------
  |  |   37|      0|#define MBEDTLS_ERR_ASN1_OUT_OF_DATA                      -0x0060
  ------------------
  |  Branch (561:20): [True: 0, False: 0]
  ------------------
  562|      0|                   (ret >= MBEDTLS_ERR_ASN1_BUF_TOO_SMALL)) {
  ------------------
  |  |   49|      0|#define MBEDTLS_ERR_ASN1_BUF_TOO_SMALL                    -0x006C
  ------------------
  |  Branch (562:20): [True: 0, False: 0]
  ------------------
  563|       |            /* In case of ASN1 error codes add MBEDTLS_ERR_PK_INVALID_PUBKEY. */
  564|      0|            ret = MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_INVALID_PUBKEY, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  565|      0|        } else {
  566|      0|            ret = MBEDTLS_ERR_PK_INVALID_PUBKEY;
  ------------------
  |  |   54|      0|#define MBEDTLS_ERR_PK_INVALID_PUBKEY      -0x3B00
  ------------------
  567|      0|        }
  568|      0|    } else
  569|  2.51k|#endif /* MBEDTLS_RSA_C */
  570|  2.51k|#if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
  571|  2.51k|    if (pk_alg == MBEDTLS_PK_ECKEY_DH || pk_alg == MBEDTLS_PK_ECKEY) {
  ------------------
  |  Branch (571:9): [True: 0, False: 2.51k]
  |  Branch (571:42): [True: 2.51k, False: 0]
  ------------------
  572|  2.51k|#if defined(MBEDTLS_PK_HAVE_RFC8410_CURVES)
  573|  2.51k|        if (MBEDTLS_PK_IS_RFC8410_GROUP_ID(ec_grp_id)) {
  ------------------
  |  |  122|  2.51k|    ((id == MBEDTLS_ECP_DP_CURVE25519) || (id == MBEDTLS_ECP_DP_CURVE448))
  |  |  ------------------
  |  |  |  Branch (122:6): [True: 0, False: 2.51k]
  |  |  |  Branch (122:43): [True: 0, False: 2.51k]
  |  |  ------------------
  ------------------
  574|      0|            ret = pk_use_ecparams_rfc8410(&alg_params, ec_grp_id, pk);
  575|      0|        } else
  576|  2.51k|#endif
  577|  2.51k|        {
  578|  2.51k|            ret = pk_use_ecparams(&alg_params, pk);
  579|  2.51k|        }
  580|  2.51k|        if (ret == 0) {
  ------------------
  |  Branch (580:13): [True: 2.51k, False: 0]
  ------------------
  581|  2.51k|            ret = mbedtls_pk_ecc_set_pubkey(pk, *p, (size_t) (end - *p));
  582|  2.51k|            *p += end - *p;
  583|  2.51k|        }
  584|  2.51k|    } else
  585|      0|#endif /* MBEDTLS_PK_HAVE_ECC_KEYS */
  586|      0|    ret = MBEDTLS_ERR_PK_UNKNOWN_PK_ALG;
  ------------------
  |  |   48|      0|#define MBEDTLS_ERR_PK_UNKNOWN_PK_ALG      -0x3C80
  ------------------
  587|       |
  588|  2.51k|    if (ret == 0 && *p != end) {
  ------------------
  |  Branch (588:9): [True: 2.51k, False: 0]
  |  Branch (588:21): [True: 0, False: 2.51k]
  ------------------
  589|      0|        ret = MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_INVALID_PUBKEY,
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  590|      0|                                MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
  591|      0|    }
  592|       |
  593|  2.51k|    if (ret != 0) {
  ------------------
  |  Branch (593:9): [True: 0, False: 2.51k]
  ------------------
  594|      0|        mbedtls_pk_free(pk);
  595|      0|    }
  596|       |
  597|  2.51k|    return ret;
  598|  2.51k|}
pkparse.c:pk_get_pk_alg:
  475|  2.51k|{
  476|  2.51k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  2.51k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  477|  2.51k|    mbedtls_asn1_buf alg_oid;
  478|       |
  479|  2.51k|    memset(params, 0, sizeof(mbedtls_asn1_buf));
  480|       |
  481|  2.51k|    if ((ret = mbedtls_asn1_get_alg(p, end, &alg_oid, params)) != 0) {
  ------------------
  |  Branch (481:9): [True: 0, False: 2.51k]
  ------------------
  482|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_INVALID_ALG, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  483|      0|    }
  484|       |
  485|  2.51k|    ret = mbedtls_oid_get_pk_alg(&alg_oid, pk_alg);
  486|  2.51k|#if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
  487|  2.51k|    if (ret == MBEDTLS_ERR_OID_NOT_FOUND) {
  ------------------
  |  |   28|  2.51k|#define MBEDTLS_ERR_OID_NOT_FOUND                         -0x002E
  ------------------
  |  Branch (487:9): [True: 0, False: 2.51k]
  ------------------
  488|      0|        ret = mbedtls_oid_get_ec_grp_algid(&alg_oid, ec_grp_id);
  489|      0|        if (ret == 0) {
  ------------------
  |  Branch (489:13): [True: 0, False: 0]
  ------------------
  490|      0|            *pk_alg = MBEDTLS_PK_ECKEY;
  491|      0|        }
  492|      0|    }
  493|       |#else
  494|       |    (void) ec_grp_id;
  495|       |#endif
  496|  2.51k|    if (ret != 0) {
  ------------------
  |  Branch (496:9): [True: 0, False: 2.51k]
  ------------------
  497|      0|        return MBEDTLS_ERR_PK_UNKNOWN_PK_ALG;
  ------------------
  |  |   48|      0|#define MBEDTLS_ERR_PK_UNKNOWN_PK_ALG      -0x3C80
  ------------------
  498|      0|    }
  499|       |
  500|       |    /*
  501|       |     * No parameters with RSA (only for EC)
  502|       |     */
  503|  2.51k|    if (*pk_alg == MBEDTLS_PK_RSA &&
  ------------------
  |  Branch (503:9): [True: 0, False: 2.51k]
  ------------------
  504|  2.51k|        ((params->tag != MBEDTLS_ASN1_NULL && params->tag != 0) ||
  ------------------
  |  |   68|      0|#define MBEDTLS_ASN1_NULL                    0x05
  ------------------
  |  Branch (504:11): [True: 0, False: 0]
  |  Branch (504:47): [True: 0, False: 0]
  ------------------
  505|      0|         params->len != 0)) {
  ------------------
  |  Branch (505:10): [True: 0, False: 0]
  ------------------
  506|      0|        return MBEDTLS_ERR_PK_INVALID_ALG;
  ------------------
  |  |   56|      0|#define MBEDTLS_ERR_PK_INVALID_ALG         -0x3A80
  ------------------
  507|      0|    }
  508|       |
  509|  2.51k|    return 0;
  510|  2.51k|}
pkparse.c:pk_use_ecparams:
  390|  2.51k|{
  391|  2.51k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  2.51k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  392|  2.51k|    mbedtls_ecp_group_id grp_id;
  393|       |
  394|  2.51k|    if (params->tag == MBEDTLS_ASN1_OID) {
  ------------------
  |  |   69|  2.51k|#define MBEDTLS_ASN1_OID                     0x06
  ------------------
  |  Branch (394:9): [True: 2.51k, False: 0]
  ------------------
  395|  2.51k|        if (mbedtls_oid_get_ec_grp(params, &grp_id) != 0) {
  ------------------
  |  Branch (395:13): [True: 0, False: 2.51k]
  ------------------
  396|      0|            return MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE;
  ------------------
  |  |   58|      0|#define MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE -0x3A00
  ------------------
  397|      0|        }
  398|  2.51k|    } else {
  399|      0|        ret = pk_ecc_group_id_from_specified(params, &grp_id);
  400|      0|        if (ret != 0) {
  ------------------
  |  Branch (400:13): [True: 0, False: 0]
  ------------------
  401|      0|            return ret;
  402|      0|        }
  403|      0|    }
  404|       |
  405|  2.51k|    return mbedtls_pk_ecc_set_group(pk, grp_id);
  406|  2.51k|}

mbedtls_zeroize_and_free:
  140|   510k|{
  141|   510k|    if (buf != NULL) {
  ------------------
  |  Branch (141:9): [True: 510k, False: 0]
  ------------------
  142|   510k|        mbedtls_platform_zeroize(buf, len);
  143|   510k|    }
  144|       |
  145|   510k|    mbedtls_free(buf);
  ------------------
  |  |  143|   510k|#define mbedtls_free       MBEDTLS_PLATFORM_FREE_MACRO
  |  |  ------------------
  |  |  |  | 4095|   510k|#define MBEDTLS_PLATFORM_FREE_MACRO            my_free
  |  |  ------------------
  ------------------
  146|   510k|}
mbedtls_platform_gmtime_r:
  178|    471|{
  179|       |#if defined(_WIN32) && !defined(PLATFORM_UTIL_USE_GMTIME)
  180|       |#if defined(__STDC_LIB_EXT1__)
  181|       |    return (gmtime_s(tt, tm_buf) == 0) ? NULL : tm_buf;
  182|       |#else
  183|       |    /* MSVC and mingw64 argument order and return value are inconsistent with the C11 standard */
  184|       |    return (gmtime_s(tm_buf, tt) == 0) ? tm_buf : NULL;
  185|       |#endif
  186|       |#elif !defined(PLATFORM_UTIL_USE_GMTIME)
  187|       |    return gmtime_r(tt, tm_buf);
  188|       |#else
  189|       |    struct tm *lt;
  190|       |
  191|       |#if defined(MBEDTLS_THREADING_C)
  192|       |    if (mbedtls_mutex_lock(&mbedtls_threading_gmtime_mutex) != 0) {
  193|       |        return NULL;
  194|       |    }
  195|       |#endif /* MBEDTLS_THREADING_C */
  196|       |
  197|       |    lt = gmtime(tt);
  198|       |
  199|       |    if (lt != NULL) {
  200|       |        memcpy(tm_buf, lt, sizeof(struct tm));
  201|       |    }
  202|       |
  203|       |#if defined(MBEDTLS_THREADING_C)
  204|       |    if (mbedtls_mutex_unlock(&mbedtls_threading_gmtime_mutex) != 0) {
  205|       |        return NULL;
  206|       |    }
  207|       |#endif /* MBEDTLS_THREADING_C */
  208|       |
  209|       |    return (lt == NULL) ? NULL : tm_buf;
  210|       |#endif /* _WIN32 && !EFIX64 && !EFI32 */
  211|    471|}

mbedtls_sha256_init:
  226|    670|{
  227|    670|    memset(ctx, 0, sizeof(mbedtls_sha256_context));
  228|    670|}
mbedtls_sha256_free:
  231|  1.14k|{
  232|  1.14k|    if (ctx == NULL) {
  ------------------
  |  Branch (232:9): [True: 0, False: 1.14k]
  ------------------
  233|      0|        return;
  234|      0|    }
  235|       |
  236|  1.14k|    mbedtls_platform_zeroize(ctx, sizeof(mbedtls_sha256_context));
  237|  1.14k|}
mbedtls_sha256_starts:
  249|    670|{
  250|       |#if defined(MBEDTLS_SHA224_C) && defined(MBEDTLS_SHA256_C)
  251|       |    if (is224 != 0 && is224 != 1) {
  252|       |        return MBEDTLS_ERR_SHA256_BAD_INPUT_DATA;
  253|       |    }
  254|       |#elif defined(MBEDTLS_SHA256_C)
  255|    670|    if (is224 != 0) {
  ------------------
  |  Branch (255:9): [True: 0, False: 670]
  ------------------
  256|      0|        return MBEDTLS_ERR_SHA256_BAD_INPUT_DATA;
  ------------------
  |  |   23|      0|#define MBEDTLS_ERR_SHA256_BAD_INPUT_DATA                 -0x0074
  ------------------
  257|      0|    }
  258|       |#else /* defined MBEDTLS_SHA224_C only */
  259|       |    if (is224 == 0) {
  260|       |        return MBEDTLS_ERR_SHA256_BAD_INPUT_DATA;
  261|       |    }
  262|       |#endif
  263|       |
  264|    670|    ctx->total[0] = 0;
  265|    670|    ctx->total[1] = 0;
  266|       |
  267|    670|    if (is224 == 0) {
  ------------------
  |  Branch (267:9): [True: 670, False: 0]
  ------------------
  268|    670|#if defined(MBEDTLS_SHA256_C)
  269|    670|        ctx->state[0] = 0x6A09E667;
  270|    670|        ctx->state[1] = 0xBB67AE85;
  271|    670|        ctx->state[2] = 0x3C6EF372;
  272|    670|        ctx->state[3] = 0xA54FF53A;
  273|    670|        ctx->state[4] = 0x510E527F;
  274|    670|        ctx->state[5] = 0x9B05688C;
  275|    670|        ctx->state[6] = 0x1F83D9AB;
  276|    670|        ctx->state[7] = 0x5BE0CD19;
  277|    670|#endif
  278|    670|    } else {
  279|       |#if defined(MBEDTLS_SHA224_C)
  280|       |        ctx->state[0] = 0xC1059ED8;
  281|       |        ctx->state[1] = 0x367CD507;
  282|       |        ctx->state[2] = 0x3070DD17;
  283|       |        ctx->state[3] = 0xF70E5939;
  284|       |        ctx->state[4] = 0xFFC00B31;
  285|       |        ctx->state[5] = 0x68581511;
  286|       |        ctx->state[6] = 0x64F98FA7;
  287|       |        ctx->state[7] = 0xBEFA4FA4;
  288|       |#endif
  289|      0|    }
  290|       |
  291|       |#if defined(MBEDTLS_SHA224_C)
  292|       |    ctx->is224 = is224;
  293|       |#endif
  294|       |
  295|    670|    return 0;
  296|    670|}
mbedtls_internal_sha256_process:
  494|  3.20k|{
  495|  3.20k|    struct {
  496|  3.20k|        uint32_t temp1, temp2, W[64];
  497|  3.20k|        uint32_t A[8];
  498|  3.20k|    } local;
  499|       |
  500|  3.20k|    unsigned int i;
  501|       |
  502|  28.8k|    for (i = 0; i < 8; i++) {
  ------------------
  |  Branch (502:17): [True: 25.6k, False: 3.20k]
  ------------------
  503|  25.6k|        local.A[i] = ctx->state[i];
  504|  25.6k|    }
  505|       |
  506|       |#if defined(MBEDTLS_SHA256_SMALLER)
  507|       |    for (i = 0; i < 64; i++) {
  508|       |        if (i < 16) {
  509|       |            local.W[i] = MBEDTLS_GET_UINT32_BE(data, 4 * i);
  510|       |        } else {
  511|       |            R(i);
  512|       |        }
  513|       |
  514|       |        P(local.A[0], local.A[1], local.A[2], local.A[3], local.A[4],
  515|       |          local.A[5], local.A[6], local.A[7], local.W[i], K[i]);
  516|       |
  517|       |        local.temp1 = local.A[7]; local.A[7] = local.A[6];
  518|       |        local.A[6] = local.A[5]; local.A[5] = local.A[4];
  519|       |        local.A[4] = local.A[3]; local.A[3] = local.A[2];
  520|       |        local.A[2] = local.A[1]; local.A[1] = local.A[0];
  521|       |        local.A[0] = local.temp1;
  522|       |    }
  523|       |#else /* MBEDTLS_SHA256_SMALLER */
  524|  54.4k|    for (i = 0; i < 16; i++) {
  ------------------
  |  Branch (524:17): [True: 51.2k, False: 3.20k]
  ------------------
  525|  51.2k|        local.W[i] = MBEDTLS_GET_UINT32_BE(data, 4 * i);
  ------------------
  |  |  413|  51.2k|    ((MBEDTLS_IS_BIG_ENDIAN)                                               \
  |  |  ------------------
  |  |  |  |  398|  51.2k|#define MBEDTLS_IS_BIG_ENDIAN 0
  |  |  ------------------
  |  |  |  Branch (413:6): [Folded - Ignored]
  |  |  ------------------
  |  |  414|  51.2k|        ? mbedtls_get_unaligned_uint32((data) + (offset))                  \
  |  |  415|  51.2k|        : MBEDTLS_BSWAP32(mbedtls_get_unaligned_uint32((data) + (offset))) \
  |  |  ------------------
  |  |  |  |  298|  51.2k|#define MBEDTLS_BSWAP32 __builtin_bswap32
  |  |  ------------------
  |  |  416|  51.2k|    )
  ------------------
  526|  51.2k|    }
  527|       |
  528|  9.61k|    for (i = 0; i < 16; i += 8) {
  ------------------
  |  Branch (528:17): [True: 6.41k, False: 3.20k]
  ------------------
  529|  6.41k|        P(local.A[0], local.A[1], local.A[2], local.A[3], local.A[4],
  ------------------
  |  |  478|  6.41k|    do                                                              \
  |  |  479|  6.41k|    {                                                               \
  |  |  480|  6.41k|        local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  466|  6.41k|#define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  469|  6.41k|#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
  |  |  ------------------
  |  |  481|  6.41k|        local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  465|  6.41k|#define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  468|  6.41k|#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
  |  |  ------------------
  |  |  482|  6.41k|        (d) += local.temp1; (h) = local.temp1 + local.temp2;        \
  |  |  483|  6.41k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (483:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  530|  6.41k|          local.A[5], local.A[6], local.A[7], local.W[i+0], K[i+0]);
  531|  6.41k|        P(local.A[7], local.A[0], local.A[1], local.A[2], local.A[3],
  ------------------
  |  |  478|  6.41k|    do                                                              \
  |  |  479|  6.41k|    {                                                               \
  |  |  480|  6.41k|        local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  466|  6.41k|#define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  469|  6.41k|#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
  |  |  ------------------
  |  |  481|  6.41k|        local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  465|  6.41k|#define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  468|  6.41k|#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
  |  |  ------------------
  |  |  482|  6.41k|        (d) += local.temp1; (h) = local.temp1 + local.temp2;        \
  |  |  483|  6.41k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (483:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  532|  6.41k|          local.A[4], local.A[5], local.A[6], local.W[i+1], K[i+1]);
  533|  6.41k|        P(local.A[6], local.A[7], local.A[0], local.A[1], local.A[2],
  ------------------
  |  |  478|  6.41k|    do                                                              \
  |  |  479|  6.41k|    {                                                               \
  |  |  480|  6.41k|        local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  466|  6.41k|#define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  469|  6.41k|#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
  |  |  ------------------
  |  |  481|  6.41k|        local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  465|  6.41k|#define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  468|  6.41k|#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
  |  |  ------------------
  |  |  482|  6.41k|        (d) += local.temp1; (h) = local.temp1 + local.temp2;        \
  |  |  483|  6.41k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (483:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  534|  6.41k|          local.A[3], local.A[4], local.A[5], local.W[i+2], K[i+2]);
  535|  6.41k|        P(local.A[5], local.A[6], local.A[7], local.A[0], local.A[1],
  ------------------
  |  |  478|  6.41k|    do                                                              \
  |  |  479|  6.41k|    {                                                               \
  |  |  480|  6.41k|        local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  466|  6.41k|#define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  469|  6.41k|#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
  |  |  ------------------
  |  |  481|  6.41k|        local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  465|  6.41k|#define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  468|  6.41k|#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
  |  |  ------------------
  |  |  482|  6.41k|        (d) += local.temp1; (h) = local.temp1 + local.temp2;        \
  |  |  483|  6.41k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (483:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  536|  6.41k|          local.A[2], local.A[3], local.A[4], local.W[i+3], K[i+3]);
  537|  6.41k|        P(local.A[4], local.A[5], local.A[6], local.A[7], local.A[0],
  ------------------
  |  |  478|  6.41k|    do                                                              \
  |  |  479|  6.41k|    {                                                               \
  |  |  480|  6.41k|        local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  466|  6.41k|#define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  469|  6.41k|#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
  |  |  ------------------
  |  |  481|  6.41k|        local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  465|  6.41k|#define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  468|  6.41k|#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
  |  |  ------------------
  |  |  482|  6.41k|        (d) += local.temp1; (h) = local.temp1 + local.temp2;        \
  |  |  483|  6.41k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (483:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  538|  6.41k|          local.A[1], local.A[2], local.A[3], local.W[i+4], K[i+4]);
  539|  6.41k|        P(local.A[3], local.A[4], local.A[5], local.A[6], local.A[7],
  ------------------
  |  |  478|  6.41k|    do                                                              \
  |  |  479|  6.41k|    {                                                               \
  |  |  480|  6.41k|        local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  466|  6.41k|#define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  469|  6.41k|#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
  |  |  ------------------
  |  |  481|  6.41k|        local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  465|  6.41k|#define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  468|  6.41k|#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
  |  |  ------------------
  |  |  482|  6.41k|        (d) += local.temp1; (h) = local.temp1 + local.temp2;        \
  |  |  483|  6.41k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (483:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  540|  6.41k|          local.A[0], local.A[1], local.A[2], local.W[i+5], K[i+5]);
  541|  6.41k|        P(local.A[2], local.A[3], local.A[4], local.A[5], local.A[6],
  ------------------
  |  |  478|  6.41k|    do                                                              \
  |  |  479|  6.41k|    {                                                               \
  |  |  480|  6.41k|        local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  466|  6.41k|#define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  469|  6.41k|#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
  |  |  ------------------
  |  |  481|  6.41k|        local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  465|  6.41k|#define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  468|  6.41k|#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
  |  |  ------------------
  |  |  482|  6.41k|        (d) += local.temp1; (h) = local.temp1 + local.temp2;        \
  |  |  483|  6.41k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (483:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  542|  6.41k|          local.A[7], local.A[0], local.A[1], local.W[i+6], K[i+6]);
  543|  6.41k|        P(local.A[1], local.A[2], local.A[3], local.A[4], local.A[5],
  ------------------
  |  |  478|  6.41k|    do                                                              \
  |  |  479|  6.41k|    {                                                               \
  |  |  480|  6.41k|        local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  466|  6.41k|#define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  469|  6.41k|#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
  |  |  ------------------
  |  |  481|  6.41k|        local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  465|  6.41k|#define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  6.41k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  6.41k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  468|  6.41k|#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
  |  |  ------------------
  |  |  482|  6.41k|        (d) += local.temp1; (h) = local.temp1 + local.temp2;        \
  |  |  483|  6.41k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (483:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  544|  6.41k|          local.A[6], local.A[7], local.A[0], local.W[i+7], K[i+7]);
  545|  6.41k|    }
  546|       |
  547|  22.4k|    for (i = 16; i < 64; i += 8) {
  ------------------
  |  Branch (547:18): [True: 19.2k, False: 3.20k]
  ------------------
  548|  19.2k|        P(local.A[0], local.A[1], local.A[2], local.A[3], local.A[4],
  ------------------
  |  |  478|  19.2k|    do                                                              \
  |  |  479|  19.2k|    {                                                               \
  |  |  480|  19.2k|        local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  466|  19.2k|#define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  469|  19.2k|#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
  |  |  ------------------
  |  |  481|  19.2k|        local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  465|  19.2k|#define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  468|  19.2k|#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
  |  |  ------------------
  |  |  482|  19.2k|        (d) += local.temp1; (h) = local.temp1 + local.temp2;        \
  |  |  483|  19.2k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (483:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  549|  19.2k|          local.A[5], local.A[6], local.A[7], R(i+0), K[i+0]);
  550|  19.2k|        P(local.A[7], local.A[0], local.A[1], local.A[2], local.A[3],
  ------------------
  |  |  478|  19.2k|    do                                                              \
  |  |  479|  19.2k|    {                                                               \
  |  |  480|  19.2k|        local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  466|  19.2k|#define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  469|  19.2k|#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
  |  |  ------------------
  |  |  481|  19.2k|        local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  465|  19.2k|#define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  468|  19.2k|#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
  |  |  ------------------
  |  |  482|  19.2k|        (d) += local.temp1; (h) = local.temp1 + local.temp2;        \
  |  |  483|  19.2k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (483:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  551|  19.2k|          local.A[4], local.A[5], local.A[6], R(i+1), K[i+1]);
  552|  19.2k|        P(local.A[6], local.A[7], local.A[0], local.A[1], local.A[2],
  ------------------
  |  |  478|  19.2k|    do                                                              \
  |  |  479|  19.2k|    {                                                               \
  |  |  480|  19.2k|        local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  466|  19.2k|#define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  469|  19.2k|#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
  |  |  ------------------
  |  |  481|  19.2k|        local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  465|  19.2k|#define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  468|  19.2k|#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
  |  |  ------------------
  |  |  482|  19.2k|        (d) += local.temp1; (h) = local.temp1 + local.temp2;        \
  |  |  483|  19.2k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (483:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  553|  19.2k|          local.A[3], local.A[4], local.A[5], R(i+2), K[i+2]);
  554|  19.2k|        P(local.A[5], local.A[6], local.A[7], local.A[0], local.A[1],
  ------------------
  |  |  478|  19.2k|    do                                                              \
  |  |  479|  19.2k|    {                                                               \
  |  |  480|  19.2k|        local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  466|  19.2k|#define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  469|  19.2k|#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
  |  |  ------------------
  |  |  481|  19.2k|        local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  465|  19.2k|#define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  468|  19.2k|#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
  |  |  ------------------
  |  |  482|  19.2k|        (d) += local.temp1; (h) = local.temp1 + local.temp2;        \
  |  |  483|  19.2k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (483:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  555|  19.2k|          local.A[2], local.A[3], local.A[4], R(i+3), K[i+3]);
  556|  19.2k|        P(local.A[4], local.A[5], local.A[6], local.A[7], local.A[0],
  ------------------
  |  |  478|  19.2k|    do                                                              \
  |  |  479|  19.2k|    {                                                               \
  |  |  480|  19.2k|        local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  466|  19.2k|#define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  469|  19.2k|#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
  |  |  ------------------
  |  |  481|  19.2k|        local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  465|  19.2k|#define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  468|  19.2k|#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
  |  |  ------------------
  |  |  482|  19.2k|        (d) += local.temp1; (h) = local.temp1 + local.temp2;        \
  |  |  483|  19.2k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (483:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  557|  19.2k|          local.A[1], local.A[2], local.A[3], R(i+4), K[i+4]);
  558|  19.2k|        P(local.A[3], local.A[4], local.A[5], local.A[6], local.A[7],
  ------------------
  |  |  478|  19.2k|    do                                                              \
  |  |  479|  19.2k|    {                                                               \
  |  |  480|  19.2k|        local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  466|  19.2k|#define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  469|  19.2k|#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
  |  |  ------------------
  |  |  481|  19.2k|        local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  465|  19.2k|#define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  468|  19.2k|#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
  |  |  ------------------
  |  |  482|  19.2k|        (d) += local.temp1; (h) = local.temp1 + local.temp2;        \
  |  |  483|  19.2k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (483:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  559|  19.2k|          local.A[0], local.A[1], local.A[2], R(i+5), K[i+5]);
  560|  19.2k|        P(local.A[2], local.A[3], local.A[4], local.A[5], local.A[6],
  ------------------
  |  |  478|  19.2k|    do                                                              \
  |  |  479|  19.2k|    {                                                               \
  |  |  480|  19.2k|        local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  466|  19.2k|#define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  469|  19.2k|#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
  |  |  ------------------
  |  |  481|  19.2k|        local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  465|  19.2k|#define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  468|  19.2k|#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
  |  |  ------------------
  |  |  482|  19.2k|        (d) += local.temp1; (h) = local.temp1 + local.temp2;        \
  |  |  483|  19.2k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (483:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  561|  19.2k|          local.A[7], local.A[0], local.A[1], R(i+6), K[i+6]);
  562|  19.2k|        P(local.A[1], local.A[2], local.A[3], local.A[4], local.A[5],
  ------------------
  |  |  478|  19.2k|    do                                                              \
  |  |  479|  19.2k|    {                                                               \
  |  |  480|  19.2k|        local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  466|  19.2k|#define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  469|  19.2k|#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
  |  |  ------------------
  |  |  481|  19.2k|        local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  465|  19.2k|#define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  19.2k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  19.2k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  468|  19.2k|#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
  |  |  ------------------
  |  |  482|  19.2k|        (d) += local.temp1; (h) = local.temp1 + local.temp2;        \
  |  |  483|  19.2k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (483:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  563|  19.2k|          local.A[6], local.A[7], local.A[0], R(i+7), K[i+7]);
  564|  19.2k|    }
  565|  3.20k|#endif /* MBEDTLS_SHA256_SMALLER */
  566|       |
  567|  28.8k|    for (i = 0; i < 8; i++) {
  ------------------
  |  Branch (567:17): [True: 25.6k, False: 3.20k]
  ------------------
  568|  25.6k|        ctx->state[i] += local.A[i];
  569|  25.6k|    }
  570|       |
  571|       |    /* Zeroise buffers and variables to clear sensitive data from memory. */
  572|  3.20k|    mbedtls_platform_zeroize(&local, sizeof(local));
  573|       |
  574|  3.20k|    return 0;
  575|  3.20k|}
mbedtls_sha256_update:
  648|    670|{
  649|    670|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|    670|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  650|    670|    size_t fill;
  651|    670|    uint32_t left;
  652|       |
  653|    670|    if (ilen == 0) {
  ------------------
  |  Branch (653:9): [True: 0, False: 670]
  ------------------
  654|      0|        return 0;
  655|      0|    }
  656|       |
  657|    670|    left = ctx->total[0] & 0x3F;
  658|    670|    fill = SHA256_BLOCK_SIZE - left;
  ------------------
  |  |  223|    670|#define SHA256_BLOCK_SIZE 64
  ------------------
  659|       |
  660|    670|    ctx->total[0] += (uint32_t) ilen;
  661|    670|    ctx->total[0] &= 0xFFFFFFFF;
  662|       |
  663|    670|    if (ctx->total[0] < (uint32_t) ilen) {
  ------------------
  |  Branch (663:9): [True: 0, False: 670]
  ------------------
  664|      0|        ctx->total[1]++;
  665|      0|    }
  666|       |
  667|    670|    if (left && ilen >= fill) {
  ------------------
  |  Branch (667:9): [True: 0, False: 670]
  |  Branch (667:17): [True: 0, False: 0]
  ------------------
  668|      0|        memcpy((void *) (ctx->buffer + left), input, fill);
  669|       |
  670|      0|        if ((ret = mbedtls_internal_sha256_process(ctx, ctx->buffer)) != 0) {
  ------------------
  |  Branch (670:13): [True: 0, False: 0]
  ------------------
  671|      0|            return ret;
  672|      0|        }
  673|       |
  674|      0|        input += fill;
  675|      0|        ilen  -= fill;
  676|      0|        left = 0;
  677|      0|    }
  678|       |
  679|  1.16k|    while (ilen >= SHA256_BLOCK_SIZE) {
  ------------------
  |  |  223|  1.16k|#define SHA256_BLOCK_SIZE 64
  ------------------
  |  Branch (679:12): [True: 496, False: 670]
  ------------------
  680|    496|        size_t processed =
  681|    496|            mbedtls_internal_sha256_process_many(ctx, input, ilen);
  682|    496|        if (processed < SHA256_BLOCK_SIZE) {
  ------------------
  |  |  223|    496|#define SHA256_BLOCK_SIZE 64
  ------------------
  |  Branch (682:13): [True: 0, False: 496]
  ------------------
  683|      0|            return MBEDTLS_ERR_ERROR_GENERIC_ERROR;
  ------------------
  |  |   98|      0|#define MBEDTLS_ERR_ERROR_GENERIC_ERROR       -0x0001
  ------------------
  684|      0|        }
  685|       |
  686|    496|        input += processed;
  687|    496|        ilen  -= processed;
  688|    496|    }
  689|       |
  690|    670|    if (ilen > 0) {
  ------------------
  |  Branch (690:9): [True: 670, False: 0]
  ------------------
  691|    670|        memcpy((void *) (ctx->buffer + left), input, ilen);
  692|    670|    }
  693|       |
  694|    670|    return 0;
  695|    670|}
mbedtls_sha256_finish:
  702|    471|{
  703|    471|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|    471|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  704|    471|    uint32_t used;
  705|    471|    uint32_t high, low;
  706|    471|    int truncated = 0;
  707|       |
  708|       |    /*
  709|       |     * Add padding: 0x80 then 0x00 until 8 bytes remain for the length
  710|       |     */
  711|    471|    used = ctx->total[0] & 0x3F;
  712|       |
  713|    471|    ctx->buffer[used++] = 0x80;
  714|       |
  715|    471|    if (used <= 56) {
  ------------------
  |  Branch (715:9): [True: 471, False: 0]
  ------------------
  716|       |        /* Enough room for padding + length in current block */
  717|    471|        memset(ctx->buffer + used, 0, 56 - used);
  718|    471|    } else {
  719|       |        /* We'll need an extra block */
  720|      0|        memset(ctx->buffer + used, 0, SHA256_BLOCK_SIZE - used);
  ------------------
  |  |  223|      0|#define SHA256_BLOCK_SIZE 64
  ------------------
  721|       |
  722|      0|        if ((ret = mbedtls_internal_sha256_process(ctx, ctx->buffer)) != 0) {
  ------------------
  |  Branch (722:13): [True: 0, False: 0]
  ------------------
  723|      0|            goto exit;
  724|      0|        }
  725|       |
  726|      0|        memset(ctx->buffer, 0, 56);
  727|      0|    }
  728|       |
  729|       |    /*
  730|       |     * Add message length
  731|       |     */
  732|    471|    high = (ctx->total[0] >> 29)
  733|    471|           | (ctx->total[1] <<  3);
  734|    471|    low  = (ctx->total[0] <<  3);
  735|       |
  736|    471|    MBEDTLS_PUT_UINT32_BE(high, ctx->buffer, 56);
  ------------------
  |  |  428|    471|    {                                                                            \
  |  |  429|    471|        if (MBEDTLS_IS_BIG_ENDIAN)                                               \
  |  |  ------------------
  |  |  |  |  398|    471|#define MBEDTLS_IS_BIG_ENDIAN 0
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (398:31): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  430|    471|        {                                                                        \
  |  |  431|      0|            mbedtls_put_unaligned_uint32((data) + (offset), (uint32_t) (n));     \
  |  |  432|      0|        }                                                                        \
  |  |  433|    471|        else                                                                     \
  |  |  434|    471|        {                                                                        \
  |  |  435|    471|            mbedtls_put_unaligned_uint32((data) + (offset), MBEDTLS_BSWAP32((uint32_t) (n))); \
  |  |  ------------------
  |  |  |  |  298|    471|#define MBEDTLS_BSWAP32 __builtin_bswap32
  |  |  ------------------
  |  |  436|    471|        }                                                                        \
  |  |  437|    471|    }
  ------------------
  737|    471|    MBEDTLS_PUT_UINT32_BE(low,  ctx->buffer, 60);
  ------------------
  |  |  428|    471|    {                                                                            \
  |  |  429|    471|        if (MBEDTLS_IS_BIG_ENDIAN)                                               \
  |  |  ------------------
  |  |  |  |  398|    471|#define MBEDTLS_IS_BIG_ENDIAN 0
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (398:31): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  430|    471|        {                                                                        \
  |  |  431|      0|            mbedtls_put_unaligned_uint32((data) + (offset), (uint32_t) (n));     \
  |  |  432|      0|        }                                                                        \
  |  |  433|    471|        else                                                                     \
  |  |  434|    471|        {                                                                        \
  |  |  435|    471|            mbedtls_put_unaligned_uint32((data) + (offset), MBEDTLS_BSWAP32((uint32_t) (n))); \
  |  |  ------------------
  |  |  |  |  298|    471|#define MBEDTLS_BSWAP32 __builtin_bswap32
  |  |  ------------------
  |  |  436|    471|        }                                                                        \
  |  |  437|    471|    }
  ------------------
  738|       |
  739|    471|    if ((ret = mbedtls_internal_sha256_process(ctx, ctx->buffer)) != 0) {
  ------------------
  |  Branch (739:9): [True: 0, False: 471]
  ------------------
  740|      0|        goto exit;
  741|      0|    }
  742|       |
  743|       |    /*
  744|       |     * Output final state
  745|       |     */
  746|    471|    MBEDTLS_PUT_UINT32_BE(ctx->state[0], output,  0);
  ------------------
  |  |  428|    471|    {                                                                            \
  |  |  429|    471|        if (MBEDTLS_IS_BIG_ENDIAN)                                               \
  |  |  ------------------
  |  |  |  |  398|    471|#define MBEDTLS_IS_BIG_ENDIAN 0
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (398:31): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  430|    471|        {                                                                        \
  |  |  431|      0|            mbedtls_put_unaligned_uint32((data) + (offset), (uint32_t) (n));     \
  |  |  432|      0|        }                                                                        \
  |  |  433|    471|        else                                                                     \
  |  |  434|    471|        {                                                                        \
  |  |  435|    471|            mbedtls_put_unaligned_uint32((data) + (offset), MBEDTLS_BSWAP32((uint32_t) (n))); \
  |  |  ------------------
  |  |  |  |  298|    471|#define MBEDTLS_BSWAP32 __builtin_bswap32
  |  |  ------------------
  |  |  436|    471|        }                                                                        \
  |  |  437|    471|    }
  ------------------
  747|    471|    MBEDTLS_PUT_UINT32_BE(ctx->state[1], output,  4);
  ------------------
  |  |  428|    471|    {                                                                            \
  |  |  429|    471|        if (MBEDTLS_IS_BIG_ENDIAN)                                               \
  |  |  ------------------
  |  |  |  |  398|    471|#define MBEDTLS_IS_BIG_ENDIAN 0
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (398:31): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  430|    471|        {                                                                        \
  |  |  431|      0|            mbedtls_put_unaligned_uint32((data) + (offset), (uint32_t) (n));     \
  |  |  432|      0|        }                                                                        \
  |  |  433|    471|        else                                                                     \
  |  |  434|    471|        {                                                                        \
  |  |  435|    471|            mbedtls_put_unaligned_uint32((data) + (offset), MBEDTLS_BSWAP32((uint32_t) (n))); \
  |  |  ------------------
  |  |  |  |  298|    471|#define MBEDTLS_BSWAP32 __builtin_bswap32
  |  |  ------------------
  |  |  436|    471|        }                                                                        \
  |  |  437|    471|    }
  ------------------
  748|    471|    MBEDTLS_PUT_UINT32_BE(ctx->state[2], output,  8);
  ------------------
  |  |  428|    471|    {                                                                            \
  |  |  429|    471|        if (MBEDTLS_IS_BIG_ENDIAN)                                               \
  |  |  ------------------
  |  |  |  |  398|    471|#define MBEDTLS_IS_BIG_ENDIAN 0
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (398:31): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  430|    471|        {                                                                        \
  |  |  431|      0|            mbedtls_put_unaligned_uint32((data) + (offset), (uint32_t) (n));     \
  |  |  432|      0|        }                                                                        \
  |  |  433|    471|        else                                                                     \
  |  |  434|    471|        {                                                                        \
  |  |  435|    471|            mbedtls_put_unaligned_uint32((data) + (offset), MBEDTLS_BSWAP32((uint32_t) (n))); \
  |  |  ------------------
  |  |  |  |  298|    471|#define MBEDTLS_BSWAP32 __builtin_bswap32
  |  |  ------------------
  |  |  436|    471|        }                                                                        \
  |  |  437|    471|    }
  ------------------
  749|    471|    MBEDTLS_PUT_UINT32_BE(ctx->state[3], output, 12);
  ------------------
  |  |  428|    471|    {                                                                            \
  |  |  429|    471|        if (MBEDTLS_IS_BIG_ENDIAN)                                               \
  |  |  ------------------
  |  |  |  |  398|    471|#define MBEDTLS_IS_BIG_ENDIAN 0
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (398:31): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  430|    471|        {                                                                        \
  |  |  431|      0|            mbedtls_put_unaligned_uint32((data) + (offset), (uint32_t) (n));     \
  |  |  432|      0|        }                                                                        \
  |  |  433|    471|        else                                                                     \
  |  |  434|    471|        {                                                                        \
  |  |  435|    471|            mbedtls_put_unaligned_uint32((data) + (offset), MBEDTLS_BSWAP32((uint32_t) (n))); \
  |  |  ------------------
  |  |  |  |  298|    471|#define MBEDTLS_BSWAP32 __builtin_bswap32
  |  |  ------------------
  |  |  436|    471|        }                                                                        \
  |  |  437|    471|    }
  ------------------
  750|    471|    MBEDTLS_PUT_UINT32_BE(ctx->state[4], output, 16);
  ------------------
  |  |  428|    471|    {                                                                            \
  |  |  429|    471|        if (MBEDTLS_IS_BIG_ENDIAN)                                               \
  |  |  ------------------
  |  |  |  |  398|    471|#define MBEDTLS_IS_BIG_ENDIAN 0
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (398:31): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  430|    471|        {                                                                        \
  |  |  431|      0|            mbedtls_put_unaligned_uint32((data) + (offset), (uint32_t) (n));     \
  |  |  432|      0|        }                                                                        \
  |  |  433|    471|        else                                                                     \
  |  |  434|    471|        {                                                                        \
  |  |  435|    471|            mbedtls_put_unaligned_uint32((data) + (offset), MBEDTLS_BSWAP32((uint32_t) (n))); \
  |  |  ------------------
  |  |  |  |  298|    471|#define MBEDTLS_BSWAP32 __builtin_bswap32
  |  |  ------------------
  |  |  436|    471|        }                                                                        \
  |  |  437|    471|    }
  ------------------
  751|    471|    MBEDTLS_PUT_UINT32_BE(ctx->state[5], output, 20);
  ------------------
  |  |  428|    471|    {                                                                            \
  |  |  429|    471|        if (MBEDTLS_IS_BIG_ENDIAN)                                               \
  |  |  ------------------
  |  |  |  |  398|    471|#define MBEDTLS_IS_BIG_ENDIAN 0
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (398:31): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  430|    471|        {                                                                        \
  |  |  431|      0|            mbedtls_put_unaligned_uint32((data) + (offset), (uint32_t) (n));     \
  |  |  432|      0|        }                                                                        \
  |  |  433|    471|        else                                                                     \
  |  |  434|    471|        {                                                                        \
  |  |  435|    471|            mbedtls_put_unaligned_uint32((data) + (offset), MBEDTLS_BSWAP32((uint32_t) (n))); \
  |  |  ------------------
  |  |  |  |  298|    471|#define MBEDTLS_BSWAP32 __builtin_bswap32
  |  |  ------------------
  |  |  436|    471|        }                                                                        \
  |  |  437|    471|    }
  ------------------
  752|    471|    MBEDTLS_PUT_UINT32_BE(ctx->state[6], output, 24);
  ------------------
  |  |  428|    471|    {                                                                            \
  |  |  429|    471|        if (MBEDTLS_IS_BIG_ENDIAN)                                               \
  |  |  ------------------
  |  |  |  |  398|    471|#define MBEDTLS_IS_BIG_ENDIAN 0
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (398:31): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  430|    471|        {                                                                        \
  |  |  431|      0|            mbedtls_put_unaligned_uint32((data) + (offset), (uint32_t) (n));     \
  |  |  432|      0|        }                                                                        \
  |  |  433|    471|        else                                                                     \
  |  |  434|    471|        {                                                                        \
  |  |  435|    471|            mbedtls_put_unaligned_uint32((data) + (offset), MBEDTLS_BSWAP32((uint32_t) (n))); \
  |  |  ------------------
  |  |  |  |  298|    471|#define MBEDTLS_BSWAP32 __builtin_bswap32
  |  |  ------------------
  |  |  436|    471|        }                                                                        \
  |  |  437|    471|    }
  ------------------
  753|       |
  754|       |#if defined(MBEDTLS_SHA224_C)
  755|       |    truncated = ctx->is224;
  756|       |#endif
  757|    471|    if (!truncated) {
  ------------------
  |  Branch (757:9): [True: 471, False: 0]
  ------------------
  758|    471|        MBEDTLS_PUT_UINT32_BE(ctx->state[7], output, 28);
  ------------------
  |  |  428|    471|    {                                                                            \
  |  |  429|    471|        if (MBEDTLS_IS_BIG_ENDIAN)                                               \
  |  |  ------------------
  |  |  |  |  398|    471|#define MBEDTLS_IS_BIG_ENDIAN 0
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (398:31): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  430|    471|        {                                                                        \
  |  |  431|      0|            mbedtls_put_unaligned_uint32((data) + (offset), (uint32_t) (n));     \
  |  |  432|      0|        }                                                                        \
  |  |  433|    471|        else                                                                     \
  |  |  434|    471|        {                                                                        \
  |  |  435|    471|            mbedtls_put_unaligned_uint32((data) + (offset), MBEDTLS_BSWAP32((uint32_t) (n))); \
  |  |  ------------------
  |  |  |  |  298|    471|#define MBEDTLS_BSWAP32 __builtin_bswap32
  |  |  ------------------
  |  |  436|    471|        }                                                                        \
  |  |  437|    471|    }
  ------------------
  759|    471|    }
  760|       |
  761|    471|    ret = 0;
  762|       |
  763|    471|exit:
  764|    471|    mbedtls_sha256_free(ctx);
  765|    471|    return ret;
  766|    471|}
mbedtls_sha256:
  777|    471|{
  778|    471|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|    471|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  779|    471|    mbedtls_sha256_context ctx;
  780|       |
  781|       |#if defined(MBEDTLS_SHA224_C) && defined(MBEDTLS_SHA256_C)
  782|       |    if (is224 != 0 && is224 != 1) {
  783|       |        return MBEDTLS_ERR_SHA256_BAD_INPUT_DATA;
  784|       |    }
  785|       |#elif defined(MBEDTLS_SHA256_C)
  786|    471|    if (is224 != 0) {
  ------------------
  |  Branch (786:9): [True: 0, False: 471]
  ------------------
  787|      0|        return MBEDTLS_ERR_SHA256_BAD_INPUT_DATA;
  ------------------
  |  |   23|      0|#define MBEDTLS_ERR_SHA256_BAD_INPUT_DATA                 -0x0074
  ------------------
  788|      0|    }
  789|       |#else /* defined MBEDTLS_SHA224_C only */
  790|       |    if (is224 == 0) {
  791|       |        return MBEDTLS_ERR_SHA256_BAD_INPUT_DATA;
  792|       |    }
  793|       |#endif
  794|       |
  795|    471|    mbedtls_sha256_init(&ctx);
  796|       |
  797|    471|    if ((ret = mbedtls_sha256_starts(&ctx, is224)) != 0) {
  ------------------
  |  Branch (797:9): [True: 0, False: 471]
  ------------------
  798|      0|        goto exit;
  799|      0|    }
  800|       |
  801|    471|    if ((ret = mbedtls_sha256_update(&ctx, input, ilen)) != 0) {
  ------------------
  |  Branch (801:9): [True: 0, False: 471]
  ------------------
  802|      0|        goto exit;
  803|      0|    }
  804|       |
  805|    471|    if ((ret = mbedtls_sha256_finish(&ctx, output)) != 0) {
  ------------------
  |  Branch (805:9): [True: 0, False: 471]
  ------------------
  806|      0|        goto exit;
  807|      0|    }
  808|       |
  809|    471|exit:
  810|    471|    mbedtls_sha256_free(&ctx);
  811|       |
  812|    471|    return ret;
  813|    471|}
sha256.c:mbedtls_internal_sha256_process_many:
  584|    496|{
  585|    496|    size_t processed = 0;
  586|       |
  587|  3.23k|    while (len >= SHA256_BLOCK_SIZE) {
  ------------------
  |  |  223|  3.23k|#define SHA256_BLOCK_SIZE 64
  ------------------
  |  Branch (587:12): [True: 2.73k, False: 496]
  ------------------
  588|  2.73k|        if (mbedtls_internal_sha256_process_c(ctx, data) != 0) {
  ------------------
  |  |  452|  2.73k|#define mbedtls_internal_sha256_process_c      mbedtls_internal_sha256_process
  ------------------
  |  Branch (588:13): [True: 0, False: 2.73k]
  ------------------
  589|      0|            return 0;
  590|      0|        }
  591|       |
  592|  2.73k|        data += SHA256_BLOCK_SIZE;
  ------------------
  |  |  223|  2.73k|#define SHA256_BLOCK_SIZE 64
  ------------------
  593|  2.73k|        len  -= SHA256_BLOCK_SIZE;
  ------------------
  |  |  223|  2.73k|#define SHA256_BLOCK_SIZE 64
  ------------------
  594|       |
  595|  2.73k|        processed += SHA256_BLOCK_SIZE;
  ------------------
  |  |  223|  2.73k|#define SHA256_BLOCK_SIZE 64
  ------------------
  596|  2.73k|    }
  597|       |
  598|    496|    return processed;
  599|    496|}

mbedtls_x509_get_serial:
   65|  2.51k|{
   66|  2.51k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  2.51k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
   67|       |
   68|  2.51k|    if ((end - *p) < 1) {
  ------------------
  |  Branch (68:9): [True: 0, False: 2.51k]
  ------------------
   69|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_SERIAL,
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
   70|      0|                                 MBEDTLS_ERR_ASN1_OUT_OF_DATA);
   71|      0|    }
   72|       |
   73|  2.51k|    if (**p != (MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_PRIMITIVE | 2) &&
  ------------------
  |  |   83|  2.51k|#define MBEDTLS_ASN1_CONTEXT_SPECIFIC        0x80
  ------------------
                  if (**p != (MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_PRIMITIVE | 2) &&
  ------------------
  |  |   81|  2.51k|#define MBEDTLS_ASN1_PRIMITIVE               0x00
  ------------------
  |  Branch (73:9): [True: 2.51k, False: 0]
  ------------------
   74|  2.51k|        **p !=   MBEDTLS_ASN1_INTEGER) {
  ------------------
  |  |   65|  2.51k|#define MBEDTLS_ASN1_INTEGER                 0x02
  ------------------
  |  Branch (74:9): [True: 0, False: 2.51k]
  ------------------
   75|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_SERIAL,
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
   76|      0|                                 MBEDTLS_ERR_ASN1_UNEXPECTED_TAG);
   77|      0|    }
   78|       |
   79|  2.51k|    serial->tag = *(*p)++;
   80|       |
   81|  2.51k|    if ((ret = mbedtls_asn1_get_len(p, end, &serial->len)) != 0) {
  ------------------
  |  Branch (81:9): [True: 0, False: 2.51k]
  ------------------
   82|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_SERIAL, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
   83|      0|    }
   84|       |
   85|  2.51k|    serial->p = *p;
   86|  2.51k|    *p += serial->len;
   87|       |
   88|  2.51k|    return 0;
   89|  2.51k|}
mbedtls_x509_get_alg:
  114|  5.02k|{
  115|  5.02k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  5.02k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  116|       |
  117|  5.02k|    if ((ret = mbedtls_asn1_get_alg(p, end, alg, params)) != 0) {
  ------------------
  |  Branch (117:9): [True: 0, False: 5.02k]
  ------------------
  118|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_ALG, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  119|      0|    }
  120|       |
  121|  5.02k|    return 0;
  122|  5.02k|}
mbedtls_x509_get_name:
  500|  5.02k|{
  501|  5.02k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  5.02k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  502|  5.02k|    size_t set_len;
  503|  5.02k|    const unsigned char *end_set;
  504|  5.02k|    mbedtls_x509_name *head = cur;
  505|       |
  506|       |    /* don't use recursion, we'd risk stack overflow if not optimized */
  507|  5.02k|    while (1) {
  ------------------
  |  Branch (507:12): [Folded - Ignored]
  ------------------
  508|       |        /*
  509|       |         * parse SET
  510|       |         */
  511|  5.02k|        if ((ret = mbedtls_asn1_get_tag(p, end, &set_len,
  ------------------
  |  Branch (511:13): [True: 0, False: 5.02k]
  ------------------
  512|  5.02k|                                        MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SET)) != 0) {
  ------------------
  |  |   82|  5.02k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                      MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SET)) != 0) {
  ------------------
  |  |   73|  5.02k|#define MBEDTLS_ASN1_SET                     0x11
  ------------------
  513|      0|            ret = MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_NAME, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  514|      0|            goto error;
  515|      0|        }
  516|       |
  517|  5.02k|        end_set  = *p + set_len;
  518|       |
  519|  5.02k|        while (1) {
  ------------------
  |  Branch (519:16): [Folded - Ignored]
  ------------------
  520|  5.02k|            if ((ret = x509_get_attr_type_value(p, end_set, cur)) != 0) {
  ------------------
  |  Branch (520:17): [True: 0, False: 5.02k]
  ------------------
  521|      0|                goto error;
  522|      0|            }
  523|       |
  524|  5.02k|            if (*p == end_set) {
  ------------------
  |  Branch (524:17): [True: 5.02k, False: 0]
  ------------------
  525|  5.02k|                break;
  526|  5.02k|            }
  527|       |
  528|       |            /* Mark this item as being no the only one in a set */
  529|      0|            cur->next_merged = 1;
  530|       |
  531|      0|            cur->next = mbedtls_calloc(1, sizeof(mbedtls_x509_name));
  ------------------
  |  |  144|      0|#define mbedtls_calloc     MBEDTLS_PLATFORM_CALLOC_MACRO
  |  |  ------------------
  |  |  |  | 4093|      0|#define MBEDTLS_PLATFORM_CALLOC_MACRO        my_calloc
  |  |  ------------------
  ------------------
  532|       |
  533|      0|            if (cur->next == NULL) {
  ------------------
  |  Branch (533:17): [True: 0, False: 0]
  ------------------
  534|      0|                ret = MBEDTLS_ERR_X509_ALLOC_FAILED;
  ------------------
  |  |   77|      0|#define MBEDTLS_ERR_X509_ALLOC_FAILED                     -0x2880
  ------------------
  535|      0|                goto error;
  536|      0|            }
  537|       |
  538|      0|            cur = cur->next;
  539|      0|        }
  540|       |
  541|       |        /*
  542|       |         * continue until end of SEQUENCE is reached
  543|       |         */
  544|  5.02k|        if (*p == end) {
  ------------------
  |  Branch (544:13): [True: 5.02k, False: 0]
  ------------------
  545|  5.02k|            return 0;
  546|  5.02k|        }
  547|       |
  548|      0|        cur->next = mbedtls_calloc(1, sizeof(mbedtls_x509_name));
  ------------------
  |  |  144|      0|#define mbedtls_calloc     MBEDTLS_PLATFORM_CALLOC_MACRO
  |  |  ------------------
  |  |  |  | 4093|      0|#define MBEDTLS_PLATFORM_CALLOC_MACRO        my_calloc
  |  |  ------------------
  ------------------
  549|       |
  550|      0|        if (cur->next == NULL) {
  ------------------
  |  Branch (550:13): [True: 0, False: 0]
  ------------------
  551|      0|            ret = MBEDTLS_ERR_X509_ALLOC_FAILED;
  ------------------
  |  |   77|      0|#define MBEDTLS_ERR_X509_ALLOC_FAILED                     -0x2880
  ------------------
  552|      0|            goto error;
  553|      0|        }
  554|       |
  555|      0|        cur = cur->next;
  556|      0|    }
  557|       |
  558|      0|error:
  559|       |    /* Skip the first element as we did not allocate it */
  560|      0|    mbedtls_asn1_free_named_data_list_shallow(head->next);
  561|      0|    head->next = NULL;
  562|       |
  563|      0|    return ret;
  564|  5.02k|}
mbedtls_x509_get_time:
  651|  5.02k|{
  652|  5.02k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  5.02k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  653|  5.02k|    size_t len, year_len;
  654|  5.02k|    unsigned char tag;
  655|       |
  656|  5.02k|    if ((end - *p) < 1) {
  ------------------
  |  Branch (656:9): [True: 0, False: 5.02k]
  ------------------
  657|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_DATE,
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  658|      0|                                 MBEDTLS_ERR_ASN1_OUT_OF_DATA);
  659|      0|    }
  660|       |
  661|  5.02k|    tag = **p;
  662|       |
  663|  5.02k|    if (tag == MBEDTLS_ASN1_UTC_TIME) {
  ------------------
  |  |   77|  5.02k|#define MBEDTLS_ASN1_UTC_TIME                0x17
  ------------------
  |  Branch (663:9): [True: 5.02k, False: 0]
  ------------------
  664|  5.02k|        year_len = 2;
  665|  5.02k|    } else if (tag == MBEDTLS_ASN1_GENERALIZED_TIME) {
  ------------------
  |  |   78|      0|#define MBEDTLS_ASN1_GENERALIZED_TIME        0x18
  ------------------
  |  Branch (665:16): [True: 0, False: 0]
  ------------------
  666|      0|        year_len = 4;
  667|      0|    } else {
  668|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_DATE,
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  669|      0|                                 MBEDTLS_ERR_ASN1_UNEXPECTED_TAG);
  670|      0|    }
  671|       |
  672|  5.02k|    (*p)++;
  673|  5.02k|    ret = mbedtls_asn1_get_len(p, end, &len);
  674|       |
  675|  5.02k|    if (ret != 0) {
  ------------------
  |  Branch (675:9): [True: 0, False: 5.02k]
  ------------------
  676|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_DATE, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  677|      0|    }
  678|       |
  679|       |    /* len is 12 or 14 depending on year_len, plus optional trailing 'Z' */
  680|  5.02k|    if (len != year_len + 10 &&
  ------------------
  |  Branch (680:9): [True: 5.02k, False: 0]
  ------------------
  681|  5.02k|        !(len == year_len + 11 && (*p)[(len - 1)] == 'Z')) {
  ------------------
  |  Branch (681:11): [True: 5.02k, False: 0]
  |  Branch (681:35): [True: 5.02k, False: 0]
  ------------------
  682|      0|        return MBEDTLS_ERR_X509_INVALID_DATE;
  ------------------
  |  |   59|      0|#define MBEDTLS_ERR_X509_INVALID_DATE                     -0x2400
  ------------------
  683|      0|    }
  684|       |
  685|  5.02k|    (*p) += len;
  686|  5.02k|    return x509_parse_time(*p - len, tm, year_len);
  687|  5.02k|}
mbedtls_x509_get_sig:
  690|  2.51k|{
  691|  2.51k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  2.51k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  692|  2.51k|    size_t len;
  693|  2.51k|    int tag_type;
  694|       |
  695|  2.51k|    if ((end - *p) < 1) {
  ------------------
  |  Branch (695:9): [True: 0, False: 2.51k]
  ------------------
  696|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_SIGNATURE,
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  697|      0|                                 MBEDTLS_ERR_ASN1_OUT_OF_DATA);
  698|      0|    }
  699|       |
  700|  2.51k|    tag_type = **p;
  701|       |
  702|  2.51k|    if ((ret = mbedtls_asn1_get_bitstring_null(p, end, &len)) != 0) {
  ------------------
  |  Branch (702:9): [True: 0, False: 2.51k]
  ------------------
  703|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_SIGNATURE, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  704|      0|    }
  705|       |
  706|  2.51k|    sig->tag = tag_type;
  707|  2.51k|    sig->len = len;
  708|  2.51k|    sig->p = *p;
  709|       |
  710|  2.51k|    *p += len;
  711|       |
  712|  2.51k|    return 0;
  713|  2.51k|}
mbedtls_x509_get_sig_alg:
  721|  2.51k|{
  722|  2.51k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  2.51k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  723|       |
  724|  2.51k|    if (*sig_opts != NULL) {
  ------------------
  |  Branch (724:9): [True: 0, False: 2.51k]
  ------------------
  725|      0|        return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
  ------------------
  |  |   75|      0|#define MBEDTLS_ERR_X509_BAD_INPUT_DATA                   -0x2800
  ------------------
  726|      0|    }
  727|       |
  728|  2.51k|    if ((ret = mbedtls_oid_get_sig_alg(sig_oid, md_alg, pk_alg)) != 0) {
  ------------------
  |  Branch (728:9): [True: 0, False: 2.51k]
  ------------------
  729|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  730|      0|    }
  731|       |
  732|  2.51k|#if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
  733|  2.51k|    if (*pk_alg == MBEDTLS_PK_RSASSA_PSS) {
  ------------------
  |  Branch (733:9): [True: 0, False: 2.51k]
  ------------------
  734|      0|        mbedtls_pk_rsassa_pss_options *pss_opts;
  735|       |
  736|      0|        pss_opts = mbedtls_calloc(1, sizeof(mbedtls_pk_rsassa_pss_options));
  ------------------
  |  |  144|      0|#define mbedtls_calloc     MBEDTLS_PLATFORM_CALLOC_MACRO
  |  |  ------------------
  |  |  |  | 4093|      0|#define MBEDTLS_PLATFORM_CALLOC_MACRO        my_calloc
  |  |  ------------------
  ------------------
  737|      0|        if (pss_opts == NULL) {
  ------------------
  |  Branch (737:13): [True: 0, False: 0]
  ------------------
  738|      0|            return MBEDTLS_ERR_X509_ALLOC_FAILED;
  ------------------
  |  |   77|      0|#define MBEDTLS_ERR_X509_ALLOC_FAILED                     -0x2880
  ------------------
  739|      0|        }
  740|       |
  741|      0|        ret = mbedtls_x509_get_rsassa_pss_params(sig_params,
  742|      0|                                                 md_alg,
  743|      0|                                                 &pss_opts->mgf1_hash_id,
  744|      0|                                                 &pss_opts->expected_salt_len);
  745|      0|        if (ret != 0) {
  ------------------
  |  Branch (745:13): [True: 0, False: 0]
  ------------------
  746|      0|            mbedtls_free(pss_opts);
  ------------------
  |  |  143|      0|#define mbedtls_free       MBEDTLS_PLATFORM_FREE_MACRO
  |  |  ------------------
  |  |  |  | 4095|      0|#define MBEDTLS_PLATFORM_FREE_MACRO            my_free
  |  |  ------------------
  ------------------
  747|      0|            return ret;
  748|      0|        }
  749|       |
  750|      0|        *sig_opts = (void *) pss_opts;
  751|      0|    } else
  752|  2.51k|#endif /* MBEDTLS_X509_RSASSA_PSS_SUPPORT */
  753|  2.51k|    {
  754|       |        /* Make sure parameters are absent or NULL */
  755|  2.51k|        if ((sig_params->tag != MBEDTLS_ASN1_NULL && sig_params->tag != 0) ||
  ------------------
  |  |   68|  5.02k|#define MBEDTLS_ASN1_NULL                    0x05
  ------------------
  |  Branch (755:14): [True: 2.51k, False: 0]
  |  Branch (755:54): [True: 0, False: 2.51k]
  ------------------
  756|  2.51k|            sig_params->len != 0) {
  ------------------
  |  Branch (756:13): [True: 0, False: 2.51k]
  ------------------
  757|      0|            return MBEDTLS_ERR_X509_INVALID_ALG;
  ------------------
  |  |   55|      0|#define MBEDTLS_ERR_X509_INVALID_ALG                      -0x2300
  ------------------
  758|      0|        }
  759|  2.51k|    }
  760|       |
  761|  2.51k|    return 0;
  762|  2.51k|}
mbedtls_x509_get_ext:
  770|  2.51k|{
  771|  2.51k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  2.51k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  772|  2.51k|    size_t len;
  773|       |
  774|       |    /* Extension structure use EXPLICIT tagging. That is, the actual
  775|       |     * `Extensions` structure is wrapped by a tag-length pair using
  776|       |     * the respective context-specific tag. */
  777|  2.51k|    ret = mbedtls_asn1_get_tag(p, end, &ext->len,
  778|  2.51k|                               MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | tag);
  ------------------
  |  |   83|  2.51k|#define MBEDTLS_ASN1_CONTEXT_SPECIFIC        0x80
  ------------------
                                             MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | tag);
  ------------------
  |  |   82|  2.51k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
  779|  2.51k|    if (ret != 0) {
  ------------------
  |  Branch (779:9): [True: 0, False: 2.51k]
  ------------------
  780|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  781|      0|    }
  782|       |
  783|  2.51k|    ext->tag = MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | tag;
  ------------------
  |  |   83|  2.51k|#define MBEDTLS_ASN1_CONTEXT_SPECIFIC        0x80
  ------------------
                  ext->tag = MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | tag;
  ------------------
  |  |   82|  2.51k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
  784|  2.51k|    ext->p   = *p;
  785|  2.51k|    end      = *p + ext->len;
  786|       |
  787|       |    /*
  788|       |     * Extensions  ::=  SEQUENCE SIZE (1..MAX) OF Extension
  789|       |     */
  790|  2.51k|    if ((ret = mbedtls_asn1_get_tag(p, end, &len,
  ------------------
  |  Branch (790:9): [True: 0, False: 2.51k]
  ------------------
  791|  2.51k|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|  2.51k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|  2.51k|#define MBEDTLS_ASN1_SEQUENCE                0x10
  ------------------
  792|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  793|      0|    }
  794|       |
  795|  2.51k|    if (end != *p + len) {
  ------------------
  |  Branch (795:9): [True: 0, False: 2.51k]
  ------------------
  796|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  797|      0|                                 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
  798|      0|    }
  799|       |
  800|  2.51k|    return 0;
  801|  2.51k|}
mbedtls_x509_time_cmp:
 1038|  2.19k|{
 1039|  2.19k|    int x;
 1040|       |
 1041|  2.19k|    x = (((t1->year << 9) | (t1->mon << 5) | (t1->day)) -
 1042|  2.19k|         ((t2->year << 9) | (t2->mon << 5) | (t2->day)));
 1043|  2.19k|    if (x != 0) {
  ------------------
  |  Branch (1043:9): [True: 2.19k, False: 0]
  ------------------
 1044|  2.19k|        return x;
 1045|  2.19k|    }
 1046|       |
 1047|      0|    x = (((t1->hour << 12) | (t1->min << 6) | (t1->sec)) -
 1048|      0|         ((t2->hour << 12) | (t2->min << 6) | (t2->sec)));
 1049|      0|    return x;
 1050|  2.19k|}
mbedtls_x509_time_gmtime:
 1054|    471|{
 1055|    471|    struct tm tm;
 1056|       |
 1057|    471|    if (mbedtls_platform_gmtime_r(&tt, &tm) == NULL) {
  ------------------
  |  Branch (1057:9): [True: 0, False: 471]
  ------------------
 1058|      0|        return -1;
 1059|      0|    }
 1060|       |
 1061|    471|    now->year = tm.tm_year + 1900;
 1062|    471|    now->mon  = tm.tm_mon  + 1;
 1063|    471|    now->day  = tm.tm_mday;
 1064|    471|    now->hour = tm.tm_hour;
 1065|    471|    now->min  = tm.tm_min;
 1066|    471|    now->sec  = tm.tm_sec;
 1067|    471|    return 0;
 1068|    471|}
mbedtls_x509_get_subject_alt_name_ext:
 1216|  1.72k|{
 1217|  1.72k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  1.72k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1218|  1.72k|    size_t tag_len;
 1219|  1.72k|    mbedtls_asn1_sequence *cur = subject_alt_name;
 1220|       |
 1221|  3.45k|    while (*p < end) {
  ------------------
  |  Branch (1221:12): [True: 1.72k, False: 1.72k]
  ------------------
 1222|  1.72k|        mbedtls_x509_subject_alternative_name tmp_san_name;
 1223|  1.72k|        mbedtls_x509_buf tmp_san_buf;
 1224|  1.72k|        memset(&tmp_san_name, 0, sizeof(tmp_san_name));
 1225|       |
 1226|  1.72k|        tmp_san_buf.tag = **p;
 1227|  1.72k|        (*p)++;
 1228|       |
 1229|  1.72k|        if ((ret = mbedtls_asn1_get_len(p, end, &tag_len)) != 0) {
  ------------------
  |  Branch (1229:13): [True: 0, False: 1.72k]
  ------------------
 1230|      0|            return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
 1231|      0|        }
 1232|       |
 1233|  1.72k|        tmp_san_buf.p = *p;
 1234|  1.72k|        tmp_san_buf.len = tag_len;
 1235|       |
 1236|  1.72k|        if ((tmp_san_buf.tag & MBEDTLS_ASN1_TAG_CLASS_MASK) !=
  ------------------
  |  |  106|  1.72k|#define MBEDTLS_ASN1_TAG_CLASS_MASK          0xC0
  ------------------
  |  Branch (1236:13): [True: 0, False: 1.72k]
  ------------------
 1237|  1.72k|            MBEDTLS_ASN1_CONTEXT_SPECIFIC) {
  ------------------
  |  |   83|  1.72k|#define MBEDTLS_ASN1_CONTEXT_SPECIFIC        0x80
  ------------------
 1238|      0|            return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
 1239|      0|                                     MBEDTLS_ERR_ASN1_UNEXPECTED_TAG);
 1240|      0|        }
 1241|       |
 1242|       |        /*
 1243|       |         * Check that the SAN is structured correctly by parsing it.
 1244|       |         * The SAN structure is discarded afterwards.
 1245|       |         */
 1246|  1.72k|        ret = mbedtls_x509_parse_subject_alt_name(&tmp_san_buf, &tmp_san_name);
 1247|       |        /*
 1248|       |         * In case the extension is malformed, return an error,
 1249|       |         * and clear the allocated sequences.
 1250|       |         */
 1251|  1.72k|        if (ret != 0 && ret != MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE) {
  ------------------
  |  |   45|  1.72k|#define MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE              -0x2080
  ------------------
  |  Branch (1251:13): [True: 1.72k, False: 0]
  |  Branch (1251:25): [True: 0, False: 1.72k]
  ------------------
 1252|      0|            mbedtls_asn1_sequence_free(subject_alt_name->next);
 1253|      0|            subject_alt_name->next = NULL;
 1254|      0|            return ret;
 1255|      0|        }
 1256|       |
 1257|  1.72k|        mbedtls_x509_free_subject_alt_name(&tmp_san_name);
 1258|       |        /* Allocate and assign next pointer */
 1259|  1.72k|        if (cur->buf.p != NULL) {
  ------------------
  |  Branch (1259:13): [True: 0, False: 1.72k]
  ------------------
 1260|      0|            if (cur->next != NULL) {
  ------------------
  |  Branch (1260:17): [True: 0, False: 0]
  ------------------
 1261|      0|                return MBEDTLS_ERR_X509_INVALID_EXTENSIONS;
  ------------------
  |  |   63|      0|#define MBEDTLS_ERR_X509_INVALID_EXTENSIONS               -0x2500
  ------------------
 1262|      0|            }
 1263|       |
 1264|      0|            cur->next = mbedtls_calloc(1, sizeof(mbedtls_asn1_sequence));
  ------------------
  |  |  144|      0|#define mbedtls_calloc     MBEDTLS_PLATFORM_CALLOC_MACRO
  |  |  ------------------
  |  |  |  | 4093|      0|#define MBEDTLS_PLATFORM_CALLOC_MACRO        my_calloc
  |  |  ------------------
  ------------------
 1265|       |
 1266|      0|            if (cur->next == NULL) {
  ------------------
  |  Branch (1266:17): [True: 0, False: 0]
  ------------------
 1267|      0|                return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
 1268|      0|                                         MBEDTLS_ERR_ASN1_ALLOC_FAILED);
 1269|      0|            }
 1270|       |
 1271|      0|            cur = cur->next;
 1272|      0|        }
 1273|       |
 1274|  1.72k|        cur->buf = tmp_san_buf;
 1275|  1.72k|        *p += tmp_san_buf.len;
 1276|  1.72k|    }
 1277|       |
 1278|       |    /* Set final sequence entry's next pointer to NULL */
 1279|  1.72k|    cur->next = NULL;
 1280|       |
 1281|  1.72k|    if (*p != end) {
  ------------------
  |  Branch (1281:9): [True: 0, False: 1.72k]
  ------------------
 1282|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
 1283|      0|                                 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
 1284|      0|    }
 1285|       |
 1286|  1.72k|    return 0;
 1287|  1.72k|}
mbedtls_x509_get_subject_alt_name:
 1320|  1.72k|{
 1321|  1.72k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  1.72k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1322|  1.72k|    size_t len;
 1323|       |
 1324|       |    /* Get main sequence tag */
 1325|  1.72k|    if ((ret = mbedtls_asn1_get_tag(p, end, &len,
  ------------------
  |  Branch (1325:9): [True: 0, False: 1.72k]
  ------------------
 1326|  1.72k|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|  1.72k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|  1.72k|#define MBEDTLS_ASN1_SEQUENCE                0x10
  ------------------
 1327|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
 1328|      0|    }
 1329|       |
 1330|  1.72k|    if (*p + len != end) {
  ------------------
  |  Branch (1330:9): [True: 0, False: 1.72k]
  ------------------
 1331|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
 1332|      0|                                 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
 1333|      0|    }
 1334|       |
 1335|  1.72k|    return mbedtls_x509_get_subject_alt_name_ext(p, end, subject_alt_name);
 1336|  1.72k|}
mbedtls_x509_get_key_usage:
 1369|  2.04k|{
 1370|  2.04k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  2.04k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1371|  2.04k|    size_t i;
 1372|  2.04k|    mbedtls_x509_bitstring bs = { 0, 0, NULL };
 1373|       |
 1374|  2.04k|    if ((ret = mbedtls_asn1_get_bitstring(p, end, &bs)) != 0) {
  ------------------
  |  Branch (1374:9): [True: 0, False: 2.04k]
  ------------------
 1375|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
 1376|      0|    }
 1377|       |
 1378|       |    /* A bitstring with no flags set is still technically valid, as it will mean
 1379|       |       that the certificate has no designated purpose at the time of creation. */
 1380|  2.04k|    if (bs.len == 0) {
  ------------------
  |  Branch (1380:9): [True: 0, False: 2.04k]
  ------------------
 1381|      0|        *key_usage = 0;
 1382|      0|        return 0;
 1383|      0|    }
 1384|       |
 1385|       |    /* Get actual bitstring */
 1386|  2.04k|    *key_usage = 0;
 1387|  4.08k|    for (i = 0; i < bs.len && i < sizeof(unsigned int); i++) {
  ------------------
  |  Branch (1387:17): [True: 2.04k, False: 2.04k]
  |  Branch (1387:31): [True: 2.04k, False: 0]
  ------------------
 1388|  2.04k|        *key_usage |= (unsigned int) bs.p[i] << (8*i);
 1389|  2.04k|    }
 1390|       |
 1391|  2.04k|    return 0;
 1392|  2.04k|}
mbedtls_x509_parse_subject_alt_name:
 1396|  1.72k|{
 1397|  1.72k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  1.72k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1398|  1.72k|    switch (san_buf->tag &
 1399|  1.72k|            (MBEDTLS_ASN1_TAG_CLASS_MASK |
  ------------------
  |  |  106|  1.72k|#define MBEDTLS_ASN1_TAG_CLASS_MASK          0xC0
  ------------------
 1400|  1.72k|             MBEDTLS_ASN1_TAG_VALUE_MASK)) {
  ------------------
  |  |  108|  1.72k|#define MBEDTLS_ASN1_TAG_VALUE_MASK          0x1F
  ------------------
 1401|       |        /*
 1402|       |         * otherName
 1403|       |         */
 1404|  1.72k|        case (MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_X509_SAN_OTHER_NAME):
  ------------------
  |  |   83|  1.72k|#define MBEDTLS_ASN1_CONTEXT_SPECIFIC        0x80
  ------------------
                      case (MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_X509_SAN_OTHER_NAME):
  ------------------
  |  |  127|  1.72k|#define MBEDTLS_X509_SAN_OTHER_NAME                      0
  ------------------
  |  Branch (1404:9): [True: 1.72k, False: 0]
  ------------------
 1405|  1.72k|        {
 1406|  1.72k|            mbedtls_x509_san_other_name other_name;
 1407|       |
 1408|  1.72k|            ret = x509_get_other_name(san_buf, &other_name);
 1409|  1.72k|            if (ret != 0) {
  ------------------
  |  Branch (1409:17): [True: 1.72k, False: 0]
  ------------------
 1410|  1.72k|                return ret;
 1411|  1.72k|            }
 1412|       |
 1413|      0|            memset(san, 0, sizeof(mbedtls_x509_subject_alternative_name));
 1414|      0|            san->type = MBEDTLS_X509_SAN_OTHER_NAME;
  ------------------
  |  |  127|      0|#define MBEDTLS_X509_SAN_OTHER_NAME                      0
  ------------------
 1415|      0|            memcpy(&san->san.other_name,
 1416|      0|                   &other_name, sizeof(other_name));
 1417|       |
 1418|      0|        }
 1419|      0|        break;
 1420|       |        /*
 1421|       |         * uniformResourceIdentifier
 1422|       |         */
 1423|      0|        case (MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_X509_SAN_UNIFORM_RESOURCE_IDENTIFIER):
  ------------------
  |  |   83|      0|#define MBEDTLS_ASN1_CONTEXT_SPECIFIC        0x80
  ------------------
                      case (MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_X509_SAN_UNIFORM_RESOURCE_IDENTIFIER):
  ------------------
  |  |  133|      0|#define MBEDTLS_X509_SAN_UNIFORM_RESOURCE_IDENTIFIER     6
  ------------------
  |  Branch (1423:9): [True: 0, False: 1.72k]
  ------------------
 1424|      0|        {
 1425|      0|            memset(san, 0, sizeof(mbedtls_x509_subject_alternative_name));
 1426|      0|            san->type = MBEDTLS_X509_SAN_UNIFORM_RESOURCE_IDENTIFIER;
  ------------------
  |  |  133|      0|#define MBEDTLS_X509_SAN_UNIFORM_RESOURCE_IDENTIFIER     6
  ------------------
 1427|       |
 1428|      0|            memcpy(&san->san.unstructured_name,
 1429|      0|                   san_buf, sizeof(*san_buf));
 1430|       |
 1431|      0|        }
 1432|      0|        break;
 1433|       |        /*
 1434|       |         * dNSName
 1435|       |         */
 1436|      0|        case (MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_X509_SAN_DNS_NAME):
  ------------------
  |  |   83|      0|#define MBEDTLS_ASN1_CONTEXT_SPECIFIC        0x80
  ------------------
                      case (MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_X509_SAN_DNS_NAME):
  ------------------
  |  |  129|      0|#define MBEDTLS_X509_SAN_DNS_NAME                        2
  ------------------
  |  Branch (1436:9): [True: 0, False: 1.72k]
  ------------------
 1437|      0|        {
 1438|      0|            memset(san, 0, sizeof(mbedtls_x509_subject_alternative_name));
 1439|      0|            san->type = MBEDTLS_X509_SAN_DNS_NAME;
  ------------------
  |  |  129|      0|#define MBEDTLS_X509_SAN_DNS_NAME                        2
  ------------------
 1440|       |
 1441|      0|            memcpy(&san->san.unstructured_name,
 1442|      0|                   san_buf, sizeof(*san_buf));
 1443|      0|        }
 1444|      0|        break;
 1445|       |        /*
 1446|       |         * IP address
 1447|       |         */
 1448|      0|        case (MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_X509_SAN_IP_ADDRESS):
  ------------------
  |  |   83|      0|#define MBEDTLS_ASN1_CONTEXT_SPECIFIC        0x80
  ------------------
                      case (MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_X509_SAN_IP_ADDRESS):
  ------------------
  |  |  134|      0|#define MBEDTLS_X509_SAN_IP_ADDRESS                      7
  ------------------
  |  Branch (1448:9): [True: 0, False: 1.72k]
  ------------------
 1449|      0|        {
 1450|      0|            memset(san, 0, sizeof(mbedtls_x509_subject_alternative_name));
 1451|      0|            san->type = MBEDTLS_X509_SAN_IP_ADDRESS;
  ------------------
  |  |  134|      0|#define MBEDTLS_X509_SAN_IP_ADDRESS                      7
  ------------------
 1452|       |            // Only IPv6 (16 bytes) and IPv4 (4 bytes) types are supported
 1453|      0|            if (san_buf->len == 4 || san_buf->len == 16) {
  ------------------
  |  Branch (1453:17): [True: 0, False: 0]
  |  Branch (1453:38): [True: 0, False: 0]
  ------------------
 1454|      0|                memcpy(&san->san.unstructured_name,
 1455|      0|                       san_buf, sizeof(*san_buf));
 1456|      0|            } else {
 1457|      0|                return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
  ------------------
  |  |   75|      0|#define MBEDTLS_ERR_X509_BAD_INPUT_DATA                   -0x2800
  ------------------
 1458|      0|            }
 1459|      0|        }
 1460|      0|        break;
 1461|       |        /*
 1462|       |         * rfc822Name
 1463|       |         */
 1464|      0|        case (MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_X509_SAN_RFC822_NAME):
  ------------------
  |  |   83|      0|#define MBEDTLS_ASN1_CONTEXT_SPECIFIC        0x80
  ------------------
                      case (MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_X509_SAN_RFC822_NAME):
  ------------------
  |  |  128|      0|#define MBEDTLS_X509_SAN_RFC822_NAME                     1
  ------------------
  |  Branch (1464:9): [True: 0, False: 1.72k]
  ------------------
 1465|      0|        {
 1466|      0|            memset(san, 0, sizeof(mbedtls_x509_subject_alternative_name));
 1467|      0|            san->type = MBEDTLS_X509_SAN_RFC822_NAME;
  ------------------
  |  |  128|      0|#define MBEDTLS_X509_SAN_RFC822_NAME                     1
  ------------------
 1468|      0|            memcpy(&san->san.unstructured_name, san_buf, sizeof(*san_buf));
 1469|      0|        }
 1470|      0|        break;
 1471|       |        /*
 1472|       |         * directoryName
 1473|       |         */
 1474|      0|        case (MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_X509_SAN_DIRECTORY_NAME):
  ------------------
  |  |   83|      0|#define MBEDTLS_ASN1_CONTEXT_SPECIFIC        0x80
  ------------------
                      case (MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_X509_SAN_DIRECTORY_NAME):
  ------------------
  |  |  131|      0|#define MBEDTLS_X509_SAN_DIRECTORY_NAME                  4
  ------------------
  |  Branch (1474:9): [True: 0, False: 1.72k]
  ------------------
 1475|      0|        {
 1476|      0|            size_t name_len;
 1477|      0|            unsigned char *p = san_buf->p;
 1478|      0|            memset(san, 0, sizeof(mbedtls_x509_subject_alternative_name));
 1479|      0|            san->type = MBEDTLS_X509_SAN_DIRECTORY_NAME;
  ------------------
  |  |  131|      0|#define MBEDTLS_X509_SAN_DIRECTORY_NAME                  4
  ------------------
 1480|       |
 1481|      0|            ret = mbedtls_asn1_get_tag(&p, p + san_buf->len, &name_len,
 1482|      0|                                       MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE);
  ------------------
  |  |   82|      0|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                     MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE);
  ------------------
  |  |   72|      0|#define MBEDTLS_ASN1_SEQUENCE                0x10
  ------------------
 1483|       |
 1484|      0|            if (ret != 0) {
  ------------------
  |  Branch (1484:17): [True: 0, False: 0]
  ------------------
 1485|      0|                return ret;
 1486|      0|            }
 1487|       |
 1488|      0|            if ((ret = mbedtls_x509_get_name(&p, p + name_len,
  ------------------
  |  Branch (1488:17): [True: 0, False: 0]
  ------------------
 1489|      0|                                             &san->san.directory_name)) != 0) {
 1490|      0|                return ret;
 1491|      0|            }
 1492|      0|        }
 1493|      0|        break;
 1494|       |        /*
 1495|       |         * Type not supported
 1496|       |         */
 1497|      0|        default:
  ------------------
  |  Branch (1497:9): [True: 0, False: 1.72k]
  ------------------
 1498|      0|            return MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE;
  ------------------
  |  |   45|      0|#define MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE              -0x2080
  ------------------
 1499|  1.72k|    }
 1500|      0|    return 0;
 1501|  1.72k|}
mbedtls_x509_free_subject_alt_name:
 1504|  1.72k|{
 1505|  1.72k|    if (san->type == MBEDTLS_X509_SAN_DIRECTORY_NAME) {
  ------------------
  |  |  131|  1.72k|#define MBEDTLS_X509_SAN_DIRECTORY_NAME                  4
  ------------------
  |  Branch (1505:9): [True: 0, False: 1.72k]
  ------------------
 1506|      0|        mbedtls_asn1_free_named_data_list_shallow(san->san.directory_name.next);
 1507|      0|    }
 1508|  1.72k|}
x509.c:x509_get_attr_type_value:
  409|  5.02k|{
  410|  5.02k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  5.02k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  411|  5.02k|    size_t len;
  412|  5.02k|    mbedtls_x509_buf *oid;
  413|  5.02k|    mbedtls_x509_buf *val;
  414|       |
  415|  5.02k|    if ((ret = mbedtls_asn1_get_tag(p, end, &len,
  ------------------
  |  Branch (415:9): [True: 0, False: 5.02k]
  ------------------
  416|  5.02k|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|  5.02k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|  5.02k|#define MBEDTLS_ASN1_SEQUENCE                0x10
  ------------------
  417|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_NAME, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  418|      0|    }
  419|       |
  420|  5.02k|    end = *p + len;
  421|       |
  422|  5.02k|    if ((end - *p) < 1) {
  ------------------
  |  Branch (422:9): [True: 0, False: 5.02k]
  ------------------
  423|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_NAME,
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  424|      0|                                 MBEDTLS_ERR_ASN1_OUT_OF_DATA);
  425|      0|    }
  426|       |
  427|  5.02k|    oid = &cur->oid;
  428|  5.02k|    oid->tag = **p;
  429|       |
  430|  5.02k|    if ((ret = mbedtls_asn1_get_tag(p, end, &oid->len, MBEDTLS_ASN1_OID)) != 0) {
  ------------------
  |  |   69|  5.02k|#define MBEDTLS_ASN1_OID                     0x06
  ------------------
  |  Branch (430:9): [True: 0, False: 5.02k]
  ------------------
  431|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_NAME, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  432|      0|    }
  433|       |
  434|  5.02k|    oid->p = *p;
  435|  5.02k|    *p += oid->len;
  436|       |
  437|  5.02k|    if ((end - *p) < 1) {
  ------------------
  |  Branch (437:9): [True: 0, False: 5.02k]
  ------------------
  438|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_NAME,
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  439|      0|                                 MBEDTLS_ERR_ASN1_OUT_OF_DATA);
  440|      0|    }
  441|       |
  442|  5.02k|    if (**p != MBEDTLS_ASN1_BMP_STRING && **p != MBEDTLS_ASN1_UTF8_STRING      &&
  ------------------
  |  |   80|  10.0k|#define MBEDTLS_ASN1_BMP_STRING              0x1E
  ------------------
                  if (**p != MBEDTLS_ASN1_BMP_STRING && **p != MBEDTLS_ASN1_UTF8_STRING      &&
  ------------------
  |  |   71|  10.0k|#define MBEDTLS_ASN1_UTF8_STRING             0x0C
  ------------------
  |  Branch (442:9): [True: 5.02k, False: 0]
  |  Branch (442:43): [True: 0, False: 5.02k]
  ------------------
  443|  5.02k|        **p != MBEDTLS_ASN1_T61_STRING && **p != MBEDTLS_ASN1_PRINTABLE_STRING &&
  ------------------
  |  |   75|  5.02k|#define MBEDTLS_ASN1_T61_STRING              0x14
  ------------------
                      **p != MBEDTLS_ASN1_T61_STRING && **p != MBEDTLS_ASN1_PRINTABLE_STRING &&
  ------------------
  |  |   74|  5.02k|#define MBEDTLS_ASN1_PRINTABLE_STRING        0x13
  ------------------
  |  Branch (443:9): [True: 0, False: 0]
  |  Branch (443:43): [True: 0, False: 0]
  ------------------
  444|  5.02k|        **p != MBEDTLS_ASN1_IA5_STRING && **p != MBEDTLS_ASN1_UNIVERSAL_STRING &&
  ------------------
  |  |   76|  5.02k|#define MBEDTLS_ASN1_IA5_STRING              0x16
  ------------------
                      **p != MBEDTLS_ASN1_IA5_STRING && **p != MBEDTLS_ASN1_UNIVERSAL_STRING &&
  ------------------
  |  |   79|  5.02k|#define MBEDTLS_ASN1_UNIVERSAL_STRING        0x1C
  ------------------
  |  Branch (444:9): [True: 0, False: 0]
  |  Branch (444:43): [True: 0, False: 0]
  ------------------
  445|  5.02k|        **p != MBEDTLS_ASN1_BIT_STRING) {
  ------------------
  |  |   66|      0|#define MBEDTLS_ASN1_BIT_STRING              0x03
  ------------------
  |  Branch (445:9): [True: 0, False: 0]
  ------------------
  446|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_NAME,
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  447|      0|                                 MBEDTLS_ERR_ASN1_UNEXPECTED_TAG);
  448|      0|    }
  449|       |
  450|  5.02k|    val = &cur->val;
  451|  5.02k|    val->tag = *(*p)++;
  452|       |
  453|  5.02k|    if ((ret = mbedtls_asn1_get_len(p, end, &val->len)) != 0) {
  ------------------
  |  Branch (453:9): [True: 0, False: 5.02k]
  ------------------
  454|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_NAME, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  455|      0|    }
  456|       |
  457|  5.02k|    val->p = *p;
  458|  5.02k|    *p += val->len;
  459|       |
  460|  5.02k|    if (*p != end) {
  ------------------
  |  Branch (460:9): [True: 0, False: 5.02k]
  ------------------
  461|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_NAME,
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  462|      0|                                 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
  463|      0|    }
  464|       |
  465|  5.02k|    cur->next = NULL;
  466|       |
  467|  5.02k|    return 0;
  468|  5.02k|}
x509.c:x509_parse_time:
  612|  5.02k|{
  613|  5.02k|    int x;
  614|       |
  615|       |    /*
  616|       |     * Parse year, month, day, hour, minute, second
  617|       |     */
  618|  5.02k|    tm->year = x509_parse2_int(p);
  619|  5.02k|    if (tm->year < 0) {
  ------------------
  |  Branch (619:9): [True: 0, False: 5.02k]
  ------------------
  620|      0|        return MBEDTLS_ERR_X509_INVALID_DATE;
  ------------------
  |  |   59|      0|#define MBEDTLS_ERR_X509_INVALID_DATE                     -0x2400
  ------------------
  621|      0|    }
  622|       |
  623|  5.02k|    if (4 == yearlen) {
  ------------------
  |  Branch (623:9): [True: 0, False: 5.02k]
  ------------------
  624|      0|        x = tm->year * 100;
  625|      0|        p += 2;
  626|      0|        tm->year = x509_parse2_int(p);
  627|      0|        if (tm->year < 0) {
  ------------------
  |  Branch (627:13): [True: 0, False: 0]
  ------------------
  628|      0|            return MBEDTLS_ERR_X509_INVALID_DATE;
  ------------------
  |  |   59|      0|#define MBEDTLS_ERR_X509_INVALID_DATE                     -0x2400
  ------------------
  629|      0|        }
  630|  5.02k|    } else {
  631|  5.02k|        x = (tm->year < 50) ? 2000 : 1900;
  ------------------
  |  Branch (631:13): [True: 5.02k, False: 0]
  ------------------
  632|  5.02k|    }
  633|  5.02k|    tm->year += x;
  634|       |
  635|  5.02k|    tm->mon  = x509_parse2_int(p + 2);
  636|  5.02k|    tm->day  = x509_parse2_int(p + 4);
  637|  5.02k|    tm->hour = x509_parse2_int(p + 6);
  638|  5.02k|    tm->min  = x509_parse2_int(p + 8);
  639|  5.02k|    tm->sec  = x509_parse2_int(p + 10);
  640|       |
  641|  5.02k|    return x509_date_is_valid(tm);
  642|  5.02k|}
x509.c:x509_parse2_int:
  600|  30.1k|{
  601|  30.1k|    uint32_t d1 = p[0] - '0';
  602|  30.1k|    uint32_t d2 = p[1] - '0';
  603|  30.1k|    return (d1 < 10 && d2 < 10) ? (int) (d1 * 10 + d2) : -1;
  ------------------
  |  Branch (603:13): [True: 30.1k, False: 0]
  |  Branch (603:24): [True: 30.1k, False: 0]
  ------------------
  604|  30.1k|}
x509.c:x509_date_is_valid:
  567|  5.02k|{
  568|  5.02k|    unsigned int month_days;
  569|  5.02k|    unsigned int year;
  570|  5.02k|    switch (t->mon) {
  571|    785|        case 1: case 3: case 5: case 7: case 8: case 10: case 12:
  ------------------
  |  Branch (571:9): [True: 0, False: 5.02k]
  |  Branch (571:17): [True: 785, False: 4.23k]
  |  Branch (571:25): [True: 0, False: 5.02k]
  |  Branch (571:33): [True: 0, False: 5.02k]
  |  Branch (571:41): [True: 0, False: 5.02k]
  |  Branch (571:49): [True: 0, False: 5.02k]
  |  Branch (571:58): [True: 0, False: 5.02k]
  ------------------
  572|    785|            month_days = 31;
  573|    785|            break;
  574|  4.23k|        case 4: case 6: case 9: case 11:
  ------------------
  |  Branch (574:9): [True: 785, False: 4.23k]
  |  Branch (574:17): [True: 0, False: 5.02k]
  |  Branch (574:25): [True: 3.45k, False: 1.57k]
  |  Branch (574:33): [True: 0, False: 5.02k]
  ------------------
  575|  4.23k|            month_days = 30;
  576|  4.23k|            break;
  577|      0|        case 2:
  ------------------
  |  Branch (577:9): [True: 0, False: 5.02k]
  ------------------
  578|      0|            year = (unsigned int) t->year;
  579|      0|            month_days = ((year & 3) || (!(year % 100)
  ------------------
  |  Branch (579:27): [True: 0, False: 0]
  |  Branch (579:42): [True: 0, False: 0]
  ------------------
  580|      0|                                         && (year % 400)))
  ------------------
  |  Branch (580:45): [True: 0, False: 0]
  ------------------
  581|      0|                          ? 28 : 29;
  582|      0|            break;
  583|      0|        default:
  ------------------
  |  Branch (583:9): [True: 0, False: 5.02k]
  ------------------
  584|      0|            return MBEDTLS_ERR_X509_INVALID_DATE;
  ------------------
  |  |   59|      0|#define MBEDTLS_ERR_X509_INVALID_DATE                     -0x2400
  ------------------
  585|  5.02k|    }
  586|       |
  587|  5.02k|    if ((unsigned int) (t->day - 1) >= month_days ||      /* (1 - days in month) */
  ------------------
  |  Branch (587:9): [True: 0, False: 5.02k]
  ------------------
  588|       |        /* (unsigned int) (t->mon - 1) >= 12 || */  /* (1 - 12) checked above */
  589|  5.02k|        (unsigned int) t->year > 9999 ||         /* (0 - 9999) */
  ------------------
  |  Branch (589:9): [True: 0, False: 5.02k]
  ------------------
  590|  5.02k|        (unsigned int) t->hour > 23 ||           /* (0 - 23) */
  ------------------
  |  Branch (590:9): [True: 0, False: 5.02k]
  ------------------
  591|  5.02k|        (unsigned int) t->min  > 59 ||           /* (0 - 59) */
  ------------------
  |  Branch (591:9): [True: 0, False: 5.02k]
  ------------------
  592|  5.02k|        (unsigned int) t->sec  > 59) {           /* (0 - 59) */
  ------------------
  |  Branch (592:9): [True: 0, False: 5.02k]
  ------------------
  593|      0|        return MBEDTLS_ERR_X509_INVALID_DATE;
  ------------------
  |  |   59|      0|#define MBEDTLS_ERR_X509_INVALID_DATE                     -0x2400
  ------------------
  594|      0|    }
  595|       |
  596|  5.02k|    return 0;
  597|  5.02k|}
x509.c:x509_get_other_name:
 1128|  1.72k|{
 1129|  1.72k|    int ret = 0;
 1130|  1.72k|    size_t len;
 1131|  1.72k|    unsigned char *p = subject_alt_name->p;
 1132|  1.72k|    const unsigned char *end = p + subject_alt_name->len;
 1133|  1.72k|    mbedtls_x509_buf cur_oid;
 1134|       |
 1135|  1.72k|    if ((subject_alt_name->tag &
  ------------------
  |  Branch (1135:9): [True: 0, False: 1.72k]
  ------------------
 1136|  1.72k|         (MBEDTLS_ASN1_TAG_CLASS_MASK | MBEDTLS_ASN1_TAG_VALUE_MASK)) !=
  ------------------
  |  |  106|  1.72k|#define MBEDTLS_ASN1_TAG_CLASS_MASK          0xC0
  ------------------
                       (MBEDTLS_ASN1_TAG_CLASS_MASK | MBEDTLS_ASN1_TAG_VALUE_MASK)) !=
  ------------------
  |  |  108|  1.72k|#define MBEDTLS_ASN1_TAG_VALUE_MASK          0x1F
  ------------------
 1137|  1.72k|        (MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_X509_SAN_OTHER_NAME)) {
  ------------------
  |  |   83|  1.72k|#define MBEDTLS_ASN1_CONTEXT_SPECIFIC        0x80
  ------------------
                      (MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_X509_SAN_OTHER_NAME)) {
  ------------------
  |  |  127|  1.72k|#define MBEDTLS_X509_SAN_OTHER_NAME                      0
  ------------------
 1138|       |        /*
 1139|       |         * The given subject alternative name is not of type "othername".
 1140|       |         */
 1141|      0|        return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
  ------------------
  |  |   75|      0|#define MBEDTLS_ERR_X509_BAD_INPUT_DATA                   -0x2800
  ------------------
 1142|      0|    }
 1143|       |
 1144|  1.72k|    if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
  ------------------
  |  Branch (1144:9): [True: 0, False: 1.72k]
  ------------------
 1145|  1.72k|                                    MBEDTLS_ASN1_OID)) != 0) {
  ------------------
  |  |   69|  1.72k|#define MBEDTLS_ASN1_OID                     0x06
  ------------------
 1146|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
 1147|      0|    }
 1148|       |
 1149|  1.72k|    cur_oid.tag = MBEDTLS_ASN1_OID;
  ------------------
  |  |   69|  1.72k|#define MBEDTLS_ASN1_OID                     0x06
  ------------------
 1150|  1.72k|    cur_oid.p = p;
 1151|  1.72k|    cur_oid.len = len;
 1152|       |
 1153|       |    /*
 1154|       |     * Only HwModuleName is currently supported.
 1155|       |     */
 1156|  1.72k|    if (MBEDTLS_OID_CMP(MBEDTLS_OID_ON_HW_MODULE_NAME, &cur_oid) != 0) {
  ------------------
  |  |  122|  1.72k|    ((MBEDTLS_OID_SIZE(oid_str) != (oid_buf)->len) ||                \
  |  |  ------------------
  |  |  |  |  113|  1.72k|#define MBEDTLS_OID_SIZE(x) (sizeof(x) - 1)
  |  |  ------------------
  |  |  |  Branch (122:6): [True: 1.72k, False: 0]
  |  |  ------------------
  |  |  123|  1.72k|     memcmp((oid_str), (oid_buf)->p, (oid_buf)->len) != 0)
  |  |  ------------------
  |  |  |  Branch (123:6): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (1156:9): [True: 1.72k, False: 0]
  ------------------
 1157|  1.72k|        return MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE;
  ------------------
  |  |   45|  1.72k|#define MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE              -0x2080
  ------------------
 1158|  1.72k|    }
 1159|      0|    other_name->type_id = cur_oid;
 1160|       |
 1161|      0|    p += len;
 1162|      0|    if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
  ------------------
  |  Branch (1162:9): [True: 0, False: 0]
  ------------------
 1163|      0|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_CONTEXT_SPECIFIC)) !=
  ------------------
  |  |   82|      0|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_CONTEXT_SPECIFIC)) !=
  ------------------
  |  |   83|      0|#define MBEDTLS_ASN1_CONTEXT_SPECIFIC        0x80
  ------------------
 1164|      0|        0) {
 1165|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
 1166|      0|    }
 1167|       |
 1168|      0|    if (end != p + len) {
  ------------------
  |  Branch (1168:9): [True: 0, False: 0]
  ------------------
 1169|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
 1170|      0|                                 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
 1171|      0|    }
 1172|       |
 1173|      0|    if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
  ------------------
  |  Branch (1173:9): [True: 0, False: 0]
  ------------------
 1174|      0|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|      0|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|      0|#define MBEDTLS_ASN1_SEQUENCE                0x10
  ------------------
 1175|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
 1176|      0|    }
 1177|       |
 1178|      0|    if (end != p + len) {
  ------------------
  |  Branch (1178:9): [True: 0, False: 0]
  ------------------
 1179|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
 1180|      0|                                 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
 1181|      0|    }
 1182|       |
 1183|      0|    if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_OID)) != 0) {
  ------------------
  |  |   69|      0|#define MBEDTLS_ASN1_OID                     0x06
  ------------------
  |  Branch (1183:9): [True: 0, False: 0]
  ------------------
 1184|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
 1185|      0|    }
 1186|       |
 1187|      0|    other_name->value.hardware_module_name.oid.tag = MBEDTLS_ASN1_OID;
  ------------------
  |  |   69|      0|#define MBEDTLS_ASN1_OID                     0x06
  ------------------
 1188|      0|    other_name->value.hardware_module_name.oid.p = p;
 1189|      0|    other_name->value.hardware_module_name.oid.len = len;
 1190|       |
 1191|      0|    p += len;
 1192|      0|    if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
  ------------------
  |  Branch (1192:9): [True: 0, False: 0]
  ------------------
 1193|      0|                                    MBEDTLS_ASN1_OCTET_STRING)) != 0) {
  ------------------
  |  |   67|      0|#define MBEDTLS_ASN1_OCTET_STRING            0x04
  ------------------
 1194|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
 1195|      0|    }
 1196|       |
 1197|      0|    other_name->value.hardware_module_name.val.tag = MBEDTLS_ASN1_OCTET_STRING;
  ------------------
  |  |   67|      0|#define MBEDTLS_ASN1_OCTET_STRING            0x04
  ------------------
 1198|      0|    other_name->value.hardware_module_name.val.p = p;
 1199|      0|    other_name->value.hardware_module_name.val.len = len;
 1200|      0|    p += len;
 1201|      0|    if (p != end) {
  ------------------
  |  Branch (1201:9): [True: 0, False: 0]
  ------------------
 1202|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
 1203|      0|                                 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
 1204|      0|    }
 1205|      0|    return 0;
 1206|      0|}

mbedtls_x509_crt_parse_der:
 1386|  2.51k|{
 1387|  2.51k|    return mbedtls_x509_crt_parse_der_internal(chain, buf, buflen, 1, NULL, NULL);
 1388|  2.51k|}
mbedtls_x509_crt_check_key_usage:
 1932|    314|{
 1933|    314|    unsigned int usage_must, usage_may;
 1934|    314|    unsigned int may_mask = MBEDTLS_X509_KU_ENCIPHER_ONLY
  ------------------
  |  |  148|    314|#define MBEDTLS_X509_KU_ENCIPHER_ONLY                (0x01)  /* bit 7 */
  ------------------
 1935|    314|                            | MBEDTLS_X509_KU_DECIPHER_ONLY;
  ------------------
  |  |  149|    314|#define MBEDTLS_X509_KU_DECIPHER_ONLY              (0x8000)  /* bit 8 */
  ------------------
 1936|       |
 1937|    314|    if ((crt->ext_types & MBEDTLS_X509_EXT_KEY_USAGE) == 0) {
  ------------------
  |  |  176|    314|#define MBEDTLS_X509_EXT_KEY_USAGE                MBEDTLS_OID_X509_EXT_KEY_USAGE
  |  |  ------------------
  |  |  |  |   39|    314|#define MBEDTLS_OID_X509_EXT_KEY_USAGE                   (1 << 2)
  |  |  ------------------
  ------------------
  |  Branch (1937:9): [True: 157, False: 157]
  ------------------
 1938|    157|        return 0;
 1939|    157|    }
 1940|       |
 1941|    157|    usage_must = usage & ~may_mask;
 1942|       |
 1943|    157|    if (((crt->key_usage & ~may_mask) & usage_must) != usage_must) {
  ------------------
  |  Branch (1943:9): [True: 0, False: 157]
  ------------------
 1944|      0|        return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
  ------------------
  |  |   75|      0|#define MBEDTLS_ERR_X509_BAD_INPUT_DATA                   -0x2800
  ------------------
 1945|      0|    }
 1946|       |
 1947|    157|    usage_may = usage & may_mask;
 1948|       |
 1949|    157|    if (((crt->key_usage & may_mask) | usage_may) != usage_may) {
  ------------------
  |  Branch (1949:9): [True: 0, False: 157]
  ------------------
 1950|      0|        return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
  ------------------
  |  |   75|      0|#define MBEDTLS_ERR_X509_BAD_INPUT_DATA                   -0x2800
  ------------------
 1951|      0|    }
 1952|       |
 1953|    157|    return 0;
 1954|    157|}
mbedtls_x509_crt_verify_with_profile:
 3175|    471|{
 3176|    471|    return x509_crt_verify_restartable_ca_cb(crt, trust_ca, ca_crl,
 3177|    471|                                             NULL, NULL,
 3178|    471|                                             profile, cn, flags,
 3179|    471|                                             f_vrfy, p_vrfy, NULL);
 3180|    471|}
mbedtls_x509_crt_init:
 3222|  2.51k|{
 3223|  2.51k|    memset(crt, 0, sizeof(mbedtls_x509_crt));
 3224|  2.51k|}
mbedtls_x509_crt_free:
 3230|  2.51k|{
 3231|  2.51k|    mbedtls_x509_crt *cert_cur = crt;
 3232|  2.51k|    mbedtls_x509_crt *cert_prv;
 3233|       |
 3234|  5.02k|    while (cert_cur != NULL) {
  ------------------
  |  Branch (3234:12): [True: 2.51k, False: 2.51k]
  ------------------
 3235|  2.51k|        mbedtls_pk_free(&cert_cur->pk);
 3236|       |
 3237|  2.51k|#if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
 3238|  2.51k|        mbedtls_free(cert_cur->sig_opts);
  ------------------
  |  |  143|  2.51k|#define mbedtls_free       MBEDTLS_PLATFORM_FREE_MACRO
  |  |  ------------------
  |  |  |  | 4095|  2.51k|#define MBEDTLS_PLATFORM_FREE_MACRO            my_free
  |  |  ------------------
  ------------------
 3239|  2.51k|#endif
 3240|       |
 3241|  2.51k|        mbedtls_asn1_free_named_data_list_shallow(cert_cur->issuer.next);
 3242|  2.51k|        mbedtls_asn1_free_named_data_list_shallow(cert_cur->subject.next);
 3243|  2.51k|        mbedtls_asn1_sequence_free(cert_cur->ext_key_usage.next);
 3244|  2.51k|        mbedtls_asn1_sequence_free(cert_cur->subject_alt_names.next);
 3245|  2.51k|        mbedtls_asn1_sequence_free(cert_cur->certificate_policies.next);
 3246|  2.51k|        mbedtls_asn1_sequence_free(cert_cur->authority_key_id.authorityCertIssuer.next);
 3247|       |
 3248|  2.51k|        if (cert_cur->raw.p != NULL && cert_cur->own_buffer) {
  ------------------
  |  Branch (3248:13): [True: 2.51k, False: 0]
  |  Branch (3248:40): [True: 2.51k, False: 0]
  ------------------
 3249|  2.51k|            mbedtls_zeroize_and_free(cert_cur->raw.p, cert_cur->raw.len);
 3250|  2.51k|        }
 3251|       |
 3252|  2.51k|        cert_prv = cert_cur;
 3253|  2.51k|        cert_cur = cert_cur->next;
 3254|       |
 3255|  2.51k|        mbedtls_platform_zeroize(cert_prv, sizeof(mbedtls_x509_crt));
 3256|  2.51k|        if (cert_prv != crt) {
  ------------------
  |  Branch (3256:13): [True: 0, False: 2.51k]
  ------------------
 3257|      0|            mbedtls_free(cert_prv);
  ------------------
  |  |  143|      0|#define mbedtls_free       MBEDTLS_PLATFORM_FREE_MACRO
  |  |  ------------------
  |  |  |  | 4095|      0|#define MBEDTLS_PLATFORM_FREE_MACRO            my_free
  |  |  ------------------
  ------------------
 3258|      0|        }
 3259|  2.51k|    }
 3260|  2.51k|}
x509_crt.c:mbedtls_x509_crt_parse_der_internal:
 1319|  2.51k|{
 1320|  2.51k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  2.51k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1321|  2.51k|    mbedtls_x509_crt *crt = chain, *prev = NULL;
 1322|       |
 1323|       |    /*
 1324|       |     * Check for valid input
 1325|       |     */
 1326|  2.51k|    if (crt == NULL || buf == NULL) {
  ------------------
  |  Branch (1326:9): [True: 0, False: 2.51k]
  |  Branch (1326:24): [True: 0, False: 2.51k]
  ------------------
 1327|      0|        return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
  ------------------
  |  |   75|      0|#define MBEDTLS_ERR_X509_BAD_INPUT_DATA                   -0x2800
  ------------------
 1328|      0|    }
 1329|       |
 1330|  2.51k|    while (crt->version != 0 && crt->next != NULL) {
  ------------------
  |  Branch (1330:12): [True: 0, False: 2.51k]
  |  Branch (1330:33): [True: 0, False: 0]
  ------------------
 1331|      0|        prev = crt;
 1332|      0|        crt = crt->next;
 1333|      0|    }
 1334|       |
 1335|       |    /*
 1336|       |     * Add new certificate on the end of the chain if needed.
 1337|       |     */
 1338|  2.51k|    if (crt->version != 0 && crt->next == NULL) {
  ------------------
  |  Branch (1338:9): [True: 0, False: 2.51k]
  |  Branch (1338:30): [True: 0, False: 0]
  ------------------
 1339|      0|        crt->next = mbedtls_calloc(1, sizeof(mbedtls_x509_crt));
  ------------------
  |  |  144|      0|#define mbedtls_calloc     MBEDTLS_PLATFORM_CALLOC_MACRO
  |  |  ------------------
  |  |  |  | 4093|      0|#define MBEDTLS_PLATFORM_CALLOC_MACRO        my_calloc
  |  |  ------------------
  ------------------
 1340|       |
 1341|      0|        if (crt->next == NULL) {
  ------------------
  |  Branch (1341:13): [True: 0, False: 0]
  ------------------
 1342|      0|            return MBEDTLS_ERR_X509_ALLOC_FAILED;
  ------------------
  |  |   77|      0|#define MBEDTLS_ERR_X509_ALLOC_FAILED                     -0x2880
  ------------------
 1343|      0|        }
 1344|       |
 1345|      0|        prev = crt;
 1346|      0|        mbedtls_x509_crt_init(crt->next);
 1347|      0|        crt = crt->next;
 1348|      0|    }
 1349|       |
 1350|  2.51k|    ret = x509_crt_parse_der_core(crt, buf, buflen, make_copy, cb, p_ctx);
 1351|  2.51k|    if (ret != 0) {
  ------------------
  |  Branch (1351:9): [True: 0, False: 2.51k]
  ------------------
 1352|      0|        if (prev) {
  ------------------
  |  Branch (1352:13): [True: 0, False: 0]
  ------------------
 1353|      0|            prev->next = NULL;
 1354|      0|        }
 1355|       |
 1356|      0|        if (crt != chain) {
  ------------------
  |  Branch (1356:13): [True: 0, False: 0]
  ------------------
 1357|      0|            mbedtls_free(crt);
  ------------------
  |  |  143|      0|#define mbedtls_free       MBEDTLS_PLATFORM_FREE_MACRO
  |  |  ------------------
  |  |  |  | 4095|      0|#define MBEDTLS_PLATFORM_FREE_MACRO            my_free
  |  |  ------------------
  ------------------
 1358|      0|        }
 1359|       |
 1360|      0|        return ret;
 1361|      0|    }
 1362|       |
 1363|  2.51k|    return 0;
 1364|  2.51k|}
x509_crt.c:x509_crt_parse_der_core:
 1079|  2.51k|{
 1080|  2.51k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  2.51k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1081|  2.51k|    size_t len;
 1082|  2.51k|    unsigned char *p, *end, *crt_end;
 1083|  2.51k|    mbedtls_x509_buf sig_params1, sig_params2, sig_oid2;
 1084|       |
 1085|  2.51k|    memset(&sig_params1, 0, sizeof(mbedtls_x509_buf));
 1086|  2.51k|    memset(&sig_params2, 0, sizeof(mbedtls_x509_buf));
 1087|  2.51k|    memset(&sig_oid2, 0, sizeof(mbedtls_x509_buf));
 1088|       |
 1089|       |    /*
 1090|       |     * Check for valid input
 1091|       |     */
 1092|  2.51k|    if (crt == NULL || buf == NULL) {
  ------------------
  |  Branch (1092:9): [True: 0, False: 2.51k]
  |  Branch (1092:24): [True: 0, False: 2.51k]
  ------------------
 1093|      0|        return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
  ------------------
  |  |   75|      0|#define MBEDTLS_ERR_X509_BAD_INPUT_DATA                   -0x2800
  ------------------
 1094|      0|    }
 1095|       |
 1096|       |    /* Use the original buffer until we figure out actual length. */
 1097|  2.51k|    p = (unsigned char *) buf;
 1098|  2.51k|    len = buflen;
 1099|  2.51k|    end = p + len;
 1100|       |
 1101|       |    /*
 1102|       |     * Certificate  ::=  SEQUENCE  {
 1103|       |     *      tbsCertificate       TBSCertificate,
 1104|       |     *      signatureAlgorithm   AlgorithmIdentifier,
 1105|       |     *      signatureValue       BIT STRING  }
 1106|       |     */
 1107|  2.51k|    if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
  ------------------
  |  Branch (1107:9): [True: 0, False: 2.51k]
  ------------------
 1108|  2.51k|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|  2.51k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|  2.51k|#define MBEDTLS_ASN1_SEQUENCE                0x10
  ------------------
 1109|      0|        mbedtls_x509_crt_free(crt);
 1110|      0|        return MBEDTLS_ERR_X509_INVALID_FORMAT;
  ------------------
  |  |   49|      0|#define MBEDTLS_ERR_X509_INVALID_FORMAT                   -0x2180
  ------------------
 1111|      0|    }
 1112|       |
 1113|  2.51k|    end = crt_end = p + len;
 1114|  2.51k|    crt->raw.len = (size_t) (crt_end - buf);
 1115|  2.51k|    if (make_copy != 0) {
  ------------------
  |  Branch (1115:9): [True: 2.51k, False: 0]
  ------------------
 1116|       |        /* Create and populate a new buffer for the raw field. */
 1117|  2.51k|        crt->raw.p = p = mbedtls_calloc(1, crt->raw.len);
  ------------------
  |  |  144|  2.51k|#define mbedtls_calloc     MBEDTLS_PLATFORM_CALLOC_MACRO
  |  |  ------------------
  |  |  |  | 4093|  2.51k|#define MBEDTLS_PLATFORM_CALLOC_MACRO        my_calloc
  |  |  ------------------
  ------------------
 1118|  2.51k|        if (crt->raw.p == NULL) {
  ------------------
  |  Branch (1118:13): [True: 0, False: 2.51k]
  ------------------
 1119|      0|            return MBEDTLS_ERR_X509_ALLOC_FAILED;
  ------------------
  |  |   77|      0|#define MBEDTLS_ERR_X509_ALLOC_FAILED                     -0x2880
  ------------------
 1120|      0|        }
 1121|       |
 1122|  2.51k|        memcpy(crt->raw.p, buf, crt->raw.len);
 1123|  2.51k|        crt->own_buffer = 1;
 1124|       |
 1125|  2.51k|        p += crt->raw.len - len;
 1126|  2.51k|        end = crt_end = p + len;
 1127|  2.51k|    } else {
 1128|      0|        crt->raw.p = (unsigned char *) buf;
 1129|      0|        crt->own_buffer = 0;
 1130|      0|    }
 1131|       |
 1132|       |    /*
 1133|       |     * TBSCertificate  ::=  SEQUENCE  {
 1134|       |     */
 1135|  2.51k|    crt->tbs.p = p;
 1136|       |
 1137|  2.51k|    if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
  ------------------
  |  Branch (1137:9): [True: 0, False: 2.51k]
  ------------------
 1138|  2.51k|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|  2.51k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|  2.51k|#define MBEDTLS_ASN1_SEQUENCE                0x10
  ------------------
 1139|      0|        mbedtls_x509_crt_free(crt);
 1140|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_FORMAT, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
 1141|      0|    }
 1142|       |
 1143|  2.51k|    end = p + len;
 1144|  2.51k|    crt->tbs.len = (size_t) (end - crt->tbs.p);
 1145|       |
 1146|       |    /*
 1147|       |     * Version  ::=  INTEGER  {  v1(0), v2(1), v3(2)  }
 1148|       |     *
 1149|       |     * CertificateSerialNumber  ::=  INTEGER
 1150|       |     *
 1151|       |     * signature            AlgorithmIdentifier
 1152|       |     */
 1153|  2.51k|    if ((ret = x509_get_version(&p, end, &crt->version)) != 0 ||
  ------------------
  |  Branch (1153:9): [True: 0, False: 2.51k]
  ------------------
 1154|  2.51k|        (ret = mbedtls_x509_get_serial(&p, end, &crt->serial)) != 0 ||
  ------------------
  |  Branch (1154:9): [True: 0, False: 2.51k]
  ------------------
 1155|  2.51k|        (ret = mbedtls_x509_get_alg(&p, end, &crt->sig_oid,
  ------------------
  |  Branch (1155:9): [True: 0, False: 2.51k]
  ------------------
 1156|  2.51k|                                    &sig_params1)) != 0) {
 1157|      0|        mbedtls_x509_crt_free(crt);
 1158|      0|        return ret;
 1159|      0|    }
 1160|       |
 1161|  2.51k|    if (crt->version < 0 || crt->version > 2) {
  ------------------
  |  Branch (1161:9): [True: 0, False: 2.51k]
  |  Branch (1161:29): [True: 0, False: 2.51k]
  ------------------
 1162|      0|        mbedtls_x509_crt_free(crt);
 1163|      0|        return MBEDTLS_ERR_X509_UNKNOWN_VERSION;
  ------------------
  |  |   65|      0|#define MBEDTLS_ERR_X509_UNKNOWN_VERSION                  -0x2580
  ------------------
 1164|      0|    }
 1165|       |
 1166|  2.51k|    crt->version++;
 1167|       |
 1168|  2.51k|    if ((ret = mbedtls_x509_get_sig_alg(&crt->sig_oid, &sig_params1,
  ------------------
  |  Branch (1168:9): [True: 0, False: 2.51k]
  ------------------
 1169|  2.51k|                                        &crt->sig_md, &crt->sig_pk,
 1170|  2.51k|                                        &crt->sig_opts)) != 0) {
 1171|      0|        mbedtls_x509_crt_free(crt);
 1172|      0|        return ret;
 1173|      0|    }
 1174|       |
 1175|       |    /*
 1176|       |     * issuer               Name
 1177|       |     */
 1178|  2.51k|    crt->issuer_raw.p = p;
 1179|       |
 1180|  2.51k|    if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
  ------------------
  |  Branch (1180:9): [True: 0, False: 2.51k]
  ------------------
 1181|  2.51k|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|  2.51k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|  2.51k|#define MBEDTLS_ASN1_SEQUENCE                0x10
  ------------------
 1182|      0|        mbedtls_x509_crt_free(crt);
 1183|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_FORMAT, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
 1184|      0|    }
 1185|       |
 1186|  2.51k|    if ((ret = mbedtls_x509_get_name(&p, p + len, &crt->issuer)) != 0) {
  ------------------
  |  Branch (1186:9): [True: 0, False: 2.51k]
  ------------------
 1187|      0|        mbedtls_x509_crt_free(crt);
 1188|      0|        return ret;
 1189|      0|    }
 1190|       |
 1191|  2.51k|    crt->issuer_raw.len = (size_t) (p - crt->issuer_raw.p);
 1192|       |
 1193|       |    /*
 1194|       |     * Validity ::= SEQUENCE {
 1195|       |     *      notBefore      Time,
 1196|       |     *      notAfter       Time }
 1197|       |     *
 1198|       |     */
 1199|  2.51k|    if ((ret = x509_get_dates(&p, end, &crt->valid_from,
  ------------------
  |  Branch (1199:9): [True: 0, False: 2.51k]
  ------------------
 1200|  2.51k|                              &crt->valid_to)) != 0) {
 1201|      0|        mbedtls_x509_crt_free(crt);
 1202|      0|        return ret;
 1203|      0|    }
 1204|       |
 1205|       |    /*
 1206|       |     * subject              Name
 1207|       |     */
 1208|  2.51k|    crt->subject_raw.p = p;
 1209|       |
 1210|  2.51k|    if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
  ------------------
  |  Branch (1210:9): [True: 0, False: 2.51k]
  ------------------
 1211|  2.51k|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|  2.51k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|  2.51k|#define MBEDTLS_ASN1_SEQUENCE                0x10
  ------------------
 1212|      0|        mbedtls_x509_crt_free(crt);
 1213|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_FORMAT, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
 1214|      0|    }
 1215|       |
 1216|  2.51k|    if (len && (ret = mbedtls_x509_get_name(&p, p + len, &crt->subject)) != 0) {
  ------------------
  |  Branch (1216:9): [True: 2.51k, False: 0]
  |  Branch (1216:16): [True: 0, False: 2.51k]
  ------------------
 1217|      0|        mbedtls_x509_crt_free(crt);
 1218|      0|        return ret;
 1219|      0|    }
 1220|       |
 1221|  2.51k|    crt->subject_raw.len = (size_t) (p - crt->subject_raw.p);
 1222|       |
 1223|       |    /*
 1224|       |     * SubjectPublicKeyInfo
 1225|       |     */
 1226|  2.51k|    crt->pk_raw.p = p;
 1227|  2.51k|    if ((ret = mbedtls_pk_parse_subpubkey(&p, end, &crt->pk)) != 0) {
  ------------------
  |  Branch (1227:9): [True: 0, False: 2.51k]
  ------------------
 1228|      0|        mbedtls_x509_crt_free(crt);
 1229|      0|        return ret;
 1230|      0|    }
 1231|  2.51k|    crt->pk_raw.len = (size_t) (p - crt->pk_raw.p);
 1232|       |
 1233|       |    /*
 1234|       |     *  issuerUniqueID  [1]  IMPLICIT UniqueIdentifier OPTIONAL,
 1235|       |     *                       -- If present, version shall be v2 or v3
 1236|       |     *  subjectUniqueID [2]  IMPLICIT UniqueIdentifier OPTIONAL,
 1237|       |     *                       -- If present, version shall be v2 or v3
 1238|       |     *  extensions      [3]  EXPLICIT Extensions OPTIONAL
 1239|       |     *                       -- If present, version shall be v3
 1240|       |     */
 1241|  2.51k|    if (crt->version == 2 || crt->version == 3) {
  ------------------
  |  Branch (1241:9): [True: 0, False: 2.51k]
  |  Branch (1241:30): [True: 2.51k, False: 0]
  ------------------
 1242|  2.51k|        ret = x509_get_uid(&p, end, &crt->issuer_id,  1);
 1243|  2.51k|        if (ret != 0) {
  ------------------
  |  Branch (1243:13): [True: 0, False: 2.51k]
  ------------------
 1244|      0|            mbedtls_x509_crt_free(crt);
 1245|      0|            return ret;
 1246|      0|        }
 1247|  2.51k|    }
 1248|       |
 1249|  2.51k|    if (crt->version == 2 || crt->version == 3) {
  ------------------
  |  Branch (1249:9): [True: 0, False: 2.51k]
  |  Branch (1249:30): [True: 2.51k, False: 0]
  ------------------
 1250|  2.51k|        ret = x509_get_uid(&p, end, &crt->subject_id,  2);
 1251|  2.51k|        if (ret != 0) {
  ------------------
  |  Branch (1251:13): [True: 0, False: 2.51k]
  ------------------
 1252|      0|            mbedtls_x509_crt_free(crt);
 1253|      0|            return ret;
 1254|      0|        }
 1255|  2.51k|    }
 1256|       |
 1257|  2.51k|    if (crt->version == 3) {
  ------------------
  |  Branch (1257:9): [True: 2.51k, False: 0]
  ------------------
 1258|  2.51k|        ret = x509_get_crt_ext(&p, end, crt, cb, p_ctx);
 1259|  2.51k|        if (ret != 0) {
  ------------------
  |  Branch (1259:13): [True: 0, False: 2.51k]
  ------------------
 1260|      0|            mbedtls_x509_crt_free(crt);
 1261|      0|            return ret;
 1262|      0|        }
 1263|  2.51k|    }
 1264|       |
 1265|  2.51k|    if (p != end) {
  ------------------
  |  Branch (1265:9): [True: 0, False: 2.51k]
  ------------------
 1266|      0|        mbedtls_x509_crt_free(crt);
 1267|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_FORMAT,
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
 1268|      0|                                 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
 1269|      0|    }
 1270|       |
 1271|  2.51k|    end = crt_end;
 1272|       |
 1273|       |    /*
 1274|       |     *  }
 1275|       |     *  -- end of TBSCertificate
 1276|       |     *
 1277|       |     *  signatureAlgorithm   AlgorithmIdentifier,
 1278|       |     *  signatureValue       BIT STRING
 1279|       |     */
 1280|  2.51k|    if ((ret = mbedtls_x509_get_alg(&p, end, &sig_oid2, &sig_params2)) != 0) {
  ------------------
  |  Branch (1280:9): [True: 0, False: 2.51k]
  ------------------
 1281|      0|        mbedtls_x509_crt_free(crt);
 1282|      0|        return ret;
 1283|      0|    }
 1284|       |
 1285|  2.51k|    if (crt->sig_oid.len != sig_oid2.len ||
  ------------------
  |  Branch (1285:9): [True: 0, False: 2.51k]
  ------------------
 1286|  2.51k|        memcmp(crt->sig_oid.p, sig_oid2.p, crt->sig_oid.len) != 0 ||
  ------------------
  |  Branch (1286:9): [True: 0, False: 2.51k]
  ------------------
 1287|  2.51k|        sig_params1.tag != sig_params2.tag ||
  ------------------
  |  Branch (1287:9): [True: 0, False: 2.51k]
  ------------------
 1288|  2.51k|        sig_params1.len != sig_params2.len ||
  ------------------
  |  Branch (1288:9): [True: 0, False: 2.51k]
  ------------------
 1289|  2.51k|        (sig_params1.len != 0 &&
  ------------------
  |  Branch (1289:10): [True: 0, False: 2.51k]
  ------------------
 1290|  2.51k|         memcmp(sig_params1.p, sig_params2.p, sig_params1.len) != 0)) {
  ------------------
  |  Branch (1290:10): [True: 0, False: 0]
  ------------------
 1291|      0|        mbedtls_x509_crt_free(crt);
 1292|      0|        return MBEDTLS_ERR_X509_SIG_MISMATCH;
  ------------------
  |  |   69|      0|#define MBEDTLS_ERR_X509_SIG_MISMATCH                     -0x2680
  ------------------
 1293|      0|    }
 1294|       |
 1295|  2.51k|    if ((ret = mbedtls_x509_get_sig(&p, end, &crt->sig)) != 0) {
  ------------------
  |  Branch (1295:9): [True: 0, False: 2.51k]
  ------------------
 1296|      0|        mbedtls_x509_crt_free(crt);
 1297|      0|        return ret;
 1298|      0|    }
 1299|       |
 1300|  2.51k|    if (p != end) {
  ------------------
  |  Branch (1300:9): [True: 0, False: 2.51k]
  ------------------
 1301|      0|        mbedtls_x509_crt_free(crt);
 1302|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_FORMAT,
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
 1303|      0|                                 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
 1304|      0|    }
 1305|       |
 1306|  2.51k|    return 0;
 1307|  2.51k|}
x509_crt.c:x509_get_version:
  398|  2.51k|{
  399|  2.51k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  2.51k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  400|  2.51k|    size_t len;
  401|       |
  402|  2.51k|    if ((ret = mbedtls_asn1_get_tag(p, end, &len,
  ------------------
  |  Branch (402:9): [True: 0, False: 2.51k]
  ------------------
  403|  2.51k|                                    MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED |
  ------------------
  |  |   83|  2.51k|#define MBEDTLS_ASN1_CONTEXT_SPECIFIC        0x80
  ------------------
                                                  MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED |
  ------------------
  |  |   82|  2.51k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
  404|  2.51k|                                    0)) != 0) {
  405|      0|        if (ret == MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) {
  ------------------
  |  |   39|      0|#define MBEDTLS_ERR_ASN1_UNEXPECTED_TAG                   -0x0062
  ------------------
  |  Branch (405:13): [True: 0, False: 0]
  ------------------
  406|      0|            *ver = 0;
  407|      0|            return 0;
  408|      0|        }
  409|       |
  410|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_FORMAT, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  411|      0|    }
  412|       |
  413|  2.51k|    end = *p + len;
  414|       |
  415|  2.51k|    if ((ret = mbedtls_asn1_get_int(p, end, ver)) != 0) {
  ------------------
  |  Branch (415:9): [True: 0, False: 2.51k]
  ------------------
  416|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_VERSION, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  417|      0|    }
  418|       |
  419|  2.51k|    if (*p != end) {
  ------------------
  |  Branch (419:9): [True: 0, False: 2.51k]
  ------------------
  420|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_VERSION,
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  421|      0|                                 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
  422|      0|    }
  423|       |
  424|  2.51k|    return 0;
  425|  2.51k|}
x509_crt.c:x509_get_dates:
  436|  2.51k|{
  437|  2.51k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  2.51k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  438|  2.51k|    size_t len;
  439|       |
  440|  2.51k|    if ((ret = mbedtls_asn1_get_tag(p, end, &len,
  ------------------
  |  Branch (440:9): [True: 0, False: 2.51k]
  ------------------
  441|  2.51k|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|  2.51k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|  2.51k|#define MBEDTLS_ASN1_SEQUENCE                0x10
  ------------------
  442|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_DATE, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  443|      0|    }
  444|       |
  445|  2.51k|    end = *p + len;
  446|       |
  447|  2.51k|    if ((ret = mbedtls_x509_get_time(p, end, from)) != 0) {
  ------------------
  |  Branch (447:9): [True: 0, False: 2.51k]
  ------------------
  448|      0|        return ret;
  449|      0|    }
  450|       |
  451|  2.51k|    if ((ret = mbedtls_x509_get_time(p, end, to)) != 0) {
  ------------------
  |  Branch (451:9): [True: 0, False: 2.51k]
  ------------------
  452|      0|        return ret;
  453|      0|    }
  454|       |
  455|  2.51k|    if (*p != end) {
  ------------------
  |  Branch (455:9): [True: 0, False: 2.51k]
  ------------------
  456|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_DATE,
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  457|      0|                                 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
  458|      0|    }
  459|       |
  460|  2.51k|    return 0;
  461|  2.51k|}
x509_crt.c:x509_get_uid:
  469|  5.02k|{
  470|  5.02k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  5.02k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  471|       |
  472|  5.02k|    if (*p == end) {
  ------------------
  |  Branch (472:9): [True: 0, False: 5.02k]
  ------------------
  473|      0|        return 0;
  474|      0|    }
  475|       |
  476|  5.02k|    uid->tag = **p;
  477|       |
  478|  5.02k|    if ((ret = mbedtls_asn1_get_tag(p, end, &uid->len,
  ------------------
  |  Branch (478:9): [True: 5.02k, False: 0]
  ------------------
  479|  5.02k|                                    MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED |
  ------------------
  |  |   83|  5.02k|#define MBEDTLS_ASN1_CONTEXT_SPECIFIC        0x80
  ------------------
                                                  MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED |
  ------------------
  |  |   82|  5.02k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
  480|  5.02k|                                    n)) != 0) {
  481|  5.02k|        if (ret == MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) {
  ------------------
  |  |   39|  5.02k|#define MBEDTLS_ERR_ASN1_UNEXPECTED_TAG                   -0x0062
  ------------------
  |  Branch (481:13): [True: 5.02k, False: 0]
  ------------------
  482|  5.02k|            return 0;
  483|  5.02k|        }
  484|       |
  485|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_FORMAT, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  486|  5.02k|    }
  487|       |
  488|      0|    uid->p = *p;
  489|      0|    *p += uid->len;
  490|       |
  491|      0|    return 0;
  492|  5.02k|}
x509_crt.c:x509_get_crt_ext:
  867|  2.51k|{
  868|  2.51k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  2.51k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  869|  2.51k|    size_t len;
  870|  2.51k|    unsigned char *end_ext_data, *start_ext_octet, *end_ext_octet;
  871|       |
  872|  2.51k|    if (*p == end) {
  ------------------
  |  Branch (872:9): [True: 0, False: 2.51k]
  ------------------
  873|      0|        return 0;
  874|      0|    }
  875|       |
  876|  2.51k|    if ((ret = mbedtls_x509_get_ext(p, end, &crt->v3_ext, 3)) != 0) {
  ------------------
  |  Branch (876:9): [True: 0, False: 2.51k]
  ------------------
  877|      0|        return ret;
  878|      0|    }
  879|       |
  880|  2.51k|    end = crt->v3_ext.p + crt->v3_ext.len;
  881|  15.5k|    while (*p < end) {
  ------------------
  |  Branch (881:12): [True: 13.0k, False: 2.51k]
  ------------------
  882|       |        /*
  883|       |         * Extension  ::=  SEQUENCE  {
  884|       |         *      extnID      OBJECT IDENTIFIER,
  885|       |         *      critical    BOOLEAN DEFAULT FALSE,
  886|       |         *      extnValue   OCTET STRING  }
  887|       |         */
  888|  13.0k|        mbedtls_x509_buf extn_oid = { 0, 0, NULL };
  889|  13.0k|        int is_critical = 0; /* DEFAULT FALSE */
  890|  13.0k|        int ext_type = 0;
  891|       |
  892|  13.0k|        if ((ret = mbedtls_asn1_get_tag(p, end, &len,
  ------------------
  |  Branch (892:13): [True: 0, False: 13.0k]
  ------------------
  893|  13.0k|                                        MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|  13.0k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                      MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|  13.0k|#define MBEDTLS_ASN1_SEQUENCE                0x10
  ------------------
  894|      0|            return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  895|      0|        }
  896|       |
  897|  13.0k|        end_ext_data = *p + len;
  898|       |
  899|       |        /* Get extension ID */
  900|  13.0k|        if ((ret = mbedtls_asn1_get_tag(p, end_ext_data, &extn_oid.len,
  ------------------
  |  Branch (900:13): [True: 0, False: 13.0k]
  ------------------
  901|  13.0k|                                        MBEDTLS_ASN1_OID)) != 0) {
  ------------------
  |  |   69|  13.0k|#define MBEDTLS_ASN1_OID                     0x06
  ------------------
  902|      0|            return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  903|      0|        }
  904|       |
  905|  13.0k|        extn_oid.tag = MBEDTLS_ASN1_OID;
  ------------------
  |  |   69|  13.0k|#define MBEDTLS_ASN1_OID                     0x06
  ------------------
  906|  13.0k|        extn_oid.p = *p;
  907|  13.0k|        *p += extn_oid.len;
  908|       |
  909|       |        /* Get optional critical */
  910|  13.0k|        if ((ret = mbedtls_asn1_get_bool(p, end_ext_data, &is_critical)) != 0 &&
  ------------------
  |  Branch (910:13): [True: 8.79k, False: 4.23k]
  ------------------
  911|  13.0k|            (ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG)) {
  ------------------
  |  |   39|  8.79k|#define MBEDTLS_ERR_ASN1_UNEXPECTED_TAG                   -0x0062
  ------------------
  |  Branch (911:13): [True: 0, False: 8.79k]
  ------------------
  912|      0|            return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  913|      0|        }
  914|       |
  915|       |        /* Data should be octet string type */
  916|  13.0k|        if ((ret = mbedtls_asn1_get_tag(p, end_ext_data, &len,
  ------------------
  |  Branch (916:13): [True: 0, False: 13.0k]
  ------------------
  917|  13.0k|                                        MBEDTLS_ASN1_OCTET_STRING)) != 0) {
  ------------------
  |  |   67|  13.0k|#define MBEDTLS_ASN1_OCTET_STRING            0x04
  ------------------
  918|      0|            return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  919|      0|        }
  920|       |
  921|  13.0k|        start_ext_octet = *p;
  922|  13.0k|        end_ext_octet = *p + len;
  923|       |
  924|  13.0k|        if (end_ext_octet != end_ext_data) {
  ------------------
  |  Branch (924:13): [True: 0, False: 13.0k]
  ------------------
  925|      0|            return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  926|      0|                                     MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
  927|      0|        }
  928|       |
  929|       |        /*
  930|       |         * Detect supported extensions
  931|       |         */
  932|  13.0k|        ret = mbedtls_oid_get_x509_ext_type(&extn_oid, &ext_type);
  933|       |
  934|  13.0k|        if (ret != 0) {
  ------------------
  |  Branch (934:13): [True: 1.72k, False: 11.3k]
  ------------------
  935|       |            /* Give the callback (if any) a chance to handle the extension */
  936|  1.72k|            if (cb != NULL) {
  ------------------
  |  Branch (936:17): [True: 0, False: 1.72k]
  ------------------
  937|      0|                ret = cb(p_ctx, crt, &extn_oid, is_critical, *p, end_ext_octet);
  938|      0|                if (ret != 0 && is_critical) {
  ------------------
  |  Branch (938:21): [True: 0, False: 0]
  |  Branch (938:33): [True: 0, False: 0]
  ------------------
  939|      0|                    return ret;
  940|      0|                }
  941|      0|                *p = end_ext_octet;
  942|      0|                continue;
  943|      0|            }
  944|       |
  945|       |            /* No parser found, skip extension */
  946|  1.72k|            *p = end_ext_octet;
  947|       |
  948|  1.72k|            if (is_critical) {
  ------------------
  |  Branch (948:17): [True: 0, False: 1.72k]
  ------------------
  949|       |                /* Data is marked as critical: fail */
  950|      0|                return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  951|      0|                                         MBEDTLS_ERR_ASN1_UNEXPECTED_TAG);
  952|      0|            }
  953|  1.72k|            continue;
  954|  1.72k|        }
  955|       |
  956|       |        /* Forbid repeated extensions */
  957|  11.3k|        if ((crt->ext_types & ext_type) != 0) {
  ------------------
  |  Branch (957:13): [True: 0, False: 11.3k]
  ------------------
  958|      0|            return MBEDTLS_ERR_X509_INVALID_EXTENSIONS;
  ------------------
  |  |   63|      0|#define MBEDTLS_ERR_X509_INVALID_EXTENSIONS               -0x2500
  ------------------
  959|      0|        }
  960|       |
  961|  11.3k|        crt->ext_types |= ext_type;
  962|       |
  963|  11.3k|        switch (ext_type) {
  964|  2.51k|            case MBEDTLS_X509_EXT_BASIC_CONSTRAINTS:
  ------------------
  |  |  182|  2.51k|#define MBEDTLS_X509_EXT_BASIC_CONSTRAINTS        MBEDTLS_OID_X509_EXT_BASIC_CONSTRAINTS        /* Supported */
  |  |  ------------------
  |  |  |  |   45|  2.51k|#define MBEDTLS_OID_X509_EXT_BASIC_CONSTRAINTS           (1 << 8)
  |  |  ------------------
  ------------------
  |  Branch (964:13): [True: 2.51k, False: 8.79k]
  ------------------
  965|       |                /* Parse basic constraints */
  966|  2.51k|                if ((ret = x509_get_basic_constraints(p, end_ext_octet,
  ------------------
  |  Branch (966:21): [True: 0, False: 2.51k]
  ------------------
  967|  2.51k|                                                      &crt->ca_istrue, &crt->max_pathlen)) != 0) {
  968|      0|                    return ret;
  969|      0|                }
  970|  2.51k|                break;
  971|       |
  972|  2.51k|            case MBEDTLS_X509_EXT_KEY_USAGE:
  ------------------
  |  |  176|  2.04k|#define MBEDTLS_X509_EXT_KEY_USAGE                MBEDTLS_OID_X509_EXT_KEY_USAGE
  |  |  ------------------
  |  |  |  |   39|  2.04k|#define MBEDTLS_OID_X509_EXT_KEY_USAGE                   (1 << 2)
  |  |  ------------------
  ------------------
  |  Branch (972:13): [True: 2.04k, False: 9.26k]
  ------------------
  973|       |                /* Parse key usage */
  974|  2.04k|                if ((ret = mbedtls_x509_get_key_usage(p, end_ext_octet,
  ------------------
  |  Branch (974:21): [True: 0, False: 2.04k]
  ------------------
  975|  2.04k|                                                      &crt->key_usage)) != 0) {
  976|      0|                    return ret;
  977|      0|                }
  978|  2.04k|                break;
  979|       |
  980|  2.04k|            case MBEDTLS_X509_EXT_EXTENDED_KEY_USAGE:
  ------------------
  |  |  185|  2.04k|#define MBEDTLS_X509_EXT_EXTENDED_KEY_USAGE       MBEDTLS_OID_X509_EXT_EXTENDED_KEY_USAGE
  |  |  ------------------
  |  |  |  |   48|  2.04k|#define MBEDTLS_OID_X509_EXT_EXTENDED_KEY_USAGE          (1 << 11)
  |  |  ------------------
  ------------------
  |  Branch (980:13): [True: 2.04k, False: 9.26k]
  ------------------
  981|       |                /* Parse extended key usage */
  982|  2.04k|                if ((ret = x509_get_ext_key_usage(p, end_ext_octet,
  ------------------
  |  Branch (982:21): [True: 0, False: 2.04k]
  ------------------
  983|  2.04k|                                                  &crt->ext_key_usage)) != 0) {
  984|      0|                    return ret;
  985|      0|                }
  986|  2.04k|                break;
  987|       |
  988|  2.51k|            case MBEDTLS_X509_EXT_SUBJECT_KEY_IDENTIFIER:
  ------------------
  |  |  175|  2.51k|#define MBEDTLS_X509_EXT_SUBJECT_KEY_IDENTIFIER   MBEDTLS_OID_X509_EXT_SUBJECT_KEY_IDENTIFIER
  |  |  ------------------
  |  |  |  |   38|  2.51k|#define MBEDTLS_OID_X509_EXT_SUBJECT_KEY_IDENTIFIER      (1 << 1)
  |  |  ------------------
  ------------------
  |  Branch (988:13): [True: 2.51k, False: 8.79k]
  ------------------
  989|       |                /* Parse subject key identifier */
  990|  2.51k|                if ((ret = x509_get_subject_key_id(p, end_ext_data,
  ------------------
  |  Branch (990:21): [True: 0, False: 2.51k]
  ------------------
  991|  2.51k|                                                   &crt->subject_key_id)) != 0) {
  992|      0|                    return ret;
  993|      0|                }
  994|  2.51k|                break;
  995|       |
  996|  2.51k|            case MBEDTLS_X509_EXT_AUTHORITY_KEY_IDENTIFIER:
  ------------------
  |  |  174|    471|#define MBEDTLS_X509_EXT_AUTHORITY_KEY_IDENTIFIER MBEDTLS_OID_X509_EXT_AUTHORITY_KEY_IDENTIFIER
  |  |  ------------------
  |  |  |  |   37|    471|#define MBEDTLS_OID_X509_EXT_AUTHORITY_KEY_IDENTIFIER    (1 << 0)
  |  |  ------------------
  ------------------
  |  Branch (996:13): [True: 471, False: 10.8k]
  ------------------
  997|       |                /* Parse authority key identifier */
  998|    471|                if ((ret = x509_get_authority_key_id(p, end_ext_octet,
  ------------------
  |  Branch (998:21): [True: 0, False: 471]
  ------------------
  999|    471|                                                     &crt->authority_key_id)) != 0) {
 1000|      0|                    return ret;
 1001|      0|                }
 1002|    471|                break;
 1003|  1.72k|            case MBEDTLS_X509_EXT_SUBJECT_ALT_NAME:
  ------------------
  |  |  179|  1.72k|#define MBEDTLS_X509_EXT_SUBJECT_ALT_NAME         MBEDTLS_OID_X509_EXT_SUBJECT_ALT_NAME         /* Supported (DNS) */
  |  |  ------------------
  |  |  |  |   42|  1.72k|#define MBEDTLS_OID_X509_EXT_SUBJECT_ALT_NAME            (1 << 5)
  |  |  ------------------
  ------------------
  |  Branch (1003:13): [True: 1.72k, False: 9.57k]
  ------------------
 1004|       |                /* Parse subject alt name
 1005|       |                 * SubjectAltName ::= GeneralNames
 1006|       |                 */
 1007|  1.72k|                if ((ret = mbedtls_x509_get_subject_alt_name(p, end_ext_octet,
  ------------------
  |  Branch (1007:21): [True: 0, False: 1.72k]
  ------------------
 1008|  1.72k|                                                             &crt->subject_alt_names)) != 0) {
 1009|      0|                    return ret;
 1010|      0|                }
 1011|  1.72k|                break;
 1012|       |
 1013|  1.72k|            case MBEDTLS_X509_EXT_NS_CERT_TYPE:
  ------------------
  |  |  189|      0|#define MBEDTLS_X509_EXT_NS_CERT_TYPE             MBEDTLS_OID_X509_EXT_NS_CERT_TYPE
  |  |  ------------------
  |  |  |  |   52|      0|#define MBEDTLS_OID_X509_EXT_NS_CERT_TYPE                (1 << 16)
  |  |  ------------------
  ------------------
  |  Branch (1013:13): [True: 0, False: 11.3k]
  ------------------
 1014|       |                /* Parse netscape certificate type */
 1015|      0|                if ((ret = mbedtls_x509_get_ns_cert_type(p, end_ext_octet,
  ------------------
  |  Branch (1015:21): [True: 0, False: 0]
  ------------------
 1016|      0|                                                         &crt->ns_cert_type)) != 0) {
 1017|      0|                    return ret;
 1018|      0|                }
 1019|      0|                break;
 1020|       |
 1021|      0|            case MBEDTLS_OID_X509_EXT_CERTIFICATE_POLICIES:
  ------------------
  |  |   40|      0|#define MBEDTLS_OID_X509_EXT_CERTIFICATE_POLICIES        (1 << 3)
  ------------------
  |  Branch (1021:13): [True: 0, False: 11.3k]
  ------------------
 1022|       |                /* Parse certificate policies type */
 1023|      0|                if ((ret = x509_get_certificate_policies(p, end_ext_octet,
  ------------------
  |  Branch (1023:21): [True: 0, False: 0]
  ------------------
 1024|      0|                                                         &crt->certificate_policies)) != 0) {
 1025|       |                    /* Give the callback (if any) a chance to handle the extension
 1026|       |                     * if it contains unsupported policies */
 1027|      0|                    if (ret == MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE && cb != NULL &&
  ------------------
  |  |   45|      0|#define MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE              -0x2080
  ------------------
  |  Branch (1027:25): [True: 0, False: 0]
  |  Branch (1027:72): [True: 0, False: 0]
  ------------------
 1028|      0|                        cb(p_ctx, crt, &extn_oid, is_critical,
  ------------------
  |  Branch (1028:25): [True: 0, False: 0]
  ------------------
 1029|      0|                           start_ext_octet, end_ext_octet) == 0) {
 1030|      0|                        break;
 1031|      0|                    }
 1032|       |
 1033|      0|                    if (is_critical) {
  ------------------
  |  Branch (1033:25): [True: 0, False: 0]
  ------------------
 1034|      0|                        return ret;
 1035|      0|                    } else
 1036|       |                    /*
 1037|       |                     * If MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE is returned, then we
 1038|       |                     * cannot interpret or enforce the policy. However, it is up to
 1039|       |                     * the user to choose how to enforce the policies,
 1040|       |                     * unless the extension is critical.
 1041|       |                     */
 1042|      0|                    if (ret != MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE) {
  ------------------
  |  |   45|      0|#define MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE              -0x2080
  ------------------
  |  Branch (1042:25): [True: 0, False: 0]
  ------------------
 1043|      0|                        return ret;
 1044|      0|                    }
 1045|      0|                }
 1046|      0|                break;
 1047|       |
 1048|      0|            default:
  ------------------
  |  Branch (1048:13): [True: 0, False: 11.3k]
  ------------------
 1049|       |                /*
 1050|       |                 * If this is a non-critical extension, which the oid layer
 1051|       |                 * supports, but there isn't an x509 parser for it,
 1052|       |                 * skip the extension.
 1053|       |                 */
 1054|      0|                if (is_critical) {
  ------------------
  |  Branch (1054:21): [True: 0, False: 0]
  ------------------
 1055|      0|                    return MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE;
  ------------------
  |  |   45|      0|#define MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE              -0x2080
  ------------------
 1056|      0|                } else {
 1057|      0|                    *p = end_ext_octet;
 1058|      0|                }
 1059|  11.3k|        }
 1060|  11.3k|    }
 1061|       |
 1062|  2.51k|    if (*p != end) {
  ------------------
  |  Branch (1062:9): [True: 0, False: 2.51k]
  ------------------
 1063|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
 1064|      0|                                 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
 1065|      0|    }
 1066|       |
 1067|  2.51k|    return 0;
 1068|  2.51k|}
x509_crt.c:x509_get_basic_constraints:
  498|  2.51k|{
  499|  2.51k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  2.51k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  500|  2.51k|    size_t len;
  501|       |
  502|       |    /*
  503|       |     * BasicConstraints ::= SEQUENCE {
  504|       |     *      cA                      BOOLEAN DEFAULT FALSE,
  505|       |     *      pathLenConstraint       INTEGER (0..MAX) OPTIONAL }
  506|       |     */
  507|  2.51k|    *ca_istrue = 0; /* DEFAULT FALSE */
  508|  2.51k|    *max_pathlen = 0; /* endless */
  509|       |
  510|  2.51k|    if ((ret = mbedtls_asn1_get_tag(p, end, &len,
  ------------------
  |  Branch (510:9): [True: 0, False: 2.51k]
  ------------------
  511|  2.51k|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|  2.51k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|  2.51k|#define MBEDTLS_ASN1_SEQUENCE                0x10
  ------------------
  512|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  513|      0|    }
  514|       |
  515|  2.51k|    if (*p == end) {
  ------------------
  |  Branch (515:9): [True: 1.72k, False: 785]
  ------------------
  516|  1.72k|        return 0;
  517|  1.72k|    }
  518|       |
  519|    785|    if ((ret = mbedtls_asn1_get_bool(p, end, ca_istrue)) != 0) {
  ------------------
  |  Branch (519:9): [True: 0, False: 785]
  ------------------
  520|      0|        if (ret == MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) {
  ------------------
  |  |   39|      0|#define MBEDTLS_ERR_ASN1_UNEXPECTED_TAG                   -0x0062
  ------------------
  |  Branch (520:13): [True: 0, False: 0]
  ------------------
  521|      0|            ret = mbedtls_asn1_get_int(p, end, ca_istrue);
  522|      0|        }
  523|       |
  524|      0|        if (ret != 0) {
  ------------------
  |  Branch (524:13): [True: 0, False: 0]
  ------------------
  525|      0|            return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  526|      0|        }
  527|       |
  528|      0|        if (*ca_istrue != 0) {
  ------------------
  |  Branch (528:13): [True: 0, False: 0]
  ------------------
  529|      0|            *ca_istrue = 1;
  530|      0|        }
  531|      0|    }
  532|       |
  533|    785|    if (*p == end) {
  ------------------
  |  Branch (533:9): [True: 785, False: 0]
  ------------------
  534|    785|        return 0;
  535|    785|    }
  536|       |
  537|      0|    if ((ret = mbedtls_asn1_get_int(p, end, max_pathlen)) != 0) {
  ------------------
  |  Branch (537:9): [True: 0, False: 0]
  ------------------
  538|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  539|      0|    }
  540|       |
  541|      0|    if (*p != end) {
  ------------------
  |  Branch (541:9): [True: 0, False: 0]
  ------------------
  542|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  543|      0|                                 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
  544|      0|    }
  545|       |
  546|       |    /* Do not accept max_pathlen equal to INT_MAX to avoid a signed integer
  547|       |     * overflow, which is an undefined behavior. */
  548|      0|    if (*max_pathlen == INT_MAX) {
  ------------------
  |  Branch (548:9): [True: 0, False: 0]
  ------------------
  549|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  550|      0|                                 MBEDTLS_ERR_ASN1_INVALID_LENGTH);
  551|      0|    }
  552|       |
  553|      0|    (*max_pathlen)++;
  554|       |
  555|      0|    return 0;
  556|      0|}
x509_crt.c:x509_get_ext_key_usage:
  566|  2.04k|{
  567|  2.04k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  2.04k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  568|       |
  569|  2.04k|    if ((ret = mbedtls_asn1_get_sequence_of(p, end, ext_key_usage, MBEDTLS_ASN1_OID)) != 0) {
  ------------------
  |  |   69|  2.04k|#define MBEDTLS_ASN1_OID                     0x06
  ------------------
  |  Branch (569:9): [True: 0, False: 2.04k]
  ------------------
  570|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  571|      0|    }
  572|       |
  573|       |    /* Sequence length must be >= 1 */
  574|  2.04k|    if (ext_key_usage->buf.p == NULL) {
  ------------------
  |  Branch (574:9): [True: 0, False: 2.04k]
  ------------------
  575|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  576|      0|                                 MBEDTLS_ERR_ASN1_INVALID_LENGTH);
  577|      0|    }
  578|       |
  579|  2.04k|    return 0;
  580|  2.04k|}
x509_crt.c:x509_get_subject_key_id:
  590|  2.51k|{
  591|  2.51k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  2.51k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  592|  2.51k|    size_t len = 0u;
  593|       |
  594|  2.51k|    if ((ret = mbedtls_asn1_get_tag(p, end, &len,
  ------------------
  |  Branch (594:9): [True: 0, False: 2.51k]
  ------------------
  595|  2.51k|                                    MBEDTLS_ASN1_OCTET_STRING)) != 0) {
  ------------------
  |  |   67|  2.51k|#define MBEDTLS_ASN1_OCTET_STRING            0x04
  ------------------
  596|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  597|      0|    }
  598|       |
  599|  2.51k|    subject_key_id->len = len;
  600|  2.51k|    subject_key_id->tag = MBEDTLS_ASN1_OCTET_STRING;
  ------------------
  |  |   67|  2.51k|#define MBEDTLS_ASN1_OCTET_STRING            0x04
  ------------------
  601|  2.51k|    subject_key_id->p = *p;
  602|  2.51k|    *p += len;
  603|       |
  604|  2.51k|    if (*p != end) {
  ------------------
  |  Branch (604:9): [True: 0, False: 2.51k]
  ------------------
  605|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  606|      0|                                 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
  607|      0|    }
  608|       |
  609|  2.51k|    return 0;
  610|  2.51k|}
x509_crt.c:x509_get_authority_key_id:
  623|    471|{
  624|    471|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|    471|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  625|    471|    size_t len = 0u;
  626|       |
  627|    471|    if ((ret = mbedtls_asn1_get_tag(p, end, &len,
  ------------------
  |  Branch (627:9): [True: 0, False: 471]
  ------------------
  628|    471|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|    471|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|    471|#define MBEDTLS_ASN1_SEQUENCE                0x10
  ------------------
  629|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  630|      0|    }
  631|       |
  632|    471|    if (*p + len != end) {
  ------------------
  |  Branch (632:9): [True: 0, False: 471]
  ------------------
  633|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  634|      0|                                 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
  635|      0|    }
  636|       |
  637|    471|    ret = mbedtls_asn1_get_tag(p, end, &len,
  638|    471|                               MBEDTLS_ASN1_CONTEXT_SPECIFIC);
  ------------------
  |  |   83|    471|#define MBEDTLS_ASN1_CONTEXT_SPECIFIC        0x80
  ------------------
  639|       |
  640|       |    /* KeyIdentifier is an OPTIONAL field */
  641|    471|    if (ret == 0) {
  ------------------
  |  Branch (641:9): [True: 471, False: 0]
  ------------------
  642|    471|        authority_key_id->keyIdentifier.len = len;
  643|    471|        authority_key_id->keyIdentifier.p = *p;
  644|       |        /* Setting tag of the keyIdentfier intentionally to 0x04.
  645|       |         * Although the .keyIdentfier field is CONTEXT_SPECIFIC ([0] OPTIONAL),
  646|       |         * its tag with the content is the payload of on OCTET STRING primitive */
  647|    471|        authority_key_id->keyIdentifier.tag = MBEDTLS_ASN1_OCTET_STRING;
  ------------------
  |  |   67|    471|#define MBEDTLS_ASN1_OCTET_STRING            0x04
  ------------------
  648|       |
  649|    471|        *p += len;
  650|    471|    } else if (ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) {
  ------------------
  |  |   39|      0|#define MBEDTLS_ERR_ASN1_UNEXPECTED_TAG                   -0x0062
  ------------------
  |  Branch (650:16): [True: 0, False: 0]
  ------------------
  651|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  652|      0|    }
  653|       |
  654|    471|    if (*p < end) {
  ------------------
  |  Branch (654:9): [True: 0, False: 471]
  ------------------
  655|       |        /* Getting authorityCertIssuer using the required specific class tag [1] */
  656|      0|        if ((ret = mbedtls_asn1_get_tag(p, end, &len,
  ------------------
  |  Branch (656:13): [True: 0, False: 0]
  ------------------
  657|      0|                                        MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED |
  ------------------
  |  |   83|      0|#define MBEDTLS_ASN1_CONTEXT_SPECIFIC        0x80
  ------------------
                                                      MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED |
  ------------------
  |  |   82|      0|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
  658|      0|                                        1)) != 0) {
  659|       |            /* authorityCertIssuer and authorityCertSerialNumber MUST both
  660|       |               be present or both be absent. At this point we expect to have both. */
  661|      0|            return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  662|      0|        }
  663|       |        /* "end" also includes the CertSerialNumber field so "len" shall be used */
  664|      0|        ret = mbedtls_x509_get_subject_alt_name_ext(p,
  665|      0|                                                    (*p+len),
  666|      0|                                                    &authority_key_id->authorityCertIssuer);
  667|      0|        if (ret != 0) {
  ------------------
  |  Branch (667:13): [True: 0, False: 0]
  ------------------
  668|      0|            return ret;
  669|      0|        }
  670|       |
  671|       |        /* Getting authorityCertSerialNumber using the required specific class tag [2] */
  672|      0|        if ((ret = mbedtls_asn1_get_tag(p, end, &len,
  ------------------
  |  Branch (672:13): [True: 0, False: 0]
  ------------------
  673|      0|                                        MBEDTLS_ASN1_CONTEXT_SPECIFIC | 2)) != 0) {
  ------------------
  |  |   83|      0|#define MBEDTLS_ASN1_CONTEXT_SPECIFIC        0x80
  ------------------
  674|      0|            return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  675|      0|        }
  676|      0|        authority_key_id->authorityCertSerialNumber.len = len;
  677|      0|        authority_key_id->authorityCertSerialNumber.p = *p;
  678|      0|        authority_key_id->authorityCertSerialNumber.tag = MBEDTLS_ASN1_INTEGER;
  ------------------
  |  |   65|      0|#define MBEDTLS_ASN1_INTEGER                 0x02
  ------------------
  679|      0|        *p += len;
  680|      0|    }
  681|       |
  682|    471|    if (*p != end) {
  ------------------
  |  Branch (682:9): [True: 0, False: 471]
  ------------------
  683|      0|        return MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
  ------------------
  |  |   63|      0|#define MBEDTLS_ERR_X509_INVALID_EXTENSIONS               -0x2500
  ------------------
  684|      0|               MBEDTLS_ERR_ASN1_LENGTH_MISMATCH;
  ------------------
  |  |   43|      0|#define MBEDTLS_ERR_ASN1_LENGTH_MISMATCH                  -0x0066
  ------------------
  685|      0|    }
  686|       |
  687|    471|    return 0;
  688|    471|}
x509_crt.c:x509_crt_verify_restartable_ca_cb:
 3068|    471|{
 3069|    471|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|    471|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 3070|    471|    mbedtls_pk_type_t pk_type;
 3071|    471|    mbedtls_x509_crt_verify_chain ver_chain;
 3072|    471|    uint32_t ee_flags;
 3073|       |
 3074|    471|    *flags = 0;
 3075|    471|    ee_flags = 0;
 3076|    471|    x509_crt_verify_chain_reset(&ver_chain);
 3077|       |
 3078|    471|    if (profile == NULL) {
  ------------------
  |  Branch (3078:9): [True: 0, False: 471]
  ------------------
 3079|      0|        ret = MBEDTLS_ERR_X509_BAD_INPUT_DATA;
  ------------------
  |  |   75|      0|#define MBEDTLS_ERR_X509_BAD_INPUT_DATA                   -0x2800
  ------------------
 3080|      0|        goto exit;
 3081|      0|    }
 3082|       |
 3083|       |    /* check name if requested */
 3084|    471|    if (cn != NULL) {
  ------------------
  |  Branch (3084:9): [True: 0, False: 471]
  ------------------
 3085|      0|        x509_crt_verify_name(crt, cn, &ee_flags);
 3086|      0|    }
 3087|       |
 3088|       |    /* Check the type and size of the key */
 3089|    471|    pk_type = mbedtls_pk_get_type(&crt->pk);
 3090|       |
 3091|    471|    if (x509_profile_check_pk_alg(profile, pk_type) != 0) {
  ------------------
  |  Branch (3091:9): [True: 0, False: 471]
  ------------------
 3092|      0|        ee_flags |= MBEDTLS_X509_BADCERT_BAD_PK;
  ------------------
  |  |  106|      0|#define MBEDTLS_X509_BADCERT_BAD_PK            0x8000  /**< The certificate is signed with an unacceptable PK alg (eg RSA vs ECDSA). */
  ------------------
 3093|      0|    }
 3094|       |
 3095|    471|    if (x509_profile_check_key(profile, &crt->pk) != 0) {
  ------------------
  |  Branch (3095:9): [True: 0, False: 471]
  ------------------
 3096|      0|        ee_flags |= MBEDTLS_X509_BADCERT_BAD_KEY;
  ------------------
  |  |  107|      0|#define MBEDTLS_X509_BADCERT_BAD_KEY         0x010000  /**< The certificate is signed with an unacceptable key (eg bad curve, RSA too short). */
  ------------------
 3097|      0|    }
 3098|       |
 3099|       |    /* Check the chain */
 3100|    471|    ret = x509_crt_verify_chain(crt, trust_ca, ca_crl,
 3101|    471|                                f_ca_cb, p_ca_cb, profile,
 3102|    471|                                &ver_chain, rs_ctx);
 3103|       |
 3104|    471|    if (ret != 0) {
  ------------------
  |  Branch (3104:9): [True: 0, False: 471]
  ------------------
 3105|      0|        goto exit;
 3106|      0|    }
 3107|       |
 3108|       |    /* Merge end-entity flags */
 3109|    471|    ver_chain.items[0].flags |= ee_flags;
 3110|       |
 3111|       |    /* Build final flags, calling callback on the way if any */
 3112|    471|    ret = x509_crt_merge_flags_with_cb(flags, &ver_chain, f_vrfy, p_vrfy);
 3113|       |
 3114|    471|exit:
 3115|       |
 3116|       |#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
 3117|       |    mbedtls_x509_crt_free(ver_chain.trust_ca_cb_result);
 3118|       |    mbedtls_free(ver_chain.trust_ca_cb_result);
 3119|       |    ver_chain.trust_ca_cb_result = NULL;
 3120|       |#endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
 3121|       |
 3122|    471|#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
 3123|    471|    if (rs_ctx != NULL && ret != MBEDTLS_ERR_ECP_IN_PROGRESS) {
  ------------------
  |  |   51|      0|#define MBEDTLS_ERR_ECP_IN_PROGRESS                       -0x4B00
  ------------------
  |  Branch (3123:9): [True: 0, False: 471]
  |  Branch (3123:27): [True: 0, False: 0]
  ------------------
 3124|      0|        mbedtls_x509_crt_restart_free(rs_ctx);
 3125|      0|    }
 3126|    471|#endif
 3127|       |
 3128|       |    /* prevent misuse of the vrfy callback - VERIFY_FAILED would be ignored by
 3129|       |     * the SSL module for authmode optional, but non-zero return from the
 3130|       |     * callback means a fatal error so it shouldn't be ignored */
 3131|    471|    if (ret == MBEDTLS_ERR_X509_CERT_VERIFY_FAILED) {
  ------------------
  |  |   71|    471|#define MBEDTLS_ERR_X509_CERT_VERIFY_FAILED               -0x2700
  ------------------
  |  Branch (3131:9): [True: 0, False: 471]
  ------------------
 3132|      0|        ret = MBEDTLS_ERR_X509_FATAL_ERROR;
  ------------------
  |  |   83|      0|#define MBEDTLS_ERR_X509_FATAL_ERROR                      -0x3000
  ------------------
 3133|      0|    }
 3134|       |
 3135|    471|    if (ret != 0) {
  ------------------
  |  Branch (3135:9): [True: 0, False: 471]
  ------------------
 3136|      0|        *flags = (uint32_t) -1;
 3137|      0|        return ret;
 3138|      0|    }
 3139|       |
 3140|    471|    if (*flags != 0) {
  ------------------
  |  Branch (3140:9): [True: 0, False: 471]
  ------------------
 3141|      0|        return MBEDTLS_ERR_X509_CERT_VERIFY_FAILED;
  ------------------
  |  |   71|      0|#define MBEDTLS_ERR_X509_CERT_VERIFY_FAILED               -0x2700
  ------------------
 3142|      0|    }
 3143|       |
 3144|    471|    return 0;
 3145|    471|}
x509_crt.c:x509_profile_check_pk_alg:
  193|    942|{
  194|    942|    if (pk_alg == MBEDTLS_PK_NONE) {
  ------------------
  |  Branch (194:9): [True: 0, False: 942]
  ------------------
  195|      0|        return -1;
  196|      0|    }
  197|       |
  198|    942|    if ((profile->allowed_pks & MBEDTLS_X509_ID_FLAG(pk_alg)) != 0) {
  ------------------
  |  |   98|    942|#define MBEDTLS_X509_ID_FLAG(id)   (1 << ((id) - 1))
  ------------------
  |  Branch (198:9): [True: 942, False: 0]
  ------------------
  199|    942|        return 0;
  200|    942|    }
  201|       |
  202|      0|    return -1;
  203|    942|}
x509_crt.c:x509_profile_check_key:
  211|    785|{
  212|    785|    const mbedtls_pk_type_t pk_alg = mbedtls_pk_get_type(pk);
  213|       |
  214|    785|#if defined(MBEDTLS_RSA_C)
  215|    785|    if (pk_alg == MBEDTLS_PK_RSA || pk_alg == MBEDTLS_PK_RSASSA_PSS) {
  ------------------
  |  Branch (215:9): [True: 0, False: 785]
  |  Branch (215:37): [True: 0, False: 785]
  ------------------
  216|      0|        if (mbedtls_pk_get_bitlen(pk) >= profile->rsa_min_bitlen) {
  ------------------
  |  Branch (216:13): [True: 0, False: 0]
  ------------------
  217|      0|            return 0;
  218|      0|        }
  219|       |
  220|      0|        return -1;
  221|      0|    }
  222|    785|#endif /* MBEDTLS_RSA_C */
  223|       |
  224|    785|#if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
  225|    785|    if (pk_alg == MBEDTLS_PK_ECDSA ||
  ------------------
  |  Branch (225:9): [True: 0, False: 785]
  ------------------
  226|    785|        pk_alg == MBEDTLS_PK_ECKEY ||
  ------------------
  |  Branch (226:9): [True: 785, False: 0]
  ------------------
  227|    785|        pk_alg == MBEDTLS_PK_ECKEY_DH) {
  ------------------
  |  Branch (227:9): [True: 0, False: 0]
  ------------------
  228|    785|        const mbedtls_ecp_group_id gid = mbedtls_pk_get_ec_group_id(pk);
  229|       |
  230|    785|        if (gid == MBEDTLS_ECP_DP_NONE) {
  ------------------
  |  Branch (230:13): [True: 0, False: 785]
  ------------------
  231|      0|            return -1;
  232|      0|        }
  233|       |
  234|    785|        if ((profile->allowed_curves & MBEDTLS_X509_ID_FLAG(gid)) != 0) {
  ------------------
  |  |   98|    785|#define MBEDTLS_X509_ID_FLAG(id)   (1 << ((id) - 1))
  ------------------
  |  Branch (234:13): [True: 785, False: 0]
  ------------------
  235|    785|            return 0;
  236|    785|        }
  237|       |
  238|      0|        return -1;
  239|    785|    }
  240|      0|#endif /* MBEDTLS_PK_HAVE_ECC_KEYS */
  241|       |
  242|      0|    return -1;
  243|    785|}
x509_crt.c:x509_crt_verify_chain:
 2515|    471|{
 2516|       |    /* Don't initialize any of those variables here, so that the compiler can
 2517|       |     * catch potential issues with jumping ahead when restarting */
 2518|    471|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|    471|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 2519|    471|    uint32_t *flags;
 2520|    471|    mbedtls_x509_crt_verify_chain_item *cur;
 2521|    471|    mbedtls_x509_crt *child;
 2522|    471|    mbedtls_x509_crt *parent;
 2523|    471|    int parent_is_trusted;
 2524|    471|    int child_is_trusted;
 2525|    471|    int signature_is_good;
 2526|    471|    unsigned self_cnt;
 2527|    471|    mbedtls_x509_crt *cur_trust_ca = NULL;
 2528|    471|    mbedtls_x509_time now;
 2529|       |
 2530|    471|#if defined(MBEDTLS_HAVE_TIME_DATE)
 2531|    471|    if (mbedtls_x509_time_gmtime(mbedtls_time(NULL), &now) != 0) {
  ------------------
  |  |   71|    471|#define mbedtls_time   time
  ------------------
  |  Branch (2531:9): [True: 0, False: 471]
  ------------------
 2532|      0|        return MBEDTLS_ERR_X509_FATAL_ERROR;
  ------------------
  |  |   83|      0|#define MBEDTLS_ERR_X509_FATAL_ERROR                      -0x3000
  ------------------
 2533|      0|    }
 2534|    471|#endif
 2535|       |
 2536|    471|#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
 2537|       |    /* resume if we had an operation in progress */
 2538|    471|    if (rs_ctx != NULL && rs_ctx->in_progress == x509_crt_rs_find_parent) {
  ------------------
  |  Branch (2538:9): [True: 0, False: 471]
  |  Branch (2538:27): [True: 0, False: 0]
  ------------------
 2539|       |        /* restore saved state */
 2540|      0|        *ver_chain = rs_ctx->ver_chain; /* struct copy */
 2541|      0|        self_cnt = rs_ctx->self_cnt;
 2542|       |
 2543|       |        /* restore derived state */
 2544|      0|        cur = &ver_chain->items[ver_chain->len - 1];
 2545|      0|        child = cur->crt;
 2546|      0|        flags = &cur->flags;
 2547|       |
 2548|      0|        goto find_parent;
 2549|      0|    }
 2550|    471|#endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
 2551|       |
 2552|    471|    child = crt;
 2553|    471|    self_cnt = 0;
 2554|    471|    parent_is_trusted = 0;
 2555|    471|    child_is_trusted = 0;
 2556|       |
 2557|    785|    while (1) {
  ------------------
  |  Branch (2557:12): [Folded - Ignored]
  ------------------
 2558|       |        /* Add certificate to the verification chain */
 2559|    785|        cur = &ver_chain->items[ver_chain->len];
 2560|    785|        cur->crt = child;
 2561|    785|        cur->flags = 0;
 2562|    785|        ver_chain->len++;
 2563|    785|        flags = &cur->flags;
 2564|       |
 2565|    785|#if defined(MBEDTLS_HAVE_TIME_DATE)
 2566|       |        /* Check time-validity (all certificates) */
 2567|    785|        if (mbedtls_x509_time_cmp(&child->valid_to, &now) < 0) {
  ------------------
  |  Branch (2567:13): [True: 0, False: 785]
  ------------------
 2568|      0|            *flags |= MBEDTLS_X509_BADCERT_EXPIRED;
  ------------------
  |  |   91|      0|#define MBEDTLS_X509_BADCERT_EXPIRED             0x01  /**< The certificate validity has expired. */
  ------------------
 2569|      0|        }
 2570|       |
 2571|    785|        if (mbedtls_x509_time_cmp(&child->valid_from, &now) > 0) {
  ------------------
  |  Branch (2571:13): [True: 0, False: 785]
  ------------------
 2572|      0|            *flags |= MBEDTLS_X509_BADCERT_FUTURE;
  ------------------
  |  |  100|      0|#define MBEDTLS_X509_BADCERT_FUTURE            0x0200  /**< The certificate validity starts in the future. */
  ------------------
 2573|      0|        }
 2574|    785|#endif
 2575|       |
 2576|       |        /* Stop here for trusted roots (but not for trusted EE certs) */
 2577|    785|        if (child_is_trusted) {
  ------------------
  |  Branch (2577:13): [True: 314, False: 471]
  ------------------
 2578|    314|            return 0;
 2579|    314|        }
 2580|       |
 2581|       |        /* Check signature algorithm: MD & PK algs */
 2582|    471|        if (x509_profile_check_md_alg(profile, child->sig_md) != 0) {
  ------------------
  |  Branch (2582:13): [True: 0, False: 471]
  ------------------
 2583|      0|            *flags |= MBEDTLS_X509_BADCERT_BAD_MD;
  ------------------
  |  |  105|      0|#define MBEDTLS_X509_BADCERT_BAD_MD            0x4000  /**< The certificate is signed with an unacceptable hash. */
  ------------------
 2584|      0|        }
 2585|       |
 2586|    471|        if (x509_profile_check_pk_alg(profile, child->sig_pk) != 0) {
  ------------------
  |  Branch (2586:13): [True: 0, False: 471]
  ------------------
 2587|      0|            *flags |= MBEDTLS_X509_BADCERT_BAD_PK;
  ------------------
  |  |  106|      0|#define MBEDTLS_X509_BADCERT_BAD_PK            0x8000  /**< The certificate is signed with an unacceptable PK alg (eg RSA vs ECDSA). */
  ------------------
 2588|      0|        }
 2589|       |
 2590|       |        /* Special case: EE certs that are locally trusted */
 2591|    471|        if (ver_chain->len == 1 &&
  ------------------
  |  Branch (2591:13): [True: 471, False: 0]
  ------------------
 2592|    471|            x509_crt_check_ee_locally_trusted(child, trust_ca) == 0) {
  ------------------
  |  Branch (2592:13): [True: 157, False: 314]
  ------------------
 2593|    157|            return 0;
 2594|    157|        }
 2595|       |
 2596|    314|#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
 2597|    314|find_parent:
 2598|    314|#endif
 2599|       |
 2600|       |        /* Obtain list of potential trusted signers from CA callback,
 2601|       |         * or use statically provided list. */
 2602|       |#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
 2603|       |        if (f_ca_cb != NULL) {
 2604|       |            mbedtls_x509_crt_free(ver_chain->trust_ca_cb_result);
 2605|       |            mbedtls_free(ver_chain->trust_ca_cb_result);
 2606|       |            ver_chain->trust_ca_cb_result = NULL;
 2607|       |
 2608|       |            ret = f_ca_cb(p_ca_cb, child, &ver_chain->trust_ca_cb_result);
 2609|       |            if (ret != 0) {
 2610|       |                return MBEDTLS_ERR_X509_FATAL_ERROR;
 2611|       |            }
 2612|       |
 2613|       |            cur_trust_ca = ver_chain->trust_ca_cb_result;
 2614|       |        } else
 2615|       |#endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
 2616|    314|        {
 2617|    314|            ((void) f_ca_cb);
 2618|    314|            ((void) p_ca_cb);
 2619|    314|            cur_trust_ca = trust_ca;
 2620|    314|        }
 2621|       |
 2622|       |        /* Look for a parent in trusted CAs or up the chain */
 2623|    314|        ret = x509_crt_find_parent(child, cur_trust_ca, &parent,
 2624|    314|                                   &parent_is_trusted, &signature_is_good,
 2625|    314|                                   ver_chain->len - 1, self_cnt, rs_ctx,
 2626|    314|                                   &now);
 2627|       |
 2628|    314|#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
 2629|    314|        if (rs_ctx != NULL && ret == MBEDTLS_ERR_ECP_IN_PROGRESS) {
  ------------------
  |  |   51|      0|#define MBEDTLS_ERR_ECP_IN_PROGRESS                       -0x4B00
  ------------------
  |  Branch (2629:13): [True: 0, False: 314]
  |  Branch (2629:31): [True: 0, False: 0]
  ------------------
 2630|       |            /* save state */
 2631|      0|            rs_ctx->in_progress = x509_crt_rs_find_parent;
 2632|      0|            rs_ctx->self_cnt = self_cnt;
 2633|      0|            rs_ctx->ver_chain = *ver_chain; /* struct copy */
 2634|       |
 2635|      0|            return ret;
 2636|      0|        }
 2637|       |#else
 2638|       |        (void) ret;
 2639|       |#endif
 2640|       |
 2641|       |        /* No parent? We're done here */
 2642|    314|        if (parent == NULL) {
  ------------------
  |  Branch (2642:13): [True: 0, False: 314]
  ------------------
 2643|      0|            *flags |= MBEDTLS_X509_BADCERT_NOT_TRUSTED;
  ------------------
  |  |   94|      0|#define MBEDTLS_X509_BADCERT_NOT_TRUSTED         0x08  /**< The certificate is not correctly signed by the trusted CA. */
  ------------------
 2644|      0|            return 0;
 2645|      0|        }
 2646|       |
 2647|       |        /* Count intermediate self-issued (not necessarily self-signed) certs.
 2648|       |         * These can occur with some strategies for key rollover, see [SIRO],
 2649|       |         * and should be excluded from max_pathlen checks. */
 2650|    314|        if (ver_chain->len != 1 &&
  ------------------
  |  Branch (2650:13): [True: 0, False: 314]
  ------------------
 2651|    314|            x509_name_cmp(&child->issuer, &child->subject) == 0) {
  ------------------
  |  Branch (2651:13): [True: 0, False: 0]
  ------------------
 2652|      0|            self_cnt++;
 2653|      0|        }
 2654|       |
 2655|       |        /* path_cnt is 0 for the first intermediate CA,
 2656|       |         * and if parent is trusted it's not an intermediate CA */
 2657|    314|        if (!parent_is_trusted &&
  ------------------
  |  Branch (2657:13): [True: 0, False: 314]
  ------------------
 2658|    314|            ver_chain->len > MBEDTLS_X509_MAX_INTERMEDIATE_CA) {
  ------------------
  |  |   37|      0|#define MBEDTLS_X509_MAX_INTERMEDIATE_CA   8
  ------------------
  |  Branch (2658:13): [True: 0, False: 0]
  ------------------
 2659|       |            /* return immediately to avoid overflow the chain array */
 2660|      0|            return MBEDTLS_ERR_X509_FATAL_ERROR;
  ------------------
  |  |   83|      0|#define MBEDTLS_ERR_X509_FATAL_ERROR                      -0x3000
  ------------------
 2661|      0|        }
 2662|       |
 2663|       |        /* signature was checked while searching parent */
 2664|    314|        if (!signature_is_good) {
  ------------------
  |  Branch (2664:13): [True: 0, False: 314]
  ------------------
 2665|      0|            *flags |= MBEDTLS_X509_BADCERT_NOT_TRUSTED;
  ------------------
  |  |   94|      0|#define MBEDTLS_X509_BADCERT_NOT_TRUSTED         0x08  /**< The certificate is not correctly signed by the trusted CA. */
  ------------------
 2666|      0|        }
 2667|       |
 2668|       |        /* check size of signing key */
 2669|    314|        if (x509_profile_check_key(profile, &parent->pk) != 0) {
  ------------------
  |  Branch (2669:13): [True: 0, False: 314]
  ------------------
 2670|      0|            *flags |= MBEDTLS_X509_BADCERT_BAD_KEY;
  ------------------
  |  |  107|      0|#define MBEDTLS_X509_BADCERT_BAD_KEY         0x010000  /**< The certificate is signed with an unacceptable key (eg bad curve, RSA too short). */
  ------------------
 2671|      0|        }
 2672|       |
 2673|    314|#if defined(MBEDTLS_X509_CRL_PARSE_C)
 2674|       |        /* Check trusted CA's CRL for the given crt */
 2675|    314|        *flags |= x509_crt_verifycrl(child, parent, ca_crl, profile, &now);
 2676|       |#else
 2677|       |        (void) ca_crl;
 2678|       |#endif
 2679|       |
 2680|       |        /* prepare for next iteration */
 2681|    314|        child = parent;
 2682|    314|        parent = NULL;
 2683|    314|        child_is_trusted = parent_is_trusted;
 2684|    314|        signature_is_good = 0;
 2685|    314|    }
 2686|    471|}
x509_crt.c:x509_profile_check_md_alg:
  175|    471|{
  176|    471|    if (md_alg == MBEDTLS_MD_NONE) {
  ------------------
  |  Branch (176:9): [True: 0, False: 471]
  ------------------
  177|      0|        return -1;
  178|      0|    }
  179|       |
  180|    471|    if ((profile->allowed_mds & MBEDTLS_X509_ID_FLAG(md_alg)) != 0) {
  ------------------
  |  |   98|    471|#define MBEDTLS_X509_ID_FLAG(id)   (1 << ((id) - 1))
  ------------------
  |  Branch (180:9): [True: 471, False: 0]
  ------------------
  181|    471|        return 0;
  182|    471|    }
  183|       |
  184|      0|    return -1;
  185|    471|}
x509_crt.c:x509_crt_check_ee_locally_trusted:
 2446|    471|{
 2447|    471|    mbedtls_x509_crt *cur;
 2448|       |
 2449|       |    /* must be self-issued */
 2450|    471|    if (x509_name_cmp(&crt->issuer, &crt->subject) != 0) {
  ------------------
  |  Branch (2450:9): [True: 314, False: 157]
  ------------------
 2451|    314|        return -1;
 2452|    314|    }
 2453|       |
 2454|       |    /* look for an exact match with trusted cert */
 2455|    157|    for (cur = trust_ca; cur != NULL; cur = cur->next) {
  ------------------
  |  Branch (2455:26): [True: 157, False: 0]
  ------------------
 2456|    157|        if (crt->raw.len == cur->raw.len &&
  ------------------
  |  Branch (2456:13): [True: 157, False: 0]
  ------------------
 2457|    157|            memcmp(crt->raw.p, cur->raw.p, crt->raw.len) == 0) {
  ------------------
  |  Branch (2457:13): [True: 157, False: 0]
  ------------------
 2458|    157|            return 0;
 2459|    157|        }
 2460|    157|    }
 2461|       |
 2462|       |    /* too bad */
 2463|      0|    return -1;
 2464|    157|}
x509_crt.c:x509_crt_find_parent:
 2387|    314|{
 2388|    314|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|    314|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 2389|    314|    mbedtls_x509_crt *search_list;
 2390|       |
 2391|    314|    *parent_is_trusted = 1;
 2392|       |
 2393|    314|#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
 2394|       |    /* restore then clear saved state if we have some stored */
 2395|    314|    if (rs_ctx != NULL && rs_ctx->parent_is_trusted != -1) {
  ------------------
  |  Branch (2395:9): [True: 0, False: 314]
  |  Branch (2395:27): [True: 0, False: 0]
  ------------------
 2396|      0|        *parent_is_trusted = rs_ctx->parent_is_trusted;
 2397|      0|        rs_ctx->parent_is_trusted = -1;
 2398|      0|    }
 2399|    314|#endif
 2400|       |
 2401|    314|    while (1) {
  ------------------
  |  Branch (2401:12): [Folded - Ignored]
  ------------------
 2402|    314|        search_list = *parent_is_trusted ? trust_ca : child->next;
  ------------------
  |  Branch (2402:23): [True: 314, False: 0]
  ------------------
 2403|       |
 2404|    314|        ret = x509_crt_find_parent_in(child, search_list,
 2405|    314|                                      parent, signature_is_good,
 2406|    314|                                      *parent_is_trusted,
 2407|    314|                                      path_cnt, self_cnt, rs_ctx, now);
 2408|       |
 2409|    314|#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
 2410|    314|        if (rs_ctx != NULL && ret == MBEDTLS_ERR_ECP_IN_PROGRESS) {
  ------------------
  |  |   51|      0|#define MBEDTLS_ERR_ECP_IN_PROGRESS                       -0x4B00
  ------------------
  |  Branch (2410:13): [True: 0, False: 314]
  |  Branch (2410:31): [True: 0, False: 0]
  ------------------
 2411|       |            /* save state */
 2412|      0|            rs_ctx->parent_is_trusted = *parent_is_trusted;
 2413|      0|            return ret;
 2414|      0|        }
 2415|       |#else
 2416|       |        (void) ret;
 2417|       |#endif
 2418|       |
 2419|       |        /* stop here if found or already in second iteration */
 2420|    314|        if (*parent != NULL || *parent_is_trusted == 0) {
  ------------------
  |  Branch (2420:13): [True: 314, False: 0]
  |  Branch (2420:32): [True: 0, False: 0]
  ------------------
 2421|    314|            break;
 2422|    314|        }
 2423|       |
 2424|       |        /* prepare second iteration */
 2425|      0|        *parent_is_trusted = 0;
 2426|      0|    }
 2427|       |
 2428|       |    /* extra precaution against mistakes in the caller */
 2429|    314|    if (*parent == NULL) {
  ------------------
  |  Branch (2429:9): [True: 0, False: 314]
  ------------------
 2430|      0|        *parent_is_trusted = 0;
 2431|      0|        *signature_is_good = 0;
 2432|      0|    }
 2433|       |
 2434|    314|    return 0;
 2435|    314|}
x509_crt.c:x509_crt_find_parent_in:
 2264|    314|{
 2265|    314|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|    314|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 2266|    314|    mbedtls_x509_crt *parent, *fallback_parent;
 2267|    314|    int signature_is_good = 0, fallback_signature_is_good;
 2268|       |
 2269|    314|#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
 2270|       |    /* did we have something in progress? */
 2271|    314|    if (rs_ctx != NULL && rs_ctx->parent != NULL) {
  ------------------
  |  Branch (2271:9): [True: 0, False: 314]
  |  Branch (2271:27): [True: 0, False: 0]
  ------------------
 2272|       |        /* restore saved state */
 2273|      0|        parent = rs_ctx->parent;
 2274|      0|        fallback_parent = rs_ctx->fallback_parent;
 2275|      0|        fallback_signature_is_good = rs_ctx->fallback_signature_is_good;
 2276|       |
 2277|       |        /* clear saved state */
 2278|      0|        rs_ctx->parent = NULL;
 2279|      0|        rs_ctx->fallback_parent = NULL;
 2280|      0|        rs_ctx->fallback_signature_is_good = 0;
 2281|       |
 2282|       |        /* resume where we left */
 2283|      0|        goto check_signature;
 2284|      0|    }
 2285|    314|#endif
 2286|       |
 2287|    314|    fallback_parent = NULL;
 2288|    314|    fallback_signature_is_good = 0;
 2289|       |
 2290|    314|    for (parent = candidates; parent != NULL; parent = parent->next) {
  ------------------
  |  Branch (2290:31): [True: 314, False: 0]
  ------------------
 2291|       |        /* basic parenting skills (name, CA bit, key usage) */
 2292|    314|        if (x509_crt_check_parent(child, parent, top) != 0) {
  ------------------
  |  Branch (2292:13): [True: 0, False: 314]
  ------------------
 2293|      0|            continue;
 2294|      0|        }
 2295|       |
 2296|       |        /* +1 because stored max_pathlen is 1 higher that the actual value */
 2297|    314|        if (parent->max_pathlen > 0 &&
  ------------------
  |  Branch (2297:13): [True: 0, False: 314]
  ------------------
 2298|    314|            (size_t) parent->max_pathlen < 1 + path_cnt - self_cnt) {
  ------------------
  |  Branch (2298:13): [True: 0, False: 0]
  ------------------
 2299|      0|            continue;
 2300|      0|        }
 2301|       |
 2302|       |        /* Signature */
 2303|    314|#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
 2304|    314|check_signature:
 2305|    314|#endif
 2306|    314|        ret = x509_crt_check_signature(child, parent, rs_ctx);
 2307|       |
 2308|    314|#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
 2309|    314|        if (rs_ctx != NULL && ret == MBEDTLS_ERR_ECP_IN_PROGRESS) {
  ------------------
  |  |   51|      0|#define MBEDTLS_ERR_ECP_IN_PROGRESS                       -0x4B00
  ------------------
  |  Branch (2309:13): [True: 0, False: 314]
  |  Branch (2309:31): [True: 0, False: 0]
  ------------------
 2310|       |            /* save state */
 2311|      0|            rs_ctx->parent = parent;
 2312|      0|            rs_ctx->fallback_parent = fallback_parent;
 2313|      0|            rs_ctx->fallback_signature_is_good = fallback_signature_is_good;
 2314|       |
 2315|      0|            return ret;
 2316|      0|        }
 2317|       |#else
 2318|       |        (void) ret;
 2319|       |#endif
 2320|       |
 2321|    314|        signature_is_good = ret == 0;
 2322|    314|        if (top && !signature_is_good) {
  ------------------
  |  Branch (2322:13): [True: 314, False: 0]
  |  Branch (2322:20): [True: 0, False: 314]
  ------------------
 2323|      0|            continue;
 2324|      0|        }
 2325|       |
 2326|    314|#if defined(MBEDTLS_HAVE_TIME_DATE)
 2327|       |        /* optional time check */
 2328|    314|        if (mbedtls_x509_time_cmp(&parent->valid_to, now) < 0 ||    /* past */
  ------------------
  |  Branch (2328:13): [True: 0, False: 314]
  ------------------
 2329|    314|            mbedtls_x509_time_cmp(&parent->valid_from, now) > 0) {  /* future */
  ------------------
  |  Branch (2329:13): [True: 0, False: 314]
  ------------------
 2330|      0|            if (fallback_parent == NULL) {
  ------------------
  |  Branch (2330:17): [True: 0, False: 0]
  ------------------
 2331|      0|                fallback_parent = parent;
 2332|      0|                fallback_signature_is_good = signature_is_good;
 2333|      0|            }
 2334|       |
 2335|      0|            continue;
 2336|      0|        }
 2337|       |#else
 2338|       |        ((void) now);
 2339|       |#endif
 2340|       |
 2341|    314|        *r_parent = parent;
 2342|    314|        *r_signature_is_good = signature_is_good;
 2343|       |
 2344|    314|        break;
 2345|    314|    }
 2346|       |
 2347|    314|    if (parent == NULL) {
  ------------------
  |  Branch (2347:9): [True: 0, False: 314]
  ------------------
 2348|      0|        *r_parent = fallback_parent;
 2349|      0|        *r_signature_is_good = fallback_signature_is_good;
 2350|      0|    }
 2351|       |
 2352|    314|    return 0;
 2353|    314|}
x509_crt.c:x509_crt_check_parent:
 2183|    314|{
 2184|    314|    int need_ca_bit;
 2185|       |
 2186|       |    /* Parent must be the issuer */
 2187|    314|    if (x509_name_cmp(&child->issuer, &parent->subject) != 0) {
  ------------------
  |  Branch (2187:9): [True: 0, False: 314]
  ------------------
 2188|      0|        return -1;
 2189|      0|    }
 2190|       |
 2191|       |    /* Parent must have the basicConstraints CA bit set as a general rule */
 2192|    314|    need_ca_bit = 1;
 2193|       |
 2194|       |    /* Exception: v1/v2 certificates that are locally trusted. */
 2195|    314|    if (top && parent->version < 3) {
  ------------------
  |  Branch (2195:9): [True: 314, False: 0]
  |  Branch (2195:16): [True: 0, False: 314]
  ------------------
 2196|      0|        need_ca_bit = 0;
 2197|      0|    }
 2198|       |
 2199|    314|    if (need_ca_bit && !parent->ca_istrue) {
  ------------------
  |  Branch (2199:9): [True: 314, False: 0]
  |  Branch (2199:24): [True: 0, False: 314]
  ------------------
 2200|      0|        return -1;
 2201|      0|    }
 2202|       |
 2203|    314|    if (need_ca_bit &&
  ------------------
  |  Branch (2203:9): [True: 314, False: 0]
  ------------------
 2204|    314|        mbedtls_x509_crt_check_key_usage(parent, MBEDTLS_X509_KU_KEY_CERT_SIGN) != 0) {
  ------------------
  |  |  146|    314|#define MBEDTLS_X509_KU_KEY_CERT_SIGN                (0x04)  /* bit 5 */
  ------------------
  |  Branch (2204:9): [True: 0, False: 314]
  ------------------
 2205|      0|        return -1;
 2206|      0|    }
 2207|       |
 2208|    314|    return 0;
 2209|    314|}
x509_crt.c:x509_crt_check_signature:
 2127|    314|{
 2128|    314|    size_t hash_len;
 2129|    314|    unsigned char hash[MBEDTLS_MD_MAX_SIZE];
 2130|    314|#if !defined(MBEDTLS_USE_PSA_CRYPTO)
 2131|    314|    const mbedtls_md_info_t *md_info;
 2132|    314|    md_info = mbedtls_md_info_from_type(child->sig_md);
 2133|    314|    hash_len = mbedtls_md_get_size(md_info);
 2134|       |
 2135|       |    /* Note: hash errors can happen only after an internal error */
 2136|    314|    if (mbedtls_md(md_info, child->tbs.p, child->tbs.len, hash) != 0) {
  ------------------
  |  Branch (2136:9): [True: 0, False: 314]
  ------------------
 2137|      0|        return -1;
 2138|      0|    }
 2139|       |#else
 2140|       |    psa_algorithm_t hash_alg = mbedtls_md_psa_alg_from_type(child->sig_md);
 2141|       |    psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
 2142|       |
 2143|       |    status = psa_hash_compute(hash_alg,
 2144|       |                              child->tbs.p,
 2145|       |                              child->tbs.len,
 2146|       |                              hash,
 2147|       |                              sizeof(hash),
 2148|       |                              &hash_len);
 2149|       |    if (status != PSA_SUCCESS) {
 2150|       |        return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
 2151|       |    }
 2152|       |
 2153|       |#endif /* MBEDTLS_USE_PSA_CRYPTO */
 2154|       |    /* Skip expensive computation on obvious mismatch */
 2155|    314|    if (!mbedtls_pk_can_do(&parent->pk, child->sig_pk)) {
  ------------------
  |  Branch (2155:9): [True: 0, False: 314]
  ------------------
 2156|      0|        return -1;
 2157|      0|    }
 2158|       |
 2159|    314|#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
 2160|    314|    if (rs_ctx != NULL && child->sig_pk == MBEDTLS_PK_ECDSA) {
  ------------------
  |  Branch (2160:9): [True: 0, False: 314]
  |  Branch (2160:27): [True: 0, False: 0]
  ------------------
 2161|      0|        return mbedtls_pk_verify_restartable(&parent->pk,
 2162|      0|                                             child->sig_md, hash, hash_len,
 2163|      0|                                             child->sig.p, child->sig.len, &rs_ctx->pk);
 2164|      0|    }
 2165|       |#else
 2166|       |    (void) rs_ctx;
 2167|       |#endif
 2168|       |
 2169|    314|    return mbedtls_pk_verify_ext(child->sig_pk, child->sig_opts, &parent->pk,
 2170|    314|                                 child->sig_md, hash, hash_len,
 2171|    314|                                 child->sig.p, child->sig.len);
 2172|    314|}
x509_crt.c:x509_name_cmp:
  340|    785|{
  341|       |    /* Avoid recursion, it might not be optimised by the compiler */
  342|  1.25k|    while (a != NULL || b != NULL) {
  ------------------
  |  Branch (342:12): [True: 785, False: 471]
  |  Branch (342:25): [True: 0, False: 471]
  ------------------
  343|    785|        if (a == NULL || b == NULL) {
  ------------------
  |  Branch (343:13): [True: 0, False: 785]
  |  Branch (343:26): [True: 0, False: 785]
  ------------------
  344|      0|            return -1;
  345|      0|        }
  346|       |
  347|       |        /* type */
  348|    785|        if (a->oid.tag != b->oid.tag ||
  ------------------
  |  Branch (348:13): [True: 0, False: 785]
  ------------------
  349|    785|            a->oid.len != b->oid.len ||
  ------------------
  |  Branch (349:13): [True: 0, False: 785]
  ------------------
  350|    785|            memcmp(a->oid.p, b->oid.p, b->oid.len) != 0) {
  ------------------
  |  Branch (350:13): [True: 0, False: 785]
  ------------------
  351|      0|            return -1;
  352|      0|        }
  353|       |
  354|       |        /* value */
  355|    785|        if (x509_string_cmp(&a->val, &b->val) != 0) {
  ------------------
  |  Branch (355:13): [True: 314, False: 471]
  ------------------
  356|    314|            return -1;
  357|    314|        }
  358|       |
  359|       |        /* structure of the list of sets */
  360|    471|        if (a->next_merged != b->next_merged) {
  ------------------
  |  Branch (360:13): [True: 0, False: 471]
  ------------------
  361|      0|            return -1;
  362|      0|        }
  363|       |
  364|    471|        a = a->next;
  365|    471|        b = b->next;
  366|    471|    }
  367|       |
  368|       |    /* a == NULL == b */
  369|    471|    return 0;
  370|    785|}
x509_crt.c:x509_string_cmp:
  312|    785|{
  313|    785|    if (a->tag == b->tag &&
  ------------------
  |  Branch (313:9): [True: 785, False: 0]
  ------------------
  314|    785|        a->len == b->len &&
  ------------------
  |  Branch (314:9): [True: 471, False: 314]
  ------------------
  315|    785|        memcmp(a->p, b->p, b->len) == 0) {
  ------------------
  |  Branch (315:9): [True: 471, False: 0]
  ------------------
  316|    471|        return 0;
  317|    471|    }
  318|       |
  319|    314|    if ((a->tag == MBEDTLS_ASN1_UTF8_STRING || a->tag == MBEDTLS_ASN1_PRINTABLE_STRING) &&
  ------------------
  |  |   71|    628|#define MBEDTLS_ASN1_UTF8_STRING             0x0C
  ------------------
                  if ((a->tag == MBEDTLS_ASN1_UTF8_STRING || a->tag == MBEDTLS_ASN1_PRINTABLE_STRING) &&
  ------------------
  |  |   74|      0|#define MBEDTLS_ASN1_PRINTABLE_STRING        0x13
  ------------------
  |  Branch (319:10): [True: 314, False: 0]
  |  Branch (319:48): [True: 0, False: 0]
  ------------------
  320|    314|        (b->tag == MBEDTLS_ASN1_UTF8_STRING || b->tag == MBEDTLS_ASN1_PRINTABLE_STRING) &&
  ------------------
  |  |   71|    628|#define MBEDTLS_ASN1_UTF8_STRING             0x0C
  ------------------
                      (b->tag == MBEDTLS_ASN1_UTF8_STRING || b->tag == MBEDTLS_ASN1_PRINTABLE_STRING) &&
  ------------------
  |  |   74|      0|#define MBEDTLS_ASN1_PRINTABLE_STRING        0x13
  ------------------
  |  Branch (320:10): [True: 314, False: 0]
  |  Branch (320:48): [True: 0, False: 0]
  ------------------
  321|    314|        a->len == b->len &&
  ------------------
  |  Branch (321:9): [True: 0, False: 314]
  ------------------
  322|    314|        x509_memcasecmp(a->p, b->p, b->len) == 0) {
  ------------------
  |  Branch (322:9): [True: 0, False: 0]
  ------------------
  323|      0|        return 0;
  324|      0|    }
  325|       |
  326|    314|    return -1;
  327|    314|}
x509_crt.c:x509_crt_verifycrl:
 2014|    314|{
 2015|    314|    int flags = 0;
 2016|    314|    unsigned char hash[MBEDTLS_MD_MAX_SIZE];
 2017|       |#if defined(MBEDTLS_USE_PSA_CRYPTO)
 2018|       |    psa_algorithm_t psa_algorithm;
 2019|       |#else
 2020|    314|    const mbedtls_md_info_t *md_info;
 2021|    314|#endif /* MBEDTLS_USE_PSA_CRYPTO */
 2022|    314|    size_t hash_length;
 2023|       |
 2024|    314|    if (ca == NULL) {
  ------------------
  |  Branch (2024:9): [True: 0, False: 314]
  ------------------
 2025|      0|        return flags;
 2026|      0|    }
 2027|       |
 2028|    314|    while (crl_list != NULL) {
  ------------------
  |  Branch (2028:12): [True: 0, False: 314]
  ------------------
 2029|      0|        if (crl_list->version == 0 ||
  ------------------
  |  Branch (2029:13): [True: 0, False: 0]
  ------------------
 2030|      0|            x509_name_cmp(&crl_list->issuer, &ca->subject) != 0) {
  ------------------
  |  Branch (2030:13): [True: 0, False: 0]
  ------------------
 2031|      0|            crl_list = crl_list->next;
 2032|      0|            continue;
 2033|      0|        }
 2034|       |
 2035|       |        /*
 2036|       |         * Check if the CA is configured to sign CRLs
 2037|       |         */
 2038|      0|        if (mbedtls_x509_crt_check_key_usage(ca,
  ------------------
  |  Branch (2038:13): [True: 0, False: 0]
  ------------------
 2039|      0|                                             MBEDTLS_X509_KU_CRL_SIGN) != 0) {
  ------------------
  |  |  147|      0|#define MBEDTLS_X509_KU_CRL_SIGN                     (0x02)  /* bit 6 */
  ------------------
 2040|      0|            flags |= MBEDTLS_X509_BADCRL_NOT_TRUSTED;
  ------------------
  |  |   95|      0|#define MBEDTLS_X509_BADCRL_NOT_TRUSTED          0x10  /**< The CRL is not correctly signed by the trusted CA. */
  ------------------
 2041|      0|            break;
 2042|      0|        }
 2043|       |
 2044|       |        /*
 2045|       |         * Check if CRL is correctly signed by the trusted CA
 2046|       |         */
 2047|      0|        if (x509_profile_check_md_alg(profile, crl_list->sig_md) != 0) {
  ------------------
  |  Branch (2047:13): [True: 0, False: 0]
  ------------------
 2048|      0|            flags |= MBEDTLS_X509_BADCRL_BAD_MD;
  ------------------
  |  |  108|      0|#define MBEDTLS_X509_BADCRL_BAD_MD           0x020000  /**< The CRL is signed with an unacceptable hash. */
  ------------------
 2049|      0|        }
 2050|       |
 2051|      0|        if (x509_profile_check_pk_alg(profile, crl_list->sig_pk) != 0) {
  ------------------
  |  Branch (2051:13): [True: 0, False: 0]
  ------------------
 2052|      0|            flags |= MBEDTLS_X509_BADCRL_BAD_PK;
  ------------------
  |  |  109|      0|#define MBEDTLS_X509_BADCRL_BAD_PK           0x040000  /**< The CRL is signed with an unacceptable PK alg (eg RSA vs ECDSA). */
  ------------------
 2053|      0|        }
 2054|       |
 2055|       |#if defined(MBEDTLS_USE_PSA_CRYPTO)
 2056|       |        psa_algorithm = mbedtls_md_psa_alg_from_type(crl_list->sig_md);
 2057|       |        if (psa_hash_compute(psa_algorithm,
 2058|       |                             crl_list->tbs.p,
 2059|       |                             crl_list->tbs.len,
 2060|       |                             hash,
 2061|       |                             sizeof(hash),
 2062|       |                             &hash_length) != PSA_SUCCESS) {
 2063|       |            /* Note: this can't happen except after an internal error */
 2064|       |            flags |= MBEDTLS_X509_BADCRL_NOT_TRUSTED;
 2065|       |            break;
 2066|       |        }
 2067|       |#else
 2068|      0|        md_info = mbedtls_md_info_from_type(crl_list->sig_md);
 2069|      0|        hash_length = mbedtls_md_get_size(md_info);
 2070|      0|        if (mbedtls_md(md_info,
  ------------------
  |  Branch (2070:13): [True: 0, False: 0]
  ------------------
 2071|      0|                       crl_list->tbs.p,
 2072|      0|                       crl_list->tbs.len,
 2073|      0|                       hash) != 0) {
 2074|       |            /* Note: this can't happen except after an internal error */
 2075|      0|            flags |= MBEDTLS_X509_BADCRL_NOT_TRUSTED;
  ------------------
  |  |   95|      0|#define MBEDTLS_X509_BADCRL_NOT_TRUSTED          0x10  /**< The CRL is not correctly signed by the trusted CA. */
  ------------------
 2076|      0|            break;
 2077|      0|        }
 2078|      0|#endif /* MBEDTLS_USE_PSA_CRYPTO */
 2079|       |
 2080|      0|        if (x509_profile_check_key(profile, &ca->pk) != 0) {
  ------------------
  |  Branch (2080:13): [True: 0, False: 0]
  ------------------
 2081|      0|            flags |= MBEDTLS_X509_BADCERT_BAD_KEY;
  ------------------
  |  |  107|      0|#define MBEDTLS_X509_BADCERT_BAD_KEY         0x010000  /**< The certificate is signed with an unacceptable key (eg bad curve, RSA too short). */
  ------------------
 2082|      0|        }
 2083|       |
 2084|      0|        if (mbedtls_pk_verify_ext(crl_list->sig_pk, crl_list->sig_opts, &ca->pk,
  ------------------
  |  Branch (2084:13): [True: 0, False: 0]
  ------------------
 2085|      0|                                  crl_list->sig_md, hash, hash_length,
 2086|      0|                                  crl_list->sig.p, crl_list->sig.len) != 0) {
 2087|      0|            flags |= MBEDTLS_X509_BADCRL_NOT_TRUSTED;
  ------------------
  |  |   95|      0|#define MBEDTLS_X509_BADCRL_NOT_TRUSTED          0x10  /**< The CRL is not correctly signed by the trusted CA. */
  ------------------
 2088|      0|            break;
 2089|      0|        }
 2090|       |
 2091|      0|#if defined(MBEDTLS_HAVE_TIME_DATE)
 2092|       |        /*
 2093|       |         * Check for validity of CRL (Do not drop out)
 2094|       |         */
 2095|      0|        if (mbedtls_x509_time_cmp(&crl_list->next_update, now) < 0) {
  ------------------
  |  Branch (2095:13): [True: 0, False: 0]
  ------------------
 2096|      0|            flags |= MBEDTLS_X509_BADCRL_EXPIRED;
  ------------------
  |  |   96|      0|#define MBEDTLS_X509_BADCRL_EXPIRED              0x20  /**< The CRL is expired. */
  ------------------
 2097|      0|        }
 2098|       |
 2099|      0|        if (mbedtls_x509_time_cmp(&crl_list->this_update, now) > 0) {
  ------------------
  |  Branch (2099:13): [True: 0, False: 0]
  ------------------
 2100|      0|            flags |= MBEDTLS_X509_BADCRL_FUTURE;
  ------------------
  |  |  101|      0|#define MBEDTLS_X509_BADCRL_FUTURE             0x0400  /**< The CRL is from the future */
  ------------------
 2101|      0|        }
 2102|       |#else
 2103|       |        ((void) now);
 2104|       |#endif
 2105|       |
 2106|       |        /*
 2107|       |         * Check if certificate is revoked
 2108|       |         */
 2109|      0|        if (mbedtls_x509_crt_is_revoked(crt, crl_list)) {
  ------------------
  |  Branch (2109:13): [True: 0, False: 0]
  ------------------
 2110|      0|            flags |= MBEDTLS_X509_BADCERT_REVOKED;
  ------------------
  |  |   92|      0|#define MBEDTLS_X509_BADCERT_REVOKED             0x02  /**< The certificate has been revoked (is on a CRL). */
  ------------------
 2111|      0|            break;
 2112|      0|        }
 2113|       |
 2114|      0|        crl_list = crl_list->next;
 2115|      0|    }
 2116|       |
 2117|    314|    return flags;
 2118|    314|}
x509_crt.c:x509_crt_merge_flags_with_cb:
 3016|    471|{
 3017|    471|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|    471|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 3018|    471|    unsigned i;
 3019|    471|    uint32_t cur_flags;
 3020|    471|    const mbedtls_x509_crt_verify_chain_item *cur;
 3021|       |
 3022|  1.25k|    for (i = ver_chain->len; i != 0; --i) {
  ------------------
  |  Branch (3022:30): [True: 785, False: 471]
  ------------------
 3023|    785|        cur = &ver_chain->items[i-1];
 3024|    785|        cur_flags = cur->flags;
 3025|       |
 3026|    785|        if (NULL != f_vrfy) {
  ------------------
  |  Branch (3026:13): [True: 0, False: 785]
  ------------------
 3027|      0|            if ((ret = f_vrfy(p_vrfy, cur->crt, (int) i-1, &cur_flags)) != 0) {
  ------------------
  |  Branch (3027:17): [True: 0, False: 0]
  ------------------
 3028|      0|                return ret;
 3029|      0|            }
 3030|      0|        }
 3031|       |
 3032|    785|        *flags |= cur_flags;
 3033|    785|    }
 3034|       |
 3035|    471|    return 0;
 3036|    471|}
x509_crt.c:x509_crt_verify_chain_reset:
  377|    471|{
  378|    471|    size_t i;
  379|       |
  380|  5.18k|    for (i = 0; i < MBEDTLS_X509_MAX_VERIFY_CHAIN_SIZE; i++) {
  ------------------
  |  |  258|  5.18k|#define MBEDTLS_X509_MAX_VERIFY_CHAIN_SIZE  (MBEDTLS_X509_MAX_INTERMEDIATE_CA + 2)
  |  |  ------------------
  |  |  |  |   37|  5.18k|#define MBEDTLS_X509_MAX_INTERMEDIATE_CA   8
  |  |  ------------------
  ------------------
  |  Branch (380:17): [True: 4.71k, False: 471]
  ------------------
  381|  4.71k|        ver_chain->items[i].crt = NULL;
  382|  4.71k|        ver_chain->items[i].flags = (uint32_t) -1;
  383|  4.71k|    }
  384|       |
  385|    471|    ver_chain->len = 0;
  386|       |
  387|       |#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
  388|       |    ver_chain->trust_ca_cb_result = NULL;
  389|       |#endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
  390|    471|}

libspdm_consttime_is_mem_equal:
   11|  2.82k|{
   12|  2.82k|    const volatile uint8_t *pointer_dst;
   13|  2.82k|    const volatile uint8_t *pointer_src;
   14|  2.82k|    uint8_t delta;
   15|       |
   16|  2.82k|    pointer_dst = (const uint8_t *)destination_buffer;
   17|  2.82k|    pointer_src = (const uint8_t *)source_buffer;
   18|  2.82k|    delta = 0;
   19|  29.5k|    while ((length-- != 0)) {
  ------------------
  |  Branch (19:12): [True: 26.6k, False: 2.82k]
  ------------------
   20|  26.6k|        delta |= *(pointer_dst++) ^ *(pointer_src++);
   21|  26.6k|    }
   22|       |
   23|  2.82k|    return ((delta == 0) ? true : false);
  ------------------
  |  Branch (23:13): [True: 942, False: 1.88k]
  ------------------
   24|  2.82k|}

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

libspdm_set_mem:
   10|    157|{
   11|    157|    volatile uint8_t *pointer;
   12|       |
   13|    157|    pointer = (uint8_t *)buffer;
   14|   643k|    while (length-- != 0) {
  ------------------
  |  Branch (14:12): [True: 643k, False: 157]
  ------------------
   15|   643k|        *(pointer++) = value;
   16|   643k|    }
   17|    157|}

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

libspdm_read_responder_public_certificate_chain:
  369|    157|{
  370|    157|    bool res;
  371|    157|    void *file_data;
  372|    157|    size_t file_size;
  373|    157|    spdm_cert_chain_t *cert_chain;
  374|    157|    size_t cert_chain_size;
  375|    157|    char *file;
  376|    157|    const uint8_t *root_cert;
  377|    157|    size_t root_cert_len;
  378|    157|    size_t digest_size;
  379|    157|    bool is_requester_cert;
  380|    157|    bool is_device_cert_model;
  381|       |
  382|    157|    is_requester_cert = false;
  383|       |
  384|       |    /*default is true*/
  385|    157|    is_device_cert_model = true;
  386|       |
  387|    157|    *data = NULL;
  388|    157|    *size = 0;
  389|    157|    if (hash != NULL) {
  ------------------
  |  Branch (389:9): [True: 0, False: 157]
  ------------------
  390|      0|        *hash = NULL;
  391|      0|    }
  392|    157|    if (hash_size != NULL) {
  ------------------
  |  Branch (392:9): [True: 0, False: 157]
  ------------------
  393|      0|        *hash_size = 0;
  394|      0|    }
  395|       |
  396|    157|    if (base_asym_algo == 0) {
  ------------------
  |  Branch (396:9): [True: 0, False: 157]
  ------------------
  397|      0|        return false;
  398|      0|    }
  399|       |
  400|    157|    switch (base_asym_algo) {
  401|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
  ------------------
  |  |  371|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048 0x00000001
  ------------------
  |  Branch (401:5): [True: 0, False: 157]
  ------------------
  402|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
  ------------------
  |  |  372|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048 0x00000002
  ------------------
  |  Branch (402:5): [True: 0, False: 157]
  ------------------
  403|      0|        file = "rsa2048/bundle_responder.certchain.der";
  404|      0|        break;
  405|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
  ------------------
  |  |  373|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072 0x00000004
  ------------------
  |  Branch (405:5): [True: 0, False: 157]
  ------------------
  406|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
  ------------------
  |  |  374|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072 0x00000008
  ------------------
  |  Branch (406:5): [True: 0, False: 157]
  ------------------
  407|      0|        file = "rsa3072/bundle_responder.certchain.der";
  408|      0|        break;
  409|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
  ------------------
  |  |  376|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096 0x00000020
  ------------------
  |  Branch (409:5): [True: 0, False: 157]
  ------------------
  410|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
  ------------------
  |  |  377|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096 0x00000040
  ------------------
  |  Branch (410:5): [True: 0, False: 157]
  ------------------
  411|      0|        file = "rsa4096/bundle_responder.certchain.der";
  412|      0|        break;
  413|    157|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
  ------------------
  |  |  375|    157|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256 0x00000010
  ------------------
  |  Branch (413:5): [True: 157, False: 0]
  ------------------
  414|    157|        file = "ecp256/bundle_responder.certchain.der";
  415|    157|        break;
  416|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
  ------------------
  |  |  378|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384 0x00000080
  ------------------
  |  Branch (416:5): [True: 0, False: 157]
  ------------------
  417|      0|        file = "ecp384/bundle_responder.certchain.der";
  418|      0|        break;
  419|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
  ------------------
  |  |  379|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521 0x00000100
  ------------------
  |  Branch (419:5): [True: 0, False: 157]
  ------------------
  420|      0|        file = "ecp521/bundle_responder.certchain.der";
  421|      0|        break;
  422|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256:
  ------------------
  |  |  384|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256 0x00000200
  ------------------
  |  Branch (422:5): [True: 0, False: 157]
  ------------------
  423|      0|        file = "sm2/bundle_responder.certchain.der";
  424|      0|        break;
  425|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
  ------------------
  |  |  385|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519 0x00000400
  ------------------
  |  Branch (425:5): [True: 0, False: 157]
  ------------------
  426|      0|        file = "ed25519/bundle_responder.certchain.der";
  427|      0|        break;
  428|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
  ------------------
  |  |  386|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448 0x00000800
  ------------------
  |  Branch (428:5): [True: 0, False: 157]
  ------------------
  429|      0|        file = "ed448/bundle_responder.certchain.der";
  430|      0|        break;
  431|      0|    default:
  ------------------
  |  Branch (431:5): [True: 0, False: 157]
  ------------------
  432|      0|        LIBSPDM_ASSERT(false);
  433|      0|        return false;
  434|    157|    }
  435|    157|    res = libspdm_read_input_file(file, &file_data, &file_size);
  436|    157|    if (!res) {
  ------------------
  |  Branch (436:9): [True: 0, False: 157]
  ------------------
  437|      0|        return res;
  438|      0|    }
  439|       |
  440|    157|    digest_size = libspdm_get_hash_size(base_hash_algo);
  441|       |
  442|    157|    cert_chain_size = sizeof(spdm_cert_chain_t) + digest_size + file_size;
  443|    157|    cert_chain = (void *)malloc(cert_chain_size);
  444|    157|    if (cert_chain == NULL) {
  ------------------
  |  Branch (444:9): [True: 0, False: 157]
  ------------------
  445|      0|        free(file_data);
  446|      0|        return false;
  447|      0|    }
  448|    157|    cert_chain->length = (uint16_t)cert_chain_size;
  449|    157|    cert_chain->reserved = 0;
  450|       |
  451|    157|    res = libspdm_verify_cert_chain_data(file_data, file_size,
  452|    157|                                         base_asym_algo, base_hash_algo,
  453|    157|                                         is_requester_cert, is_device_cert_model);
  454|    157|    if (!res) {
  ------------------
  |  Branch (454:9): [True: 0, False: 157]
  ------------------
  455|      0|        free(file_data);
  456|      0|        free(cert_chain);
  457|      0|        return res;
  458|      0|    }
  459|       |
  460|       |
  461|       |    /* Get Root Certificate and calculate hash value*/
  462|       |
  463|    157|    res = libspdm_x509_get_cert_from_cert_chain(file_data, file_size, 0, &root_cert,
  464|    157|                                                &root_cert_len);
  465|    157|    if (!res) {
  ------------------
  |  Branch (465:9): [True: 0, False: 157]
  ------------------
  466|      0|        free(file_data);
  467|      0|        free(cert_chain);
  468|      0|        return res;
  469|      0|    }
  470|       |
  471|    157|    res = libspdm_hash_all(base_hash_algo, root_cert, root_cert_len,
  472|    157|                           (uint8_t *)(cert_chain + 1));
  473|    157|    if (!res) {
  ------------------
  |  Branch (473:9): [True: 0, False: 157]
  ------------------
  474|      0|        free(file_data);
  475|      0|        free(cert_chain);
  476|      0|        return res;
  477|      0|    }
  478|    157|    libspdm_copy_mem((uint8_t *)cert_chain + sizeof(spdm_cert_chain_t) + digest_size,
  479|    157|                     cert_chain_size - (sizeof(spdm_cert_chain_t) + digest_size),
  480|    157|                     file_data, file_size);
  481|       |
  482|    157|    *data = cert_chain;
  483|    157|    *size = cert_chain_size;
  484|    157|    if (hash != NULL) {
  ------------------
  |  Branch (484:9): [True: 0, False: 157]
  ------------------
  485|      0|        *hash = (cert_chain + 1);
  486|      0|    }
  487|    157|    if (hash_size != NULL) {
  ------------------
  |  Branch (487:9): [True: 0, False: 157]
  ------------------
  488|      0|        *hash_size = digest_size;
  489|      0|    }
  490|       |
  491|    157|    free(file_data);
  492|    157|    return true;
  493|    157|}

libspdm_setup_test_context:
   59|    157|{
   60|    157|    m_libspdm_test_context = spdm_test_context;
   61|    157|}
libspdm_unit_test_group_setup:
   64|    314|{
   65|    314|    libspdm_test_context_t *spdm_test_context;
   66|    314|    void *spdm_context;
   67|       |
   68|    314|    spdm_test_context = m_libspdm_test_context;
   69|    314|    spdm_test_context->spdm_context =
   70|    314|        (void *)malloc(libspdm_get_context_size());
   71|    314|    if (spdm_test_context->spdm_context == NULL) {
  ------------------
  |  Branch (71:9): [True: 0, False: 314]
  ------------------
   72|      0|        return (size_t)-1;
   73|      0|    }
   74|    314|    spdm_context = spdm_test_context->spdm_context;
   75|       |
   76|    314|    libspdm_init_context(spdm_context);
   77|       |
   78|    314|    libspdm_register_device_io_func(spdm_context,
   79|    314|                                    spdm_test_context->send_message,
   80|    314|                                    spdm_test_context->receive_message);
   81|    314|    libspdm_register_transport_layer_func(spdm_context,
   82|    314|                                          LIBSPDM_MAX_SPDM_MSG_SIZE,
  ------------------
  |  |  101|    314|#define LIBSPDM_MAX_SPDM_MSG_SIZE 0x1200
  ------------------
   83|    314|                                          LIBSPDM_TEST_TRANSPORT_HEADER_SIZE,
  ------------------
  |  |   27|    314|#define LIBSPDM_TEST_TRANSPORT_HEADER_SIZE  (2 + 8 + \
  |  |   28|    314|                                             LIBSPDM_TEST_SEQUENCE_NUMBER_COUNT)
  |  |  ------------------
  |  |  |  |   16|    314|#define LIBSPDM_TEST_SEQUENCE_NUMBER_COUNT 2
  |  |  ------------------
  ------------------
   84|    314|                                          LIBSPDM_TEST_TRANSPORT_TAIL_SIZE,
  ------------------
  |  |   30|    314|#define LIBSPDM_TEST_TRANSPORT_TAIL_SIZE    (LIBSPDM_TEST_MAX_RANDOM_NUMBER_COUNT + \
  |  |  ------------------
  |  |  |  |   17|    314|#define LIBSPDM_TEST_MAX_RANDOM_NUMBER_COUNT 32
  |  |  ------------------
  |  |   31|    314|                                             LIBSPDM_MAX_AEAD_TAG_SIZE + \
  |  |  ------------------
  |  |  |  |   75|    314|#define LIBSPDM_MAX_AEAD_TAG_SIZE 16
  |  |  ------------------
  |  |   32|    314|                                             (LIBSPDM_TEST_ALIGNMENT - 1))
  |  |  ------------------
  |  |  |  |   15|    314|#define LIBSPDM_TEST_ALIGNMENT 4
  |  |  ------------------
  ------------------
   85|    314|                                          libspdm_transport_test_encode_message,
   86|    314|                                          libspdm_transport_test_decode_message);
   87|    314|    libspdm_register_device_buffer_func(spdm_context,
   88|    314|                                        LIBSPDM_MAX_SENDER_RECEIVER_BUFFER_SIZE,
  ------------------
  |  |   93|    314|#define LIBSPDM_MAX_SENDER_RECEIVER_BUFFER_SIZE LIBSPDM_RECEIVER_BUFFER_SIZE
  |  |  ------------------
  |  |  |  |   78|    314|#define LIBSPDM_RECEIVER_BUFFER_SIZE (0x1200 + \
  |  |  |  |   79|    314|                                      LIBSPDM_TRANSPORT_ADDITIONAL_SIZE)
  |  |  |  |  ------------------
  |  |  |  |  |  |   70|    314|#define LIBSPDM_TRANSPORT_ADDITIONAL_SIZE    (LIBSPDM_TEST_TRANSPORT_HEADER_SIZE + \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   27|    314|#define LIBSPDM_TEST_TRANSPORT_HEADER_SIZE  (2 + 8 + \
  |  |  |  |  |  |  |  |   28|    314|                                             LIBSPDM_TEST_SEQUENCE_NUMBER_COUNT)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   16|    314|#define LIBSPDM_TEST_SEQUENCE_NUMBER_COUNT 2
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |   71|    314|                                              LIBSPDM_TEST_TRANSPORT_TAIL_SIZE)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   30|    314|#define LIBSPDM_TEST_TRANSPORT_TAIL_SIZE    (LIBSPDM_TEST_MAX_RANDOM_NUMBER_COUNT + \
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   17|    314|#define LIBSPDM_TEST_MAX_RANDOM_NUMBER_COUNT 32
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|    314|                                             LIBSPDM_MAX_AEAD_TAG_SIZE + \
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   75|    314|#define LIBSPDM_MAX_AEAD_TAG_SIZE 16
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   32|    314|                                             (LIBSPDM_TEST_ALIGNMENT - 1))
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   15|    314|#define LIBSPDM_TEST_ALIGNMENT 4
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   89|    314|                                        LIBSPDM_MAX_SENDER_RECEIVER_BUFFER_SIZE,
  ------------------
  |  |   93|    314|#define LIBSPDM_MAX_SENDER_RECEIVER_BUFFER_SIZE LIBSPDM_RECEIVER_BUFFER_SIZE
  |  |  ------------------
  |  |  |  |   78|    314|#define LIBSPDM_RECEIVER_BUFFER_SIZE (0x1200 + \
  |  |  |  |   79|    314|                                      LIBSPDM_TRANSPORT_ADDITIONAL_SIZE)
  |  |  |  |  ------------------
  |  |  |  |  |  |   70|    314|#define LIBSPDM_TRANSPORT_ADDITIONAL_SIZE    (LIBSPDM_TEST_TRANSPORT_HEADER_SIZE + \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   27|    314|#define LIBSPDM_TEST_TRANSPORT_HEADER_SIZE  (2 + 8 + \
  |  |  |  |  |  |  |  |   28|    314|                                             LIBSPDM_TEST_SEQUENCE_NUMBER_COUNT)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   16|    314|#define LIBSPDM_TEST_SEQUENCE_NUMBER_COUNT 2
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |   71|    314|                                              LIBSPDM_TEST_TRANSPORT_TAIL_SIZE)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   30|    314|#define LIBSPDM_TEST_TRANSPORT_TAIL_SIZE    (LIBSPDM_TEST_MAX_RANDOM_NUMBER_COUNT + \
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   17|    314|#define LIBSPDM_TEST_MAX_RANDOM_NUMBER_COUNT 32
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|    314|                                             LIBSPDM_MAX_AEAD_TAG_SIZE + \
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   75|    314|#define LIBSPDM_MAX_AEAD_TAG_SIZE 16
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   32|    314|                                             (LIBSPDM_TEST_ALIGNMENT - 1))
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   15|    314|#define LIBSPDM_TEST_ALIGNMENT 4
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   90|    314|                                        spdm_device_acquire_sender_buffer,
   91|    314|                                        spdm_device_release_sender_buffer,
   92|    314|                                        spdm_device_acquire_receiver_buffer,
   93|    314|                                        spdm_device_release_receiver_buffer);
   94|       |
   95|    314|    spdm_test_context->scratch_buffer_size =
   96|    314|        libspdm_get_sizeof_required_scratch_buffer(spdm_context);
   97|    314|    spdm_test_context->scratch_buffer = (void *)malloc(spdm_test_context->scratch_buffer_size);
   98|    314|    libspdm_set_scratch_buffer (spdm_context,
   99|    314|                                spdm_test_context->scratch_buffer,
  100|    314|                                spdm_test_context->scratch_buffer_size);
  101|       |
  102|    314|    *State = spdm_test_context;
  103|    314|    return 0;
  104|    314|}
libspdm_unit_test_group_teardown:
  107|    314|{
  108|    314|    libspdm_test_context_t *spdm_test_context;
  109|       |
  110|    314|    spdm_test_context = *State;
  111|    314|    free(spdm_test_context->spdm_context);
  112|    314|    free(spdm_test_context->scratch_buffer);
  113|    314|    spdm_test_context->spdm_context = NULL;
  114|    314|    return 0;
  115|    314|}
libspdm_read_input_file:
  119|    157|{
  120|    157|    FILE *fp_in;
  121|    157|    size_t temp_result;
  122|       |
  123|    157|    if ((fp_in = fopen(file_name, "rb")) == NULL) {
  ------------------
  |  Branch (123:9): [True: 0, False: 157]
  ------------------
  124|      0|        printf("Unable to open file %s\n", file_name);
  125|      0|        *file_data = NULL;
  126|      0|        return false;
  127|      0|    }
  128|       |
  129|    157|    fseek(fp_in, 0, SEEK_END);
  130|    157|    *file_size = ftell(fp_in);
  131|       |
  132|    157|    *file_data = (void *)malloc(*file_size);
  133|    157|    if (NULL == *file_data) {
  ------------------
  |  Branch (133:9): [True: 0, False: 157]
  ------------------
  134|      0|        printf("No sufficient memory to allocate %s\n", file_name);
  135|      0|        fclose(fp_in);
  136|      0|        return false;
  137|      0|    }
  138|       |
  139|    157|    fseek(fp_in, 0, SEEK_SET);
  140|    157|    temp_result = fread(*file_data, 1, *file_size, fp_in);
  141|    157|    if (temp_result != *file_size) {
  ------------------
  |  Branch (141:9): [True: 0, False: 157]
  ------------------
  142|      0|        printf("Read input file error %s", file_name);
  143|      0|        free((void *)*file_data);
  144|      0|        fclose(fp_in);
  145|      0|        return false;
  146|      0|    }
  147|       |
  148|    157|    fclose(fp_in);
  149|       |
  150|    157|    return true;
  151|    157|}

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

libspdm_get_max_buffer_size:
   16|    314|{
   17|    314|    return LIBSPDM_MAX_SPDM_MSG_SIZE;
  ------------------
  |  |  101|    314|#define LIBSPDM_MAX_SPDM_MSG_SIZE 0x1200
  ------------------
   18|    314|}
libspdm_test_responder_encap_get_digests_case1:
   26|    157|{
   27|    157|    libspdm_test_context_t *spdm_test_context;
   28|    157|    libspdm_context_t *spdm_context;
   29|    157|    bool need_continue;
   30|    157|    uint8_t m_local_certificate_chain[LIBSPDM_MAX_CERT_CHAIN_SIZE];
   31|       |
   32|    157|    spdm_test_context = *State;
   33|    157|    spdm_context = spdm_test_context->spdm_context;
   34|    157|    spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
  ------------------
  |  |  111|    157|#define SPDM_MESSAGE_VERSION_11 0x11
  ------------------
   35|    157|                                            SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    157|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
   36|    157|    spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
   37|    157|    spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
  ------------------
  |  |  234|    157|#define SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP 0x00000002
  ------------------
   38|    157|    spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
   39|    157|    spdm_context->local_context.local_cert_chain_provision[0] = m_local_certificate_chain;
   40|    157|    spdm_context->local_context.local_cert_chain_provision_size[0] =
   41|    157|        sizeof(m_local_certificate_chain);
   42|    157|    libspdm_set_mem(m_local_certificate_chain, sizeof(m_local_certificate_chain), (uint8_t)(0xFF));
   43|       |
   44|    157|    libspdm_process_encap_response_digest(spdm_context, spdm_test_context->test_buffer_size,
   45|    157|                                          spdm_test_context->test_buffer, &need_continue);
   46|    157|    libspdm_reset_message_mut_c(spdm_context);
   47|    157|}
libspdm_test_get_encap_request_get_digest_case2:
   50|    157|{
   51|       |
   52|    157|    libspdm_test_context_t *spdm_test_context;
   53|    157|    spdm_get_digest_request_t *spdm_request;
   54|    157|    libspdm_context_t *spdm_context;
   55|    157|    size_t encap_request_size;
   56|    157|    void *data;
   57|    157|    size_t data_size;
   58|       |
   59|    157|    spdm_test_context = *State;
   60|    157|    spdm_context = spdm_test_context->spdm_context;
   61|    157|    encap_request_size = spdm_test_context->test_buffer_size;
   62|       |
   63|    157|    if (encap_request_size < sizeof(spdm_get_digest_request_t)) {
  ------------------
  |  Branch (63:9): [True: 0, False: 157]
  ------------------
   64|      0|        encap_request_size = sizeof(spdm_get_digest_request_t);
   65|      0|    }
   66|    157|    spdm_request = malloc(encap_request_size);
   67|       |
   68|    157|    spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
   69|    157|    spdm_context->connection_info.capability.flags = 0;
   70|    157|    spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
  ------------------
  |  |  185|    157|#define SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP 0x00000002
  ------------------
   71|    157|    spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
  ------------------
  |  |  111|    157|#define SPDM_MESSAGE_VERSION_11 0x11
  ------------------
   72|    157|                                            SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    157|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
   73|    157|    libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
   74|    157|                                                    m_libspdm_use_asym_algo, &data,
   75|    157|                                                    &data_size,
   76|    157|                                                    NULL, NULL);
   77|    157|    spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
   78|    157|    spdm_context->local_context.local_cert_chain_provision[0] = data;
   79|    157|    spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
   80|    157|    spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
   81|    157|    libspdm_reset_message_b(spdm_context);
   82|       |
   83|    157|    libspdm_get_encap_request_get_digest(spdm_context, &encap_request_size, spdm_request);
   84|    157|    libspdm_reset_message_mut_c(spdm_context);
   85|    157|    free(spdm_request);
   86|    157|    free(data);
   87|    157|}
libspdm_run_test_harness:
   90|    157|{
   91|    157|    void *State;
   92|       |
   93|    157|    libspdm_setup_test_context(&m_libspdm_responder_encap_get_digests_test_context);
   94|       |
   95|    157|    m_libspdm_responder_encap_get_digests_test_context.test_buffer = test_buffer;
   96|    157|    m_libspdm_responder_encap_get_digests_test_context.test_buffer_size = test_buffer_size;
   97|       |
   98|       |    /* Success Case */
   99|    157|    libspdm_unit_test_group_setup(&State);
  100|    157|    libspdm_test_responder_encap_get_digests_case1(&State);
  101|    157|    libspdm_unit_test_group_teardown(&State);
  102|       |
  103|       |    /* Success Case */
  104|    157|    libspdm_unit_test_group_setup(&State);
  105|    157|    libspdm_test_get_encap_request_get_digest_case2(&State);
  106|    157|    libspdm_unit_test_group_teardown(&State);
  107|    157|}

