libspdm_get_scratch_buffer_secure_message_capacity:
   17|  3.16k|uint32_t libspdm_get_scratch_buffer_secure_message_capacity(libspdm_context_t *spdm_context) {
   18|  3.16k|    return spdm_context->local_context.capability.max_spdm_msg_size +
   19|  3.16k|           spdm_context->local_context.capability.transport_header_size +
   20|  3.16k|           spdm_context->local_context.capability.transport_tail_size;
   21|  3.16k|}
libspdm_get_scratch_buffer_large_message_capacity:
   28|  3.16k|uint32_t libspdm_get_scratch_buffer_large_message_capacity(libspdm_context_t *spdm_context) {
   29|  3.16k|    return spdm_context->local_context.capability.max_spdm_msg_size;
   30|  3.16k|}
libspdm_get_scratch_buffer_sender_receiver_capacity:
   43|  3.16k|uint32_t libspdm_get_scratch_buffer_sender_receiver_capacity(libspdm_context_t *spdm_context) {
   44|  3.16k|    return spdm_context->local_context.capability.max_spdm_msg_size +
   45|  3.16k|           spdm_context->local_context.capability.transport_header_size +
   46|  3.16k|           spdm_context->local_context.capability.transport_tail_size;
   47|  3.16k|}
libspdm_get_scratch_buffer_large_sender_receiver_capacity:
   58|  3.16k|{
   59|  3.16k|    return spdm_context->local_context.capability.max_spdm_msg_size +
   60|  3.16k|           spdm_context->local_context.capability.transport_header_size +
   61|  3.16k|           spdm_context->local_context.capability.transport_tail_size;
   62|  3.16k|}
libspdm_get_scratch_buffer_last_spdm_request_offset:
   66|  1.05k|uint32_t libspdm_get_scratch_buffer_last_spdm_request_offset(libspdm_context_t *spdm_context) {
   67|  1.05k|    return 0 +
   68|  1.05k|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
   69|  1.05k|           libspdm_get_scratch_buffer_secure_message_capacity(spdm_context) +
   70|  1.05k|           libspdm_get_scratch_buffer_large_message_capacity(spdm_context) +
   71|  1.05k|#endif
   72|  1.05k|           libspdm_get_scratch_buffer_sender_receiver_capacity(spdm_context) +
   73|  1.05k|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
   74|  1.05k|           libspdm_get_scratch_buffer_large_sender_receiver_capacity(spdm_context) +
   75|  1.05k|#endif
   76|  1.05k|           0;
   77|  1.05k|}
libspdm_get_scratch_buffer_last_spdm_request_capacity:
   79|  2.11k|uint32_t libspdm_get_scratch_buffer_last_spdm_request_capacity(libspdm_context_t *spdm_context) {
   80|  2.11k|    return spdm_context->local_context.capability.max_spdm_msg_size;
   81|  2.11k|}
libspdm_get_scratch_buffer_cache_spdm_request_offset:
   85|  1.05k|uint32_t libspdm_get_scratch_buffer_cache_spdm_request_offset(libspdm_context_t *spdm_context) {
   86|  1.05k|    return 0 +
   87|  1.05k|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
   88|  1.05k|           libspdm_get_scratch_buffer_secure_message_capacity(spdm_context) +
   89|  1.05k|           libspdm_get_scratch_buffer_large_message_capacity(spdm_context) +
   90|  1.05k|#endif
   91|  1.05k|           libspdm_get_scratch_buffer_sender_receiver_capacity(spdm_context) +
   92|  1.05k|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
   93|  1.05k|           libspdm_get_scratch_buffer_large_sender_receiver_capacity(spdm_context) +
   94|  1.05k|#endif
   95|  1.05k|           libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context) +
   96|  1.05k|           0;
   97|  1.05k|}
libspdm_get_scratch_buffer_cache_spdm_request_capacity:
   99|  1.05k|uint32_t libspdm_get_scratch_buffer_cache_spdm_request_capacity(libspdm_context_t *spdm_context) {
  100|  1.05k|    return spdm_context->local_context.capability.max_spdm_msg_size;
  101|  1.05k|}
libspdm_get_scratch_buffer_capacity:
  105|  1.05k|uint32_t libspdm_get_scratch_buffer_capacity(libspdm_context_t *spdm_context) {
  106|  1.05k|    return 0 +
  107|  1.05k|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
  108|  1.05k|           libspdm_get_scratch_buffer_secure_message_capacity(spdm_context) +
  109|  1.05k|           libspdm_get_scratch_buffer_large_message_capacity(spdm_context) +
  110|  1.05k|#endif
  111|  1.05k|           libspdm_get_scratch_buffer_sender_receiver_capacity(spdm_context) +
  112|  1.05k|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
  113|  1.05k|           libspdm_get_scratch_buffer_large_sender_receiver_capacity(spdm_context) +
  114|  1.05k|#endif
  115|  1.05k|           libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context) +
  116|  1.05k|#if LIBSPDM_RESPOND_IF_READY_SUPPORT
  117|  1.05k|           libspdm_get_scratch_buffer_cache_spdm_request_capacity(spdm_context) +
  118|  1.05k|#endif
  119|  1.05k|           0;
  120|  1.05k|}
libspdm_reset_message_b:
 1280|      6|{
 1281|       |#if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
 1282|       |    libspdm_reset_managed_buffer(&spdm_context->transcript.message_b);
 1283|       |#else
 1284|      6|    if (spdm_context->transcript.digest_context_m1m2 != NULL) {
  ------------------
  |  Branch (1284:9): [True: 3, False: 3]
  ------------------
 1285|      3|        libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
 1286|      3|                           spdm_context->transcript.digest_context_m1m2);
 1287|      3|        spdm_context->transcript.digest_context_m1m2 = NULL;
 1288|      3|    }
 1289|      6|#endif
 1290|      6|}
libspdm_reset_message_c:
 1298|  1.06k|{
 1299|       |#if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
 1300|       |    libspdm_reset_managed_buffer(&spdm_context->transcript.message_c);
 1301|       |#else
 1302|  1.06k|    if (spdm_context->transcript.digest_context_m1m2 != NULL) {
  ------------------
  |  Branch (1302:9): [True: 0, False: 1.06k]
  ------------------
 1303|      0|        libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
 1304|      0|                           spdm_context->transcript.digest_context_m1m2);
 1305|      0|        spdm_context->transcript.digest_context_m1m2 = NULL;
 1306|      0|    }
 1307|  1.06k|#endif
 1308|  1.06k|}
libspdm_reset_message_mut_b:
 1316|      1|{
 1317|       |#if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
 1318|       |    libspdm_reset_managed_buffer(&spdm_context->transcript.message_mut_b);
 1319|       |#else
 1320|      1|    if (spdm_context->transcript.digest_context_mut_m1m2 != NULL) {
  ------------------
  |  Branch (1320:9): [True: 0, False: 1]
  ------------------
 1321|      0|        libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
 1322|      0|                           spdm_context->transcript.digest_context_mut_m1m2);
 1323|      0|        spdm_context->transcript.digest_context_mut_m1m2 = NULL;
 1324|      0|    }
 1325|      1|#endif
 1326|      1|}
libspdm_reset_message_mut_c:
 1334|      1|{
 1335|       |#if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
 1336|       |    libspdm_reset_managed_buffer(&spdm_context->transcript.message_mut_c);
 1337|       |#else
 1338|      1|    if (spdm_context->transcript.digest_context_mut_m1m2 != NULL) {
  ------------------
  |  Branch (1338:9): [True: 0, False: 1]
  ------------------
 1339|      0|        libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
 1340|      0|                           spdm_context->transcript.digest_context_mut_m1m2);
 1341|      0|        spdm_context->transcript.digest_context_mut_m1m2 = NULL;
 1342|      0|    }
 1343|      1|#endif
 1344|      1|}
libspdm_reset_message_m:
 1355|      3|{
 1356|      3|    libspdm_session_info_t *spdm_session_info;
 1357|       |
 1358|      3|    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|      3|    if (spdm_session_info == NULL) {
  ------------------
  |  Branch (1366:9): [True: 3, False: 0]
  ------------------
 1367|      3|        if (spdm_context->transcript.digest_context_l1l2 != NULL) {
  ------------------
  |  Branch (1367:13): [True: 0, False: 3]
  ------------------
 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|      3|    } 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|      3|#endif
 1380|      3|}
libspdm_reset_message_buffer_via_request_code:
 1533|      3|{
 1534|      3|    libspdm_context_t *spdm_context;
 1535|       |
 1536|      3|    spdm_context = context;
 1537|       |    /**
 1538|       |     * Any request other than SPDM_GET_MEASUREMENTS resets L1/L2
 1539|       |     */
 1540|      3|    if (request_code != SPDM_GET_MEASUREMENTS) {
  ------------------
  |  |   70|      3|#define SPDM_GET_MEASUREMENTS 0xE0
  ------------------
  |  Branch (1540:9): [True: 3, False: 0]
  ------------------
 1541|      3|        libspdm_reset_message_m(spdm_context, session_info);
 1542|      3|    }
 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|      3|    switch (request_code)
 1549|      3|    {
 1550|      0|    case SPDM_KEY_EXCHANGE:
  ------------------
  |  |   77|      0|#define SPDM_KEY_EXCHANGE 0xE4
  ------------------
  |  Branch (1550:5): [True: 0, False: 3]
  ------------------
 1551|      0|    case SPDM_GET_MEASUREMENTS:
  ------------------
  |  |   70|      0|#define SPDM_GET_MEASUREMENTS 0xE0
  ------------------
  |  Branch (1551:5): [True: 0, False: 3]
  ------------------
 1552|      0|    case SPDM_FINISH:
  ------------------
  |  |   78|      0|#define SPDM_FINISH 0xE5
  ------------------
  |  Branch (1552:5): [True: 0, False: 3]
  ------------------
 1553|      0|    case SPDM_PSK_EXCHANGE:
  ------------------
  |  |   79|      0|#define SPDM_PSK_EXCHANGE 0xE6
  ------------------
  |  Branch (1553:5): [True: 0, False: 3]
  ------------------
 1554|      0|    case SPDM_PSK_FINISH:
  ------------------
  |  |   80|      0|#define SPDM_PSK_FINISH 0xE7
  ------------------
  |  Branch (1554:5): [True: 0, False: 3]
  ------------------
 1555|      0|    case SPDM_KEY_UPDATE:
  ------------------
  |  |   82|      0|#define SPDM_KEY_UPDATE 0xE9
  ------------------
  |  Branch (1555:5): [True: 0, False: 3]
  ------------------
 1556|      0|    case SPDM_HEARTBEAT:
  ------------------
  |  |   81|      0|#define SPDM_HEARTBEAT 0xE8
  ------------------
  |  Branch (1556:5): [True: 0, False: 3]
  ------------------
 1557|      0|    case SPDM_GET_ENCAPSULATED_REQUEST:
  ------------------
  |  |   83|      0|#define SPDM_GET_ENCAPSULATED_REQUEST 0xEA
  ------------------
  |  Branch (1557:5): [True: 0, False: 3]
  ------------------
 1558|      0|    case SPDM_END_SESSION:
  ------------------
  |  |   85|      0|#define SPDM_END_SESSION 0xEC
  ------------------
  |  Branch (1558:5): [True: 0, False: 3]
  ------------------
 1559|      0|    case SPDM_GET_MEASUREMENT_EXTENSION_LOG:
  ------------------
  |  |   98|      0|#define SPDM_GET_MEASUREMENT_EXTENSION_LOG 0xEF
  ------------------
  |  Branch (1559:5): [True: 0, False: 3]
  ------------------
 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: 3]
  ------------------
 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: 3]
  ------------------
 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: 3]
  ------------------
 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|      3|    default:
  ------------------
  |  Branch (1582:5): [True: 3, False: 0]
  ------------------
 1583|      3|        break;
 1584|      3|    }
 1585|      3|}
libspdm_append_message_c:
 1699|      6|{
 1700|       |#if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
 1701|       |    return libspdm_append_managed_buffer(&spdm_context->transcript.message_c,
 1702|       |                                         message, message_size);
 1703|       |#else
 1704|      6|    {
 1705|      6|        bool result;
 1706|       |
 1707|      6|        if (spdm_context->transcript.digest_context_m1m2 == NULL) {
  ------------------
  |  Branch (1707:13): [True: 3, False: 3]
  ------------------
 1708|      3|            spdm_context->transcript.digest_context_m1m2 = libspdm_hash_new (
 1709|      3|                spdm_context->connection_info.algorithm.base_hash_algo);
 1710|      3|            if (spdm_context->transcript.digest_context_m1m2 == NULL) {
  ------------------
  |  Branch (1710:17): [True: 0, False: 3]
  ------------------
 1711|      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)))
  |  |  ------------------
  ------------------
 1712|      0|            }
 1713|      3|            result = libspdm_hash_init (spdm_context->connection_info.algorithm.base_hash_algo,
 1714|      3|                                        spdm_context->transcript.digest_context_m1m2);
 1715|      3|            if (!result) {
  ------------------
  |  Branch (1715:17): [True: 0, False: 3]
  ------------------
 1716|      0|                libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
 1717|      0|                                   spdm_context->transcript.digest_context_m1m2);
 1718|      0|                spdm_context->transcript.digest_context_m1m2 = NULL;
 1719|      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)))
  |  |  ------------------
  ------------------
 1720|      0|            }
 1721|      3|            result = libspdm_hash_update (spdm_context->connection_info.algorithm.base_hash_algo,
 1722|      3|                                          spdm_context->transcript.digest_context_m1m2,
 1723|      3|                                          libspdm_get_managed_buffer(&spdm_context->transcript.
 1724|      3|                                                                     message_a),
 1725|      3|                                          libspdm_get_managed_buffer_size(&spdm_context->transcript.
 1726|      3|                                                                          message_a));
 1727|      3|            if (!result) {
  ------------------
  |  Branch (1727:17): [True: 0, False: 3]
  ------------------
 1728|      0|                libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
 1729|      0|                                   spdm_context->transcript.digest_context_m1m2);
 1730|      0|                spdm_context->transcript.digest_context_m1m2 = NULL;
 1731|      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)))
  |  |  ------------------
  ------------------
 1732|      0|            }
 1733|      3|        }
 1734|       |
 1735|      6|        result = libspdm_hash_update (spdm_context->connection_info.algorithm.base_hash_algo,
 1736|      6|                                      spdm_context->transcript.digest_context_m1m2, message,
 1737|      6|                                      message_size);
 1738|      6|        if (!result) {
  ------------------
  |  Branch (1738:13): [True: 0, False: 6]
  ------------------
 1739|      0|            libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
 1740|      0|                               spdm_context->transcript.digest_context_m1m2);
 1741|      0|            spdm_context->transcript.digest_context_m1m2 = NULL;
 1742|      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)))
  |  |  ------------------
  ------------------
 1743|      0|        }
 1744|       |
 1745|      6|        return LIBSPDM_STATUS_SUCCESS;
  ------------------
  |  |   59|      6|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_SUCCESS, LIBSPDM_SOURCE_SUCCESS, 0x0000)
  |  |  ------------------
  |  |  |  |   55|      6|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
 1746|      6|    }
 1747|      6|#endif
 1748|      6|}
libspdm_get_connection_version:
 2632|  2.11k|{
 2633|  2.11k|    return (uint8_t)(spdm_context->connection_info.version >> SPDM_VERSION_NUMBER_SHIFT_BIT);
  ------------------
  |  |  140|  2.11k|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 2634|  2.11k|}
libspdm_is_capabilities_flag_supported:
 2651|    207|{
 2652|    207|    uint32_t negotiated_requester_capabilities_flag;
 2653|    207|    uint32_t negotiated_responder_capabilities_flag;
 2654|       |
 2655|    207|    if (is_requester) {
  ------------------
  |  Branch (2655:9): [True: 0, False: 207]
  ------------------
 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|    207|    } else {
 2659|    207|        negotiated_requester_capabilities_flag = spdm_context->connection_info.capability.flags;
 2660|    207|        negotiated_responder_capabilities_flag = spdm_context->local_context.capability.flags;
 2661|    207|    }
 2662|       |
 2663|    207|    if (((requester_capabilities_flag == 0) ||
  ------------------
  |  Branch (2663:10): [True: 200, False: 7]
  ------------------
 2664|    207|         ((negotiated_requester_capabilities_flag &
  ------------------
  |  Branch (2664:10): [True: 4, False: 3]
  ------------------
 2665|      7|           requester_capabilities_flag) != 0)) &&
 2666|    207|        ((responder_capabilities_flag == 0) ||
  ------------------
  |  Branch (2666:10): [True: 3, False: 201]
  ------------------
 2667|    204|         ((negotiated_responder_capabilities_flag &
  ------------------
  |  Branch (2667:10): [True: 141, False: 60]
  ------------------
 2668|    201|           responder_capabilities_flag) != 0))) {
 2669|    144|        return true;
 2670|    144|    } else {
 2671|     63|        return false;
 2672|     63|    }
 2673|    207|}
libspdm_register_device_io_func:
 2720|  1.05k|{
 2721|  1.05k|    libspdm_context_t *context;
 2722|       |
 2723|  1.05k|    context = spdm_context;
 2724|  1.05k|    context->send_message = send_message;
 2725|  1.05k|    context->receive_message = receive_message;
 2726|  1.05k|}
libspdm_register_device_buffer_func:
 2779|  1.05k|{
 2780|  1.05k|    libspdm_context_t *context;
 2781|       |
 2782|  1.05k|    context = spdm_context;
 2783|  1.05k|    context->sender_buffer_size = sender_buffer_size;
 2784|  1.05k|    context->receiver_buffer_size = receiver_buffer_size;
 2785|  1.05k|    context->acquire_sender_buffer = acquire_sender_buffer;
 2786|  1.05k|    context->release_sender_buffer = release_sender_buffer;
 2787|  1.05k|    context->acquire_receiver_buffer = acquire_receiver_buffer;
 2788|  1.05k|    context->release_receiver_buffer = release_receiver_buffer;
 2789|       |
 2790|  1.05k|    LIBSPDM_ASSERT (sender_buffer_size >=
 2791|  1.05k|                    context->local_context.capability.transport_header_size +
 2792|  1.05k|                    context->local_context.capability.transport_tail_size);
 2793|  1.05k|    sender_buffer_size -= (context->local_context.capability.transport_header_size +
 2794|  1.05k|                           context->local_context.capability.transport_tail_size);
 2795|  1.05k|    LIBSPDM_ASSERT (sender_buffer_size >= SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12);
 2796|  1.05k|    context->local_context.capability.sender_data_transfer_size = sender_buffer_size;
 2797|       |
 2798|  1.05k|    LIBSPDM_ASSERT(receiver_buffer_size >=
 2799|  1.05k|                   context->local_context.capability.transport_header_size +
 2800|  1.05k|                   context->local_context.capability.transport_tail_size);
 2801|  1.05k|    receiver_buffer_size -= (context->local_context.capability.transport_header_size +
 2802|  1.05k|                             context->local_context.capability.transport_tail_size);
 2803|  1.05k|    LIBSPDM_ASSERT (receiver_buffer_size >= SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12);
 2804|  1.05k|    context->local_context.capability.data_transfer_size = receiver_buffer_size;
 2805|  1.05k|}
libspdm_register_transport_layer_func:
 2823|  1.05k|{
 2824|  1.05k|    libspdm_context_t *context;
 2825|       |
 2826|  1.05k|    context = spdm_context;
 2827|       |
 2828|       |    /* fix the data_transfer_size if it is set before */
 2829|  1.05k|    if ((context->local_context.capability.data_transfer_size != 0) &&
  ------------------
  |  Branch (2829:9): [True: 0, False: 1.05k]
  ------------------
 2830|  1.05k|        (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|  1.05k|    if ((context->local_context.capability.sender_data_transfer_size != 0) &&
  ------------------
  |  Branch (2836:9): [True: 0, False: 1.05k]
  ------------------
 2837|  1.05k|        (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|  1.05k|    context->local_context.capability.max_spdm_msg_size = max_spdm_msg_size;
 2845|  1.05k|    context->local_context.capability.transport_header_size = transport_header_size;
 2846|  1.05k|    context->local_context.capability.transport_tail_size = transport_tail_size;
 2847|  1.05k|    context->transport_encode_message = transport_encode_message;
 2848|  1.05k|    context->transport_decode_message = transport_decode_message;
 2849|  1.05k|}
libspdm_get_sizeof_required_scratch_buffer:
 2886|  1.05k|{
 2887|  1.05k|    libspdm_context_t *context;
 2888|  1.05k|    size_t scratch_buffer_size;
 2889|       |
 2890|  1.05k|    context = spdm_context;
 2891|  1.05k|    LIBSPDM_ASSERT (context->local_context.capability.max_spdm_msg_size != 0);
 2892|       |
 2893|  1.05k|    scratch_buffer_size = libspdm_get_scratch_buffer_capacity(context);
 2894|  1.05k|    return scratch_buffer_size;
 2895|  1.05k|}
libspdm_set_scratch_buffer:
 2911|  1.05k|{
 2912|  1.05k|    libspdm_context_t *context;
 2913|       |
 2914|  1.05k|    context = spdm_context;
 2915|  1.05k|    LIBSPDM_ASSERT (context->local_context.capability.max_spdm_msg_size != 0);
 2916|  1.05k|    LIBSPDM_ASSERT (scratch_buffer_size >= libspdm_get_scratch_buffer_capacity(spdm_context));
 2917|  1.05k|    context->scratch_buffer = scratch_buffer;
 2918|  1.05k|    context->scratch_buffer_size = scratch_buffer_size;
 2919|  1.05k|    context->last_spdm_request = (uint8_t *)scratch_buffer +
 2920|  1.05k|                                 libspdm_get_scratch_buffer_last_spdm_request_offset(spdm_context);
 2921|  1.05k|#if LIBSPDM_RESPOND_IF_READY_SUPPORT
 2922|  1.05k|    context->cache_spdm_request = (uint8_t *)scratch_buffer +
 2923|  1.05k|                                  libspdm_get_scratch_buffer_cache_spdm_request_offset(spdm_context);
 2924|  1.05k|#endif
 2925|  1.05k|}
libspdm_init_context_with_secured_context:
 3240|  1.05k|{
 3241|  1.05k|    libspdm_context_t *context;
 3242|  1.05k|    size_t index;
 3243|       |
 3244|  1.05k|    LIBSPDM_ASSERT(spdm_context != NULL);
 3245|  1.05k|    LIBSPDM_ASSERT(secured_contexts != NULL);
 3246|  1.05k|    LIBSPDM_ASSERT(num_secured_contexts == LIBSPDM_MAX_SESSION_COUNT);
 3247|       |
 3248|  1.05k|    context = spdm_context;
 3249|  1.05k|    libspdm_zero_mem(context, sizeof(libspdm_context_t));
 3250|  1.05k|    context->version = LIBSPDM_CONTEXT_STRUCT_VERSION;
  ------------------
  |  |  527|  1.05k|#define LIBSPDM_CONTEXT_STRUCT_VERSION 0x3
  ------------------
 3251|  1.05k|    context->transcript.message_a.max_buffer_size =
 3252|  1.05k|        sizeof(context->transcript.message_a.buffer);
 3253|  1.05k|    context->transcript.message_d.max_buffer_size =
 3254|  1.05k|        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|  1.05k|    context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
 3272|  1.05k|    context->local_context.version.spdm_version_count = SPDM_MAX_VERSION_COUNT;
  ------------------
  |  |   17|  1.05k|#define SPDM_MAX_VERSION_COUNT 4
  ------------------
 3273|  1.05k|    context->local_context.version.spdm_version[0] = SPDM_MESSAGE_VERSION_10 <<
  ------------------
  |  |  110|  1.05k|#define SPDM_MESSAGE_VERSION_10 0x10
  ------------------
 3274|  1.05k|                                                     SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|  1.05k|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3275|  1.05k|    context->local_context.version.spdm_version[1] = SPDM_MESSAGE_VERSION_11 <<
  ------------------
  |  |  111|  1.05k|#define SPDM_MESSAGE_VERSION_11 0x11
  ------------------
 3276|  1.05k|                                                     SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|  1.05k|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3277|  1.05k|    context->local_context.version.spdm_version[2] = SPDM_MESSAGE_VERSION_12 <<
  ------------------
  |  |  112|  1.05k|#define SPDM_MESSAGE_VERSION_12 0x12
  ------------------
 3278|  1.05k|                                                     SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|  1.05k|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3279|  1.05k|    context->local_context.version.spdm_version[3] = SPDM_MESSAGE_VERSION_13 <<
  ------------------
  |  |  113|  1.05k|#define SPDM_MESSAGE_VERSION_13 0x13
  ------------------
 3280|  1.05k|                                                     SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|  1.05k|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3281|  1.05k|    context->local_context.secured_message_version.spdm_version_count =
 3282|  1.05k|        SECURED_SPDM_MAX_VERSION_COUNT;
  ------------------
  |  |   55|  1.05k|#define SECURED_SPDM_MAX_VERSION_COUNT 3
  ------------------
 3283|  1.05k|    context->local_context.secured_message_version.spdm_version[0] =
 3284|  1.05k|        SECURED_SPDM_VERSION_10 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |   57|  1.05k|#define SECURED_SPDM_VERSION_10 0x10
  ------------------
                      SECURED_SPDM_VERSION_10 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|  1.05k|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3285|  1.05k|    context->local_context.secured_message_version.spdm_version[1] =
 3286|  1.05k|        SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |   58|  1.05k|#define SECURED_SPDM_VERSION_11 0x11
  ------------------
                      SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|  1.05k|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3287|  1.05k|    context->local_context.secured_message_version.spdm_version[2] =
 3288|  1.05k|        SECURED_SPDM_VERSION_12 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |   59|  1.05k|#define SECURED_SPDM_VERSION_12 0x12
  ------------------
                      SECURED_SPDM_VERSION_12 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|  1.05k|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3289|  1.05k|    context->local_context.capability.st1 = SPDM_ST1_VALUE_US;
  ------------------
  |  | 1514|  1.05k|#define SPDM_ST1_VALUE_US 100000
  ------------------
 3290|       |
 3291|  1.05k|    context->mut_auth_cert_chain_buffer_size = 0;
 3292|       |
 3293|  1.05k|    context->max_spdm_session_sequence_number = LIBSPDM_MAX_SPDM_SESSION_SEQUENCE_NUMBER;
  ------------------
  |  |   39|  1.05k|#define LIBSPDM_MAX_SPDM_SESSION_SEQUENCE_NUMBER 0xFFFFFFFFFFFFFFFFull
  ------------------
 3294|       |
 3295|  1.05k|    context->latest_session_id = INVALID_SESSION_ID;
  ------------------
  |  |   28|  1.05k|#define INVALID_SESSION_ID 0
  ------------------
 3296|  1.05k|    context->last_spdm_request_session_id = INVALID_SESSION_ID;
  ------------------
  |  |   28|  1.05k|#define INVALID_SESSION_ID 0
  ------------------
 3297|  1.05k|    context->last_spdm_request_session_id_valid = false;
 3298|  1.05k|    context->last_spdm_request_size = 0;
 3299|       |
 3300|       |    /* To be updated in libspdm_register_device_buffer_func */
 3301|  1.05k|    context->local_context.capability.data_transfer_size = 0;
 3302|  1.05k|    context->local_context.capability.sender_data_transfer_size = 0;
 3303|  1.05k|    context->local_context.capability.max_spdm_msg_size = 0;
 3304|       |
 3305|  5.28k|    for (index = 0; index < num_secured_contexts; index++) {
  ------------------
  |  Branch (3305:21): [True: 4.22k, False: 1.05k]
  ------------------
 3306|  4.22k|        if (secured_contexts[index] == NULL) {
  ------------------
  |  Branch (3306:13): [True: 0, False: 4.22k]
  ------------------
 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|  4.22k|        context->session_info[index].secured_message_context = secured_contexts[index];
 3311|  4.22k|        libspdm_secured_message_init_context(
 3312|  4.22k|            context->session_info[index].secured_message_context);
 3313|  4.22k|    }
 3314|       |
 3315|  1.05k|    return LIBSPDM_STATUS_SUCCESS;
  ------------------
  |  |   59|  1.05k|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_SUCCESS, LIBSPDM_SOURCE_SUCCESS, 0x0000)
  |  |  ------------------
  |  |  |  |   55|  1.05k|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
 3316|  1.05k|}
libspdm_init_context:
 3331|  1.05k|{
 3332|  1.05k|    libspdm_context_t *context;
 3333|  1.05k|    void *secured_context;
 3334|  1.05k|    void *secured_contexts[LIBSPDM_MAX_SESSION_COUNT];
 3335|  1.05k|    size_t secured_context_size;
 3336|  1.05k|    size_t index;
 3337|       |
 3338|  1.05k|    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|  1.05k|    context = spdm_context;
 3343|  1.05k|    secured_context = (void *)((size_t)(context + 1));
 3344|  1.05k|    secured_context_size = libspdm_secured_message_get_context_size();
 3345|       |
 3346|  5.28k|    for (index = 0; index < LIBSPDM_MAX_SESSION_COUNT; index++)
  ------------------
  |  |  198|  5.28k|#define LIBSPDM_MAX_SESSION_COUNT 4
  ------------------
  |  Branch (3346:21): [True: 4.22k, False: 1.05k]
  ------------------
 3347|  4.22k|    {
 3348|  4.22k|        secured_contexts[index] = (uint8_t *)secured_context + secured_context_size * index;
 3349|  4.22k|    }
 3350|       |
 3351|  1.05k|    return libspdm_init_context_with_secured_context(spdm_context,
 3352|  1.05k|                                                     secured_contexts,
 3353|  1.05k|                                                     LIBSPDM_MAX_SESSION_COUNT);
  ------------------
  |  |  198|  1.05k|#define LIBSPDM_MAX_SESSION_COUNT 4
  ------------------
 3354|  1.05k|}
libspdm_get_context_size:
 3467|  1.05k|{
 3468|  1.05k|    size_t size;
 3469|       |
 3470|  1.05k|    size = sizeof(libspdm_context_t) +
 3471|  1.05k|           libspdm_secured_message_get_context_size() * LIBSPDM_MAX_SESSION_COUNT;
  ------------------
  |  |  198|  1.05k|#define LIBSPDM_MAX_SESSION_COUNT 4
  ------------------
 3472|  1.05k|    LIBSPDM_ASSERT (size == LIBSPDM_CONTEXT_SIZE_ALL);
 3473|  1.05k|    return size;
 3474|  1.05k|}

libspdm_generate_cert_chain_hash:
  702|      3|{
  703|      3|    LIBSPDM_ASSERT(slot_id < SPDM_MAX_SLOT_COUNT);
  704|      3|    return libspdm_hash_all(
  705|      3|        spdm_context->connection_info.algorithm.base_hash_algo,
  706|      3|        spdm_context->local_context.local_cert_chain_provision[slot_id],
  707|      3|        spdm_context->local_context.local_cert_chain_provision_size[slot_id], hash);
  708|      3|}
libspdm_get_cert_slot_mask:
  736|      3|{
  737|      3|    size_t index;
  738|      3|    uint8_t slot_mask;
  739|       |
  740|      3|    slot_mask = 0;
  741|     27|    for (index = 0; index < SPDM_MAX_SLOT_COUNT; index++) {
  ------------------
  |  |   18|     27|#define SPDM_MAX_SLOT_COUNT 8
  ------------------
  |  Branch (741:21): [True: 24, False: 3]
  ------------------
  742|     24|        if (spdm_context->local_context.local_cert_chain_provision[index] != NULL) {
  ------------------
  |  Branch (742:13): [True: 3, False: 21]
  ------------------
  743|      3|            slot_mask |= (1 << index);
  744|      3|        }
  745|     24|    }
  746|       |
  747|      3|    return slot_mask;
  748|      3|}
libspdm_generate_challenge_auth_signature:
  946|      3|{
  947|      3|    bool result;
  948|      3|    size_t signature_size;
  949|       |#if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
  950|       |    libspdm_m1m2_managed_buffer_t m1m2;
  951|       |    uint8_t *m1m2_buffer;
  952|       |    size_t m1m2_buffer_size;
  953|       |#else
  954|      3|    uint8_t m1m2_hash[LIBSPDM_MAX_HASH_SIZE];
  955|      3|    size_t m1m2_hash_size;
  956|      3|#endif
  957|       |
  958|       |#if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
  959|       |    result = libspdm_calculate_m1m2(spdm_context, is_requester, &m1m2);
  960|       |    m1m2_buffer = libspdm_get_managed_buffer(&m1m2);
  961|       |    m1m2_buffer_size = libspdm_get_managed_buffer_size(&m1m2);
  962|       |#else
  963|      3|    m1m2_hash_size = sizeof(m1m2_hash);
  964|      3|    result = libspdm_calculate_m1m2_hash(spdm_context, is_requester, &m1m2_hash_size, &m1m2_hash);
  965|      3|#endif
  966|      3|    if (is_requester) {
  ------------------
  |  Branch (966:9): [True: 0, False: 3]
  ------------------
  967|      0|        libspdm_reset_message_mut_b(spdm_context);
  968|      0|        libspdm_reset_message_mut_c(spdm_context);
  969|      3|    } else {
  970|      3|        libspdm_reset_message_b(spdm_context);
  971|      3|        libspdm_reset_message_c(spdm_context);
  972|      3|    }
  973|      3|    if (!result) {
  ------------------
  |  Branch (973:9): [True: 0, False: 3]
  ------------------
  974|      0|        return false;
  975|      0|    }
  976|       |
  977|      3|    if (is_requester) {
  ------------------
  |  Branch (977:9): [True: 0, False: 3]
  ------------------
  978|      0|#if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
  979|      0|        signature_size = libspdm_get_req_asym_signature_size(
  980|      0|            spdm_context->connection_info.algorithm.req_base_asym_alg);
  981|       |#if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
  982|       |        result = libspdm_requester_data_sign(
  983|       |#if LIBSPDM_HAL_PASS_SPDM_CONTEXT
  984|       |            spdm_context,
  985|       |#endif
  986|       |            spdm_context->connection_info.version, SPDM_CHALLENGE_AUTH,
  987|       |            spdm_context->connection_info.algorithm.req_base_asym_alg,
  988|       |            spdm_context->connection_info.algorithm.base_hash_algo,
  989|       |            false, m1m2_buffer, m1m2_buffer_size, signature, &signature_size);
  990|       |#else
  991|      0|        result = libspdm_requester_data_sign(
  992|       |#if LIBSPDM_HAL_PASS_SPDM_CONTEXT
  993|       |            spdm_context,
  994|       |#endif
  995|      0|            spdm_context->connection_info.version, SPDM_CHALLENGE_AUTH,
  ------------------
  |  |   31|      0|#define SPDM_CHALLENGE_AUTH 0x03
  ------------------
  996|      0|            spdm_context->connection_info.algorithm.req_base_asym_alg,
  997|      0|            spdm_context->connection_info.algorithm.base_hash_algo,
  998|      0|            true, m1m2_hash, m1m2_hash_size, signature, &signature_size);
  999|      0|#endif
 1000|       |#else /* LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP */
 1001|       |        result = false;
 1002|       |#endif /* LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP */
 1003|      3|    } else {
 1004|      3|        signature_size = libspdm_get_asym_signature_size(
 1005|      3|            spdm_context->connection_info.algorithm.base_asym_algo);
 1006|       |#if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
 1007|       |        result = libspdm_responder_data_sign(
 1008|       |#if LIBSPDM_HAL_PASS_SPDM_CONTEXT
 1009|       |            spdm_context,
 1010|       |#endif
 1011|       |            spdm_context->connection_info.version, SPDM_CHALLENGE_AUTH,
 1012|       |            spdm_context->connection_info.algorithm.base_asym_algo,
 1013|       |            spdm_context->connection_info.algorithm.base_hash_algo,
 1014|       |            false, m1m2_buffer, m1m2_buffer_size, signature,
 1015|       |            &signature_size);
 1016|       |#else
 1017|      3|        result = libspdm_responder_data_sign(
 1018|       |#if LIBSPDM_HAL_PASS_SPDM_CONTEXT
 1019|       |            spdm_context,
 1020|       |#endif
 1021|      3|            spdm_context->connection_info.version, SPDM_CHALLENGE_AUTH,
  ------------------
  |  |   31|      3|#define SPDM_CHALLENGE_AUTH 0x03
  ------------------
 1022|      3|            spdm_context->connection_info.algorithm.base_asym_algo,
 1023|      3|            spdm_context->connection_info.algorithm.base_hash_algo,
 1024|      3|            true, m1m2_hash, m1m2_hash_size, signature,
 1025|      3|            &signature_size);
 1026|      3|#endif
 1027|      3|    }
 1028|       |
 1029|      3|    return result;
 1030|      3|}
libspdm_get_measurement_summary_hash_size:
 1326|      3|{
 1327|      3|    if (!libspdm_is_capabilities_flag_supported(
  ------------------
  |  Branch (1327:9): [True: 2, False: 1]
  ------------------
 1328|      3|            spdm_context, is_requester, 0,
 1329|      3|            SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP)) {
  ------------------
  |  |  236|      3|#define SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP (0x00000008 | 0x00000010)
  ------------------
 1330|      2|        return 0;
 1331|      2|    }
 1332|       |
 1333|      1|    switch (measurement_summary_hash_type) {
 1334|      1|    case SPDM_REQUEST_NO_MEASUREMENT_SUMMARY_HASH:
  ------------------
  |  |  689|      1|#define SPDM_REQUEST_NO_MEASUREMENT_SUMMARY_HASH 0
  ------------------
  |  Branch (1334:5): [True: 1, False: 0]
  ------------------
 1335|      1|        return 0;
 1336|      0|        break;
 1337|       |
 1338|      0|    case SPDM_REQUEST_TCB_COMPONENT_MEASUREMENT_HASH:
  ------------------
  |  |  690|      0|#define SPDM_REQUEST_TCB_COMPONENT_MEASUREMENT_HASH 1
  ------------------
  |  Branch (1338:5): [True: 0, False: 1]
  ------------------
 1339|      0|    case SPDM_REQUEST_ALL_MEASUREMENTS_HASH:
  ------------------
  |  |  691|      0|#define SPDM_REQUEST_ALL_MEASUREMENTS_HASH 0xFF
  ------------------
  |  Branch (1339:5): [True: 0, False: 1]
  ------------------
 1340|      0|        return libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
 1341|      0|        break;
 1342|      0|    default:
  ------------------
  |  Branch (1342:5): [True: 0, False: 1]
  ------------------
 1343|      0|        return 0;
 1344|      0|        break;
 1345|      1|    }
 1346|      1|}
libspdm_com_crypto_service.c:libspdm_calculate_m1m2_hash:
  459|      3|{
  460|      3|    libspdm_context_t *spdm_context;
  461|      3|    uint32_t hash_size;
  462|      3|    bool result;
  463|       |
  464|      3|    spdm_context = context;
  465|       |
  466|      3|    hash_size = libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
  467|       |
  468|      3|    if (is_mut) {
  ------------------
  |  Branch (468:9): [True: 0, False: 3]
  ------------------
  469|      0|        result = libspdm_hash_final (spdm_context->connection_info.algorithm.base_hash_algo,
  470|      0|                                     spdm_context->transcript.digest_context_mut_m1m2, m1m2_hash);
  471|      0|        if (!result) {
  ------------------
  |  Branch (471:13): [True: 0, False: 0]
  ------------------
  472|      0|            return false;
  473|      0|        }
  474|      0|        LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m1m2 Mut hash - "));
  475|      0|        LIBSPDM_INTERNAL_DUMP_DATA(m1m2_hash, hash_size);
  476|      0|        LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
  477|       |
  478|      3|    } else {
  479|      3|        result = libspdm_hash_final (spdm_context->connection_info.algorithm.base_hash_algo,
  480|      3|                                     spdm_context->transcript.digest_context_m1m2, m1m2_hash);
  481|      3|        if (!result) {
  ------------------
  |  Branch (481:13): [True: 0, False: 3]
  ------------------
  482|      0|            return false;
  483|      0|        }
  484|      3|        LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m1m2 hash - "));
  485|      3|        LIBSPDM_INTERNAL_DUMP_DATA(m1m2_hash, hash_size);
  486|      3|        LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
  487|      3|    }
  488|       |
  489|      3|    *m1m2_hash_size = hash_size;
  490|       |
  491|      3|    return true;
  492|      3|}

libspdm_write_uint16:
  181|      3|{
  182|      3|    buffer[0] = (uint8_t)(value & 0xFF);
  183|      3|    buffer[1] = (uint8_t)((value >> 8) & 0xFF);
  184|      3|}
libspdm_get_managed_buffer_size:
  293|      3|{
  294|      3|    libspdm_managed_buffer_t *managed_buffer;
  295|       |
  296|      3|    managed_buffer = m_buffer;
  297|       |
  298|      3|    return managed_buffer->buffer_size;
  299|      3|}
libspdm_get_managed_buffer:
  302|      3|{
  303|      3|    libspdm_managed_buffer_t *managed_buffer;
  304|       |
  305|      3|    managed_buffer = m_buffer;
  306|       |
  307|      3|    return (managed_buffer + 1);
  308|      3|}

libspdm_get_asym_signature_size:
  180|      6|{
  181|      6|    switch (base_asym_algo) {
  182|      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 (182:5): [True: 0, False: 6]
  ------------------
  183|      0|#if LIBSPDM_RSA_SSA_2048_SUPPORT
  184|      0|        return 256;
  185|       |#else
  186|       |        return 0;
  187|       |#endif
  188|      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 (188:5): [True: 0, False: 6]
  ------------------
  189|      0|#if LIBSPDM_RSA_PSS_2048_SUPPORT
  190|      0|        return 256;
  191|       |#else
  192|       |        return 0;
  193|       |#endif
  194|      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 (194:5): [True: 0, False: 6]
  ------------------
  195|      0|#if LIBSPDM_RSA_SSA_3072_SUPPORT
  196|      0|        return 384;
  197|       |#else
  198|       |        return 0;
  199|       |#endif
  200|      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 (200:5): [True: 0, False: 6]
  ------------------
  201|      0|#if LIBSPDM_RSA_PSS_3072_SUPPORT
  202|      0|        return 384;
  203|       |#else
  204|       |        return 0;
  205|       |#endif
  206|      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 (206:5): [True: 0, False: 6]
  ------------------
  207|      0|#if LIBSPDM_RSA_SSA_4096_SUPPORT
  208|      0|        return 512;
  209|       |#else
  210|       |        return 0;
  211|       |#endif
  212|      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 (212:5): [True: 0, False: 6]
  ------------------
  213|      0|#if LIBSPDM_RSA_PSS_4096_SUPPORT
  214|      0|        return 512;
  215|       |#else
  216|       |        return 0;
  217|       |#endif
  218|      6|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
  ------------------
  |  |  375|      6|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256 0x00000010
  ------------------
  |  Branch (218:5): [True: 6, False: 0]
  ------------------
  219|      6|#if LIBSPDM_ECDSA_P256_SUPPORT
  220|      6|        return 32 * 2;
  221|       |#else
  222|       |        return 0;
  223|       |#endif
  224|      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 (224:5): [True: 0, False: 6]
  ------------------
  225|      0|#if LIBSPDM_ECDSA_P384_SUPPORT
  226|      0|        return 48 * 2;
  227|       |#else
  228|       |        return 0;
  229|       |#endif
  230|      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 (230:5): [True: 0, False: 6]
  ------------------
  231|      0|#if LIBSPDM_ECDSA_P521_SUPPORT
  232|      0|        return 66 * 2;
  233|       |#else
  234|       |        return 0;
  235|       |#endif
  236|      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 (236:5): [True: 0, False: 6]
  ------------------
  237|       |#if LIBSPDM_SM2_DSA_P256_SUPPORT
  238|       |        return 32 * 2;
  239|       |#else
  240|      0|        return 0;
  241|      0|#endif
  242|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
  ------------------
  |  |  385|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519 0x00000400
  ------------------
  |  Branch (242:5): [True: 0, False: 6]
  ------------------
  243|       |#if LIBSPDM_EDDSA_ED25519_SUPPORT
  244|       |        return 32 * 2;
  245|       |#else
  246|      0|        return 0;
  247|      0|#endif
  248|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
  ------------------
  |  |  386|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448 0x00000800
  ------------------
  |  Branch (248:5): [True: 0, False: 6]
  ------------------
  249|       |#if LIBSPDM_EDDSA_ED448_SUPPORT
  250|       |        return 57 * 2;
  251|       |#else
  252|      0|        return 0;
  253|      0|#endif
  254|      0|    default:
  ------------------
  |  Branch (254:5): [True: 0, False: 6]
  ------------------
  255|      0|        return 0;
  256|      6|    }
  257|      6|}
libspdm_asym_free:
  362|  1.05k|{
  363|  1.05k|    if (context == NULL) {
  ------------------
  |  Branch (363:9): [True: 0, False: 1.05k]
  ------------------
  364|      0|        return;
  365|      0|    }
  366|  1.05k|    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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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|  1.05k|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
  ------------------
  |  |  375|  1.05k|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256 0x00000010
  ------------------
  |  Branch (379:5): [True: 1.05k, False: 0]
  ------------------
  380|  1.05k|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
  ------------------
  |  |  378|  1.05k|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384 0x00000080
  ------------------
  |  Branch (380:5): [True: 0, False: 1.05k]
  ------------------
  381|  1.05k|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
  ------------------
  |  |  379|  1.05k|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521 0x00000100
  ------------------
  |  Branch (381:5): [True: 0, False: 1.05k]
  ------------------
  382|  1.05k|#if LIBSPDM_ECDSA_SUPPORT
  383|  1.05k|        libspdm_ec_free(context);
  384|       |#else
  385|       |        LIBSPDM_ASSERT(false);
  386|       |#endif
  387|  1.05k|        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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  404|      0|        LIBSPDM_ASSERT(false);
  405|      0|        break;
  406|  1.05k|    }
  407|  1.05k|}
libspdm_asym_sign_hash:
 1295|      3|{
 1296|      3|    bool need_hash;
 1297|      3|    uint8_t *message;
 1298|      3|    size_t message_size;
 1299|      3|    uint8_t full_message_hash[LIBSPDM_MAX_HASH_SIZE];
 1300|      3|    bool result;
 1301|      3|    size_t hash_nid;
 1302|      3|    uint8_t spdm12_signing_context_with_hash[SPDM_VERSION_1_2_SIGNING_CONTEXT_SIZE +
 1303|      3|                                             LIBSPDM_MAX_HASH_SIZE];
 1304|      3|    const void *param;
 1305|      3|    size_t param_size;
 1306|       |
 1307|      3|    hash_nid = libspdm_get_hash_nid(base_hash_algo);
 1308|      3|    need_hash = libspdm_asym_func_need_hash(base_asym_algo);
 1309|      3|    LIBSPDM_ASSERT (hash_size == libspdm_get_hash_size(base_hash_algo));
 1310|       |
 1311|      3|    param = NULL;
 1312|      3|    param_size = 0;
 1313|       |
 1314|      3|    if ((spdm_version >> SPDM_VERSION_NUMBER_SHIFT_BIT) > SPDM_MESSAGE_VERSION_11) {
  ------------------
  |  |  140|      3|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
                  if ((spdm_version >> SPDM_VERSION_NUMBER_SHIFT_BIT) > SPDM_MESSAGE_VERSION_11) {
  ------------------
  |  |  111|      3|#define SPDM_MESSAGE_VERSION_11 0x11
  ------------------
  |  Branch (1314:9): [True: 0, False: 3]
  ------------------
 1315|       |        /* Need use SPDM 1.2 signing */
 1316|      0|        switch (base_asym_algo) {
 1317|      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 (1317:9): [True: 0, False: 0]
  ------------------
 1318|      0|            param = "";
 1319|      0|            param_size = 0;
 1320|      0|            break;
 1321|      0|        case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
  ------------------
  |  |  385|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519 0x00000400
  ------------------
  |  Branch (1321:9): [True: 0, False: 0]
  ------------------
 1322|      0|            hash_nid = LIBSPDM_CRYPTO_NID_NULL;
  ------------------
  |  |   19|      0|#define LIBSPDM_CRYPTO_NID_NULL 0x0000
  ------------------
 1323|      0|            break;
 1324|      0|        case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
  ------------------
  |  |  386|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448 0x00000800
  ------------------
  |  Branch (1324:9): [True: 0, False: 0]
  ------------------
 1325|      0|            hash_nid = LIBSPDM_CRYPTO_NID_NULL;
  ------------------
  |  |   19|      0|#define LIBSPDM_CRYPTO_NID_NULL 0x0000
  ------------------
 1326|      0|            param = libspdm_get_signing_context_string (spdm_version, op_code, false, &param_size);
 1327|      0|            break;
 1328|      0|        default:
  ------------------
  |  Branch (1328:9): [True: 0, False: 0]
  ------------------
 1329|       |            /* pass thru for rest algorithm */
 1330|      0|            break;
 1331|      0|        }
 1332|       |
 1333|      0|        libspdm_create_signing_context (spdm_version, op_code, false,
 1334|      0|                                        spdm12_signing_context_with_hash);
 1335|      0|        libspdm_copy_mem(&spdm12_signing_context_with_hash[SPDM_VERSION_1_2_SIGNING_CONTEXT_SIZE],
  ------------------
  |  |  145|      0|#define SPDM_VERSION_1_2_SIGNING_CONTEXT_SIZE 100
  ------------------
 1336|      0|                         sizeof(spdm12_signing_context_with_hash)
 1337|      0|                         - (&spdm12_signing_context_with_hash[SPDM_VERSION_1_2_SIGNING_CONTEXT_SIZE]
  ------------------
  |  |  145|      0|#define SPDM_VERSION_1_2_SIGNING_CONTEXT_SIZE 100
  ------------------
 1338|      0|                            - spdm12_signing_context_with_hash),
 1339|      0|                         message_hash, hash_size);
 1340|       |
 1341|       |        /* assign message and message_size for signing */
 1342|      0|        message = spdm12_signing_context_with_hash;
 1343|      0|        message_size = SPDM_VERSION_1_2_SIGNING_CONTEXT_SIZE + hash_size;
  ------------------
  |  |  145|      0|#define SPDM_VERSION_1_2_SIGNING_CONTEXT_SIZE 100
  ------------------
 1344|       |
 1345|      0|        if (need_hash) {
  ------------------
  |  Branch (1345:13): [True: 0, False: 0]
  ------------------
 1346|      0|            result = libspdm_hash_all(base_hash_algo, message, message_size, full_message_hash);
 1347|      0|            if (!result) {
  ------------------
  |  Branch (1347:17): [True: 0, False: 0]
  ------------------
 1348|      0|                return false;
 1349|      0|            }
 1350|      0|            return libspdm_asym_sign_wrap(context, hash_nid, base_asym_algo,
 1351|      0|                                          param, param_size,
 1352|      0|                                          full_message_hash, hash_size,
 1353|      0|                                          signature, sig_size);
 1354|      0|        } else {
 1355|      0|            return libspdm_asym_sign_wrap(context, hash_nid, base_asym_algo,
 1356|      0|                                          param, param_size,
 1357|      0|                                          message, message_size,
 1358|      0|                                          signature, sig_size);
 1359|      0|        }
 1360|       |
 1361|       |        /* SPDM 1.2 signing done. */
 1362|      0|    }
 1363|       |
 1364|      3|    if (need_hash) {
  ------------------
  |  Branch (1364:9): [True: 3, False: 0]
  ------------------
 1365|      3|        return libspdm_asym_sign_wrap(context, hash_nid, base_asym_algo,
 1366|      3|                                      param, param_size,
 1367|      3|                                      message_hash, hash_size,
 1368|      3|                                      signature, sig_size);
 1369|      3|    } else {
 1370|      0|        LIBSPDM_ASSERT (false);
 1371|      0|        return false;
 1372|      0|    }
 1373|      3|}
libspdm_crypt_asym.c:libspdm_asym_func_need_hash:
  510|      3|{
  511|      3|    switch (base_asym_algo) {
  512|      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 (512:5): [True: 0, False: 3]
  ------------------
  513|      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 (513:5): [True: 0, False: 3]
  ------------------
  514|      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 (514:5): [True: 0, False: 3]
  ------------------
  515|      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 (515:5): [True: 0, False: 3]
  ------------------
  516|      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 (516:5): [True: 0, False: 3]
  ------------------
  517|      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 (517:5): [True: 0, False: 3]
  ------------------
  518|      0|        return true;
  519|      3|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
  ------------------
  |  |  375|      3|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256 0x00000010
  ------------------
  |  Branch (519:5): [True: 3, False: 0]
  ------------------
  520|      3|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
  ------------------
  |  |  378|      3|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384 0x00000080
  ------------------
  |  Branch (520:5): [True: 0, False: 3]
  ------------------
  521|      3|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
  ------------------
  |  |  379|      3|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521 0x00000100
  ------------------
  |  Branch (521:5): [True: 0, False: 3]
  ------------------
  522|      3|        return true;
  523|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
  ------------------
  |  |  385|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519 0x00000400
  ------------------
  |  Branch (523:5): [True: 0, False: 3]
  ------------------
  524|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
  ------------------
  |  |  386|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448 0x00000800
  ------------------
  |  Branch (524:5): [True: 0, False: 3]
  ------------------
  525|      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 (525:5): [True: 0, False: 3]
  ------------------
  526|      0|        return false;
  527|      0|    default:
  ------------------
  |  Branch (527:5): [True: 0, False: 3]
  ------------------
  528|      0|        LIBSPDM_ASSERT(false);
  529|      0|        break;
  530|      3|    }
  531|       |
  532|      0|    return false;
  533|      3|}
libspdm_crypt_asym.c:libspdm_asym_sign_wrap:
  263|      3|{
  264|      3|    switch (base_asym_algo) {
  265|      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 (265:5): [True: 0, False: 3]
  ------------------
  266|      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 (266:5): [True: 0, False: 3]
  ------------------
  267|      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 (267:5): [True: 0, False: 3]
  ------------------
  268|      0|#if LIBSPDM_RSA_SSA_SUPPORT
  269|       |#if !LIBSPDM_RSA_SSA_2048_SUPPORT
  270|       |        LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048);
  271|       |#endif
  272|       |#if !LIBSPDM_RSA_SSA_3072_SUPPORT
  273|       |        LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072);
  274|       |#endif
  275|       |#if !LIBSPDM_RSA_SSA_4096_SUPPORT
  276|       |        LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096);
  277|       |#endif
  278|      0|        return libspdm_rsa_pkcs1_sign_with_nid_wrap(context, hash_nid,
  279|      0|                                                    param, param_size,
  280|      0|                                                    message, message_size,
  281|      0|                                                    signature, sig_size);
  282|       |#else
  283|       |        LIBSPDM_ASSERT(false);
  284|       |        return false;
  285|       |#endif
  286|      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 (286:5): [True: 0, False: 3]
  ------------------
  287|      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 (287:5): [True: 0, False: 3]
  ------------------
  288|      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 (288:5): [True: 0, False: 3]
  ------------------
  289|      0|#if LIBSPDM_RSA_PSS_SUPPORT
  290|       |#if !LIBSPDM_RSA_PSS_2048_SUPPORT
  291|       |        LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048);
  292|       |#endif
  293|       |#if !LIBSPDM_RSA_PSS_3072_SUPPORT
  294|       |        LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072);
  295|       |#endif
  296|       |#if !LIBSPDM_RSA_PSS_4096_SUPPORT
  297|       |        LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096);
  298|       |#endif
  299|      0|        return libspdm_rsa_pss_sign_wrap(context, hash_nid,
  300|      0|                                         param, param_size,
  301|      0|                                         message, message_size,
  302|      0|                                         signature, sig_size);
  303|       |#else
  304|       |        LIBSPDM_ASSERT(false);
  305|       |        return false;
  306|       |#endif
  307|      3|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
  ------------------
  |  |  375|      3|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256 0x00000010
  ------------------
  |  Branch (307:5): [True: 3, False: 0]
  ------------------
  308|      3|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
  ------------------
  |  |  378|      3|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384 0x00000080
  ------------------
  |  Branch (308:5): [True: 0, False: 3]
  ------------------
  309|      3|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
  ------------------
  |  |  379|      3|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521 0x00000100
  ------------------
  |  Branch (309:5): [True: 0, False: 3]
  ------------------
  310|      3|#if LIBSPDM_ECDSA_SUPPORT
  311|       |#if !LIBSPDM_ECDSA_P256_SUPPORT
  312|       |        LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256);
  313|       |#endif
  314|       |#if !LIBSPDM_ECDSA_P384_SUPPORT
  315|       |        LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384);
  316|       |#endif
  317|       |#if !LIBSPDM_ECDSA_P521_SUPPORT
  318|       |        LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521);
  319|       |#endif
  320|      3|        return libspdm_ecdsa_sign_wrap(context, hash_nid,
  321|      3|                                       param, param_size,
  322|      3|                                       message, message_size,
  323|      3|                                       signature, sig_size);
  324|       |#else
  325|       |        LIBSPDM_ASSERT(false);
  326|       |        return false;
  327|       |#endif
  328|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
  ------------------
  |  |  385|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519 0x00000400
  ------------------
  |  Branch (328:5): [True: 0, False: 3]
  ------------------
  329|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
  ------------------
  |  |  386|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448 0x00000800
  ------------------
  |  Branch (329:5): [True: 0, False: 3]
  ------------------
  330|       |#if (LIBSPDM_EDDSA_ED25519_SUPPORT) || (LIBSPDM_EDDSA_ED448_SUPPORT)
  331|       |#if !LIBSPDM_EDDSA_ED25519_SUPPORT
  332|       |        LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519);
  333|       |#endif
  334|       |#if !LIBSPDM_EDDSA_ED448_SUPPORT
  335|       |        LIBSPDM_ASSERT(base_asym_algo!= SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448);
  336|       |#endif
  337|       |        return libspdm_eddsa_sign_wrap(context, hash_nid,
  338|       |                                       param, param_size,
  339|       |                                       message, message_size,
  340|       |                                       signature, sig_size);
  341|       |#else
  342|      0|        LIBSPDM_ASSERT(false);
  343|      0|        return false;
  344|      0|#endif
  345|      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 (345:5): [True: 0, False: 3]
  ------------------
  346|       |#if LIBSPDM_SM2_DSA_SUPPORT
  347|       |        return libspdm_sm2_dsa_sign_wrap(context, hash_nid,
  348|       |                                         param, param_size,
  349|       |                                         message, message_size,
  350|       |                                         signature, sig_size);
  351|       |#else
  352|      0|        LIBSPDM_ASSERT(false);
  353|      0|        return false;
  354|      0|#endif
  355|      0|    default:
  ------------------
  |  Branch (355:5): [True: 0, False: 3]
  ------------------
  356|      0|        LIBSPDM_ASSERT(false);
  357|      0|        return false;
  358|      3|    }
  359|      3|}
libspdm_crypt_asym.c:libspdm_ecdsa_sign_wrap:
   67|      3|{
   68|      3|    return libspdm_ecdsa_sign (context, hash_nid,
   69|      3|                               message, message_size, signature, sig_size);
   70|      3|}

libspdm_asym_get_public_key_from_x509:
  220|  1.05k|{
  221|  1.05k|    libspdm_asym_get_public_key_from_x509_func get_public_key_from_x509_function;
  222|  1.05k|    get_public_key_from_x509_function = libspdm_get_asym_get_public_key_from_x509(base_asym_algo);
  223|  1.05k|    if (get_public_key_from_x509_function == NULL) {
  ------------------
  |  Branch (223:9): [True: 0, False: 1.05k]
  ------------------
  224|      0|        return false;
  225|      0|    }
  226|  1.05k|    return get_public_key_from_x509_function(cert, cert_size, context);
  227|  1.05k|}
libspdm_x509_common_certificate_check:
 1071|  1.05k|{
 1072|  1.05k|    uint8_t end_cert_from[64];
 1073|  1.05k|    size_t end_cert_from_len;
 1074|  1.05k|    uint8_t end_cert_to[64];
 1075|  1.05k|    size_t end_cert_to_len;
 1076|  1.05k|    size_t asn1_buffer_len;
 1077|  1.05k|    bool status;
 1078|  1.05k|    size_t cert_version;
 1079|  1.05k|    void *context;
 1080|       |#if LIBSPDM_ADDITIONAL_CHECK_CERT
 1081|       |    size_t signature_algo_oid_size;
 1082|       |#endif /* LIBSPDM_ADDITIONAL_CHECK_CERT */
 1083|       |
 1084|  1.05k|    if (cert == NULL || cert_size == 0) {
  ------------------
  |  Branch (1084:9): [True: 0, False: 1.05k]
  |  Branch (1084:25): [True: 0, False: 1.05k]
  ------------------
 1085|      0|        return false;
 1086|      0|    }
 1087|       |
 1088|  1.05k|    status = true;
 1089|  1.05k|    context = NULL;
 1090|  1.05k|    end_cert_from_len = 64;
 1091|  1.05k|    end_cert_to_len = 64;
 1092|       |
 1093|       |    /* 1. version*/
 1094|  1.05k|    cert_version = 0;
 1095|  1.05k|    status = libspdm_x509_get_version(cert, cert_size, &cert_version);
 1096|  1.05k|    if (!status) {
  ------------------
  |  Branch (1096:9): [True: 0, False: 1.05k]
  ------------------
 1097|      0|        goto cleanup;
 1098|      0|    }
 1099|  1.05k|    if (cert_version != 2) {
  ------------------
  |  Branch (1099:9): [True: 0, False: 1.05k]
  ------------------
 1100|      0|        status = false;
 1101|      0|        goto cleanup;
 1102|      0|    }
 1103|       |
 1104|       |    /* 2. serial_number*/
 1105|  1.05k|    asn1_buffer_len = 0;
 1106|  1.05k|    status = libspdm_x509_get_serial_number(cert, cert_size, NULL, &asn1_buffer_len);
 1107|  1.05k|    if (asn1_buffer_len == 0) {
  ------------------
  |  Branch (1107:9): [True: 0, False: 1.05k]
  ------------------
 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|  1.05k|    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: 1.05k, False: 0]
  |  Branch (1134:22): [True: 0, False: 0]
  ------------------
 1135|  1.05k|        status = libspdm_verify_cert_subject_public_key_info(cert, cert_size, base_asym_algo);
 1136|  1.05k|        if (!status) {
  ------------------
  |  Branch (1136:13): [True: 0, False: 1.05k]
  ------------------
 1137|      0|            goto cleanup;
 1138|      0|        }
 1139|  1.05k|    }
 1140|       |
 1141|       |    /* 5. issuer_name*/
 1142|  1.05k|    asn1_buffer_len = 0;
 1143|  1.05k|    status = libspdm_x509_get_issuer_name(cert, cert_size, NULL, &asn1_buffer_len);
 1144|  1.05k|    if (status) {
  ------------------
  |  Branch (1144:9): [True: 0, False: 1.05k]
  ------------------
 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|  1.05k|    } else {
 1151|  1.05k|        if (asn1_buffer_len == 0) {
  ------------------
  |  Branch (1151:13): [True: 0, False: 1.05k]
  ------------------
 1152|      0|            status = false;
 1153|      0|            goto cleanup;
 1154|      0|        }
 1155|  1.05k|    }
 1156|       |
 1157|       |    /* 6. subject_name*/
 1158|  1.05k|    asn1_buffer_len = 0;
 1159|  1.05k|    status = libspdm_x509_get_subject_name(cert, cert_size, NULL, &asn1_buffer_len);
 1160|  1.05k|    if (status) {
  ------------------
  |  Branch (1160:9): [True: 0, False: 1.05k]
  ------------------
 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|  1.05k|    } else {
 1167|  1.05k|        if (asn1_buffer_len == 0) {
  ------------------
  |  Branch (1167:13): [True: 0, False: 1.05k]
  ------------------
 1168|      0|            status = false;
 1169|      0|            goto cleanup;
 1170|      0|        }
 1171|  1.05k|    }
 1172|       |
 1173|       |    /* 7. validity*/
 1174|  1.05k|    status = libspdm_x509_get_validity(cert, cert_size, end_cert_from,
 1175|  1.05k|                                       &end_cert_from_len, end_cert_to,
 1176|  1.05k|                                       &end_cert_to_len);
 1177|  1.05k|    if (status) {
  ------------------
  |  Branch (1177:9): [True: 1.05k, False: 0]
  ------------------
 1178|  1.05k|        if ((end_cert_from_len == 0) &&
  ------------------
  |  Branch (1178:13): [True: 0, False: 1.05k]
  ------------------
 1179|  1.05k|            (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|  1.05k|    } 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|  1.05k|    if (end_cert_from_len != 0) {
  ------------------
  |  Branch (1190:9): [True: 1.05k, False: 0]
  ------------------
 1191|  1.05k|        status = libspdm_internal_x509_date_time_check(
 1192|  1.05k|            end_cert_from, end_cert_from_len, end_cert_to, end_cert_to_len);
 1193|  1.05k|        if (!status) {
  ------------------
  |  Branch (1193:13): [True: 0, False: 1.05k]
  ------------------
 1194|      0|            goto cleanup;
 1195|      0|        }
 1196|  1.05k|    }
 1197|       |
 1198|       |    /* 8. subject_public_key*/
 1199|  1.05k|    status = libspdm_asym_get_public_key_from_x509(base_asym_algo, cert, cert_size, &context);
 1200|  1.05k|    if (!status) {
  ------------------
  |  Branch (1200:9): [True: 0, False: 1.05k]
  ------------------
 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|  1.05k|    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: 1.05k, False: 0]
  |  Branch (1208:22): [True: 0, False: 0]
  ------------------
 1209|  1.05k|        size_t value = 0;
 1210|       |
 1211|  1.05k|        status = libspdm_x509_get_key_usage(cert, cert_size, &value);
 1212|  1.05k|        if (!status) {
  ------------------
  |  Branch (1212:13): [True: 0, False: 1.05k]
  ------------------
 1213|      0|            goto cleanup;
 1214|  1.05k|        } else {
 1215|  1.05k|            if (value == 0) {
  ------------------
  |  Branch (1215:17): [True: 0, False: 1.05k]
  ------------------
 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|  1.05k|            } else {
 1221|  1.05k|                if ((LIBSPDM_CRYPTO_X509_KU_DIGITAL_SIGNATURE & value) == 0) {
  ------------------
  |  |   62|  1.05k|#define LIBSPDM_CRYPTO_X509_KU_DIGITAL_SIGNATURE 0x80
  ------------------
  |  Branch (1221:21): [True: 0, False: 1.05k]
  ------------------
 1222|      0|                    status = false;
 1223|      0|                    goto cleanup;
 1224|      0|                }
 1225|  1.05k|            }
 1226|  1.05k|        }
 1227|  1.05k|    }
 1228|       |
 1229|       |    /* 10. verify spdm defined extended key usage*/
 1230|  1.05k|    status = libspdm_verify_leaf_cert_spdm_eku(cert, cert_size, is_requester_cert);
 1231|  1.05k|    if (!status) {
  ------------------
  |  Branch (1231:9): [True: 0, False: 1.05k]
  ------------------
 1232|      0|        goto cleanup;
 1233|      0|    }
 1234|       |
 1235|  1.05k|    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: 1.05k, False: 0]
  |  Branch (1235:24): [True: 0, False: 0]
  ------------------
 1236|       |        /* 11. verify spdm defined extension*/
 1237|  1.05k|        status = libspdm_verify_leaf_cert_spdm_extension(cert, cert_size,
 1238|  1.05k|                                                         is_requester_cert, cert_model);
 1239|  1.05k|        if (!status) {
  ------------------
  |  Branch (1239:13): [True: 0, False: 1.05k]
  ------------------
 1240|      0|            goto cleanup;
 1241|      0|        }
 1242|  1.05k|    }
 1243|       |
 1244|  1.05k|cleanup:
 1245|  1.05k|    libspdm_asym_free(base_asym_algo, context);
 1246|  1.05k|    return status;
 1247|  1.05k|}
libspdm_x509_certificate_check:
 1268|  1.05k|{
 1269|  1.05k|    bool status;
 1270|  1.05k|    uint8_t cert_model;
 1271|       |
 1272|  1.05k|    if (is_device_cert_model) {
  ------------------
  |  Branch (1272:9): [True: 1.05k, False: 0]
  ------------------
 1273|  1.05k|        cert_model = SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT;
  ------------------
  |  |  598|  1.05k|#define SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT 0x1
  ------------------
 1274|  1.05k|    } 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|  1.05k|    status = libspdm_x509_common_certificate_check(cert, cert_size, base_asym_algo,
 1279|  1.05k|                                                   base_hash_algo, is_requester,
 1280|  1.05k|                                                   cert_model, false);
 1281|  1.05k|    if (!status) {
  ------------------
  |  Branch (1281:9): [True: 0, False: 1.05k]
  ------------------
 1282|      0|        return false;
 1283|      0|    }
 1284|       |
 1285|       |    /* verify basic constraints: the leaf cert always is ca:false in get_cert*/
 1286|  1.05k|    status = libspdm_verify_leaf_cert_basic_constraints(cert, cert_size, false);
 1287|  1.05k|    return status;
 1288|  1.05k|}
libspdm_verify_cert_chain_data:
 1669|  1.05k|{
 1670|  1.05k|    const uint8_t *root_cert_buffer;
 1671|  1.05k|    size_t root_cert_buffer_size;
 1672|  1.05k|    const uint8_t *leaf_cert_buffer;
 1673|  1.05k|    size_t leaf_cert_buffer_size;
 1674|       |
 1675|  1.05k|    if (cert_chain_data_size >
  ------------------
  |  Branch (1675:9): [True: 0, False: 1.05k]
  ------------------
 1676|  1.05k|        0xFFFF - (sizeof(spdm_cert_chain_t) + LIBSPDM_MAX_HASH_SIZE)) {
  ------------------
  |  |   65|  1.05k|#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|  1.05k|    if (!libspdm_x509_get_cert_from_cert_chain(
  ------------------
  |  Branch (1682:9): [True: 0, False: 1.05k]
  ------------------
 1683|  1.05k|            cert_chain_data, cert_chain_data_size, 0, &root_cert_buffer,
 1684|  1.05k|            &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|  1.05k|    if (!libspdm_x509_verify_cert_chain(root_cert_buffer, root_cert_buffer_size,
  ------------------
  |  Branch (1690:9): [True: 0, False: 1.05k]
  ------------------
 1691|  1.05k|                                        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|  1.05k|    if (!libspdm_x509_get_cert_from_cert_chain(
  ------------------
  |  Branch (1697:9): [True: 0, False: 1.05k]
  ------------------
 1698|  1.05k|            cert_chain_data, cert_chain_data_size, -1,
 1699|  1.05k|            &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|  1.05k|    if (!libspdm_x509_certificate_check(leaf_cert_buffer, leaf_cert_buffer_size,
  ------------------
  |  Branch (1705:9): [True: 0, False: 1.05k]
  ------------------
 1706|  1.05k|                                        base_asym_algo, base_hash_algo,
 1707|  1.05k|                                        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|  1.05k|    return true;
 1714|  1.05k|}
libspdm_crypt_cert.c:libspdm_get_asym_get_public_key_from_x509:
  124|  1.05k|{
  125|  1.05k|    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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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|  1.05k|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
  ------------------
  |  |  375|  1.05k|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256 0x00000010
  ------------------
  |  Branch (156:5): [True: 1.05k, False: 0]
  ------------------
  157|  1.05k|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
  ------------------
  |  |  378|  1.05k|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384 0x00000080
  ------------------
  |  Branch (157:5): [True: 0, False: 1.05k]
  ------------------
  158|  1.05k|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
  ------------------
  |  |  379|  1.05k|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521 0x00000100
  ------------------
  |  Branch (158:5): [True: 0, False: 1.05k]
  ------------------
  159|  1.05k|#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|  1.05k|        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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  196|      0|        LIBSPDM_ASSERT(false);
  197|      0|        break;
  198|  1.05k|    }
  199|       |
  200|      0|    return NULL;
  201|  1.05k|}
libspdm_crypt_cert.c:libspdm_verify_cert_subject_public_key_info:
  693|  1.05k|{
  694|  1.05k|    size_t oid_len;
  695|  1.05k|    bool status;
  696|       |
  697|       |    /*public key encrypt algo OID from cert*/
  698|  1.05k|    uint8_t cert_public_key_crypt_algo_oid[LIBSPDM_MAX_ENCRYPTION_ALGO_OID_LEN];
  699|       |    /*public key encrypt algo OID from libspdm stored*/
  700|  1.05k|    uint8_t libspdm_public_key_crypt_algo_oid[LIBSPDM_MAX_ENCRYPTION_ALGO_OID_LEN];
  701|  1.05k|    uint8_t libspdm_public_key_crypt_algo_oid_other[LIBSPDM_MAX_ENCRYPTION_ALGO_OID_LEN];
  702|       |
  703|  1.05k|    libspdm_zero_mem(libspdm_public_key_crypt_algo_oid, LIBSPDM_MAX_ENCRYPTION_ALGO_OID_LEN);
  ------------------
  |  |   32|  1.05k|#define LIBSPDM_MAX_ENCRYPTION_ALGO_OID_LEN 10
  ------------------
  704|  1.05k|    libspdm_zero_mem(libspdm_public_key_crypt_algo_oid_other, LIBSPDM_MAX_ENCRYPTION_ALGO_OID_LEN);
  ------------------
  |  |   32|  1.05k|#define LIBSPDM_MAX_ENCRYPTION_ALGO_OID_LEN 10
  ------------------
  705|       |
  706|       |    /*work around: skip the sm2*/
  707|  1.05k|    if (base_asym_algo == SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256) {
  ------------------
  |  |  384|  1.05k|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256 0x00000200
  ------------------
  |  Branch (707:9): [True: 0, False: 1.05k]
  ------------------
  708|      0|        return true;
  709|      0|    }
  710|       |
  711|  1.05k|    oid_len = libspdm_get_public_key_algo_OID_len(base_asym_algo);
  712|  1.05k|    if(oid_len == 0) {
  ------------------
  |  Branch (712:8): [True: 0, False: 1.05k]
  ------------------
  713|      0|        return false;
  714|      0|    }
  715|       |    /*get public key encrypt algo OID from libspdm stored*/
  716|  1.05k|    status = libspdm_get_public_key_algo_OID(base_asym_algo,
  717|  1.05k|                                             libspdm_public_key_crypt_algo_oid,
  718|  1.05k|                                             libspdm_public_key_crypt_algo_oid_other);
  719|  1.05k|    if (!status) {
  ------------------
  |  Branch (719:9): [True: 0, False: 1.05k]
  ------------------
  720|      0|        return status;
  721|      0|    }
  722|       |
  723|       |    /*get public key encrypt algo OID from cert*/
  724|  1.05k|    status = libspdm_get_public_key_oid(cert, cert_size, cert_public_key_crypt_algo_oid, oid_len,
  725|  1.05k|                                        base_asym_algo);
  726|  1.05k|    if (!status || (!libspdm_consttime_is_mem_equal(cert_public_key_crypt_algo_oid,
  ------------------
  |  Branch (726:9): [True: 0, False: 1.05k]
  |  Branch (726:21): [True: 0, False: 1.05k]
  ------------------
  727|  1.05k|                                                    libspdm_public_key_crypt_algo_oid, oid_len) &&
  728|  1.05k|                    !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|  1.05k|    return status;
  735|  1.05k|}
libspdm_crypt_cert.c:libspdm_get_public_key_algo_OID_len:
  329|  2.11k|{
  330|  2.11k|    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: 2.11k]
  ------------------
  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: 2.11k]
  ------------------
  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: 2.11k]
  ------------------
  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: 2.11k]
  ------------------
  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: 2.11k]
  ------------------
  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: 2.11k]
  ------------------
  362|      0|#if LIBSPDM_RSA_PSS_4096_SUPPORT
  363|      0|        return 4;
  364|       |#else
  365|       |        return 0;
  366|       |#endif
  367|  2.11k|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
  ------------------
  |  |  375|  2.11k|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256 0x00000010
  ------------------
  |  Branch (367:5): [True: 2.11k, False: 0]
  ------------------
  368|  2.11k|#if LIBSPDM_ECDSA_P256_SUPPORT
  369|  2.11k|        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: 2.11k]
  ------------------
  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: 2.11k]
  ------------------
  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: 2.11k]
  ------------------
  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: 2.11k]
  ------------------
  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: 2.11k]
  ------------------
  398|      0|        LIBSPDM_ASSERT(false);
  399|      0|        return 0;
  400|  2.11k|    }
  401|  2.11k|}
libspdm_crypt_cert.c:libspdm_get_public_key_algo_OID:
  416|  1.05k|{
  417|  1.05k|    uint32_t oid_len;
  418|  1.05k|    oid_len = libspdm_get_public_key_algo_OID_len(base_asym_algo);
  419|  1.05k|    if(oid_len == 0) {
  ------------------
  |  Branch (419:8): [True: 0, False: 1.05k]
  ------------------
  420|      0|        return false;
  421|      0|    }
  422|       |
  423|  1.05k|    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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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|  1.05k|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256: {
  ------------------
  |  |  375|  1.05k|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256 0x00000010
  ------------------
  |  Branch (461:5): [True: 1.05k, False: 0]
  ------------------
  462|  1.05k|#if LIBSPDM_ECDSA_P256_SUPPORT
  463|  1.05k|        uint8_t encry_algo_oid_ecc256[] = KEY_ENCRY_ALGO_ECC256_OID;
  ------------------
  |  |   70|  1.05k|#define KEY_ENCRY_ALGO_ECC256_OID {0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07}
  ------------------
  464|  1.05k|        libspdm_copy_mem(oid, oid_len, encry_algo_oid_ecc256, oid_len);
  465|  1.05k|        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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  515|      0|        LIBSPDM_ASSERT(false);
  516|      0|        return false;
  517|  1.05k|    }
  518|  1.05k|}
libspdm_crypt_cert.c:libspdm_get_public_key_oid:
  534|  1.05k|{
  535|  1.05k|    bool ret;
  536|  1.05k|    uint8_t *ptr;
  537|  1.05k|    int32_t length;
  538|  1.05k|    size_t obj_len;
  539|  1.05k|    uint8_t *end;
  540|  1.05k|    uint8_t index;
  541|  1.05k|    uint8_t sequence_time;
  542|       |
  543|  1.05k|    length = (int32_t)cert_size;
  544|  1.05k|    ptr = (uint8_t*)(size_t)cert;
  545|  1.05k|    obj_len = 0;
  546|  1.05k|    end = ptr + length;
  547|  1.05k|    ret = true;
  548|       |
  549|       |    /* TBSCertificate have 5 sequence before subjectPublicKeyInfo*/
  550|  1.05k|    sequence_time = 5;
  551|       |
  552|       |    /*all cert sequence*/
  553|  1.05k|    ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
  554|  1.05k|                               LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   80|  1.05k|#define LIBSPDM_CRYPTO_ASN1_SEQUENCE 0x10
  ------------------
                                             LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   90|  1.05k|#define LIBSPDM_CRYPTO_ASN1_CONSTRUCTED 0x20
  ------------------
  555|  1.05k|    if (!ret) {
  ------------------
  |  Branch (555:9): [True: 0, False: 1.05k]
  ------------------
  556|      0|        return false;
  557|      0|    }
  558|       |
  559|       |    /*TBSCertificate sequence*/
  560|  1.05k|    ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
  561|  1.05k|                               LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   80|  1.05k|#define LIBSPDM_CRYPTO_ASN1_SEQUENCE 0x10
  ------------------
                                             LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   90|  1.05k|#define LIBSPDM_CRYPTO_ASN1_CONSTRUCTED 0x20
  ------------------
  562|  1.05k|    if (!ret) {
  ------------------
  |  Branch (562:9): [True: 0, False: 1.05k]
  ------------------
  563|      0|        return false;
  564|      0|    }
  565|       |
  566|  1.05k|    end = ptr + obj_len;
  567|       |    /*version*/
  568|  1.05k|    ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
  569|  1.05k|                               LIBSPDM_CRYPTO_ASN1_CONTEXT_SPECIFIC |
  ------------------
  |  |   91|  1.05k|#define LIBSPDM_CRYPTO_ASN1_CONTEXT_SPECIFIC 0x80
  ------------------
  570|  1.05k|                               LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   90|  1.05k|#define LIBSPDM_CRYPTO_ASN1_CONSTRUCTED 0x20
  ------------------
  571|  1.05k|    if (!ret) {
  ------------------
  |  Branch (571:9): [True: 0, False: 1.05k]
  ------------------
  572|      0|        return false;
  573|      0|    }
  574|       |
  575|  1.05k|    ptr += obj_len;
  576|       |    /*serialNumber*/
  577|  1.05k|    ret = libspdm_asn1_get_tag(&ptr, end, &obj_len, LIBSPDM_CRYPTO_ASN1_INTEGER);
  ------------------
  |  |   74|  1.05k|#define LIBSPDM_CRYPTO_ASN1_INTEGER 0x02
  ------------------
  578|  1.05k|    if (!ret) {
  ------------------
  |  Branch (578:9): [True: 0, False: 1.05k]
  ------------------
  579|      0|        return false;
  580|      0|    }
  581|       |
  582|       |    /**
  583|       |     * signature AlgorithmIdentifier,
  584|       |     * issuer Name,
  585|       |     * validity Validity,
  586|       |     * subject Name,
  587|       |     * subjectPublicKeyInfo
  588|       |     **/
  589|  6.33k|    for (index = 0; index < sequence_time; index++) {
  ------------------
  |  Branch (589:21): [True: 5.28k, False: 1.05k]
  ------------------
  590|  5.28k|        ptr += obj_len;
  591|  5.28k|        ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
  592|  5.28k|                                   LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   80|  5.28k|#define LIBSPDM_CRYPTO_ASN1_SEQUENCE 0x10
  ------------------
                                                 LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   90|  5.28k|#define LIBSPDM_CRYPTO_ASN1_CONSTRUCTED 0x20
  ------------------
  593|  5.28k|        if (!ret) {
  ------------------
  |  Branch (593:13): [True: 0, False: 5.28k]
  ------------------
  594|      0|            return false;
  595|      0|        }
  596|  5.28k|    }
  597|       |
  598|  1.05k|    switch (base_asym_algo)
  599|  1.05k|    {
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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|  1.05k|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
  ------------------
  |  |  375|  1.05k|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256 0x00000010
  ------------------
  |  Branch (627:5): [True: 1.05k, False: 0]
  ------------------
  628|  1.05k|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
  ------------------
  |  |  378|  1.05k|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384 0x00000080
  ------------------
  |  Branch (628:5): [True: 0, False: 1.05k]
  ------------------
  629|  1.05k|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
  ------------------
  |  |  379|  1.05k|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521 0x00000100
  ------------------
  |  Branch (629:5): [True: 0, False: 1.05k]
  ------------------
  630|  1.05k|        ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
  631|  1.05k|                                   LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   80|  1.05k|#define LIBSPDM_CRYPTO_ASN1_SEQUENCE 0x10
  ------------------
                                                 LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   90|  1.05k|#define LIBSPDM_CRYPTO_ASN1_CONSTRUCTED 0x20
  ------------------
  632|  1.05k|        if (!ret) {
  ------------------
  |  Branch (632:13): [True: 0, False: 1.05k]
  ------------------
  633|      0|            return false;
  634|      0|        }
  635|  1.05k|        ret = libspdm_asn1_get_tag(&ptr, end, &obj_len, LIBSPDM_CRYPTO_ASN1_OID);
  ------------------
  |  |   78|  1.05k|#define LIBSPDM_CRYPTO_ASN1_OID 0x06
  ------------------
  636|  1.05k|        if (!ret) {
  ------------------
  |  Branch (636:13): [True: 0, False: 1.05k]
  ------------------
  637|      0|            return false;
  638|      0|        }
  639|       |
  640|       |        /*get ecc second oid*/
  641|  1.05k|        ptr +=obj_len;
  642|  1.05k|        ret = libspdm_asn1_get_tag(&ptr, end, &obj_len, LIBSPDM_CRYPTO_ASN1_OID);
  ------------------
  |  |   78|  1.05k|#define LIBSPDM_CRYPTO_ASN1_OID 0x06
  ------------------
  643|  1.05k|        if (!ret) {
  ------------------
  |  Branch (643:13): [True: 0, False: 1.05k]
  ------------------
  644|      0|            return false;
  645|      0|        }
  646|       |
  647|  1.05k|        if (oid_size != obj_len) {
  ------------------
  |  Branch (647:13): [True: 0, False: 1.05k]
  ------------------
  648|      0|            return false;
  649|      0|        }
  650|       |
  651|  1.05k|        libspdm_copy_mem(oid, oid_size, ptr, obj_len);
  652|  1.05k|        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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  674|      0|        LIBSPDM_ASSERT(false);
  675|      0|        return false;
  676|  1.05k|    }
  677|       |
  678|  1.05k|    return true;
  679|  1.05k|}
libspdm_crypt_cert.c:libspdm_internal_x509_date_time_check:
  285|  1.05k|{
  286|  1.05k|    int32_t ret;
  287|  1.05k|    bool status;
  288|  1.05k|    uint8_t f0[64];
  289|  1.05k|    uint8_t t0[64];
  290|  1.05k|    size_t f0_size;
  291|  1.05k|    size_t t0_size;
  292|       |
  293|  1.05k|    f0_size = 64;
  294|  1.05k|    t0_size = 64;
  295|       |
  296|  1.05k|    status = libspdm_x509_set_date_time("19700101000000Z", f0, &f0_size);
  297|  1.05k|    if (!status) {
  ------------------
  |  Branch (297:9): [True: 0, False: 1.05k]
  ------------------
  298|      0|        return false;
  299|      0|    }
  300|       |
  301|  1.05k|    status = libspdm_x509_set_date_time("99991231235959Z", t0, &t0_size);
  302|  1.05k|    if (!status) {
  ------------------
  |  Branch (302:9): [True: 0, False: 1.05k]
  ------------------
  303|      0|        return false;
  304|      0|    }
  305|       |
  306|       |    /* from >= f0*/
  307|  1.05k|    ret = libspdm_x509_compare_date_time(from, f0);
  308|  1.05k|    if (ret < 0) {
  ------------------
  |  Branch (308:9): [True: 0, False: 1.05k]
  ------------------
  309|      0|        return false;
  310|      0|    }
  311|       |
  312|       |    /* to <= t0*/
  313|  1.05k|    ret = libspdm_x509_compare_date_time(t0, to);
  314|  1.05k|    if (ret < 0) {
  ------------------
  |  Branch (314:9): [True: 0, False: 1.05k]
  ------------------
  315|      0|        return false;
  316|      0|    }
  317|       |
  318|  1.05k|    return true;
  319|  1.05k|}
libspdm_crypt_cert.c:libspdm_verify_leaf_cert_spdm_eku:
  887|  1.05k|{
  888|  1.05k|    bool status;
  889|  1.05k|    uint8_t eku[256];
  890|  1.05k|    size_t eku_size;
  891|  1.05k|    bool req_auth_oid_find_success;
  892|  1.05k|    bool rsp_auth_oid_find_success;
  893|  1.05k|    uint8_t *ptr;
  894|  1.05k|    size_t obj_len;
  895|       |
  896|       |    /* SPDM defined OID */
  897|  1.05k|    uint8_t eku_requester_auth_oid[] = SPDM_OID_DMTF_EKU_REQUESTER_AUTH;
  ------------------
  |  | 1533|  1.05k|    { /*0x06, 0x0A,*/ 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1C, 0x82, 0x12, 0x04 }
  ------------------
  898|  1.05k|    uint8_t eku_responder_auth_oid[] = SPDM_OID_DMTF_EKU_RESPONDER_AUTH;
  ------------------
  |  | 1530|  1.05k|    { /*0x06, 0x0A,*/ 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1C, 0x82, 0x12, 0x03 }
  ------------------
  899|       |
  900|  1.05k|    eku_size = sizeof(eku);
  901|  1.05k|    status = libspdm_x509_get_extended_key_usage(cert, cert_size, eku, &eku_size);
  902|  1.05k|    if (!status) {
  ------------------
  |  Branch (902:9): [True: 0, False: 1.05k]
  ------------------
  903|      0|        return false;
  904|  1.05k|    } else if (eku_size == 0) {
  ------------------
  |  Branch (904:16): [True: 0, False: 1.05k]
  ------------------
  905|       |        /* eku is not present in cert */
  906|      0|        return true;
  907|      0|    }
  908|       |
  909|  1.05k|    ptr = eku;
  910|  1.05k|    obj_len = 0;
  911|  1.05k|    req_auth_oid_find_success = false;
  912|  1.05k|    rsp_auth_oid_find_success = false;
  913|       |
  914|  1.05k|    status = libspdm_asn1_get_tag(&ptr, eku + eku_size, &obj_len,
  915|  1.05k|                                  LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   80|  1.05k|#define LIBSPDM_CRYPTO_ASN1_SEQUENCE 0x10
  ------------------
                                                LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   90|  1.05k|#define LIBSPDM_CRYPTO_ASN1_CONSTRUCTED 0x20
  ------------------
  916|  1.05k|    if (!status) {
  ------------------
  |  Branch (916:9): [True: 0, False: 1.05k]
  ------------------
  917|      0|        return false;
  918|      0|    }
  919|       |
  920|  4.22k|    while(ptr < eku + eku_size) {
  ------------------
  |  Branch (920:11): [True: 3.16k, False: 1.05k]
  ------------------
  921|  3.16k|        status = libspdm_asn1_get_tag(&ptr, eku + eku_size, &obj_len, LIBSPDM_CRYPTO_ASN1_OID);
  ------------------
  |  |   78|  3.16k|#define LIBSPDM_CRYPTO_ASN1_OID 0x06
  ------------------
  922|  3.16k|        if (!status) {
  ------------------
  |  Branch (922:13): [True: 0, False: 3.16k]
  ------------------
  923|      0|            return false;
  924|      0|        }
  925|       |
  926|  3.16k|        if ((obj_len == sizeof(eku_requester_auth_oid)) &&
  ------------------
  |  Branch (926:13): [True: 0, False: 3.16k]
  ------------------
  927|  3.16k|            (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|  3.16k|        if ((obj_len == sizeof(eku_responder_auth_oid)) &&
  ------------------
  |  Branch (931:13): [True: 0, False: 3.16k]
  ------------------
  932|  3.16k|            (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|  3.16k|        ptr += obj_len;
  938|  3.16k|    }
  939|       |
  940|  1.05k|    if (ptr != eku + eku_size) {
  ------------------
  |  Branch (940:9): [True: 0, False: 1.05k]
  ------------------
  941|      0|        return false;
  942|      0|    }
  943|       |
  944|  1.05k|    if (is_requester_cert) {
  ------------------
  |  Branch (944:9): [True: 0, False: 1.05k]
  ------------------
  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|  1.05k|    } else {
  950|       |        /* it should not only contain requester auth oid */
  951|  1.05k|        if (req_auth_oid_find_success && !rsp_auth_oid_find_success) {
  ------------------
  |  Branch (951:13): [True: 0, False: 1.05k]
  |  Branch (951:42): [True: 0, False: 0]
  ------------------
  952|      0|            return false;
  953|      0|        }
  954|  1.05k|    }
  955|       |
  956|  1.05k|    return true;
  957|  1.05k|}
libspdm_crypt_cert.c:libspdm_verify_leaf_cert_spdm_extension:
  973|  1.05k|{
  974|  1.05k|    bool status;
  975|  1.05k|    bool find_sucessful;
  976|  1.05k|    uint8_t spdm_extension[LIBSPDM_MAX_EXTENSION_LEN];
  977|  1.05k|    size_t len;
  978|  1.05k|    uint8_t *ptr;
  979|  1.05k|    uint8_t *temptr;
  980|  1.05k|    size_t obj_len;
  981|       |
  982|       |    /* SPDM defined OID */
  983|  1.05k|    uint8_t oid_spdm_extension[] = SPDM_OID_DMTF_SPDM_EXTENSION;
  ------------------
  |  | 1539|  1.05k|    { /*0x06, 0x0A,*/ 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1C, 0x82, 0x12, 0x06 }
  ------------------
  984|  1.05k|    uint8_t hardware_identity_oid[] = SPDM_OID_DMTF_HARDWARE_IDENTITY;
  ------------------
  |  | 1527|  1.05k|    { /*0x06, 0x0A,*/ 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1C, 0x82, 0x12, 0x02 }
  ------------------
  985|       |
  986|  1.05k|    len = LIBSPDM_MAX_EXTENSION_LEN;
  ------------------
  |  |   23|  1.05k|#define LIBSPDM_MAX_EXTENSION_LEN 30
  ------------------
  987|       |
  988|  1.05k|    if (cert == NULL || cert_size == 0) {
  ------------------
  |  Branch (988:9): [True: 0, False: 1.05k]
  |  Branch (988:25): [True: 0, False: 1.05k]
  ------------------
  989|      0|        return false;
  990|      0|    }
  991|       |
  992|  1.05k|    status = libspdm_x509_get_extension_data(cert, cert_size,
  993|  1.05k|                                             (const uint8_t *)oid_spdm_extension,
  994|  1.05k|                                             sizeof(oid_spdm_extension),
  995|  1.05k|                                             spdm_extension,
  996|  1.05k|                                             &len);
  997|  1.05k|    if (!status) {
  ------------------
  |  Branch (997:9): [True: 0, False: 1.05k]
  ------------------
  998|      0|        return false;
  999|  1.05k|    } else if(len == 0) {
  ------------------
  |  Branch (999:15): [True: 0, False: 1.05k]
  ------------------
 1000|      0|        return true;
 1001|      0|    }
 1002|       |
 1003|       |    /*find the spdm hardware identity OID*/
 1004|  1.05k|    find_sucessful = false;
 1005|  1.05k|    ptr = spdm_extension;
 1006|  1.05k|    obj_len = 0;
 1007|       |
 1008|       |    /*id-spdm-cert-oids ::= SEQUENCE SIZE (1..MAX) OF id-spdm-cert-oid*/
 1009|  1.05k|    status = libspdm_asn1_get_tag(
 1010|  1.05k|        &ptr, spdm_extension + len, &obj_len,
 1011|  1.05k|        LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   80|  1.05k|#define LIBSPDM_CRYPTO_ASN1_SEQUENCE 0x10
  ------------------
                      LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   90|  1.05k|#define LIBSPDM_CRYPTO_ASN1_CONSTRUCTED 0x20
  ------------------
 1012|  1.05k|    if (!status) {
  ------------------
  |  Branch (1012:9): [True: 0, False: 1.05k]
  ------------------
 1013|      0|        return false;
 1014|      0|    }
 1015|       |
 1016|  2.11k|    while(ptr < spdm_extension + len) {
  ------------------
  |  Branch (1016:11): [True: 1.05k, False: 1.05k]
  ------------------
 1017|  1.05k|        status = libspdm_asn1_get_tag(
 1018|  1.05k|            &ptr, spdm_extension + len, &obj_len,
 1019|  1.05k|            LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   80|  1.05k|#define LIBSPDM_CRYPTO_ASN1_SEQUENCE 0x10
  ------------------
                          LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   90|  1.05k|#define LIBSPDM_CRYPTO_ASN1_CONSTRUCTED 0x20
  ------------------
 1020|  1.05k|        if (!status) {
  ------------------
  |  Branch (1020:13): [True: 0, False: 1.05k]
  ------------------
 1021|      0|            return false;
 1022|      0|        }
 1023|       |
 1024|  1.05k|        temptr = ptr + obj_len;
 1025|  1.05k|        status = libspdm_asn1_get_tag(
 1026|  1.05k|            &ptr, spdm_extension + len, &obj_len, LIBSPDM_CRYPTO_ASN1_OID);
  ------------------
  |  |   78|  1.05k|#define LIBSPDM_CRYPTO_ASN1_OID 0x06
  ------------------
 1027|  1.05k|        if (!status) {
  ------------------
  |  Branch (1027:13): [True: 0, False: 1.05k]
  ------------------
 1028|      0|            return false;
 1029|      0|        }
 1030|  1.05k|        if ((obj_len == sizeof(hardware_identity_oid)) &&
  ------------------
  |  Branch (1030:13): [True: 1.05k, False: 0]
  ------------------
 1031|  1.05k|            (libspdm_consttime_is_mem_equal(ptr, hardware_identity_oid,
  ------------------
  |  Branch (1031:13): [True: 1.05k, False: 0]
  ------------------
 1032|  1.05k|                                            sizeof(hardware_identity_oid)))) {
 1033|  1.05k|            find_sucessful = true;
 1034|  1.05k|        }
 1035|  1.05k|        ptr = temptr;
 1036|  1.05k|    }
 1037|       |
 1038|  1.05k|    if (ptr != spdm_extension + len) {
  ------------------
  |  Branch (1038:9): [True: 0, False: 1.05k]
  ------------------
 1039|      0|        return false;
 1040|      0|    }
 1041|       |
 1042|       |    /* Responder does not determine Requester's certificate model */
 1043|  1.05k|    if (!is_requester_cert) {
  ------------------
  |  Branch (1043:9): [True: 1.05k, False: 0]
  ------------------
 1044|  1.05k|        if ((find_sucessful) && (cert_model == SPDM_CERTIFICATE_INFO_CERT_MODEL_ALIAS_CERT)) {
  ------------------
  |  |  599|  1.05k|#define SPDM_CERTIFICATE_INFO_CERT_MODEL_ALIAS_CERT 0x2
  ------------------
  |  Branch (1044:13): [True: 1.05k, False: 0]
  |  Branch (1044:33): [True: 0, False: 1.05k]
  ------------------
 1045|       |            /* Hardware_identity_OID is found in alias cert model */
 1046|      0|            return false;
 1047|      0|        }
 1048|  1.05k|    }
 1049|       |
 1050|  1.05k|    return true;
 1051|  1.05k|}
libspdm_crypt_cert.c:libspdm_verify_leaf_cert_basic_constraints:
  750|  1.05k|{
  751|  1.05k|    bool status;
  752|       |    /*basic_constraints from cert*/
  753|  1.05k|    uint8_t cert_basic_constraints[LIBSPDM_MAX_BASIC_CONSTRAINTS_CA_LEN];
  754|  1.05k|    size_t len;
  755|       |
  756|  1.05k|    uint8_t basic_constraints_false_case1[] = BASIC_CONSTRAINTS_STRING_FALSE_CASE1;
  ------------------
  |  |   92|  1.05k|#define BASIC_CONSTRAINTS_STRING_FALSE_CASE1 {0x30, 0x00}
  ------------------
  757|  1.05k|    uint8_t basic_constraints_false_case2[] = BASIC_CONSTRAINTS_STRING_FALSE_CASE2;
  ------------------
  |  |   95|  1.05k|#define BASIC_CONSTRAINTS_STRING_FALSE_CASE2 {0x30, 0x03, 0x01, 0x01, 0x00}
  ------------------
  758|       |
  759|  1.05k|    len = LIBSPDM_MAX_BASIC_CONSTRAINTS_CA_LEN;
  ------------------
  |  |   37|  1.05k|#define LIBSPDM_MAX_BASIC_CONSTRAINTS_CA_LEN 10
  ------------------
  760|       |
  761|  1.05k|    status = libspdm_x509_get_extended_basic_constraints(cert, cert_size,
  762|  1.05k|                                                         cert_basic_constraints, &len);
  763|  1.05k|    if (!status) {
  ------------------
  |  Branch (763:9): [True: 0, False: 1.05k]
  ------------------
  764|      0|        return false;
  765|  1.05k|    } else if (len == 0) {
  ------------------
  |  Branch (765:16): [True: 0, False: 1.05k]
  ------------------
  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|  1.05k|    if ((len == sizeof(basic_constraints_false_case1)) &&
  ------------------
  |  Branch (774:9): [True: 1.05k, False: 0]
  ------------------
  775|  1.05k|        (libspdm_consttime_is_mem_equal(cert_basic_constraints,
  ------------------
  |  Branch (775:9): [True: 1.05k, False: 0]
  ------------------
  776|  1.05k|                                        basic_constraints_false_case1,
  777|  1.05k|                                        sizeof(basic_constraints_false_case1)))) {
  778|  1.05k|        return true;
  779|  1.05k|    }
  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|  1.06k|{
   11|  1.06k|    switch (base_hash_algo) {
   12|  1.06k|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
  ------------------
  |  |  391|  1.06k|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256 0x00000001
  ------------------
  |  Branch (12:5): [True: 1.06k, False: 0]
  ------------------
   13|  1.06k|#if LIBSPDM_SHA256_SUPPORT
   14|  1.06k|        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: 1.06k]
  ------------------
   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: 1.06k]
  ------------------
   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: 1.06k]
  ------------------
   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: 1.06k]
  ------------------
   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: 1.06k]
  ------------------
   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: 1.06k]
  ------------------
   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: 1.06k]
  ------------------
   55|      0|        return 0;
   56|  1.06k|    }
   57|  1.06k|}
libspdm_get_hash_nid:
   60|      3|{
   61|      3|    switch (base_hash_algo) {
   62|      3|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
  ------------------
  |  |  391|      3|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256 0x00000001
  ------------------
  |  Branch (62:5): [True: 3, False: 0]
  ------------------
   63|      3|        return LIBSPDM_CRYPTO_NID_SHA256;
  ------------------
  |  |   22|      3|#define LIBSPDM_CRYPTO_NID_SHA256 0x0001
  ------------------
   64|      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 (64:5): [True: 0, False: 3]
  ------------------
   65|      0|        return LIBSPDM_CRYPTO_NID_SHA384;
  ------------------
  |  |   23|      0|#define LIBSPDM_CRYPTO_NID_SHA384 0x0002
  ------------------
   66|      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 (66:5): [True: 0, False: 3]
  ------------------
   67|      0|        return LIBSPDM_CRYPTO_NID_SHA512;
  ------------------
  |  |   24|      0|#define LIBSPDM_CRYPTO_NID_SHA512 0x0003
  ------------------
   68|      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 (68:5): [True: 0, False: 3]
  ------------------
   69|      0|        return LIBSPDM_CRYPTO_NID_SHA3_256;
  ------------------
  |  |   25|      0|#define LIBSPDM_CRYPTO_NID_SHA3_256 0x0004
  ------------------
   70|      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 (70:5): [True: 0, False: 3]
  ------------------
   71|      0|        return LIBSPDM_CRYPTO_NID_SHA3_384;
  ------------------
  |  |   26|      0|#define LIBSPDM_CRYPTO_NID_SHA3_384 0x0005
  ------------------
   72|      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 (72:5): [True: 0, False: 3]
  ------------------
   73|      0|        return LIBSPDM_CRYPTO_NID_SHA3_512;
  ------------------
  |  |   27|      0|#define LIBSPDM_CRYPTO_NID_SHA3_512 0x0006
  ------------------
   74|      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 (74:5): [True: 0, False: 3]
  ------------------
   75|      0|        return LIBSPDM_CRYPTO_NID_SM3_256;
  ------------------
  |  |   28|      0|#define LIBSPDM_CRYPTO_NID_SM3_256 0x0007
  ------------------
   76|      0|    default:
  ------------------
  |  Branch (76:5): [True: 0, False: 3]
  ------------------
   77|      0|        return LIBSPDM_CRYPTO_NID_NULL;
  ------------------
  |  |   19|      0|#define LIBSPDM_CRYPTO_NID_NULL 0x0000
  ------------------
   78|      3|    }
   79|      3|}
libspdm_hash_new:
   82|      3|{
   83|      3|    switch (base_hash_algo) {
   84|      3|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
  ------------------
  |  |  391|      3|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256 0x00000001
  ------------------
  |  Branch (84:5): [True: 3, False: 0]
  ------------------
   85|      3|#if LIBSPDM_SHA256_SUPPORT
   86|      3|        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: 3]
  ------------------
   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: 3]
  ------------------
   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: 3]
  ------------------
  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: 3]
  ------------------
  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: 3]
  ------------------
  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: 3]
  ------------------
  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: 3]
  ------------------
  134|      0|        LIBSPDM_ASSERT(false);
  135|      0|        return NULL;
  136|      3|    }
  137|      3|}
libspdm_hash_free:
  140|      3|{
  141|      3|    if (hash_context == NULL) {
  ------------------
  |  Branch (141:9): [True: 0, False: 3]
  ------------------
  142|      0|        return;
  143|      0|    }
  144|      3|    switch (base_hash_algo) {
  145|      3|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
  ------------------
  |  |  391|      3|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256 0x00000001
  ------------------
  |  Branch (145:5): [True: 3, False: 0]
  ------------------
  146|      3|#if LIBSPDM_SHA256_SUPPORT
  147|      3|        libspdm_sha256_free(hash_context);
  148|       |#else
  149|       |        LIBSPDM_ASSERT(false);
  150|       |#endif
  151|      3|        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: 3]
  ------------------
  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: 3]
  ------------------
  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: 3]
  ------------------
  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: 3]
  ------------------
  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: 3]
  ------------------
  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: 3]
  ------------------
  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: 3]
  ------------------
  195|      0|        LIBSPDM_ASSERT(false);
  196|      0|        break;
  197|      3|    }
  198|      3|}
libspdm_hash_init:
  201|      3|{
  202|      3|    switch (base_hash_algo) {
  203|      3|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
  ------------------
  |  |  391|      3|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256 0x00000001
  ------------------
  |  Branch (203:5): [True: 3, False: 0]
  ------------------
  204|      3|#if LIBSPDM_SHA256_SUPPORT
  205|      3|        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: 3]
  ------------------
  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: 3]
  ------------------
  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: 3]
  ------------------
  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: 3]
  ------------------
  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: 3]
  ------------------
  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: 3]
  ------------------
  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: 3]
  ------------------
  253|      0|        LIBSPDM_ASSERT(false);
  254|      0|        return false;
  255|      3|    }
  256|      3|}
libspdm_hash_update:
  318|      9|{
  319|      9|    switch (base_hash_algo) {
  320|      9|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
  ------------------
  |  |  391|      9|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256 0x00000001
  ------------------
  |  Branch (320:5): [True: 9, False: 0]
  ------------------
  321|      9|#if LIBSPDM_SHA256_SUPPORT
  322|      9|        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: 9]
  ------------------
  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: 9]
  ------------------
  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: 9]
  ------------------
  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: 9]
  ------------------
  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: 9]
  ------------------
  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: 9]
  ------------------
  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: 9]
  ------------------
  370|      0|        LIBSPDM_ASSERT(false);
  371|      0|        return false;
  372|      9|    }
  373|      9|}
libspdm_hash_final:
  376|      3|{
  377|      3|    switch (base_hash_algo) {
  378|      3|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
  ------------------
  |  |  391|      3|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256 0x00000001
  ------------------
  |  Branch (378:5): [True: 3, False: 0]
  ------------------
  379|      3|#if LIBSPDM_SHA256_SUPPORT
  380|      3|        return libspdm_sha256_final(hash_context, hash_value);
  381|       |#else
  382|       |        LIBSPDM_ASSERT(false);
  383|       |        return false;
  384|       |#endif
  385|      0|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384:
  ------------------
  |  |  392|      0|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384 0x00000002
  ------------------
  |  Branch (385:5): [True: 0, False: 3]
  ------------------
  386|      0|#if LIBSPDM_SHA384_SUPPORT
  387|      0|        return libspdm_sha384_final(hash_context, hash_value);
  388|       |#else
  389|       |        LIBSPDM_ASSERT(false);
  390|       |        return false;
  391|       |#endif
  392|      0|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512:
  ------------------
  |  |  393|      0|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512 0x00000004
  ------------------
  |  Branch (392:5): [True: 0, False: 3]
  ------------------
  393|      0|#if LIBSPDM_SHA512_SUPPORT
  394|      0|        return libspdm_sha512_final(hash_context, hash_value);
  395|       |#else
  396|       |        LIBSPDM_ASSERT(false);
  397|       |        return false;
  398|       |#endif
  399|      0|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_256:
  ------------------
  |  |  394|      0|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_256 0x00000008
  ------------------
  |  Branch (399:5): [True: 0, False: 3]
  ------------------
  400|      0|#if LIBSPDM_SHA3_256_SUPPORT
  401|      0|        return libspdm_sha3_256_final(hash_context, hash_value);
  402|       |#else
  403|       |        LIBSPDM_ASSERT(false);
  404|       |        return false;
  405|       |#endif
  406|      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 (406:5): [True: 0, False: 3]
  ------------------
  407|      0|#if LIBSPDM_SHA3_384_SUPPORT
  408|      0|        return libspdm_sha3_384_final(hash_context, hash_value);
  409|       |#else
  410|       |        LIBSPDM_ASSERT(false);
  411|       |        return false;
  412|       |#endif
  413|      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 (413:5): [True: 0, False: 3]
  ------------------
  414|      0|#if LIBSPDM_SHA3_512_SUPPORT
  415|      0|        return libspdm_sha3_512_final(hash_context, hash_value);
  416|       |#else
  417|       |        LIBSPDM_ASSERT(false);
  418|       |        return false;
  419|       |#endif
  420|      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 (420:5): [True: 0, False: 3]
  ------------------
  421|       |#if LIBSPDM_SM3_256_SUPPORT
  422|       |        return libspdm_sm3_256_final(hash_context, hash_value);
  423|       |#else
  424|      0|        LIBSPDM_ASSERT(false);
  425|      0|        return false;
  426|      0|#endif
  427|      0|    default:
  ------------------
  |  Branch (427:5): [True: 0, False: 3]
  ------------------
  428|      0|        LIBSPDM_ASSERT(false);
  429|      0|        return false;
  430|      3|    }
  431|      3|}
libspdm_hash_all:
  435|  1.05k|{
  436|  1.05k|    switch (base_hash_algo) {
  437|  1.05k|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
  ------------------
  |  |  391|  1.05k|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256 0x00000001
  ------------------
  |  Branch (437:5): [True: 1.05k, False: 0]
  ------------------
  438|  1.05k|#if LIBSPDM_SHA256_SUPPORT
  439|  1.05k|        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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  487|      0|        LIBSPDM_ASSERT(false);
  488|      0|        return false;
  489|  1.05k|    }
  490|  1.05k|}

libspdm_get_random_number:
   10|      3|{
   11|      3|    if (size == 0) {
  ------------------
  |  Branch (11:9): [True: 0, False: 3]
  ------------------
   12|      0|        return true;
   13|      0|    }
   14|      3|    return libspdm_random_bytes(rand, size);
   15|      3|}

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

libspdm_init_basic_mut_auth_encap_state:
  441|      1|{
  442|      1|    spdm_context->encap_context.current_request_op_code = 0x00;
  443|      1|    spdm_context->encap_context.request_id = 0;
  444|      1|    spdm_context->encap_context.last_encap_request_size = 0;
  445|      1|    libspdm_zero_mem(&spdm_context->encap_context.last_encap_request_header,
  446|      1|                     sizeof(spdm_context->encap_context.last_encap_request_header));
  447|      1|    spdm_context->mut_auth_cert_chain_buffer_size = 0;
  448|       |
  449|       |    /* Clear Cache. */
  450|      1|    libspdm_reset_message_mut_b(spdm_context);
  451|      1|    libspdm_reset_message_mut_c(spdm_context);
  452|       |
  453|       |    /* Possible Sequence:
  454|       |     * 1. Basic Mutual Auth:
  455|       |     *    1.1 GET_DIGEST/GET_CERTIFICATE/CHALLENGE (encap_context.req_slot_id must not be 0xFF)
  456|       |     *    1.2 CHALLENGE (REQUEST_FLAGS_PUB_KEY_ID_CAP, encap_context req_slot_id must be 0xFF) */
  457|      1|    libspdm_zero_mem(spdm_context->encap_context.request_op_code_sequence,
  458|      1|                     sizeof(spdm_context->encap_context.request_op_code_sequence));
  459|       |    /* Basic Mutual Auth*/
  460|      1|    if (libspdm_is_capabilities_flag_supported(
  ------------------
  |  Branch (460:9): [True: 1, False: 0]
  ------------------
  461|      1|            spdm_context, false,
  462|      1|            SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PUB_KEY_ID_CAP, 0)) {
  ------------------
  |  |  197|      1|#define SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PUB_KEY_ID_CAP 0x00010000
  ------------------
  463|      1|        LIBSPDM_ASSERT (spdm_context->encap_context.req_slot_id == 0xFF);
  464|       |
  465|      1|        spdm_context->encap_context.request_op_code_count = 1;
  466|      1|        spdm_context->encap_context.request_op_code_sequence[0] = SPDM_CHALLENGE;
  ------------------
  |  |   68|      1|#define SPDM_CHALLENGE 0x83
  ------------------
  467|      1|    } else {
  468|      0|        LIBSPDM_ASSERT (spdm_context->encap_context.req_slot_id != 0xFF);
  469|      0|        LIBSPDM_ASSERT(spdm_context->mut_auth_cert_chain_buffer != NULL);
  470|      0|        LIBSPDM_ASSERT(spdm_context->mut_auth_cert_chain_buffer_max_size != 0);
  471|       |
  472|      0|        spdm_context->encap_context.request_op_code_count = 3;
  473|      0|        spdm_context->encap_context.request_op_code_sequence[0] = SPDM_GET_DIGESTS;
  ------------------
  |  |   66|      0|#define SPDM_GET_DIGESTS 0x81
  ------------------
  474|      0|        spdm_context->encap_context.request_op_code_sequence[1] = SPDM_GET_CERTIFICATE;
  ------------------
  |  |   67|      0|#define SPDM_GET_CERTIFICATE 0x82
  ------------------
  475|      0|        spdm_context->encap_context.request_op_code_sequence[2] = SPDM_CHALLENGE;
  ------------------
  |  |   68|      0|#define SPDM_CHALLENGE 0x83
  ------------------
  476|      0|    }
  477|       |
  478|      1|    spdm_context->response_state = LIBSPDM_RESPONSE_STATE_PROCESSING_ENCAP;
  479|      1|}

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

libspdm_responder_handle_response_state:
   13|     20|{
   14|     20|    libspdm_return_t status;
   15|       |
   16|     20|    switch (spdm_context->response_state) {
   17|     20|    case LIBSPDM_RESPONSE_STATE_BUSY:
  ------------------
  |  Branch (17:5): [True: 20, False: 0]
  ------------------
   18|     20|        return libspdm_generate_error_response(spdm_context, SPDM_ERROR_CODE_BUSY,
  ------------------
  |  |  856|     20|#define SPDM_ERROR_CODE_BUSY 0x03
  ------------------
   19|     20|                                               0, response_size, response);
   20|       |    /* NOTE: Need to reset status to Normal in up level*/
   21|      0|    case LIBSPDM_RESPONSE_STATE_NEED_RESYNC:
  ------------------
  |  Branch (21:5): [True: 0, False: 20]
  ------------------
   22|      0|        status = libspdm_generate_error_response(spdm_context,
   23|      0|                                                 SPDM_ERROR_CODE_REQUEST_RESYNCH, 0,
  ------------------
  |  |  862|      0|#define SPDM_ERROR_CODE_REQUEST_RESYNCH 0x43
  ------------------
   24|      0|                                                 response_size, response);
   25|      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]
  |  |  ------------------
  ------------------
   26|      0|            return status;
   27|      0|        }
   28|       |        /* NOTE: Need to let SPDM_VERSION reset the State*/
   29|      0|        libspdm_set_connection_state(spdm_context,
   30|      0|                                     LIBSPDM_CONNECTION_STATE_NOT_STARTED);
   31|      0|        return LIBSPDM_STATUS_SUCCESS;
  ------------------
  |  |   59|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_SUCCESS, LIBSPDM_SOURCE_SUCCESS, 0x0000)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
   32|      0|    #if LIBSPDM_RESPOND_IF_READY_SUPPORT
   33|      0|    case LIBSPDM_RESPONSE_STATE_NOT_READY:
  ------------------
  |  Branch (33:5): [True: 0, False: 20]
  ------------------
   34|       |        /*do not update ErrorData if a previous request has not been completed*/
   35|      0|        if(request_code != SPDM_RESPOND_IF_READY) {
  ------------------
  |  |   74|      0|#define SPDM_RESPOND_IF_READY 0xFF
  ------------------
  |  Branch (35:12): [True: 0, False: 0]
  ------------------
   36|      0|            spdm_context->cache_spdm_request_size = spdm_context->last_spdm_request_size;
   37|      0|            libspdm_copy_mem(spdm_context->cache_spdm_request,
   38|      0|                             libspdm_get_scratch_buffer_cache_spdm_request_capacity(spdm_context),
   39|      0|                             spdm_context->last_spdm_request,
   40|      0|                             spdm_context->last_spdm_request_size);
   41|      0|            spdm_context->error_data.rd_exponent = 1;
   42|      0|            spdm_context->error_data.rd_tm = 1;
   43|      0|            spdm_context->error_data.request_code = request_code;
   44|      0|            spdm_context->error_data.token = spdm_context->current_token++;
   45|      0|        }
   46|      0|        return libspdm_generate_extended_error_response(
   47|      0|            spdm_context, SPDM_ERROR_CODE_RESPONSE_NOT_READY, 0,
  ------------------
  |  |  861|      0|#define SPDM_ERROR_CODE_RESPONSE_NOT_READY 0x42
  ------------------
   48|      0|            sizeof(spdm_error_data_response_not_ready_t),
   49|      0|            (uint8_t *)(void *)&spdm_context->error_data,
   50|      0|            response_size, response);
   51|      0|    #endif /* LIBSPDM_RESPOND_IF_READY_SUPPORT */
   52|       |    /* NOTE: Need to reset status to Normal in up level*/
   53|      0|    case LIBSPDM_RESPONSE_STATE_PROCESSING_ENCAP:
  ------------------
  |  Branch (53:5): [True: 0, False: 20]
  ------------------
   54|      0|        return libspdm_generate_error_response(spdm_context,
   55|      0|                                               SPDM_ERROR_CODE_REQUEST_IN_FLIGHT,
  ------------------
  |  |  867|      0|#define SPDM_ERROR_CODE_REQUEST_IN_FLIGHT 0x08
  ------------------
   56|      0|                                               0, response_size, response);
   57|       |    /* NOTE: Need let SPDM_ENCAPSULATED_RESPONSE_ACK reset the State*/
   58|      0|    default:
  ------------------
  |  Branch (58:5): [True: 0, False: 20]
  ------------------
   59|      0|        return LIBSPDM_STATUS_SUCCESS;
  ------------------
  |  |   59|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_SUCCESS, LIBSPDM_SOURCE_SUCCESS, 0x0000)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
   60|     20|    }
   61|     20|}

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

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

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

libspdm_ec_get_private_key_from_pem:
  143|      3|{
  144|      3|    int ret;
  145|      3|    mbedtls_pk_context pk;
  146|      3|    mbedtls_ecdh_context *ecdh;
  147|      3|    uint8_t *new_pem_data;
  148|      3|    size_t password_len;
  149|       |
  150|      3|    if (pem_data == NULL || ec_context == NULL || pem_size > INT_MAX) {
  ------------------
  |  Branch (150:9): [True: 0, False: 3]
  |  Branch (150:29): [True: 0, False: 3]
  |  Branch (150:51): [True: 0, False: 3]
  ------------------
  151|      0|        return false;
  152|      0|    }
  153|       |
  154|      3|    new_pem_data = NULL;
  155|      3|    if (pem_data[pem_size - 1] != 0) {
  ------------------
  |  Branch (155:9): [True: 3, False: 0]
  ------------------
  156|      3|        new_pem_data = allocate_pool(pem_size + 1);
  157|      3|        if (new_pem_data == NULL) {
  ------------------
  |  Branch (157:13): [True: 0, False: 3]
  ------------------
  158|      0|            return false;
  159|      0|        }
  160|      3|        libspdm_copy_mem(new_pem_data, pem_size + 1, pem_data, pem_size);
  161|      3|        new_pem_data[pem_size] = 0;
  162|      3|        pem_data = new_pem_data;
  163|      3|        pem_size += 1;
  164|      3|    }
  165|       |
  166|      3|    mbedtls_pk_init(&pk);
  167|       |
  168|      3|    if (password != NULL) {
  ------------------
  |  Branch (168:9): [True: 0, False: 3]
  ------------------
  169|      0|        password_len = ascii_str_len(password);
  170|      3|    } else {
  171|      3|        password_len = 0;
  172|      3|    }
  173|       |
  174|      3|    ret = mbedtls_pk_parse_key(&pk, pem_data, pem_size,
  175|      3|                               (const uint8_t *)password, password_len,
  176|      3|                               libspdm_myrand, NULL);
  177|       |
  178|      3|    if (new_pem_data != NULL) {
  ------------------
  |  Branch (178:9): [True: 3, False: 0]
  ------------------
  179|      3|        free_pool(new_pem_data);
  180|      3|        new_pem_data = NULL;
  181|      3|    }
  182|       |
  183|      3|    if (ret != 0) {
  ------------------
  |  Branch (183:9): [True: 0, False: 3]
  ------------------
  184|      0|        mbedtls_pk_free(&pk);
  185|      0|        return false;
  186|      0|    }
  187|       |
  188|      3|    if (mbedtls_pk_get_type(&pk) != MBEDTLS_PK_ECKEY) {
  ------------------
  |  Branch (188:9): [True: 0, False: 3]
  ------------------
  189|      0|        mbedtls_pk_free(&pk);
  190|      0|        return false;
  191|      0|    }
  192|       |
  193|      3|    ecdh = allocate_zero_pool(sizeof(mbedtls_ecdh_context));
  194|      3|    if (ecdh == NULL) {
  ------------------
  |  Branch (194:9): [True: 0, False: 3]
  ------------------
  195|      0|        mbedtls_pk_free(&pk);
  196|      0|        return false;
  197|      0|    }
  198|      3|    mbedtls_ecdh_init(ecdh);
  199|       |
  200|      3|    ret = mbedtls_ecdh_get_params(ecdh, mbedtls_pk_ec(pk),
  201|      3|                                  MBEDTLS_ECDH_OURS);
  202|      3|    if (ret != 0) {
  ------------------
  |  Branch (202:9): [True: 0, False: 3]
  ------------------
  203|      0|        mbedtls_ecdh_free(ecdh);
  204|      0|        free_pool(ecdh);
  205|      0|        mbedtls_pk_free(&pk);
  206|      0|        return false;
  207|      0|    }
  208|      3|    mbedtls_pk_free(&pk);
  209|       |
  210|      3|    *ec_context = ecdh;
  211|      3|    return true;
  212|      3|}

libspdm_ec_free:
   75|  1.05k|{
   76|  1.05k|    mbedtls_ecdh_free(ec_context);
   77|  1.05k|    free_pool(ec_context);
   78|  1.05k|}
libspdm_ecdsa_sign:
  516|      3|{
  517|      3|    int ret;
  518|      3|    mbedtls_ecdh_context *ctx;
  519|      3|    mbedtls_mpi bn_r;
  520|      3|    mbedtls_mpi bn_s;
  521|      3|    size_t r_size;
  522|      3|    size_t s_size;
  523|      3|    size_t half_size;
  524|       |
  525|      3|    if (ec_context == NULL || message_hash == NULL) {
  ------------------
  |  Branch (525:9): [True: 0, False: 3]
  |  Branch (525:31): [True: 0, False: 3]
  ------------------
  526|      0|        return false;
  527|      0|    }
  528|       |
  529|      3|    if (signature == NULL) {
  ------------------
  |  Branch (529:9): [True: 0, False: 3]
  ------------------
  530|      0|        return false;
  531|      0|    }
  532|       |
  533|      3|    ctx = ec_context;
  534|      3|    switch (mbedtls_ecdh_get_grp_id(ctx)) {
  535|      3|    case MBEDTLS_ECP_DP_SECP256R1:
  ------------------
  |  Branch (535:5): [True: 3, False: 0]
  ------------------
  536|      3|        half_size = 32;
  537|      3|        break;
  538|      0|    case MBEDTLS_ECP_DP_SECP384R1:
  ------------------
  |  Branch (538:5): [True: 0, False: 3]
  ------------------
  539|      0|        half_size = 48;
  540|      0|        break;
  541|      0|    case MBEDTLS_ECP_DP_SECP521R1:
  ------------------
  |  Branch (541:5): [True: 0, False: 3]
  ------------------
  542|      0|        half_size = 66;
  543|      0|        break;
  544|      0|    default:
  ------------------
  |  Branch (544:5): [True: 0, False: 3]
  ------------------
  545|      0|        return false;
  546|      3|    }
  547|      3|    if (*sig_size < (size_t)(half_size * 2)) {
  ------------------
  |  Branch (547:9): [True: 0, False: 3]
  ------------------
  548|      0|        *sig_size = half_size * 2;
  549|      0|        return false;
  550|      0|    }
  551|      3|    *sig_size = half_size * 2;
  552|      3|    libspdm_zero_mem(signature, *sig_size);
  553|       |
  554|      3|    switch (hash_nid) {
  555|      3|    case LIBSPDM_CRYPTO_NID_SHA256:
  ------------------
  |  |   22|      3|#define LIBSPDM_CRYPTO_NID_SHA256 0x0001
  ------------------
  |  Branch (555:5): [True: 3, False: 0]
  ------------------
  556|      3|        if (hash_size != LIBSPDM_SHA256_DIGEST_SIZE) {
  ------------------
  |  |   11|      3|#define LIBSPDM_SHA256_DIGEST_SIZE 32
  ------------------
  |  Branch (556:13): [True: 0, False: 3]
  ------------------
  557|      0|            return false;
  558|      0|        }
  559|      3|        break;
  560|       |
  561|      3|    case LIBSPDM_CRYPTO_NID_SHA384:
  ------------------
  |  |   23|      0|#define LIBSPDM_CRYPTO_NID_SHA384 0x0002
  ------------------
  |  Branch (561:5): [True: 0, False: 3]
  ------------------
  562|      0|        if (hash_size != LIBSPDM_SHA384_DIGEST_SIZE) {
  ------------------
  |  |   14|      0|#define LIBSPDM_SHA384_DIGEST_SIZE 48
  ------------------
  |  Branch (562:13): [True: 0, False: 0]
  ------------------
  563|      0|            return false;
  564|      0|        }
  565|      0|        break;
  566|       |
  567|      0|    case LIBSPDM_CRYPTO_NID_SHA512:
  ------------------
  |  |   24|      0|#define LIBSPDM_CRYPTO_NID_SHA512 0x0003
  ------------------
  |  Branch (567:5): [True: 0, False: 3]
  ------------------
  568|      0|        if (hash_size != LIBSPDM_SHA512_DIGEST_SIZE) {
  ------------------
  |  |   17|      0|#define LIBSPDM_SHA512_DIGEST_SIZE 64
  ------------------
  |  Branch (568:13): [True: 0, False: 0]
  ------------------
  569|      0|            return false;
  570|      0|        }
  571|      0|        break;
  572|       |
  573|      0|    case LIBSPDM_CRYPTO_NID_SHA3_256:
  ------------------
  |  |   25|      0|#define LIBSPDM_CRYPTO_NID_SHA3_256 0x0004
  ------------------
  |  Branch (573:5): [True: 0, False: 3]
  ------------------
  574|      0|        if (hash_size != LIBSPDM_SHA3_256_DIGEST_SIZE) {
  ------------------
  |  |   20|      0|#define LIBSPDM_SHA3_256_DIGEST_SIZE 32
  ------------------
  |  Branch (574:13): [True: 0, False: 0]
  ------------------
  575|      0|            return false;
  576|      0|        }
  577|      0|        break;
  578|       |
  579|      0|    case LIBSPDM_CRYPTO_NID_SHA3_384:
  ------------------
  |  |   26|      0|#define LIBSPDM_CRYPTO_NID_SHA3_384 0x0005
  ------------------
  |  Branch (579:5): [True: 0, False: 3]
  ------------------
  580|      0|        if (hash_size != LIBSPDM_SHA3_384_DIGEST_SIZE) {
  ------------------
  |  |   23|      0|#define LIBSPDM_SHA3_384_DIGEST_SIZE 48
  ------------------
  |  Branch (580:13): [True: 0, False: 0]
  ------------------
  581|      0|            return false;
  582|      0|        }
  583|      0|        break;
  584|       |
  585|      0|    case LIBSPDM_CRYPTO_NID_SHA3_512:
  ------------------
  |  |   27|      0|#define LIBSPDM_CRYPTO_NID_SHA3_512 0x0006
  ------------------
  |  Branch (585:5): [True: 0, False: 3]
  ------------------
  586|      0|        if (hash_size != LIBSPDM_SHA3_512_DIGEST_SIZE) {
  ------------------
  |  |   26|      0|#define LIBSPDM_SHA3_512_DIGEST_SIZE 64
  ------------------
  |  Branch (586:13): [True: 0, False: 0]
  ------------------
  587|      0|            return false;
  588|      0|        }
  589|      0|        break;
  590|       |
  591|      0|    default:
  ------------------
  |  Branch (591:5): [True: 0, False: 3]
  ------------------
  592|      0|        return false;
  593|      3|    }
  594|       |
  595|      3|    mbedtls_mpi_init(&bn_r);
  596|      3|    mbedtls_mpi_init(&bn_s);
  597|       |
  598|      3|    ret = mbedtls_ecdsa_sign(&ctx->MBEDTLS_PRIVATE(grp), &bn_r, &bn_s,
  ------------------
  |  |   15|      3|#define MBEDTLS_PRIVATE(member) private_##member
  ------------------
  599|      3|                             &ctx->MBEDTLS_PRIVATE(d), message_hash,
  ------------------
  |  |   15|      3|#define MBEDTLS_PRIVATE(member) private_##member
  ------------------
  600|      3|                             hash_size, libspdm_myrand, NULL);
  601|      3|    if (ret != 0) {
  ------------------
  |  Branch (601:9): [True: 0, False: 3]
  ------------------
  602|      0|        return false;
  603|      0|    }
  604|       |
  605|      3|    r_size = mbedtls_mpi_size(&bn_r);
  606|      3|    s_size = mbedtls_mpi_size(&bn_s);
  607|      3|    LIBSPDM_ASSERT(r_size <= half_size && s_size <= half_size);
  608|       |
  609|      3|    ret = mbedtls_mpi_write_binary(
  610|      3|        &bn_r, &signature[0 + half_size - r_size], r_size);
  611|      3|    if (ret != 0) {
  ------------------
  |  Branch (611:9): [True: 0, False: 3]
  ------------------
  612|      0|        mbedtls_mpi_free(&bn_r);
  613|      0|        mbedtls_mpi_free(&bn_s);
  614|      0|        return false;
  615|      0|    }
  616|      3|    ret = mbedtls_mpi_write_binary(
  617|      3|        &bn_s, &signature[half_size + half_size - s_size], s_size);
  618|      3|    if (ret != 0) {
  ------------------
  |  Branch (618:9): [True: 0, False: 3]
  ------------------
  619|      0|        mbedtls_mpi_free(&bn_r);
  620|      0|        mbedtls_mpi_free(&bn_s);
  621|      0|        return false;
  622|      0|    }
  623|       |
  624|      3|    mbedtls_mpi_free(&bn_r);
  625|      3|    mbedtls_mpi_free(&bn_s);
  626|       |
  627|      3|    return true;
  628|      3|}

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

libspdm_random_bytes:
   27|     15|{
   28|     15|    bool ret;
   29|     15|    uint64_t temp_rand;
   30|     15|    size_t dst_size;
   31|       |
   32|     15|    ret = false;
   33|     15|    dst_size = size;
   34|       |
   35|     75|    while (size > 0) {
  ------------------
  |  Branch (35:12): [True: 60, False: 15]
  ------------------
   36|       |        /* Use rnglib to get random number*/
   37|     60|        ret = libspdm_get_random_number_64(&temp_rand);
   38|       |
   39|     60|        if (!ret) {
  ------------------
  |  Branch (39:13): [True: 0, False: 60]
  ------------------
   40|      0|            return ret;
   41|      0|        }
   42|       |
   43|     60|        if (size >= sizeof(uint64_t)) {
  ------------------
  |  Branch (43:13): [True: 60, False: 0]
  ------------------
   44|     60|            libspdm_copy_mem(output, dst_size, &temp_rand, sizeof(uint64_t));
   45|     60|            output += sizeof(uint64_t);
   46|     60|            size -= sizeof(uint64_t);
   47|     60|            dst_size -= sizeof(uint64_t);
   48|     60|        } else {
   49|      0|            libspdm_copy_mem(output, dst_size, &temp_rand, size);
   50|      0|            size = 0;
   51|      0|        }
   52|     60|    }
   53|       |
   54|     15|    return ret;
   55|     15|}
libspdm_myrand:
   58|     12|{
   59|     12|    bool result = libspdm_random_bytes(output, len);
   60|       |
   61|       |
   62|       |    /* The MbedTLS function f_rng, which myrand implements, is not
   63|       |     * documented well. From looking at code: zero is considered success,
   64|       |     * while non-zero return value is considered failure.*/
   65|       |
   66|     12|    return result ? 0 : -1;
  ------------------
  |  Branch (66:12): [True: 12, False: 0]
  ------------------
   67|     12|}

mbedtls_platform_zeroize:
   29|  3.56M|{
   30|  3.56M|    libspdm_zero_mem(buf, len);
   31|  3.56M|}

my_calloc:
   34|  3.48M|{
   35|  3.48M|    CRYPTMEM_HEAD *pool_hdr;
   36|  3.48M|    size_t new_size;
   37|  3.48M|    void *data;
   38|       |
   39|       |
   40|       |    /* Adjust the size by the buffer header overhead*/
   41|       |
   42|  3.48M|    new_size = (size_t)(size * num) + CRYPTMEM_OVERHEAD;
  ------------------
  |  |   26|  3.48M|#define CRYPTMEM_OVERHEAD sizeof(CRYPTMEM_HEAD)
  ------------------
   43|       |
   44|  3.48M|    data = allocate_zero_pool(new_size);
   45|  3.48M|    if (data != NULL) {
  ------------------
  |  Branch (45:9): [True: 3.48M, False: 0]
  ------------------
   46|  3.48M|        pool_hdr = (CRYPTMEM_HEAD *)data;
   47|       |
   48|       |        /* Record the memory brief information*/
   49|       |
   50|  3.48M|        pool_hdr->version = CRYPTMEM_HEAD_VERSION;
  ------------------
  |  |   19|  3.48M|#define CRYPTMEM_HEAD_VERSION 0x1
  ------------------
   51|  3.48M|        pool_hdr->size = size;
   52|       |
   53|  3.48M|        return (void *)(pool_hdr + 1);
   54|  3.48M|    } else {
   55|       |
   56|       |        /* The buffer allocation failed.*/
   57|       |
   58|      0|        return NULL;
   59|      0|    }
   60|  3.48M|}
my_free:
   64|  3.50M|{
   65|  3.50M|    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|  3.50M|    if (ptr != NULL) {
  ------------------
  |  Branch (71:9): [True: 3.48M, False: 19.0k]
  ------------------
   72|  3.48M|        pool_hdr = (CRYPTMEM_HEAD *)ptr - 1;
   73|  3.48M|        LIBSPDM_ASSERT(pool_hdr->version == CRYPTMEM_HEAD_VERSION);
   74|  3.48M|        free_pool(pool_hdr);
   75|  3.48M|    }
   76|  3.50M|}

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

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

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

sha256.c:mbedtls_get_unaligned_uint32:
  168|   339k|{
  169|   339k|    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|   339k|    memcpy(&r, p, sizeof(r));
  178|   339k|#endif
  179|   339k|    return r;
  180|   339k|}
sha256.c:mbedtls_put_unaligned_uint32:
  195|  31.7k|{
  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|  31.7k|    memcpy(p, &x, sizeof(x));
  204|  31.7k|#endif
  205|  31.7k|}

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

mbedtls_base64_decode:
  130|      6|{
  131|      6|    size_t i; /* index in source */
  132|      6|    size_t n; /* number of digits or trailing = in source */
  133|      6|    uint32_t x; /* value accumulator */
  134|      6|    unsigned accumulated_digits = 0;
  135|      6|    unsigned equals = 0;
  136|      6|    int spaces_present = 0;
  137|      6|    unsigned char *p;
  138|       |
  139|       |    /* First pass: check for validity and get output length */
  140|  1.14k|    for (i = n = 0; i < slen; i++) {
  ------------------
  |  Branch (140:21): [True: 1.14k, False: 6]
  ------------------
  141|       |        /* Skip spaces before checking for EOL */
  142|  1.14k|        spaces_present = 0;
  143|  1.14k|        while (i < slen && src[i] == ' ') {
  ------------------
  |  Branch (143:16): [True: 1.14k, False: 0]
  |  Branch (143:28): [True: 0, False: 1.14k]
  ------------------
  144|      0|            ++i;
  145|      0|            spaces_present = 1;
  146|      0|        }
  147|       |
  148|       |        /* Spaces at end of buffer are OK */
  149|  1.14k|        if (i == slen) {
  ------------------
  |  Branch (149:13): [True: 0, False: 1.14k]
  ------------------
  150|      0|            break;
  151|      0|        }
  152|       |
  153|  1.14k|        if ((slen - i) >= 2 &&
  ------------------
  |  Branch (153:13): [True: 1.13k, False: 6]
  ------------------
  154|  1.14k|            src[i] == '\r' && src[i + 1] == '\n') {
  ------------------
  |  Branch (154:13): [True: 18, False: 1.11k]
  |  Branch (154:31): [True: 18, False: 0]
  ------------------
  155|     18|            continue;
  156|     18|        }
  157|       |
  158|  1.12k|        if (src[i] == '\n') {
  ------------------
  |  Branch (158:13): [True: 18, False: 1.10k]
  ------------------
  159|     18|            continue;
  160|     18|        }
  161|       |
  162|       |        /* Space inside a line is an error */
  163|  1.10k|        if (spaces_present) {
  ------------------
  |  Branch (163:13): [True: 0, False: 1.10k]
  ------------------
  164|      0|            return MBEDTLS_ERR_BASE64_INVALID_CHARACTER;
  ------------------
  |  |   20|      0|#define MBEDTLS_ERR_BASE64_INVALID_CHARACTER              -0x002C
  ------------------
  165|      0|        }
  166|       |
  167|  1.10k|        if (src[i] > 127) {
  ------------------
  |  Branch (167:13): [True: 0, False: 1.10k]
  ------------------
  168|      0|            return MBEDTLS_ERR_BASE64_INVALID_CHARACTER;
  ------------------
  |  |   20|      0|#define MBEDTLS_ERR_BASE64_INVALID_CHARACTER              -0x002C
  ------------------
  169|      0|        }
  170|       |
  171|  1.10k|        if (src[i] == '=') {
  ------------------
  |  Branch (171:13): [True: 0, False: 1.10k]
  ------------------
  172|      0|            if (++equals > 2) {
  ------------------
  |  Branch (172:17): [True: 0, False: 0]
  ------------------
  173|      0|                return MBEDTLS_ERR_BASE64_INVALID_CHARACTER;
  ------------------
  |  |   20|      0|#define MBEDTLS_ERR_BASE64_INVALID_CHARACTER              -0x002C
  ------------------
  174|      0|            }
  175|  1.10k|        } else {
  176|  1.10k|            if (equals != 0) {
  ------------------
  |  Branch (176:17): [True: 0, False: 1.10k]
  ------------------
  177|      0|                return MBEDTLS_ERR_BASE64_INVALID_CHARACTER;
  ------------------
  |  |   20|      0|#define MBEDTLS_ERR_BASE64_INVALID_CHARACTER              -0x002C
  ------------------
  178|      0|            }
  179|  1.10k|            if (mbedtls_ct_base64_dec_value(src[i]) < 0) {
  ------------------
  |  Branch (179:17): [True: 0, False: 1.10k]
  ------------------
  180|      0|                return MBEDTLS_ERR_BASE64_INVALID_CHARACTER;
  ------------------
  |  |   20|      0|#define MBEDTLS_ERR_BASE64_INVALID_CHARACTER              -0x002C
  ------------------
  181|      0|            }
  182|  1.10k|        }
  183|  1.10k|        n++;
  184|  1.10k|    }
  185|       |
  186|      6|    if (n == 0) {
  ------------------
  |  Branch (186:9): [True: 0, False: 6]
  ------------------
  187|      0|        *olen = 0;
  188|      0|        return 0;
  189|      0|    }
  190|       |
  191|       |    /* The following expression is to calculate the following formula without
  192|       |     * risk of integer overflow in n:
  193|       |     *     n = ( ( n * 6 ) + 7 ) >> 3;
  194|       |     */
  195|      6|    n = (6 * (n >> 3)) + ((6 * (n & 0x7) + 7) >> 3);
  196|      6|    n -= equals;
  197|       |
  198|      6|    if (dst == NULL || dlen < n) {
  ------------------
  |  Branch (198:9): [True: 3, False: 3]
  |  Branch (198:24): [True: 0, False: 3]
  ------------------
  199|      3|        *olen = n;
  200|      3|        return MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL;
  ------------------
  |  |   18|      3|#define MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL               -0x002A
  ------------------
  201|      3|    }
  202|       |
  203|      3|    equals = 0;
  204|    573|    for (x = 0, p = dst; i > 0; i--, src++) {
  ------------------
  |  Branch (204:26): [True: 570, False: 3]
  ------------------
  205|    570|        if (*src == '\r' || *src == '\n' || *src == ' ') {
  ------------------
  |  Branch (205:13): [True: 9, False: 561]
  |  Branch (205:29): [True: 9, False: 552]
  |  Branch (205:45): [True: 0, False: 552]
  ------------------
  206|     18|            continue;
  207|     18|        }
  208|       |
  209|    552|        x = x << 6;
  210|    552|        if (*src == '=') {
  ------------------
  |  Branch (210:13): [True: 0, False: 552]
  ------------------
  211|      0|            ++equals;
  212|    552|        } else {
  213|    552|            x |= mbedtls_ct_base64_dec_value(*src);
  214|    552|        }
  215|       |
  216|    552|        if (++accumulated_digits == 4) {
  ------------------
  |  Branch (216:13): [True: 138, False: 414]
  ------------------
  217|    138|            accumulated_digits = 0;
  218|    138|            *p++ = MBEDTLS_BYTE_2(x);
  ------------------
  |  |  270|    138|#define MBEDTLS_BYTE_2(x) ((uint8_t) (((x) >> 16) & 0xff))
  ------------------
  219|    138|            if (equals <= 1) {
  ------------------
  |  Branch (219:17): [True: 138, False: 0]
  ------------------
  220|    138|                *p++ = MBEDTLS_BYTE_1(x);
  ------------------
  |  |  269|    138|#define MBEDTLS_BYTE_1(x) ((uint8_t) (((x) >>  8) & 0xff))
  ------------------
  221|    138|            }
  222|    138|            if (equals <= 0) {
  ------------------
  |  Branch (222:17): [True: 138, False: 0]
  ------------------
  223|    138|                *p++ = MBEDTLS_BYTE_0(x);
  ------------------
  |  |  268|    138|#define MBEDTLS_BYTE_0(x) ((uint8_t) ((x)         & 0xff))
  ------------------
  224|    138|            }
  225|    138|        }
  226|    552|    }
  227|       |
  228|      3|    *olen = (size_t) (p - dst);
  229|       |
  230|      3|    return 0;
  231|      6|}
base64.c:mbedtls_ct_base64_dec_value:
   42|  1.65k|{
   43|  1.65k|    unsigned char val = 0;
   44|       |    /* For each range of digits, if c is in that range, mask val with
   45|       |     * the corresponding value. Since c can only be in a single range,
   46|       |     * only at most one masking will change val. Set val to one plus
   47|       |     * the desired value so that it stays 0 if c is in none of the ranges. */
   48|  1.65k|    val |= mbedtls_ct_uchar_in_range_if('A', 'Z', c, c - 'A' +  0 + 1);
   49|  1.65k|    val |= mbedtls_ct_uchar_in_range_if('a', 'z', c, c - 'a' + 26 + 1);
   50|  1.65k|    val |= mbedtls_ct_uchar_in_range_if('0', '9', c, c - '0' + 52 + 1);
   51|  1.65k|    val |= mbedtls_ct_uchar_in_range_if('+', '+', c, c - '+' + 62 + 1);
   52|  1.65k|    val |= mbedtls_ct_uchar_in_range_if('/', '/', c, c - '/' + 63 + 1);
   53|       |    /* At this point, val is 0 if c is an invalid digit and v+1 if c is
   54|       |     * a digit with the value v. */
   55|  1.65k|    return val - 1;
   56|  1.65k|}

mbedtls_mpi_safe_cond_assign:
  121|  6.04M|{
  122|  6.04M|    int ret = 0;
  123|       |
  124|  6.04M|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, Y->n));
  ------------------
  |  |   41|  6.04M|    do                           \
  |  |   42|  6.04M|    {                            \
  |  |   43|  6.04M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 6.04M]
  |  |  ------------------
  |  |   44|  6.04M|        goto cleanup;        \
  |  |   45|  6.04M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  125|       |
  126|  6.04M|    {
  127|  6.04M|        mbedtls_ct_condition_t do_assign = mbedtls_ct_bool(assign);
  128|       |
  129|  6.04M|        X->s = mbedtls_ct_mpi_sign_if(do_assign, Y->s, X->s);
  130|       |
  131|  6.04M|        mbedtls_mpi_core_cond_assign(X->p, Y->p, Y->n, do_assign);
  132|       |
  133|  6.04M|        mbedtls_ct_condition_t do_not_assign = mbedtls_ct_bool_not(do_assign);
  134|  6.06M|        for (size_t i = Y->n; i < X->n; i++) {
  ------------------
  |  Branch (134:31): [True: 21.1k, False: 6.04M]
  ------------------
  135|  21.1k|            X->p[i] = mbedtls_ct_mpi_uint_if_else_0(do_not_assign, X->p[i]);
  136|  21.1k|        }
  137|  6.04M|    }
  138|       |
  139|  6.04M|cleanup:
  140|  6.04M|    return ret;
  141|  6.04M|}
mbedtls_mpi_init:
  182|  17.6M|{
  183|  17.6M|    X->s = 1;
  184|  17.6M|    X->n = 0;
  185|  17.6M|    X->p = NULL;
  186|  17.6M|}
mbedtls_mpi_free:
  192|  17.5M|{
  193|  17.5M|    if (X == NULL) {
  ------------------
  |  Branch (193:9): [True: 0, False: 17.5M]
  ------------------
  194|      0|        return;
  195|      0|    }
  196|       |
  197|  17.5M|    if (X->p != NULL) {
  ------------------
  |  Branch (197:9): [True: 3.03M, False: 14.4M]
  ------------------
  198|  3.03M|        mbedtls_mpi_zeroize_and_free(X->p, X->n);
  ------------------
  |  |  176|  3.03M|#define mbedtls_mpi_zeroize_and_free(v, n) mbedtls_zeroize_and_free(v, ciL * (n))
  |  |  ------------------
  |  |  |  |   79|  3.03M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  199|  3.03M|    }
  200|       |
  201|  17.5M|    X->s = 1;
  202|  17.5M|    X->n = 0;
  203|  17.5M|    X->p = NULL;
  204|  17.5M|}
mbedtls_mpi_grow:
  210|  66.5M|{
  211|  66.5M|    mbedtls_mpi_uint *p;
  212|       |
  213|  66.5M|    if (nblimbs > MBEDTLS_MPI_MAX_LIMBS) {
  ------------------
  |  |   50|  66.5M|#define MBEDTLS_MPI_MAX_LIMBS                             10000
  ------------------
  |  Branch (213:9): [True: 0, False: 66.5M]
  ------------------
  214|      0|        return MBEDTLS_ERR_MPI_ALLOC_FAILED;
  ------------------
  |  |   38|      0|#define MBEDTLS_ERR_MPI_ALLOC_FAILED                      -0x0010
  ------------------
  215|      0|    }
  216|       |
  217|  66.5M|    if (X->n < nblimbs) {
  ------------------
  |  Branch (217:9): [True: 3.37M, False: 63.1M]
  ------------------
  218|  3.37M|        if ((p = (mbedtls_mpi_uint *) mbedtls_calloc(nblimbs, ciL)) == NULL) {
  ------------------
  |  |  144|  3.37M|#define mbedtls_calloc     MBEDTLS_PLATFORM_CALLOC_MACRO
  |  |  ------------------
  |  |  |  | 4093|  3.37M|#define MBEDTLS_PLATFORM_CALLOC_MACRO        my_calloc
  |  |  ------------------
  ------------------
                      if ((p = (mbedtls_mpi_uint *) mbedtls_calloc(nblimbs, ciL)) == NULL) {
  ------------------
  |  |   79|  3.37M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  |  Branch (218:13): [True: 0, False: 3.37M]
  ------------------
  219|      0|            return MBEDTLS_ERR_MPI_ALLOC_FAILED;
  ------------------
  |  |   38|      0|#define MBEDTLS_ERR_MPI_ALLOC_FAILED                      -0x0010
  ------------------
  220|      0|        }
  221|       |
  222|  3.37M|        if (X->p != NULL) {
  ------------------
  |  Branch (222:13): [True: 340k, False: 3.03M]
  ------------------
  223|   340k|            memcpy(p, X->p, X->n * ciL);
  ------------------
  |  |   79|   340k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  224|   340k|            mbedtls_mpi_zeroize_and_free(X->p, X->n);
  ------------------
  |  |  176|   340k|#define mbedtls_mpi_zeroize_and_free(v, n) mbedtls_zeroize_and_free(v, ciL * (n))
  |  |  ------------------
  |  |  |  |   79|   340k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  225|   340k|        }
  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|  3.37M|        X->n = (unsigned short) nblimbs;
  230|  3.37M|        X->p = p;
  231|  3.37M|    }
  232|       |
  233|  66.5M|    return 0;
  234|  66.5M|}
mbedtls_mpi_shrink:
  241|  42.2k|{
  242|  42.2k|    mbedtls_mpi_uint *p;
  243|  42.2k|    size_t i;
  244|       |
  245|  42.2k|    if (nblimbs > MBEDTLS_MPI_MAX_LIMBS) {
  ------------------
  |  |   50|  42.2k|#define MBEDTLS_MPI_MAX_LIMBS                             10000
  ------------------
  |  Branch (245:9): [True: 0, False: 42.2k]
  ------------------
  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|  42.2k|    if (X->n <= nblimbs) {
  ------------------
  |  Branch (250:9): [True: 0, False: 42.2k]
  ------------------
  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|   253k|    for (i = X->n - 1; i > 0; i--) {
  ------------------
  |  Branch (255:24): [True: 253k, False: 0]
  ------------------
  256|   253k|        if (X->p[i] != 0) {
  ------------------
  |  Branch (256:13): [True: 42.2k, False: 211k]
  ------------------
  257|  42.2k|            break;
  258|  42.2k|        }
  259|   253k|    }
  260|  42.2k|    i++;
  261|       |
  262|  42.2k|    if (i < nblimbs) {
  ------------------
  |  Branch (262:9): [True: 0, False: 42.2k]
  ------------------
  263|      0|        i = nblimbs;
  264|      0|    }
  265|       |
  266|  42.2k|    if ((p = (mbedtls_mpi_uint *) mbedtls_calloc(i, ciL)) == NULL) {
  ------------------
  |  |  144|  42.2k|#define mbedtls_calloc     MBEDTLS_PLATFORM_CALLOC_MACRO
  |  |  ------------------
  |  |  |  | 4093|  42.2k|#define MBEDTLS_PLATFORM_CALLOC_MACRO        my_calloc
  |  |  ------------------
  ------------------
                  if ((p = (mbedtls_mpi_uint *) mbedtls_calloc(i, ciL)) == NULL) {
  ------------------
  |  |   79|  42.2k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  |  Branch (266:9): [True: 0, False: 42.2k]
  ------------------
  267|      0|        return MBEDTLS_ERR_MPI_ALLOC_FAILED;
  ------------------
  |  |   38|      0|#define MBEDTLS_ERR_MPI_ALLOC_FAILED                      -0x0010
  ------------------
  268|      0|    }
  269|       |
  270|  42.2k|    if (X->p != NULL) {
  ------------------
  |  Branch (270:9): [True: 42.2k, False: 0]
  ------------------
  271|  42.2k|        memcpy(p, X->p, i * ciL);
  ------------------
  |  |   79|  42.2k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  272|  42.2k|        mbedtls_mpi_zeroize_and_free(X->p, X->n);
  ------------------
  |  |  176|  42.2k|#define mbedtls_mpi_zeroize_and_free(v, n) mbedtls_zeroize_and_free(v, ciL * (n))
  |  |  ------------------
  |  |  |  |   79|  42.2k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  273|  42.2k|    }
  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|  42.2k|    X->n = (unsigned short) i;
  278|  42.2k|    X->p = p;
  279|       |
  280|  42.2k|    return 0;
  281|  42.2k|}
mbedtls_mpi_copy:
  308|  6.08M|{
  309|  6.08M|    int ret = 0;
  310|  6.08M|    size_t i;
  311|       |
  312|  6.08M|    if (X == Y) {
  ------------------
  |  Branch (312:9): [True: 27.5k, False: 6.05M]
  ------------------
  313|  27.5k|        return 0;
  314|  27.5k|    }
  315|       |
  316|  6.05M|    if (Y->n == 0) {
  ------------------
  |  Branch (316:9): [True: 1.05k, False: 6.05M]
  ------------------
  317|  1.05k|        if (X->n != 0) {
  ------------------
  |  Branch (317:13): [True: 0, False: 1.05k]
  ------------------
  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|  1.05k|        return 0;
  322|  1.05k|    }
  323|       |
  324|  33.6M|    for (i = Y->n - 1; i > 0; i--) {
  ------------------
  |  Branch (324:24): [True: 33.5M, False: 34.8k]
  ------------------
  325|  33.5M|        if (Y->p[i] != 0) {
  ------------------
  |  Branch (325:13): [True: 6.01M, False: 27.5M]
  ------------------
  326|  6.01M|            break;
  327|  6.01M|        }
  328|  33.5M|    }
  329|  6.05M|    i++;
  330|       |
  331|  6.05M|    X->s = Y->s;
  332|       |
  333|  6.05M|    if (X->n < i) {
  ------------------
  |  Branch (333:9): [True: 2.51M, False: 3.53M]
  ------------------
  334|  2.51M|        MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, i));
  ------------------
  |  |   41|  2.51M|    do                           \
  |  |   42|  2.51M|    {                            \
  |  |   43|  2.51M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.51M]
  |  |  ------------------
  |  |   44|  2.51M|        goto cleanup;        \
  |  |   45|  2.51M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  335|  3.53M|    } else {
  336|  3.53M|        memset(X->p + i, 0, (X->n - i) * ciL);
  ------------------
  |  |   79|  3.53M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  337|  3.53M|    }
  338|       |
  339|  6.05M|    memcpy(X->p, Y->p, i * ciL);
  ------------------
  |  |   79|  6.05M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  340|       |
  341|  6.05M|cleanup:
  342|       |
  343|  6.05M|    return ret;
  344|  6.05M|}
mbedtls_mpi_lset:
  378|  8.68M|{
  379|  8.68M|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  8.68M|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  380|       |
  381|  8.68M|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, 1));
  ------------------
  |  |   41|  8.68M|    do                           \
  |  |   42|  8.68M|    {                            \
  |  |   43|  8.68M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 8.68M]
  |  |  ------------------
  |  |   44|  8.68M|        goto cleanup;        \
  |  |   45|  8.68M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  382|  8.68M|    memset(X->p, 0, X->n * ciL);
  ------------------
  |  |   79|  8.68M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  383|       |
  384|  8.68M|    X->p[0] = mpi_sint_abs(z);
  385|  8.68M|    X->s    = TO_SIGN(z);
  ------------------
  |  |  372|  8.68M|#define TO_SIGN(x) ((mbedtls_mpi_sint) (((mbedtls_mpi_uint) x) >> (biL - 1)) * -2 + 1)
  |  |  ------------------
  |  |  |  |   80|  8.68M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  |  |  ------------------
  |  |  |  |  |  |   79|  8.68M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  386|       |
  387|  8.68M|cleanup:
  388|       |
  389|  8.68M|    return ret;
  390|  8.68M|}
mbedtls_mpi_get_bit:
  396|  1.11M|{
  397|  1.11M|    if (X->n * biL <= pos) {
  ------------------
  |  |   80|  1.11M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  1.11M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  |  Branch (397:9): [True: 8.46k, False: 1.10M]
  ------------------
  398|  8.46k|        return 0;
  399|  8.46k|    }
  400|       |
  401|  1.10M|    return (X->p[pos / biL] >> (pos % biL)) & 0x01;
  ------------------
  |  |   80|  1.10M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  1.10M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
                  return (X->p[pos / biL] >> (pos % biL)) & 0x01;
  ------------------
  |  |   80|  1.10M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  1.10M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  402|  1.11M|}
mbedtls_mpi_lsb:
  437|  4.60M|{
  438|  4.60M|    size_t i;
  439|       |
  440|  4.60M|#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|  4.60M|#endif
  449|       |
  450|  4.60M|#if defined(mbedtls_mpi_uint_ctz)
  451|  4.60M|    for (i = 0; i < X->n; i++) {
  ------------------
  |  Branch (451:17): [True: 4.60M, False: 0]
  ------------------
  452|  4.60M|        if (X->p[i] != 0) {
  ------------------
  |  Branch (452:13): [True: 4.60M, False: 0]
  ------------------
  453|  4.60M|            return i * biL + mbedtls_mpi_uint_ctz(X->p[i]);
  ------------------
  |  |   80|  4.60M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  4.60M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
                          return i * biL + mbedtls_mpi_uint_ctz(X->p[i]);
  ------------------
  |  |  444|  4.60M|    #define mbedtls_mpi_uint_ctz __builtin_ctzl
  ------------------
  454|  4.60M|        }
  455|  4.60M|    }
  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|  4.60M|}
mbedtls_mpi_bitlen:
  474|  11.2M|{
  475|  11.2M|    return mbedtls_mpi_core_bitlen(X->p, X->n);
  476|  11.2M|}
mbedtls_mpi_size:
  482|  16.9k|{
  483|  16.9k|    return (mbedtls_mpi_bitlen(X) + 7) >> 3;
  484|  16.9k|}
mbedtls_mpi_read_binary:
  821|  40.1k|{
  822|  40.1k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  40.1k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  823|  40.1k|    const size_t limbs = CHARS_TO_LIMBS(buflen);
  ------------------
  |  |   88|  40.1k|#define CHARS_TO_LIMBS(i) ((i) / ciL + ((i) % ciL != 0))
  |  |  ------------------
  |  |  |  |   79|  40.1k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  |  |               #define CHARS_TO_LIMBS(i) ((i) / ciL + ((i) % ciL != 0))
  |  |  ------------------
  |  |  |  |   79|  40.1k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  824|       |
  825|       |    /* Ensure that target MPI has exactly the necessary number of limbs */
  826|  40.1k|    MBEDTLS_MPI_CHK(mbedtls_mpi_resize_clear(X, limbs));
  ------------------
  |  |   41|  40.1k|    do                           \
  |  |   42|  40.1k|    {                            \
  |  |   43|  40.1k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 40.1k]
  |  |  ------------------
  |  |   44|  40.1k|        goto cleanup;        \
  |  |   45|  40.1k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  827|       |
  828|  40.1k|    MBEDTLS_MPI_CHK(mbedtls_mpi_core_read_be(X->p, X->n, buf, buflen));
  ------------------
  |  |   41|  40.1k|    do                           \
  |  |   42|  40.1k|    {                            \
  |  |   43|  40.1k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 40.1k]
  |  |  ------------------
  |  |   44|  40.1k|        goto cleanup;        \
  |  |   45|  40.1k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  829|       |
  830|  40.1k|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|  40.1k|    return ret;
  838|  40.1k|}
mbedtls_mpi_write_binary:
  854|      6|{
  855|      6|    return mbedtls_mpi_core_write_be(X->p, X->n, buf, buflen);
  856|      6|}
mbedtls_mpi_shift_l:
  862|  2.90M|{
  863|  2.90M|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  2.90M|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  864|  2.90M|    size_t i;
  865|       |
  866|  2.90M|    i = mbedtls_mpi_bitlen(X) + count;
  867|       |
  868|  2.90M|    if (X->n * biL < i) {
  ------------------
  |  |   80|  2.90M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  2.90M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  |  Branch (868:9): [True: 12.6k, False: 2.89M]
  ------------------
  869|  12.6k|        MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, BITS_TO_LIMBS(i)));
  ------------------
  |  |   41|  12.6k|    do                           \
  |  |   42|  12.6k|    {                            \
  |  |   43|  12.6k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 12.6k]
  |  |  ------------------
  |  |   44|  12.6k|        goto cleanup;        \
  |  |   45|  12.6k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  870|  12.6k|    }
  871|       |
  872|  2.90M|    ret = 0;
  873|       |
  874|  2.90M|    mbedtls_mpi_core_shift_l(X->p, X->n, count);
  875|  2.90M|cleanup:
  876|       |
  877|  2.90M|    return ret;
  878|  2.90M|}
mbedtls_mpi_shift_r:
  884|  20.5M|{
  885|  20.5M|    if (X->n != 0) {
  ------------------
  |  Branch (885:9): [True: 20.5M, False: 0]
  ------------------
  886|  20.5M|        mbedtls_mpi_core_shift_r(X->p, X->n, count);
  887|  20.5M|    }
  888|  20.5M|    return 0;
  889|  20.5M|}
mbedtls_mpi_cmp_abs:
  895|  20.5M|{
  896|  20.5M|    size_t i, j;
  897|       |
  898|  93.2M|    for (i = X->n; i > 0; i--) {
  ------------------
  |  Branch (898:20): [True: 93.2M, False: 20.0k]
  ------------------
  899|  93.2M|        if (X->p[i - 1] != 0) {
  ------------------
  |  Branch (899:13): [True: 20.5M, False: 72.7M]
  ------------------
  900|  20.5M|            break;
  901|  20.5M|        }
  902|  93.2M|    }
  903|       |
  904|  50.3M|    for (j = Y->n; j > 0; j--) {
  ------------------
  |  Branch (904:20): [True: 50.3M, False: 5.28k]
  ------------------
  905|  50.3M|        if (Y->p[j - 1] != 0) {
  ------------------
  |  Branch (905:13): [True: 20.5M, False: 29.8M]
  ------------------
  906|  20.5M|            break;
  907|  20.5M|        }
  908|  50.3M|    }
  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|  20.5M|    if (i > j) {
  ------------------
  |  Branch (913:9): [True: 2.10M, False: 18.4M]
  ------------------
  914|  2.10M|        return 1;
  915|  2.10M|    }
  916|  18.4M|    if (j > i) {
  ------------------
  |  Branch (916:9): [True: 36.9k, False: 18.4M]
  ------------------
  917|  36.9k|        return -1;
  918|  36.9k|    }
  919|       |
  920|  18.5M|    for (; i > 0; i--) {
  ------------------
  |  Branch (920:12): [True: 18.5M, False: 29.5k]
  ------------------
  921|  18.5M|        if (X->p[i - 1] > Y->p[i - 1]) {
  ------------------
  |  Branch (921:13): [True: 6.15M, False: 12.3M]
  ------------------
  922|  6.15M|            return 1;
  923|  6.15M|        }
  924|  12.3M|        if (X->p[i - 1] < Y->p[i - 1]) {
  ------------------
  |  Branch (924:13): [True: 12.2M, False: 100k]
  ------------------
  925|  12.2M|            return -1;
  926|  12.2M|        }
  927|  12.3M|    }
  928|       |
  929|  29.5k|    return 0;
  930|  18.4M|}
mbedtls_mpi_cmp_mpi:
  936|  36.3M|{
  937|  36.3M|    size_t i, j;
  938|       |
  939|   172M|    for (i = X->n; i > 0; i--) {
  ------------------
  |  Branch (939:20): [True: 172M, False: 25.3k]
  ------------------
  940|   172M|        if (X->p[i - 1] != 0) {
  ------------------
  |  Branch (940:13): [True: 36.3M, False: 135M]
  ------------------
  941|  36.3M|            break;
  942|  36.3M|        }
  943|   172M|    }
  944|       |
  945|  58.3M|    for (j = Y->n; j > 0; j--) {
  ------------------
  |  Branch (945:20): [True: 43.4M, False: 14.9M]
  ------------------
  946|  43.4M|        if (Y->p[j - 1] != 0) {
  ------------------
  |  Branch (946:13): [True: 21.4M, False: 21.9M]
  ------------------
  947|  21.4M|            break;
  948|  21.4M|        }
  949|  43.4M|    }
  950|       |
  951|  36.3M|    if (i == 0 && j == 0) {
  ------------------
  |  Branch (951:9): [True: 25.3k, False: 36.3M]
  |  Branch (951:19): [True: 25.3k, False: 0]
  ------------------
  952|  25.3k|        return 0;
  953|  25.3k|    }
  954|       |
  955|  36.3M|    if (i > j) {
  ------------------
  |  Branch (955:9): [True: 18.8M, False: 17.4M]
  ------------------
  956|  18.8M|        return X->s;
  957|  18.8M|    }
  958|  17.4M|    if (j > i) {
  ------------------
  |  Branch (958:9): [True: 90.8k, False: 17.3M]
  ------------------
  959|  90.8k|        return -Y->s;
  960|  90.8k|    }
  961|       |
  962|  17.3M|    if (X->s > 0 && Y->s < 0) {
  ------------------
  |  Branch (962:9): [True: 17.3M, False: 0]
  |  Branch (962:21): [True: 0, False: 17.3M]
  ------------------
  963|      0|        return 1;
  964|      0|    }
  965|  17.3M|    if (Y->s > 0 && X->s < 0) {
  ------------------
  |  Branch (965:9): [True: 17.3M, False: 0]
  |  Branch (965:21): [True: 0, False: 17.3M]
  ------------------
  966|      0|        return -1;
  967|      0|    }
  968|       |
  969|  17.8M|    for (; i > 0; i--) {
  ------------------
  |  Branch (969:12): [True: 17.4M, False: 348k]
  ------------------
  970|  17.4M|        if (X->p[i - 1] > Y->p[i - 1]) {
  ------------------
  |  Branch (970:13): [True: 2.27M, False: 15.2M]
  ------------------
  971|  2.27M|            return X->s;
  972|  2.27M|        }
  973|  15.2M|        if (X->p[i - 1] < Y->p[i - 1]) {
  ------------------
  |  Branch (973:13): [True: 14.7M, False: 464k]
  ------------------
  974|  14.7M|            return -X->s;
  975|  14.7M|        }
  976|  15.2M|    }
  977|       |
  978|   348k|    return 0;
  979|  17.3M|}
mbedtls_mpi_cmp_int:
  985|  15.2M|{
  986|  15.2M|    mbedtls_mpi Y;
  987|  15.2M|    mbedtls_mpi_uint p[1];
  988|       |
  989|  15.2M|    *p  = mpi_sint_abs(z);
  990|  15.2M|    Y.s = TO_SIGN(z);
  ------------------
  |  |  372|  15.2M|#define TO_SIGN(x) ((mbedtls_mpi_sint) (((mbedtls_mpi_uint) x) >> (biL - 1)) * -2 + 1)
  |  |  ------------------
  |  |  |  |   80|  15.2M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  |  |  ------------------
  |  |  |  |  |  |   79|  15.2M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  991|  15.2M|    Y.n = 1;
  992|  15.2M|    Y.p = p;
  993|       |
  994|  15.2M|    return mbedtls_mpi_cmp_mpi(X, &Y);
  995|  15.2M|}
mbedtls_mpi_add_abs:
 1001|  5.14M|{
 1002|  5.14M|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  5.14M|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1003|  5.14M|    size_t j;
 1004|  5.14M|    mbedtls_mpi_uint *p;
 1005|  5.14M|    mbedtls_mpi_uint c;
 1006|       |
 1007|  5.14M|    if (X == B) {
  ------------------
  |  Branch (1007:9): [True: 0, False: 5.14M]
  ------------------
 1008|      0|        const mbedtls_mpi *T = A; A = X; B = T;
 1009|      0|    }
 1010|       |
 1011|  5.14M|    if (X != A) {
  ------------------
  |  Branch (1011:9): [True: 650k, False: 4.49M]
  ------------------
 1012|   650k|        MBEDTLS_MPI_CHK(mbedtls_mpi_copy(X, A));
  ------------------
  |  |   41|   650k|    do                           \
  |  |   42|   650k|    {                            \
  |  |   43|   650k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 650k]
  |  |  ------------------
  |  |   44|   650k|        goto cleanup;        \
  |  |   45|   650k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1013|   650k|    }
 1014|       |
 1015|       |    /*
 1016|       |     * X must always be positive as a result of unsigned additions.
 1017|       |     */
 1018|  5.14M|    X->s = 1;
 1019|       |
 1020|  9.50M|    for (j = B->n; j > 0; j--) {
  ------------------
  |  Branch (1020:20): [True: 9.50M, False: 1.05k]
  ------------------
 1021|  9.50M|        if (B->p[j - 1] != 0) {
  ------------------
  |  Branch (1021:13): [True: 5.14M, False: 4.35M]
  ------------------
 1022|  5.14M|            break;
 1023|  5.14M|        }
 1024|  9.50M|    }
 1025|       |
 1026|       |    /* Exit early to avoid undefined behavior on NULL+0 when X->n == 0
 1027|       |     * and B is 0 (of any size). */
 1028|  5.14M|    if (j == 0) {
  ------------------
  |  Branch (1028:9): [True: 1.05k, False: 5.14M]
  ------------------
 1029|  1.05k|        return 0;
 1030|  1.05k|    }
 1031|       |
 1032|  5.14M|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, j));
  ------------------
  |  |   41|  5.14M|    do                           \
  |  |   42|  5.14M|    {                            \
  |  |   43|  5.14M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 5.14M]
  |  |  ------------------
  |  |   44|  5.14M|        goto cleanup;        \
  |  |   45|  5.14M|    } 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|  5.14M|    p = X->p;
 1037|       |
 1038|  5.14M|    c = mbedtls_mpi_core_add(p, p, B->p, j);
 1039|       |
 1040|  5.14M|    p += j;
 1041|       |
 1042|       |    /* Now propagate any carry */
 1043|       |
 1044|  7.41M|    while (c != 0) {
  ------------------
  |  Branch (1044:12): [True: 2.26M, False: 5.14M]
  ------------------
 1045|  2.26M|        if (j >= X->n) {
  ------------------
  |  Branch (1045:13): [True: 24.3k, False: 2.24M]
  ------------------
 1046|  24.3k|            MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, j + 1));
  ------------------
  |  |   41|  24.3k|    do                           \
  |  |   42|  24.3k|    {                            \
  |  |   43|  24.3k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 24.3k]
  |  |  ------------------
  |  |   44|  24.3k|        goto cleanup;        \
  |  |   45|  24.3k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1047|  24.3k|            p = X->p + j;
 1048|  24.3k|        }
 1049|       |
 1050|  2.26M|        *p += c; c = (*p < c); j++; p++;
 1051|  2.26M|    }
 1052|       |
 1053|  5.14M|cleanup:
 1054|       |
 1055|  5.14M|    return ret;
 1056|  5.14M|}
mbedtls_mpi_sub_abs:
 1062|  26.7M|{
 1063|  26.7M|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  26.7M|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1064|  26.7M|    size_t n;
 1065|  26.7M|    mbedtls_mpi_uint carry;
 1066|       |
 1067|  96.0M|    for (n = B->n; n > 0; n--) {
  ------------------
  |  Branch (1067:20): [True: 96.0M, False: 25.3k]
  ------------------
 1068|  96.0M|        if (B->p[n - 1] != 0) {
  ------------------
  |  Branch (1068:13): [True: 26.7M, False: 69.3M]
  ------------------
 1069|  26.7M|            break;
 1070|  26.7M|        }
 1071|  96.0M|    }
 1072|  26.7M|    if (n > A->n) {
  ------------------
  |  Branch (1072:9): [True: 0, False: 26.7M]
  ------------------
 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|  26.7M|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, A->n));
  ------------------
  |  |   41|  26.7M|    do                           \
  |  |   42|  26.7M|    {                            \
  |  |   43|  26.7M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 26.7M]
  |  |  ------------------
  |  |   44|  26.7M|        goto cleanup;        \
  |  |   45|  26.7M|    } 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|  26.7M|    if (A->n > n && A != X) {
  ------------------
  |  Branch (1083:9): [True: 16.2M, False: 10.5M]
  |  Branch (1083:21): [True: 3.81M, False: 12.4M]
  ------------------
 1084|  3.81M|        memcpy(X->p + n, A->p + n, (A->n - n) * ciL);
  ------------------
  |  |   79|  3.81M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
 1085|  3.81M|    }
 1086|  26.7M|    if (X->n > A->n) {
  ------------------
  |  Branch (1086:9): [True: 8.48M, False: 18.2M]
  ------------------
 1087|  8.48M|        memset(X->p + A->n, 0, (X->n - A->n) * ciL);
  ------------------
  |  |   79|  8.48M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
 1088|  8.48M|    }
 1089|       |
 1090|  26.7M|    carry = mbedtls_mpi_core_sub(X->p, A->p, B->p, n);
 1091|  26.7M|    if (carry != 0) {
  ------------------
  |  Branch (1091:9): [True: 5.93M, False: 20.7M]
  ------------------
 1092|       |        /* Propagate the carry through the rest of X. */
 1093|  5.93M|        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|  5.93M|        if (carry != 0) {
  ------------------
  |  Branch (1096:13): [True: 0, False: 5.93M]
  ------------------
 1097|      0|            ret = MBEDTLS_ERR_MPI_NEGATIVE_VALUE;
  ------------------
  |  |   32|      0|#define MBEDTLS_ERR_MPI_NEGATIVE_VALUE                    -0x000A
  ------------------
 1098|      0|            goto cleanup;
 1099|      0|        }
 1100|  5.93M|    }
 1101|       |
 1102|       |    /* X should always be positive as a result of unsigned subtractions. */
 1103|  26.7M|    X->s = 1;
 1104|       |
 1105|  26.7M|cleanup:
 1106|  26.7M|    return ret;
 1107|  26.7M|}
mbedtls_mpi_add_mpi:
 1146|  11.7M|{
 1147|  11.7M|    return add_sub_mpi(X, A, B, 1);
 1148|  11.7M|}
mbedtls_mpi_sub_mpi:
 1154|  13.9M|{
 1155|  13.9M|    return add_sub_mpi(X, A, B, -1);
 1156|  13.9M|}
mbedtls_mpi_sub_int:
 1178|  21.1k|{
 1179|  21.1k|    mbedtls_mpi B;
 1180|  21.1k|    mbedtls_mpi_uint p[1];
 1181|       |
 1182|  21.1k|    p[0] = mpi_sint_abs(b);
 1183|  21.1k|    B.s = TO_SIGN(b);
  ------------------
  |  |  372|  21.1k|#define TO_SIGN(x) ((mbedtls_mpi_sint) (((mbedtls_mpi_uint) x) >> (biL - 1)) * -2 + 1)
  |  |  ------------------
  |  |  |  |   80|  21.1k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  |  |  ------------------
  |  |  |  |  |  |   79|  21.1k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1184|  21.1k|    B.n = 1;
 1185|  21.1k|    B.p = p;
 1186|       |
 1187|  21.1k|    return mbedtls_mpi_sub_mpi(X, A, &B);
 1188|  21.1k|}
mbedtls_mpi_mul_mpi:
 1194|  8.31M|{
 1195|  8.31M|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  8.31M|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1196|  8.31M|    size_t i, j;
 1197|  8.31M|    mbedtls_mpi TA, TB;
 1198|  8.31M|    int result_is_zero = 0;
 1199|       |
 1200|  8.31M|    mbedtls_mpi_init(&TA);
 1201|  8.31M|    mbedtls_mpi_init(&TB);
 1202|       |
 1203|  8.31M|    if (X == A) {
  ------------------
  |  Branch (1203:9): [True: 2.33M, False: 5.97M]
  ------------------
 1204|  2.33M|        MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TA, A)); A = &TA;
  ------------------
  |  |   41|  2.33M|    do                           \
  |  |   42|  2.33M|    {                            \
  |  |   43|  2.33M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.33M]
  |  |  ------------------
  |  |   44|  2.33M|        goto cleanup;        \
  |  |   45|  2.33M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1205|  2.33M|    }
 1206|  8.31M|    if (X == B) {
  ------------------
  |  Branch (1206:9): [True: 27.4k, False: 8.28M]
  ------------------
 1207|  27.4k|        MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TB, B)); B = &TB;
  ------------------
  |  |   41|  27.4k|    do                           \
  |  |   42|  27.4k|    {                            \
  |  |   43|  27.4k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 27.4k]
  |  |  ------------------
  |  |   44|  27.4k|        goto cleanup;        \
  |  |   45|  27.4k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1208|  27.4k|    }
 1209|       |
 1210|  28.0M|    for (i = A->n; i > 0; i--) {
  ------------------
  |  Branch (1210:20): [True: 28.0M, False: 0]
  ------------------
 1211|  28.0M|        if (A->p[i - 1] != 0) {
  ------------------
  |  Branch (1211:13): [True: 8.31M, False: 19.7M]
  ------------------
 1212|  8.31M|            break;
 1213|  8.31M|        }
 1214|  28.0M|    }
 1215|  8.31M|    if (i == 0) {
  ------------------
  |  Branch (1215:9): [True: 0, False: 8.31M]
  ------------------
 1216|      0|        result_is_zero = 1;
 1217|      0|    }
 1218|       |
 1219|  37.0M|    for (j = B->n; j > 0; j--) {
  ------------------
  |  Branch (1219:20): [True: 37.0M, False: 0]
  ------------------
 1220|  37.0M|        if (B->p[j - 1] != 0) {
  ------------------
  |  Branch (1220:13): [True: 8.31M, False: 28.7M]
  ------------------
 1221|  8.31M|            break;
 1222|  8.31M|        }
 1223|  37.0M|    }
 1224|  8.31M|    if (j == 0) {
  ------------------
  |  Branch (1224:9): [True: 0, False: 8.31M]
  ------------------
 1225|      0|        result_is_zero = 1;
 1226|      0|    }
 1227|       |
 1228|  8.31M|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, i + j));
  ------------------
  |  |   41|  8.31M|    do                           \
  |  |   42|  8.31M|    {                            \
  |  |   43|  8.31M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 8.31M]
  |  |  ------------------
  |  |   44|  8.31M|        goto cleanup;        \
  |  |   45|  8.31M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1229|  8.31M|    MBEDTLS_MPI_CHK(mbedtls_mpi_lset(X, 0));
  ------------------
  |  |   41|  8.31M|    do                           \
  |  |   42|  8.31M|    {                            \
  |  |   43|  8.31M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 8.31M]
  |  |  ------------------
  |  |   44|  8.31M|        goto cleanup;        \
  |  |   45|  8.31M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1230|       |
 1231|  8.31M|    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|  8.31M|    if (result_is_zero) {
  ------------------
  |  Branch (1237:9): [True: 0, False: 8.31M]
  ------------------
 1238|      0|        X->s = 1;
 1239|  8.31M|    } else {
 1240|  8.31M|        X->s = A->s * B->s;
 1241|  8.31M|    }
 1242|       |
 1243|  8.31M|cleanup:
 1244|       |
 1245|  8.31M|    mbedtls_mpi_free(&TB); mbedtls_mpi_free(&TA);
 1246|       |
 1247|  8.31M|    return ret;
 1248|  8.31M|}
mbedtls_mpi_mul_int:
 1254|   693k|{
 1255|   693k|    size_t n = A->n;
 1256|  4.21M|    while (n > 0 && A->p[n - 1] == 0) {
  ------------------
  |  Branch (1256:12): [True: 4.21M, False: 0]
  |  Branch (1256:21): [True: 3.52M, False: 693k]
  ------------------
 1257|  3.52M|        --n;
 1258|  3.52M|    }
 1259|       |
 1260|       |    /* The general method below doesn't work if b==0. */
 1261|   693k|    if (b == 0 || n == 0) {
  ------------------
  |  Branch (1261:9): [True: 0, False: 693k]
  |  Branch (1261:19): [True: 0, False: 693k]
  ------------------
 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|   693k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|   693k|#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|   693k|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, n + 1));
  ------------------
  |  |   41|   693k|    do                           \
  |  |   42|   693k|    {                            \
  |  |   43|   693k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 693k]
  |  |  ------------------
  |  |   44|   693k|        goto cleanup;        \
  |  |   45|   693k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1279|   693k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(X, A));
  ------------------
  |  |   41|   693k|    do                           \
  |  |   42|   693k|    {                            \
  |  |   43|   693k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 693k]
  |  |  ------------------
  |  |   44|   693k|        goto cleanup;        \
  |  |   45|   693k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1280|   693k|    mbedtls_mpi_core_mla(X->p, X->n, A->p, n, b - 1);
 1281|       |
 1282|   693k|cleanup:
 1283|   693k|    return ret;
 1284|   693k|}
mbedtls_mpi_div_mpi:
 1395|  19.0k|{
 1396|  19.0k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  19.0k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1397|  19.0k|    size_t i, n, t, k;
 1398|  19.0k|    mbedtls_mpi X, Y, Z, T1, T2;
 1399|  19.0k|    mbedtls_mpi_uint TP2[3];
 1400|       |
 1401|  19.0k|    if (mbedtls_mpi_cmp_int(B, 0) == 0) {
  ------------------
  |  Branch (1401:9): [True: 0, False: 19.0k]
  ------------------
 1402|      0|        return MBEDTLS_ERR_MPI_DIVISION_BY_ZERO;
  ------------------
  |  |   34|      0|#define MBEDTLS_ERR_MPI_DIVISION_BY_ZERO                  -0x000C
  ------------------
 1403|      0|    }
 1404|       |
 1405|  19.0k|    mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y); mbedtls_mpi_init(&Z);
 1406|  19.0k|    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|  19.0k|    T2.s = 1;
 1415|  19.0k|    T2.n = sizeof(TP2) / sizeof(*TP2);
 1416|  19.0k|    T2.p = TP2;
 1417|       |
 1418|  19.0k|    if (mbedtls_mpi_cmp_abs(A, B) < 0) {
  ------------------
  |  Branch (1418:9): [True: 14.7k, False: 4.23k]
  ------------------
 1419|  14.7k|        if (Q != NULL) {
  ------------------
  |  Branch (1419:13): [True: 0, False: 14.7k]
  ------------------
 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|  14.7k|        if (R != NULL) {
  ------------------
  |  Branch (1422:13): [True: 14.7k, False: 0]
  ------------------
 1423|  14.7k|            MBEDTLS_MPI_CHK(mbedtls_mpi_copy(R, A));
  ------------------
  |  |   41|  14.7k|    do                           \
  |  |   42|  14.7k|    {                            \
  |  |   43|  14.7k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 14.7k]
  |  |  ------------------
  |  |   44|  14.7k|        goto cleanup;        \
  |  |   45|  14.7k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1424|  14.7k|        }
 1425|  14.7k|        return 0;
 1426|  14.7k|    }
 1427|       |
 1428|  4.23k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&X, A));
  ------------------
  |  |   41|  4.23k|    do                           \
  |  |   42|  4.23k|    {                            \
  |  |   43|  4.23k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.23k]
  |  |  ------------------
  |  |   44|  4.23k|        goto cleanup;        \
  |  |   45|  4.23k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1429|  4.23k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&Y, B));
  ------------------
  |  |   41|  4.23k|    do                           \
  |  |   42|  4.23k|    {                            \
  |  |   43|  4.23k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.23k]
  |  |  ------------------
  |  |   44|  4.23k|        goto cleanup;        \
  |  |   45|  4.23k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1430|  4.23k|    X.s = Y.s = 1;
 1431|       |
 1432|  4.23k|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(&Z, A->n + 2));
  ------------------
  |  |   41|  4.23k|    do                           \
  |  |   42|  4.23k|    {                            \
  |  |   43|  4.23k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.23k]
  |  |  ------------------
  |  |   44|  4.23k|        goto cleanup;        \
  |  |   45|  4.23k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1433|  4.23k|    MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&Z,  0));
  ------------------
  |  |   41|  4.23k|    do                           \
  |  |   42|  4.23k|    {                            \
  |  |   43|  4.23k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.23k]
  |  |  ------------------
  |  |   44|  4.23k|        goto cleanup;        \
  |  |   45|  4.23k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1434|  4.23k|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(&T1, A->n + 2));
  ------------------
  |  |   41|  4.23k|    do                           \
  |  |   42|  4.23k|    {                            \
  |  |   43|  4.23k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.23k]
  |  |  ------------------
  |  |   44|  4.23k|        goto cleanup;        \
  |  |   45|  4.23k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1435|       |
 1436|  4.23k|    k = mbedtls_mpi_bitlen(&Y) % biL;
  ------------------
  |  |   80|  4.23k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  4.23k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
 1437|  4.23k|    if (k < biL - 1) {
  ------------------
  |  |   80|  4.23k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  4.23k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  |  Branch (1437:9): [True: 4.23k, False: 0]
  ------------------
 1438|  4.23k|        k = biL - 1 - k;
  ------------------
  |  |   80|  4.23k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  4.23k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
 1439|  4.23k|        MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&X, k));
  ------------------
  |  |   41|  4.23k|    do                           \
  |  |   42|  4.23k|    {                            \
  |  |   43|  4.23k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.23k]
  |  |  ------------------
  |  |   44|  4.23k|        goto cleanup;        \
  |  |   45|  4.23k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1440|  4.23k|        MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&Y, k));
  ------------------
  |  |   41|  4.23k|    do                           \
  |  |   42|  4.23k|    {                            \
  |  |   43|  4.23k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.23k]
  |  |  ------------------
  |  |   44|  4.23k|        goto cleanup;        \
  |  |   45|  4.23k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1441|  4.23k|    } else {
 1442|      0|        k = 0;
 1443|      0|    }
 1444|       |
 1445|  4.23k|    n = X.n - 1;
 1446|  4.23k|    t = Y.n - 1;
 1447|  4.23k|    MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&Y, biL * (n - t)));
  ------------------
  |  |   41|  4.23k|    do                           \
  |  |   42|  4.23k|    {                            \
  |  |   43|  4.23k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.23k]
  |  |  ------------------
  |  |   44|  4.23k|        goto cleanup;        \
  |  |   45|  4.23k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1448|       |
 1449|  4.23k|    while (mbedtls_mpi_cmp_mpi(&X, &Y) >= 0) {
  ------------------
  |  Branch (1449:12): [True: 0, False: 4.23k]
  ------------------
 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|  4.23k|    MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&Y, biL * (n - t)));
  ------------------
  |  |   41|  4.23k|    do                           \
  |  |   42|  4.23k|    {                            \
  |  |   43|  4.23k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.23k]
  |  |  ------------------
  |  |   44|  4.23k|        goto cleanup;        \
  |  |   45|  4.23k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1454|       |
 1455|  21.1k|    for (i = n; i > t; i--) {
  ------------------
  |  Branch (1455:17): [True: 16.9k, False: 4.23k]
  ------------------
 1456|  16.9k|        if (X.p[i] >= Y.p[t]) {
  ------------------
  |  Branch (1456:13): [True: 0, False: 16.9k]
  ------------------
 1457|      0|            Z.p[i - t - 1] = ~(mbedtls_mpi_uint) 0u;
 1458|  16.9k|        } else {
 1459|  16.9k|            Z.p[i - t - 1] = mbedtls_int_div_int(X.p[i], X.p[i - 1],
 1460|  16.9k|                                                 Y.p[t], NULL);
 1461|  16.9k|        }
 1462|       |
 1463|  16.9k|        T2.p[0] = (i < 2) ? 0 : X.p[i - 2];
  ------------------
  |  Branch (1463:19): [True: 0, False: 16.9k]
  ------------------
 1464|  16.9k|        T2.p[1] = (i < 1) ? 0 : X.p[i - 1];
  ------------------
  |  Branch (1464:19): [True: 0, False: 16.9k]
  ------------------
 1465|  16.9k|        T2.p[2] = X.p[i];
 1466|       |
 1467|  16.9k|        Z.p[i - t - 1]++;
 1468|  25.4k|        do {
 1469|  25.4k|            Z.p[i - t - 1]--;
 1470|       |
 1471|  25.4k|            MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&T1, 0));
  ------------------
  |  |   41|  25.4k|    do                           \
  |  |   42|  25.4k|    {                            \
  |  |   43|  25.4k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 25.4k]
  |  |  ------------------
  |  |   44|  25.4k|        goto cleanup;        \
  |  |   45|  25.4k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1472|  25.4k|            T1.p[0] = (t < 1) ? 0 : Y.p[t - 1];
  ------------------
  |  Branch (1472:23): [True: 0, False: 25.4k]
  ------------------
 1473|  25.4k|            T1.p[1] = Y.p[t];
 1474|  25.4k|            MBEDTLS_MPI_CHK(mbedtls_mpi_mul_int(&T1, &T1, Z.p[i - t - 1]));
  ------------------
  |  |   41|  25.4k|    do                           \
  |  |   42|  25.4k|    {                            \
  |  |   43|  25.4k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 25.4k]
  |  |  ------------------
  |  |   44|  25.4k|        goto cleanup;        \
  |  |   45|  25.4k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1475|  25.4k|        } while (mbedtls_mpi_cmp_mpi(&T1, &T2) > 0);
  ------------------
  |  Branch (1475:18): [True: 8.46k, False: 16.9k]
  ------------------
 1476|       |
 1477|  16.9k|        MBEDTLS_MPI_CHK(mbedtls_mpi_mul_int(&T1, &Y, Z.p[i - t - 1]));
  ------------------
  |  |   41|  16.9k|    do                           \
  |  |   42|  16.9k|    {                            \
  |  |   43|  16.9k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 16.9k]
  |  |  ------------------
  |  |   44|  16.9k|        goto cleanup;        \
  |  |   45|  16.9k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1478|  16.9k|        MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&T1,  biL * (i - t - 1)));
  ------------------
  |  |   41|  16.9k|    do                           \
  |  |   42|  16.9k|    {                            \
  |  |   43|  16.9k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 16.9k]
  |  |  ------------------
  |  |   44|  16.9k|        goto cleanup;        \
  |  |   45|  16.9k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1479|  16.9k|        MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&X, &X, &T1));
  ------------------
  |  |   41|  16.9k|    do                           \
  |  |   42|  16.9k|    {                            \
  |  |   43|  16.9k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 16.9k]
  |  |  ------------------
  |  |   44|  16.9k|        goto cleanup;        \
  |  |   45|  16.9k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1480|       |
 1481|  16.9k|        if (mbedtls_mpi_cmp_int(&X, 0) < 0) {
  ------------------
  |  Branch (1481:13): [True: 0, False: 16.9k]
  ------------------
 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|  16.9k|    }
 1488|       |
 1489|  4.23k|    if (Q != NULL) {
  ------------------
  |  Branch (1489:9): [True: 0, False: 4.23k]
  ------------------
 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|  4.23k|    if (R != NULL) {
  ------------------
  |  Branch (1494:9): [True: 4.23k, False: 0]
  ------------------
 1495|  4.23k|        MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&X, k));
  ------------------
  |  |   41|  4.23k|    do                           \
  |  |   42|  4.23k|    {                            \
  |  |   43|  4.23k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.23k]
  |  |  ------------------
  |  |   44|  4.23k|        goto cleanup;        \
  |  |   45|  4.23k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1496|  4.23k|        X.s = A->s;
 1497|  4.23k|        MBEDTLS_MPI_CHK(mbedtls_mpi_copy(R, &X));
  ------------------
  |  |   41|  4.23k|    do                           \
  |  |   42|  4.23k|    {                            \
  |  |   43|  4.23k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.23k]
  |  |  ------------------
  |  |   44|  4.23k|        goto cleanup;        \
  |  |   45|  4.23k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1498|       |
 1499|  4.23k|        if (mbedtls_mpi_cmp_int(R, 0) == 0) {
  ------------------
  |  Branch (1499:13): [True: 0, False: 4.23k]
  ------------------
 1500|      0|            R->s = 1;
 1501|      0|        }
 1502|  4.23k|    }
 1503|       |
 1504|  4.23k|cleanup:
 1505|       |
 1506|  4.23k|    mbedtls_mpi_free(&X); mbedtls_mpi_free(&Y); mbedtls_mpi_free(&Z);
 1507|  4.23k|    mbedtls_mpi_free(&T1);
 1508|  4.23k|    mbedtls_platform_zeroize(TP2, sizeof(TP2));
 1509|       |
 1510|  4.23k|    return ret;
 1511|  4.23k|}
mbedtls_mpi_mod_mpi:
 1535|  19.0k|{
 1536|  19.0k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  19.0k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1537|       |
 1538|  19.0k|    if (mbedtls_mpi_cmp_int(B, 0) < 0) {
  ------------------
  |  Branch (1538:9): [True: 0, False: 19.0k]
  ------------------
 1539|      0|        return MBEDTLS_ERR_MPI_NEGATIVE_VALUE;
  ------------------
  |  |   32|      0|#define MBEDTLS_ERR_MPI_NEGATIVE_VALUE                    -0x000A
  ------------------
 1540|      0|    }
 1541|       |
 1542|  19.0k|    MBEDTLS_MPI_CHK(mbedtls_mpi_div_mpi(NULL, R, A, B));
  ------------------
  |  |   41|  19.0k|    do                           \
  |  |   42|  19.0k|    {                            \
  |  |   43|  19.0k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 19.0k]
  |  |  ------------------
  |  |   44|  19.0k|        goto cleanup;        \
  |  |   45|  19.0k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1543|       |
 1544|  19.0k|    while (mbedtls_mpi_cmp_int(R, 0) < 0) {
  ------------------
  |  Branch (1544:12): [True: 0, False: 19.0k]
  ------------------
 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|  19.0k|    while (mbedtls_mpi_cmp_mpi(R, B) >= 0) {
  ------------------
  |  Branch (1548:12): [True: 0, False: 19.0k]
  ------------------
 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|  19.0k|cleanup:
 1553|       |
 1554|  19.0k|    return ret;
 1555|  19.0k|}
mbedtls_mpi_gcd:
 1750|  12.6k|{
 1751|  12.6k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  12.6k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1752|  12.6k|    size_t lz, lzt;
 1753|  12.6k|    mbedtls_mpi TA, TB;
 1754|       |
 1755|  12.6k|    mbedtls_mpi_init(&TA); mbedtls_mpi_init(&TB);
 1756|       |
 1757|  12.6k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TA, A));
  ------------------
  |  |   41|  12.6k|    do                           \
  |  |   42|  12.6k|    {                            \
  |  |   43|  12.6k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 12.6k]
  |  |  ------------------
  |  |   44|  12.6k|        goto cleanup;        \
  |  |   45|  12.6k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1758|  12.6k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TB, B));
  ------------------
  |  |   41|  12.6k|    do                           \
  |  |   42|  12.6k|    {                            \
  |  |   43|  12.6k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 12.6k]
  |  |  ------------------
  |  |   44|  12.6k|        goto cleanup;        \
  |  |   45|  12.6k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1759|       |
 1760|  12.6k|    lz = mbedtls_mpi_lsb(&TA);
 1761|  12.6k|    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|  12.6k|    if (lzt == 0 && mbedtls_mpi_get_bit(&TB, 0) == 0) {
  ------------------
  |  Branch (1767:9): [True: 12.6k, False: 0]
  |  Branch (1767:21): [True: 0, False: 12.6k]
  ------------------
 1768|      0|        ret = mbedtls_mpi_copy(G, A);
 1769|      0|        goto cleanup;
 1770|      0|    }
 1771|       |
 1772|  12.6k|    if (lzt < lz) {
  ------------------
  |  Branch (1772:9): [True: 7.39k, False: 5.28k]
  ------------------
 1773|  7.39k|        lz = lzt;
 1774|  7.39k|    }
 1775|       |
 1776|  12.6k|    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|  2.30M|    while (mbedtls_mpi_cmp_int(&TA, 0) != 0) {
  ------------------
  |  Branch (1811:12): [True: 2.29M, False: 12.6k]
  ------------------
 1812|       |        /* Divisions by 2 preserve the invariant (I). */
 1813|  2.29M|        MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TA, mbedtls_mpi_lsb(&TA)));
  ------------------
  |  |   41|  2.29M|    do                           \
  |  |   42|  2.29M|    {                            \
  |  |   43|  2.29M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.29M]
  |  |  ------------------
  |  |   44|  2.29M|        goto cleanup;        \
  |  |   45|  2.29M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1814|  2.29M|        MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TB, mbedtls_mpi_lsb(&TB)));
  ------------------
  |  |   41|  2.29M|    do                           \
  |  |   42|  2.29M|    {                            \
  |  |   43|  2.29M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.29M]
  |  |  ------------------
  |  |   44|  2.29M|        goto cleanup;        \
  |  |   45|  2.29M|    } 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|  2.29M|        if (mbedtls_mpi_cmp_mpi(&TA, &TB) >= 0) {
  ------------------
  |  Branch (1823:13): [True: 1.17M, False: 1.11M]
  ------------------
 1824|  1.17M|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs(&TA, &TA, &TB));
  ------------------
  |  |   41|  1.17M|    do                           \
  |  |   42|  1.17M|    {                            \
  |  |   43|  1.17M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.17M]
  |  |  ------------------
  |  |   44|  1.17M|        goto cleanup;        \
  |  |   45|  1.17M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1825|  1.17M|            MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TA, 1));
  ------------------
  |  |   41|  1.17M|    do                           \
  |  |   42|  1.17M|    {                            \
  |  |   43|  1.17M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.17M]
  |  |  ------------------
  |  |   44|  1.17M|        goto cleanup;        \
  |  |   45|  1.17M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1826|  1.17M|        } else {
 1827|  1.11M|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs(&TB, &TB, &TA));
  ------------------
  |  |   41|  1.11M|    do                           \
  |  |   42|  1.11M|    {                            \
  |  |   43|  1.11M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.11M]
  |  |  ------------------
  |  |   44|  1.11M|        goto cleanup;        \
  |  |   45|  1.11M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1828|  1.11M|            MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TB, 1));
  ------------------
  |  |   41|  1.11M|    do                           \
  |  |   42|  1.11M|    {                            \
  |  |   43|  1.11M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.11M]
  |  |  ------------------
  |  |   44|  1.11M|        goto cleanup;        \
  |  |   45|  1.11M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1829|  1.11M|        }
 1830|       |        /* Note that one of TA or TB is still odd. */
 1831|  2.29M|    }
 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|  12.6k|    MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&TB, lz));
  ------------------
  |  |   41|  12.6k|    do                           \
  |  |   42|  12.6k|    {                            \
  |  |   43|  12.6k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 12.6k]
  |  |  ------------------
  |  |   44|  12.6k|        goto cleanup;        \
  |  |   45|  12.6k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1843|  12.6k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(G, &TB));
  ------------------
  |  |   41|  12.6k|    do                           \
  |  |   42|  12.6k|    {                            \
  |  |   43|  12.6k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 12.6k]
  |  |  ------------------
  |  |   44|  12.6k|        goto cleanup;        \
  |  |   45|  12.6k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1844|       |
 1845|  12.6k|cleanup:
 1846|       |
 1847|  12.6k|    mbedtls_mpi_free(&TA); mbedtls_mpi_free(&TB);
 1848|       |
 1849|  12.6k|    return ret;
 1850|  12.6k|}
mbedtls_mpi_random:
 1882|     12|{
 1883|     12|    if (min < 0) {
  ------------------
  |  Branch (1883:9): [True: 0, False: 12]
  ------------------
 1884|      0|        return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MPI_BAD_INPUT_DATA                    -0x0004
  ------------------
 1885|      0|    }
 1886|     12|    if (mbedtls_mpi_cmp_int(N, min) <= 0) {
  ------------------
  |  Branch (1886:9): [True: 0, False: 12]
  ------------------
 1887|      0|        return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MPI_BAD_INPUT_DATA                    -0x0004
  ------------------
 1888|      0|    }
 1889|       |
 1890|       |    /* Ensure that target MPI has exactly the same number of limbs
 1891|       |     * as the upper bound, even if the upper bound has leading zeros.
 1892|       |     * This is necessary for mbedtls_mpi_core_random. */
 1893|     12|    int ret = mbedtls_mpi_resize_clear(X, N->n);
 1894|     12|    if (ret != 0) {
  ------------------
  |  Branch (1894:9): [True: 0, False: 12]
  ------------------
 1895|      0|        return ret;
 1896|      0|    }
 1897|       |
 1898|     12|    return mbedtls_mpi_core_random(X->p, min, N->p, X->n, f_rng, p_rng);
 1899|     12|}
mbedtls_mpi_inv_mod:
 1905|  12.6k|{
 1906|  12.6k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  12.6k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1907|  12.6k|    mbedtls_mpi G, TA, TU, U1, U2, TB, TV, V1, V2;
 1908|       |
 1909|  12.6k|    if (mbedtls_mpi_cmp_int(N, 1) <= 0) {
  ------------------
  |  Branch (1909:9): [True: 0, False: 12.6k]
  ------------------
 1910|      0|        return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MPI_BAD_INPUT_DATA                    -0x0004
  ------------------
 1911|      0|    }
 1912|       |
 1913|  12.6k|    mbedtls_mpi_init(&TA); mbedtls_mpi_init(&TU); mbedtls_mpi_init(&U1); mbedtls_mpi_init(&U2);
 1914|  12.6k|    mbedtls_mpi_init(&G); mbedtls_mpi_init(&TB); mbedtls_mpi_init(&TV);
 1915|  12.6k|    mbedtls_mpi_init(&V1); mbedtls_mpi_init(&V2);
 1916|       |
 1917|  12.6k|    MBEDTLS_MPI_CHK(mbedtls_mpi_gcd(&G, A, N));
  ------------------
  |  |   41|  12.6k|    do                           \
  |  |   42|  12.6k|    {                            \
  |  |   43|  12.6k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 12.6k]
  |  |  ------------------
  |  |   44|  12.6k|        goto cleanup;        \
  |  |   45|  12.6k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1918|       |
 1919|  12.6k|    if (mbedtls_mpi_cmp_int(&G, 1) != 0) {
  ------------------
  |  Branch (1919:9): [True: 0, False: 12.6k]
  ------------------
 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|  12.6k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&TA, A, N));
  ------------------
  |  |   41|  12.6k|    do                           \
  |  |   42|  12.6k|    {                            \
  |  |   43|  12.6k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 12.6k]
  |  |  ------------------
  |  |   44|  12.6k|        goto cleanup;        \
  |  |   45|  12.6k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1925|  12.6k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TU, &TA));
  ------------------
  |  |   41|  12.6k|    do                           \
  |  |   42|  12.6k|    {                            \
  |  |   43|  12.6k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 12.6k]
  |  |  ------------------
  |  |   44|  12.6k|        goto cleanup;        \
  |  |   45|  12.6k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1926|  12.6k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TB, N));
  ------------------
  |  |   41|  12.6k|    do                           \
  |  |   42|  12.6k|    {                            \
  |  |   43|  12.6k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 12.6k]
  |  |  ------------------
  |  |   44|  12.6k|        goto cleanup;        \
  |  |   45|  12.6k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1927|  12.6k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TV, N));
  ------------------
  |  |   41|  12.6k|    do                           \
  |  |   42|  12.6k|    {                            \
  |  |   43|  12.6k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 12.6k]
  |  |  ------------------
  |  |   44|  12.6k|        goto cleanup;        \
  |  |   45|  12.6k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1928|       |
 1929|  12.6k|    MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&U1, 1));
  ------------------
  |  |   41|  12.6k|    do                           \
  |  |   42|  12.6k|    {                            \
  |  |   43|  12.6k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 12.6k]
  |  |  ------------------
  |  |   44|  12.6k|        goto cleanup;        \
  |  |   45|  12.6k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1930|  12.6k|    MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&U2, 0));
  ------------------
  |  |   41|  12.6k|    do                           \
  |  |   42|  12.6k|    {                            \
  |  |   43|  12.6k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 12.6k]
  |  |  ------------------
  |  |   44|  12.6k|        goto cleanup;        \
  |  |   45|  12.6k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1931|  12.6k|    MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&V1, 0));
  ------------------
  |  |   41|  12.6k|    do                           \
  |  |   42|  12.6k|    {                            \
  |  |   43|  12.6k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 12.6k]
  |  |  ------------------
  |  |   44|  12.6k|        goto cleanup;        \
  |  |   45|  12.6k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1932|  12.6k|    MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&V2, 1));
  ------------------
  |  |   41|  12.6k|    do                           \
  |  |   42|  12.6k|    {                            \
  |  |   43|  12.6k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 12.6k]
  |  |  ------------------
  |  |   44|  12.6k|        goto cleanup;        \
  |  |   45|  12.6k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1933|       |
 1934|  2.29M|    do {
 1935|  4.59M|        while ((TU.p[0] & 1) == 0) {
  ------------------
  |  Branch (1935:16): [True: 2.30M, False: 2.29M]
  ------------------
 1936|  2.30M|            MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TU, 1));
  ------------------
  |  |   41|  2.30M|    do                           \
  |  |   42|  2.30M|    {                            \
  |  |   43|  2.30M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.30M]
  |  |  ------------------
  |  |   44|  2.30M|        goto cleanup;        \
  |  |   45|  2.30M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1937|       |
 1938|  2.30M|            if ((U1.p[0] & 1) != 0 || (U2.p[0] & 1) != 0) {
  ------------------
  |  Branch (1938:17): [True: 955k, False: 1.35M]
  |  Branch (1938:39): [True: 0, False: 1.35M]
  ------------------
 1939|   955k|                MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&U1, &U1, &TB));
  ------------------
  |  |   41|   955k|    do                           \
  |  |   42|   955k|    {                            \
  |  |   43|   955k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 955k]
  |  |  ------------------
  |  |   44|   955k|        goto cleanup;        \
  |  |   45|   955k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1940|   955k|                MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&U2, &U2, &TA));
  ------------------
  |  |   41|   955k|    do                           \
  |  |   42|   955k|    {                            \
  |  |   43|   955k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 955k]
  |  |  ------------------
  |  |   44|   955k|        goto cleanup;        \
  |  |   45|   955k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1941|   955k|            }
 1942|       |
 1943|  2.30M|            MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&U1, 1));
  ------------------
  |  |   41|  2.30M|    do                           \
  |  |   42|  2.30M|    {                            \
  |  |   43|  2.30M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.30M]
  |  |  ------------------
  |  |   44|  2.30M|        goto cleanup;        \
  |  |   45|  2.30M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1944|  2.30M|            MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&U2, 1));
  ------------------
  |  |   41|  2.30M|    do                           \
  |  |   42|  2.30M|    {                            \
  |  |   43|  2.30M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.30M]
  |  |  ------------------
  |  |   44|  2.30M|        goto cleanup;        \
  |  |   45|  2.30M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1945|  2.30M|        }
 1946|       |
 1947|  4.54M|        while ((TV.p[0] & 1) == 0) {
  ------------------
  |  Branch (1947:16): [True: 2.25M, False: 2.29M]
  ------------------
 1948|  2.25M|            MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TV, 1));
  ------------------
  |  |   41|  2.25M|    do                           \
  |  |   42|  2.25M|    {                            \
  |  |   43|  2.25M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.25M]
  |  |  ------------------
  |  |   44|  2.25M|        goto cleanup;        \
  |  |   45|  2.25M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1949|       |
 1950|  2.25M|            if ((V1.p[0] & 1) != 0 || (V2.p[0] & 1) != 0) {
  ------------------
  |  Branch (1950:17): [True: 1.00M, False: 1.24M]
  |  Branch (1950:39): [True: 0, False: 1.24M]
  ------------------
 1951|  1.00M|                MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&V1, &V1, &TB));
  ------------------
  |  |   41|  1.00M|    do                           \
  |  |   42|  1.00M|    {                            \
  |  |   43|  1.00M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.00M]
  |  |  ------------------
  |  |   44|  1.00M|        goto cleanup;        \
  |  |   45|  1.00M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1952|  1.00M|                MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&V2, &V2, &TA));
  ------------------
  |  |   41|  1.00M|    do                           \
  |  |   42|  1.00M|    {                            \
  |  |   43|  1.00M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.00M]
  |  |  ------------------
  |  |   44|  1.00M|        goto cleanup;        \
  |  |   45|  1.00M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1953|  1.00M|            }
 1954|       |
 1955|  2.25M|            MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&V1, 1));
  ------------------
  |  |   41|  2.25M|    do                           \
  |  |   42|  2.25M|    {                            \
  |  |   43|  2.25M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.25M]
  |  |  ------------------
  |  |   44|  2.25M|        goto cleanup;        \
  |  |   45|  2.25M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1956|  2.25M|            MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&V2, 1));
  ------------------
  |  |   41|  2.25M|    do                           \
  |  |   42|  2.25M|    {                            \
  |  |   43|  2.25M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.25M]
  |  |  ------------------
  |  |   44|  2.25M|        goto cleanup;        \
  |  |   45|  2.25M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1957|  2.25M|        }
 1958|       |
 1959|  2.29M|        if (mbedtls_mpi_cmp_mpi(&TU, &TV) >= 0) {
  ------------------
  |  Branch (1959:13): [True: 1.17M, False: 1.11M]
  ------------------
 1960|  1.17M|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&TU, &TU, &TV));
  ------------------
  |  |   41|  1.17M|    do                           \
  |  |   42|  1.17M|    {                            \
  |  |   43|  1.17M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.17M]
  |  |  ------------------
  |  |   44|  1.17M|        goto cleanup;        \
  |  |   45|  1.17M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1961|  1.17M|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&U1, &U1, &V1));
  ------------------
  |  |   41|  1.17M|    do                           \
  |  |   42|  1.17M|    {                            \
  |  |   43|  1.17M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.17M]
  |  |  ------------------
  |  |   44|  1.17M|        goto cleanup;        \
  |  |   45|  1.17M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1962|  1.17M|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&U2, &U2, &V2));
  ------------------
  |  |   41|  1.17M|    do                           \
  |  |   42|  1.17M|    {                            \
  |  |   43|  1.17M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.17M]
  |  |  ------------------
  |  |   44|  1.17M|        goto cleanup;        \
  |  |   45|  1.17M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1963|  1.17M|        } else {
 1964|  1.11M|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&TV, &TV, &TU));
  ------------------
  |  |   41|  1.11M|    do                           \
  |  |   42|  1.11M|    {                            \
  |  |   43|  1.11M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.11M]
  |  |  ------------------
  |  |   44|  1.11M|        goto cleanup;        \
  |  |   45|  1.11M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1965|  1.11M|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&V1, &V1, &U1));
  ------------------
  |  |   41|  1.11M|    do                           \
  |  |   42|  1.11M|    {                            \
  |  |   43|  1.11M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.11M]
  |  |  ------------------
  |  |   44|  1.11M|        goto cleanup;        \
  |  |   45|  1.11M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1966|  1.11M|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&V2, &V2, &U2));
  ------------------
  |  |   41|  1.11M|    do                           \
  |  |   42|  1.11M|    {                            \
  |  |   43|  1.11M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.11M]
  |  |  ------------------
  |  |   44|  1.11M|        goto cleanup;        \
  |  |   45|  1.11M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1967|  1.11M|        }
 1968|  2.29M|    } while (mbedtls_mpi_cmp_int(&TU, 0) != 0);
  ------------------
  |  Branch (1968:14): [True: 2.27M, False: 12.6k]
  ------------------
 1969|       |
 1970|  13.7k|    while (mbedtls_mpi_cmp_int(&V1, 0) < 0) {
  ------------------
  |  Branch (1970:12): [True: 1.05k, False: 12.6k]
  ------------------
 1971|  1.05k|        MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&V1, &V1, N));
  ------------------
  |  |   41|  1.05k|    do                           \
  |  |   42|  1.05k|    {                            \
  |  |   43|  1.05k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.05k]
  |  |  ------------------
  |  |   44|  1.05k|        goto cleanup;        \
  |  |   45|  1.05k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1972|  1.05k|    }
 1973|       |
 1974|  12.6k|    while (mbedtls_mpi_cmp_mpi(&V1, N) >= 0) {
  ------------------
  |  Branch (1974:12): [True: 0, False: 12.6k]
  ------------------
 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|  12.6k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(X, &V1));
  ------------------
  |  |   41|  12.6k|    do                           \
  |  |   42|  12.6k|    {                            \
  |  |   43|  12.6k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 12.6k]
  |  |  ------------------
  |  |   44|  12.6k|        goto cleanup;        \
  |  |   45|  12.6k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1979|       |
 1980|  12.6k|cleanup:
 1981|       |
 1982|  12.6k|    mbedtls_mpi_free(&TA); mbedtls_mpi_free(&TU); mbedtls_mpi_free(&U1); mbedtls_mpi_free(&U2);
 1983|  12.6k|    mbedtls_mpi_free(&G); mbedtls_mpi_free(&TB); mbedtls_mpi_free(&TV);
 1984|  12.6k|    mbedtls_mpi_free(&V1); mbedtls_mpi_free(&V2);
 1985|       |
 1986|  12.6k|    return ret;
 1987|  12.6k|}
bignum.c:mbedtls_ct_mpi_sign_if:
   50|  6.04M|{
   51|  6.04M|    return (signed short) mbedtls_ct_uint_if(cond, sign1 + 1, sign2 + 1) - 1;
   52|  6.04M|}
bignum.c:mpi_sint_abs:
  359|  23.9M|{
  360|  23.9M|    if (z >= 0) {
  ------------------
  |  Branch (360:9): [True: 23.9M, False: 4.22k]
  ------------------
  361|  23.9M|        return z;
  362|  23.9M|    }
  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|  4.22k|    return (mbedtls_mpi_uint) 0 - (mbedtls_mpi_uint) z;
  368|  23.9M|}
bignum.c:mbedtls_mpi_resize_clear:
  285|  40.1k|{
  286|  40.1k|    if (limbs == 0) {
  ------------------
  |  Branch (286:9): [True: 0, False: 40.1k]
  ------------------
  287|      0|        mbedtls_mpi_free(X);
  288|      0|        return 0;
  289|  40.1k|    } else if (X->n == limbs) {
  ------------------
  |  Branch (289:16): [True: 0, False: 40.1k]
  ------------------
  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|  40.1k|    } else {
  294|  40.1k|        mbedtls_mpi_free(X);
  295|  40.1k|        return mbedtls_mpi_grow(X, limbs);
  296|  40.1k|    }
  297|  40.1k|}
bignum.c:add_sub_mpi:
 1115|  25.7M|{
 1116|  25.7M|    int ret, s;
 1117|       |
 1118|  25.7M|    s = A->s;
 1119|  25.7M|    if (A->s * B->s * flip_B < 0) {
  ------------------
  |  Branch (1119:9): [True: 20.5M, False: 5.14M]
  ------------------
 1120|  20.5M|        int cmp = mbedtls_mpi_cmp_abs(A, B);
 1121|  20.5M|        if (cmp >= 0) {
  ------------------
  |  Branch (1121:13): [True: 8.29M, False: 12.2M]
  ------------------
 1122|  8.29M|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs(X, A, B));
  ------------------
  |  |   41|  8.29M|    do                           \
  |  |   42|  8.29M|    {                            \
  |  |   43|  8.29M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 8.29M]
  |  |  ------------------
  |  |   44|  8.29M|        goto cleanup;        \
  |  |   45|  8.29M|    } 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|  8.29M|            X->s = cmp == 0 ? 1 : s;
  ------------------
  |  Branch (1126:20): [True: 29.5k, False: 8.26M]
  ------------------
 1127|  12.2M|        } else {
 1128|  12.2M|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs(X, B, A));
  ------------------
  |  |   41|  12.2M|    do                           \
  |  |   42|  12.2M|    {                            \
  |  |   43|  12.2M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 12.2M]
  |  |  ------------------
  |  |   44|  12.2M|        goto cleanup;        \
  |  |   45|  12.2M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1129|       |            /* Since |A| < |B|, the sign is the opposite of A. */
 1130|  12.2M|            X->s = -s;
 1131|  12.2M|        }
 1132|  20.5M|    } else {
 1133|  5.14M|        MBEDTLS_MPI_CHK(mbedtls_mpi_add_abs(X, A, B));
  ------------------
  |  |   41|  5.14M|    do                           \
  |  |   42|  5.14M|    {                            \
  |  |   43|  5.14M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 5.14M]
  |  |  ------------------
  |  |   44|  5.14M|        goto cleanup;        \
  |  |   45|  5.14M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1134|  5.14M|        X->s = s;
 1135|  5.14M|    }
 1136|       |
 1137|  25.7M|cleanup:
 1138|       |
 1139|  25.7M|    return ret;
 1140|  25.7M|}
bignum.c:mbedtls_int_div_int:
 1294|  16.9k|{
 1295|  16.9k|#if defined(MBEDTLS_HAVE_UDBL)
 1296|  16.9k|    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|  16.9k|    if (0 == d || u1 >= d) {
  ------------------
  |  Branch (1308:9): [True: 0, False: 16.9k]
  |  Branch (1308:19): [True: 0, False: 16.9k]
  ------------------
 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|  16.9k|#if defined(MBEDTLS_HAVE_UDBL)
 1317|  16.9k|    dividend  = (mbedtls_t_udbl) u1 << biL;
  ------------------
  |  |   80|  16.9k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  16.9k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
 1318|  16.9k|    dividend |= (mbedtls_t_udbl) u0;
 1319|  16.9k|    quotient = dividend / d;
 1320|  16.9k|    if (quotient > ((mbedtls_t_udbl) 1 << biL) - 1) {
  ------------------
  |  |   80|  16.9k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  16.9k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  |  Branch (1320:9): [True: 0, False: 16.9k]
  ------------------
 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|  16.9k|    if (r != NULL) {
  ------------------
  |  Branch (1324:9): [True: 0, False: 16.9k]
  ------------------
 1325|      0|        *r = (mbedtls_mpi_uint) (dividend - (quotient * d));
 1326|      0|    }
 1327|       |
 1328|  16.9k|    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|  16.9k|}

mbedtls_mpi_core_clz:
   25|  11.2M|{
   26|  11.2M|#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|  11.2M|#endif
   35|  11.2M|#if defined(core_clz)
   36|  11.2M|    return (size_t) core_clz(a);
  ------------------
  |  |   30|  11.2M|    #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|  11.2M|}
mbedtls_mpi_core_bitlen:
   54|  11.2M|{
   55|  11.2M|    int i;
   56|  11.2M|    size_t j;
   57|       |
   58|  34.0M|    for (i = ((int) A_limbs) - 1; i >= 0; i--) {
  ------------------
  |  Branch (58:35): [True: 34.0M, False: 0]
  ------------------
   59|  34.0M|        if (A[i] != 0) {
  ------------------
  |  Branch (59:13): [True: 11.2M, False: 22.7M]
  ------------------
   60|  11.2M|            j = biL - mbedtls_mpi_core_clz(A[i]);
  ------------------
  |  |   80|  11.2M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  11.2M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
   61|  11.2M|            return (i * biL) + j;
  ------------------
  |  |   80|  11.2M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  11.2M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
   62|  11.2M|        }
   63|  34.0M|    }
   64|       |
   65|      0|    return 0;
   66|  11.2M|}
mbedtls_mpi_core_bigendian_to_host:
   84|  40.1k|{
   85|  40.1k|    mbedtls_mpi_uint *cur_limb_left;
   86|  40.1k|    mbedtls_mpi_uint *cur_limb_right;
   87|  40.1k|    if (A_limbs == 0) {
  ------------------
  |  Branch (87:9): [True: 0, False: 40.1k]
  ------------------
   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|  40.1k|    for (cur_limb_left = A, cur_limb_right = A + (A_limbs - 1);
  101|   122k|         cur_limb_left <= cur_limb_right;
  ------------------
  |  Branch (101:10): [True: 82.4k, False: 40.1k]
  ------------------
  102|  82.4k|         cur_limb_left++, cur_limb_right--) {
  103|  82.4k|        mbedtls_mpi_uint tmp;
  104|       |        /* Note that if cur_limb_left == cur_limb_right,
  105|       |         * this code effectively swaps the bytes only once. */
  106|  82.4k|        tmp             = mpi_bigendian_to_host(*cur_limb_left);
  107|  82.4k|        *cur_limb_left  = mpi_bigendian_to_host(*cur_limb_right);
  108|  82.4k|        *cur_limb_right = tmp;
  109|  82.4k|    }
  110|  40.1k|}
mbedtls_mpi_core_uint_le_mpi:
  117|     12|{
  118|       |    /* min <= least significant limb? */
  119|     12|    mbedtls_ct_condition_t min_le_lsl = mbedtls_ct_uint_ge(A[0], min);
  120|       |
  121|       |    /* limbs other than the least significant one are all zero? */
  122|     12|    mbedtls_ct_condition_t msll_mask = MBEDTLS_CT_FALSE;
  ------------------
  |  |   86|     12|#define MBEDTLS_CT_FALSE ((mbedtls_ct_condition_t) mbedtls_ct_compiler_opaque(0))
  ------------------
  123|     48|    for (size_t i = 1; i < A_limbs; i++) {
  ------------------
  |  Branch (123:24): [True: 36, False: 12]
  ------------------
  124|     36|        msll_mask = mbedtls_ct_bool_or(msll_mask, mbedtls_ct_bool(A[i]));
  125|     36|    }
  126|       |
  127|       |    /* min <= A iff the lowest limb of A is >= min or the other limbs
  128|       |     * are not all zero. */
  129|     12|    return mbedtls_ct_bool_or(msll_mask, min_le_lsl);
  130|     12|}
mbedtls_mpi_core_lt_ct:
  135|     12|{
  136|     12|    mbedtls_ct_condition_t ret = MBEDTLS_CT_FALSE, cond = MBEDTLS_CT_FALSE, done = MBEDTLS_CT_FALSE;
  ------------------
  |  |   86|     12|#define MBEDTLS_CT_FALSE ((mbedtls_ct_condition_t) mbedtls_ct_compiler_opaque(0))
  ------------------
                  mbedtls_ct_condition_t ret = MBEDTLS_CT_FALSE, cond = MBEDTLS_CT_FALSE, done = MBEDTLS_CT_FALSE;
  ------------------
  |  |   86|     12|#define MBEDTLS_CT_FALSE ((mbedtls_ct_condition_t) mbedtls_ct_compiler_opaque(0))
  ------------------
                  mbedtls_ct_condition_t ret = MBEDTLS_CT_FALSE, cond = MBEDTLS_CT_FALSE, done = MBEDTLS_CT_FALSE;
  ------------------
  |  |   86|     12|#define MBEDTLS_CT_FALSE ((mbedtls_ct_condition_t) mbedtls_ct_compiler_opaque(0))
  ------------------
  137|       |
  138|     60|    for (size_t i = limbs; i > 0; i--) {
  ------------------
  |  Branch (138:28): [True: 48, False: 12]
  ------------------
  139|       |        /*
  140|       |         * If B[i - 1] < A[i - 1] then A < B is false and the result must
  141|       |         * remain 0.
  142|       |         *
  143|       |         * Again even if we can make a decision, we just mark the result and
  144|       |         * the fact that we are done and continue looping.
  145|       |         */
  146|     48|        cond = mbedtls_ct_uint_lt(B[i - 1], A[i - 1]);
  147|     48|        done = mbedtls_ct_bool_or(done, cond);
  148|       |
  149|       |        /*
  150|       |         * If A[i - 1] < B[i - 1] then A < B is true.
  151|       |         *
  152|       |         * Again even if we can make a decision, we just mark the result and
  153|       |         * the fact that we are done and continue looping.
  154|       |         */
  155|     48|        cond = mbedtls_ct_uint_lt(A[i - 1], B[i - 1]);
  156|     48|        ret  = mbedtls_ct_bool_or(ret, mbedtls_ct_bool_and(cond, mbedtls_ct_bool_not(done)));
  157|     48|        done = mbedtls_ct_bool_or(done, cond);
  158|     48|    }
  159|       |
  160|       |    /*
  161|       |     * If all the limbs were equal, then the numbers are equal, A < B is false
  162|       |     * and leaving the result 0 is correct.
  163|       |     */
  164|       |
  165|     12|    return ret;
  166|     12|}
mbedtls_mpi_core_cond_assign:
  172|  6.04M|{
  173|  6.04M|    if (X == A) {
  ------------------
  |  Branch (173:9): [True: 0, False: 6.04M]
  ------------------
  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|  30.2M|    for (size_t i = 0; i < limbs; i++) {
  ------------------
  |  Branch (182:24): [True: 24.1M, False: 6.04M]
  ------------------
  183|  24.1M|        X[i] = mbedtls_ct_mpi_uint_if(assign, A[i], X[i]);
  184|  24.1M|    }
  185|  6.04M|}
mbedtls_mpi_core_read_be:
  230|  40.1k|{
  231|  40.1k|    const size_t limbs = CHARS_TO_LIMBS(input_length);
  ------------------
  |  |   88|  40.1k|#define CHARS_TO_LIMBS(i) ((i) / ciL + ((i) % ciL != 0))
  |  |  ------------------
  |  |  |  |   79|  40.1k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  |  |               #define CHARS_TO_LIMBS(i) ((i) / ciL + ((i) % ciL != 0))
  |  |  ------------------
  |  |  |  |   79|  40.1k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  232|       |
  233|  40.1k|    if (X_limbs < limbs) {
  ------------------
  |  Branch (233:9): [True: 0, False: 40.1k]
  ------------------
  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|  40.1k|    if (X_limbs == 0) {
  ------------------
  |  Branch (239:9): [True: 0, False: 40.1k]
  ------------------
  240|      0|        return 0;
  241|      0|    }
  242|       |
  243|  40.1k|    memset(X, 0, X_limbs * ciL);
  ------------------
  |  |   79|  40.1k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  244|       |
  245|       |    /* memcpy() with (NULL, 0) is undefined behaviour */
  246|  40.1k|    if (input_length != 0) {
  ------------------
  |  Branch (246:9): [True: 40.1k, False: 0]
  ------------------
  247|  40.1k|        size_t overhead = (X_limbs * ciL) - input_length;
  ------------------
  |  |   79|  40.1k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  248|  40.1k|        unsigned char *Xp = (unsigned char *) X;
  249|  40.1k|        memcpy(Xp + overhead, input, input_length);
  250|  40.1k|    }
  251|       |
  252|  40.1k|    mbedtls_mpi_core_bigendian_to_host(X, X_limbs);
  253|       |
  254|  40.1k|    return 0;
  255|  40.1k|}
mbedtls_mpi_core_write_be:
  295|      6|{
  296|      6|    size_t stored_bytes;
  297|      6|    size_t bytes_to_copy;
  298|      6|    unsigned char *p;
  299|       |
  300|      6|    stored_bytes = X_limbs * ciL;
  ------------------
  |  |   79|      6|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  301|       |
  302|      6|    if (stored_bytes < output_length) {
  ------------------
  |  Branch (302:9): [True: 0, False: 6]
  ------------------
  303|       |        /* There is enough space in the output buffer. Write initial
  304|       |         * null bytes and record the position at which to start
  305|       |         * writing the significant bytes. In this case, the execution
  306|       |         * trace of this function does not depend on the value of the
  307|       |         * number. */
  308|      0|        bytes_to_copy = stored_bytes;
  309|      0|        p = output + output_length - stored_bytes;
  310|      0|        memset(output, 0, output_length - stored_bytes);
  311|      6|    } else {
  312|       |        /* The output buffer is smaller than the allocated size of X.
  313|       |         * However X may fit if its leading bytes are zero. */
  314|      6|        bytes_to_copy = output_length;
  315|      6|        p = output;
  316|    294|        for (size_t i = bytes_to_copy; i < stored_bytes; i++) {
  ------------------
  |  Branch (316:40): [True: 288, False: 6]
  ------------------
  317|    288|            if (GET_BYTE(X, i) != 0) {
  ------------------
  |  |   91|    288|    (((X)[(i) / ciL] >> (((i) % ciL) * 8)) & 0xff)
  |  |  ------------------
  |  |  |  |   79|    288|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  |  |                   (((X)[(i) / ciL] >> (((i) % ciL) * 8)) & 0xff)
  |  |  ------------------
  |  |  |  |   79|    288|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  |  Branch (317:17): [True: 0, False: 288]
  ------------------
  318|      0|                return MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL;
  ------------------
  |  |   30|      0|#define MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL                  -0x0008
  ------------------
  319|      0|            }
  320|    288|        }
  321|      6|    }
  322|       |
  323|    198|    for (size_t i = 0; i < bytes_to_copy; i++) {
  ------------------
  |  Branch (323:24): [True: 192, False: 6]
  ------------------
  324|    192|        p[bytes_to_copy - i - 1] = GET_BYTE(X, i);
  ------------------
  |  |   91|    192|    (((X)[(i) / ciL] >> (((i) % ciL) * 8)) & 0xff)
  |  |  ------------------
  |  |  |  |   79|    192|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  |  |                   (((X)[(i) / ciL] >> (((i) % ciL) * 8)) & 0xff)
  |  |  ------------------
  |  |  |  |   79|    192|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  325|    192|    }
  326|       |
  327|      6|    return 0;
  328|      6|}
mbedtls_mpi_core_shift_r:
  332|  20.5M|{
  333|  20.5M|    size_t i, v0, v1;
  334|  20.5M|    mbedtls_mpi_uint r0 = 0, r1;
  335|       |
  336|  20.5M|    v0 = count /  biL;
  ------------------
  |  |   80|  20.5M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  20.5M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  337|  20.5M|    v1 = count & (biL - 1);
  ------------------
  |  |   80|  20.5M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  20.5M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  338|       |
  339|  20.5M|    if (v0 > limbs || (v0 == limbs && v1 > 0)) {
  ------------------
  |  Branch (339:9): [True: 0, False: 20.5M]
  |  Branch (339:24): [True: 0, False: 20.5M]
  |  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|  20.5M|    if (v0 > 0) {
  ------------------
  |  Branch (347:9): [True: 4.23k, False: 20.5M]
  ------------------
  348|  25.3k|        for (i = 0; i < limbs - v0; i++) {
  ------------------
  |  Branch (348:21): [True: 21.1k, False: 4.23k]
  ------------------
  349|  21.1k|            X[i] = X[i + v0];
  350|  21.1k|        }
  351|       |
  352|  21.1k|        for (; i < limbs; i++) {
  ------------------
  |  Branch (352:16): [True: 16.9k, False: 4.23k]
  ------------------
  353|  16.9k|            X[i] = 0;
  354|  16.9k|        }
  355|  4.23k|    }
  356|       |
  357|       |    /*
  358|       |     * shift by count % limb_size
  359|       |     */
  360|  20.5M|    if (v1 > 0) {
  ------------------
  |  Branch (360:9): [True: 17.1M, False: 3.43M]
  ------------------
  361|  92.1M|        for (i = limbs; i > 0; i--) {
  ------------------
  |  Branch (361:25): [True: 75.0M, False: 17.1M]
  ------------------
  362|  75.0M|            r1 = X[i - 1] << (biL - v1);
  ------------------
  |  |   80|  75.0M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  75.0M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  363|  75.0M|            X[i - 1] >>= v1;
  364|  75.0M|            X[i - 1] |= r0;
  365|  75.0M|            r0 = r1;
  366|  75.0M|        }
  367|  17.1M|    }
  368|  20.5M|}
mbedtls_mpi_core_shift_l:
  372|  2.90M|{
  373|  2.90M|    size_t i, v0, v1;
  374|  2.90M|    mbedtls_mpi_uint r0 = 0, r1;
  375|       |
  376|  2.90M|    v0 = count / (biL);
  ------------------
  |  |   80|  2.90M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  2.90M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  377|  2.90M|    v1 = count & (biL - 1);
  ------------------
  |  |   80|  2.90M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  2.90M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  378|       |
  379|       |    /*
  380|       |     * shift by count / limb_size
  381|       |     */
  382|  2.90M|    if (v0 > 0) {
  ------------------
  |  Branch (382:9): [True: 16.9k, False: 2.89M]
  ------------------
  383|   139k|        for (i = limbs; i > v0; i--) {
  ------------------
  |  Branch (383:25): [True: 122k, False: 16.9k]
  ------------------
  384|   122k|            X[i - 1] = X[i - v0 - 1];
  385|   122k|        }
  386|       |
  387|  59.4k|        for (; i > 0; i--) {
  ------------------
  |  Branch (387:16): [True: 42.5k, False: 16.9k]
  ------------------
  388|  42.5k|            X[i - 1] = 0;
  389|  42.5k|        }
  390|  16.9k|    }
  391|       |
  392|       |    /*
  393|       |     * shift by count % limb_size
  394|       |     */
  395|  2.90M|    if (v1 > 0) {
  ------------------
  |  Branch (395:9): [True: 2.87M, False: 33.8k]
  ------------------
  396|  28.7M|        for (i = v0; i < limbs; i++) {
  ------------------
  |  Branch (396:22): [True: 25.8M, False: 2.87M]
  ------------------
  397|  25.8M|            r1 = X[i] >> (biL - v1);
  ------------------
  |  |   80|  25.8M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  25.8M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  398|  25.8M|            X[i] <<= v1;
  399|  25.8M|            X[i] |= r0;
  400|  25.8M|            r0 = r1;
  401|  25.8M|        }
  402|  2.87M|    }
  403|  2.90M|}
mbedtls_mpi_core_add:
  409|  5.14M|{
  410|  5.14M|    mbedtls_mpi_uint c = 0;
  411|       |
  412|  25.7M|    for (size_t i = 0; i < limbs; i++) {
  ------------------
  |  Branch (412:24): [True: 20.5M, False: 5.14M]
  ------------------
  413|  20.5M|        mbedtls_mpi_uint t = c + A[i];
  414|  20.5M|        c = (t < A[i]);
  415|  20.5M|        t += B[i];
  416|  20.5M|        c += (t < B[i]);
  417|  20.5M|        X[i] = t;
  418|  20.5M|    }
  419|       |
  420|  5.14M|    return c;
  421|  5.14M|}
mbedtls_mpi_core_sub:
  448|  26.7M|{
  449|  26.7M|    mbedtls_mpi_uint c = 0;
  450|       |
  451|   126M|    for (size_t i = 0; i < limbs; i++) {
  ------------------
  |  Branch (451:24): [True: 99.7M, False: 26.7M]
  ------------------
  452|  99.7M|        mbedtls_mpi_uint z = (A[i] < c);
  453|  99.7M|        mbedtls_mpi_uint t = A[i] - c;
  454|  99.7M|        c = (t < B[i]) + z;
  455|  99.7M|        X[i] = t - B[i];
  456|  99.7M|    }
  457|       |
  458|  26.7M|    return c;
  459|  26.7M|}
mbedtls_mpi_core_mla:
  464|  33.8M|{
  465|  33.8M|    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|  33.8M|    if (d_len < s_len) {
  ------------------
  |  Branch (471:9): [True: 0, False: 33.8M]
  ------------------
  472|      0|        s_len = d_len;
  473|      0|    }
  474|  33.8M|    size_t excess_len = d_len - s_len;
  475|  33.8M|    size_t steps_x8 = s_len / 8;
  476|  33.8M|    size_t steps_x1 = s_len & 7;
  477|       |
  478|  33.8M|    while (steps_x8--) {
  ------------------
  |  Branch (478:12): [True: 12, False: 33.8M]
  ------------------
  479|     12|        MULADDC_X8_INIT
  ------------------
  |  | 1088|     12|#define MULADDC_X8_INIT MULADDC_X4_INIT
  |  |  ------------------
  |  |  |  | 1082|     12|#define MULADDC_X4_INIT MULADDC_X2_INIT
  |  |  |  |  ------------------
  |  |  |  |  |  | 1076|     12|#define MULADDC_X2_INIT MULADDC_X1_INIT
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  216|     12|    asm(                                    \
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  321|     12|#define asm __asm__
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  217|     12|        "xorq   %%r8, %%r8\n"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  480|     12|        MULADDC_X8_CORE
  481|     12|            MULADDC_X8_STOP
  ------------------
  |  | 1089|     12|#define MULADDC_X8_STOP MULADDC_X4_STOP
  |  |  ------------------
  |  |  |  | 1083|     12|#define MULADDC_X4_STOP MULADDC_X2_STOP
  |  |  |  |  ------------------
  |  |  |  |  |  | 1077|     12|#define MULADDC_X2_STOP MULADDC_X1_STOP
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  232|     12|        : "+c" (c), "+D" (d), "+S" (s), "+m" (*(uint64_t (*)[16]) d) \
  |  |  |  |  |  |  |  |  233|     12|        : "b" (b), "m" (*(const uint64_t (*)[16]) s)                 \
  |  |  |  |  |  |  |  |  234|     12|        : "rax", "rdx", "r8"                                         \
  |  |  |  |  |  |  |  |  235|     12|    );
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  482|     12|    }
  483|       |
  484|   168M|    while (steps_x1--) {
  ------------------
  |  Branch (484:12): [True: 135M, False: 33.8M]
  ------------------
  485|   135M|        MULADDC_X1_INIT
  ------------------
  |  |  216|   135M|    asm(                                    \
  |  |  ------------------
  |  |  |  |  321|   135M|#define asm __asm__
  |  |  ------------------
  |  |  217|   135M|        "xorq   %%r8, %%r8\n"
  ------------------
  486|   135M|        MULADDC_X1_CORE
  487|   135M|            MULADDC_X1_STOP
  ------------------
  |  |  232|   135M|        : "+c" (c), "+D" (d), "+S" (s), "+m" (*(uint64_t (*)[16]) d) \
  |  |  233|   135M|        : "b" (b), "m" (*(const uint64_t (*)[16]) s)                 \
  |  |  234|   135M|        : "rax", "rdx", "r8"                                         \
  |  |  235|   135M|    );
  ------------------
  488|   135M|    }
  489|       |
  490|  68.9M|    while (excess_len--) {
  ------------------
  |  Branch (490:12): [True: 35.0M, False: 33.8M]
  ------------------
  491|  35.0M|        *d += c;
  492|  35.0M|        c = (*d < c);
  493|  35.0M|        d++;
  494|  35.0M|    }
  495|       |
  496|  33.8M|    return c;
  497|  33.8M|}
mbedtls_mpi_core_mul:
  502|  8.31M|{
  503|  8.31M|    memset(X, 0, (A_limbs + B_limbs) * ciL);
  ------------------
  |  |   79|  8.31M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  504|       |
  505|  41.4M|    for (size_t i = 0; i < B_limbs; i++) {
  ------------------
  |  Branch (505:24): [True: 33.1M, False: 8.31M]
  ------------------
  506|  33.1M|        (void) mbedtls_mpi_core_mla(X + i, A_limbs + 1, A, A_limbs, B[i]);
  507|  33.1M|    }
  508|  8.31M|}
mbedtls_mpi_core_fill_random:
  619|     12|{
  620|     12|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|     12|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  621|     12|    const size_t limbs = CHARS_TO_LIMBS(n_bytes);
  ------------------
  |  |   88|     12|#define CHARS_TO_LIMBS(i) ((i) / ciL + ((i) % ciL != 0))
  |  |  ------------------
  |  |  |  |   79|     12|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  |  |               #define CHARS_TO_LIMBS(i) ((i) / ciL + ((i) % ciL != 0))
  |  |  ------------------
  |  |  |  |   79|     12|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  622|     12|    const size_t overhead = (limbs * ciL) - n_bytes;
  ------------------
  |  |   79|     12|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  623|       |
  624|     12|    if (X_limbs < limbs) {
  ------------------
  |  Branch (624:9): [True: 0, False: 12]
  ------------------
  625|      0|        return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MPI_BAD_INPUT_DATA                    -0x0004
  ------------------
  626|      0|    }
  627|       |
  628|     12|    memset(X, 0, overhead);
  629|     12|    memset((unsigned char *) X + limbs * ciL, 0, (X_limbs - limbs) * ciL);
  ------------------
  |  |   79|     12|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
                  memset((unsigned char *) X + limbs * ciL, 0, (X_limbs - limbs) * ciL);
  ------------------
  |  |   79|     12|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  630|     12|    MBEDTLS_MPI_CHK(f_rng(p_rng, (unsigned char *) X + overhead, n_bytes));
  ------------------
  |  |   41|     12|    do                           \
  |  |   42|     12|    {                            \
  |  |   43|     12|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 12]
  |  |  ------------------
  |  |   44|     12|        goto cleanup;        \
  |  |   45|     12|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  631|     12|    mbedtls_mpi_core_bigendian_to_host(X, limbs);
  632|       |
  633|     12|cleanup:
  634|     12|    return ret;
  635|     12|}
mbedtls_mpi_core_random:
  643|     12|{
  644|     12|    mbedtls_ct_condition_t ge_lower = MBEDTLS_CT_TRUE, lt_upper = MBEDTLS_CT_FALSE;
  ------------------
  |  |   77|     12|#define MBEDTLS_CT_TRUE  ((mbedtls_ct_condition_t) mbedtls_ct_compiler_opaque(UINT64_MAX))
  ------------------
                  mbedtls_ct_condition_t ge_lower = MBEDTLS_CT_TRUE, lt_upper = MBEDTLS_CT_FALSE;
  ------------------
  |  |   86|     12|#define MBEDTLS_CT_FALSE ((mbedtls_ct_condition_t) mbedtls_ct_compiler_opaque(0))
  ------------------
  645|     12|    size_t n_bits = mbedtls_mpi_core_bitlen(N, limbs);
  646|     12|    size_t n_bytes = (n_bits + 7) / 8;
  647|     12|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|     12|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  648|       |
  649|       |    /*
  650|       |     * When min == 0, each try has at worst a probability 1/2 of failing
  651|       |     * (the msb has a probability 1/2 of being 0, and then the result will
  652|       |     * be < N), so after 30 tries failure probability is a most 2**(-30).
  653|       |     *
  654|       |     * When N is just below a power of 2, as is the case when generating
  655|       |     * a random scalar on most elliptic curves, 1 try is enough with
  656|       |     * overwhelming probability. When N is just above a power of 2,
  657|       |     * as when generating a random scalar on secp224k1, each try has
  658|       |     * a probability of failing that is almost 1/2.
  659|       |     *
  660|       |     * The probabilities are almost the same if min is nonzero but negligible
  661|       |     * compared to N. This is always the case when N is crypto-sized, but
  662|       |     * it's convenient to support small N for testing purposes. When N
  663|       |     * is small, use a higher repeat count, otherwise the probability of
  664|       |     * failure is macroscopic.
  665|       |     */
  666|     12|    int count = (n_bytes > 4 ? 30 : 250);
  ------------------
  |  Branch (666:18): [True: 12, False: 0]
  ------------------
  667|       |
  668|       |    /*
  669|       |     * Match the procedure given in RFC 6979 §3.3 (deterministic ECDSA)
  670|       |     * when f_rng is a suitably parametrized instance of HMAC_DRBG:
  671|       |     * - use the same byte ordering;
  672|       |     * - keep the leftmost n_bits bits of the generated octet string;
  673|       |     * - try until result is in the desired range.
  674|       |     * This also avoids any bias, which is especially important for ECDSA.
  675|       |     */
  676|     12|    do {
  677|     12|        MBEDTLS_MPI_CHK(mbedtls_mpi_core_fill_random(X, limbs,
  ------------------
  |  |   41|     12|    do                           \
  |  |   42|     12|    {                            \
  |  |   43|     12|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 12]
  |  |  ------------------
  |  |   44|     12|        goto cleanup;        \
  |  |   45|     12|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  678|     12|                                                     n_bytes,
  679|     12|                                                     f_rng, p_rng));
  680|     12|        mbedtls_mpi_core_shift_r(X, limbs, 8 * n_bytes - n_bits);
  681|       |
  682|     12|        if (--count == 0) {
  ------------------
  |  Branch (682:13): [True: 0, False: 12]
  ------------------
  683|      0|            ret = MBEDTLS_ERR_MPI_NOT_ACCEPTABLE;
  ------------------
  |  |   36|      0|#define MBEDTLS_ERR_MPI_NOT_ACCEPTABLE                    -0x000E
  ------------------
  684|      0|            goto cleanup;
  685|      0|        }
  686|       |
  687|     12|        ge_lower = mbedtls_mpi_core_uint_le_mpi(min, X, limbs);
  688|     12|        lt_upper = mbedtls_mpi_core_lt_ct(X, N, limbs);
  689|     12|    } while (mbedtls_ct_bool_and(ge_lower, lt_upper) == MBEDTLS_CT_FALSE);
  ------------------
  |  |   86|     12|#define MBEDTLS_CT_FALSE ((mbedtls_ct_condition_t) mbedtls_ct_compiler_opaque(0))
  ------------------
  |  Branch (689:14): [True: 0, False: 12]
  ------------------
  690|       |
  691|     12|cleanup:
  692|     12|    return ret;
  693|     12|}
mbedtls_mpi_core_sub_int:
  973|  5.93M|{
  974|  33.4M|    for (size_t i = 0; i < limbs; i++) {
  ------------------
  |  Branch (974:24): [True: 27.5M, False: 5.93M]
  ------------------
  975|  27.5M|        mbedtls_mpi_uint s = A[i];
  976|  27.5M|        mbedtls_mpi_uint t = s - c;
  977|  27.5M|        c = (t > s);
  978|  27.5M|        X[i] = t;
  979|  27.5M|    }
  980|       |
  981|  5.93M|    return c;
  982|  5.93M|}
bignum_core.c:mpi_bigendian_to_host:
   69|   164k|{
   70|   164k|    if (MBEDTLS_IS_BIG_ENDIAN) {
  ------------------
  |  |  398|   164k|#define MBEDTLS_IS_BIG_ENDIAN 0
  |  |  ------------------
  |  |  |  Branch (398:31): [Folded - Ignored]
  |  |  ------------------
  ------------------
   71|       |        /* Nothing to do on bigendian systems. */
   72|      0|        return a;
   73|   164k|    } else {
   74|       |#if defined(MBEDTLS_HAVE_INT32)
   75|       |        return (mbedtls_mpi_uint) MBEDTLS_BSWAP32(a);
   76|       |#elif defined(MBEDTLS_HAVE_INT64)
   77|   164k|        return (mbedtls_mpi_uint) MBEDTLS_BSWAP64(a);
  ------------------
  |  |  301|   164k|#define MBEDTLS_BSWAP64 __builtin_bswap64
  ------------------
   78|   164k|#endif
   79|   164k|    }
   80|   164k|}

bignum.c:mbedtls_ct_bool:
  136|  6.04M|{
  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|  6.04M|    asm volatile ("mov  %[x], %[s]                                \n\t"
  ------------------
  |  |  321|  6.04M|#define asm __asm__
  ------------------
  175|  6.04M|                  "neg  %[s]                                      \n\t"
  176|  6.04M|                  "or   %[x], %[s]                                \n\t"
  177|  6.04M|                  "sar  $63, %[s]                                 \n\t"
  178|  6.04M|                  :
  179|  6.04M|                  [s] "=&a" (s)
  180|  6.04M|                  :
  181|  6.04M|                  [x] "D" (x)
  182|  6.04M|                  :
  183|  6.04M|                  );
  184|  6.04M|    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|  6.04M|}
bignum.c:mbedtls_ct_bool_not:
  547|  6.04M|{
  548|  6.04M|    return (mbedtls_ct_condition_t) (~x);
  549|  6.04M|}
bignum.c:mbedtls_ct_uint_if:
  436|  6.04M|{
  437|  6.04M|    return (unsigned) mbedtls_ct_if(condition, (mbedtls_ct_uint_t) if1, (mbedtls_ct_uint_t) if0);
  438|  6.04M|}
bignum.c:mbedtls_ct_if:
  223|  6.04M|{
  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|  6.04M|    asm volatile ("and  %[condition], %[if1]                      \n\t"
  ------------------
  |  |  321|  6.04M|#define asm __asm__
  ------------------
  255|  6.04M|                  "not  %[condition]                              \n\t"
  256|  6.04M|                  "and  %[condition], %[if0]                      \n\t"
  257|  6.04M|                  "or   %[if1], %[if0]                            \n\t"
  258|  6.04M|                  :
  259|  6.04M|                  [condition] "+&D" (condition),
  260|  6.04M|                  [if1] "+&S" (if1),
  261|  6.04M|                  [if0] "+&a" (if0)
  262|  6.04M|                  :
  263|  6.04M|                  :
  264|  6.04M|                  );
  265|  6.04M|    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|  6.04M|}
bignum.c:mbedtls_ct_mpi_uint_if_else_0:
  481|  21.1k|{
  482|  21.1k|    return (mbedtls_mpi_uint) (condition & if1);
  483|  21.1k|}
bignum_core.c:mbedtls_ct_uint_ge:
  518|     12|{
  519|     12|    return ~mbedtls_ct_uint_lt(x, y);
  520|     12|}
bignum_core.c:mbedtls_ct_compiler_opaque:
  101|     84|{
  102|     84|#if defined(MBEDTLS_CT_ASM)
  103|     84|    asm volatile ("" : [x] "+r" (x) :);
  ------------------
  |  |  321|     84|#define asm __asm__
  ------------------
  104|     84|    return x;
  105|       |#else
  106|       |    return x ^ mbedtls_ct_zero;
  107|       |#endif
  108|     84|}
bignum_core.c:mbedtls_ct_bool_or:
  542|    192|{
  543|    192|    return (mbedtls_ct_condition_t) (x | y);
  544|    192|}
bignum_core.c:mbedtls_ct_bool:
  136|     36|{
  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|     36|    asm volatile ("mov  %[x], %[s]                                \n\t"
  ------------------
  |  |  321|     36|#define asm __asm__
  ------------------
  175|     36|                  "neg  %[s]                                      \n\t"
  176|     36|                  "or   %[x], %[s]                                \n\t"
  177|     36|                  "sar  $63, %[s]                                 \n\t"
  178|     36|                  :
  179|     36|                  [s] "=&a" (s)
  180|     36|                  :
  181|     36|                  [x] "D" (x)
  182|     36|                  :
  183|     36|                  );
  184|     36|    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|     36|}
bignum_core.c:mbedtls_ct_uint_lt:
  287|    108|{
  288|       |#if defined(MBEDTLS_CT_AARCH64_ASM) && (defined(MBEDTLS_CT_SIZE_32) || defined(MBEDTLS_CT_SIZE_64))
  289|       |    uint64_t s1;
  290|       |    asm volatile ("eor     %x[s1], %x[y], %x[x]                   \n\t"
  291|       |                  "sub     %x[x], %x[x], %x[y]                    \n\t"
  292|       |                  "bic     %x[x], %x[x], %x[s1]                   \n\t"
  293|       |                  "and     %x[s1], %x[s1], %x[y]                  \n\t"
  294|       |                  "orr     %x[s1], %x[x], %x[s1]                  \n\t"
  295|       |                  "asr     %x[x], %x[s1], 63"
  296|       |                  :
  297|       |                  [s1] "=&r" (s1),
  298|       |                  [x] "+&r" (x)
  299|       |                  :
  300|       |                  [y] "r" (y)
  301|       |                  :
  302|       |                  );
  303|       |    return (mbedtls_ct_condition_t) x;
  304|       |#elif defined(MBEDTLS_CT_ARM_ASM) && defined(MBEDTLS_CT_SIZE_32)
  305|       |    uint32_t s1;
  306|       |    asm volatile (
  307|       |        ".syntax unified                                          \n\t"
  308|       |#if defined(__thumb__) && !defined(__thumb2__)
  309|       |        "movs     %[s1], %[x]                                     \n\t"
  310|       |        "eors     %[s1], %[s1], %[y]                              \n\t"
  311|       |#else
  312|       |        "eors     %[s1], %[x], %[y]                               \n\t"
  313|       |#endif
  314|       |        "subs    %[x], %[x], %[y]                                 \n\t"
  315|       |        "bics    %[x], %[x], %[s1]                                \n\t"
  316|       |        "ands    %[y], %[s1], %[y]                                \n\t"
  317|       |        "orrs    %[x], %[x], %[y]                                 \n\t"
  318|       |        "asrs    %[x], %[x], #31                                  \n\t"
  319|       |        RESTORE_ASM_SYNTAX
  320|       |        :
  321|       |        [s1] "=&l" (s1),
  322|       |        [x] "+&l" (x),
  323|       |        [y] "+&l" (y)
  324|       |        :
  325|       |        :
  326|       |        "cc"
  327|       |        );
  328|       |    return (mbedtls_ct_condition_t) x;
  329|       |#elif defined(MBEDTLS_CT_X86_64_ASM) && (defined(MBEDTLS_CT_SIZE_32) || defined(MBEDTLS_CT_SIZE_64))
  330|       |    uint64_t s;
  331|    108|    asm volatile ("mov %[x], %[s]                                 \n\t"
  ------------------
  |  |  321|    108|#define asm __asm__
  ------------------
  332|    108|                  "xor %[y], %[s]                                 \n\t"
  333|    108|                  "sub %[y], %[x]                                 \n\t"
  334|    108|                  "and %[s], %[y]                                 \n\t"
  335|    108|                  "not %[s]                                       \n\t"
  336|    108|                  "and %[s], %[x]                                 \n\t"
  337|    108|                  "or %[y], %[x]                                  \n\t"
  338|    108|                  "sar $63, %[x]                                  \n\t"
  339|    108|                  :
  340|    108|                  [s] "=&a" (s),
  341|    108|                  [x] "+&D" (x),
  342|    108|                  [y] "+&S" (y)
  343|    108|                  :
  344|    108|                  :
  345|    108|                  );
  346|    108|    return (mbedtls_ct_condition_t) x;
  347|       |#elif defined(MBEDTLS_CT_X86_ASM) && defined(MBEDTLS_CT_SIZE_32)
  348|       |    uint32_t s;
  349|       |    asm volatile ("mov %[x], %[s]                                 \n\t"
  350|       |                  "xor %[y], %[s]                                 \n\t"
  351|       |                  "sub %[y], %[x]                                 \n\t"
  352|       |                  "and %[s], %[y]                                 \n\t"
  353|       |                  "not %[s]                                       \n\t"
  354|       |                  "and %[s], %[x]                                 \n\t"
  355|       |                  "or  %[y], %[x]                                 \n\t"
  356|       |                  "sar $31, %[x]                                  \n\t"
  357|       |                  :
  358|       |                  [s] "=&b" (s),
  359|       |                  [x] "+&a" (x),
  360|       |                  [y] "+&c" (y)
  361|       |                  :
  362|       |                  :
  363|       |                  );
  364|       |    return (mbedtls_ct_condition_t) x;
  365|       |#else
  366|       |    /* Ensure that the compiler cannot optimise the following operations over x and y,
  367|       |     * even if it knows the value of x and y.
  368|       |     */
  369|       |    const mbedtls_ct_uint_t xo = mbedtls_ct_compiler_opaque(x);
  370|       |    const mbedtls_ct_uint_t yo = mbedtls_ct_compiler_opaque(y);
  371|       |    /*
  372|       |     * Check if the most significant bits (MSB) of the operands are different.
  373|       |     * cond is true iff the MSBs differ.
  374|       |     */
  375|       |    mbedtls_ct_condition_t cond = mbedtls_ct_bool((xo ^ yo) >> (MBEDTLS_CT_SIZE - 1));
  376|       |
  377|       |    /*
  378|       |     * If the MSB are the same then the difference x-y will be negative (and
  379|       |     * have its MSB set to 1 during conversion to unsigned) if and only if x<y.
  380|       |     *
  381|       |     * If the MSB are different, then the operand with the MSB of 1 is the
  382|       |     * bigger. (That is if y has MSB of 1, then x<y is true and it is false if
  383|       |     * the MSB of y is 0.)
  384|       |     */
  385|       |
  386|       |    // Select either y, or x - y
  387|       |    mbedtls_ct_uint_t ret = mbedtls_ct_if(cond, yo, (mbedtls_ct_uint_t) (xo - yo));
  388|       |
  389|       |    // Extract only the MSB of ret
  390|       |    ret = ret >> (MBEDTLS_CT_SIZE - 1);
  391|       |
  392|       |    // Convert to a condition (i.e., all bits set iff non-zero)
  393|       |    return mbedtls_ct_bool(ret);
  394|       |#endif
  395|    108|}
bignum_core.c:mbedtls_ct_bool_and:
  536|     60|{
  537|     60|    return (mbedtls_ct_condition_t) (x & y);
  538|     60|}
bignum_core.c:mbedtls_ct_bool_not:
  547|     48|{
  548|     48|    return (mbedtls_ct_condition_t) (~x);
  549|     48|}
bignum_core.c:mbedtls_ct_mpi_uint_if:
  453|  24.1M|{
  454|  24.1M|    return (mbedtls_mpi_uint) mbedtls_ct_if(condition,
  455|  24.1M|                                            (mbedtls_ct_uint_t) if1,
  456|  24.1M|                                            (mbedtls_ct_uint_t) if0);
  457|  24.1M|}
bignum_core.c:mbedtls_ct_if:
  223|  24.1M|{
  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|  24.1M|    asm volatile ("and  %[condition], %[if1]                      \n\t"
  ------------------
  |  |  321|  24.1M|#define asm __asm__
  ------------------
  255|  24.1M|                  "not  %[condition]                              \n\t"
  256|  24.1M|                  "and  %[condition], %[if0]                      \n\t"
  257|  24.1M|                  "or   %[if1], %[if0]                            \n\t"
  258|  24.1M|                  :
  259|  24.1M|                  [condition] "+&D" (condition),
  260|  24.1M|                  [if1] "+&S" (if1),
  261|  24.1M|                  [if0] "+&a" (if0)
  262|  24.1M|                  :
  263|  24.1M|                  :
  264|  24.1M|                  );
  265|  24.1M|    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|  24.1M|}
base64.c:mbedtls_ct_uchar_in_range_if:
  410|  8.28k|{
  411|  8.28k|    const unsigned char co = (unsigned char) mbedtls_ct_compiler_opaque(c);
  412|  8.28k|    const unsigned char to = (unsigned char) mbedtls_ct_compiler_opaque(t);
  413|       |
  414|       |    /* low_mask is: 0 if low <= c, 0x...ff if low > c */
  415|  8.28k|    unsigned low_mask = ((unsigned) co - low) >> 8;
  416|       |    /* high_mask is: 0 if c <= high, 0x...ff if c > high */
  417|  8.28k|    unsigned high_mask = ((unsigned) high - co) >> 8;
  418|       |
  419|  8.28k|    return (unsigned char) (~(low_mask | high_mask)) & to;
  420|  8.28k|}
base64.c:mbedtls_ct_compiler_opaque:
  101|  16.5k|{
  102|  16.5k|#if defined(MBEDTLS_CT_ASM)
  103|  16.5k|    asm volatile ("" : [x] "+r" (x) :);
  ------------------
  |  |  321|  16.5k|#define asm __asm__
  ------------------
  104|  16.5k|    return x;
  105|       |#else
  106|       |    return x ^ mbedtls_ct_zero;
  107|       |#endif
  108|  16.5k|}

mbedtls_ecdh_get_grp_id:
  148|      3|{
  149|      3|#if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
  150|      3|    return ctx->MBEDTLS_PRIVATE(grp).id;
  ------------------
  |  |   17|      3|#define MBEDTLS_PRIVATE(member) member
  ------------------
  151|       |#else
  152|       |    return ctx->MBEDTLS_PRIVATE(grp_id);
  153|       |#endif
  154|      3|}
mbedtls_ecdh_init:
  160|  1.05k|{
  161|  1.05k|#if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
  162|  1.05k|    ecdh_init_internal(ctx);
  163|  1.05k|    mbedtls_ecp_point_init(&ctx->Vi);
  164|  1.05k|    mbedtls_ecp_point_init(&ctx->Vf);
  165|  1.05k|    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|  1.05k|    ctx->point_format = MBEDTLS_ECP_PF_UNCOMPRESSED;
  ------------------
  |  |  439|  1.05k|#define MBEDTLS_ECP_PF_UNCOMPRESSED    0
  ------------------
  172|  1.05k|#if defined(MBEDTLS_ECP_RESTARTABLE)
  173|  1.05k|    ctx->restart_enabled = 0;
  174|  1.05k|#endif
  175|  1.05k|}
mbedtls_ecdh_setup:
  194|  1.05k|{
  195|  1.05k|#if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
  196|  1.05k|    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|  1.05k|}
mbedtls_ecdh_free:
  243|  1.05k|{
  244|  1.05k|    if (ctx == NULL) {
  ------------------
  |  Branch (244:9): [True: 0, False: 1.05k]
  ------------------
  245|      0|        return;
  246|      0|    }
  247|       |
  248|  1.05k|#if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
  249|  1.05k|    mbedtls_ecp_point_free(&ctx->Vi);
  250|  1.05k|    mbedtls_ecp_point_free(&ctx->Vf);
  251|  1.05k|    mbedtls_mpi_free(&ctx->_d);
  252|  1.05k|    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|  1.05k|}
mbedtls_ecdh_get_params:
  448|  1.05k|{
  449|  1.05k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  1.05k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  450|  1.05k|    if (side != MBEDTLS_ECDH_OURS && side != MBEDTLS_ECDH_THEIRS) {
  ------------------
  |  Branch (450:9): [True: 0, False: 1.05k]
  |  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|  1.05k|    if (mbedtls_ecdh_grp_id(ctx) == MBEDTLS_ECP_DP_NONE) {
  ------------------
  |  Branch (454:9): [True: 1.05k, False: 0]
  ------------------
  455|       |        /* This is the first call to get_params(). Set up the context
  456|       |         * for use with the group. */
  457|  1.05k|        if ((ret = mbedtls_ecdh_setup(ctx, key->grp.id)) != 0) {
  ------------------
  |  Branch (457:13): [True: 0, False: 1.05k]
  ------------------
  458|      0|            return ret;
  459|      0|        }
  460|  1.05k|    } 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|  1.05k|#if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
  470|  1.05k|    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|  1.05k|}
ecdh.c:ecdh_init_internal:
  135|  1.05k|{
  136|  1.05k|    mbedtls_ecp_group_init(&ctx->grp);
  137|  1.05k|    mbedtls_mpi_init(&ctx->d);
  138|  1.05k|    mbedtls_ecp_point_init(&ctx->Q);
  139|  1.05k|    mbedtls_ecp_point_init(&ctx->Qp);
  140|  1.05k|    mbedtls_mpi_init(&ctx->z);
  141|       |
  142|  1.05k|#if defined(MBEDTLS_ECP_RESTARTABLE)
  143|  1.05k|    mbedtls_ecp_restart_init(&ctx->rs);
  144|  1.05k|#endif
  145|  1.05k|}
ecdh.c:ecdh_setup_internal:
  179|  1.05k|{
  180|  1.05k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  1.05k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  181|       |
  182|  1.05k|    ret = mbedtls_ecp_group_load(&ctx->grp, grp_id);
  183|  1.05k|    if (ret != 0) {
  ------------------
  |  Branch (183:9): [True: 0, False: 1.05k]
  ------------------
  184|      0|        return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
  ------------------
  |  |   39|      0|#define MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE               -0x4E80
  ------------------
  185|      0|    }
  186|       |
  187|  1.05k|    return 0;
  188|  1.05k|}
ecdh.c:ecdh_free_internal:
  217|  1.05k|{
  218|  1.05k|    mbedtls_ecp_group_free(&ctx->grp);
  219|  1.05k|    mbedtls_mpi_free(&ctx->d);
  220|  1.05k|    mbedtls_ecp_point_free(&ctx->Q);
  221|  1.05k|    mbedtls_ecp_point_free(&ctx->Qp);
  222|  1.05k|    mbedtls_mpi_free(&ctx->z);
  223|       |
  224|  1.05k|#if defined(MBEDTLS_ECP_RESTARTABLE)
  225|  1.05k|    mbedtls_ecp_restart_free(&ctx->rs);
  226|  1.05k|#endif
  227|  1.05k|}
ecdh.c:mbedtls_ecdh_grp_id:
   31|  1.05k|{
   32|  1.05k|#if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
   33|  1.05k|    return ctx->grp.id;
   34|       |#else
   35|       |    return ctx->grp_id;
   36|       |#endif
   37|  1.05k|}
ecdh.c:ecdh_get_params_internal:
  421|  1.05k|{
  422|  1.05k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  1.05k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  423|       |
  424|       |    /* If it's not our key, just import the public part as Qp */
  425|  1.05k|    if (side == MBEDTLS_ECDH_THEIRS) {
  ------------------
  |  Branch (425:9): [True: 0, False: 1.05k]
  ------------------
  426|      0|        return mbedtls_ecp_copy(&ctx->Qp, &key->Q);
  427|      0|    }
  428|       |
  429|       |    /* Our key: import public (as Q) and private parts */
  430|  1.05k|    if (side != MBEDTLS_ECDH_OURS) {
  ------------------
  |  Branch (430:9): [True: 0, False: 1.05k]
  ------------------
  431|      0|        return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
  432|      0|    }
  433|       |
  434|  1.05k|    if ((ret = mbedtls_ecp_copy(&ctx->Q, &key->Q)) != 0 ||
  ------------------
  |  Branch (434:9): [True: 0, False: 1.05k]
  ------------------
  435|  1.05k|        (ret = mbedtls_mpi_copy(&ctx->d, &key->d)) != 0) {
  ------------------
  |  Branch (435:9): [True: 0, False: 1.05k]
  ------------------
  436|      0|        return ret;
  437|      0|    }
  438|       |
  439|  1.05k|    return 0;
  440|  1.05k|}

mbedtls_ecdsa_can_do:
  226|  2.11k|{
  227|  2.11k|    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: 2.11k]
  ------------------
  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: 2.11k]
  ------------------
  233|      0|#endif
  234|  2.11k|        default: return 1;
  ------------------
  |  Branch (234:9): [True: 2.11k, False: 0]
  ------------------
  235|  2.11k|    }
  236|  2.11k|}
mbedtls_ecdsa_sign_restartable:
  250|      3|{
  251|      3|    int ret, key_tries, sign_tries;
  252|      3|    int *p_sign_tries = &sign_tries, *p_key_tries = &key_tries;
  253|      3|    mbedtls_ecp_point R;
  254|      3|    mbedtls_mpi k, e, t;
  255|      3|    mbedtls_mpi *pk = &k, *pr = r;
  256|       |
  257|       |    /* Fail cleanly on curves such as Curve25519 that can't be used for ECDSA */
  258|      3|    if (!mbedtls_ecdsa_can_do(grp->id) || grp->N.p == NULL) {
  ------------------
  |  Branch (258:9): [True: 0, False: 3]
  |  Branch (258:43): [True: 0, False: 3]
  ------------------
  259|      0|        return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
  260|      0|    }
  261|       |
  262|       |    /* Make sure d is in range 1..n-1 */
  263|      3|    if (mbedtls_mpi_cmp_int(d, 1) < 0 || mbedtls_mpi_cmp_mpi(d, &grp->N) >= 0) {
  ------------------
  |  Branch (263:9): [True: 0, False: 3]
  |  Branch (263:42): [True: 0, False: 3]
  ------------------
  264|      0|        return MBEDTLS_ERR_ECP_INVALID_KEY;
  ------------------
  |  |   47|      0|#define MBEDTLS_ERR_ECP_INVALID_KEY                       -0x4C80
  ------------------
  265|      0|    }
  266|       |
  267|      3|    mbedtls_ecp_point_init(&R);
  268|      3|    mbedtls_mpi_init(&k); mbedtls_mpi_init(&e); mbedtls_mpi_init(&t);
  269|       |
  270|      3|    ECDSA_RS_ENTER(sig);
  ------------------
  |  |  153|      3|#define ECDSA_RS_ENTER(SUB)   do {                                 \
  |  |  154|      3|        /* reset ops count for this call if top-level */                 \
  |  |  155|      3|        if (rs_ctx != NULL && rs_ctx->ecp.depth++ == 0)                 \
  |  |  ------------------
  |  |  |  Branch (155:13): [True: 0, False: 3]
  |  |  |  Branch (155:31): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      3|        rs_ctx->ecp.ops_done = 0;                                    \
  |  |  157|      3|                                                                     \
  |  |  158|      3|        /* set up our own sub-context if needed */                       \
  |  |  159|      3|        if (mbedtls_ecp_restart_is_enabled() &&                          \
  |  |  ------------------
  |  |  |  Branch (159:13): [True: 0, False: 3]
  |  |  ------------------
  |  |  160|      3|            rs_ctx != NULL && rs_ctx->SUB == NULL)                      \
  |  |  ------------------
  |  |  |  Branch (160:13): [True: 0, False: 0]
  |  |  |  Branch (160:31): [True: 0, False: 0]
  |  |  ------------------
  |  |  161|      3|        {                                                                \
  |  |  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|      3|} while (0)
  |  |  ------------------
  |  |  |  Branch (168:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
  271|       |
  272|      3|#if defined(MBEDTLS_ECP_RESTARTABLE)
  273|      3|    if (rs_ctx != NULL && rs_ctx->sig != NULL) {
  ------------------
  |  Branch (273:9): [True: 0, False: 3]
  |  Branch (273:27): [True: 0, False: 0]
  ------------------
  274|       |        /* redirect to our context */
  275|      0|        p_sign_tries = &rs_ctx->sig->sign_tries;
  276|      0|        p_key_tries = &rs_ctx->sig->key_tries;
  277|      0|        pk = &rs_ctx->sig->k;
  278|      0|        pr = &rs_ctx->sig->r;
  279|       |
  280|       |        /* jump to current step */
  281|      0|        if (rs_ctx->sig->state == ecdsa_sig_mul) {
  ------------------
  |  Branch (281:13): [True: 0, False: 0]
  ------------------
  282|      0|            goto mul;
  283|      0|        }
  284|      0|        if (rs_ctx->sig->state == ecdsa_sig_modn) {
  ------------------
  |  Branch (284:13): [True: 0, False: 0]
  ------------------
  285|      0|            goto modn;
  286|      0|        }
  287|      0|    }
  288|      3|#endif /* MBEDTLS_ECP_RESTARTABLE */
  289|       |
  290|      3|    *p_sign_tries = 0;
  291|      3|    do {
  292|      3|        if ((*p_sign_tries)++ > 10) {
  ------------------
  |  Branch (292:13): [True: 0, False: 3]
  ------------------
  293|      0|            ret = MBEDTLS_ERR_ECP_RANDOM_FAILED;
  ------------------
  |  |   45|      0|#define MBEDTLS_ERR_ECP_RANDOM_FAILED                     -0x4D00
  ------------------
  294|      0|            goto cleanup;
  295|      0|        }
  296|       |
  297|       |        /*
  298|       |         * Steps 1-3: generate a suitable ephemeral keypair
  299|       |         * and set r = xR mod n
  300|       |         */
  301|      3|        *p_key_tries = 0;
  302|      3|        do {
  303|      3|            if ((*p_key_tries)++ > 10) {
  ------------------
  |  Branch (303:17): [True: 0, False: 3]
  ------------------
  304|      0|                ret = MBEDTLS_ERR_ECP_RANDOM_FAILED;
  ------------------
  |  |   45|      0|#define MBEDTLS_ERR_ECP_RANDOM_FAILED                     -0x4D00
  ------------------
  305|      0|                goto cleanup;
  306|      0|            }
  307|       |
  308|      3|            MBEDTLS_MPI_CHK(mbedtls_ecp_gen_privkey(grp, pk, f_rng, p_rng));
  ------------------
  |  |   41|      3|    do                           \
  |  |   42|      3|    {                            \
  |  |   43|      3|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3]
  |  |  ------------------
  |  |   44|      3|        goto cleanup;        \
  |  |   45|      3|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  309|       |
  310|      3|#if defined(MBEDTLS_ECP_RESTARTABLE)
  311|      3|            if (rs_ctx != NULL && rs_ctx->sig != NULL) {
  ------------------
  |  Branch (311:17): [True: 0, False: 3]
  |  Branch (311:35): [True: 0, False: 0]
  ------------------
  312|      0|                rs_ctx->sig->state = ecdsa_sig_mul;
  313|      0|            }
  314|       |
  315|      3|mul:
  316|      3|#endif
  317|      3|            MBEDTLS_MPI_CHK(mbedtls_ecp_mul_restartable(grp, &R, pk, &grp->G,
  ------------------
  |  |   41|      3|    do                           \
  |  |   42|      3|    {                            \
  |  |   43|      6|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3]
  |  |  |  Branch (43:21): [True: 3, False: 0]
  |  |  ------------------
  |  |   44|      3|        goto cleanup;        \
  |  |   45|      3|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  318|      3|                                                        f_rng_blind,
  319|      3|                                                        p_rng_blind,
  320|      3|                                                        ECDSA_RS_ECP));
  321|      3|            MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(pr, &R.X, &grp->N));
  ------------------
  |  |   41|      3|    do                           \
  |  |   42|      3|    {                            \
  |  |   43|      3|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3]
  |  |  ------------------
  |  |   44|      3|        goto cleanup;        \
  |  |   45|      3|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  322|      3|        } while (mbedtls_mpi_cmp_int(pr, 0) == 0);
  ------------------
  |  Branch (322:18): [True: 0, False: 3]
  ------------------
  323|       |
  324|      3|#if defined(MBEDTLS_ECP_RESTARTABLE)
  325|      3|        if (rs_ctx != NULL && rs_ctx->sig != NULL) {
  ------------------
  |  Branch (325:13): [True: 0, False: 3]
  |  Branch (325:31): [True: 0, False: 0]
  ------------------
  326|      0|            rs_ctx->sig->state = ecdsa_sig_modn;
  327|      0|        }
  328|       |
  329|      3|modn:
  330|      3|#endif
  331|       |        /*
  332|       |         * Accounting for everything up to the end of the loop
  333|       |         * (step 6, but checking now avoids saving e and t)
  334|       |         */
  335|      3|        ECDSA_BUDGET(MBEDTLS_ECP_OPS_INV + 4);
  ------------------
  |  |  150|      3|    MBEDTLS_MPI_CHK(mbedtls_ecp_check_budget(grp, ECDSA_RS_ECP, ops));
  |  |  ------------------
  |  |  |  |   41|      3|    do                           \
  |  |  |  |   42|      3|    {                            \
  |  |  |  |   43|      6|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 3]
  |  |  |  |  |  Branch (43:21): [True: 3, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   44|      3|        goto cleanup;        \
  |  |  |  |   45|      3|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  336|       |
  337|       |        /*
  338|       |         * Step 5: derive MPI from hashed message
  339|       |         */
  340|      3|        MBEDTLS_MPI_CHK(derive_mpi(grp, &e, buf, blen));
  ------------------
  |  |   41|      3|    do                           \
  |  |   42|      3|    {                            \
  |  |   43|      3|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3]
  |  |  ------------------
  |  |   44|      3|        goto cleanup;        \
  |  |   45|      3|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  341|       |
  342|       |        /*
  343|       |         * Generate a random value to blind inv_mod in next step,
  344|       |         * avoiding a potential timing leak.
  345|       |         */
  346|      3|        MBEDTLS_MPI_CHK(mbedtls_ecp_gen_privkey(grp, &t, f_rng_blind,
  ------------------
  |  |   41|      3|    do                           \
  |  |   42|      3|    {                            \
  |  |   43|      3|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3]
  |  |  ------------------
  |  |   44|      3|        goto cleanup;        \
  |  |   45|      3|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  347|      3|                                                p_rng_blind));
  348|       |
  349|       |        /*
  350|       |         * Step 6: compute s = (e + r * d) / k = t (e + rd) / (kt) mod n
  351|       |         */
  352|      3|        MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(s, pr, d));
  ------------------
  |  |   41|      3|    do                           \
  |  |   42|      3|    {                            \
  |  |   43|      3|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3]
  |  |  ------------------
  |  |   44|      3|        goto cleanup;        \
  |  |   45|      3|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  353|      3|        MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&e, &e, s));
  ------------------
  |  |   41|      3|    do                           \
  |  |   42|      3|    {                            \
  |  |   43|      3|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3]
  |  |  ------------------
  |  |   44|      3|        goto cleanup;        \
  |  |   45|      3|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  354|      3|        MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&e, &e, &t));
  ------------------
  |  |   41|      3|    do                           \
  |  |   42|      3|    {                            \
  |  |   43|      3|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3]
  |  |  ------------------
  |  |   44|      3|        goto cleanup;        \
  |  |   45|      3|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  355|      3|        MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(pk, pk, &t));
  ------------------
  |  |   41|      3|    do                           \
  |  |   42|      3|    {                            \
  |  |   43|      3|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3]
  |  |  ------------------
  |  |   44|      3|        goto cleanup;        \
  |  |   45|      3|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  356|      3|        MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(pk, pk, &grp->N));
  ------------------
  |  |   41|      3|    do                           \
  |  |   42|      3|    {                            \
  |  |   43|      3|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3]
  |  |  ------------------
  |  |   44|      3|        goto cleanup;        \
  |  |   45|      3|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  357|      3|        MBEDTLS_MPI_CHK(mbedtls_mpi_inv_mod(s, pk, &grp->N));
  ------------------
  |  |   41|      3|    do                           \
  |  |   42|      3|    {                            \
  |  |   43|      3|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3]
  |  |  ------------------
  |  |   44|      3|        goto cleanup;        \
  |  |   45|      3|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  358|      3|        MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(s, s, &e));
  ------------------
  |  |   41|      3|    do                           \
  |  |   42|      3|    {                            \
  |  |   43|      3|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3]
  |  |  ------------------
  |  |   44|      3|        goto cleanup;        \
  |  |   45|      3|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  359|      3|        MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(s, s, &grp->N));
  ------------------
  |  |   41|      3|    do                           \
  |  |   42|      3|    {                            \
  |  |   43|      3|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3]
  |  |  ------------------
  |  |   44|      3|        goto cleanup;        \
  |  |   45|      3|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  360|      3|    } while (mbedtls_mpi_cmp_int(s, 0) == 0);
  ------------------
  |  Branch (360:14): [True: 0, False: 3]
  ------------------
  361|       |
  362|      3|#if defined(MBEDTLS_ECP_RESTARTABLE)
  363|      3|    if (rs_ctx != NULL && rs_ctx->sig != NULL) {
  ------------------
  |  Branch (363:9): [True: 0, False: 3]
  |  Branch (363:27): [True: 0, False: 0]
  ------------------
  364|      0|        MBEDTLS_MPI_CHK(mbedtls_mpi_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]
  |  |  ------------------
  ------------------
  365|      0|    }
  366|      3|#endif
  367|       |
  368|      3|cleanup:
  369|      3|    mbedtls_ecp_point_free(&R);
  370|      3|    mbedtls_mpi_free(&k); mbedtls_mpi_free(&e); mbedtls_mpi_free(&t);
  371|       |
  372|      3|    ECDSA_RS_LEAVE(sig);
  ------------------
  |  |  171|      3|#define ECDSA_RS_LEAVE(SUB)   do {                                 \
  |  |  172|      3|        /* clear our sub-context when not in progress (done or error) */ \
  |  |  173|      3|        if (rs_ctx != NULL && rs_ctx->SUB != NULL &&                     \
  |  |  ------------------
  |  |  |  Branch (173:13): [True: 0, False: 3]
  |  |  |  Branch (173:31): [True: 0, False: 0]
  |  |  ------------------
  |  |  174|      3|            ret != MBEDTLS_ERR_ECP_IN_PROGRESS)                         \
  |  |  ------------------
  |  |  |  |   51|      0|#define MBEDTLS_ERR_ECP_IN_PROGRESS                       -0x4B00
  |  |  ------------------
  |  |  |  Branch (174:13): [True: 0, False: 0]
  |  |  ------------------
  |  |  175|      3|        {                                                                \
  |  |  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|      3|                                                                     \
  |  |  181|      3|        if (rs_ctx != NULL)                                             \
  |  |  ------------------
  |  |  |  Branch (181:13): [True: 0, False: 3]
  |  |  ------------------
  |  |  182|      3|        rs_ctx->ecp.depth--;                                         \
  |  |  183|      3|} while (0)
  |  |  ------------------
  |  |  |  Branch (183:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
  373|       |
  374|      3|    return ret;
  375|      3|}
mbedtls_ecdsa_sign:
  383|      3|{
  384|       |    /* Use the same RNG for both blinding and ephemeral key generation */
  385|      3|    return mbedtls_ecdsa_sign_restartable(grp, r, s, d, buf, blen,
  386|      3|                                          f_rng, p_rng, f_rng, p_rng, NULL);
  387|      3|}
mbedtls_ecdsa_verify_restartable:
  494|  2.11k|{
  495|  2.11k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  2.11k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  496|  2.11k|    mbedtls_mpi e, s_inv, u1, u2;
  497|  2.11k|    mbedtls_ecp_point R;
  498|  2.11k|    mbedtls_mpi *pu1 = &u1, *pu2 = &u2;
  499|       |
  500|  2.11k|    mbedtls_ecp_point_init(&R);
  501|  2.11k|    mbedtls_mpi_init(&e); mbedtls_mpi_init(&s_inv);
  502|  2.11k|    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|  2.11k|    if (!mbedtls_ecdsa_can_do(grp->id) || grp->N.p == NULL) {
  ------------------
  |  Branch (505:9): [True: 0, False: 2.11k]
  |  Branch (505:43): [True: 0, False: 2.11k]
  ------------------
  506|      0|        return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
  507|      0|    }
  508|       |
  509|  2.11k|    ECDSA_RS_ENTER(ver);
  ------------------
  |  |  153|  2.11k|#define ECDSA_RS_ENTER(SUB)   do {                                 \
  |  |  154|  2.11k|        /* reset ops count for this call if top-level */                 \
  |  |  155|  2.11k|        if (rs_ctx != NULL && rs_ctx->ecp.depth++ == 0)                 \
  |  |  ------------------
  |  |  |  Branch (155:13): [True: 0, False: 2.11k]
  |  |  |  Branch (155:31): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|  2.11k|        rs_ctx->ecp.ops_done = 0;                                    \
  |  |  157|  2.11k|                                                                     \
  |  |  158|  2.11k|        /* set up our own sub-context if needed */                       \
  |  |  159|  2.11k|        if (mbedtls_ecp_restart_is_enabled() &&                          \
  |  |  ------------------
  |  |  |  Branch (159:13): [True: 0, False: 2.11k]
  |  |  ------------------
  |  |  160|  2.11k|            rs_ctx != NULL && rs_ctx->SUB == NULL)                      \
  |  |  ------------------
  |  |  |  Branch (160:13): [True: 0, False: 0]
  |  |  |  Branch (160:31): [True: 0, False: 0]
  |  |  ------------------
  |  |  161|  2.11k|        {                                                                \
  |  |  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|  2.11k|} while (0)
  |  |  ------------------
  |  |  |  Branch (168:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
  510|       |
  511|  2.11k|#if defined(MBEDTLS_ECP_RESTARTABLE)
  512|  2.11k|    if (rs_ctx != NULL && rs_ctx->ver != NULL) {
  ------------------
  |  Branch (512:9): [True: 0, False: 2.11k]
  |  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|  2.11k|#endif /* MBEDTLS_ECP_RESTARTABLE */
  523|       |
  524|       |    /*
  525|       |     * Step 1: make sure r and s are in range 1..n-1
  526|       |     */
  527|  2.11k|    if (mbedtls_mpi_cmp_int(r, 1) < 0 || mbedtls_mpi_cmp_mpi(r, &grp->N) >= 0 ||
  ------------------
  |  Branch (527:9): [True: 0, False: 2.11k]
  |  Branch (527:42): [True: 0, False: 2.11k]
  ------------------
  528|  2.11k|        mbedtls_mpi_cmp_int(s, 1) < 0 || mbedtls_mpi_cmp_mpi(s, &grp->N) >= 0) {
  ------------------
  |  Branch (528:9): [True: 0, False: 2.11k]
  |  Branch (528:42): [True: 0, False: 2.11k]
  ------------------
  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|  2.11k|    MBEDTLS_MPI_CHK(derive_mpi(grp, &e, buf, blen));
  ------------------
  |  |   41|  2.11k|    do                           \
  |  |   42|  2.11k|    {                            \
  |  |   43|  2.11k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.11k]
  |  |  ------------------
  |  |   44|  2.11k|        goto cleanup;        \
  |  |   45|  2.11k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  537|       |
  538|       |    /*
  539|       |     * Step 4: u1 = e / s mod n, u2 = r / s mod n
  540|       |     */
  541|  2.11k|    ECDSA_BUDGET(MBEDTLS_ECP_OPS_CHK + MBEDTLS_ECP_OPS_INV + 2);
  ------------------
  |  |  150|  2.11k|    MBEDTLS_MPI_CHK(mbedtls_ecp_check_budget(grp, ECDSA_RS_ECP, ops));
  |  |  ------------------
  |  |  |  |   41|  2.11k|    do                           \
  |  |  |  |   42|  2.11k|    {                            \
  |  |  |  |   43|  4.22k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 2.11k]
  |  |  |  |  |  Branch (43:21): [True: 2.11k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   44|  2.11k|        goto cleanup;        \
  |  |  |  |   45|  2.11k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  542|       |
  543|  2.11k|    MBEDTLS_MPI_CHK(mbedtls_mpi_inv_mod(&s_inv, s, &grp->N));
  ------------------
  |  |   41|  2.11k|    do                           \
  |  |   42|  2.11k|    {                            \
  |  |   43|  2.11k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.11k]
  |  |  ------------------
  |  |   44|  2.11k|        goto cleanup;        \
  |  |   45|  2.11k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  544|       |
  545|  2.11k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(pu1, &e, &s_inv));
  ------------------
  |  |   41|  2.11k|    do                           \
  |  |   42|  2.11k|    {                            \
  |  |   43|  2.11k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.11k]
  |  |  ------------------
  |  |   44|  2.11k|        goto cleanup;        \
  |  |   45|  2.11k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  546|  2.11k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(pu1, pu1, &grp->N));
  ------------------
  |  |   41|  2.11k|    do                           \
  |  |   42|  2.11k|    {                            \
  |  |   43|  2.11k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.11k]
  |  |  ------------------
  |  |   44|  2.11k|        goto cleanup;        \
  |  |   45|  2.11k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  547|       |
  548|  2.11k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(pu2, r, &s_inv));
  ------------------
  |  |   41|  2.11k|    do                           \
  |  |   42|  2.11k|    {                            \
  |  |   43|  2.11k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.11k]
  |  |  ------------------
  |  |   44|  2.11k|        goto cleanup;        \
  |  |   45|  2.11k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  549|  2.11k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(pu2, pu2, &grp->N));
  ------------------
  |  |   41|  2.11k|    do                           \
  |  |   42|  2.11k|    {                            \
  |  |   43|  2.11k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.11k]
  |  |  ------------------
  |  |   44|  2.11k|        goto cleanup;        \
  |  |   45|  2.11k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  550|       |
  551|  2.11k|#if defined(MBEDTLS_ECP_RESTARTABLE)
  552|  2.11k|    if (rs_ctx != NULL && rs_ctx->ver != NULL) {
  ------------------
  |  Branch (552:9): [True: 0, False: 2.11k]
  |  Branch (552:27): [True: 0, False: 0]
  ------------------
  553|      0|        rs_ctx->ver->state = ecdsa_ver_muladd;
  554|      0|    }
  555|       |
  556|  2.11k|muladd:
  557|  2.11k|#endif
  558|       |    /*
  559|       |     * Step 5: R = u1 G + u2 Q
  560|       |     */
  561|  2.11k|    MBEDTLS_MPI_CHK(mbedtls_ecp_muladd_restartable(grp,
  ------------------
  |  |   41|  2.11k|    do                           \
  |  |   42|  2.11k|    {                            \
  |  |   43|  4.22k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.11k]
  |  |  |  Branch (43:21): [True: 2.11k, False: 0]
  |  |  ------------------
  |  |   44|  2.11k|        goto cleanup;        \
  |  |   45|  2.11k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  562|  2.11k|                                                   &R, pu1, &grp->G, pu2, Q, ECDSA_RS_ECP));
  563|       |
  564|  2.11k|    if (mbedtls_ecp_is_zero(&R)) {
  ------------------
  |  Branch (564:9): [True: 0, False: 2.11k]
  ------------------
  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|  2.11k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&R.X, &R.X, &grp->N));
  ------------------
  |  |   41|  2.11k|    do                           \
  |  |   42|  2.11k|    {                            \
  |  |   43|  2.11k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.11k]
  |  |  ------------------
  |  |   44|  2.11k|        goto cleanup;        \
  |  |   45|  2.11k|    } 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|  2.11k|    if (mbedtls_mpi_cmp_mpi(&R.X, r) != 0) {
  ------------------
  |  Branch (578:9): [True: 0, False: 2.11k]
  ------------------
  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|  2.11k|cleanup:
  584|  2.11k|    mbedtls_ecp_point_free(&R);
  585|  2.11k|    mbedtls_mpi_free(&e); mbedtls_mpi_free(&s_inv);
  586|  2.11k|    mbedtls_mpi_free(&u1); mbedtls_mpi_free(&u2);
  587|       |
  588|  2.11k|    ECDSA_RS_LEAVE(ver);
  ------------------
  |  |  171|  2.11k|#define ECDSA_RS_LEAVE(SUB)   do {                                 \
  |  |  172|  2.11k|        /* clear our sub-context when not in progress (done or error) */ \
  |  |  173|  2.11k|        if (rs_ctx != NULL && rs_ctx->SUB != NULL &&                     \
  |  |  ------------------
  |  |  |  Branch (173:13): [True: 0, False: 2.11k]
  |  |  |  Branch (173:31): [True: 0, False: 0]
  |  |  ------------------
  |  |  174|  2.11k|            ret != MBEDTLS_ERR_ECP_IN_PROGRESS)                         \
  |  |  ------------------
  |  |  |  |   51|      0|#define MBEDTLS_ERR_ECP_IN_PROGRESS                       -0x4B00
  |  |  ------------------
  |  |  |  Branch (174:13): [True: 0, False: 0]
  |  |  ------------------
  |  |  175|  2.11k|        {                                                                \
  |  |  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|  2.11k|                                                                     \
  |  |  181|  2.11k|        if (rs_ctx != NULL)                                             \
  |  |  ------------------
  |  |  |  Branch (181:13): [True: 0, False: 2.11k]
  |  |  ------------------
  |  |  182|  2.11k|        rs_ctx->ecp.depth--;                                         \
  |  |  183|  2.11k|} while (0)
  |  |  ------------------
  |  |  |  Branch (183:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
  589|       |
  590|  2.11k|    return ret;
  591|  2.11k|}
mbedtls_ecdsa_read_signature:
  706|  2.11k|{
  707|  2.11k|    return mbedtls_ecdsa_read_signature_restartable(
  708|  2.11k|        ctx, hash, hlen, sig, slen, NULL);
  709|  2.11k|}
mbedtls_ecdsa_read_signature_restartable:
  718|  2.11k|{
  719|  2.11k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  2.11k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  720|  2.11k|    unsigned char *p = (unsigned char *) sig;
  721|  2.11k|    const unsigned char *end = sig + slen;
  722|  2.11k|    size_t len;
  723|  2.11k|    mbedtls_mpi r, s;
  724|  2.11k|    mbedtls_mpi_init(&r);
  725|  2.11k|    mbedtls_mpi_init(&s);
  726|       |
  727|  2.11k|    if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
  ------------------
  |  Branch (727:9): [True: 0, False: 2.11k]
  ------------------
  728|  2.11k|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|  2.11k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|  2.11k|#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|  2.11k|    if (p + len != end) {
  ------------------
  |  Branch (733:9): [True: 0, False: 2.11k]
  ------------------
  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|  2.11k|    if ((ret = mbedtls_asn1_get_mpi(&p, end, &r)) != 0 ||
  ------------------
  |  Branch (739:9): [True: 0, False: 2.11k]
  ------------------
  740|  2.11k|        (ret = mbedtls_asn1_get_mpi(&p, end, &s)) != 0) {
  ------------------
  |  Branch (740:9): [True: 0, False: 2.11k]
  ------------------
  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|  2.11k|    if ((ret = mbedtls_ecdsa_verify_restartable(&ctx->grp, hash, hlen,
  ------------------
  |  Branch (752:9): [True: 0, False: 2.11k]
  ------------------
  753|  2.11k|                                                &ctx->Q, &r, &s, rs_ctx)) != 0) {
  754|      0|        goto cleanup;
  755|      0|    }
  756|  2.11k|#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|  2.11k|    if (p != end) {
  ------------------
  |  Branch (761:9): [True: 0, False: 2.11k]
  ------------------
  762|      0|        ret = MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH;
  ------------------
  |  |   49|      0|#define MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH                  -0x4C00
  ------------------
  763|      0|    }
  764|       |
  765|  2.11k|cleanup:
  766|  2.11k|    mbedtls_mpi_free(&r);
  767|  2.11k|    mbedtls_mpi_free(&s);
  768|       |
  769|  2.11k|    return ret;
  770|  2.11k|}
ecdsa.c:derive_mpi:
  205|  2.11k|{
  206|  2.11k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  2.11k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  207|  2.11k|    size_t n_size = (grp->nbits + 7) / 8;
  208|  2.11k|    size_t use_size = blen > n_size ? n_size : blen;
  ------------------
  |  Branch (208:23): [True: 0, False: 2.11k]
  ------------------
  209|       |
  210|  2.11k|    MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(x, buf, use_size));
  ------------------
  |  |   41|  2.11k|    do                           \
  |  |   42|  2.11k|    {                            \
  |  |   43|  2.11k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.11k]
  |  |  ------------------
  |  |   44|  2.11k|        goto cleanup;        \
  |  |   45|  2.11k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  211|  2.11k|    if (use_size * 8 > grp->nbits) {
  ------------------
  |  Branch (211:9): [True: 0, False: 2.11k]
  ------------------
  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|  2.11k|    if (mbedtls_mpi_cmp_mpi(x, &grp->N) >= 0) {
  ------------------
  |  Branch (216:9): [True: 0, False: 2.11k]
  ------------------
  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|  2.11k|cleanup:
  221|  2.11k|    return ret;
  222|  2.11k|}

mbedtls_ecp_restart_is_enabled:
  117|  8.45k|{
  118|  8.45k|    return ecp_max_ops != 0;
  119|  8.45k|}
mbedtls_ecp_restart_init:
  218|  2.11k|{
  219|  2.11k|    ctx->ops_done = 0;
  220|  2.11k|    ctx->depth = 0;
  221|  2.11k|    ctx->rsm = NULL;
  222|  2.11k|    ctx->ma = NULL;
  223|  2.11k|}
mbedtls_ecp_restart_free:
  229|  1.05k|{
  230|  1.05k|    if (ctx == NULL) {
  ------------------
  |  Branch (230:9): [True: 0, False: 1.05k]
  ------------------
  231|      0|        return;
  232|      0|    }
  233|       |
  234|  1.05k|    ecp_restart_rsm_free(ctx->rsm);
  235|  1.05k|    mbedtls_free(ctx->rsm);
  ------------------
  |  |  143|  1.05k|#define mbedtls_free       MBEDTLS_PLATFORM_FREE_MACRO
  |  |  ------------------
  |  |  |  | 4095|  1.05k|#define MBEDTLS_PLATFORM_FREE_MACRO            my_free
  |  |  ------------------
  ------------------
  236|       |
  237|  1.05k|    ecp_restart_ma_free(ctx->ma);
  238|  1.05k|    mbedtls_free(ctx->ma);
  ------------------
  |  |  143|  1.05k|#define mbedtls_free       MBEDTLS_PLATFORM_FREE_MACRO
  |  |  ------------------
  |  |  |  | 4095|  1.05k|#define MBEDTLS_PLATFORM_FREE_MACRO            my_free
  |  |  ------------------
  ------------------
  239|       |
  240|  1.05k|    mbedtls_ecp_restart_init(ctx);
  241|  1.05k|}
mbedtls_ecp_check_budget:
  249|   671k|{
  250|   671k|    if (rs_ctx != NULL && ecp_max_ops != 0) {
  ------------------
  |  Branch (250:9): [True: 0, False: 671k]
  |  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|   671k|    return 0;
  274|   671k|}
mbedtls_ecp_get_type:
  487|  95.0k|{
  488|  95.0k|    if (grp->G.X.p == NULL) {
  ------------------
  |  Branch (488:9): [True: 0, False: 95.0k]
  ------------------
  489|      0|        return MBEDTLS_ECP_TYPE_NONE;
  490|      0|    }
  491|       |
  492|  95.0k|    if (grp->G.Y.p == NULL) {
  ------------------
  |  Branch (492:9): [True: 0, False: 95.0k]
  ------------------
  493|      0|        return MBEDTLS_ECP_TYPE_MONTGOMERY;
  494|  95.0k|    } else {
  495|  95.0k|        return MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS;
  496|  95.0k|    }
  497|  95.0k|}
mbedtls_ecp_point_init:
  503|  82.4k|{
  504|  82.4k|    mbedtls_mpi_init(&pt->X);
  505|  82.4k|    mbedtls_mpi_init(&pt->Y);
  506|  82.4k|    mbedtls_mpi_init(&pt->Z);
  507|  82.4k|}
mbedtls_ecp_group_init:
  513|  35.9k|{
  514|  35.9k|    grp->id = MBEDTLS_ECP_DP_NONE;
  515|  35.9k|    mbedtls_mpi_init(&grp->P);
  516|  35.9k|    mbedtls_mpi_init(&grp->A);
  517|  35.9k|    mbedtls_mpi_init(&grp->B);
  518|  35.9k|    mbedtls_ecp_point_init(&grp->G);
  519|  35.9k|    mbedtls_mpi_init(&grp->N);
  520|  35.9k|    grp->pbits = 0;
  521|  35.9k|    grp->nbits = 0;
  522|  35.9k|    grp->h = 0;
  523|  35.9k|    grp->modp = NULL;
  524|  35.9k|    grp->t_pre = NULL;
  525|  35.9k|    grp->t_post = NULL;
  526|  35.9k|    grp->t_data = NULL;
  527|  35.9k|    grp->T = NULL;
  528|  35.9k|    grp->T_size = 0;
  529|  35.9k|}
mbedtls_ecp_keypair_init:
  535|  16.8k|{
  536|  16.8k|    mbedtls_ecp_group_init(&key->grp);
  537|  16.8k|    mbedtls_mpi_init(&key->d);
  538|  16.8k|    mbedtls_ecp_point_init(&key->Q);
  539|  16.8k|}
mbedtls_ecp_point_free:
  545|  64.4k|{
  546|  64.4k|    if (pt == NULL) {
  ------------------
  |  Branch (546:9): [True: 0, False: 64.4k]
  ------------------
  547|      0|        return;
  548|      0|    }
  549|       |
  550|  64.4k|    mbedtls_mpi_free(&(pt->X));
  551|  64.4k|    mbedtls_mpi_free(&(pt->Y));
  552|  64.4k|    mbedtls_mpi_free(&(pt->Z));
  553|  64.4k|}
mbedtls_ecp_group_free:
  572|  35.9k|{
  573|  35.9k|    size_t i;
  574|       |
  575|  35.9k|    if (grp == NULL) {
  ------------------
  |  Branch (575:9): [True: 0, False: 35.9k]
  ------------------
  576|      0|        return;
  577|      0|    }
  578|       |
  579|  35.9k|    if (grp->h != 1) {
  ------------------
  |  Branch (579:9): [True: 17.9k, False: 17.9k]
  ------------------
  580|  17.9k|        mbedtls_mpi_free(&grp->A);
  581|  17.9k|        mbedtls_mpi_free(&grp->B);
  582|  17.9k|        mbedtls_ecp_point_free(&grp->G);
  583|       |
  584|  17.9k|#if !defined(MBEDTLS_ECP_WITH_MPI_UINT)
  585|  17.9k|        mbedtls_mpi_free(&grp->N);
  586|  17.9k|        mbedtls_mpi_free(&grp->P);
  587|  17.9k|#endif
  588|  17.9k|    }
  589|       |
  590|  35.9k|    if (!ecp_group_is_static_comb_table(grp) && grp->T != NULL) {
  ------------------
  |  Branch (590:9): [True: 17.9k, False: 17.9k]
  |  Branch (590:49): [True: 0, False: 17.9k]
  ------------------
  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|  35.9k|    mbedtls_platform_zeroize(grp, sizeof(mbedtls_ecp_group));
  598|  35.9k|}
mbedtls_ecp_keypair_free:
  604|  16.8k|{
  605|  16.8k|    if (key == NULL) {
  ------------------
  |  Branch (605:9): [True: 0, False: 16.8k]
  ------------------
  606|      0|        return;
  607|      0|    }
  608|       |
  609|  16.8k|    mbedtls_ecp_group_free(&key->grp);
  610|  16.8k|    mbedtls_mpi_free(&key->d);
  611|  16.8k|    mbedtls_ecp_point_free(&key->Q);
  612|  16.8k|}
mbedtls_ecp_copy:
  618|  9.50k|{
  619|  9.50k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  9.50k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  620|  9.50k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&P->X, &Q->X));
  ------------------
  |  |   41|  9.50k|    do                           \
  |  |   42|  9.50k|    {                            \
  |  |   43|  9.50k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 9.50k]
  |  |  ------------------
  |  |   44|  9.50k|        goto cleanup;        \
  |  |   45|  9.50k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  621|  9.50k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&P->Y, &Q->Y));
  ------------------
  |  |   41|  9.50k|    do                           \
  |  |   42|  9.50k|    {                            \
  |  |   43|  9.50k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 9.50k]
  |  |  ------------------
  |  |   44|  9.50k|        goto cleanup;        \
  |  |   45|  9.50k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  622|  9.50k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&P->Z, &Q->Z));
  ------------------
  |  |   41|  9.50k|    do                           \
  |  |   42|  9.50k|    {                            \
  |  |   43|  9.50k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 9.50k]
  |  |  ------------------
  |  |   44|  9.50k|        goto cleanup;        \
  |  |   45|  9.50k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  623|       |
  624|  9.50k|cleanup:
  625|  9.50k|    return ret;
  626|  9.50k|}
mbedtls_ecp_is_zero:
  654|  2.11k|{
  655|  2.11k|    return mbedtls_mpi_cmp_int(&pt->Z, 0) == 0;
  656|  2.11k|}
mbedtls_ecp_point_read_binary:
  772|  16.8k|{
  773|  16.8k|    int ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
  ------------------
  |  |   39|  16.8k|#define MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE               -0x4E80
  ------------------
  774|  16.8k|    size_t plen;
  775|  16.8k|    if (ilen < 1) {
  ------------------
  |  Branch (775:9): [True: 0, False: 16.8k]
  ------------------
  776|      0|        return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
  777|      0|    }
  778|       |
  779|  16.8k|    plen = mbedtls_mpi_size(&grp->P);
  780|       |
  781|  16.8k|#if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED)
  782|  16.8k|    if (mbedtls_ecp_get_type(grp) == MBEDTLS_ECP_TYPE_MONTGOMERY) {
  ------------------
  |  Branch (782:9): [True: 0, False: 16.8k]
  ------------------
  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|  16.8k|#endif
  798|  16.8k|#if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
  799|  16.8k|    if (mbedtls_ecp_get_type(grp) == MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS) {
  ------------------
  |  Branch (799:9): [True: 16.8k, False: 0]
  ------------------
  800|  16.8k|        if (buf[0] == 0x00) {
  ------------------
  |  Branch (800:13): [True: 0, False: 16.8k]
  ------------------
  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|  16.8k|        if (ilen < 1 + plen) {
  ------------------
  |  Branch (808:13): [True: 0, False: 16.8k]
  ------------------
  809|      0|            return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
  810|      0|        }
  811|       |
  812|  16.8k|        MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&pt->X, buf + 1, plen));
  ------------------
  |  |   41|  16.8k|    do                           \
  |  |   42|  16.8k|    {                            \
  |  |   43|  16.8k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 16.8k]
  |  |  ------------------
  |  |   44|  16.8k|        goto cleanup;        \
  |  |   45|  16.8k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  813|  16.8k|        MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&pt->Z, 1));
  ------------------
  |  |   41|  16.8k|    do                           \
  |  |   42|  16.8k|    {                            \
  |  |   43|  16.8k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 16.8k]
  |  |  ------------------
  |  |   44|  16.8k|        goto cleanup;        \
  |  |   45|  16.8k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  814|       |
  815|  16.8k|        if (buf[0] == 0x04) {
  ------------------
  |  Branch (815:13): [True: 16.8k, False: 0]
  ------------------
  816|       |            /* format == MBEDTLS_ECP_PF_UNCOMPRESSED */
  817|  16.8k|            if (ilen != 1 + plen * 2) {
  ------------------
  |  Branch (817:17): [True: 0, False: 16.8k]
  ------------------
  818|      0|                return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
  819|      0|            }
  820|  16.8k|            return mbedtls_mpi_read_binary(&pt->Y, buf + 1 + plen, plen);
  821|  16.8k|        } 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|  16.8k|    }
  832|      0|#endif
  833|       |
  834|      0|cleanup:
  835|      0|    return ret;
  836|  16.8k|}
mbedtls_ecp_mul_restartable:
 2701|      3|{
 2702|      3|    if (f_rng == NULL) {
  ------------------
  |  Branch (2702:9): [True: 0, False: 3]
  ------------------
 2703|      0|        return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
 2704|      0|    }
 2705|       |
 2706|      3|    return ecp_mul_restartable_internal(grp, R, m, P, f_rng, p_rng, rs_ctx);
 2707|      3|}
mbedtls_ecp_muladd_restartable:
 2805|  2.11k|{
 2806|  2.11k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  2.11k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 2807|  2.11k|    mbedtls_ecp_point mP;
 2808|  2.11k|    mbedtls_ecp_point *pmP = &mP;
 2809|  2.11k|    mbedtls_ecp_point *pR = R;
 2810|  2.11k|    mbedtls_mpi tmp[4];
 2811|       |#if defined(MBEDTLS_ECP_INTERNAL_ALT)
 2812|       |    char is_grp_capable = 0;
 2813|       |#endif
 2814|  2.11k|    if (mbedtls_ecp_get_type(grp) != MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS) {
  ------------------
  |  Branch (2814:9): [True: 0, False: 2.11k]
  ------------------
 2815|      0|        return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
  ------------------
  |  |   39|      0|#define MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE               -0x4E80
  ------------------
 2816|      0|    }
 2817|       |
 2818|  2.11k|    mbedtls_ecp_point_init(&mP);
 2819|  2.11k|    mpi_init_many(tmp, sizeof(tmp) / sizeof(mbedtls_mpi));
 2820|       |
 2821|  2.11k|    ECP_RS_ENTER(ma);
  ------------------
  |  |  277|  2.11k|#define ECP_RS_ENTER(SUB)   do {                                      \
  |  |  278|  2.11k|        /* reset ops count for this call if top-level */                    \
  |  |  279|  2.11k|        if (rs_ctx != NULL && rs_ctx->depth++ == 0)                        \
  |  |  ------------------
  |  |  |  Branch (279:13): [True: 0, False: 2.11k]
  |  |  |  Branch (279:31): [True: 0, False: 0]
  |  |  ------------------
  |  |  280|  2.11k|        rs_ctx->ops_done = 0;                                           \
  |  |  281|  2.11k|                                                                        \
  |  |  282|  2.11k|        /* set up our own sub-context if needed */                          \
  |  |  283|  2.11k|        if (mbedtls_ecp_restart_is_enabled() &&                             \
  |  |  ------------------
  |  |  |  Branch (283:13): [True: 0, False: 2.11k]
  |  |  ------------------
  |  |  284|  2.11k|            rs_ctx != NULL && rs_ctx->SUB == NULL)                         \
  |  |  ------------------
  |  |  |  Branch (284:13): [True: 0, False: 0]
  |  |  |  Branch (284:31): [True: 0, False: 0]
  |  |  ------------------
  |  |  285|  2.11k|        {                                                                   \
  |  |  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|  2.11k|} while (0)
  |  |  ------------------
  |  |  |  Branch (292:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2822|       |
 2823|  2.11k|#if defined(MBEDTLS_ECP_RESTARTABLE)
 2824|  2.11k|    if (rs_ctx != NULL && rs_ctx->ma != NULL) {
  ------------------
  |  Branch (2824:9): [True: 0, False: 2.11k]
  |  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|  2.11k|#endif /* MBEDTLS_ECP_RESTARTABLE */
 2841|       |
 2842|  2.11k|    MBEDTLS_MPI_CHK(mbedtls_ecp_mul_shortcuts(grp, pmP, m, P, rs_ctx));
  ------------------
  |  |   41|  2.11k|    do                           \
  |  |   42|  2.11k|    {                            \
  |  |   43|  2.11k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.11k]
  |  |  ------------------
  |  |   44|  2.11k|        goto cleanup;        \
  |  |   45|  2.11k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2843|  2.11k|#if defined(MBEDTLS_ECP_RESTARTABLE)
 2844|  2.11k|    if (rs_ctx != NULL && rs_ctx->ma != NULL) {
  ------------------
  |  Branch (2844:9): [True: 0, False: 2.11k]
  |  Branch (2844:27): [True: 0, False: 0]
  ------------------
 2845|      0|        rs_ctx->ma->state = ecp_rsma_mul2;
 2846|      0|    }
 2847|       |
 2848|  2.11k|mul2:
 2849|  2.11k|#endif
 2850|  2.11k|    MBEDTLS_MPI_CHK(mbedtls_ecp_mul_shortcuts(grp, pR,  n, Q, rs_ctx));
  ------------------
  |  |   41|  2.11k|    do                           \
  |  |   42|  2.11k|    {                            \
  |  |   43|  2.11k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.11k]
  |  |  ------------------
  |  |   44|  2.11k|        goto cleanup;        \
  |  |   45|  2.11k|    } 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|  2.11k|#if defined(MBEDTLS_ECP_RESTARTABLE)
 2859|  2.11k|    if (rs_ctx != NULL && rs_ctx->ma != NULL) {
  ------------------
  |  Branch (2859:9): [True: 0, False: 2.11k]
  |  Branch (2859:27): [True: 0, False: 0]
  ------------------
 2860|      0|        rs_ctx->ma->state = ecp_rsma_add;
 2861|      0|    }
 2862|       |
 2863|  2.11k|add:
 2864|  2.11k|#endif
 2865|  2.11k|    MBEDTLS_ECP_BUDGET(MBEDTLS_ECP_OPS_ADD);
  ------------------
  |  |  408|  2.11k|    MBEDTLS_MPI_CHK(mbedtls_ecp_check_budget(grp, rs_ctx, \
  |  |  ------------------
  |  |  |  |   41|  2.11k|    do                           \
  |  |  |  |   42|  2.11k|    {                            \
  |  |  |  |   43|  2.11k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 2.11k]
  |  |  |  |  ------------------
  |  |  |  |   44|  2.11k|        goto cleanup;        \
  |  |  |  |   45|  2.11k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  409|  2.11k|                                             (unsigned) (ops)));
  ------------------
 2866|  2.11k|    MBEDTLS_MPI_CHK(ecp_add_mixed(grp, pR, pmP, pR, tmp));
  ------------------
  |  |   41|  2.11k|    do                           \
  |  |   42|  2.11k|    {                            \
  |  |   43|  2.11k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.11k]
  |  |  ------------------
  |  |   44|  2.11k|        goto cleanup;        \
  |  |   45|  2.11k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2867|  2.11k|#if defined(MBEDTLS_ECP_RESTARTABLE)
 2868|  2.11k|    if (rs_ctx != NULL && rs_ctx->ma != NULL) {
  ------------------
  |  Branch (2868:9): [True: 0, False: 2.11k]
  |  Branch (2868:27): [True: 0, False: 0]
  ------------------
 2869|      0|        rs_ctx->ma->state = ecp_rsma_norm;
 2870|      0|    }
 2871|       |
 2872|  2.11k|norm:
 2873|  2.11k|#endif
 2874|  2.11k|    MBEDTLS_ECP_BUDGET(MBEDTLS_ECP_OPS_INV);
  ------------------
  |  |  408|  2.11k|    MBEDTLS_MPI_CHK(mbedtls_ecp_check_budget(grp, rs_ctx, \
  |  |  ------------------
  |  |  |  |   41|  2.11k|    do                           \
  |  |  |  |   42|  2.11k|    {                            \
  |  |  |  |   43|  2.11k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 2.11k]
  |  |  |  |  ------------------
  |  |  |  |   44|  2.11k|        goto cleanup;        \
  |  |  |  |   45|  2.11k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  409|  2.11k|                                             (unsigned) (ops)));
  ------------------
 2875|  2.11k|    MBEDTLS_MPI_CHK(ecp_normalize_jac(grp, pR));
  ------------------
  |  |   41|  2.11k|    do                           \
  |  |   42|  2.11k|    {                            \
  |  |   43|  2.11k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.11k]
  |  |  ------------------
  |  |   44|  2.11k|        goto cleanup;        \
  |  |   45|  2.11k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2876|       |
 2877|  2.11k|#if defined(MBEDTLS_ECP_RESTARTABLE)
 2878|  2.11k|    if (rs_ctx != NULL && rs_ctx->ma != NULL) {
  ------------------
  |  Branch (2878:9): [True: 0, False: 2.11k]
  |  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|  2.11k|#endif
 2882|       |
 2883|  2.11k|cleanup:
 2884|       |
 2885|  2.11k|    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|  2.11k|    mbedtls_ecp_point_free(&mP);
 2894|       |
 2895|  2.11k|    ECP_RS_LEAVE(ma);
  ------------------
  |  |  295|  2.11k|#define ECP_RS_LEAVE(SUB)   do {                                      \
  |  |  296|  2.11k|        /* clear our sub-context when not in progress (done or error) */    \
  |  |  297|  2.11k|        if (rs_ctx != NULL && rs_ctx->SUB != NULL &&                        \
  |  |  ------------------
  |  |  |  Branch (297:13): [True: 0, False: 2.11k]
  |  |  |  Branch (297:31): [True: 0, False: 0]
  |  |  ------------------
  |  |  298|  2.11k|            ret != MBEDTLS_ERR_ECP_IN_PROGRESS)                            \
  |  |  ------------------
  |  |  |  |   51|      0|#define MBEDTLS_ERR_ECP_IN_PROGRESS                       -0x4B00
  |  |  ------------------
  |  |  |  Branch (298:13): [True: 0, False: 0]
  |  |  ------------------
  |  |  299|  2.11k|        {                                                                   \
  |  |  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|  2.11k|                                                                        \
  |  |  305|  2.11k|        if (rs_ctx != NULL)                                                \
  |  |  ------------------
  |  |  |  Branch (305:13): [True: 0, False: 2.11k]
  |  |  ------------------
  |  |  306|  2.11k|        rs_ctx->depth--;                                                \
  |  |  307|  2.11k|} while (0)
  |  |  ------------------
  |  |  |  Branch (307:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2896|       |
 2897|  2.11k|    return ret;
 2898|  2.11k|}
mbedtls_ecp_check_pubkey:
 3029|  21.1k|{
 3030|       |    /* Must use affine coordinates */
 3031|  21.1k|    if (mbedtls_mpi_cmp_int(&pt->Z, 1) != 0) {
  ------------------
  |  Branch (3031:9): [True: 0, False: 21.1k]
  ------------------
 3032|      0|        return MBEDTLS_ERR_ECP_INVALID_KEY;
  ------------------
  |  |   47|      0|#define MBEDTLS_ERR_ECP_INVALID_KEY                       -0x4C80
  ------------------
 3033|      0|    }
 3034|       |
 3035|  21.1k|#if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED)
 3036|  21.1k|    if (mbedtls_ecp_get_type(grp) == MBEDTLS_ECP_TYPE_MONTGOMERY) {
  ------------------
  |  Branch (3036:9): [True: 0, False: 21.1k]
  ------------------
 3037|      0|        return ecp_check_pubkey_mx(grp, pt);
 3038|      0|    }
 3039|  21.1k|#endif
 3040|  21.1k|#if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
 3041|  21.1k|    if (mbedtls_ecp_get_type(grp) == MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS) {
  ------------------
  |  Branch (3041:9): [True: 21.1k, False: 0]
  ------------------
 3042|  21.1k|        return ecp_check_pubkey_sw(grp, pt);
 3043|  21.1k|    }
 3044|      0|#endif
 3045|      0|    return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
 3046|  21.1k|}
mbedtls_ecp_check_privkey:
 3053|  4.23k|{
 3054|  4.23k|#if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED)
 3055|  4.23k|    if (mbedtls_ecp_get_type(grp) == MBEDTLS_ECP_TYPE_MONTGOMERY) {
  ------------------
  |  Branch (3055:9): [True: 0, False: 4.23k]
  ------------------
 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|  4.23k|#endif /* MBEDTLS_ECP_MONTGOMERY_ENABLED */
 3071|  4.23k|#if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
 3072|  4.23k|    if (mbedtls_ecp_get_type(grp) == MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS) {
  ------------------
  |  Branch (3072:9): [True: 4.23k, False: 0]
  ------------------
 3073|       |        /* see SEC1 3.2 */
 3074|  4.23k|        if (mbedtls_mpi_cmp_int(d, 1) < 0 ||
  ------------------
  |  Branch (3074:13): [True: 0, False: 4.23k]
  ------------------
 3075|  4.23k|            mbedtls_mpi_cmp_mpi(d, &grp->N) >= 0) {
  ------------------
  |  Branch (3075:13): [True: 0, False: 4.23k]
  ------------------
 3076|      0|            return MBEDTLS_ERR_ECP_INVALID_KEY;
  ------------------
  |  |   47|      0|#define MBEDTLS_ERR_ECP_INVALID_KEY                       -0x4C80
  ------------------
 3077|  4.23k|        } else {
 3078|  4.23k|            return 0;
 3079|  4.23k|        }
 3080|  4.23k|    }
 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|  4.23k|}
mbedtls_ecp_gen_privkey:
 3141|      6|{
 3142|      6|#if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED)
 3143|      6|    if (mbedtls_ecp_get_type(grp) == MBEDTLS_ECP_TYPE_MONTGOMERY) {
  ------------------
  |  Branch (3143:9): [True: 0, False: 6]
  ------------------
 3144|      0|        return mbedtls_ecp_gen_privkey_mx(grp->nbits, d, f_rng, p_rng);
 3145|      0|    }
 3146|      6|#endif /* MBEDTLS_ECP_MONTGOMERY_ENABLED */
 3147|       |
 3148|      6|#if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
 3149|      6|    if (mbedtls_ecp_get_type(grp) == MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS) {
  ------------------
  |  Branch (3149:9): [True: 6, False: 0]
  ------------------
 3150|      6|        return mbedtls_ecp_gen_privkey_sw(&grp->N, d, f_rng, p_rng);
 3151|      6|    }
 3152|      0|#endif /* MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED */
 3153|       |
 3154|      0|    return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
 3155|      6|}
mbedtls_ecp_read_key:
 3227|      3|{
 3228|      3|    int ret = 0;
 3229|       |
 3230|      3|    if ((ret = mbedtls_ecp_group_load(&key->grp, grp_id)) != 0) {
  ------------------
  |  Branch (3230:9): [True: 0, False: 3]
  ------------------
 3231|      0|        return ret;
 3232|      0|    }
 3233|       |
 3234|      3|    ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
  ------------------
  |  |   39|      3|#define MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE               -0x4E80
  ------------------
 3235|       |
 3236|      3|#if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED)
 3237|      3|    if (mbedtls_ecp_get_type(&key->grp) == MBEDTLS_ECP_TYPE_MONTGOMERY) {
  ------------------
  |  Branch (3237:9): [True: 0, False: 3]
  ------------------
 3238|       |        /*
 3239|       |         * Mask the key as mandated by RFC7748 for Curve25519 and Curve448.
 3240|       |         */
 3241|      0|        if (grp_id == MBEDTLS_ECP_DP_CURVE25519) {
  ------------------
  |  Branch (3241:13): [True: 0, False: 0]
  ------------------
 3242|      0|            if (buflen != ECP_CURVE25519_KEY_SIZE) {
  ------------------
  |  | 3220|      0|#define ECP_CURVE25519_KEY_SIZE 32
  ------------------
  |  Branch (3242:17): [True: 0, False: 0]
  ------------------
 3243|      0|                return MBEDTLS_ERR_ECP_INVALID_KEY;
  ------------------
  |  |   47|      0|#define MBEDTLS_ERR_ECP_INVALID_KEY                       -0x4C80
  ------------------
 3244|      0|            }
 3245|       |
 3246|      0|            MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary_le(&key->d, buf, buflen));
  ------------------
  |  |   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]
  |  |  ------------------
  ------------------
 3247|       |
 3248|       |            /* Set the three least significant bits to 0 */
 3249|      0|            MBEDTLS_MPI_CHK(mbedtls_mpi_set_bit(&key->d, 0, 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]
  |  |  ------------------
  ------------------
 3250|      0|            MBEDTLS_MPI_CHK(mbedtls_mpi_set_bit(&key->d, 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]
  |  |  ------------------
  ------------------
 3251|      0|            MBEDTLS_MPI_CHK(mbedtls_mpi_set_bit(&key->d, 2, 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]
  |  |  ------------------
  ------------------
 3252|       |
 3253|       |            /* Set the most significant bit to 0 */
 3254|      0|            MBEDTLS_MPI_CHK(
  ------------------
  |  |   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]
  |  |  ------------------
  ------------------
 3255|      0|                mbedtls_mpi_set_bit(&key->d,
 3256|      0|                                    ECP_CURVE25519_KEY_SIZE * 8 - 1, 0)
 3257|      0|                );
 3258|       |
 3259|       |            /* Set the second most significant bit to 1 */
 3260|      0|            MBEDTLS_MPI_CHK(
  ------------------
  |  |   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]
  |  |  ------------------
  ------------------
 3261|      0|                mbedtls_mpi_set_bit(&key->d,
 3262|      0|                                    ECP_CURVE25519_KEY_SIZE * 8 - 2, 1)
 3263|      0|                );
 3264|      0|        } else if (grp_id == MBEDTLS_ECP_DP_CURVE448) {
  ------------------
  |  Branch (3264:20): [True: 0, False: 0]
  ------------------
 3265|      0|            if (buflen != ECP_CURVE448_KEY_SIZE) {
  ------------------
  |  | 3221|      0|#define ECP_CURVE448_KEY_SIZE   56
  ------------------
  |  Branch (3265:17): [True: 0, False: 0]
  ------------------
 3266|      0|                return MBEDTLS_ERR_ECP_INVALID_KEY;
  ------------------
  |  |   47|      0|#define MBEDTLS_ERR_ECP_INVALID_KEY                       -0x4C80
  ------------------
 3267|      0|            }
 3268|       |
 3269|      0|            MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary_le(&key->d, buf, buflen));
  ------------------
  |  |   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]
  |  |  ------------------
  ------------------
 3270|       |
 3271|       |            /* Set the two least significant bits to 0 */
 3272|      0|            MBEDTLS_MPI_CHK(mbedtls_mpi_set_bit(&key->d, 0, 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]
  |  |  ------------------
  ------------------
 3273|      0|            MBEDTLS_MPI_CHK(mbedtls_mpi_set_bit(&key->d, 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]
  |  |  ------------------
  ------------------
 3274|       |
 3275|       |            /* Set the most significant bit to 1 */
 3276|      0|            MBEDTLS_MPI_CHK(
  ------------------
  |  |   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]
  |  |  ------------------
  ------------------
 3277|      0|                mbedtls_mpi_set_bit(&key->d,
 3278|      0|                                    ECP_CURVE448_KEY_SIZE * 8 - 1, 1)
 3279|      0|                );
 3280|      0|        }
 3281|      0|    }
 3282|      3|#endif
 3283|      3|#if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
 3284|      3|    if (mbedtls_ecp_get_type(&key->grp) == MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS) {
  ------------------
  |  Branch (3284:9): [True: 3, False: 0]
  ------------------
 3285|      3|        MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&key->d, buf, buflen));
  ------------------
  |  |   41|      3|    do                           \
  |  |   42|      3|    {                            \
  |  |   43|      3|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3]
  |  |  ------------------
  |  |   44|      3|        goto cleanup;        \
  |  |   45|      3|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 3286|      3|    }
 3287|      3|#endif
 3288|       |
 3289|      3|    if (ret == 0) {
  ------------------
  |  Branch (3289:9): [True: 3, False: 0]
  ------------------
 3290|      3|        MBEDTLS_MPI_CHK(mbedtls_ecp_check_privkey(&key->grp, &key->d));
  ------------------
  |  |   41|      3|    do                           \
  |  |   42|      3|    {                            \
  |  |   43|      3|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3]
  |  |  ------------------
  |  |   44|      3|        goto cleanup;        \
  |  |   45|      3|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 3291|      3|    }
 3292|       |
 3293|      3|cleanup:
 3294|       |
 3295|      3|    if (ret != 0) {
  ------------------
  |  Branch (3295:9): [True: 0, False: 3]
  ------------------
 3296|      0|        mbedtls_mpi_free(&key->d);
 3297|      0|    }
 3298|       |
 3299|      3|    return ret;
 3300|      3|}
ecp.c:ecp_restart_rsm_free:
  156|  1.05k|{
  157|  1.05k|    unsigned char i;
  158|       |
  159|  1.05k|    if (ctx == NULL) {
  ------------------
  |  Branch (159:9): [True: 1.05k, False: 0]
  ------------------
  160|  1.05k|        return;
  161|  1.05k|    }
  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|  1.05k|{
  204|  1.05k|    if (ctx == NULL) {
  ------------------
  |  Branch (204:9): [True: 1.05k, False: 0]
  ------------------
  205|  1.05k|        return;
  206|  1.05k|    }
  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|  38.0k|{
  560|  38.0k|#if MBEDTLS_ECP_FIXED_POINT_OPTIM == 1
  561|  38.0k|    return grp->T != NULL && grp->T_size == 0;
  ------------------
  |  Branch (561:12): [True: 20.0k, False: 17.9k]
  |  Branch (561:30): [True: 20.0k, False: 0]
  ------------------
  562|       |#else
  563|       |    (void) grp;
  564|       |    return 0;
  565|       |#endif
  566|  38.0k|}
ecp.c:ecp_sw_rhs:
 1228|  21.1k|{
 1229|  21.1k|    int ret;
 1230|       |
 1231|       |    /* Compute X^3 + A X + B as X (X^2 + A) + B */
 1232|  21.1k|    MPI_ECP_SQR(rhs, X);
  ------------------
  |  | 1170|  21.1k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, A))
  |  |  ------------------
  |  |  |  |   41|  21.1k|    do                           \
  |  |  |  |   42|  21.1k|    {                            \
  |  |  |  |   43|  21.1k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 21.1k]
  |  |  |  |  ------------------
  |  |  |  |   44|  21.1k|        goto cleanup;        \
  |  |  |  |   45|  21.1k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1233|       |
 1234|       |    /* Special case for A = -3 */
 1235|  21.1k|    if (mbedtls_ecp_group_a_is_minus_3(grp)) {
  ------------------
  |  Branch (1235:9): [True: 21.1k, False: 0]
  ------------------
 1236|  21.1k|        MPI_ECP_SUB_INT(rhs, rhs, 3);
  ------------------
  |  | 1140|  21.1k|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int_mod(grp, X, A, c))
  |  |  ------------------
  |  |  |  |   41|  21.1k|    do                           \
  |  |  |  |   42|  21.1k|    {                            \
  |  |  |  |   43|  21.1k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 21.1k]
  |  |  |  |  ------------------
  |  |  |  |   44|  21.1k|        goto cleanup;        \
  |  |  |  |   45|  21.1k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1237|  21.1k|    } 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|  21.1k|    MPI_ECP_MUL(rhs, rhs, X);
  ------------------
  |  | 1167|  21.1k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  21.1k|    do                           \
  |  |  |  |   42|  21.1k|    {                            \
  |  |  |  |   43|  21.1k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 21.1k]
  |  |  |  |  ------------------
  |  |  |  |   44|  21.1k|        goto cleanup;        \
  |  |  |  |   45|  21.1k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1242|  21.1k|    MPI_ECP_ADD(rhs, rhs, &grp->B);
  ------------------
  |  | 1161|  21.1k|    MBEDTLS_MPI_CHK(mbedtls_mpi_add_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  21.1k|    do                           \
  |  |  |  |   42|  21.1k|    {                            \
  |  |  |  |   43|  21.1k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 21.1k]
  |  |  |  |  ------------------
  |  |  |  |   44|  21.1k|        goto cleanup;        \
  |  |  |  |   45|  21.1k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1243|       |
 1244|  21.1k|cleanup:
 1245|  21.1k|    return ret;
 1246|  21.1k|}
ecp.c:mbedtls_mpi_mul_mod:
 1059|  8.31M|{
 1060|  8.31M|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  8.31M|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1061|  8.31M|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(X, A, B));
  ------------------
  |  |   41|  8.31M|    do                           \
  |  |   42|  8.31M|    {                            \
  |  |   43|  8.31M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 8.31M]
  |  |  ------------------
  |  |   44|  8.31M|        goto cleanup;        \
  |  |   45|  8.31M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1062|  8.31M|    MOD_MUL(*X);
  ------------------
  |  | 1049|  8.31M|    do                                                                  \
  |  | 1050|  8.31M|    {                                                                   \
  |  | 1051|  8.31M|        MBEDTLS_MPI_CHK(ecp_modp(&(N), grp));                       \
  |  |  ------------------
  |  |  |  |   41|  8.31M|    do                           \
  |  |  |  |   42|  8.31M|    {                            \
  |  |  |  |   43|  8.31M|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 8.31M]
  |  |  |  |  ------------------
  |  |  |  |   44|  8.31M|        goto cleanup;        \
  |  |  |  |   45|  8.31M|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 1052|  8.31M|        INC_MUL_COUNT                                                   \
  |  |  ------------------
  |  |  |  | 1043|  8.31M|#define INC_MUL_COUNT   mul_count++;
  |  |  ------------------
  |  | 1053|  8.31M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (1053:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1063|  8.31M|cleanup:
 1064|  8.31M|    return ret;
 1065|  8.31M|}
ecp.c:ecp_modp:
 1000|  8.31M|{
 1001|  8.31M|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  8.31M|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1002|       |
 1003|  8.31M|    if (grp->modp == NULL) {
  ------------------
  |  Branch (1003:9): [True: 0, False: 8.31M]
  ------------------
 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|  8.31M|    if ((N->s < 0 && mbedtls_mpi_cmp_int(N, 0) != 0) ||
  ------------------
  |  Branch (1008:10): [True: 0, False: 8.31M]
  |  Branch (1008:22): [True: 0, False: 0]
  ------------------
 1009|  8.31M|        mbedtls_mpi_bitlen(N) > 2 * grp->pbits) {
  ------------------
  |  Branch (1009:9): [True: 0, False: 8.31M]
  ------------------
 1010|      0|        return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
 1011|      0|    }
 1012|       |
 1013|  8.31M|    MBEDTLS_MPI_CHK(grp->modp(N));
  ------------------
  |  |   41|  8.31M|    do                           \
  |  |   42|  8.31M|    {                            \
  |  |   43|  8.31M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 8.31M]
  |  |  ------------------
  |  |   44|  8.31M|        goto cleanup;        \
  |  |   45|  8.31M|    } 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|  15.0M|    while (N->s < 0 && mbedtls_mpi_cmp_int(N, 0) != 0) {
  ------------------
  |  Branch (1016:12): [True: 6.69M, False: 8.31M]
  |  Branch (1016:24): [True: 6.69M, False: 0]
  ------------------
 1017|  6.69M|        MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(N, N, &grp->P));
  ------------------
  |  |   41|  6.69M|    do                           \
  |  |   42|  6.69M|    {                            \
  |  |   43|  6.69M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 6.69M]
  |  |  ------------------
  |  |   44|  6.69M|        goto cleanup;        \
  |  |   45|  6.69M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1018|  6.69M|    }
 1019|       |
 1020|  9.82M|    while (mbedtls_mpi_cmp_mpi(N, &grp->P) >= 0) {
  ------------------
  |  Branch (1020:12): [True: 1.51M, False: 8.31M]
  ------------------
 1021|       |        /* we known P, N and the result are positive */
 1022|  1.51M|        MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs(N, N, &grp->P));
  ------------------
  |  |   41|  1.51M|    do                           \
  |  |   42|  1.51M|    {                            \
  |  |   43|  1.51M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.51M]
  |  |  ------------------
  |  |   44|  1.51M|        goto cleanup;        \
  |  |   45|  1.51M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1023|  1.51M|    }
 1024|       |
 1025|  8.31M|cleanup:
 1026|  8.31M|    return ret;
 1027|  8.31M|}
ecp.c:mbedtls_mpi_sub_int_mod:
 1130|  21.1k|{
 1131|  21.1k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  21.1k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1132|       |
 1133|  21.1k|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(X, A, c));
  ------------------
  |  |   41|  21.1k|    do                           \
  |  |   42|  21.1k|    {                            \
  |  |   43|  21.1k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 21.1k]
  |  |  ------------------
  |  |   44|  21.1k|        goto cleanup;        \
  |  |   45|  21.1k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1134|  21.1k|    MOD_SUB(X);
  ------------------
  |  | 1072|  21.1k|    do {                                                                      \
  |  | 1073|  21.1k|        while ((N)->s < 0 && mbedtls_mpi_cmp_int((N), 0) != 0)             \
  |  |  ------------------
  |  |  |  Branch (1073:16): [True: 0, False: 21.1k]
  |  |  |  Branch (1073:30): [True: 0, False: 0]
  |  |  ------------------
  |  | 1074|  21.1k|        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|  21.1k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (1075:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1135|  21.1k|cleanup:
 1136|  21.1k|    return ret;
 1137|  21.1k|}
ecp.c:mbedtls_mpi_add_mod:
 1103|   671k|{
 1104|   671k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|   671k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1105|   671k|    MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(X, A, B));
  ------------------
  |  |   41|   671k|    do                           \
  |  |   42|   671k|    {                            \
  |  |   43|   671k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 671k]
  |  |  ------------------
  |  |   44|   671k|        goto cleanup;        \
  |  |   45|   671k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1106|   671k|    MOD_ADD(X);
  ------------------
  |  | 1096|   991k|    while (mbedtls_mpi_cmp_mpi((N), &grp->P) >= 0)                  \
  |  |  ------------------
  |  |  |  Branch (1096:12): [True: 320k, False: 671k]
  |  |  ------------------
  |  | 1097|   671k|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs((N), (N), &grp->P))
  |  |  ------------------
  |  |  |  |   41|   991k|    do                           \
  |  |  |  |   42|   991k|    {                            \
  |  |  |  |   43|   320k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 320k]
  |  |  |  |  ------------------
  |  |  |  |   44|   320k|        goto cleanup;        \
  |  |  |  |   45|   320k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1107|   671k|cleanup:
 1108|   671k|    return ret;
 1109|   671k|}
ecp.c:ecp_mul_restartable_internal:
 2630|  4.22k|{
 2631|  4.22k|    int ret = MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|  4.22k|#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|  4.22k|#if defined(MBEDTLS_ECP_RESTARTABLE)
 2637|       |    /* reset ops count for this call if top-level */
 2638|  4.22k|    if (rs_ctx != NULL && rs_ctx->depth++ == 0) {
  ------------------
  |  Branch (2638:9): [True: 0, False: 4.22k]
  |  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|  4.22k|    int restarting = 0;
 2652|  4.22k|#if defined(MBEDTLS_ECP_RESTARTABLE)
 2653|  4.22k|    restarting = (rs_ctx != NULL && rs_ctx->rsm != NULL);
  ------------------
  |  Branch (2653:19): [True: 0, False: 4.22k]
  |  Branch (2653:37): [True: 0, False: 0]
  ------------------
 2654|  4.22k|#endif
 2655|       |    /* skip argument check when restarting */
 2656|  4.22k|    if (!restarting) {
  ------------------
  |  Branch (2656:9): [True: 4.22k, False: 0]
  ------------------
 2657|       |        /* check_privkey is free */
 2658|  4.22k|        MBEDTLS_ECP_BUDGET(MBEDTLS_ECP_OPS_CHK);
  ------------------
  |  |  408|  4.22k|    MBEDTLS_MPI_CHK(mbedtls_ecp_check_budget(grp, rs_ctx, \
  |  |  ------------------
  |  |  |  |   41|  4.22k|    do                           \
  |  |  |  |   42|  4.22k|    {                            \
  |  |  |  |   43|  4.22k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 4.22k]
  |  |  |  |  ------------------
  |  |  |  |   44|  4.22k|        goto cleanup;        \
  |  |  |  |   45|  4.22k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  409|  4.22k|                                             (unsigned) (ops)));
  ------------------
 2659|       |
 2660|       |        /* Common sanity checks */
 2661|  4.22k|        MBEDTLS_MPI_CHK(mbedtls_ecp_check_privkey(grp, m));
  ------------------
  |  |   41|  4.22k|    do                           \
  |  |   42|  4.22k|    {                            \
  |  |   43|  4.22k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.22k]
  |  |  ------------------
  |  |   44|  4.22k|        goto cleanup;        \
  |  |   45|  4.22k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2662|  4.22k|        MBEDTLS_MPI_CHK(mbedtls_ecp_check_pubkey(grp, P));
  ------------------
  |  |   41|  4.22k|    do                           \
  |  |   42|  4.22k|    {                            \
  |  |   43|  4.22k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.22k]
  |  |  ------------------
  |  |   44|  4.22k|        goto cleanup;        \
  |  |   45|  4.22k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2663|  4.22k|    }
 2664|       |
 2665|  4.22k|    ret = MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|  4.22k|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
 2666|  4.22k|#if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED)
 2667|  4.22k|    if (mbedtls_ecp_get_type(grp) == MBEDTLS_ECP_TYPE_MONTGOMERY) {
  ------------------
  |  Branch (2667:9): [True: 0, False: 4.22k]
  ------------------
 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|  4.22k|#endif
 2671|  4.22k|#if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
 2672|  4.22k|    if (mbedtls_ecp_get_type(grp) == MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS) {
  ------------------
  |  Branch (2672:9): [True: 4.22k, False: 0]
  ------------------
 2673|  4.22k|        MBEDTLS_MPI_CHK(ecp_mul_comb(grp, R, m, P, f_rng, p_rng, rs_ctx));
  ------------------
  |  |   41|  4.22k|    do                           \
  |  |   42|  4.22k|    {                            \
  |  |   43|  4.22k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.22k]
  |  |  ------------------
  |  |   44|  4.22k|        goto cleanup;        \
  |  |   45|  4.22k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2674|  4.22k|    }
 2675|  4.22k|#endif
 2676|       |
 2677|  4.22k|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|  4.22k|#if defined(MBEDTLS_ECP_RESTARTABLE)
 2686|  4.22k|    if (rs_ctx != NULL) {
  ------------------
  |  Branch (2686:9): [True: 0, False: 4.22k]
  ------------------
 2687|      0|        rs_ctx->depth--;
 2688|      0|    }
 2689|  4.22k|#endif
 2690|       |
 2691|  4.22k|    return ret;
 2692|  4.22k|}
ecp.c:mbedtls_mpi_sub_mod:
 1082|  4.82M|{
 1083|  4.82M|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  4.82M|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1084|  4.82M|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(X, A, B));
  ------------------
  |  |   41|  4.82M|    do                           \
  |  |   42|  4.82M|    {                            \
  |  |   43|  4.82M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.82M]
  |  |  ------------------
  |  |   44|  4.82M|        goto cleanup;        \
  |  |   45|  4.82M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1085|  4.82M|    MOD_SUB(X);
  ------------------
  |  | 1072|  4.82M|    do {                                                                      \
  |  | 1073|  7.25M|        while ((N)->s < 0 && mbedtls_mpi_cmp_int((N), 0) != 0)             \
  |  |  ------------------
  |  |  |  Branch (1073:16): [True: 2.42M, False: 4.82M]
  |  |  |  Branch (1073:30): [True: 2.42M, False: 0]
  |  |  ------------------
  |  | 1074|  4.82M|        MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi((N), (N), &grp->P));      \
  |  |  ------------------
  |  |  |  |   41|  2.42M|    do                           \
  |  |  |  |   42|  2.42M|    {                            \
  |  |  |  |   43|  2.42M|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 2.42M]
  |  |  |  |  ------------------
  |  |  |  |   44|  2.42M|        goto cleanup;        \
  |  |  |  |   45|  2.42M|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 1075|  4.82M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (1075:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1086|  4.82M|cleanup:
 1087|  4.82M|    return ret;
 1088|  4.82M|}
ecp.c:ecp_mul_comb:
 2294|  4.22k|{
 2295|  4.22k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  4.22k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 2296|  4.22k|    unsigned char w, p_eq_g, i;
 2297|  4.22k|    size_t d;
 2298|  4.22k|    unsigned char T_size = 0, T_ok = 0;
 2299|  4.22k|    mbedtls_ecp_point *T = NULL;
 2300|       |
 2301|  4.22k|    ECP_RS_ENTER(rsm);
  ------------------
  |  |  277|  4.22k|#define ECP_RS_ENTER(SUB)   do {                                      \
  |  |  278|  4.22k|        /* reset ops count for this call if top-level */                    \
  |  |  279|  4.22k|        if (rs_ctx != NULL && rs_ctx->depth++ == 0)                        \
  |  |  ------------------
  |  |  |  Branch (279:13): [True: 0, False: 4.22k]
  |  |  |  Branch (279:31): [True: 0, False: 0]
  |  |  ------------------
  |  |  280|  4.22k|        rs_ctx->ops_done = 0;                                           \
  |  |  281|  4.22k|                                                                        \
  |  |  282|  4.22k|        /* set up our own sub-context if needed */                          \
  |  |  283|  4.22k|        if (mbedtls_ecp_restart_is_enabled() &&                             \
  |  |  ------------------
  |  |  |  Branch (283:13): [True: 0, False: 4.22k]
  |  |  ------------------
  |  |  284|  4.22k|            rs_ctx != NULL && rs_ctx->SUB == NULL)                         \
  |  |  ------------------
  |  |  |  Branch (284:13): [True: 0, False: 0]
  |  |  |  Branch (284:31): [True: 0, False: 0]
  |  |  ------------------
  |  |  285|  4.22k|        {                                                                   \
  |  |  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|  4.22k|} while (0)
  |  |  ------------------
  |  |  |  Branch (292:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2302|       |
 2303|       |    /* Is P the base point ? */
 2304|  4.22k|#if MBEDTLS_ECP_FIXED_POINT_OPTIM == 1
 2305|  4.22k|    p_eq_g = (MPI_ECP_CMP(&P->Y, &grp->G.Y) == 0 &&
  ------------------
  |  | 1191|  4.22k|    mbedtls_mpi_cmp_mpi(X, Y)
  ------------------
  |  Branch (2305:15): [True: 2.11k, False: 2.11k]
  ------------------
 2306|  4.22k|              MPI_ECP_CMP(&P->X, &grp->G.X) == 0);
  ------------------
  |  | 1191|  2.11k|    mbedtls_mpi_cmp_mpi(X, Y)
  ------------------
  |  Branch (2306:15): [True: 2.11k, False: 0]
  ------------------
 2307|       |#else
 2308|       |    p_eq_g = 0;
 2309|       |#endif
 2310|       |
 2311|       |    /* Pick window size and deduce related sizes */
 2312|  4.22k|    w = ecp_pick_window_size(grp, p_eq_g);
 2313|  4.22k|    T_size = 1U << (w - 1);
 2314|  4.22k|    d = (grp->nbits + w - 1) / w;
 2315|       |
 2316|       |    /* Pre-computed table: do we have it already for the base point? */
 2317|  4.22k|    if (p_eq_g && grp->T != NULL) {
  ------------------
  |  Branch (2317:9): [True: 2.11k, False: 2.11k]
  |  Branch (2317:19): [True: 2.11k, False: 0]
  ------------------
 2318|       |        /* second pointer to the same table, will be deleted on exit */
 2319|  2.11k|        T = grp->T;
 2320|  2.11k|        T_ok = 1;
 2321|  2.11k|    } else
 2322|  2.11k|#if defined(MBEDTLS_ECP_RESTARTABLE)
 2323|       |    /* Pre-computed table: do we have one in progress? complete? */
 2324|  2.11k|    if (rs_ctx != NULL && rs_ctx->rsm != NULL && rs_ctx->rsm->T != NULL) {
  ------------------
  |  Branch (2324:9): [True: 0, False: 2.11k]
  |  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|  2.11k|#endif
 2334|       |    /* Allocate table if we didn't have any */
 2335|  2.11k|    {
 2336|  2.11k|        T = mbedtls_calloc(T_size, sizeof(mbedtls_ecp_point));
  ------------------
  |  |  144|  2.11k|#define mbedtls_calloc     MBEDTLS_PLATFORM_CALLOC_MACRO
  |  |  ------------------
  |  |  |  | 4093|  2.11k|#define MBEDTLS_PLATFORM_CALLOC_MACRO        my_calloc
  |  |  ------------------
  ------------------
 2337|  2.11k|        if (T == NULL) {
  ------------------
  |  Branch (2337:13): [True: 0, False: 2.11k]
  ------------------
 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|  19.0k|        for (i = 0; i < T_size; i++) {
  ------------------
  |  Branch (2342:21): [True: 16.8k, False: 2.11k]
  ------------------
 2343|  16.8k|            mbedtls_ecp_point_init(&T[i]);
 2344|  16.8k|        }
 2345|       |
 2346|  2.11k|        T_ok = 0;
 2347|  2.11k|    }
 2348|       |
 2349|       |    /* Compute table (or finish computing it) if not done already */
 2350|  4.22k|    if (!T_ok) {
  ------------------
  |  Branch (2350:9): [True: 2.11k, False: 2.11k]
  ------------------
 2351|  2.11k|        MBEDTLS_MPI_CHK(ecp_precompute_comb(grp, T, P, w, d, rs_ctx));
  ------------------
  |  |   41|  2.11k|    do                           \
  |  |   42|  2.11k|    {                            \
  |  |   43|  2.11k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.11k]
  |  |  ------------------
  |  |   44|  2.11k|        goto cleanup;        \
  |  |   45|  2.11k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2352|       |
 2353|  2.11k|        if (p_eq_g) {
  ------------------
  |  Branch (2353:13): [True: 0, False: 2.11k]
  ------------------
 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|  2.11k|    }
 2360|       |
 2361|       |    /* Actual comb multiplication using precomputed points */
 2362|  4.22k|    MBEDTLS_MPI_CHK(ecp_mul_comb_after_precomp(grp, R, m,
  ------------------
  |  |   41|  4.22k|    do                           \
  |  |   42|  4.22k|    {                            \
  |  |   43|  4.22k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.22k]
  |  |  ------------------
  |  |   44|  4.22k|        goto cleanup;        \
  |  |   45|  4.22k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2363|  4.22k|                                               T, T_size, w, d,
 2364|  4.22k|                                               f_rng, p_rng, rs_ctx));
 2365|       |
 2366|  4.22k|cleanup:
 2367|       |
 2368|       |    /* does T belong to the group? */
 2369|  4.22k|    if (T == grp->T) {
  ------------------
  |  Branch (2369:9): [True: 2.11k, False: 2.11k]
  ------------------
 2370|  2.11k|        T = NULL;
 2371|  2.11k|    }
 2372|       |
 2373|       |    /* does T belong to the restart context? */
 2374|  4.22k|#if defined(MBEDTLS_ECP_RESTARTABLE)
 2375|  4.22k|    if (rs_ctx != NULL && rs_ctx->rsm != NULL && ret == MBEDTLS_ERR_ECP_IN_PROGRESS && T != NULL) {
  ------------------
  |  |   51|  4.22k|#define MBEDTLS_ERR_ECP_IN_PROGRESS                       -0x4B00
  ------------------
  |  Branch (2375:9): [True: 0, False: 4.22k]
  |  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|  4.22k|#endif
 2382|       |
 2383|       |    /* did T belong to us? then let's destroy it! */
 2384|  4.22k|    if (T != NULL) {
  ------------------
  |  Branch (2384:9): [True: 2.11k, False: 2.11k]
  ------------------
 2385|  19.0k|        for (i = 0; i < T_size; i++) {
  ------------------
  |  Branch (2385:21): [True: 16.8k, False: 2.11k]
  ------------------
 2386|  16.8k|            mbedtls_ecp_point_free(&T[i]);
 2387|  16.8k|        }
 2388|  2.11k|        mbedtls_free(T);
  ------------------
  |  |  143|  2.11k|#define mbedtls_free       MBEDTLS_PLATFORM_FREE_MACRO
  |  |  ------------------
  |  |  |  | 4095|  2.11k|#define MBEDTLS_PLATFORM_FREE_MACRO            my_free
  |  |  ------------------
  ------------------
 2389|  2.11k|    }
 2390|       |
 2391|       |    /* prevent caller from using invalid value */
 2392|  4.22k|    int should_free_R = (ret != 0);
 2393|  4.22k|#if defined(MBEDTLS_ECP_RESTARTABLE)
 2394|       |    /* don't free R while in progress in case R == P */
 2395|  4.22k|    if (ret == MBEDTLS_ERR_ECP_IN_PROGRESS) {
  ------------------
  |  |   51|  4.22k|#define MBEDTLS_ERR_ECP_IN_PROGRESS                       -0x4B00
  ------------------
  |  Branch (2395:9): [True: 0, False: 4.22k]
  ------------------
 2396|      0|        should_free_R = 0;
 2397|      0|    }
 2398|  4.22k|#endif
 2399|  4.22k|    if (should_free_R) {
  ------------------
  |  Branch (2399:9): [True: 0, False: 4.22k]
  ------------------
 2400|      0|        mbedtls_ecp_point_free(R);
 2401|      0|    }
 2402|       |
 2403|  4.22k|    ECP_RS_LEAVE(rsm);
  ------------------
  |  |  295|  4.22k|#define ECP_RS_LEAVE(SUB)   do {                                      \
  |  |  296|  4.22k|        /* clear our sub-context when not in progress (done or error) */    \
  |  |  297|  4.22k|        if (rs_ctx != NULL && rs_ctx->SUB != NULL &&                        \
  |  |  ------------------
  |  |  |  Branch (297:13): [True: 0, False: 4.22k]
  |  |  |  Branch (297:31): [True: 0, False: 0]
  |  |  ------------------
  |  |  298|  4.22k|            ret != MBEDTLS_ERR_ECP_IN_PROGRESS)                            \
  |  |  ------------------
  |  |  |  |   51|      0|#define MBEDTLS_ERR_ECP_IN_PROGRESS                       -0x4B00
  |  |  ------------------
  |  |  |  Branch (298:13): [True: 0, False: 0]
  |  |  ------------------
  |  |  299|  4.22k|        {                                                                   \
  |  |  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|  4.22k|                                                                        \
  |  |  305|  4.22k|        if (rs_ctx != NULL)                                                \
  |  |  ------------------
  |  |  |  Branch (305:13): [True: 0, False: 4.22k]
  |  |  ------------------
  |  |  306|  4.22k|        rs_ctx->depth--;                                                \
  |  |  307|  4.22k|} while (0)
  |  |  ------------------
  |  |  |  Branch (307:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2404|       |
 2405|  4.22k|    return ret;
 2406|  4.22k|}
ecp.c:ecp_pick_window_size:
 2236|  4.22k|{
 2237|  4.22k|    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|  4.22k|    w = grp->nbits >= 384 ? 5 : 4;
  ------------------
  |  Branch (2244:9): [True: 0, False: 4.22k]
  ------------------
 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|  4.22k|    if (p_eq_g) {
  ------------------
  |  Branch (2251:9): [True: 2.11k, False: 2.11k]
  ------------------
 2252|  2.11k|        w++;
 2253|  2.11k|    }
 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|  4.22k|#if (MBEDTLS_ECP_WINDOW_SIZE < 6)
 2265|  4.22k|    if ((!p_eq_g || !ecp_group_is_static_comb_table(grp)) && w > MBEDTLS_ECP_WINDOW_SIZE) {
  ------------------
  |  |  291|  2.11k|#define MBEDTLS_ECP_WINDOW_SIZE    4   /**< The maximum window size used. */
  ------------------
  |  Branch (2265:10): [True: 2.11k, False: 2.11k]
  |  Branch (2265:21): [True: 0, False: 2.11k]
  |  Branch (2265:62): [True: 0, False: 2.11k]
  ------------------
 2266|      0|        w = MBEDTLS_ECP_WINDOW_SIZE;
  ------------------
  |  |  291|      0|#define MBEDTLS_ECP_WINDOW_SIZE    4   /**< The maximum window size used. */
  ------------------
 2267|      0|    }
 2268|  4.22k|#endif
 2269|  4.22k|    if (w >= grp->nbits) {
  ------------------
  |  Branch (2269:9): [True: 0, False: 4.22k]
  ------------------
 2270|      0|        w = 2;
 2271|      0|    }
 2272|       |
 2273|  4.22k|    return w;
 2274|  4.22k|}
ecp.c:ecp_precompute_comb:
 1853|  2.11k|{
 1854|  2.11k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  2.11k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1855|  2.11k|    unsigned char i;
 1856|  2.11k|    size_t j = 0;
 1857|  2.11k|    const unsigned char T_size = 1U << (w - 1);
 1858|  2.11k|    mbedtls_ecp_point *cur, *TT[COMB_MAX_PRE - 1] = { NULL };
 1859|       |
 1860|  2.11k|    mbedtls_mpi tmp[4];
 1861|       |
 1862|  2.11k|    mpi_init_many(tmp, sizeof(tmp) / sizeof(mbedtls_mpi));
 1863|       |
 1864|  2.11k|#if defined(MBEDTLS_ECP_RESTARTABLE)
 1865|  2.11k|    if (rs_ctx != NULL && rs_ctx->rsm != NULL) {
  ------------------
  |  Branch (1865:9): [True: 0, False: 2.11k]
  |  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|  2.11k|#if defined(MBEDTLS_ECP_RESTARTABLE)
 1884|  2.11k|    if (rs_ctx != NULL && rs_ctx->rsm != NULL) {
  ------------------
  |  Branch (1884:9): [True: 0, False: 2.11k]
  |  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|  2.11k|dbl:
 1892|  2.11k|#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|  2.11k|    MBEDTLS_MPI_CHK(mbedtls_ecp_copy(&T[0], P));
  ------------------
  |  |   41|  2.11k|    do                           \
  |  |   42|  2.11k|    {                            \
  |  |   43|  2.11k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.11k]
  |  |  ------------------
  |  |   44|  2.11k|        goto cleanup;        \
  |  |   45|  2.11k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1898|       |
 1899|  2.11k|#if defined(MBEDTLS_ECP_RESTARTABLE)
 1900|  2.11k|    if (rs_ctx != NULL && rs_ctx->rsm != NULL && rs_ctx->rsm->i != 0) {
  ------------------
  |  Branch (1900:9): [True: 0, False: 2.11k]
  |  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|  2.11k|#endif
 1904|  2.11k|    j = 0;
 1905|       |
 1906|   407k|    for (; j < d * (w - 1); j++) {
  ------------------
  |  Branch (1906:12): [True: 405k, False: 2.11k]
  ------------------
 1907|   405k|        MBEDTLS_ECP_BUDGET(MBEDTLS_ECP_OPS_DBL);
  ------------------
  |  |  408|   405k|    MBEDTLS_MPI_CHK(mbedtls_ecp_check_budget(grp, rs_ctx, \
  |  |  ------------------
  |  |  |  |   41|   405k|    do                           \
  |  |  |  |   42|   405k|    {                            \
  |  |  |  |   43|   405k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 405k]
  |  |  |  |  ------------------
  |  |  |  |   44|   405k|        goto cleanup;        \
  |  |  |  |   45|   405k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  409|   405k|                                             (unsigned) (ops)));
  ------------------
 1908|       |
 1909|   405k|        i = 1U << (j / d);
 1910|   405k|        cur = T + i;
 1911|       |
 1912|   405k|        if (j % d == 0) {
  ------------------
  |  Branch (1912:13): [True: 6.33k, False: 399k]
  ------------------
 1913|  6.33k|            MBEDTLS_MPI_CHK(mbedtls_ecp_copy(cur, T + (i >> 1)));
  ------------------
  |  |   41|  6.33k|    do                           \
  |  |   42|  6.33k|    {                            \
  |  |   43|  6.33k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 6.33k]
  |  |  ------------------
  |  |   44|  6.33k|        goto cleanup;        \
  |  |   45|  6.33k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1914|  6.33k|        }
 1915|       |
 1916|   405k|        MBEDTLS_MPI_CHK(ecp_double_jac(grp, cur, cur, tmp));
  ------------------
  |  |   41|   405k|    do                           \
  |  |   42|   405k|    {                            \
  |  |   43|   405k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 405k]
  |  |  ------------------
  |  |   44|   405k|        goto cleanup;        \
  |  |   45|   405k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1917|   405k|    }
 1918|       |
 1919|  2.11k|#if defined(MBEDTLS_ECP_RESTARTABLE)
 1920|  2.11k|    if (rs_ctx != NULL && rs_ctx->rsm != NULL) {
  ------------------
  |  Branch (1920:9): [True: 0, False: 2.11k]
  |  Branch (1920:27): [True: 0, False: 0]
  ------------------
 1921|      0|        rs_ctx->rsm->state = ecp_rsm_pre_norm_dbl;
 1922|      0|    }
 1923|       |
 1924|  2.11k|norm_dbl:
 1925|  2.11k|#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|  2.11k|    j = 0;
 1934|  8.44k|    for (i = 1; i < T_size; i <<= 1) {
  ------------------
  |  Branch (1934:17): [True: 6.33k, False: 2.11k]
  ------------------
 1935|  6.33k|        TT[j++] = T + i;
 1936|  6.33k|    }
 1937|       |
 1938|  2.11k|    MBEDTLS_ECP_BUDGET(MBEDTLS_ECP_OPS_INV + 6 * j - 2);
  ------------------
  |  |  408|  2.11k|    MBEDTLS_MPI_CHK(mbedtls_ecp_check_budget(grp, rs_ctx, \
  |  |  ------------------
  |  |  |  |   41|  2.11k|    do                           \
  |  |  |  |   42|  2.11k|    {                            \
  |  |  |  |   43|  2.11k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 2.11k]
  |  |  |  |  ------------------
  |  |  |  |   44|  2.11k|        goto cleanup;        \
  |  |  |  |   45|  2.11k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  409|  2.11k|                                             (unsigned) (ops)));
  ------------------
 1939|       |
 1940|  2.11k|    MBEDTLS_MPI_CHK(ecp_normalize_jac_many(grp, TT, j));
  ------------------
  |  |   41|  2.11k|    do                           \
  |  |   42|  2.11k|    {                            \
  |  |   43|  2.11k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.11k]
  |  |  ------------------
  |  |   44|  2.11k|        goto cleanup;        \
  |  |   45|  2.11k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1941|       |
 1942|  2.11k|#if defined(MBEDTLS_ECP_RESTARTABLE)
 1943|  2.11k|    if (rs_ctx != NULL && rs_ctx->rsm != NULL) {
  ------------------
  |  Branch (1943:9): [True: 0, False: 2.11k]
  |  Branch (1943:27): [True: 0, False: 0]
  ------------------
 1944|      0|        rs_ctx->rsm->state = ecp_rsm_pre_add;
 1945|      0|    }
 1946|       |
 1947|  2.11k|add:
 1948|  2.11k|#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|  2.11k|    MBEDTLS_ECP_BUDGET((T_size - 1) * MBEDTLS_ECP_OPS_ADD);
  ------------------
  |  |  408|  2.11k|    MBEDTLS_MPI_CHK(mbedtls_ecp_check_budget(grp, rs_ctx, \
  |  |  ------------------
  |  |  |  |   41|  2.11k|    do                           \
  |  |  |  |   42|  2.11k|    {                            \
  |  |  |  |   43|  2.11k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 2.11k]
  |  |  |  |  ------------------
  |  |  |  |   44|  2.11k|        goto cleanup;        \
  |  |  |  |   45|  2.11k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  409|  2.11k|                                             (unsigned) (ops)));
  ------------------
 1954|       |
 1955|  8.44k|    for (i = 1; i < T_size; i <<= 1) {
  ------------------
  |  Branch (1955:17): [True: 6.33k, False: 2.11k]
  ------------------
 1956|  6.33k|        j = i;
 1957|  21.1k|        while (j--) {
  ------------------
  |  Branch (1957:16): [True: 14.7k, False: 6.33k]
  ------------------
 1958|  14.7k|            MBEDTLS_MPI_CHK(ecp_add_mixed(grp, &T[i + j], &T[j], &T[i], tmp));
  ------------------
  |  |   41|  14.7k|    do                           \
  |  |   42|  14.7k|    {                            \
  |  |   43|  14.7k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 14.7k]
  |  |  ------------------
  |  |   44|  14.7k|        goto cleanup;        \
  |  |   45|  14.7k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1959|  14.7k|        }
 1960|  6.33k|    }
 1961|       |
 1962|  2.11k|#if defined(MBEDTLS_ECP_RESTARTABLE)
 1963|  2.11k|    if (rs_ctx != NULL && rs_ctx->rsm != NULL) {
  ------------------
  |  Branch (1963:9): [True: 0, False: 2.11k]
  |  Branch (1963:27): [True: 0, False: 0]
  ------------------
 1964|      0|        rs_ctx->rsm->state = ecp_rsm_pre_norm_add;
 1965|      0|    }
 1966|       |
 1967|  2.11k|norm_add:
 1968|  2.11k|#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|  16.8k|    for (j = 0; j + 1 < T_size; j++) {
  ------------------
  |  Branch (1974:17): [True: 14.7k, False: 2.11k]
  ------------------
 1975|  14.7k|        TT[j] = T + j + 1;
 1976|  14.7k|    }
 1977|       |
 1978|  2.11k|    MBEDTLS_ECP_BUDGET(MBEDTLS_ECP_OPS_INV + 6 * j - 2);
  ------------------
  |  |  408|  2.11k|    MBEDTLS_MPI_CHK(mbedtls_ecp_check_budget(grp, rs_ctx, \
  |  |  ------------------
  |  |  |  |   41|  2.11k|    do                           \
  |  |  |  |   42|  2.11k|    {                            \
  |  |  |  |   43|  2.11k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 2.11k]
  |  |  |  |  ------------------
  |  |  |  |   44|  2.11k|        goto cleanup;        \
  |  |  |  |   45|  2.11k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  409|  2.11k|                                             (unsigned) (ops)));
  ------------------
 1979|       |
 1980|  2.11k|    MBEDTLS_MPI_CHK(ecp_normalize_jac_many(grp, TT, j));
  ------------------
  |  |   41|  2.11k|    do                           \
  |  |   42|  2.11k|    {                            \
  |  |   43|  2.11k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.11k]
  |  |  ------------------
  |  |   44|  2.11k|        goto cleanup;        \
  |  |   45|  2.11k|    } 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|  19.0k|    for (i = 0; i < T_size; i++) {
  ------------------
  |  Branch (1987:17): [True: 16.8k, False: 2.11k]
  ------------------
 1988|  16.8k|        mbedtls_mpi_free(&T[i].Z);
 1989|  16.8k|    }
 1990|       |
 1991|  2.11k|cleanup:
 1992|       |
 1993|  2.11k|    mpi_free_many(tmp, sizeof(tmp) / sizeof(mbedtls_mpi));
 1994|       |
 1995|  2.11k|#if defined(MBEDTLS_ECP_RESTARTABLE)
 1996|  2.11k|    if (rs_ctx != NULL && rs_ctx->rsm != NULL &&
  ------------------
  |  Branch (1996:9): [True: 0, False: 2.11k]
  |  Branch (1996:27): [True: 0, False: 0]
  ------------------
 1997|  2.11k|        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|  2.11k|#endif
 2003|       |
 2004|  2.11k|    return ret;
 2005|  2.11k|}
ecp.c:ecp_double_jac:
 1489|   650k|{
 1490|   650k|#if defined(MBEDTLS_SELF_TEST)
 1491|   650k|    dbl_count++;
 1492|   650k|#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|   650k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|   650k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1504|       |
 1505|       |    /* Special case for A = -3 */
 1506|   650k|    if (mbedtls_ecp_group_a_is_minus_3(grp)) {
  ------------------
  |  Branch (1506:9): [True: 650k, False: 0]
  ------------------
 1507|       |        /* tmp[0] <- M = 3(X + Z^2)(X - Z^2) */
 1508|   650k|        MPI_ECP_SQR(&tmp[1],  &P->Z);
  ------------------
  |  | 1170|   650k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, A))
  |  |  ------------------
  |  |  |  |   41|   650k|    do                           \
  |  |  |  |   42|   650k|    {                            \
  |  |  |  |   43|   650k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 650k]
  |  |  |  |  ------------------
  |  |  |  |   44|   650k|        goto cleanup;        \
  |  |  |  |   45|   650k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1509|   650k|        MPI_ECP_ADD(&tmp[2],  &P->X,  &tmp[1]);
  ------------------
  |  | 1161|   650k|    MBEDTLS_MPI_CHK(mbedtls_mpi_add_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|   650k|    do                           \
  |  |  |  |   42|   650k|    {                            \
  |  |  |  |   43|   650k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 650k]
  |  |  |  |  ------------------
  |  |  |  |   44|   650k|        goto cleanup;        \
  |  |  |  |   45|   650k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1510|   650k|        MPI_ECP_SUB(&tmp[3],  &P->X,  &tmp[1]);
  ------------------
  |  | 1164|   650k|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|   650k|    do                           \
  |  |  |  |   42|   650k|    {                            \
  |  |  |  |   43|   650k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 650k]
  |  |  |  |  ------------------
  |  |  |  |   44|   650k|        goto cleanup;        \
  |  |  |  |   45|   650k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1511|   650k|        MPI_ECP_MUL(&tmp[1],  &tmp[2],     &tmp[3]);
  ------------------
  |  | 1167|   650k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|   650k|    do                           \
  |  |  |  |   42|   650k|    {                            \
  |  |  |  |   43|   650k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 650k]
  |  |  |  |  ------------------
  |  |  |  |   44|   650k|        goto cleanup;        \
  |  |  |  |   45|   650k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1512|   650k|        MPI_ECP_MUL_INT(&tmp[0],  &tmp[1],     3);
  ------------------
  |  | 1173|   650k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_int_mod(grp, X, A, c))
  |  |  ------------------
  |  |  |  |   41|   650k|    do                           \
  |  |  |  |   42|   650k|    {                            \
  |  |  |  |   43|   650k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 650k]
  |  |  |  |  ------------------
  |  |  |  |   44|   650k|        goto cleanup;        \
  |  |  |  |   45|   650k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1513|   650k|    } 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|   650k|    MPI_ECP_SQR(&tmp[2],  &P->Y);
  ------------------
  |  | 1170|   650k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, A))
  |  |  ------------------
  |  |  |  |   41|   650k|    do                           \
  |  |  |  |   42|   650k|    {                            \
  |  |  |  |   43|   650k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 650k]
  |  |  |  |  ------------------
  |  |  |  |   44|   650k|        goto cleanup;        \
  |  |  |  |   45|   650k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1530|   650k|    MPI_ECP_SHIFT_L(&tmp[2],  1);
  ------------------
  |  | 1182|   650k|    MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l_mod(grp, X, count))
  |  |  ------------------
  |  |  |  |   41|   650k|    do                           \
  |  |  |  |   42|   650k|    {                            \
  |  |  |  |   43|   650k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 650k]
  |  |  |  |  ------------------
  |  |  |  |   44|   650k|        goto cleanup;        \
  |  |  |  |   45|   650k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1531|   650k|    MPI_ECP_MUL(&tmp[1],  &P->X, &tmp[2]);
  ------------------
  |  | 1167|   650k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|   650k|    do                           \
  |  |  |  |   42|   650k|    {                            \
  |  |  |  |   43|   650k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 650k]
  |  |  |  |  ------------------
  |  |  |  |   44|   650k|        goto cleanup;        \
  |  |  |  |   45|   650k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1532|   650k|    MPI_ECP_SHIFT_L(&tmp[1],  1);
  ------------------
  |  | 1182|   650k|    MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l_mod(grp, X, count))
  |  |  ------------------
  |  |  |  |   41|   650k|    do                           \
  |  |  |  |   42|   650k|    {                            \
  |  |  |  |   43|   650k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 650k]
  |  |  |  |  ------------------
  |  |  |  |   44|   650k|        goto cleanup;        \
  |  |  |  |   45|   650k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1533|       |
 1534|       |    /* tmp[3] <- U = 8.Y^4 */
 1535|   650k|    MPI_ECP_SQR(&tmp[3],  &tmp[2]);
  ------------------
  |  | 1170|   650k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, A))
  |  |  ------------------
  |  |  |  |   41|   650k|    do                           \
  |  |  |  |   42|   650k|    {                            \
  |  |  |  |   43|   650k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 650k]
  |  |  |  |  ------------------
  |  |  |  |   44|   650k|        goto cleanup;        \
  |  |  |  |   45|   650k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1536|   650k|    MPI_ECP_SHIFT_L(&tmp[3],  1);
  ------------------
  |  | 1182|   650k|    MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l_mod(grp, X, count))
  |  |  ------------------
  |  |  |  |   41|   650k|    do                           \
  |  |  |  |   42|   650k|    {                            \
  |  |  |  |   43|   650k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 650k]
  |  |  |  |  ------------------
  |  |  |  |   44|   650k|        goto cleanup;        \
  |  |  |  |   45|   650k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1537|       |
 1538|       |    /* tmp[2] <- T = M^2 - 2.S */
 1539|   650k|    MPI_ECP_SQR(&tmp[2],  &tmp[0]);
  ------------------
  |  | 1170|   650k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, A))
  |  |  ------------------
  |  |  |  |   41|   650k|    do                           \
  |  |  |  |   42|   650k|    {                            \
  |  |  |  |   43|   650k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 650k]
  |  |  |  |  ------------------
  |  |  |  |   44|   650k|        goto cleanup;        \
  |  |  |  |   45|   650k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1540|   650k|    MPI_ECP_SUB(&tmp[2],  &tmp[2], &tmp[1]);
  ------------------
  |  | 1164|   650k|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|   650k|    do                           \
  |  |  |  |   42|   650k|    {                            \
  |  |  |  |   43|   650k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 650k]
  |  |  |  |  ------------------
  |  |  |  |   44|   650k|        goto cleanup;        \
  |  |  |  |   45|   650k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1541|   650k|    MPI_ECP_SUB(&tmp[2],  &tmp[2], &tmp[1]);
  ------------------
  |  | 1164|   650k|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|   650k|    do                           \
  |  |  |  |   42|   650k|    {                            \
  |  |  |  |   43|   650k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 650k]
  |  |  |  |  ------------------
  |  |  |  |   44|   650k|        goto cleanup;        \
  |  |  |  |   45|   650k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1542|       |
 1543|       |    /* tmp[1] <- S = M(S - T) - U */
 1544|   650k|    MPI_ECP_SUB(&tmp[1],  &tmp[1],     &tmp[2]);
  ------------------
  |  | 1164|   650k|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|   650k|    do                           \
  |  |  |  |   42|   650k|    {                            \
  |  |  |  |   43|   650k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 650k]
  |  |  |  |  ------------------
  |  |  |  |   44|   650k|        goto cleanup;        \
  |  |  |  |   45|   650k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1545|   650k|    MPI_ECP_MUL(&tmp[1],  &tmp[1],     &tmp[0]);
  ------------------
  |  | 1167|   650k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|   650k|    do                           \
  |  |  |  |   42|   650k|    {                            \
  |  |  |  |   43|   650k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 650k]
  |  |  |  |  ------------------
  |  |  |  |   44|   650k|        goto cleanup;        \
  |  |  |  |   45|   650k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1546|   650k|    MPI_ECP_SUB(&tmp[1],  &tmp[1],     &tmp[3]);
  ------------------
  |  | 1164|   650k|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|   650k|    do                           \
  |  |  |  |   42|   650k|    {                            \
  |  |  |  |   43|   650k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 650k]
  |  |  |  |  ------------------
  |  |  |  |   44|   650k|        goto cleanup;        \
  |  |  |  |   45|   650k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1547|       |
 1548|       |    /* tmp[3] <- U = 2.Y.Z */
 1549|   650k|    MPI_ECP_MUL(&tmp[3],  &P->Y,  &P->Z);
  ------------------
  |  | 1167|   650k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|   650k|    do                           \
  |  |  |  |   42|   650k|    {                            \
  |  |  |  |   43|   650k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 650k]
  |  |  |  |  ------------------
  |  |  |  |   44|   650k|        goto cleanup;        \
  |  |  |  |   45|   650k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1550|   650k|    MPI_ECP_SHIFT_L(&tmp[3],  1);
  ------------------
  |  | 1182|   650k|    MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l_mod(grp, X, count))
  |  |  ------------------
  |  |  |  |   41|   650k|    do                           \
  |  |  |  |   42|   650k|    {                            \
  |  |  |  |   43|   650k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 650k]
  |  |  |  |  ------------------
  |  |  |  |   44|   650k|        goto cleanup;        \
  |  |  |  |   45|   650k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1551|       |
 1552|       |    /* Store results */
 1553|   650k|    MPI_ECP_MOV(&R->X, &tmp[2]);
  ------------------
  |  | 1179|   650k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(X, A))
  |  |  ------------------
  |  |  |  |   41|   650k|    do                           \
  |  |  |  |   42|   650k|    {                            \
  |  |  |  |   43|   650k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 650k]
  |  |  |  |  ------------------
  |  |  |  |   44|   650k|        goto cleanup;        \
  |  |  |  |   45|   650k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1554|   650k|    MPI_ECP_MOV(&R->Y, &tmp[1]);
  ------------------
  |  | 1179|   650k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(X, A))
  |  |  ------------------
  |  |  |  |   41|   650k|    do                           \
  |  |  |  |   42|   650k|    {                            \
  |  |  |  |   43|   650k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 650k]
  |  |  |  |  ------------------
  |  |  |  |   44|   650k|        goto cleanup;        \
  |  |  |  |   45|   650k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1555|   650k|    MPI_ECP_MOV(&R->Z, &tmp[3]);
  ------------------
  |  | 1179|   650k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(X, A))
  |  |  ------------------
  |  |  |  |   41|   650k|    do                           \
  |  |  |  |   42|   650k|    {                            \
  |  |  |  |   43|   650k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 650k]
  |  |  |  |  ------------------
  |  |  |  |   44|   650k|        goto cleanup;        \
  |  |  |  |   45|   650k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1556|       |
 1557|   650k|cleanup:
 1558|       |
 1559|   650k|    return ret;
 1560|   650k|#endif /* !defined(MBEDTLS_ECP_NO_FALLBACK) || !defined(MBEDTLS_ECP_DOUBLE_JAC_ALT) */
 1561|   650k|}
ecp.c:mbedtls_mpi_mul_int_mod:
 1116|   650k|{
 1117|   650k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|   650k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1118|       |
 1119|   650k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_int(X, A, c));
  ------------------
  |  |   41|   650k|    do                           \
  |  |   42|   650k|    {                            \
  |  |   43|   650k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 650k]
  |  |  ------------------
  |  |   44|   650k|        goto cleanup;        \
  |  |   45|   650k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1120|   650k|    MOD_ADD(X);
  ------------------
  |  | 1096|  1.28M|    while (mbedtls_mpi_cmp_mpi((N), &grp->P) >= 0)                  \
  |  |  ------------------
  |  |  |  Branch (1096:12): [True: 635k, False: 650k]
  |  |  ------------------
  |  | 1097|   650k|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs((N), (N), &grp->P))
  |  |  ------------------
  |  |  |  |   41|  1.28M|    do                           \
  |  |  |  |   42|  1.28M|    {                            \
  |  |  |  |   43|   635k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 635k]
  |  |  |  |  ------------------
  |  |  |  |   44|   635k|        goto cleanup;        \
  |  |  |  |   45|   635k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1121|   650k|cleanup:
 1122|   650k|    return ret;
 1123|   650k|}
ecp.c:mbedtls_mpi_shift_l_mod:
 1146|  2.86M|{
 1147|  2.86M|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  2.86M|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1148|  2.86M|    MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(X, count));
  ------------------
  |  |   41|  2.86M|    do                           \
  |  |   42|  2.86M|    {                            \
  |  |   43|  2.86M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.86M]
  |  |  ------------------
  |  |   44|  2.86M|        goto cleanup;        \
  |  |   45|  2.86M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1149|  2.86M|    MOD_ADD(X);
  ------------------
  |  | 1096|  4.26M|    while (mbedtls_mpi_cmp_mpi((N), &grp->P) >= 0)                  \
  |  |  ------------------
  |  |  |  Branch (1096:12): [True: 1.40M, False: 2.86M]
  |  |  ------------------
  |  | 1097|  2.86M|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs((N), (N), &grp->P))
  |  |  ------------------
  |  |  |  |   41|  4.26M|    do                           \
  |  |  |  |   42|  4.26M|    {                            \
  |  |  |  |   43|  1.40M|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 1.40M]
  |  |  |  |  ------------------
  |  |  |  |   44|  1.40M|        goto cleanup;        \
  |  |  |  |   45|  1.40M|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1150|  2.86M|cleanup:
 1151|  2.86M|    return ret;
 1152|  2.86M|}
ecp.c:ecp_normalize_jac_many:
 1362|  4.22k|{
 1363|  4.22k|    if (T_size < 2) {
  ------------------
  |  Branch (1363:9): [True: 0, False: 4.22k]
  ------------------
 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|  4.22k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  4.22k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1377|  4.22k|    size_t i;
 1378|  4.22k|    mbedtls_mpi *c, t;
 1379|       |
 1380|  4.22k|    if ((c = mbedtls_calloc(T_size, sizeof(mbedtls_mpi))) == NULL) {
  ------------------
  |  |  144|  4.22k|#define mbedtls_calloc     MBEDTLS_PLATFORM_CALLOC_MACRO
  |  |  ------------------
  |  |  |  | 4093|  4.22k|#define MBEDTLS_PLATFORM_CALLOC_MACRO        my_calloc
  |  |  ------------------
  ------------------
  |  Branch (1380:9): [True: 0, False: 4.22k]
  ------------------
 1381|      0|        return MBEDTLS_ERR_ECP_ALLOC_FAILED;
  ------------------
  |  |   43|      0|#define MBEDTLS_ERR_ECP_ALLOC_FAILED                      -0x4D80
  ------------------
 1382|      0|    }
 1383|       |
 1384|  4.22k|    mbedtls_mpi_init(&t);
 1385|       |
 1386|  4.22k|    mpi_init_many(c, T_size);
 1387|       |    /*
 1388|       |     * c[i] = Z_0 * ... * Z_i,   i = 0,..,n := T_size-1
 1389|       |     */
 1390|  4.22k|    MPI_ECP_MOV(&c[0], &T[0]->Z);
  ------------------
  |  | 1179|  4.22k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(X, A))
  |  |  ------------------
  |  |  |  |   41|  4.22k|    do                           \
  |  |  |  |   42|  4.22k|    {                            \
  |  |  |  |   43|  4.22k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 4.22k]
  |  |  |  |  ------------------
  |  |  |  |   44|  4.22k|        goto cleanup;        \
  |  |  |  |   45|  4.22k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1391|  21.1k|    for (i = 1; i < T_size; i++) {
  ------------------
  |  Branch (1391:17): [True: 16.8k, False: 4.22k]
  ------------------
 1392|  16.8k|        MPI_ECP_MUL(&c[i], &c[i-1], &T[i]->Z);
  ------------------
  |  | 1167|  16.8k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  16.8k|    do                           \
  |  |  |  |   42|  16.8k|    {                            \
  |  |  |  |   43|  16.8k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 16.8k]
  |  |  |  |  ------------------
  |  |  |  |   44|  16.8k|        goto cleanup;        \
  |  |  |  |   45|  16.8k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1393|  16.8k|    }
 1394|       |
 1395|       |    /*
 1396|       |     * c[n] = 1 / (Z_0 * ... * Z_n) mod P
 1397|       |     */
 1398|  4.22k|    MPI_ECP_INV(&c[T_size-1], &c[T_size-1]);
  ------------------
  |  | 1176|  4.22k|    MBEDTLS_MPI_CHK(mbedtls_mpi_inv_mod((dst), (src), &grp->P))
  |  |  ------------------
  |  |  |  |   41|  4.22k|    do                           \
  |  |  |  |   42|  4.22k|    {                            \
  |  |  |  |   43|  4.22k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 4.22k]
  |  |  |  |  ------------------
  |  |  |  |   44|  4.22k|        goto cleanup;        \
  |  |  |  |   45|  4.22k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1399|       |
 1400|  21.1k|    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|  21.1k|        if (i > 0) {
  ------------------
  |  Branch (1413:13): [True: 16.8k, False: 4.22k]
  ------------------
 1414|       |            /* Compute 1/Z_i and establish invariant for the next iteration. */
 1415|  16.8k|            MPI_ECP_MUL(&t,      &c[i], &c[i-1]);
  ------------------
  |  | 1167|  16.8k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  16.8k|    do                           \
  |  |  |  |   42|  16.8k|    {                            \
  |  |  |  |   43|  16.8k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 16.8k]
  |  |  |  |  ------------------
  |  |  |  |   44|  16.8k|        goto cleanup;        \
  |  |  |  |   45|  16.8k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1416|  16.8k|            MPI_ECP_MUL(&c[i-1], &c[i], &T[i]->Z);
  ------------------
  |  | 1167|  16.8k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  16.8k|    do                           \
  |  |  |  |   42|  16.8k|    {                            \
  |  |  |  |   43|  16.8k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 16.8k]
  |  |  |  |  ------------------
  |  |  |  |   44|  16.8k|        goto cleanup;        \
  |  |  |  |   45|  16.8k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1417|  16.8k|        } else {
 1418|  4.22k|            MPI_ECP_MOV(&t, &c[0]);
  ------------------
  |  | 1179|  4.22k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(X, A))
  |  |  ------------------
  |  |  |  |   41|  4.22k|    do                           \
  |  |  |  |   42|  4.22k|    {                            \
  |  |  |  |   43|  4.22k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 4.22k]
  |  |  |  |  ------------------
  |  |  |  |   44|  4.22k|        goto cleanup;        \
  |  |  |  |   45|  4.22k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1419|  4.22k|        }
 1420|       |
 1421|       |        /* Now t holds 1 / Z_i; normalize as in ecp_normalize_jac() */
 1422|  21.1k|        MPI_ECP_MUL(&T[i]->Y, &T[i]->Y, &t);
  ------------------
  |  | 1167|  21.1k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  21.1k|    do                           \
  |  |  |  |   42|  21.1k|    {                            \
  |  |  |  |   43|  21.1k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 21.1k]
  |  |  |  |  ------------------
  |  |  |  |   44|  21.1k|        goto cleanup;        \
  |  |  |  |   45|  21.1k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1423|  21.1k|        MPI_ECP_SQR(&t,       &t);
  ------------------
  |  | 1170|  21.1k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, A))
  |  |  ------------------
  |  |  |  |   41|  21.1k|    do                           \
  |  |  |  |   42|  21.1k|    {                            \
  |  |  |  |   43|  21.1k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 21.1k]
  |  |  |  |  ------------------
  |  |  |  |   44|  21.1k|        goto cleanup;        \
  |  |  |  |   45|  21.1k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1424|  21.1k|        MPI_ECP_MUL(&T[i]->X, &T[i]->X, &t);
  ------------------
  |  | 1167|  21.1k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  21.1k|    do                           \
  |  |  |  |   42|  21.1k|    {                            \
  |  |  |  |   43|  21.1k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 21.1k]
  |  |  |  |  ------------------
  |  |  |  |   44|  21.1k|        goto cleanup;        \
  |  |  |  |   45|  21.1k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1425|  21.1k|        MPI_ECP_MUL(&T[i]->Y, &T[i]->Y, &t);
  ------------------
  |  | 1167|  21.1k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  21.1k|    do                           \
  |  |  |  |   42|  21.1k|    {                            \
  |  |  |  |   43|  21.1k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 21.1k]
  |  |  |  |  ------------------
  |  |  |  |   44|  21.1k|        goto cleanup;        \
  |  |  |  |   45|  21.1k|    } 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|  21.1k|        MBEDTLS_MPI_CHK(mbedtls_mpi_shrink(&T[i]->X, grp->P.n));
  ------------------
  |  |   41|  21.1k|    do                           \
  |  |   42|  21.1k|    {                            \
  |  |   43|  21.1k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 21.1k]
  |  |  ------------------
  |  |   44|  21.1k|        goto cleanup;        \
  |  |   45|  21.1k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1434|  21.1k|        MBEDTLS_MPI_CHK(mbedtls_mpi_shrink(&T[i]->Y, grp->P.n));
  ------------------
  |  |   41|  21.1k|    do                           \
  |  |   42|  21.1k|    {                            \
  |  |   43|  21.1k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 21.1k]
  |  |  ------------------
  |  |   44|  21.1k|        goto cleanup;        \
  |  |   45|  21.1k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1435|       |
 1436|  21.1k|        MPI_ECP_LSET(&T[i]->Z, 1);
  ------------------
  |  | 1185|  21.1k|    MBEDTLS_MPI_CHK(mbedtls_mpi_lset(X, c))
  |  |  ------------------
  |  |  |  |   41|  21.1k|    do                           \
  |  |  |  |   42|  21.1k|    {                            \
  |  |  |  |   43|  21.1k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 21.1k]
  |  |  |  |  ------------------
  |  |  |  |   44|  21.1k|        goto cleanup;        \
  |  |  |  |   45|  21.1k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1437|       |
 1438|  21.1k|        if (i == 0) {
  ------------------
  |  Branch (1438:13): [True: 4.22k, False: 16.8k]
  ------------------
 1439|  4.22k|            break;
 1440|  4.22k|        }
 1441|  21.1k|    }
 1442|       |
 1443|  4.22k|cleanup:
 1444|       |
 1445|  4.22k|    mbedtls_mpi_free(&t);
 1446|  4.22k|    mpi_free_many(c, T_size);
 1447|  4.22k|    mbedtls_free(c);
  ------------------
  |  |  143|  4.22k|#define mbedtls_free       MBEDTLS_PLATFORM_FREE_MACRO
  |  |  ------------------
  |  |  |  | 4095|  4.22k|#define MBEDTLS_PLATFORM_FREE_MACRO            my_free
  |  |  ------------------
  ------------------
 1448|       |
 1449|  4.22k|    return ret;
 1450|  4.22k|#endif /* !defined(MBEDTLS_ECP_NO_FALLBACK) || !defined(MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT) */
 1451|  4.22k|}
ecp.c:ecp_mul_comb_after_precomp:
 2174|  4.22k|{
 2175|  4.22k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  4.22k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 2176|  4.22k|    unsigned char parity_trick;
 2177|  4.22k|    unsigned char k[COMB_MAX_D + 1];
 2178|  4.22k|    mbedtls_ecp_point *RR = R;
 2179|       |
 2180|  4.22k|#if defined(MBEDTLS_ECP_RESTARTABLE)
 2181|  4.22k|    if (rs_ctx != NULL && rs_ctx->rsm != NULL) {
  ------------------
  |  Branch (2181:9): [True: 0, False: 4.22k]
  |  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|  4.22k|#endif
 2189|       |
 2190|  4.22k|    MBEDTLS_MPI_CHK(ecp_comb_recode_scalar(grp, m, k, d, w,
  ------------------
  |  |   41|  4.22k|    do                           \
  |  |   42|  4.22k|    {                            \
  |  |   43|  4.22k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.22k]
  |  |  ------------------
  |  |   44|  4.22k|        goto cleanup;        \
  |  |   45|  4.22k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2191|  4.22k|                                           &parity_trick));
 2192|  4.22k|    MBEDTLS_MPI_CHK(ecp_mul_comb_core(grp, RR, T, T_size, k, d,
  ------------------
  |  |   41|  4.22k|    do                           \
  |  |   42|  4.22k|    {                            \
  |  |   43|  4.22k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.22k]
  |  |  ------------------
  |  |   44|  4.22k|        goto cleanup;        \
  |  |   45|  4.22k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2193|  4.22k|                                      f_rng, p_rng, rs_ctx));
 2194|  4.22k|    MBEDTLS_MPI_CHK(ecp_safe_invert_jac(grp, RR, parity_trick));
  ------------------
  |  |   41|  4.22k|    do                           \
  |  |   42|  4.22k|    {                            \
  |  |   43|  4.22k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.22k]
  |  |  ------------------
  |  |   44|  4.22k|        goto cleanup;        \
  |  |   45|  4.22k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2195|       |
 2196|  4.22k|#if defined(MBEDTLS_ECP_RESTARTABLE)
 2197|  4.22k|    if (rs_ctx != NULL && rs_ctx->rsm != NULL) {
  ------------------
  |  Branch (2197:9): [True: 0, False: 4.22k]
  |  Branch (2197:27): [True: 0, False: 0]
  ------------------
 2198|      0|        rs_ctx->rsm->state = ecp_rsm_final_norm;
 2199|      0|    }
 2200|       |
 2201|  4.22k|final_norm:
 2202|  4.22k|    MBEDTLS_ECP_BUDGET(MBEDTLS_ECP_OPS_INV);
  ------------------
  |  |  408|  4.22k|    MBEDTLS_MPI_CHK(mbedtls_ecp_check_budget(grp, rs_ctx, \
  |  |  ------------------
  |  |  |  |   41|  4.22k|    do                           \
  |  |  |  |   42|  4.22k|    {                            \
  |  |  |  |   43|  4.22k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 4.22k]
  |  |  |  |  ------------------
  |  |  |  |   44|  4.22k|        goto cleanup;        \
  |  |  |  |   45|  4.22k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  409|  4.22k|                                             (unsigned) (ops)));
  ------------------
 2203|  4.22k|#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|  4.22k|    if (f_rng != 0) {
  ------------------
  |  Branch (2215:9): [True: 3, False: 4.22k]
  ------------------
 2216|      3|        MBEDTLS_MPI_CHK(ecp_randomize_jac(grp, RR, f_rng, p_rng));
  ------------------
  |  |   41|      3|    do                           \
  |  |   42|      3|    {                            \
  |  |   43|      3|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3]
  |  |  ------------------
  |  |   44|      3|        goto cleanup;        \
  |  |   45|      3|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2217|      3|    }
 2218|       |
 2219|  4.22k|    MBEDTLS_MPI_CHK(ecp_normalize_jac(grp, RR));
  ------------------
  |  |   41|  4.22k|    do                           \
  |  |   42|  4.22k|    {                            \
  |  |   43|  4.22k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.22k]
  |  |  ------------------
  |  |   44|  4.22k|        goto cleanup;        \
  |  |   45|  4.22k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2220|       |
 2221|  4.22k|#if defined(MBEDTLS_ECP_RESTARTABLE)
 2222|  4.22k|    if (rs_ctx != NULL && rs_ctx->rsm != NULL) {
  ------------------
  |  Branch (2222:9): [True: 0, False: 4.22k]
  |  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|  4.22k|#endif
 2226|       |
 2227|  4.22k|cleanup:
 2228|  4.22k|    return ret;
 2229|  4.22k|}
ecp.c:ecp_comb_recode_scalar:
 2127|  4.22k|{
 2128|  4.22k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  4.22k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 2129|  4.22k|    mbedtls_mpi M, mm;
 2130|       |
 2131|  4.22k|    mbedtls_mpi_init(&M);
 2132|  4.22k|    mbedtls_mpi_init(&mm);
 2133|       |
 2134|       |    /* N is always odd (see above), just make extra sure */
 2135|  4.22k|    if (mbedtls_mpi_get_bit(&grp->N, 0) != 1) {
  ------------------
  |  Branch (2135:9): [True: 0, False: 4.22k]
  ------------------
 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|  4.22k|    *parity_trick = (mbedtls_mpi_get_bit(m, 0) == 0);
 2141|       |
 2142|       |    /* execute parity fix in constant time */
 2143|  4.22k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&M, m));
  ------------------
  |  |   41|  4.22k|    do                           \
  |  |   42|  4.22k|    {                            \
  |  |   43|  4.22k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.22k]
  |  |  ------------------
  |  |   44|  4.22k|        goto cleanup;        \
  |  |   45|  4.22k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2144|  4.22k|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&mm, &grp->N, m));
  ------------------
  |  |   41|  4.22k|    do                           \
  |  |   42|  4.22k|    {                            \
  |  |   43|  4.22k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.22k]
  |  |  ------------------
  |  |   44|  4.22k|        goto cleanup;        \
  |  |   45|  4.22k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2145|  4.22k|    MBEDTLS_MPI_CHK(mbedtls_mpi_safe_cond_assign(&M, &mm, *parity_trick));
  ------------------
  |  |   41|  4.22k|    do                           \
  |  |   42|  4.22k|    {                            \
  |  |   43|  4.22k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.22k]
  |  |  ------------------
  |  |   44|  4.22k|        goto cleanup;        \
  |  |   45|  4.22k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2146|       |
 2147|       |    /* actual scalar recoding */
 2148|  4.22k|    ecp_comb_recode_core(k, d, w, &M);
 2149|       |
 2150|  4.22k|cleanup:
 2151|  4.22k|    mbedtls_mpi_free(&mm);
 2152|  4.22k|    mbedtls_mpi_free(&M);
 2153|       |
 2154|  4.22k|    return ret;
 2155|  4.22k|}
ecp.c:ecp_comb_recode_core:
 1786|  4.22k|{
 1787|  4.22k|    size_t i, j;
 1788|  4.22k|    unsigned char c, cc, adjust;
 1789|       |
 1790|  4.22k|    memset(x, 0, d+1);
 1791|       |
 1792|       |    /* First get the classical comb values (except for x_d = 0) */
 1793|   249k|    for (i = 0; i < d; i++) {
  ------------------
  |  Branch (1793:17): [True: 245k, False: 4.22k]
  ------------------
 1794|  1.33M|        for (j = 0; j < w; j++) {
  ------------------
  |  Branch (1794:21): [True: 1.09M, False: 245k]
  ------------------
 1795|  1.09M|            x[i] |= mbedtls_mpi_get_bit(m, i + d * j) << j;
 1796|  1.09M|        }
 1797|   245k|    }
 1798|       |
 1799|       |    /* Now make sure x_1 .. x_d are odd */
 1800|  4.22k|    c = 0;
 1801|   249k|    for (i = 1; i <= d; i++) {
  ------------------
  |  Branch (1801:17): [True: 245k, False: 4.22k]
  ------------------
 1802|       |        /* Add carry and update it */
 1803|   245k|        cc   = x[i] & c;
 1804|   245k|        x[i] = x[i] ^ c;
 1805|   245k|        c = cc;
 1806|       |
 1807|       |        /* Adjust if needed, avoiding branches */
 1808|   245k|        adjust = 1 - (x[i] & 0x01);
 1809|   245k|        c   |= x[i] & (x[i-1] * adjust);
 1810|   245k|        x[i] = x[i] ^ (x[i-1] * adjust);
 1811|   245k|        x[i-1] |= adjust << 7;
 1812|   245k|    }
 1813|  4.22k|}
ecp.c:ecp_mul_comb_core:
 2049|  4.22k|{
 2050|  4.22k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  4.22k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 2051|  4.22k|    mbedtls_ecp_point Txi;
 2052|  4.22k|    mbedtls_mpi tmp[4];
 2053|  4.22k|    size_t i;
 2054|       |
 2055|  4.22k|    mbedtls_ecp_point_init(&Txi);
 2056|  4.22k|    mpi_init_many(tmp, sizeof(tmp) / sizeof(mbedtls_mpi));
 2057|       |
 2058|       |#if !defined(MBEDTLS_ECP_RESTARTABLE)
 2059|       |    (void) rs_ctx;
 2060|       |#endif
 2061|       |
 2062|  4.22k|#if defined(MBEDTLS_ECP_RESTARTABLE)
 2063|  4.22k|    if (rs_ctx != NULL && rs_ctx->rsm != NULL &&
  ------------------
  |  Branch (2063:9): [True: 0, False: 4.22k]
  |  Branch (2063:27): [True: 0, False: 0]
  ------------------
 2064|  4.22k|        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|  4.22k|    if (rs_ctx != NULL && rs_ctx->rsm != NULL && rs_ctx->rsm->i != 0) {
  ------------------
  |  Branch (2070:9): [True: 0, False: 4.22k]
  |  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|  4.22k|#endif
 2075|  4.22k|    {
 2076|       |        /* Start with a non-zero point and randomize its coordinates */
 2077|  4.22k|        i = d;
 2078|  4.22k|        MBEDTLS_MPI_CHK(ecp_select_comb(grp, R, T, T_size, x[i]));
  ------------------
  |  |   41|  4.22k|    do                           \
  |  |   42|  4.22k|    {                            \
  |  |   43|  4.22k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.22k]
  |  |  ------------------
  |  |   44|  4.22k|        goto cleanup;        \
  |  |   45|  4.22k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2079|  4.22k|        if (f_rng != 0) {
  ------------------
  |  Branch (2079:13): [True: 3, False: 4.22k]
  ------------------
 2080|      3|            MBEDTLS_MPI_CHK(ecp_randomize_jac(grp, R, f_rng, p_rng));
  ------------------
  |  |   41|      3|    do                           \
  |  |   42|      3|    {                            \
  |  |   43|      3|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3]
  |  |  ------------------
  |  |   44|      3|        goto cleanup;        \
  |  |   45|      3|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2081|      3|        }
 2082|  4.22k|    }
 2083|       |
 2084|   249k|    while (i != 0) {
  ------------------
  |  Branch (2084:12): [True: 245k, False: 4.22k]
  ------------------
 2085|   245k|        MBEDTLS_ECP_BUDGET(MBEDTLS_ECP_OPS_DBL + MBEDTLS_ECP_OPS_ADD);
  ------------------
  |  |  408|   245k|    MBEDTLS_MPI_CHK(mbedtls_ecp_check_budget(grp, rs_ctx, \
  |  |  ------------------
  |  |  |  |   41|   245k|    do                           \
  |  |  |  |   42|   245k|    {                            \
  |  |  |  |   43|   245k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 245k]
  |  |  |  |  ------------------
  |  |  |  |   44|   245k|        goto cleanup;        \
  |  |  |  |   45|   245k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  409|   245k|                                             (unsigned) (ops)));
  ------------------
 2086|   245k|        --i;
 2087|       |
 2088|   245k|        MBEDTLS_MPI_CHK(ecp_double_jac(grp, R, R, tmp));
  ------------------
  |  |   41|   245k|    do                           \
  |  |   42|   245k|    {                            \
  |  |   43|   245k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 245k]
  |  |  ------------------
  |  |   44|   245k|        goto cleanup;        \
  |  |   45|   245k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2089|   245k|        MBEDTLS_MPI_CHK(ecp_select_comb(grp, &Txi, T, T_size, x[i]));
  ------------------
  |  |   41|   245k|    do                           \
  |  |   42|   245k|    {                            \
  |  |   43|   245k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 245k]
  |  |  ------------------
  |  |   44|   245k|        goto cleanup;        \
  |  |   45|   245k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2090|   245k|        MBEDTLS_MPI_CHK(ecp_add_mixed(grp, R, R, &Txi, tmp));
  ------------------
  |  |   41|   245k|    do                           \
  |  |   42|   245k|    {                            \
  |  |   43|   245k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 245k]
  |  |  ------------------
  |  |   44|   245k|        goto cleanup;        \
  |  |   45|   245k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2091|   245k|    }
 2092|       |
 2093|  4.22k|cleanup:
 2094|       |
 2095|  4.22k|    mbedtls_ecp_point_free(&Txi);
 2096|  4.22k|    mpi_free_many(tmp, sizeof(tmp) / sizeof(mbedtls_mpi));
 2097|       |
 2098|  4.22k|#if defined(MBEDTLS_ECP_RESTARTABLE)
 2099|  4.22k|    if (rs_ctx != NULL && rs_ctx->rsm != NULL &&
  ------------------
  |  Branch (2099:9): [True: 0, False: 4.22k]
  |  Branch (2099:27): [True: 0, False: 0]
  ------------------
 2100|  4.22k|        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|  4.22k|#endif
 2105|       |
 2106|  4.22k|    return ret;
 2107|  4.22k|}
ecp.c:ecp_select_comb:
 2015|   249k|{
 2016|   249k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|   249k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 2017|   249k|    unsigned char ii, j;
 2018|       |
 2019|       |    /* Ignore the "sign" bit and scale down */
 2020|   249k|    ii =  (i & 0x7Fu) >> 1;
 2021|       |
 2022|       |    /* Read the whole table to thwart cache-based timing attacks */
 2023|  3.14M|    for (j = 0; j < T_size; j++) {
  ------------------
  |  Branch (2023:17): [True: 2.89M, False: 249k]
  ------------------
 2024|  2.89M|        MPI_ECP_COND_ASSIGN(&R->X, &T[j].X, j == ii);
  ------------------
  |  | 1214|  2.89M|    MBEDTLS_MPI_CHK(mbedtls_mpi_safe_cond_assign((X), (Y), (cond)))
  |  |  ------------------
  |  |  |  |   41|  2.89M|    do                           \
  |  |  |  |   42|  2.89M|    {                            \
  |  |  |  |   43|  2.89M|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 2.89M]
  |  |  |  |  ------------------
  |  |  |  |   44|  2.89M|        goto cleanup;        \
  |  |  |  |   45|  2.89M|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2025|  2.89M|        MPI_ECP_COND_ASSIGN(&R->Y, &T[j].Y, j == ii);
  ------------------
  |  | 1214|  2.89M|    MBEDTLS_MPI_CHK(mbedtls_mpi_safe_cond_assign((X), (Y), (cond)))
  |  |  ------------------
  |  |  |  |   41|  2.89M|    do                           \
  |  |  |  |   42|  2.89M|    {                            \
  |  |  |  |   43|  2.89M|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 2.89M]
  |  |  |  |  ------------------
  |  |  |  |   44|  2.89M|        goto cleanup;        \
  |  |  |  |   45|  2.89M|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2026|  2.89M|    }
 2027|       |
 2028|       |    /* Safely invert result if i is "negative" */
 2029|   249k|    MBEDTLS_MPI_CHK(ecp_safe_invert_jac(grp, R, i >> 7));
  ------------------
  |  |   41|   249k|    do                           \
  |  |   42|   249k|    {                            \
  |  |   43|   249k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 249k]
  |  |  ------------------
  |  |   44|   249k|        goto cleanup;        \
  |  |   45|   249k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2030|       |
 2031|   249k|    MPI_ECP_LSET(&R->Z, 1);
  ------------------
  |  | 1185|   249k|    MBEDTLS_MPI_CHK(mbedtls_mpi_lset(X, c))
  |  |  ------------------
  |  |  |  |   41|   249k|    do                           \
  |  |  |  |   42|   249k|    {                            \
  |  |  |  |   43|   249k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 249k]
  |  |  |  |  ------------------
  |  |  |  |   44|   249k|        goto cleanup;        \
  |  |  |  |   45|   249k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2032|       |
 2033|   249k|cleanup:
 2034|   249k|    return ret;
 2035|   249k|}
ecp.c:ecp_safe_invert_jac:
 1460|   253k|{
 1461|   253k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|   253k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1462|   253k|    mbedtls_mpi tmp;
 1463|   253k|    mbedtls_mpi_init(&tmp);
 1464|       |
 1465|   253k|    MPI_ECP_COND_NEG(&Q->Y, inv);
  ------------------
  |  | 1200|   253k|    do                                                                     \
  |  | 1201|   253k|    {                                                                      \
  |  | 1202|   253k|        unsigned char nonzero = mbedtls_mpi_cmp_int((X), 0) != 0;        \
  |  | 1203|   253k|        MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&tmp, &grp->P, (X)));      \
  |  |  ------------------
  |  |  |  |   41|   253k|    do                           \
  |  |  |  |   42|   253k|    {                            \
  |  |  |  |   43|   253k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 253k]
  |  |  |  |  ------------------
  |  |  |  |   44|   253k|        goto cleanup;        \
  |  |  |  |   45|   253k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 1204|   253k|        MBEDTLS_MPI_CHK(mbedtls_mpi_safe_cond_assign((X), &tmp,          \
  |  |  ------------------
  |  |  |  |   41|   253k|    do                           \
  |  |  |  |   42|   253k|    {                            \
  |  |  |  |   43|   253k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 253k]
  |  |  |  |  ------------------
  |  |  |  |   44|   253k|        goto cleanup;        \
  |  |  |  |   45|   253k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 1205|   253k|                                                     nonzero & cond)); \
  |  | 1206|   253k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (1206:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1466|       |
 1467|   253k|cleanup:
 1468|   253k|    mbedtls_mpi_free(&tmp);
 1469|   253k|    return ret;
 1470|   253k|}
ecp.c:ecp_randomize_jac:
 1683|      6|{
 1684|       |#if defined(MBEDTLS_ECP_RANDOMIZE_JAC_ALT)
 1685|       |    if (mbedtls_internal_ecp_grp_capable(grp)) {
 1686|       |        return mbedtls_internal_ecp_randomize_jac(grp, pt, f_rng, p_rng);
 1687|       |    }
 1688|       |#endif /* MBEDTLS_ECP_RANDOMIZE_JAC_ALT */
 1689|       |
 1690|       |#if defined(MBEDTLS_ECP_NO_FALLBACK) && defined(MBEDTLS_ECP_RANDOMIZE_JAC_ALT)
 1691|       |    return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
 1692|       |#else
 1693|      6|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|      6|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1694|      6|    mbedtls_mpi l;
 1695|       |
 1696|      6|    mbedtls_mpi_init(&l);
 1697|       |
 1698|       |    /* Generate l such that 1 < l < p */
 1699|      6|    MPI_ECP_RAND(&l);
  ------------------
  |  | 1195|      6|    MBEDTLS_MPI_CHK(mbedtls_mpi_random((X), 2, &grp->P, f_rng, p_rng))
  |  |  ------------------
  |  |  |  |   41|      6|    do                           \
  |  |  |  |   42|      6|    {                            \
  |  |  |  |   43|      6|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 6]
  |  |  |  |  ------------------
  |  |  |  |   44|      6|        goto cleanup;        \
  |  |  |  |   45|      6|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1700|       |
 1701|       |    /* Z' = l * Z */
 1702|      6|    MPI_ECP_MUL(&pt->Z,   &pt->Z,     &l);
  ------------------
  |  | 1167|      6|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|      6|    do                           \
  |  |  |  |   42|      6|    {                            \
  |  |  |  |   43|      6|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 6]
  |  |  |  |  ------------------
  |  |  |  |   44|      6|        goto cleanup;        \
  |  |  |  |   45|      6|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1703|       |
 1704|       |    /* Y' = l * Y */
 1705|      6|    MPI_ECP_MUL(&pt->Y,   &pt->Y,     &l);
  ------------------
  |  | 1167|      6|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|      6|    do                           \
  |  |  |  |   42|      6|    {                            \
  |  |  |  |   43|      6|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 6]
  |  |  |  |  ------------------
  |  |  |  |   44|      6|        goto cleanup;        \
  |  |  |  |   45|      6|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1706|       |
 1707|       |    /* X' = l^2 * X */
 1708|      6|    MPI_ECP_SQR(&l,       &l);
  ------------------
  |  | 1170|      6|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, A))
  |  |  ------------------
  |  |  |  |   41|      6|    do                           \
  |  |  |  |   42|      6|    {                            \
  |  |  |  |   43|      6|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 6]
  |  |  |  |  ------------------
  |  |  |  |   44|      6|        goto cleanup;        \
  |  |  |  |   45|      6|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1709|      6|    MPI_ECP_MUL(&pt->X,   &pt->X,     &l);
  ------------------
  |  | 1167|      6|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|      6|    do                           \
  |  |  |  |   42|      6|    {                            \
  |  |  |  |   43|      6|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 6]
  |  |  |  |  ------------------
  |  |  |  |   44|      6|        goto cleanup;        \
  |  |  |  |   45|      6|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1710|       |
 1711|       |    /* Y'' = l^2 * Y' = l^3 * Y */
 1712|      6|    MPI_ECP_MUL(&pt->Y,   &pt->Y,     &l);
  ------------------
  |  | 1167|      6|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|      6|    do                           \
  |  |  |  |   42|      6|    {                            \
  |  |  |  |   43|      6|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 6]
  |  |  |  |  ------------------
  |  |  |  |   44|      6|        goto cleanup;        \
  |  |  |  |   45|      6|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1713|       |
 1714|      6|cleanup:
 1715|      6|    mbedtls_mpi_free(&l);
 1716|       |
 1717|      6|    if (ret == MBEDTLS_ERR_MPI_NOT_ACCEPTABLE) {
  ------------------
  |  |   36|      6|#define MBEDTLS_ERR_MPI_NOT_ACCEPTABLE                    -0x000E
  ------------------
  |  Branch (1717:9): [True: 0, False: 6]
  ------------------
 1718|      0|        ret = MBEDTLS_ERR_ECP_RANDOM_FAILED;
  ------------------
  |  |   45|      0|#define MBEDTLS_ERR_ECP_RANDOM_FAILED                     -0x4D00
  ------------------
 1719|      0|    }
 1720|      6|    return ret;
 1721|      6|#endif /* !defined(MBEDTLS_ECP_NO_FALLBACK) || !defined(MBEDTLS_ECP_RANDOMIZE_JAC_ALT) */
 1722|      6|}
ecp.c:mpi_init_many:
  318|  12.6k|{
  319|  67.5k|    while (size--) {
  ------------------
  |  Branch (319:12): [True: 54.9k, False: 12.6k]
  ------------------
  320|  54.9k|        mbedtls_mpi_init(arr++);
  321|  54.9k|    }
  322|  12.6k|}
ecp.c:mbedtls_ecp_mul_shortcuts:
 2770|  4.22k|{
 2771|  4.22k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  4.22k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 2772|  4.22k|    mbedtls_mpi tmp;
 2773|  4.22k|    mbedtls_mpi_init(&tmp);
 2774|       |
 2775|  4.22k|    if (mbedtls_mpi_cmp_int(m, 0) == 0) {
  ------------------
  |  Branch (2775:9): [True: 0, False: 4.22k]
  ------------------
 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|  4.22k|    } else if (mbedtls_mpi_cmp_int(m, 1) == 0) {
  ------------------
  |  Branch (2778:16): [True: 0, False: 4.22k]
  ------------------
 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|  4.22k|    } else if (mbedtls_mpi_cmp_int(m, -1) == 0) {
  ------------------
  |  Branch (2781:16): [True: 0, False: 4.22k]
  ------------------
 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|  4.22k|    } else {
 2786|  4.22k|        MBEDTLS_MPI_CHK(ecp_mul_restartable_internal(grp, R, m, P,
  ------------------
  |  |   41|  4.22k|    do                           \
  |  |   42|  4.22k|    {                            \
  |  |   43|  4.22k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.22k]
  |  |  ------------------
  |  |   44|  4.22k|        goto cleanup;        \
  |  |   45|  4.22k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2787|  4.22k|                                                     NULL, NULL, rs_ctx));
 2788|  4.22k|    }
 2789|       |
 2790|  4.22k|cleanup:
 2791|  4.22k|    mbedtls_mpi_free(&tmp);
 2792|       |
 2793|  4.22k|    return ret;
 2794|  4.22k|}
ecp.c:ecp_add_mixed:
 1586|   262k|{
 1587|   262k|#if defined(MBEDTLS_SELF_TEST)
 1588|   262k|    add_count++;
 1589|   262k|#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|   262k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|   262k|#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|   262k|    mbedtls_mpi * const X = &R->X;
 1606|   262k|    mbedtls_mpi * const Y = &R->Y;
 1607|   262k|    mbedtls_mpi * const Z = &R->Z;
 1608|       |
 1609|   262k|    if (!MPI_ECP_VALID(&Q->Z)) {
  ------------------
  |  | 1211|   262k|    ((X)->p != NULL)
  ------------------
  |  Branch (1609:9): [True: 0, False: 262k]
  ------------------
 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|   262k|    if (MPI_ECP_CMP_INT(&P->Z, 0) == 0) {
  ------------------
  |  | 1188|   262k|    mbedtls_mpi_cmp_int(X, c)
  ------------------
  |  Branch (1616:9): [True: 0, False: 262k]
  ------------------
 1617|      0|        return mbedtls_ecp_copy(R, Q);
 1618|      0|    }
 1619|       |
 1620|   262k|    if (MPI_ECP_CMP_INT(&Q->Z, 0) == 0) {
  ------------------
  |  | 1188|   262k|    mbedtls_mpi_cmp_int(X, c)
  ------------------
  |  Branch (1620:9): [True: 0, False: 262k]
  ------------------
 1621|      0|        return mbedtls_ecp_copy(R, P);
 1622|      0|    }
 1623|       |
 1624|       |    /*
 1625|       |     * Make sure Q coordinates are normalized
 1626|       |     */
 1627|   262k|    if (MPI_ECP_CMP_INT(&Q->Z, 1) != 0) {
  ------------------
  |  | 1188|   262k|    mbedtls_mpi_cmp_int(X, c)
  ------------------
  |  Branch (1627:9): [True: 0, False: 262k]
  ------------------
 1628|      0|        return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
 1629|      0|    }
 1630|       |
 1631|   262k|    MPI_ECP_SQR(&tmp[0], &P->Z);
  ------------------
  |  | 1170|   262k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, A))
  |  |  ------------------
  |  |  |  |   41|   262k|    do                           \
  |  |  |  |   42|   262k|    {                            \
  |  |  |  |   43|   262k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 262k]
  |  |  |  |  ------------------
  |  |  |  |   44|   262k|        goto cleanup;        \
  |  |  |  |   45|   262k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1632|   262k|    MPI_ECP_MUL(&tmp[1], &tmp[0], &P->Z);
  ------------------
  |  | 1167|   262k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|   262k|    do                           \
  |  |  |  |   42|   262k|    {                            \
  |  |  |  |   43|   262k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 262k]
  |  |  |  |  ------------------
  |  |  |  |   44|   262k|        goto cleanup;        \
  |  |  |  |   45|   262k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1633|   262k|    MPI_ECP_MUL(&tmp[0], &tmp[0], &Q->X);
  ------------------
  |  | 1167|   262k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|   262k|    do                           \
  |  |  |  |   42|   262k|    {                            \
  |  |  |  |   43|   262k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 262k]
  |  |  |  |  ------------------
  |  |  |  |   44|   262k|        goto cleanup;        \
  |  |  |  |   45|   262k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1634|   262k|    MPI_ECP_MUL(&tmp[1], &tmp[1], &Q->Y);
  ------------------
  |  | 1167|   262k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|   262k|    do                           \
  |  |  |  |   42|   262k|    {                            \
  |  |  |  |   43|   262k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 262k]
  |  |  |  |  ------------------
  |  |  |  |   44|   262k|        goto cleanup;        \
  |  |  |  |   45|   262k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1635|   262k|    MPI_ECP_SUB(&tmp[0], &tmp[0], &P->X);
  ------------------
  |  | 1164|   262k|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|   262k|    do                           \
  |  |  |  |   42|   262k|    {                            \
  |  |  |  |   43|   262k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 262k]
  |  |  |  |  ------------------
  |  |  |  |   44|   262k|        goto cleanup;        \
  |  |  |  |   45|   262k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1636|   262k|    MPI_ECP_SUB(&tmp[1], &tmp[1], &P->Y);
  ------------------
  |  | 1164|   262k|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|   262k|    do                           \
  |  |  |  |   42|   262k|    {                            \
  |  |  |  |   43|   262k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 262k]
  |  |  |  |  ------------------
  |  |  |  |   44|   262k|        goto cleanup;        \
  |  |  |  |   45|   262k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1637|       |
 1638|       |    /* Special cases (2) and (3) */
 1639|   262k|    if (MPI_ECP_CMP_INT(&tmp[0], 0) == 0) {
  ------------------
  |  | 1188|   262k|    mbedtls_mpi_cmp_int(X, c)
  ------------------
  |  Branch (1639:9): [True: 0, False: 262k]
  ------------------
 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|   262k|    MPI_ECP_MUL(Z,        &P->Z,    &tmp[0]);
  ------------------
  |  | 1167|   262k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|   262k|    do                           \
  |  |  |  |   42|   262k|    {                            \
  |  |  |  |   43|   262k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 262k]
  |  |  |  |  ------------------
  |  |  |  |   44|   262k|        goto cleanup;        \
  |  |  |  |   45|   262k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1651|   262k|    MPI_ECP_SQR(&tmp[2],  &tmp[0]);
  ------------------
  |  | 1170|   262k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, A))
  |  |  ------------------
  |  |  |  |   41|   262k|    do                           \
  |  |  |  |   42|   262k|    {                            \
  |  |  |  |   43|   262k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 262k]
  |  |  |  |  ------------------
  |  |  |  |   44|   262k|        goto cleanup;        \
  |  |  |  |   45|   262k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1652|   262k|    MPI_ECP_MUL(&tmp[3],  &tmp[2],  &tmp[0]);
  ------------------
  |  | 1167|   262k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|   262k|    do                           \
  |  |  |  |   42|   262k|    {                            \
  |  |  |  |   43|   262k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 262k]
  |  |  |  |  ------------------
  |  |  |  |   44|   262k|        goto cleanup;        \
  |  |  |  |   45|   262k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1653|   262k|    MPI_ECP_MUL(&tmp[2],  &tmp[2],  &P->X);
  ------------------
  |  | 1167|   262k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|   262k|    do                           \
  |  |  |  |   42|   262k|    {                            \
  |  |  |  |   43|   262k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 262k]
  |  |  |  |  ------------------
  |  |  |  |   44|   262k|        goto cleanup;        \
  |  |  |  |   45|   262k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1654|       |
 1655|   262k|    MPI_ECP_MOV(&tmp[0], &tmp[2]);
  ------------------
  |  | 1179|   262k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(X, A))
  |  |  ------------------
  |  |  |  |   41|   262k|    do                           \
  |  |  |  |   42|   262k|    {                            \
  |  |  |  |   43|   262k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 262k]
  |  |  |  |  ------------------
  |  |  |  |   44|   262k|        goto cleanup;        \
  |  |  |  |   45|   262k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1656|   262k|    MPI_ECP_SHIFT_L(&tmp[0], 1);
  ------------------
  |  | 1182|   262k|    MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l_mod(grp, X, count))
  |  |  ------------------
  |  |  |  |   41|   262k|    do                           \
  |  |  |  |   42|   262k|    {                            \
  |  |  |  |   43|   262k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 262k]
  |  |  |  |  ------------------
  |  |  |  |   44|   262k|        goto cleanup;        \
  |  |  |  |   45|   262k|    } 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|   262k|    MPI_ECP_SQR(X,        &tmp[1]);
  ------------------
  |  | 1170|   262k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, A))
  |  |  ------------------
  |  |  |  |   41|   262k|    do                           \
  |  |  |  |   42|   262k|    {                            \
  |  |  |  |   43|   262k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 262k]
  |  |  |  |  ------------------
  |  |  |  |   44|   262k|        goto cleanup;        \
  |  |  |  |   45|   262k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1660|   262k|    MPI_ECP_SUB(X,        X,        &tmp[0]);
  ------------------
  |  | 1164|   262k|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|   262k|    do                           \
  |  |  |  |   42|   262k|    {                            \
  |  |  |  |   43|   262k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 262k]
  |  |  |  |  ------------------
  |  |  |  |   44|   262k|        goto cleanup;        \
  |  |  |  |   45|   262k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1661|   262k|    MPI_ECP_SUB(X,        X,        &tmp[3]);
  ------------------
  |  | 1164|   262k|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|   262k|    do                           \
  |  |  |  |   42|   262k|    {                            \
  |  |  |  |   43|   262k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 262k]
  |  |  |  |  ------------------
  |  |  |  |   44|   262k|        goto cleanup;        \
  |  |  |  |   45|   262k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1662|   262k|    MPI_ECP_SUB(&tmp[2],  &tmp[2],  X);
  ------------------
  |  | 1164|   262k|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|   262k|    do                           \
  |  |  |  |   42|   262k|    {                            \
  |  |  |  |   43|   262k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 262k]
  |  |  |  |  ------------------
  |  |  |  |   44|   262k|        goto cleanup;        \
  |  |  |  |   45|   262k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1663|   262k|    MPI_ECP_MUL(&tmp[2],  &tmp[2],  &tmp[1]);
  ------------------
  |  | 1167|   262k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|   262k|    do                           \
  |  |  |  |   42|   262k|    {                            \
  |  |  |  |   43|   262k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 262k]
  |  |  |  |  ------------------
  |  |  |  |   44|   262k|        goto cleanup;        \
  |  |  |  |   45|   262k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1664|   262k|    MPI_ECP_MUL(&tmp[3],  &tmp[3],  &P->Y);
  ------------------
  |  | 1167|   262k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|   262k|    do                           \
  |  |  |  |   42|   262k|    {                            \
  |  |  |  |   43|   262k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 262k]
  |  |  |  |  ------------------
  |  |  |  |   44|   262k|        goto cleanup;        \
  |  |  |  |   45|   262k|    } 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|   262k|    MPI_ECP_SUB(Y,     &tmp[2],     &tmp[3]);
  ------------------
  |  | 1164|   262k|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|   262k|    do                           \
  |  |  |  |   42|   262k|    {                            \
  |  |  |  |   43|   262k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 262k]
  |  |  |  |  ------------------
  |  |  |  |   44|   262k|        goto cleanup;        \
  |  |  |  |   45|   262k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1667|       |
 1668|   262k|cleanup:
 1669|       |
 1670|   262k|    return ret;
 1671|   262k|#endif /* !defined(MBEDTLS_ECP_NO_FALLBACK) || !defined(MBEDTLS_ECP_ADD_MIXED_ALT) */
 1672|   262k|}
ecp.c:ecp_normalize_jac:
 1315|  6.33k|{
 1316|  6.33k|    if (MPI_ECP_CMP_INT(&pt->Z, 0) == 0) {
  ------------------
  |  | 1188|  6.33k|    mbedtls_mpi_cmp_int(X, c)
  ------------------
  |  Branch (1316:9): [True: 0, False: 6.33k]
  ------------------
 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|  6.33k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  6.33k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1330|  6.33k|    mbedtls_mpi T;
 1331|  6.33k|    mbedtls_mpi_init(&T);
 1332|       |
 1333|  6.33k|    MPI_ECP_INV(&T,       &pt->Z);            /* T   <-          1 / Z   */
  ------------------
  |  | 1176|  6.33k|    MBEDTLS_MPI_CHK(mbedtls_mpi_inv_mod((dst), (src), &grp->P))
  |  |  ------------------
  |  |  |  |   41|  6.33k|    do                           \
  |  |  |  |   42|  6.33k|    {                            \
  |  |  |  |   43|  6.33k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 6.33k]
  |  |  |  |  ------------------
  |  |  |  |   44|  6.33k|        goto cleanup;        \
  |  |  |  |   45|  6.33k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1334|  6.33k|    MPI_ECP_MUL(&pt->Y,   &pt->Y,     &T);    /* Y'  <- Y*T    = Y / Z   */
  ------------------
  |  | 1167|  6.33k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  6.33k|    do                           \
  |  |  |  |   42|  6.33k|    {                            \
  |  |  |  |   43|  6.33k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 6.33k]
  |  |  |  |  ------------------
  |  |  |  |   44|  6.33k|        goto cleanup;        \
  |  |  |  |   45|  6.33k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1335|  6.33k|    MPI_ECP_SQR(&T,       &T);                /* T   <- T^2    = 1 / Z^2 */
  ------------------
  |  | 1170|  6.33k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, A))
  |  |  ------------------
  |  |  |  |   41|  6.33k|    do                           \
  |  |  |  |   42|  6.33k|    {                            \
  |  |  |  |   43|  6.33k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 6.33k]
  |  |  |  |  ------------------
  |  |  |  |   44|  6.33k|        goto cleanup;        \
  |  |  |  |   45|  6.33k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1336|  6.33k|    MPI_ECP_MUL(&pt->X,   &pt->X,     &T);    /* X   <- X  * T = X / Z^2 */
  ------------------
  |  | 1167|  6.33k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  6.33k|    do                           \
  |  |  |  |   42|  6.33k|    {                            \
  |  |  |  |   43|  6.33k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 6.33k]
  |  |  |  |  ------------------
  |  |  |  |   44|  6.33k|        goto cleanup;        \
  |  |  |  |   45|  6.33k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1337|  6.33k|    MPI_ECP_MUL(&pt->Y,   &pt->Y,     &T);    /* Y'' <- Y' * T = Y / Z^3 */
  ------------------
  |  | 1167|  6.33k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|  6.33k|    do                           \
  |  |  |  |   42|  6.33k|    {                            \
  |  |  |  |   43|  6.33k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 6.33k]
  |  |  |  |  ------------------
  |  |  |  |   44|  6.33k|        goto cleanup;        \
  |  |  |  |   45|  6.33k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1338|       |
 1339|  6.33k|    MPI_ECP_LSET(&pt->Z, 1);
  ------------------
  |  | 1185|  6.33k|    MBEDTLS_MPI_CHK(mbedtls_mpi_lset(X, c))
  |  |  ------------------
  |  |  |  |   41|  6.33k|    do                           \
  |  |  |  |   42|  6.33k|    {                            \
  |  |  |  |   43|  6.33k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 6.33k]
  |  |  |  |  ------------------
  |  |  |  |   44|  6.33k|        goto cleanup;        \
  |  |  |  |   45|  6.33k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1340|       |
 1341|  6.33k|cleanup:
 1342|       |
 1343|  6.33k|    mbedtls_mpi_free(&T);
 1344|       |
 1345|  6.33k|    return ret;
 1346|  6.33k|#endif /* !defined(MBEDTLS_ECP_NO_FALLBACK) || !defined(MBEDTLS_ECP_NORMALIZE_JAC_ALT) */
 1347|  6.33k|}
ecp.c:mpi_free_many:
  325|  12.6k|{
  326|  67.5k|    while (size--) {
  ------------------
  |  Branch (326:12): [True: 54.9k, False: 12.6k]
  ------------------
  327|  54.9k|        mbedtls_mpi_free(arr++);
  328|  54.9k|    }
  329|  12.6k|}
ecp.c:ecp_check_pubkey_sw:
 2726|  21.1k|{
 2727|  21.1k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  21.1k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 2728|  21.1k|    mbedtls_mpi YY, RHS;
 2729|       |
 2730|       |    /* pt coordinates must be normalized for our checks */
 2731|  21.1k|    if (mbedtls_mpi_cmp_int(&pt->X, 0) < 0 ||
  ------------------
  |  Branch (2731:9): [True: 0, False: 21.1k]
  ------------------
 2732|  21.1k|        mbedtls_mpi_cmp_int(&pt->Y, 0) < 0 ||
  ------------------
  |  Branch (2732:9): [True: 0, False: 21.1k]
  ------------------
 2733|  21.1k|        mbedtls_mpi_cmp_mpi(&pt->X, &grp->P) >= 0 ||
  ------------------
  |  Branch (2733:9): [True: 0, False: 21.1k]
  ------------------
 2734|  21.1k|        mbedtls_mpi_cmp_mpi(&pt->Y, &grp->P) >= 0) {
  ------------------
  |  Branch (2734:9): [True: 0, False: 21.1k]
  ------------------
 2735|      0|        return MBEDTLS_ERR_ECP_INVALID_KEY;
  ------------------
  |  |   47|      0|#define MBEDTLS_ERR_ECP_INVALID_KEY                       -0x4C80
  ------------------
 2736|      0|    }
 2737|       |
 2738|  21.1k|    mbedtls_mpi_init(&YY); mbedtls_mpi_init(&RHS);
 2739|       |
 2740|       |    /*
 2741|       |     * YY = Y^2
 2742|       |     * RHS = X^3 + A X + B
 2743|       |     */
 2744|  21.1k|    MPI_ECP_SQR(&YY,  &pt->Y);
  ------------------
  |  | 1170|  21.1k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, A))
  |  |  ------------------
  |  |  |  |   41|  21.1k|    do                           \
  |  |  |  |   42|  21.1k|    {                            \
  |  |  |  |   43|  21.1k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 21.1k]
  |  |  |  |  ------------------
  |  |  |  |   44|  21.1k|        goto cleanup;        \
  |  |  |  |   45|  21.1k|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2745|  21.1k|    MBEDTLS_MPI_CHK(ecp_sw_rhs(grp, &RHS, &pt->X));
  ------------------
  |  |   41|  21.1k|    do                           \
  |  |   42|  21.1k|    {                            \
  |  |   43|  21.1k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 21.1k]
  |  |  ------------------
  |  |   44|  21.1k|        goto cleanup;        \
  |  |   45|  21.1k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2746|       |
 2747|  21.1k|    if (MPI_ECP_CMP(&YY, &RHS) != 0) {
  ------------------
  |  | 1191|  21.1k|    mbedtls_mpi_cmp_mpi(X, Y)
  ------------------
  |  Branch (2747:9): [True: 0, False: 21.1k]
  ------------------
 2748|      0|        ret = MBEDTLS_ERR_ECP_INVALID_KEY;
  ------------------
  |  |   47|      0|#define MBEDTLS_ERR_ECP_INVALID_KEY                       -0x4C80
  ------------------
 2749|      0|    }
 2750|       |
 2751|  21.1k|cleanup:
 2752|       |
 2753|  21.1k|    mbedtls_mpi_free(&YY); mbedtls_mpi_free(&RHS);
 2754|       |
 2755|  21.1k|    return ret;
 2756|  21.1k|}
ecp.c:mbedtls_ecp_gen_privkey_sw:
 3123|      6|{
 3124|      6|    int ret = mbedtls_mpi_random(d, 1, N, f_rng, p_rng);
 3125|      6|    switch (ret) {
 3126|      0|        case MBEDTLS_ERR_MPI_NOT_ACCEPTABLE:
  ------------------
  |  |   36|      0|#define MBEDTLS_ERR_MPI_NOT_ACCEPTABLE                    -0x000E
  ------------------
  |  Branch (3126:9): [True: 0, False: 6]
  ------------------
 3127|      0|            return MBEDTLS_ERR_ECP_RANDOM_FAILED;
  ------------------
  |  |   45|      0|#define MBEDTLS_ERR_ECP_RANDOM_FAILED                     -0x4D00
  ------------------
 3128|      6|        default:
  ------------------
  |  Branch (3128:9): [True: 6, False: 0]
  ------------------
 3129|      6|            return ret;
 3130|      6|    }
 3131|      6|}

mbedtls_ecp_group_load:
 4718|  17.9k|{
 4719|  17.9k|    mbedtls_ecp_group_free(grp);
 4720|       |
 4721|  17.9k|    mbedtls_ecp_group_init(grp);
 4722|       |
 4723|  17.9k|    grp->id = id;
 4724|       |
 4725|  17.9k|    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|  17.9k|        case MBEDTLS_ECP_DP_SECP256R1:
  ------------------
  |  Branch (4739:9): [True: 17.9k, False: 0]
  ------------------
 4740|  17.9k|            NIST_MODP(p256);
  ------------------
  |  | 4567|  17.9k|#define NIST_MODP(P)      grp->modp = ecp_mod_ ## P;
  ------------------
 4741|  17.9k|            return LOAD_GROUP(secp256r1);
  ------------------
  |  | 4600|  17.9k|#define LOAD_GROUP(G)     ecp_group_load(grp,            \
  |  | 4601|  17.9k|                                         G ## _p,  sizeof(G ## _p),   \
  |  | 4602|  17.9k|                                         NULL,     0,                    \
  |  | 4603|  17.9k|                                         G ## _b,  sizeof(G ## _b),   \
  |  | 4604|  17.9k|                                         G ## _gx, sizeof(G ## _gx),   \
  |  | 4605|  17.9k|                                         G ## _gy, sizeof(G ## _gy),   \
  |  | 4606|  17.9k|                                         G ## _n,  sizeof(G ## _n),   \
  |  | 4607|  17.9k|                                         G ## _T                         \
  |  | 4608|  17.9k|                                         )
  ------------------
 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: 17.9k]
  ------------------
 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: 17.9k]
  ------------------
 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: 17.9k]
  ------------------
 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: 17.9k]
  ------------------
 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: 17.9k]
  ------------------
 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|  17.9k|    }
 4805|  17.9k|}
ecp_curves.c:ecp_group_load:
 4522|  17.9k|{
 4523|  17.9k|    ecp_mpi_load(&grp->P, p, plen);
 4524|  17.9k|    if (a != NULL) {
  ------------------
  |  Branch (4524:9): [True: 0, False: 17.9k]
  ------------------
 4525|      0|        ecp_mpi_load(&grp->A, a, alen);
 4526|      0|    }
 4527|  17.9k|    ecp_mpi_load(&grp->B, b, blen);
 4528|  17.9k|    ecp_mpi_load(&grp->N, n, nlen);
 4529|       |
 4530|  17.9k|    ecp_mpi_load(&grp->G.X, gx, gxlen);
 4531|  17.9k|    ecp_mpi_load(&grp->G.Y, gy, gylen);
 4532|  17.9k|    ecp_mpi_set1(&grp->G.Z);
 4533|       |
 4534|  17.9k|    grp->pbits = mbedtls_mpi_bitlen(&grp->P);
 4535|  17.9k|    grp->nbits = mbedtls_mpi_bitlen(&grp->N);
 4536|       |
 4537|  17.9k|    grp->h = 1;
 4538|       |
 4539|  17.9k|    grp->T = (mbedtls_ecp_point *) T;
 4540|       |    /*
 4541|       |     * Set T_size to 0 to prevent T free by mbedtls_ecp_group_free.
 4542|       |     */
 4543|  17.9k|    grp->T_size = 0;
 4544|       |
 4545|  17.9k|    return 0;
 4546|  17.9k|}
ecp_curves.c:ecp_mpi_load:
 4495|  89.8k|{
 4496|  89.8k|    X->s = 1;
 4497|  89.8k|    X->n = (unsigned short) (len / sizeof(mbedtls_mpi_uint));
 4498|  89.8k|    X->p = (mbedtls_mpi_uint *) p;
 4499|  89.8k|}
ecp_curves.c:ecp_mpi_set1:
 4505|  17.9k|{
 4506|  17.9k|    X->s = 1;
 4507|  17.9k|    X->n = 1;
 4508|  17.9k|    X->p = (mbedtls_mpi_uint *) mpi_one; /* X->p will not be modified so the cast is safe */
 4509|  17.9k|}
ecp_curves.c:ecp_mod_p256:
 5037|  8.31M|{
 5038|  8.31M|    INIT(256);
  ------------------
  |  | 4954|  8.31M|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;                    \
  |  |  ------------------
  |  |  |  |  100|  8.31M|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  |  |  ------------------
  |  | 4955|  8.31M|    signed char c = 0, cc;                                              \
  |  | 4956|  8.31M|    uint32_t cur;                                                       \
  |  | 4957|  8.31M|    size_t i = 0, bits = (b);                                           \
  |  | 4958|  8.31M|    /* N is the size of the product of two b-bit numbers, plus one */   \
  |  | 4959|  8.31M|    /* limb for fix_negative */                                         \
  |  | 4960|  8.31M|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(N, (b) * 2 / biL + 1));      \
  |  |  ------------------
  |  |  |  |   41|  8.31M|    do                           \
  |  |  |  |   42|  8.31M|    {                            \
  |  |  |  |   43|  8.31M|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 8.31M]
  |  |  |  |  ------------------
  |  |  |  |   44|  8.31M|        goto cleanup;        \
  |  |  |  |   45|  8.31M|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 4961|  8.31M|    LOAD32;
  |  |  ------------------
  |  |  |  | 4908|  8.31M|#define LOAD32      cur = A(i);
  |  |  |  |  ------------------
  |  |  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (4919:14): [True: 0, False: 8.31M]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5039|       |
 5040|  8.31M|    ADD(8); ADD(9);
  ------------------
  |  | 4947|  8.31M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(8); ADD(9);
  ------------------
  |  | 4947|  8.31M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
 5041|  8.31M|    SUB(11); SUB(12); SUB(13); SUB(14);             NEXT;         // A0
  ------------------
  |  | 4948|  8.31M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(11); SUB(12); SUB(13); SUB(14);             NEXT;         // A0
  ------------------
  |  | 4948|  8.31M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(11); SUB(12); SUB(13); SUB(14);             NEXT;         // A0
  ------------------
  |  | 4948|  8.31M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(11); SUB(12); SUB(13); SUB(14);             NEXT;         // A0
  ------------------
  |  | 4948|  8.31M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(11); SUB(12); SUB(13); SUB(14);             NEXT;         // A0
  ------------------
  |  | 4964|  8.31M|    STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4922|  8.31M|    if (i % 2) {                                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4922:9): [True: 0, False: 8.31M]
  |  |  |  |  ------------------
  |  |  |  | 4923|      0|        N->p[i/2] &= 0x00000000FFFFFFFF;          \
  |  |  |  | 4924|      0|        N->p[i/2] |= ((mbedtls_mpi_uint) cur) << 32;        \
  |  |  |  | 4925|  8.31M|    } else {                                      \
  |  |  |  | 4926|  8.31M|        N->p[i/2] &= 0xFFFFFFFF00000000;          \
  |  |  |  | 4927|  8.31M|        N->p[i/2] |= (mbedtls_mpi_uint) cur;                \
  |  |  |  | 4928|  8.31M|    }
  |  |  ------------------
  |  |                   STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4908|  8.31M|#define LOAD32      cur = A(i);
  |  |  |  |  ------------------
  |  |  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (4919:14): [True: 8.31M, False: 0]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 4965|  8.31M|    cc = c; c = 0;              \
  |  | 4966|  8.31M|    if (cc < 0)                \
  |  |  ------------------
  |  |  |  Branch (4966:9): [True: 6.18M, False: 2.12M]
  |  |  ------------------
  |  | 4967|  8.31M|    sub32(&cur, -cc, &c); \
  |  | 4968|  8.31M|    else                        \
  |  | 4969|  8.31M|    add32(&cur, cc, &c);  \
  ------------------
 5042|       |
 5043|  8.31M|    ADD(9); ADD(10);
  ------------------
  |  | 4947|  8.31M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(9); ADD(10);
  ------------------
  |  | 4947|  8.31M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
 5044|  8.31M|    SUB(12); SUB(13); SUB(14); SUB(15);             NEXT;         // A1
  ------------------
  |  | 4948|  8.31M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(12); SUB(13); SUB(14); SUB(15);             NEXT;         // A1
  ------------------
  |  | 4948|  8.31M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(12); SUB(13); SUB(14); SUB(15);             NEXT;         // A1
  ------------------
  |  | 4948|  8.31M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(12); SUB(13); SUB(14); SUB(15);             NEXT;         // A1
  ------------------
  |  | 4948|  8.31M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(12); SUB(13); SUB(14); SUB(15);             NEXT;         // A1
  ------------------
  |  | 4964|  8.31M|    STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4922|  8.31M|    if (i % 2) {                                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4922:9): [True: 8.31M, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 4923|  8.31M|        N->p[i/2] &= 0x00000000FFFFFFFF;          \
  |  |  |  | 4924|  8.31M|        N->p[i/2] |= ((mbedtls_mpi_uint) cur) << 32;        \
  |  |  |  | 4925|  8.31M|    } else {                                      \
  |  |  |  | 4926|      0|        N->p[i/2] &= 0xFFFFFFFF00000000;          \
  |  |  |  | 4927|      0|        N->p[i/2] |= (mbedtls_mpi_uint) cur;                \
  |  |  |  | 4928|      0|    }
  |  |  ------------------
  |  |                   STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4908|  8.31M|#define LOAD32      cur = A(i);
  |  |  |  |  ------------------
  |  |  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (4919:14): [True: 0, False: 8.31M]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 4965|  8.31M|    cc = c; c = 0;              \
  |  | 4966|  8.31M|    if (cc < 0)                \
  |  |  ------------------
  |  |  |  Branch (4966:9): [True: 5.30M, False: 3.00M]
  |  |  ------------------
  |  | 4967|  8.31M|    sub32(&cur, -cc, &c); \
  |  | 4968|  8.31M|    else                        \
  |  | 4969|  8.31M|    add32(&cur, cc, &c);  \
  ------------------
 5045|       |
 5046|  8.31M|    ADD(10); ADD(11);
  ------------------
  |  | 4947|  8.31M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(10); ADD(11);
  ------------------
  |  | 4947|  8.31M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
 5047|  8.31M|    SUB(13); SUB(14); SUB(15);                        NEXT;       // A2
  ------------------
  |  | 4948|  8.31M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(13); SUB(14); SUB(15);                        NEXT;       // A2
  ------------------
  |  | 4948|  8.31M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(13); SUB(14); SUB(15);                        NEXT;       // A2
  ------------------
  |  | 4948|  8.31M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(13); SUB(14); SUB(15);                        NEXT;       // A2
  ------------------
  |  | 4964|  8.31M|    STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4922|  8.31M|    if (i % 2) {                                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4922:9): [True: 0, False: 8.31M]
  |  |  |  |  ------------------
  |  |  |  | 4923|      0|        N->p[i/2] &= 0x00000000FFFFFFFF;          \
  |  |  |  | 4924|      0|        N->p[i/2] |= ((mbedtls_mpi_uint) cur) << 32;        \
  |  |  |  | 4925|  8.31M|    } else {                                      \
  |  |  |  | 4926|  8.31M|        N->p[i/2] &= 0xFFFFFFFF00000000;          \
  |  |  |  | 4927|  8.31M|        N->p[i/2] |= (mbedtls_mpi_uint) cur;                \
  |  |  |  | 4928|  8.31M|    }
  |  |  ------------------
  |  |                   STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4908|  8.31M|#define LOAD32      cur = A(i);
  |  |  |  |  ------------------
  |  |  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (4919:14): [True: 8.31M, False: 0]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 4965|  8.31M|    cc = c; c = 0;              \
  |  | 4966|  8.31M|    if (cc < 0)                \
  |  |  ------------------
  |  |  |  Branch (4966:9): [True: 3.22M, False: 5.08M]
  |  |  ------------------
  |  | 4967|  8.31M|    sub32(&cur, -cc, &c); \
  |  | 4968|  8.31M|    else                        \
  |  | 4969|  8.31M|    add32(&cur, cc, &c);  \
  ------------------
 5048|       |
 5049|  8.31M|    ADD(11); ADD(11); ADD(12); ADD(12); ADD(13);
  ------------------
  |  | 4947|  8.31M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(11); ADD(11); ADD(12); ADD(12); ADD(13);
  ------------------
  |  | 4947|  8.31M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(11); ADD(11); ADD(12); ADD(12); ADD(13);
  ------------------
  |  | 4947|  8.31M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(11); ADD(11); ADD(12); ADD(12); ADD(13);
  ------------------
  |  | 4947|  8.31M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(11); ADD(11); ADD(12); ADD(12); ADD(13);
  ------------------
  |  | 4947|  8.31M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
 5050|  8.31M|    SUB(15); SUB(8); SUB(9);                        NEXT;         // A3
  ------------------
  |  | 4948|  8.31M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(15); SUB(8); SUB(9);                        NEXT;         // A3
  ------------------
  |  | 4948|  8.31M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(15); SUB(8); SUB(9);                        NEXT;         // A3
  ------------------
  |  | 4948|  8.31M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(15); SUB(8); SUB(9);                        NEXT;         // A3
  ------------------
  |  | 4964|  8.31M|    STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4922|  8.31M|    if (i % 2) {                                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4922:9): [True: 8.31M, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 4923|  8.31M|        N->p[i/2] &= 0x00000000FFFFFFFF;          \
  |  |  |  | 4924|  8.31M|        N->p[i/2] |= ((mbedtls_mpi_uint) cur) << 32;        \
  |  |  |  | 4925|  8.31M|    } else {                                      \
  |  |  |  | 4926|      0|        N->p[i/2] &= 0xFFFFFFFF00000000;          \
  |  |  |  | 4927|      0|        N->p[i/2] |= (mbedtls_mpi_uint) cur;                \
  |  |  |  | 4928|      0|    }
  |  |  ------------------
  |  |                   STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4908|  8.31M|#define LOAD32      cur = A(i);
  |  |  |  |  ------------------
  |  |  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (4919:14): [True: 0, False: 8.31M]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 4965|  8.31M|    cc = c; c = 0;              \
  |  | 4966|  8.31M|    if (cc < 0)                \
  |  |  ------------------
  |  |  |  Branch (4966:9): [True: 411k, False: 7.89M]
  |  |  ------------------
  |  | 4967|  8.31M|    sub32(&cur, -cc, &c); \
  |  | 4968|  8.31M|    else                        \
  |  | 4969|  8.31M|    add32(&cur, cc, &c);  \
  ------------------
 5051|       |
 5052|  8.31M|    ADD(12); ADD(12); ADD(13); ADD(13); ADD(14);
  ------------------
  |  | 4947|  8.31M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(12); ADD(12); ADD(13); ADD(13); ADD(14);
  ------------------
  |  | 4947|  8.31M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(12); ADD(12); ADD(13); ADD(13); ADD(14);
  ------------------
  |  | 4947|  8.31M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(12); ADD(12); ADD(13); ADD(13); ADD(14);
  ------------------
  |  | 4947|  8.31M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(12); ADD(12); ADD(13); ADD(13); ADD(14);
  ------------------
  |  | 4947|  8.31M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
 5053|  8.31M|    SUB(9); SUB(10);                                   NEXT;      // A4
  ------------------
  |  | 4948|  8.31M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(9); SUB(10);                                   NEXT;      // A4
  ------------------
  |  | 4948|  8.31M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(9); SUB(10);                                   NEXT;      // A4
  ------------------
  |  | 4964|  8.31M|    STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4922|  8.31M|    if (i % 2) {                                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4922:9): [True: 0, False: 8.31M]
  |  |  |  |  ------------------
  |  |  |  | 4923|      0|        N->p[i/2] &= 0x00000000FFFFFFFF;          \
  |  |  |  | 4924|      0|        N->p[i/2] |= ((mbedtls_mpi_uint) cur) << 32;        \
  |  |  |  | 4925|  8.31M|    } else {                                      \
  |  |  |  | 4926|  8.31M|        N->p[i/2] &= 0xFFFFFFFF00000000;          \
  |  |  |  | 4927|  8.31M|        N->p[i/2] |= (mbedtls_mpi_uint) cur;                \
  |  |  |  | 4928|  8.31M|    }
  |  |  ------------------
  |  |                   STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4908|  8.31M|#define LOAD32      cur = A(i);
  |  |  |  |  ------------------
  |  |  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (4919:14): [True: 8.31M, False: 0]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 4965|  8.31M|    cc = c; c = 0;              \
  |  | 4966|  8.31M|    if (cc < 0)                \
  |  |  ------------------
  |  |  |  Branch (4966:9): [True: 169k, False: 8.14M]
  |  |  ------------------
  |  | 4967|  8.31M|    sub32(&cur, -cc, &c); \
  |  | 4968|  8.31M|    else                        \
  |  | 4969|  8.31M|    add32(&cur, cc, &c);  \
  ------------------
 5054|       |
 5055|  8.31M|    ADD(13); ADD(13); ADD(14); ADD(14); ADD(15);
  ------------------
  |  | 4947|  8.31M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(13); ADD(13); ADD(14); ADD(14); ADD(15);
  ------------------
  |  | 4947|  8.31M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(13); ADD(13); ADD(14); ADD(14); ADD(15);
  ------------------
  |  | 4947|  8.31M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(13); ADD(13); ADD(14); ADD(14); ADD(15);
  ------------------
  |  | 4947|  8.31M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(13); ADD(13); ADD(14); ADD(14); ADD(15);
  ------------------
  |  | 4947|  8.31M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
 5056|  8.31M|    SUB(10); SUB(11);                                   NEXT;     // A5
  ------------------
  |  | 4948|  8.31M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(10); SUB(11);                                   NEXT;     // A5
  ------------------
  |  | 4948|  8.31M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(10); SUB(11);                                   NEXT;     // A5
  ------------------
  |  | 4964|  8.31M|    STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4922|  8.31M|    if (i % 2) {                                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4922:9): [True: 8.31M, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 4923|  8.31M|        N->p[i/2] &= 0x00000000FFFFFFFF;          \
  |  |  |  | 4924|  8.31M|        N->p[i/2] |= ((mbedtls_mpi_uint) cur) << 32;        \
  |  |  |  | 4925|  8.31M|    } else {                                      \
  |  |  |  | 4926|      0|        N->p[i/2] &= 0xFFFFFFFF00000000;          \
  |  |  |  | 4927|      0|        N->p[i/2] |= (mbedtls_mpi_uint) cur;                \
  |  |  |  | 4928|      0|    }
  |  |  ------------------
  |  |                   STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4908|  8.31M|#define LOAD32      cur = A(i);
  |  |  |  |  ------------------
  |  |  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (4919:14): [True: 0, False: 8.31M]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 4965|  8.31M|    cc = c; c = 0;              \
  |  | 4966|  8.31M|    if (cc < 0)                \
  |  |  ------------------
  |  |  |  Branch (4966:9): [True: 285k, False: 8.02M]
  |  |  ------------------
  |  | 4967|  8.31M|    sub32(&cur, -cc, &c); \
  |  | 4968|  8.31M|    else                        \
  |  | 4969|  8.31M|    add32(&cur, cc, &c);  \
  ------------------
 5057|       |
 5058|  8.31M|    ADD(14); ADD(14); ADD(15); ADD(15); ADD(14); ADD(13);
  ------------------
  |  | 4947|  8.31M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(14); ADD(14); ADD(15); ADD(15); ADD(14); ADD(13);
  ------------------
  |  | 4947|  8.31M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(14); ADD(14); ADD(15); ADD(15); ADD(14); ADD(13);
  ------------------
  |  | 4947|  8.31M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(14); ADD(14); ADD(15); ADD(15); ADD(14); ADD(13);
  ------------------
  |  | 4947|  8.31M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(14); ADD(14); ADD(15); ADD(15); ADD(14); ADD(13);
  ------------------
  |  | 4947|  8.31M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(14); ADD(14); ADD(15); ADD(15); ADD(14); ADD(13);
  ------------------
  |  | 4947|  8.31M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
 5059|  8.31M|    SUB(8); SUB(9);                                   NEXT;       // A6
  ------------------
  |  | 4948|  8.31M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(8); SUB(9);                                   NEXT;       // A6
  ------------------
  |  | 4948|  8.31M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(8); SUB(9);                                   NEXT;       // A6
  ------------------
  |  | 4964|  8.31M|    STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4922|  8.31M|    if (i % 2) {                                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4922:9): [True: 0, False: 8.31M]
  |  |  |  |  ------------------
  |  |  |  | 4923|      0|        N->p[i/2] &= 0x00000000FFFFFFFF;          \
  |  |  |  | 4924|      0|        N->p[i/2] |= ((mbedtls_mpi_uint) cur) << 32;        \
  |  |  |  | 4925|  8.31M|    } else {                                      \
  |  |  |  | 4926|  8.31M|        N->p[i/2] &= 0xFFFFFFFF00000000;          \
  |  |  |  | 4927|  8.31M|        N->p[i/2] |= (mbedtls_mpi_uint) cur;                \
  |  |  |  | 4928|  8.31M|    }
  |  |  ------------------
  |  |                   STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4908|  8.31M|#define LOAD32      cur = A(i);
  |  |  |  |  ------------------
  |  |  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (4919:14): [True: 8.31M, False: 0]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 4965|  8.31M|    cc = c; c = 0;              \
  |  | 4966|  8.31M|    if (cc < 0)                \
  |  |  ------------------
  |  |  |  Branch (4966:9): [True: 246k, False: 8.06M]
  |  |  ------------------
  |  | 4967|  8.31M|    sub32(&cur, -cc, &c); \
  |  | 4968|  8.31M|    else                        \
  |  | 4969|  8.31M|    add32(&cur, cc, &c);  \
  ------------------
 5060|       |
 5061|  8.31M|    ADD(15); ADD(15); ADD(15); ADD(8);
  ------------------
  |  | 4947|  8.31M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(15); ADD(15); ADD(15); ADD(8);
  ------------------
  |  | 4947|  8.31M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(15); ADD(15); ADD(15); ADD(8);
  ------------------
  |  | 4947|  8.31M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(15); ADD(15); ADD(15); ADD(8);
  ------------------
  |  | 4947|  8.31M|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
 5062|  8.31M|    SUB(10); SUB(11); SUB(12); SUB(13);             LAST;         // A7
  ------------------
  |  | 4948|  8.31M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(10); SUB(11); SUB(12); SUB(13);             LAST;         // A7
  ------------------
  |  | 4948|  8.31M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(10); SUB(11); SUB(12); SUB(13);             LAST;         // A7
  ------------------
  |  | 4948|  8.31M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(10); SUB(11); SUB(12); SUB(13);             LAST;         // A7
  ------------------
  |  | 4948|  8.31M|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|  8.31M|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|  8.31M|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(10); SUB(11); SUB(12); SUB(13);             LAST;         // A7
  ------------------
  |  | 4972|  8.31M|    STORE32; i++;                               \
  |  |  ------------------
  |  |  |  | 4922|  8.31M|    if (i % 2) {                                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4922:9): [True: 8.31M, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 4923|  8.31M|        N->p[i/2] &= 0x00000000FFFFFFFF;          \
  |  |  |  | 4924|  8.31M|        N->p[i/2] |= ((mbedtls_mpi_uint) cur) << 32;        \
  |  |  |  | 4925|  8.31M|    } else {                                      \
  |  |  |  | 4926|      0|        N->p[i/2] &= 0xFFFFFFFF00000000;          \
  |  |  |  | 4927|      0|        N->p[i/2] |= (mbedtls_mpi_uint) cur;                \
  |  |  |  | 4928|      0|    }
  |  |  ------------------
  |  | 4973|  8.31M|    cur = c > 0 ? c : 0; STORE32;               \
  |  |  ------------------
  |  |  |  | 4922|  8.31M|    if (i % 2) {                                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4922:9): [True: 0, False: 8.31M]
  |  |  |  |  ------------------
  |  |  |  | 4923|      0|        N->p[i/2] &= 0x00000000FFFFFFFF;          \
  |  |  |  | 4924|      0|        N->p[i/2] |= ((mbedtls_mpi_uint) cur) << 32;        \
  |  |  |  | 4925|  8.31M|    } else {                                      \
  |  |  |  | 4926|  8.31M|        N->p[i/2] &= 0xFFFFFFFF00000000;          \
  |  |  |  | 4927|  8.31M|        N->p[i/2] |= (mbedtls_mpi_uint) cur;                \
  |  |  |  | 4928|  8.31M|    }
  |  |  ------------------
  |  |  |  Branch (4973:11): [True: 1.23M, False: 7.07M]
  |  |  ------------------
  |  | 4974|  83.1M|    cur = 0; while (++i < MAX32) { STORE32; }  \
  |  |  ------------------
  |  |  |  | 4918|  83.1M|#define MAX32       N->n * 2
  |  |  ------------------
  |  |                   cur = 0; while (++i < MAX32) { STORE32; }  \
  |  |  ------------------
  |  |  |  | 4922|  74.8M|    if (i % 2) {                                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4922:9): [True: 41.5M, False: 33.2M]
  |  |  |  |  ------------------
  |  |  |  | 4923|  41.5M|        N->p[i/2] &= 0x00000000FFFFFFFF;          \
  |  |  |  | 4924|  41.5M|        N->p[i/2] |= ((mbedtls_mpi_uint) cur) << 32;        \
  |  |  |  | 4925|  41.5M|    } else {                                      \
  |  |  |  | 4926|  33.2M|        N->p[i/2] &= 0xFFFFFFFF00000000;          \
  |  |  |  | 4927|  33.2M|        N->p[i/2] |= (mbedtls_mpi_uint) cur;                \
  |  |  |  | 4928|  33.2M|    }
  |  |  ------------------
  |  |  |  Branch (4974:21): [True: 74.8M, False: 8.31M]
  |  |  ------------------
  |  | 4975|  8.31M|    if (c < 0) mbedtls_ecp_fix_negative(N, c, bits);
  |  |  ------------------
  |  |  |  Branch (4975:9): [True: 4.76M, False: 3.54M]
  |  |  ------------------
  ------------------
 5063|       |
 5064|  8.31M|cleanup:
 5065|  8.31M|    return ret;
 5066|  8.31M|}
ecp_curves.c:add32:
 4936|   300M|{
 4937|   300M|    *dst += src;
 4938|   300M|    *carry += (*dst < src);
 4939|   300M|}
ecp_curves.c:sub32:
 4942|   215M|{
 4943|   215M|    *carry -= (*dst < src);
 4944|   215M|    *dst -= src;
 4945|   215M|}
ecp_curves.c:mbedtls_ecp_fix_negative:
 4982|  4.76M|{
 4983|  4.76M|    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|  28.5M|    for (i = 0; i <= bits / 8 / sizeof(mbedtls_mpi_uint); i++) {
  ------------------
  |  Branch (4988:17): [True: 23.8M, False: 4.76M]
  ------------------
 4989|  23.8M|        N->p[i] = ~(mbedtls_mpi_uint) 0 - N->p[i];
 4990|  23.8M|    }
 4991|       |    /* Add 1, taking care of the carry. */
 4992|  4.76M|    i = 0;
 4993|  4.76M|    do {
 4994|  4.76M|        ++N->p[i];
 4995|  4.76M|    } while (N->p[i++] == 0 && i <= bits / 8 / sizeof(mbedtls_mpi_uint));
  ------------------
  |  Branch (4995:14): [True: 0, False: 4.76M]
  |  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|  4.76M|    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|  4.76M|    mbedtls_mpi_uint msw = (mbedtls_mpi_uint) -c;
 5003|  4.76M|#if defined(MBEDTLS_HAVE_INT64)
 5004|  4.76M|    if (bits == 224) {
  ------------------
  |  Branch (5004:9): [True: 0, False: 4.76M]
  ------------------
 5005|      0|        msw <<= 32;
 5006|      0|    }
 5007|  4.76M|#endif
 5008|  4.76M|    N->p[bits / 8 / sizeof(mbedtls_mpi_uint)] += msw;
 5009|  4.76M|}

mbedtls_md_info_from_type:
  140|  2.11k|{
  141|  2.11k|    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|  2.11k|        case MBEDTLS_MD_SHA256:
  ------------------
  |  Branch (159:9): [True: 2.11k, False: 0]
  ------------------
  160|  2.11k|            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: 2.11k]
  ------------------
  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: 2.11k]
  ------------------
  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: 2.11k]
  ------------------
  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: 2.11k]
  ------------------
  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: 2.11k]
  ------------------
  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: 2.11k]
  ------------------
  184|      0|            return &mbedtls_sha3_512_info;
  185|      0|#endif
  186|      0|        default:
  ------------------
  |  Branch (186:9): [True: 0, False: 2.11k]
  ------------------
  187|      0|            return NULL;
  188|  2.11k|    }
  189|  2.11k|}
mbedtls_md:
  687|  2.11k|{
  688|  2.11k|    if (md_info == NULL) {
  ------------------
  |  Branch (688:9): [True: 0, False: 2.11k]
  ------------------
  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|  2.11k|    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|  2.11k|        case MBEDTLS_MD_SHA256:
  ------------------
  |  Branch (720:9): [True: 2.11k, False: 0]
  ------------------
  721|  2.11k|            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: 2.11k]
  ------------------
  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: 2.11k]
  ------------------
  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: 2.11k]
  ------------------
  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: 2.11k]
  ------------------
  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: 2.11k]
  ------------------
  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: 2.11k]
  ------------------
  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: 2.11k]
  ------------------
  742|      0|            return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MD_BAD_INPUT_DATA                     -0x5100
  ------------------
  743|  2.11k|    }
  744|  2.11k|}
mbedtls_md_get_size:
  747|  2.11k|{
  748|  2.11k|    if (md_info == NULL) {
  ------------------
  |  Branch (748:9): [True: 0, False: 2.11k]
  ------------------
  749|      0|        return 0;
  750|      0|    }
  751|       |
  752|  2.11k|    return md_info->size;
  753|  2.11k|}

mbedtls_oid_get_x509_ext_type:
   84|  87.6k|    {                                                                       \
   85|  87.6k|        const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1(oid);        \
   86|  87.6k|        if (data == NULL) return MBEDTLS_ERR_OID_NOT_FOUND;            \
  ------------------
  |  |   28|  11.6k|#define MBEDTLS_ERR_OID_NOT_FOUND                         -0x002E
  ------------------
  |  Branch (86:13): [True: 11.6k, False: 76.0k]
  ------------------
   87|  87.6k|        *ATTR1 = data->ATTR1;                                               \
   88|  76.0k|        return 0;                                                        \
   89|  87.6k|    }
mbedtls_oid_get_sig_alg:
   99|  16.8k|    {                                                                           \
  100|  16.8k|        const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1(oid);            \
  101|  16.8k|        if (data == NULL) return MBEDTLS_ERR_OID_NOT_FOUND;                 \
  ------------------
  |  |   28|      0|#define MBEDTLS_ERR_OID_NOT_FOUND                         -0x002E
  ------------------
  |  Branch (101:13): [True: 0, False: 16.8k]
  ------------------
  102|  16.8k|        *(ATTR1) = data->ATTR1;                                                 \
  103|  16.8k|        *(ATTR2) = data->ATTR2;                                                 \
  104|  16.8k|        return 0;                                                            \
  105|  16.8k|    }
mbedtls_oid_get_pk_alg:
   84|  16.8k|    {                                                                       \
   85|  16.8k|        const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1(oid);        \
   86|  16.8k|        if (data == NULL) return MBEDTLS_ERR_OID_NOT_FOUND;            \
  ------------------
  |  |   28|      0|#define MBEDTLS_ERR_OID_NOT_FOUND                         -0x002E
  ------------------
  |  Branch (86:13): [True: 0, False: 16.8k]
  ------------------
   87|  16.8k|        *ATTR1 = data->ATTR1;                                               \
   88|  16.8k|        return 0;                                                        \
   89|  16.8k|    }
mbedtls_oid_get_ec_grp:
   84|  16.8k|    {                                                                       \
   85|  16.8k|        const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1(oid);        \
   86|  16.8k|        if (data == NULL) return MBEDTLS_ERR_OID_NOT_FOUND;            \
  ------------------
  |  |   28|      0|#define MBEDTLS_ERR_OID_NOT_FOUND                         -0x002E
  ------------------
  |  Branch (86:13): [True: 0, False: 16.8k]
  ------------------
   87|  16.8k|        *ATTR1 = data->ATTR1;                                               \
   88|  16.8k|        return 0;                                                        \
   89|  16.8k|    }
oid.c:oid_x509_ext_from_asn1:
   47|  87.6k|    {                                                                   \
   48|  87.6k|        const TYPE_T *p = (LIST);                                       \
   49|  87.6k|        const mbedtls_oid_descriptor_t *cur =                           \
   50|  87.6k|            (const mbedtls_oid_descriptor_t *) p;                       \
   51|  87.6k|        if (p == NULL || oid == NULL) return NULL;                  \
  ------------------
  |  Branch (51:13): [True: 0, False: 87.6k]
  |  Branch (51:26): [True: 0, False: 87.6k]
  ------------------
   52|   380k|        while (cur->asn1 != NULL) {                                    \
  ------------------
  |  Branch (52:16): [True: 368k, False: 11.6k]
  ------------------
   53|   368k|            if (cur->asn1_len == oid->len &&                            \
  ------------------
  |  Branch (53:17): [True: 255k, False: 112k]
  ------------------
   54|   368k|                memcmp(cur->asn1, oid->p, oid->len) == 0) {          \
  ------------------
  |  Branch (54:17): [True: 76.0k, False: 179k]
  ------------------
   55|  76.0k|                return p;                                            \
   56|  76.0k|            }                                                           \
   57|   368k|            p++;                                                        \
   58|   292k|            cur = (const mbedtls_oid_descriptor_t *) p;                 \
   59|   292k|        }                                                               \
   60|  87.6k|        return NULL;                                                 \
   61|  87.6k|    }
oid.c:oid_sig_alg_from_asn1:
   47|  16.8k|    {                                                                   \
   48|  16.8k|        const TYPE_T *p = (LIST);                                       \
   49|  16.8k|        const mbedtls_oid_descriptor_t *cur =                           \
   50|  16.8k|            (const mbedtls_oid_descriptor_t *) p;                       \
   51|  16.8k|        if (p == NULL || oid == NULL) return NULL;                  \
  ------------------
  |  Branch (51:13): [True: 0, False: 16.8k]
  |  Branch (51:26): [True: 0, False: 16.8k]
  ------------------
   52|  67.5k|        while (cur->asn1 != NULL) {                                    \
  ------------------
  |  Branch (52:16): [True: 67.5k, False: 0]
  ------------------
   53|  67.5k|            if (cur->asn1_len == oid->len &&                            \
  ------------------
  |  Branch (53:17): [True: 16.8k, False: 50.6k]
  ------------------
   54|  67.5k|                memcmp(cur->asn1, oid->p, oid->len) == 0) {          \
  ------------------
  |  Branch (54:17): [True: 16.8k, False: 0]
  ------------------
   55|  16.8k|                return p;                                            \
   56|  16.8k|            }                                                           \
   57|  67.5k|            p++;                                                        \
   58|  50.6k|            cur = (const mbedtls_oid_descriptor_t *) p;                 \
   59|  50.6k|        }                                                               \
   60|  16.8k|        return NULL;                                                 \
   61|  16.8k|    }
oid.c:oid_pk_alg_from_asn1:
   47|  16.8k|    {                                                                   \
   48|  16.8k|        const TYPE_T *p = (LIST);                                       \
   49|  16.8k|        const mbedtls_oid_descriptor_t *cur =                           \
   50|  16.8k|            (const mbedtls_oid_descriptor_t *) p;                       \
   51|  16.8k|        if (p == NULL || oid == NULL) return NULL;                  \
  ------------------
  |  Branch (51:13): [True: 0, False: 16.8k]
  |  Branch (51:26): [True: 0, False: 16.8k]
  ------------------
   52|  33.7k|        while (cur->asn1 != NULL) {                                    \
  ------------------
  |  Branch (52:16): [True: 33.7k, False: 0]
  ------------------
   53|  33.7k|            if (cur->asn1_len == oid->len &&                            \
  ------------------
  |  Branch (53:17): [True: 16.8k, False: 16.8k]
  ------------------
   54|  33.7k|                memcmp(cur->asn1, oid->p, oid->len) == 0) {          \
  ------------------
  |  Branch (54:17): [True: 16.8k, False: 0]
  ------------------
   55|  16.8k|                return p;                                            \
   56|  16.8k|            }                                                           \
   57|  33.7k|            p++;                                                        \
   58|  16.8k|            cur = (const mbedtls_oid_descriptor_t *) p;                 \
   59|  16.8k|        }                                                               \
   60|  16.8k|        return NULL;                                                 \
   61|  16.8k|    }
oid.c:oid_grp_id_from_asn1:
   47|  16.8k|    {                                                                   \
   48|  16.8k|        const TYPE_T *p = (LIST);                                       \
   49|  16.8k|        const mbedtls_oid_descriptor_t *cur =                           \
   50|  16.8k|            (const mbedtls_oid_descriptor_t *) p;                       \
   51|  16.8k|        if (p == NULL || oid == NULL) return NULL;                  \
  ------------------
  |  Branch (51:13): [True: 0, False: 16.8k]
  |  Branch (51:26): [True: 0, False: 16.8k]
  ------------------
   52|  50.6k|        while (cur->asn1 != NULL) {                                    \
  ------------------
  |  Branch (52:16): [True: 50.6k, False: 0]
  ------------------
   53|  50.6k|            if (cur->asn1_len == oid->len &&                            \
  ------------------
  |  Branch (53:17): [True: 33.7k, False: 16.8k]
  ------------------
   54|  50.6k|                memcmp(cur->asn1, oid->p, oid->len) == 0) {          \
  ------------------
  |  Branch (54:17): [True: 16.8k, False: 16.8k]
  ------------------
   55|  16.8k|                return p;                                            \
   56|  16.8k|            }                                                           \
   57|  50.6k|            p++;                                                        \
   58|  33.7k|            cur = (const mbedtls_oid_descriptor_t *) p;                 \
   59|  33.7k|        }                                                               \
   60|  16.8k|        return NULL;                                                 \
   61|  16.8k|    }

mbedtls_pem_init:
   39|      3|{
   40|      3|    memset(ctx, 0, sizeof(mbedtls_pem_context));
   41|      3|}
mbedtls_pem_read_buffer:
  271|      9|{
  272|      9|    int ret, enc;
  273|      9|    size_t len;
  274|      9|    unsigned char *buf;
  275|      9|    const unsigned char *s1, *s2, *end;
  276|       |#if defined(PEM_RFC1421)
  277|       |    unsigned char pem_iv[16];
  278|       |    mbedtls_cipher_type_t enc_alg = MBEDTLS_CIPHER_NONE;
  279|       |#else
  280|      9|    ((void) pwd);
  281|      9|    ((void) pwdlen);
  282|      9|#endif /* PEM_RFC1421 */
  283|       |
  284|      9|    if (ctx == NULL) {
  ------------------
  |  Branch (284:9): [True: 0, False: 9]
  ------------------
  285|      0|        return MBEDTLS_ERR_PEM_BAD_INPUT_DATA;
  ------------------
  |  |   41|      0|#define MBEDTLS_ERR_PEM_BAD_INPUT_DATA                    -0x1480
  ------------------
  286|      0|    }
  287|       |
  288|      9|    s1 = (unsigned char *) strstr((const char *) data, header);
  289|       |
  290|      9|    if (s1 == NULL) {
  ------------------
  |  Branch (290:9): [True: 6, False: 3]
  ------------------
  291|      6|        return MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT;
  ------------------
  |  |   25|      6|#define MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT          -0x1080
  ------------------
  292|      6|    }
  293|       |
  294|      3|    s2 = (unsigned char *) strstr((const char *) data, footer);
  295|       |
  296|      3|    if (s2 == NULL || s2 <= s1) {
  ------------------
  |  Branch (296:9): [True: 0, False: 3]
  |  Branch (296:23): [True: 0, False: 3]
  ------------------
  297|      0|        return MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT;
  ------------------
  |  |   25|      0|#define MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT          -0x1080
  ------------------
  298|      0|    }
  299|       |
  300|      3|    s1 += strlen(header);
  301|      3|    if (*s1 == ' ') {
  ------------------
  |  Branch (301:9): [True: 0, False: 3]
  ------------------
  302|      0|        s1++;
  303|      0|    }
  304|      3|    if (*s1 == '\r') {
  ------------------
  |  Branch (304:9): [True: 3, False: 0]
  ------------------
  305|      3|        s1++;
  306|      3|    }
  307|      3|    if (*s1 == '\n') {
  ------------------
  |  Branch (307:9): [True: 3, False: 0]
  ------------------
  308|      3|        s1++;
  309|      3|    } else {
  310|      0|        return MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT;
  ------------------
  |  |   25|      0|#define MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT          -0x1080
  ------------------
  311|      0|    }
  312|       |
  313|      3|    end = s2;
  314|      3|    end += strlen(footer);
  315|      3|    if (*end == ' ') {
  ------------------
  |  Branch (315:9): [True: 0, False: 3]
  ------------------
  316|      0|        end++;
  317|      0|    }
  318|      3|    if (*end == '\r') {
  ------------------
  |  Branch (318:9): [True: 3, False: 0]
  ------------------
  319|      3|        end++;
  320|      3|    }
  321|      3|    if (*end == '\n') {
  ------------------
  |  Branch (321:9): [True: 3, False: 0]
  ------------------
  322|      3|        end++;
  323|      3|    }
  324|      3|    *use_len = (size_t) (end - data);
  325|       |
  326|      3|    enc = 0;
  327|       |
  328|      3|    if (s2 - s1 >= 22 && memcmp(s1, "Proc-Type: 4,ENCRYPTED", 22) == 0) {
  ------------------
  |  Branch (328:9): [True: 3, False: 0]
  |  Branch (328:26): [True: 0, False: 3]
  ------------------
  329|       |#if defined(PEM_RFC1421)
  330|       |        enc++;
  331|       |
  332|       |        s1 += 22;
  333|       |        if (*s1 == '\r') {
  334|       |            s1++;
  335|       |        }
  336|       |        if (*s1 == '\n') {
  337|       |            s1++;
  338|       |        } else {
  339|       |            return MBEDTLS_ERR_PEM_INVALID_DATA;
  340|       |        }
  341|       |
  342|       |
  343|       |#if defined(MBEDTLS_DES_C)
  344|       |        if (s2 - s1 >= 23 && memcmp(s1, "DEK-Info: DES-EDE3-CBC,", 23) == 0) {
  345|       |            enc_alg = MBEDTLS_CIPHER_DES_EDE3_CBC;
  346|       |
  347|       |            s1 += 23;
  348|       |            if (s2 - s1 < 16 || pem_get_iv(s1, pem_iv, 8) != 0) {
  349|       |                return MBEDTLS_ERR_PEM_INVALID_ENC_IV;
  350|       |            }
  351|       |
  352|       |            s1 += 16;
  353|       |        } else if (s2 - s1 >= 18 && memcmp(s1, "DEK-Info: DES-CBC,", 18) == 0) {
  354|       |            enc_alg = MBEDTLS_CIPHER_DES_CBC;
  355|       |
  356|       |            s1 += 18;
  357|       |            if (s2 - s1 < 16 || pem_get_iv(s1, pem_iv, 8) != 0) {
  358|       |                return MBEDTLS_ERR_PEM_INVALID_ENC_IV;
  359|       |            }
  360|       |
  361|       |            s1 += 16;
  362|       |        }
  363|       |#endif /* MBEDTLS_DES_C */
  364|       |
  365|       |#if defined(MBEDTLS_AES_C)
  366|       |        if (s2 - s1 >= 14 && memcmp(s1, "DEK-Info: AES-", 14) == 0) {
  367|       |            if (s2 - s1 < 22) {
  368|       |                return MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG;
  369|       |            } else if (memcmp(s1, "DEK-Info: AES-128-CBC,", 22) == 0) {
  370|       |                enc_alg = MBEDTLS_CIPHER_AES_128_CBC;
  371|       |            } else if (memcmp(s1, "DEK-Info: AES-192-CBC,", 22) == 0) {
  372|       |                enc_alg = MBEDTLS_CIPHER_AES_192_CBC;
  373|       |            } else if (memcmp(s1, "DEK-Info: AES-256-CBC,", 22) == 0) {
  374|       |                enc_alg = MBEDTLS_CIPHER_AES_256_CBC;
  375|       |            } else {
  376|       |                return MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG;
  377|       |            }
  378|       |
  379|       |            s1 += 22;
  380|       |            if (s2 - s1 < 32 || pem_get_iv(s1, pem_iv, 16) != 0) {
  381|       |                return MBEDTLS_ERR_PEM_INVALID_ENC_IV;
  382|       |            }
  383|       |
  384|       |            s1 += 32;
  385|       |        }
  386|       |#endif /* MBEDTLS_AES_C */
  387|       |
  388|       |        if (enc_alg == MBEDTLS_CIPHER_NONE) {
  389|       |            return MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG;
  390|       |        }
  391|       |
  392|       |        if (*s1 == '\r') {
  393|       |            s1++;
  394|       |        }
  395|       |        if (*s1 == '\n') {
  396|       |            s1++;
  397|       |        } else {
  398|       |            return MBEDTLS_ERR_PEM_INVALID_DATA;
  399|       |        }
  400|       |#else
  401|      0|        return MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE;
  ------------------
  |  |   39|      0|#define MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE               -0x1400
  ------------------
  402|      0|#endif /* PEM_RFC1421 */
  403|      0|    }
  404|       |
  405|      3|    if (s1 >= s2) {
  ------------------
  |  Branch (405:9): [True: 0, False: 3]
  ------------------
  406|      0|        return MBEDTLS_ERR_PEM_INVALID_DATA;
  ------------------
  |  |   27|      0|#define MBEDTLS_ERR_PEM_INVALID_DATA                      -0x1100
  ------------------
  407|      0|    }
  408|       |
  409|      3|    ret = mbedtls_base64_decode(NULL, 0, &len, s1, (size_t) (s2 - s1));
  410|       |
  411|      3|    if (ret == MBEDTLS_ERR_BASE64_INVALID_CHARACTER) {
  ------------------
  |  |   20|      3|#define MBEDTLS_ERR_BASE64_INVALID_CHARACTER              -0x002C
  ------------------
  |  Branch (411:9): [True: 0, False: 3]
  ------------------
  412|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PEM_INVALID_DATA, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  413|      0|    }
  414|       |
  415|      3|    if (len == 0) {
  ------------------
  |  Branch (415:9): [True: 0, False: 3]
  ------------------
  416|      0|        return MBEDTLS_ERR_PEM_BAD_INPUT_DATA;
  ------------------
  |  |   41|      0|#define MBEDTLS_ERR_PEM_BAD_INPUT_DATA                    -0x1480
  ------------------
  417|      0|    }
  418|       |
  419|      3|    if ((buf = mbedtls_calloc(1, len)) == NULL) {
  ------------------
  |  |  144|      3|#define mbedtls_calloc     MBEDTLS_PLATFORM_CALLOC_MACRO
  |  |  ------------------
  |  |  |  | 4093|      3|#define MBEDTLS_PLATFORM_CALLOC_MACRO        my_calloc
  |  |  ------------------
  ------------------
  |  Branch (419:9): [True: 0, False: 3]
  ------------------
  420|      0|        return MBEDTLS_ERR_PEM_ALLOC_FAILED;
  ------------------
  |  |   29|      0|#define MBEDTLS_ERR_PEM_ALLOC_FAILED                      -0x1180
  ------------------
  421|      0|    }
  422|       |
  423|      3|    if ((ret = mbedtls_base64_decode(buf, len, &len, s1, (size_t) (s2 - s1))) != 0) {
  ------------------
  |  Branch (423:9): [True: 0, False: 3]
  ------------------
  424|      0|        mbedtls_zeroize_and_free(buf, len);
  425|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PEM_INVALID_DATA, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  426|      0|    }
  427|       |
  428|      3|    if (enc != 0) {
  ------------------
  |  Branch (428:9): [True: 0, False: 3]
  ------------------
  429|       |#if defined(PEM_RFC1421)
  430|       |        if (pwd == NULL) {
  431|       |            mbedtls_zeroize_and_free(buf, len);
  432|       |            return MBEDTLS_ERR_PEM_PASSWORD_REQUIRED;
  433|       |        }
  434|       |
  435|       |        ret = 0;
  436|       |
  437|       |#if defined(MBEDTLS_DES_C)
  438|       |        if (enc_alg == MBEDTLS_CIPHER_DES_EDE3_CBC) {
  439|       |            ret = pem_des3_decrypt(pem_iv, buf, len, pwd, pwdlen);
  440|       |        } else if (enc_alg == MBEDTLS_CIPHER_DES_CBC) {
  441|       |            ret = pem_des_decrypt(pem_iv, buf, len, pwd, pwdlen);
  442|       |        }
  443|       |#endif /* MBEDTLS_DES_C */
  444|       |
  445|       |#if defined(MBEDTLS_AES_C)
  446|       |        if (enc_alg == MBEDTLS_CIPHER_AES_128_CBC) {
  447|       |            ret = pem_aes_decrypt(pem_iv, 16, buf, len, pwd, pwdlen);
  448|       |        } else if (enc_alg == MBEDTLS_CIPHER_AES_192_CBC) {
  449|       |            ret = pem_aes_decrypt(pem_iv, 24, buf, len, pwd, pwdlen);
  450|       |        } else if (enc_alg == MBEDTLS_CIPHER_AES_256_CBC) {
  451|       |            ret = pem_aes_decrypt(pem_iv, 32, buf, len, pwd, pwdlen);
  452|       |        }
  453|       |#endif /* MBEDTLS_AES_C */
  454|       |
  455|       |        if (ret != 0) {
  456|       |            mbedtls_zeroize_and_free(buf, len);
  457|       |            return ret;
  458|       |        }
  459|       |
  460|       |        /* Check PKCS padding and update data length based on padding info.
  461|       |         * This can be used to detect invalid padding data and password
  462|       |         * mismatches. */
  463|       |        size_t unpadded_len;
  464|       |        ret = pem_check_pkcs_padding(buf, len, &unpadded_len);
  465|       |        if (ret != 0) {
  466|       |            mbedtls_zeroize_and_free(buf, len);
  467|       |            return ret;
  468|       |        }
  469|       |        len = unpadded_len;
  470|       |#else
  471|      0|        mbedtls_zeroize_and_free(buf, len);
  472|      0|        return MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE;
  ------------------
  |  |   39|      0|#define MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE               -0x1400
  ------------------
  473|      0|#endif /* PEM_RFC1421 */
  474|      0|    }
  475|       |
  476|      3|    ctx->buf = buf;
  477|      3|    ctx->buflen = len;
  478|       |
  479|      3|    return 0;
  480|      3|}
mbedtls_pem_free:
  483|      3|{
  484|      3|    if (ctx == NULL) {
  ------------------
  |  Branch (484:9): [True: 0, False: 3]
  ------------------
  485|      0|        return;
  486|      0|    }
  487|       |
  488|      3|    if (ctx->buf != NULL) {
  ------------------
  |  Branch (488:9): [True: 3, False: 0]
  ------------------
  489|      3|        mbedtls_zeroize_and_free(ctx->buf, ctx->buflen);
  490|      3|    }
  491|      3|    mbedtls_free(ctx->info);
  ------------------
  |  |  143|      3|#define mbedtls_free       MBEDTLS_PLATFORM_FREE_MACRO
  |  |  ------------------
  |  |  |  | 4095|      3|#define MBEDTLS_PLATFORM_FREE_MACRO            my_free
  |  |  ------------------
  ------------------
  492|       |
  493|      3|    mbedtls_platform_zeroize(ctx, sizeof(mbedtls_pem_context));
  494|      3|}

mbedtls_pk_init:
   46|      3|{
   47|      3|    ctx->pk_info = NULL;
   48|      3|    ctx->pk_ctx = NULL;
   49|       |#if defined(MBEDTLS_USE_PSA_CRYPTO)
   50|       |    ctx->priv_id = MBEDTLS_SVC_KEY_ID_INIT;
   51|       |#endif /* MBEDTLS_USE_PSA_CRYPTO */
   52|       |#if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
   53|       |    memset(ctx->pub_raw, 0, sizeof(ctx->pub_raw));
   54|       |    ctx->pub_raw_len = 0;
   55|       |    ctx->ec_family = 0;
   56|       |    ctx->ec_bits = 0;
   57|       |#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
   58|      3|}
mbedtls_pk_free:
   64|  16.8k|{
   65|  16.8k|    if (ctx == NULL) {
  ------------------
  |  Branch (65:9): [True: 0, False: 16.8k]
  ------------------
   66|      0|        return;
   67|      0|    }
   68|       |
   69|  16.8k|    if ((ctx->pk_info != NULL) && (ctx->pk_info->ctx_free_func != NULL)) {
  ------------------
  |  Branch (69:9): [True: 16.8k, False: 0]
  |  Branch (69:35): [True: 16.8k, False: 0]
  ------------------
   70|  16.8k|        ctx->pk_info->ctx_free_func(ctx->pk_ctx);
   71|  16.8k|    }
   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|  16.8k|    mbedtls_platform_zeroize(ctx, sizeof(mbedtls_pk_context));
   82|  16.8k|}
mbedtls_pk_info_from_type:
  115|  16.8k|{
  116|  16.8k|    switch (pk_type) {
  117|      0|#if defined(MBEDTLS_RSA_C)
  118|      0|        case MBEDTLS_PK_RSA:
  ------------------
  |  Branch (118:9): [True: 0, False: 16.8k]
  ------------------
  119|      0|            return &mbedtls_rsa_info;
  120|      0|#endif /* MBEDTLS_RSA_C */
  121|      0|#if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
  122|  16.8k|        case MBEDTLS_PK_ECKEY:
  ------------------
  |  Branch (122:9): [True: 16.8k, False: 0]
  ------------------
  123|  16.8k|            return &mbedtls_eckey_info;
  124|      0|        case MBEDTLS_PK_ECKEY_DH:
  ------------------
  |  Branch (124:9): [True: 0, False: 16.8k]
  ------------------
  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: 16.8k]
  ------------------
  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: 16.8k]
  ------------------
  133|      0|            return NULL;
  134|  16.8k|    }
  135|  16.8k|}
mbedtls_pk_setup:
  141|  16.8k|{
  142|  16.8k|    if (info == NULL || ctx->pk_info != NULL) {
  ------------------
  |  Branch (142:9): [True: 0, False: 16.8k]
  |  Branch (142:25): [True: 0, False: 16.8k]
  ------------------
  143|      0|        return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
  ------------------
  |  |   40|      0|#define MBEDTLS_ERR_PK_BAD_INPUT_DATA      -0x3E80
  ------------------
  144|      0|    }
  145|       |
  146|  16.8k|    if ((info->ctx_alloc_func != NULL) &&
  ------------------
  |  Branch (146:9): [True: 16.8k, False: 0]
  ------------------
  147|  16.8k|        ((ctx->pk_ctx = info->ctx_alloc_func()) == NULL)) {
  ------------------
  |  Branch (147:9): [True: 0, False: 16.8k]
  ------------------
  148|      0|        return MBEDTLS_ERR_PK_ALLOC_FAILED;
  ------------------
  |  |   36|      0|#define MBEDTLS_ERR_PK_ALLOC_FAILED        -0x3F80
  ------------------
  149|      0|    }
  150|       |
  151|  16.8k|    ctx->pk_info = info;
  152|       |
  153|  16.8k|    return 0;
  154|  16.8k|}
mbedtls_pk_can_do:
  232|  4.22k|{
  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|  4.22k|    if (ctx == NULL || ctx->pk_info == NULL) {
  ------------------
  |  Branch (236:9): [True: 0, False: 4.22k]
  |  Branch (236:24): [True: 0, False: 4.22k]
  ------------------
  237|      0|        return 0;
  238|      0|    }
  239|       |
  240|  4.22k|    return ctx->pk_info->can_do(type);
  241|  4.22k|}
mbedtls_pk_verify_restartable:
 1047|  2.11k|{
 1048|  2.11k|    if ((md_alg != MBEDTLS_MD_NONE || hash_len != 0) && hash == NULL) {
  ------------------
  |  Branch (1048:10): [True: 2.11k, False: 0]
  |  Branch (1048:39): [True: 0, False: 0]
  |  Branch (1048:57): [True: 0, False: 2.11k]
  ------------------
 1049|      0|        return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
  ------------------
  |  |   40|      0|#define MBEDTLS_ERR_PK_BAD_INPUT_DATA      -0x3E80
  ------------------
 1050|      0|    }
 1051|       |
 1052|  2.11k|    if (ctx->pk_info == NULL ||
  ------------------
  |  Branch (1052:9): [True: 0, False: 2.11k]
  ------------------
 1053|  2.11k|        pk_hashlen_helper(md_alg, &hash_len) != 0) {
  ------------------
  |  Branch (1053:9): [True: 0, False: 2.11k]
  ------------------
 1054|      0|        return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
  ------------------
  |  |   40|      0|#define MBEDTLS_ERR_PK_BAD_INPUT_DATA      -0x3E80
  ------------------
 1055|      0|    }
 1056|       |
 1057|  2.11k|#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
 1058|       |    /* optimization: use non-restartable version if restart disabled */
 1059|  2.11k|    if (rs_ctx != NULL &&
  ------------------
  |  Branch (1059:9): [True: 0, False: 2.11k]
  ------------------
 1060|  2.11k|        mbedtls_ecp_restart_is_enabled() &&
  ------------------
  |  Branch (1060:9): [True: 0, False: 0]
  ------------------
 1061|  2.11k|        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|  2.11k|    if (ctx->pk_info->verify_func == NULL) {
  ------------------
  |  Branch (1081:9): [True: 0, False: 2.11k]
  ------------------
 1082|      0|        return MBEDTLS_ERR_PK_TYPE_MISMATCH;
  ------------------
  |  |   38|      0|#define MBEDTLS_ERR_PK_TYPE_MISMATCH       -0x3F00
  ------------------
 1083|      0|    }
 1084|       |
 1085|  2.11k|    return ctx->pk_info->verify_func(ctx, md_alg, hash, hash_len,
 1086|  2.11k|                                     sig, sig_len);
 1087|  2.11k|}
mbedtls_pk_verify:
 1095|  2.11k|{
 1096|  2.11k|    return mbedtls_pk_verify_restartable(ctx, md_alg, hash, hash_len,
 1097|  2.11k|                                         sig, sig_len, NULL);
 1098|  2.11k|}
mbedtls_pk_verify_ext:
 1107|  2.11k|{
 1108|  2.11k|    if ((md_alg != MBEDTLS_MD_NONE || hash_len != 0) && hash == NULL) {
  ------------------
  |  Branch (1108:10): [True: 2.11k, False: 0]
  |  Branch (1108:39): [True: 0, False: 0]
  |  Branch (1108:57): [True: 0, False: 2.11k]
  ------------------
 1109|      0|        return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
  ------------------
  |  |   40|      0|#define MBEDTLS_ERR_PK_BAD_INPUT_DATA      -0x3E80
  ------------------
 1110|      0|    }
 1111|       |
 1112|  2.11k|    if (ctx->pk_info == NULL) {
  ------------------
  |  Branch (1112:9): [True: 0, False: 2.11k]
  ------------------
 1113|      0|        return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
  ------------------
  |  |   40|      0|#define MBEDTLS_ERR_PK_BAD_INPUT_DATA      -0x3E80
  ------------------
 1114|      0|    }
 1115|       |
 1116|  2.11k|    if (!mbedtls_pk_can_do(ctx, type)) {
  ------------------
  |  Branch (1116:9): [True: 0, False: 2.11k]
  ------------------
 1117|      0|        return MBEDTLS_ERR_PK_TYPE_MISMATCH;
  ------------------
  |  |   38|      0|#define MBEDTLS_ERR_PK_TYPE_MISMATCH       -0x3F00
  ------------------
 1118|      0|    }
 1119|       |
 1120|  2.11k|    if (type != MBEDTLS_PK_RSASSA_PSS) {
  ------------------
  |  Branch (1120:9): [True: 2.11k, False: 0]
  ------------------
 1121|       |        /* General case: no options */
 1122|  2.11k|        if (options != NULL) {
  ------------------
  |  Branch (1122:13): [True: 0, False: 2.11k]
  ------------------
 1123|      0|            return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
  ------------------
  |  |   40|      0|#define MBEDTLS_ERR_PK_BAD_INPUT_DATA      -0x3E80
  ------------------
 1124|      0|        }
 1125|       |
 1126|  2.11k|        return mbedtls_pk_verify(ctx, md_alg, hash, hash_len, sig, sig_len);
 1127|  2.11k|    }
 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|  49.6k|{
 1500|  49.6k|    if (ctx == NULL || ctx->pk_info == NULL) {
  ------------------
  |  Branch (1500:9): [True: 0, False: 49.6k]
  |  Branch (1500:24): [True: 0, False: 49.6k]
  ------------------
 1501|      0|        return MBEDTLS_PK_NONE;
 1502|      0|    }
 1503|       |
 1504|  49.6k|    return ctx->pk_info->type;
 1505|  49.6k|}
pk.c:pk_hashlen_helper:
  998|  2.11k|{
  999|  2.11k|    if (*hash_len != 0) {
  ------------------
  |  Branch (999:9): [True: 2.11k, False: 0]
  ------------------
 1000|  2.11k|        return 0;
 1001|  2.11k|    }
 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|  16.8k|{
   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|  16.8k|    mbedtls_ecp_keypair *ecp = mbedtls_pk_ec_rw(*pk);
   36|       |
   37|       |    /* grp may already be initialized; if so, make sure IDs match */
   38|  16.8k|    if (mbedtls_pk_ec_ro(*pk)->grp.id != MBEDTLS_ECP_DP_NONE &&
  ------------------
  |  Branch (38:9): [True: 0, False: 16.8k]
  ------------------
   39|  16.8k|        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|  16.8k|    return mbedtls_ecp_group_load(&(ecp->grp), grp_id);
   45|  16.8k|#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
   46|  16.8k|}
mbedtls_pk_ecc_set_key:
   49|      3|{
   50|       |#if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
   51|       |    psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
   52|       |    psa_key_usage_t flags;
   53|       |    psa_status_t status;
   54|       |
   55|       |    psa_set_key_type(&attributes, PSA_KEY_TYPE_ECC_KEY_PAIR(pk->ec_family));
   56|       |    if (pk->ec_family == PSA_ECC_FAMILY_MONTGOMERY) {
   57|       |        /* Do not set algorithm here because Montgomery keys cannot do ECDSA and
   58|       |         * the PK module cannot do ECDH. When the key will be used in TLS for
   59|       |         * ECDH, it will be exported and then re-imported with proper flags
   60|       |         * and algorithm. */
   61|       |        flags = PSA_KEY_USAGE_EXPORT;
   62|       |    } else {
   63|       |        psa_set_key_algorithm(&attributes,
   64|       |                              MBEDTLS_PK_PSA_ALG_ECDSA_MAYBE_DET(PSA_ALG_ANY_HASH));
   65|       |        flags = PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_SIGN_MESSAGE |
   66|       |                PSA_KEY_USAGE_EXPORT;
   67|       |    }
   68|       |    psa_set_key_usage_flags(&attributes, flags);
   69|       |
   70|       |    status = psa_import_key(&attributes, key, key_len, &pk->priv_id);
   71|       |    return psa_pk_status_to_mbedtls(status);
   72|       |
   73|       |#else /* MBEDTLS_PK_USE_PSA_EC_DATA */
   74|       |
   75|      3|    mbedtls_ecp_keypair *eck = mbedtls_pk_ec_rw(*pk);
   76|      3|    int ret = mbedtls_ecp_read_key(eck->grp.id, eck, key, key_len);
   77|      3|    if (ret != 0) {
  ------------------
  |  Branch (77:9): [True: 0, False: 3]
  ------------------
   78|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
   79|      0|    }
   80|      3|    return 0;
   81|      3|#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
   82|      3|}
mbedtls_pk_ecc_set_pubkey:
  205|  16.8k|{
  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|  16.8k|    int ret;
  245|  16.8k|    mbedtls_ecp_keypair *ec_key = (mbedtls_ecp_keypair *) pk->pk_ctx;
  246|  16.8k|    ret = mbedtls_ecp_point_read_binary(&ec_key->grp, &ec_key->Q, pub, pub_len);
  247|  16.8k|    if (ret != 0) {
  ------------------
  |  Branch (247:9): [True: 0, False: 16.8k]
  ------------------
  248|      0|        return ret;
  249|      0|    }
  250|  16.8k|    return mbedtls_ecp_check_pubkey(&ec_key->grp, &ec_key->Q);
  251|       |
  252|  16.8k|#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
  253|  16.8k|}

x509_crt.c:mbedtls_pk_get_ec_group_id:
   87|  5.28k|{
   88|  5.28k|    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|  5.28k|    {
  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|  5.28k|        id = mbedtls_pk_ec_ro(*pk)->grp.id;
  110|  5.28k|#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
  111|  5.28k|    }
  112|       |
  113|  5.28k|    return id;
  114|  5.28k|}
x509_crt.c:mbedtls_pk_ec_ro:
   61|  5.28k|{
   62|  5.28k|    switch (mbedtls_pk_get_type(&pk)) {
   63|  5.28k|        case MBEDTLS_PK_ECKEY:
  ------------------
  |  Branch (63:9): [True: 5.28k, False: 0]
  ------------------
   64|  5.28k|        case MBEDTLS_PK_ECKEY_DH:
  ------------------
  |  Branch (64:9): [True: 0, False: 5.28k]
  ------------------
   65|  5.28k|        case MBEDTLS_PK_ECDSA:
  ------------------
  |  Branch (65:9): [True: 0, False: 5.28k]
  ------------------
   66|  5.28k|            return (const mbedtls_ecp_keypair *) (pk).MBEDTLS_PRIVATE(pk_ctx);
  ------------------
  |  |   17|  5.28k|#define MBEDTLS_PRIVATE(member) member
  ------------------
   67|      0|        default:
  ------------------
  |  Branch (67:9): [True: 0, False: 5.28k]
  ------------------
   68|      0|            return NULL;
   69|  5.28k|    }
   70|  5.28k|}
pk_ecc.c:mbedtls_pk_ec_rw:
   73|  16.9k|{
   74|  16.9k|    switch (mbedtls_pk_get_type(&pk)) {
   75|  16.9k|        case MBEDTLS_PK_ECKEY:
  ------------------
  |  Branch (75:9): [True: 16.9k, False: 0]
  ------------------
   76|  16.9k|        case MBEDTLS_PK_ECKEY_DH:
  ------------------
  |  Branch (76:9): [True: 0, False: 16.9k]
  ------------------
   77|  16.9k|        case MBEDTLS_PK_ECDSA:
  ------------------
  |  Branch (77:9): [True: 0, False: 16.9k]
  ------------------
   78|  16.9k|            return (mbedtls_ecp_keypair *) (pk).MBEDTLS_PRIVATE(pk_ctx);
  ------------------
  |  |   17|  16.9k|#define MBEDTLS_PRIVATE(member) member
  ------------------
   79|      0|        default:
  ------------------
  |  Branch (79:9): [True: 0, False: 16.9k]
  ------------------
   80|      0|            return NULL;
   81|  16.9k|    }
   82|  16.9k|}
pk_ecc.c:mbedtls_pk_ec_ro:
   61|  16.8k|{
   62|  16.8k|    switch (mbedtls_pk_get_type(&pk)) {
   63|  16.8k|        case MBEDTLS_PK_ECKEY:
  ------------------
  |  Branch (63:9): [True: 16.8k, False: 0]
  ------------------
   64|  16.8k|        case MBEDTLS_PK_ECKEY_DH:
  ------------------
  |  Branch (64:9): [True: 0, False: 16.8k]
  ------------------
   65|  16.8k|        case MBEDTLS_PK_ECDSA:
  ------------------
  |  Branch (65:9): [True: 0, False: 16.8k]
  ------------------
   66|  16.8k|            return (const mbedtls_ecp_keypair *) (pk).MBEDTLS_PRIVATE(pk_ctx);
  ------------------
  |  |   17|  16.8k|#define MBEDTLS_PRIVATE(member) member
  ------------------
   67|      0|        default:
  ------------------
  |  Branch (67:9): [True: 0, False: 16.8k]
  ------------------
   68|      0|            return NULL;
   69|  16.8k|    }
   70|  16.8k|}

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

mbedtls_pk_parse_subpubkey:
  519|  16.8k|{
  520|  16.8k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  16.8k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  521|  16.8k|    size_t len;
  522|  16.8k|    mbedtls_asn1_buf alg_params;
  523|  16.8k|    mbedtls_pk_type_t pk_alg = MBEDTLS_PK_NONE;
  524|  16.8k|    mbedtls_ecp_group_id ec_grp_id = MBEDTLS_ECP_DP_NONE;
  525|  16.8k|    const mbedtls_pk_info_t *pk_info;
  526|       |
  527|  16.8k|    if ((ret = mbedtls_asn1_get_tag(p, end, &len,
  ------------------
  |  Branch (527:9): [True: 0, False: 16.8k]
  ------------------
  528|  16.8k|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|  16.8k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|  16.8k|#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|  16.8k|    end = *p + len;
  533|       |
  534|  16.8k|    if ((ret = pk_get_pk_alg(p, end, &pk_alg, &alg_params, &ec_grp_id)) != 0) {
  ------------------
  |  Branch (534:9): [True: 0, False: 16.8k]
  ------------------
  535|      0|        return ret;
  536|      0|    }
  537|       |
  538|  16.8k|    if ((ret = mbedtls_asn1_get_bitstring_null(p, end, &len)) != 0) {
  ------------------
  |  Branch (538:9): [True: 0, False: 16.8k]
  ------------------
  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|  16.8k|    if (*p + len != end) {
  ------------------
  |  Branch (542:9): [True: 0, False: 16.8k]
  ------------------
  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|  16.8k|    if ((pk_info = mbedtls_pk_info_from_type(pk_alg)) == NULL) {
  ------------------
  |  Branch (547:9): [True: 0, False: 16.8k]
  ------------------
  548|      0|        return MBEDTLS_ERR_PK_UNKNOWN_PK_ALG;
  ------------------
  |  |   48|      0|#define MBEDTLS_ERR_PK_UNKNOWN_PK_ALG      -0x3C80
  ------------------
  549|      0|    }
  550|       |
  551|  16.8k|    if ((ret = mbedtls_pk_setup(pk, pk_info)) != 0) {
  ------------------
  |  Branch (551:9): [True: 0, False: 16.8k]
  ------------------
  552|      0|        return ret;
  553|      0|    }
  554|       |
  555|  16.8k|#if defined(MBEDTLS_RSA_C)
  556|  16.8k|    if (pk_alg == MBEDTLS_PK_RSA) {
  ------------------
  |  Branch (556:9): [True: 0, False: 16.8k]
  ------------------
  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|  16.8k|#endif /* MBEDTLS_RSA_C */
  570|  16.8k|#if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
  571|  16.8k|    if (pk_alg == MBEDTLS_PK_ECKEY_DH || pk_alg == MBEDTLS_PK_ECKEY) {
  ------------------
  |  Branch (571:9): [True: 0, False: 16.8k]
  |  Branch (571:42): [True: 16.8k, False: 0]
  ------------------
  572|  16.8k|#if defined(MBEDTLS_PK_HAVE_RFC8410_CURVES)
  573|  16.8k|        if (MBEDTLS_PK_IS_RFC8410_GROUP_ID(ec_grp_id)) {
  ------------------
  |  |  122|  16.8k|    ((id == MBEDTLS_ECP_DP_CURVE25519) || (id == MBEDTLS_ECP_DP_CURVE448))
  |  |  ------------------
  |  |  |  Branch (122:6): [True: 0, False: 16.8k]
  |  |  |  Branch (122:43): [True: 0, False: 16.8k]
  |  |  ------------------
  ------------------
  574|      0|            ret = pk_use_ecparams_rfc8410(&alg_params, ec_grp_id, pk);
  575|      0|        } else
  576|  16.8k|#endif
  577|  16.8k|        {
  578|  16.8k|            ret = pk_use_ecparams(&alg_params, pk);
  579|  16.8k|        }
  580|  16.8k|        if (ret == 0) {
  ------------------
  |  Branch (580:13): [True: 16.8k, False: 0]
  ------------------
  581|  16.8k|            ret = mbedtls_pk_ecc_set_pubkey(pk, *p, (size_t) (end - *p));
  582|  16.8k|            *p += end - *p;
  583|  16.8k|        }
  584|  16.8k|    } 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|  16.8k|    if (ret == 0 && *p != end) {
  ------------------
  |  Branch (588:9): [True: 16.8k, False: 0]
  |  Branch (588:21): [True: 0, False: 16.8k]
  ------------------
  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|  16.8k|    if (ret != 0) {
  ------------------
  |  Branch (593:9): [True: 0, False: 16.8k]
  ------------------
  594|      0|        mbedtls_pk_free(pk);
  595|      0|    }
  596|       |
  597|  16.8k|    return ret;
  598|  16.8k|}
mbedtls_pk_parse_key:
  977|      3|{
  978|      3|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|      3|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  979|      3|    const mbedtls_pk_info_t *pk_info;
  980|      3|#if defined(MBEDTLS_PEM_PARSE_C)
  981|      3|    size_t len;
  982|      3|    mbedtls_pem_context pem;
  983|      3|#endif
  984|       |
  985|      3|    if (keylen == 0) {
  ------------------
  |  Branch (985:9): [True: 0, False: 3]
  ------------------
  986|      0|        return MBEDTLS_ERR_PK_KEY_INVALID_FORMAT;
  ------------------
  |  |   46|      0|#define MBEDTLS_ERR_PK_KEY_INVALID_FORMAT  -0x3D00
  ------------------
  987|      0|    }
  988|       |
  989|      3|#if defined(MBEDTLS_PEM_PARSE_C)
  990|      3|    mbedtls_pem_init(&pem);
  991|       |
  992|      3|#if defined(MBEDTLS_RSA_C)
  993|       |    /* Avoid calling mbedtls_pem_read_buffer() on non-null-terminated string */
  994|      3|    if (key[keylen - 1] != '\0') {
  ------------------
  |  Branch (994:9): [True: 0, False: 3]
  ------------------
  995|      0|        ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT;
  ------------------
  |  |   25|      0|#define MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT          -0x1080
  ------------------
  996|      3|    } else {
  997|      3|        ret = mbedtls_pem_read_buffer(&pem,
  998|      3|                                      PEM_BEGIN_PRIVATE_KEY_RSA, PEM_END_PRIVATE_KEY_RSA,
  ------------------
  |  |   36|      3|#define PEM_BEGIN_PRIVATE_KEY_RSA   "-----BEGIN RSA PRIVATE KEY-----"
  ------------------
                                                    PEM_BEGIN_PRIVATE_KEY_RSA, PEM_END_PRIVATE_KEY_RSA,
  ------------------
  |  |   37|      3|#define PEM_END_PRIVATE_KEY_RSA     "-----END RSA PRIVATE KEY-----"
  ------------------
  999|      3|                                      key, pwd, pwdlen, &len);
 1000|      3|    }
 1001|       |
 1002|      3|    if (ret == 0) {
  ------------------
  |  Branch (1002:9): [True: 0, False: 3]
  ------------------
 1003|      0|        pk_info = mbedtls_pk_info_from_type(MBEDTLS_PK_RSA);
 1004|      0|        if ((ret = mbedtls_pk_setup(pk, pk_info)) != 0 ||
  ------------------
  |  Branch (1004:13): [True: 0, False: 0]
  ------------------
 1005|      0|            (ret = mbedtls_rsa_parse_key(mbedtls_pk_rsa(*pk),
  ------------------
  |  Branch (1005:13): [True: 0, False: 0]
  ------------------
 1006|      0|                                         pem.buf, pem.buflen)) != 0) {
 1007|      0|            mbedtls_pk_free(pk);
 1008|      0|        }
 1009|       |
 1010|      0|        mbedtls_pem_free(&pem);
 1011|      0|        return ret;
 1012|      3|    } else if (ret == MBEDTLS_ERR_PEM_PASSWORD_MISMATCH) {
  ------------------
  |  |   37|      3|#define MBEDTLS_ERR_PEM_PASSWORD_MISMATCH                 -0x1380
  ------------------
  |  Branch (1012:16): [True: 0, False: 3]
  ------------------
 1013|      0|        return MBEDTLS_ERR_PK_PASSWORD_MISMATCH;
  ------------------
  |  |   52|      0|#define MBEDTLS_ERR_PK_PASSWORD_MISMATCH   -0x3B80
  ------------------
 1014|      3|    } else if (ret == MBEDTLS_ERR_PEM_PASSWORD_REQUIRED) {
  ------------------
  |  |   35|      3|#define MBEDTLS_ERR_PEM_PASSWORD_REQUIRED                 -0x1300
  ------------------
  |  Branch (1014:16): [True: 0, False: 3]
  ------------------
 1015|      0|        return MBEDTLS_ERR_PK_PASSWORD_REQUIRED;
  ------------------
  |  |   50|      0|#define MBEDTLS_ERR_PK_PASSWORD_REQUIRED   -0x3C00
  ------------------
 1016|      3|    } else if (ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) {
  ------------------
  |  |   25|      3|#define MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT          -0x1080
  ------------------
  |  Branch (1016:16): [True: 0, False: 3]
  ------------------
 1017|      0|        return ret;
 1018|      0|    }
 1019|      3|#endif /* MBEDTLS_RSA_C */
 1020|       |
 1021|      3|#if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
 1022|       |    /* Avoid calling mbedtls_pem_read_buffer() on non-null-terminated string */
 1023|      3|    if (key[keylen - 1] != '\0') {
  ------------------
  |  Branch (1023:9): [True: 0, False: 3]
  ------------------
 1024|      0|        ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT;
  ------------------
  |  |   25|      0|#define MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT          -0x1080
  ------------------
 1025|      3|    } else {
 1026|      3|        ret = mbedtls_pem_read_buffer(&pem,
 1027|      3|                                      PEM_BEGIN_PRIVATE_KEY_EC,
  ------------------
  |  |   40|      3|#define PEM_BEGIN_PRIVATE_KEY_EC    "-----BEGIN EC PRIVATE KEY-----"
  ------------------
 1028|      3|                                      PEM_END_PRIVATE_KEY_EC,
  ------------------
  |  |   41|      3|#define PEM_END_PRIVATE_KEY_EC      "-----END EC PRIVATE KEY-----"
  ------------------
 1029|      3|                                      key, pwd, pwdlen, &len);
 1030|      3|    }
 1031|      3|    if (ret == 0) {
  ------------------
  |  Branch (1031:9): [True: 0, False: 3]
  ------------------
 1032|      0|        pk_info = mbedtls_pk_info_from_type(MBEDTLS_PK_ECKEY);
 1033|       |
 1034|      0|        if ((ret = mbedtls_pk_setup(pk, pk_info)) != 0 ||
  ------------------
  |  Branch (1034:13): [True: 0, False: 0]
  ------------------
 1035|      0|            (ret = pk_parse_key_sec1_der(pk,
  ------------------
  |  Branch (1035:13): [True: 0, False: 0]
  ------------------
 1036|      0|                                         pem.buf, pem.buflen,
 1037|      0|                                         f_rng, p_rng)) != 0) {
 1038|      0|            mbedtls_pk_free(pk);
 1039|      0|        }
 1040|       |
 1041|      0|        mbedtls_pem_free(&pem);
 1042|      0|        return ret;
 1043|      3|    } else if (ret == MBEDTLS_ERR_PEM_PASSWORD_MISMATCH) {
  ------------------
  |  |   37|      3|#define MBEDTLS_ERR_PEM_PASSWORD_MISMATCH                 -0x1380
  ------------------
  |  Branch (1043:16): [True: 0, False: 3]
  ------------------
 1044|      0|        return MBEDTLS_ERR_PK_PASSWORD_MISMATCH;
  ------------------
  |  |   52|      0|#define MBEDTLS_ERR_PK_PASSWORD_MISMATCH   -0x3B80
  ------------------
 1045|      3|    } else if (ret == MBEDTLS_ERR_PEM_PASSWORD_REQUIRED) {
  ------------------
  |  |   35|      3|#define MBEDTLS_ERR_PEM_PASSWORD_REQUIRED                 -0x1300
  ------------------
  |  Branch (1045:16): [True: 0, False: 3]
  ------------------
 1046|      0|        return MBEDTLS_ERR_PK_PASSWORD_REQUIRED;
  ------------------
  |  |   50|      0|#define MBEDTLS_ERR_PK_PASSWORD_REQUIRED   -0x3C00
  ------------------
 1047|      3|    } else if (ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) {
  ------------------
  |  |   25|      3|#define MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT          -0x1080
  ------------------
  |  Branch (1047:16): [True: 0, False: 3]
  ------------------
 1048|      0|        return ret;
 1049|      0|    }
 1050|      3|#endif /* MBEDTLS_PK_HAVE_ECC_KEYS */
 1051|       |
 1052|       |    /* Avoid calling mbedtls_pem_read_buffer() on non-null-terminated string */
 1053|      3|    if (key[keylen - 1] != '\0') {
  ------------------
  |  Branch (1053:9): [True: 0, False: 3]
  ------------------
 1054|      0|        ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT;
  ------------------
  |  |   25|      0|#define MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT          -0x1080
  ------------------
 1055|      3|    } else {
 1056|      3|        ret = mbedtls_pem_read_buffer(&pem,
 1057|      3|                                      PEM_BEGIN_PRIVATE_KEY_PKCS8, PEM_END_PRIVATE_KEY_PKCS8,
  ------------------
  |  |   42|      3|#define PEM_BEGIN_PRIVATE_KEY_PKCS8 "-----BEGIN PRIVATE KEY-----"
  ------------------
                                                    PEM_BEGIN_PRIVATE_KEY_PKCS8, PEM_END_PRIVATE_KEY_PKCS8,
  ------------------
  |  |   43|      3|#define PEM_END_PRIVATE_KEY_PKCS8   "-----END PRIVATE KEY-----"
  ------------------
 1058|      3|                                      key, NULL, 0, &len);
 1059|      3|    }
 1060|      3|    if (ret == 0) {
  ------------------
  |  Branch (1060:9): [True: 3, False: 0]
  ------------------
 1061|      3|        if ((ret = pk_parse_key_pkcs8_unencrypted_der(pk,
  ------------------
  |  Branch (1061:13): [True: 0, False: 3]
  ------------------
 1062|      3|                                                      pem.buf, pem.buflen, f_rng, p_rng)) != 0) {
 1063|      0|            mbedtls_pk_free(pk);
 1064|      0|        }
 1065|       |
 1066|      3|        mbedtls_pem_free(&pem);
 1067|      3|        return ret;
 1068|      3|    } else if (ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) {
  ------------------
  |  |   25|      0|#define MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT          -0x1080
  ------------------
  |  Branch (1068:16): [True: 0, False: 0]
  ------------------
 1069|      0|        return ret;
 1070|      0|    }
 1071|       |
 1072|       |#if defined(MBEDTLS_PKCS12_C) || defined(MBEDTLS_PKCS5_C)
 1073|       |    /* Avoid calling mbedtls_pem_read_buffer() on non-null-terminated string */
 1074|       |    if (key[keylen - 1] != '\0') {
 1075|       |        ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT;
 1076|       |    } else {
 1077|       |        ret = mbedtls_pem_read_buffer(&pem,
 1078|       |                                      PEM_BEGIN_ENCRYPTED_PRIVATE_KEY_PKCS8,
 1079|       |                                      PEM_END_ENCRYPTED_PRIVATE_KEY_PKCS8,
 1080|       |                                      key, NULL, 0, &len);
 1081|       |    }
 1082|       |    if (ret == 0) {
 1083|       |        if ((ret = mbedtls_pk_parse_key_pkcs8_encrypted_der(pk, pem.buf, pem.buflen,
 1084|       |                                                            pwd, pwdlen, f_rng, p_rng)) != 0) {
 1085|       |            mbedtls_pk_free(pk);
 1086|       |        }
 1087|       |
 1088|       |        mbedtls_pem_free(&pem);
 1089|       |        return ret;
 1090|       |    } else if (ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) {
 1091|       |        return ret;
 1092|       |    }
 1093|       |#endif /* MBEDTLS_PKCS12_C || MBEDTLS_PKCS5_C */
 1094|       |#else
 1095|       |    ((void) pwd);
 1096|       |    ((void) pwdlen);
 1097|       |#endif /* MBEDTLS_PEM_PARSE_C */
 1098|       |
 1099|       |    /*
 1100|       |     * At this point we only know it's not a PEM formatted key. Could be any
 1101|       |     * of the known DER encoded private key formats
 1102|       |     *
 1103|       |     * We try the different DER format parsers to see if one passes without
 1104|       |     * error
 1105|       |     */
 1106|       |#if defined(MBEDTLS_PKCS12_C) || defined(MBEDTLS_PKCS5_C)
 1107|       |    if (pwdlen != 0) {
 1108|       |        unsigned char *key_copy;
 1109|       |
 1110|       |        if ((key_copy = mbedtls_calloc(1, keylen)) == NULL) {
 1111|       |            return MBEDTLS_ERR_PK_ALLOC_FAILED;
 1112|       |        }
 1113|       |
 1114|       |        memcpy(key_copy, key, keylen);
 1115|       |
 1116|       |        ret = mbedtls_pk_parse_key_pkcs8_encrypted_der(pk, key_copy, keylen,
 1117|       |                                                       pwd, pwdlen, f_rng, p_rng);
 1118|       |
 1119|       |        mbedtls_zeroize_and_free(key_copy, keylen);
 1120|       |    }
 1121|       |
 1122|       |    if (ret == 0) {
 1123|       |        return 0;
 1124|       |    }
 1125|       |
 1126|       |    mbedtls_pk_free(pk);
 1127|       |    mbedtls_pk_init(pk);
 1128|       |
 1129|       |    if (ret == MBEDTLS_ERR_PK_PASSWORD_MISMATCH) {
 1130|       |        return ret;
 1131|       |    }
 1132|       |#endif /* MBEDTLS_PKCS12_C || MBEDTLS_PKCS5_C */
 1133|       |
 1134|      0|    ret = pk_parse_key_pkcs8_unencrypted_der(pk, key, keylen, f_rng, p_rng);
 1135|      0|    if (ret == 0) {
  ------------------
  |  Branch (1135:9): [True: 0, False: 0]
  ------------------
 1136|      0|        return 0;
 1137|      0|    }
 1138|       |
 1139|      0|    mbedtls_pk_free(pk);
 1140|      0|    mbedtls_pk_init(pk);
 1141|       |
 1142|      0|#if defined(MBEDTLS_RSA_C)
 1143|       |
 1144|      0|    pk_info = mbedtls_pk_info_from_type(MBEDTLS_PK_RSA);
 1145|      0|    if (mbedtls_pk_setup(pk, pk_info) == 0 &&
  ------------------
  |  Branch (1145:9): [True: 0, False: 0]
  ------------------
 1146|      0|        mbedtls_rsa_parse_key(mbedtls_pk_rsa(*pk), key, keylen) == 0) {
  ------------------
  |  Branch (1146:9): [True: 0, False: 0]
  ------------------
 1147|      0|        return 0;
 1148|      0|    }
 1149|       |
 1150|      0|    mbedtls_pk_free(pk);
 1151|      0|    mbedtls_pk_init(pk);
 1152|      0|#endif /* MBEDTLS_RSA_C */
 1153|       |
 1154|      0|#if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
 1155|      0|    pk_info = mbedtls_pk_info_from_type(MBEDTLS_PK_ECKEY);
 1156|      0|    if (mbedtls_pk_setup(pk, pk_info) == 0 &&
  ------------------
  |  Branch (1156:9): [True: 0, False: 0]
  ------------------
 1157|      0|        pk_parse_key_sec1_der(pk,
  ------------------
  |  Branch (1157:9): [True: 0, False: 0]
  ------------------
 1158|      0|                              key, keylen, f_rng, p_rng) == 0) {
 1159|      0|        return 0;
 1160|      0|    }
 1161|      0|    mbedtls_pk_free(pk);
 1162|      0|#endif /* MBEDTLS_PK_HAVE_ECC_KEYS */
 1163|       |
 1164|       |    /* If MBEDTLS_RSA_C is defined but MBEDTLS_PK_HAVE_ECC_KEYS isn't,
 1165|       |     * it is ok to leave the PK context initialized but not
 1166|       |     * freed: It is the caller's responsibility to call pk_init()
 1167|       |     * before calling this function, and to call pk_free()
 1168|       |     * when it fails. If MBEDTLS_PK_HAVE_ECC_KEYS is defined but MBEDTLS_RSA_C
 1169|       |     * isn't, this leads to mbedtls_pk_free() being called
 1170|       |     * twice, once here and once by the caller, but this is
 1171|       |     * also ok and in line with the mbedtls_pk_free() calls
 1172|       |     * on failed PEM parsing attempts. */
 1173|       |
 1174|      0|    return MBEDTLS_ERR_PK_KEY_INVALID_FORMAT;
  ------------------
  |  |   46|      0|#define MBEDTLS_ERR_PK_KEY_INVALID_FORMAT  -0x3D00
  ------------------
 1175|      0|}
pkparse.c:pk_get_pk_alg:
  475|  16.8k|{
  476|  16.8k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  16.8k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  477|  16.8k|    mbedtls_asn1_buf alg_oid;
  478|       |
  479|  16.8k|    memset(params, 0, sizeof(mbedtls_asn1_buf));
  480|       |
  481|  16.8k|    if ((ret = mbedtls_asn1_get_alg(p, end, &alg_oid, params)) != 0) {
  ------------------
  |  Branch (481:9): [True: 0, False: 16.8k]
  ------------------
  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|  16.8k|    ret = mbedtls_oid_get_pk_alg(&alg_oid, pk_alg);
  486|  16.8k|#if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
  487|  16.8k|    if (ret == MBEDTLS_ERR_OID_NOT_FOUND) {
  ------------------
  |  |   28|  16.8k|#define MBEDTLS_ERR_OID_NOT_FOUND                         -0x002E
  ------------------
  |  Branch (487:9): [True: 0, False: 16.8k]
  ------------------
  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|  16.8k|    if (ret != 0) {
  ------------------
  |  Branch (496:9): [True: 0, False: 16.8k]
  ------------------
  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|  16.8k|    if (*pk_alg == MBEDTLS_PK_RSA &&
  ------------------
  |  Branch (503:9): [True: 0, False: 16.8k]
  ------------------
  504|  16.8k|        ((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|  16.8k|    return 0;
  510|  16.8k|}
pkparse.c:pk_use_ecparams:
  390|  16.8k|{
  391|  16.8k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  16.8k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  392|  16.8k|    mbedtls_ecp_group_id grp_id;
  393|       |
  394|  16.8k|    if (params->tag == MBEDTLS_ASN1_OID) {
  ------------------
  |  |   69|  16.8k|#define MBEDTLS_ASN1_OID                     0x06
  ------------------
  |  Branch (394:9): [True: 16.8k, False: 0]
  ------------------
  395|  16.8k|        if (mbedtls_oid_get_ec_grp(params, &grp_id) != 0) {
  ------------------
  |  Branch (395:13): [True: 0, False: 16.8k]
  ------------------
  396|      0|            return MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE;
  ------------------
  |  |   58|      0|#define MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE -0x3A00
  ------------------
  397|      0|        }
  398|  16.8k|    } 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|  16.8k|    return mbedtls_pk_ecc_set_group(pk, grp_id);
  406|  16.8k|}
pkparse.c:pk_parse_key_sec1_der:
  607|      3|{
  608|      3|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|      3|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  609|      3|    int version, pubkey_done;
  610|      3|    size_t len, d_len;
  611|      3|    mbedtls_asn1_buf params = { 0, 0, NULL };
  612|      3|    unsigned char *p = (unsigned char *) key;
  613|      3|    unsigned char *d;
  614|      3|    unsigned char *end = p + keylen;
  615|      3|    unsigned char *end2;
  616|       |
  617|       |    /*
  618|       |     * RFC 5915, or SEC1 Appendix C.4
  619|       |     *
  620|       |     * ECPrivateKey ::= SEQUENCE {
  621|       |     *      version        INTEGER { ecPrivkeyVer1(1) } (ecPrivkeyVer1),
  622|       |     *      privateKey     OCTET STRING,
  623|       |     *      parameters [0] ECParameters {{ NamedCurve }} OPTIONAL,
  624|       |     *      publicKey  [1] BIT STRING OPTIONAL
  625|       |     *    }
  626|       |     */
  627|      3|    if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
  ------------------
  |  Branch (627:9): [True: 0, False: 3]
  ------------------
  628|      3|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|      3|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|      3|#define MBEDTLS_ASN1_SEQUENCE                0x10
  ------------------
  629|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  630|      0|    }
  631|       |
  632|      3|    end = p + len;
  633|       |
  634|      3|    if ((ret = mbedtls_asn1_get_int(&p, end, &version)) != 0) {
  ------------------
  |  Branch (634:9): [True: 0, False: 3]
  ------------------
  635|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  636|      0|    }
  637|       |
  638|      3|    if (version != 1) {
  ------------------
  |  Branch (638:9): [True: 0, False: 3]
  ------------------
  639|      0|        return MBEDTLS_ERR_PK_KEY_INVALID_VERSION;
  ------------------
  |  |   44|      0|#define MBEDTLS_ERR_PK_KEY_INVALID_VERSION -0x3D80
  ------------------
  640|      0|    }
  641|       |
  642|      3|    if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_OCTET_STRING)) != 0) {
  ------------------
  |  |   67|      3|#define MBEDTLS_ASN1_OCTET_STRING            0x04
  ------------------
  |  Branch (642:9): [True: 0, False: 3]
  ------------------
  643|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  644|      0|    }
  645|       |
  646|       |    /* Keep a reference to the position fo the private key. It will be used
  647|       |     * later in this function. */
  648|      3|    d = p;
  649|      3|    d_len = len;
  650|       |
  651|      3|    p += len;
  652|       |
  653|      3|    pubkey_done = 0;
  654|      3|    if (p != end) {
  ------------------
  |  Branch (654:9): [True: 3, False: 0]
  ------------------
  655|       |        /*
  656|       |         * Is 'parameters' present?
  657|       |         */
  658|      3|        if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
  ------------------
  |  Branch (658:13): [True: 0, False: 3]
  ------------------
  659|      3|                                        MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED |
  ------------------
  |  |   83|      3|#define MBEDTLS_ASN1_CONTEXT_SPECIFIC        0x80
  ------------------
                                                      MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED |
  ------------------
  |  |   82|      3|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
  660|      3|                                        0)) == 0) {
  661|      0|            if ((ret = pk_get_ecparams(&p, p + len, &params)) != 0 ||
  ------------------
  |  Branch (661:17): [True: 0, False: 0]
  ------------------
  662|      0|                (ret = pk_use_ecparams(&params, pk)) != 0) {
  ------------------
  |  Branch (662:17): [True: 0, False: 0]
  ------------------
  663|      0|                return ret;
  664|      0|            }
  665|      3|        } else if (ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) {
  ------------------
  |  |   39|      3|#define MBEDTLS_ERR_ASN1_UNEXPECTED_TAG                   -0x0062
  ------------------
  |  Branch (665:20): [True: 0, False: 3]
  ------------------
  666|      0|            return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  667|      0|        }
  668|      3|    }
  669|       |
  670|       |    /*
  671|       |     * Load the private key
  672|       |     */
  673|      3|    ret = mbedtls_pk_ecc_set_key(pk, d, d_len);
  674|      3|    if (ret != 0) {
  ------------------
  |  Branch (674:9): [True: 0, False: 3]
  ------------------
  675|      0|        return ret;
  676|      0|    }
  677|       |
  678|      3|    if (p != end) {
  ------------------
  |  Branch (678:9): [True: 3, False: 0]
  ------------------
  679|       |        /*
  680|       |         * Is 'publickey' present? If not, or if we can't read it (eg because it
  681|       |         * is compressed), create it from the private key.
  682|       |         */
  683|      3|        if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
  ------------------
  |  Branch (683:13): [True: 3, False: 0]
  ------------------
  684|      3|                                        MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED |
  ------------------
  |  |   83|      3|#define MBEDTLS_ASN1_CONTEXT_SPECIFIC        0x80
  ------------------
                                                      MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED |
  ------------------
  |  |   82|      3|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
  685|      3|                                        1)) == 0) {
  686|      3|            end2 = p + len;
  687|       |
  688|      3|            if ((ret = mbedtls_asn1_get_bitstring_null(&p, end2, &len)) != 0) {
  ------------------
  |  Branch (688:17): [True: 0, False: 3]
  ------------------
  689|      0|                return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  690|      0|            }
  691|       |
  692|      3|            if (p + len != end2) {
  ------------------
  |  Branch (692:17): [True: 0, False: 3]
  ------------------
  693|      0|                return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT,
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  694|      0|                                         MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
  695|      0|            }
  696|       |
  697|      3|            if ((ret = mbedtls_pk_ecc_set_pubkey(pk, p, (size_t) (end2 - p))) == 0) {
  ------------------
  |  Branch (697:17): [True: 3, False: 0]
  ------------------
  698|      3|                pubkey_done = 1;
  699|      3|            } else {
  700|       |                /*
  701|       |                 * The only acceptable failure mode of mbedtls_pk_ecc_set_pubkey() above
  702|       |                 * is if the point format is not recognized.
  703|       |                 */
  704|      0|                if (ret != MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE) {
  ------------------
  |  |   39|      0|#define MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE               -0x4E80
  ------------------
  |  Branch (704:21): [True: 0, False: 0]
  ------------------
  705|      0|                    return MBEDTLS_ERR_PK_KEY_INVALID_FORMAT;
  ------------------
  |  |   46|      0|#define MBEDTLS_ERR_PK_KEY_INVALID_FORMAT  -0x3D00
  ------------------
  706|      0|                }
  707|      0|            }
  708|      3|        } else if (ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) {
  ------------------
  |  |   39|      0|#define MBEDTLS_ERR_ASN1_UNEXPECTED_TAG                   -0x0062
  ------------------
  |  Branch (708:20): [True: 0, False: 0]
  ------------------
  709|      0|            return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  710|      0|        }
  711|      3|    }
  712|       |
  713|      3|    if (!pubkey_done) {
  ------------------
  |  Branch (713:9): [True: 0, False: 3]
  ------------------
  714|      0|        if ((ret = mbedtls_pk_ecc_set_pubkey_from_prv(pk, d, d_len, f_rng, p_rng)) != 0) {
  ------------------
  |  Branch (714:13): [True: 0, False: 0]
  ------------------
  715|      0|            return ret;
  716|      0|        }
  717|      0|    }
  718|       |
  719|      3|    return 0;
  720|      3|}
pkparse.c:pk_parse_key_pkcs8_unencrypted_der:
  746|      3|{
  747|      3|    int ret, version;
  748|      3|    size_t len;
  749|      3|    mbedtls_asn1_buf params;
  750|      3|    unsigned char *p = (unsigned char *) key;
  751|      3|    unsigned char *end = p + keylen;
  752|      3|    mbedtls_pk_type_t pk_alg = MBEDTLS_PK_NONE;
  753|      3|    mbedtls_ecp_group_id ec_grp_id = MBEDTLS_ECP_DP_NONE;
  754|      3|    const mbedtls_pk_info_t *pk_info;
  755|       |
  756|       |#if !defined(MBEDTLS_PK_HAVE_ECC_KEYS)
  757|       |    (void) f_rng;
  758|       |    (void) p_rng;
  759|       |#endif
  760|       |
  761|       |    /*
  762|       |     * This function parses the PrivateKeyInfo object (PKCS#8 v1.2 = RFC 5208)
  763|       |     *
  764|       |     *    PrivateKeyInfo ::= SEQUENCE {
  765|       |     *      version                   Version,
  766|       |     *      privateKeyAlgorithm       PrivateKeyAlgorithmIdentifier,
  767|       |     *      privateKey                PrivateKey,
  768|       |     *      attributes           [0]  IMPLICIT Attributes OPTIONAL }
  769|       |     *
  770|       |     *    Version ::= INTEGER
  771|       |     *    PrivateKeyAlgorithmIdentifier ::= AlgorithmIdentifier
  772|       |     *    PrivateKey ::= OCTET STRING
  773|       |     *
  774|       |     *  The PrivateKey OCTET STRING is a SEC1 ECPrivateKey
  775|       |     */
  776|       |
  777|      3|    if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
  ------------------
  |  Branch (777:9): [True: 0, False: 3]
  ------------------
  778|      3|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|      3|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|      3|#define MBEDTLS_ASN1_SEQUENCE                0x10
  ------------------
  779|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  780|      0|    }
  781|       |
  782|      3|    end = p + len;
  783|       |
  784|      3|    if ((ret = mbedtls_asn1_get_int(&p, end, &version)) != 0) {
  ------------------
  |  Branch (784:9): [True: 0, False: 3]
  ------------------
  785|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  786|      0|    }
  787|       |
  788|      3|    if (version != 0) {
  ------------------
  |  Branch (788:9): [True: 0, False: 3]
  ------------------
  789|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_VERSION, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  790|      0|    }
  791|       |
  792|      3|    if ((ret = pk_get_pk_alg(&p, end, &pk_alg, &params, &ec_grp_id)) != 0) {
  ------------------
  |  Branch (792:9): [True: 0, False: 3]
  ------------------
  793|      0|        return ret;
  794|      0|    }
  795|       |
  796|      3|    if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_OCTET_STRING)) != 0) {
  ------------------
  |  |   67|      3|#define MBEDTLS_ASN1_OCTET_STRING            0x04
  ------------------
  |  Branch (796:9): [True: 0, False: 3]
  ------------------
  797|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  798|      0|    }
  799|       |
  800|      3|    if (len < 1) {
  ------------------
  |  Branch (800:9): [True: 0, False: 3]
  ------------------
  801|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT,
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  802|      0|                                 MBEDTLS_ERR_ASN1_OUT_OF_DATA);
  803|      0|    }
  804|       |
  805|      3|    if ((pk_info = mbedtls_pk_info_from_type(pk_alg)) == NULL) {
  ------------------
  |  Branch (805:9): [True: 0, False: 3]
  ------------------
  806|      0|        return MBEDTLS_ERR_PK_UNKNOWN_PK_ALG;
  ------------------
  |  |   48|      0|#define MBEDTLS_ERR_PK_UNKNOWN_PK_ALG      -0x3C80
  ------------------
  807|      0|    }
  808|       |
  809|      3|    if ((ret = mbedtls_pk_setup(pk, pk_info)) != 0) {
  ------------------
  |  Branch (809:9): [True: 0, False: 3]
  ------------------
  810|      0|        return ret;
  811|      0|    }
  812|       |
  813|      3|#if defined(MBEDTLS_RSA_C)
  814|      3|    if (pk_alg == MBEDTLS_PK_RSA) {
  ------------------
  |  Branch (814:9): [True: 0, False: 3]
  ------------------
  815|      0|        if ((ret = mbedtls_rsa_parse_key(mbedtls_pk_rsa(*pk), p, len)) != 0) {
  ------------------
  |  Branch (815:13): [True: 0, False: 0]
  ------------------
  816|      0|            mbedtls_pk_free(pk);
  817|      0|            return ret;
  818|      0|        }
  819|      0|    } else
  820|      3|#endif /* MBEDTLS_RSA_C */
  821|      3|#if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
  822|      3|    if (pk_alg == MBEDTLS_PK_ECKEY || pk_alg == MBEDTLS_PK_ECKEY_DH) {
  ------------------
  |  Branch (822:9): [True: 3, False: 0]
  |  Branch (822:39): [True: 0, False: 0]
  ------------------
  823|      3|#if defined(MBEDTLS_PK_HAVE_RFC8410_CURVES)
  824|      3|        if (MBEDTLS_PK_IS_RFC8410_GROUP_ID(ec_grp_id)) {
  ------------------
  |  |  122|      3|    ((id == MBEDTLS_ECP_DP_CURVE25519) || (id == MBEDTLS_ECP_DP_CURVE448))
  |  |  ------------------
  |  |  |  Branch (122:6): [True: 0, False: 3]
  |  |  |  Branch (122:43): [True: 0, False: 3]
  |  |  ------------------
  ------------------
  825|      0|            if ((ret =
  ------------------
  |  Branch (825:17): [True: 0, False: 0]
  ------------------
  826|      0|                     pk_use_ecparams_rfc8410(&params, ec_grp_id, pk)) != 0 ||
  827|      0|                (ret =
  ------------------
  |  Branch (827:17): [True: 0, False: 0]
  ------------------
  828|      0|                     pk_parse_key_rfc8410_der(pk, p, len, end, f_rng,
  829|      0|                                              p_rng)) != 0) {
  830|      0|                mbedtls_pk_free(pk);
  831|      0|                return ret;
  832|      0|            }
  833|      0|        } else
  834|      3|#endif
  835|      3|        {
  836|      3|            if ((ret = pk_use_ecparams(&params, pk)) != 0 ||
  ------------------
  |  Branch (836:17): [True: 0, False: 3]
  ------------------
  837|      3|                (ret = pk_parse_key_sec1_der(pk, p, len, f_rng, p_rng)) != 0) {
  ------------------
  |  Branch (837:17): [True: 0, False: 3]
  ------------------
  838|      0|                mbedtls_pk_free(pk);
  839|      0|                return ret;
  840|      0|            }
  841|      3|        }
  842|      3|    } else
  843|      0|#endif /* MBEDTLS_PK_HAVE_ECC_KEYS */
  844|      0|    return MBEDTLS_ERR_PK_UNKNOWN_PK_ALG;
  ------------------
  |  |   48|      0|#define MBEDTLS_ERR_PK_UNKNOWN_PK_ALG      -0x3C80
  ------------------
  845|       |
  846|      3|    end = p + len;
  847|      3|    if (end != (key + keylen)) {
  ------------------
  |  Branch (847:9): [True: 0, False: 3]
  ------------------
  848|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT,
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  849|      0|                                 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
  850|      0|    }
  851|       |
  852|      3|    return 0;
  853|      3|}

mbedtls_zeroize_and_free:
  140|  3.43M|{
  141|  3.43M|    if (buf != NULL) {
  ------------------
  |  Branch (141:9): [True: 3.43M, False: 0]
  ------------------
  142|  3.43M|        mbedtls_platform_zeroize(buf, len);
  143|  3.43M|    }
  144|       |
  145|  3.43M|    mbedtls_free(buf);
  ------------------
  |  |  143|  3.43M|#define mbedtls_free       MBEDTLS_PLATFORM_FREE_MACRO
  |  |  ------------------
  |  |  |  | 4095|  3.43M|#define MBEDTLS_PLATFORM_FREE_MACRO            my_free
  |  |  ------------------
  ------------------
  146|  3.43M|}
mbedtls_platform_gmtime_r:
  178|  3.16k|{
  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|  3.16k|}

mbedtls_sha256_init:
  226|  3.17k|{
  227|  3.17k|    memset(ctx, 0, sizeof(mbedtls_sha256_context));
  228|  3.17k|}
mbedtls_sha256_free:
  231|  6.35k|{
  232|  6.35k|    if (ctx == NULL) {
  ------------------
  |  Branch (232:9): [True: 0, False: 6.35k]
  ------------------
  233|      0|        return;
  234|      0|    }
  235|       |
  236|  6.35k|    mbedtls_platform_zeroize(ctx, sizeof(mbedtls_sha256_context));
  237|  6.35k|}
mbedtls_sha256_starts:
  249|  3.17k|{
  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|  3.17k|    if (is224 != 0) {
  ------------------
  |  Branch (255:9): [True: 0, False: 3.17k]
  ------------------
  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|  3.17k|    ctx->total[0] = 0;
  265|  3.17k|    ctx->total[1] = 0;
  266|       |
  267|  3.17k|    if (is224 == 0) {
  ------------------
  |  Branch (267:9): [True: 3.17k, False: 0]
  ------------------
  268|  3.17k|#if defined(MBEDTLS_SHA256_C)
  269|  3.17k|        ctx->state[0] = 0x6A09E667;
  270|  3.17k|        ctx->state[1] = 0xBB67AE85;
  271|  3.17k|        ctx->state[2] = 0x3C6EF372;
  272|  3.17k|        ctx->state[3] = 0xA54FF53A;
  273|  3.17k|        ctx->state[4] = 0x510E527F;
  274|  3.17k|        ctx->state[5] = 0x9B05688C;
  275|  3.17k|        ctx->state[6] = 0x1F83D9AB;
  276|  3.17k|        ctx->state[7] = 0x5BE0CD19;
  277|  3.17k|#endif
  278|  3.17k|    } 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|  3.17k|    return 0;
  296|  3.17k|}
mbedtls_internal_sha256_process:
  494|  21.1k|{
  495|  21.1k|    struct {
  496|  21.1k|        uint32_t temp1, temp2, W[64];
  497|  21.1k|        uint32_t A[8];
  498|  21.1k|    } local;
  499|       |
  500|  21.1k|    unsigned int i;
  501|       |
  502|   190k|    for (i = 0; i < 8; i++) {
  ------------------
  |  Branch (502:17): [True: 169k, False: 21.1k]
  ------------------
  503|   169k|        local.A[i] = ctx->state[i];
  504|   169k|    }
  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|   360k|    for (i = 0; i < 16; i++) {
  ------------------
  |  Branch (524:17): [True: 339k, False: 21.1k]
  ------------------
  525|   339k|        local.W[i] = MBEDTLS_GET_UINT32_BE(data, 4 * i);
  ------------------
  |  |  413|   339k|    ((MBEDTLS_IS_BIG_ENDIAN)                                               \
  |  |  ------------------
  |  |  |  |  398|   339k|#define MBEDTLS_IS_BIG_ENDIAN 0
  |  |  ------------------
  |  |  |  Branch (413:6): [Folded - Ignored]
  |  |  ------------------
  |  |  414|   339k|        ? mbedtls_get_unaligned_uint32((data) + (offset))                  \
  |  |  415|   339k|        : MBEDTLS_BSWAP32(mbedtls_get_unaligned_uint32((data) + (offset))) \
  |  |  ------------------
  |  |  |  |  298|   339k|#define MBEDTLS_BSWAP32 __builtin_bswap32
  |  |  ------------------
  |  |  416|   339k|    )
  ------------------
  526|   339k|    }
  527|       |
  528|  63.5k|    for (i = 0; i < 16; i += 8) {
  ------------------
  |  Branch (528:17): [True: 42.3k, False: 21.1k]
  ------------------
  529|  42.3k|        P(local.A[0], local.A[1], local.A[2], local.A[3], local.A[4],
  ------------------
  |  |  478|  42.3k|    do                                                              \
  |  |  479|  42.3k|    {                                                               \
  |  |  480|  42.3k|        local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  466|  42.3k|#define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  469|  42.3k|#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
  |  |  ------------------
  |  |  481|  42.3k|        local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  465|  42.3k|#define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  468|  42.3k|#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
  |  |  ------------------
  |  |  482|  42.3k|        (d) += local.temp1; (h) = local.temp1 + local.temp2;        \
  |  |  483|  42.3k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (483:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  530|  42.3k|          local.A[5], local.A[6], local.A[7], local.W[i+0], K[i+0]);
  531|  42.3k|        P(local.A[7], local.A[0], local.A[1], local.A[2], local.A[3],
  ------------------
  |  |  478|  42.3k|    do                                                              \
  |  |  479|  42.3k|    {                                                               \
  |  |  480|  42.3k|        local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  466|  42.3k|#define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  469|  42.3k|#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
  |  |  ------------------
  |  |  481|  42.3k|        local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  465|  42.3k|#define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  468|  42.3k|#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
  |  |  ------------------
  |  |  482|  42.3k|        (d) += local.temp1; (h) = local.temp1 + local.temp2;        \
  |  |  483|  42.3k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (483:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  532|  42.3k|          local.A[4], local.A[5], local.A[6], local.W[i+1], K[i+1]);
  533|  42.3k|        P(local.A[6], local.A[7], local.A[0], local.A[1], local.A[2],
  ------------------
  |  |  478|  42.3k|    do                                                              \
  |  |  479|  42.3k|    {                                                               \
  |  |  480|  42.3k|        local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  466|  42.3k|#define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  469|  42.3k|#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
  |  |  ------------------
  |  |  481|  42.3k|        local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  465|  42.3k|#define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  468|  42.3k|#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
  |  |  ------------------
  |  |  482|  42.3k|        (d) += local.temp1; (h) = local.temp1 + local.temp2;        \
  |  |  483|  42.3k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (483:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  534|  42.3k|          local.A[3], local.A[4], local.A[5], local.W[i+2], K[i+2]);
  535|  42.3k|        P(local.A[5], local.A[6], local.A[7], local.A[0], local.A[1],
  ------------------
  |  |  478|  42.3k|    do                                                              \
  |  |  479|  42.3k|    {                                                               \
  |  |  480|  42.3k|        local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  466|  42.3k|#define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  469|  42.3k|#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
  |  |  ------------------
  |  |  481|  42.3k|        local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  465|  42.3k|#define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  468|  42.3k|#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
  |  |  ------------------
  |  |  482|  42.3k|        (d) += local.temp1; (h) = local.temp1 + local.temp2;        \
  |  |  483|  42.3k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (483:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  536|  42.3k|          local.A[2], local.A[3], local.A[4], local.W[i+3], K[i+3]);
  537|  42.3k|        P(local.A[4], local.A[5], local.A[6], local.A[7], local.A[0],
  ------------------
  |  |  478|  42.3k|    do                                                              \
  |  |  479|  42.3k|    {                                                               \
  |  |  480|  42.3k|        local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  466|  42.3k|#define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  469|  42.3k|#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
  |  |  ------------------
  |  |  481|  42.3k|        local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  465|  42.3k|#define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  468|  42.3k|#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
  |  |  ------------------
  |  |  482|  42.3k|        (d) += local.temp1; (h) = local.temp1 + local.temp2;        \
  |  |  483|  42.3k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (483:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  538|  42.3k|          local.A[1], local.A[2], local.A[3], local.W[i+4], K[i+4]);
  539|  42.3k|        P(local.A[3], local.A[4], local.A[5], local.A[6], local.A[7],
  ------------------
  |  |  478|  42.3k|    do                                                              \
  |  |  479|  42.3k|    {                                                               \
  |  |  480|  42.3k|        local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  466|  42.3k|#define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  469|  42.3k|#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
  |  |  ------------------
  |  |  481|  42.3k|        local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  465|  42.3k|#define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  468|  42.3k|#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
  |  |  ------------------
  |  |  482|  42.3k|        (d) += local.temp1; (h) = local.temp1 + local.temp2;        \
  |  |  483|  42.3k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (483:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  540|  42.3k|          local.A[0], local.A[1], local.A[2], local.W[i+5], K[i+5]);
  541|  42.3k|        P(local.A[2], local.A[3], local.A[4], local.A[5], local.A[6],
  ------------------
  |  |  478|  42.3k|    do                                                              \
  |  |  479|  42.3k|    {                                                               \
  |  |  480|  42.3k|        local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  466|  42.3k|#define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  469|  42.3k|#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
  |  |  ------------------
  |  |  481|  42.3k|        local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  465|  42.3k|#define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  468|  42.3k|#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
  |  |  ------------------
  |  |  482|  42.3k|        (d) += local.temp1; (h) = local.temp1 + local.temp2;        \
  |  |  483|  42.3k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (483:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  542|  42.3k|          local.A[7], local.A[0], local.A[1], local.W[i+6], K[i+6]);
  543|  42.3k|        P(local.A[1], local.A[2], local.A[3], local.A[4], local.A[5],
  ------------------
  |  |  478|  42.3k|    do                                                              \
  |  |  479|  42.3k|    {                                                               \
  |  |  480|  42.3k|        local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  466|  42.3k|#define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  469|  42.3k|#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
  |  |  ------------------
  |  |  481|  42.3k|        local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  465|  42.3k|#define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|  42.3k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|  42.3k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  468|  42.3k|#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
  |  |  ------------------
  |  |  482|  42.3k|        (d) += local.temp1; (h) = local.temp1 + local.temp2;        \
  |  |  483|  42.3k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (483:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  544|  42.3k|          local.A[6], local.A[7], local.A[0], local.W[i+7], K[i+7]);
  545|  42.3k|    }
  546|       |
  547|   148k|    for (i = 16; i < 64; i += 8) {
  ------------------
  |  Branch (547:18): [True: 127k, False: 21.1k]
  ------------------
  548|   127k|        P(local.A[0], local.A[1], local.A[2], local.A[3], local.A[4],
  ------------------
  |  |  478|   127k|    do                                                              \
  |  |  479|   127k|    {                                                               \
  |  |  480|   127k|        local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  466|   127k|#define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  469|   127k|#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
  |  |  ------------------
  |  |  481|   127k|        local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  465|   127k|#define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  468|   127k|#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
  |  |  ------------------
  |  |  482|   127k|        (d) += local.temp1; (h) = local.temp1 + local.temp2;        \
  |  |  483|   127k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (483:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  549|   127k|          local.A[5], local.A[6], local.A[7], R(i+0), K[i+0]);
  550|   127k|        P(local.A[7], local.A[0], local.A[1], local.A[2], local.A[3],
  ------------------
  |  |  478|   127k|    do                                                              \
  |  |  479|   127k|    {                                                               \
  |  |  480|   127k|        local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  466|   127k|#define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  469|   127k|#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
  |  |  ------------------
  |  |  481|   127k|        local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  465|   127k|#define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  468|   127k|#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
  |  |  ------------------
  |  |  482|   127k|        (d) += local.temp1; (h) = local.temp1 + local.temp2;        \
  |  |  483|   127k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (483:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  551|   127k|          local.A[4], local.A[5], local.A[6], R(i+1), K[i+1]);
  552|   127k|        P(local.A[6], local.A[7], local.A[0], local.A[1], local.A[2],
  ------------------
  |  |  478|   127k|    do                                                              \
  |  |  479|   127k|    {                                                               \
  |  |  480|   127k|        local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  466|   127k|#define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  469|   127k|#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
  |  |  ------------------
  |  |  481|   127k|        local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  465|   127k|#define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  468|   127k|#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
  |  |  ------------------
  |  |  482|   127k|        (d) += local.temp1; (h) = local.temp1 + local.temp2;        \
  |  |  483|   127k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (483:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  553|   127k|          local.A[3], local.A[4], local.A[5], R(i+2), K[i+2]);
  554|   127k|        P(local.A[5], local.A[6], local.A[7], local.A[0], local.A[1],
  ------------------
  |  |  478|   127k|    do                                                              \
  |  |  479|   127k|    {                                                               \
  |  |  480|   127k|        local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  466|   127k|#define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  469|   127k|#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
  |  |  ------------------
  |  |  481|   127k|        local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  465|   127k|#define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  468|   127k|#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
  |  |  ------------------
  |  |  482|   127k|        (d) += local.temp1; (h) = local.temp1 + local.temp2;        \
  |  |  483|   127k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (483:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  555|   127k|          local.A[2], local.A[3], local.A[4], R(i+3), K[i+3]);
  556|   127k|        P(local.A[4], local.A[5], local.A[6], local.A[7], local.A[0],
  ------------------
  |  |  478|   127k|    do                                                              \
  |  |  479|   127k|    {                                                               \
  |  |  480|   127k|        local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  466|   127k|#define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  469|   127k|#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
  |  |  ------------------
  |  |  481|   127k|        local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  465|   127k|#define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  468|   127k|#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
  |  |  ------------------
  |  |  482|   127k|        (d) += local.temp1; (h) = local.temp1 + local.temp2;        \
  |  |  483|   127k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (483:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  557|   127k|          local.A[1], local.A[2], local.A[3], R(i+4), K[i+4]);
  558|   127k|        P(local.A[3], local.A[4], local.A[5], local.A[6], local.A[7],
  ------------------
  |  |  478|   127k|    do                                                              \
  |  |  479|   127k|    {                                                               \
  |  |  480|   127k|        local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  466|   127k|#define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  469|   127k|#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
  |  |  ------------------
  |  |  481|   127k|        local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  465|   127k|#define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  468|   127k|#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
  |  |  ------------------
  |  |  482|   127k|        (d) += local.temp1; (h) = local.temp1 + local.temp2;        \
  |  |  483|   127k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (483:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  559|   127k|          local.A[0], local.A[1], local.A[2], R(i+5), K[i+5]);
  560|   127k|        P(local.A[2], local.A[3], local.A[4], local.A[5], local.A[6],
  ------------------
  |  |  478|   127k|    do                                                              \
  |  |  479|   127k|    {                                                               \
  |  |  480|   127k|        local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  466|   127k|#define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  469|   127k|#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
  |  |  ------------------
  |  |  481|   127k|        local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  465|   127k|#define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  468|   127k|#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
  |  |  ------------------
  |  |  482|   127k|        (d) += local.temp1; (h) = local.temp1 + local.temp2;        \
  |  |  483|   127k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (483:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  561|   127k|          local.A[7], local.A[0], local.A[1], R(i+6), K[i+6]);
  562|   127k|        P(local.A[1], local.A[2], local.A[3], local.A[4], local.A[5],
  ------------------
  |  |  478|   127k|    do                                                              \
  |  |  479|   127k|    {                                                               \
  |  |  480|   127k|        local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  466|   127k|#define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  469|   127k|#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
  |  |  ------------------
  |  |  481|   127k|        local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  465|   127k|#define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |  460|   127k|#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  459|   127k|#define  SHR(x, n) (((x) & 0xFFFFFFFF) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  468|   127k|#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
  |  |  ------------------
  |  |  482|   127k|        (d) += local.temp1; (h) = local.temp1 + local.temp2;        \
  |  |  483|   127k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (483:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  563|   127k|          local.A[6], local.A[7], local.A[0], R(i+7), K[i+7]);
  564|   127k|    }
  565|  21.1k|#endif /* MBEDTLS_SHA256_SMALLER */
  566|       |
  567|   190k|    for (i = 0; i < 8; i++) {
  ------------------
  |  Branch (567:17): [True: 169k, False: 21.1k]
  ------------------
  568|   169k|        ctx->state[i] += local.A[i];
  569|   169k|    }
  570|       |
  571|       |    /* Zeroise buffers and variables to clear sensitive data from memory. */
  572|  21.1k|    mbedtls_platform_zeroize(&local, sizeof(local));
  573|       |
  574|  21.1k|    return 0;
  575|  21.1k|}
mbedtls_sha256_update:
  648|  3.18k|{
  649|  3.18k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  3.18k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  650|  3.18k|    size_t fill;
  651|  3.18k|    uint32_t left;
  652|       |
  653|  3.18k|    if (ilen == 0) {
  ------------------
  |  Branch (653:9): [True: 3, False: 3.17k]
  ------------------
  654|      3|        return 0;
  655|      3|    }
  656|       |
  657|  3.17k|    left = ctx->total[0] & 0x3F;
  658|  3.17k|    fill = SHA256_BLOCK_SIZE - left;
  ------------------
  |  |  223|  3.17k|#define SHA256_BLOCK_SIZE 64
  ------------------
  659|       |
  660|  3.17k|    ctx->total[0] += (uint32_t) ilen;
  661|  3.17k|    ctx->total[0] &= 0xFFFFFFFF;
  662|       |
  663|  3.17k|    if (ctx->total[0] < (uint32_t) ilen) {
  ------------------
  |  Branch (663:9): [True: 0, False: 3.17k]
  ------------------
  664|      0|        ctx->total[1]++;
  665|      0|    }
  666|       |
  667|  3.17k|    if (left && ilen >= fill) {
  ------------------
  |  Branch (667:9): [True: 3, False: 3.17k]
  |  Branch (667:17): [True: 3, False: 0]
  ------------------
  668|      3|        memcpy((void *) (ctx->buffer + left), input, fill);
  669|       |
  670|      3|        if ((ret = mbedtls_internal_sha256_process(ctx, ctx->buffer)) != 0) {
  ------------------
  |  Branch (670:13): [True: 0, False: 3]
  ------------------
  671|      0|            return ret;
  672|      0|        }
  673|       |
  674|      3|        input += fill;
  675|      3|        ilen  -= fill;
  676|      3|        left = 0;
  677|      3|    }
  678|       |
  679|  6.34k|    while (ilen >= SHA256_BLOCK_SIZE) {
  ------------------
  |  |  223|  6.34k|#define SHA256_BLOCK_SIZE 64
  ------------------
  |  Branch (679:12): [True: 3.17k, False: 3.17k]
  ------------------
  680|  3.17k|        size_t processed =
  681|  3.17k|            mbedtls_internal_sha256_process_many(ctx, input, ilen);
  682|  3.17k|        if (processed < SHA256_BLOCK_SIZE) {
  ------------------
  |  |  223|  3.17k|#define SHA256_BLOCK_SIZE 64
  ------------------
  |  Branch (682:13): [True: 0, False: 3.17k]
  ------------------
  683|      0|            return MBEDTLS_ERR_ERROR_GENERIC_ERROR;
  ------------------
  |  |   98|      0|#define MBEDTLS_ERR_ERROR_GENERIC_ERROR       -0x0001
  ------------------
  684|      0|        }
  685|       |
  686|  3.17k|        input += processed;
  687|  3.17k|        ilen  -= processed;
  688|  3.17k|    }
  689|       |
  690|  3.17k|    if (ilen > 0) {
  ------------------
  |  Branch (690:9): [True: 3.17k, False: 0]
  ------------------
  691|  3.17k|        memcpy((void *) (ctx->buffer + left), input, ilen);
  692|  3.17k|    }
  693|       |
  694|  3.17k|    return 0;
  695|  3.17k|}
mbedtls_sha256_finish:
  702|  3.17k|{
  703|  3.17k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  3.17k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  704|  3.17k|    uint32_t used;
  705|  3.17k|    uint32_t high, low;
  706|  3.17k|    int truncated = 0;
  707|       |
  708|       |    /*
  709|       |     * Add padding: 0x80 then 0x00 until 8 bytes remain for the length
  710|       |     */
  711|  3.17k|    used = ctx->total[0] & 0x3F;
  712|       |
  713|  3.17k|    ctx->buffer[used++] = 0x80;
  714|       |
  715|  3.17k|    if (used <= 56) {
  ------------------
  |  Branch (715:9): [True: 3.17k, False: 0]
  ------------------
  716|       |        /* Enough room for padding + length in current block */
  717|  3.17k|        memset(ctx->buffer + used, 0, 56 - used);
  718|  3.17k|    } 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|  3.17k|    high = (ctx->total[0] >> 29)
  733|  3.17k|           | (ctx->total[1] <<  3);
  734|  3.17k|    low  = (ctx->total[0] <<  3);
  735|       |
  736|  3.17k|    MBEDTLS_PUT_UINT32_BE(high, ctx->buffer, 56);
  ------------------
  |  |  428|  3.17k|    {                                                                            \
  |  |  429|  3.17k|        if (MBEDTLS_IS_BIG_ENDIAN)                                               \
  |  |  ------------------
  |  |  |  |  398|  3.17k|#define MBEDTLS_IS_BIG_ENDIAN 0
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (398:31): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  430|  3.17k|        {                                                                        \
  |  |  431|      0|            mbedtls_put_unaligned_uint32((data) + (offset), (uint32_t) (n));     \
  |  |  432|      0|        }                                                                        \
  |  |  433|  3.17k|        else                                                                     \
  |  |  434|  3.17k|        {                                                                        \
  |  |  435|  3.17k|            mbedtls_put_unaligned_uint32((data) + (offset), MBEDTLS_BSWAP32((uint32_t) (n))); \
  |  |  ------------------
  |  |  |  |  298|  3.17k|#define MBEDTLS_BSWAP32 __builtin_bswap32
  |  |  ------------------
  |  |  436|  3.17k|        }                                                                        \
  |  |  437|  3.17k|    }
  ------------------
  737|  3.17k|    MBEDTLS_PUT_UINT32_BE(low,  ctx->buffer, 60);
  ------------------
  |  |  428|  3.17k|    {                                                                            \
  |  |  429|  3.17k|        if (MBEDTLS_IS_BIG_ENDIAN)                                               \
  |  |  ------------------
  |  |  |  |  398|  3.17k|#define MBEDTLS_IS_BIG_ENDIAN 0
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (398:31): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  430|  3.17k|        {                                                                        \
  |  |  431|      0|            mbedtls_put_unaligned_uint32((data) + (offset), (uint32_t) (n));     \
  |  |  432|      0|        }                                                                        \
  |  |  433|  3.17k|        else                                                                     \
  |  |  434|  3.17k|        {                                                                        \
  |  |  435|  3.17k|            mbedtls_put_unaligned_uint32((data) + (offset), MBEDTLS_BSWAP32((uint32_t) (n))); \
  |  |  ------------------
  |  |  |  |  298|  3.17k|#define MBEDTLS_BSWAP32 __builtin_bswap32
  |  |  ------------------
  |  |  436|  3.17k|        }                                                                        \
  |  |  437|  3.17k|    }
  ------------------
  738|       |
  739|  3.17k|    if ((ret = mbedtls_internal_sha256_process(ctx, ctx->buffer)) != 0) {
  ------------------
  |  Branch (739:9): [True: 0, False: 3.17k]
  ------------------
  740|      0|        goto exit;
  741|      0|    }
  742|       |
  743|       |    /*
  744|       |     * Output final state
  745|       |     */
  746|  3.17k|    MBEDTLS_PUT_UINT32_BE(ctx->state[0], output,  0);
  ------------------
  |  |  428|  3.17k|    {                                                                            \
  |  |  429|  3.17k|        if (MBEDTLS_IS_BIG_ENDIAN)                                               \
  |  |  ------------------
  |  |  |  |  398|  3.17k|#define MBEDTLS_IS_BIG_ENDIAN 0
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (398:31): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  430|  3.17k|        {                                                                        \
  |  |  431|      0|            mbedtls_put_unaligned_uint32((data) + (offset), (uint32_t) (n));     \
  |  |  432|      0|        }                                                                        \
  |  |  433|  3.17k|        else                                                                     \
  |  |  434|  3.17k|        {                                                                        \
  |  |  435|  3.17k|            mbedtls_put_unaligned_uint32((data) + (offset), MBEDTLS_BSWAP32((uint32_t) (n))); \
  |  |  ------------------
  |  |  |  |  298|  3.17k|#define MBEDTLS_BSWAP32 __builtin_bswap32
  |  |  ------------------
  |  |  436|  3.17k|        }                                                                        \
  |  |  437|  3.17k|    }
  ------------------
  747|  3.17k|    MBEDTLS_PUT_UINT32_BE(ctx->state[1], output,  4);
  ------------------
  |  |  428|  3.17k|    {                                                                            \
  |  |  429|  3.17k|        if (MBEDTLS_IS_BIG_ENDIAN)                                               \
  |  |  ------------------
  |  |  |  |  398|  3.17k|#define MBEDTLS_IS_BIG_ENDIAN 0
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (398:31): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  430|  3.17k|        {                                                                        \
  |  |  431|      0|            mbedtls_put_unaligned_uint32((data) + (offset), (uint32_t) (n));     \
  |  |  432|      0|        }                                                                        \
  |  |  433|  3.17k|        else                                                                     \
  |  |  434|  3.17k|        {                                                                        \
  |  |  435|  3.17k|            mbedtls_put_unaligned_uint32((data) + (offset), MBEDTLS_BSWAP32((uint32_t) (n))); \
  |  |  ------------------
  |  |  |  |  298|  3.17k|#define MBEDTLS_BSWAP32 __builtin_bswap32
  |  |  ------------------
  |  |  436|  3.17k|        }                                                                        \
  |  |  437|  3.17k|    }
  ------------------
  748|  3.17k|    MBEDTLS_PUT_UINT32_BE(ctx->state[2], output,  8);
  ------------------
  |  |  428|  3.17k|    {                                                                            \
  |  |  429|  3.17k|        if (MBEDTLS_IS_BIG_ENDIAN)                                               \
  |  |  ------------------
  |  |  |  |  398|  3.17k|#define MBEDTLS_IS_BIG_ENDIAN 0
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (398:31): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  430|  3.17k|        {                                                                        \
  |  |  431|      0|            mbedtls_put_unaligned_uint32((data) + (offset), (uint32_t) (n));     \
  |  |  432|      0|        }                                                                        \
  |  |  433|  3.17k|        else                                                                     \
  |  |  434|  3.17k|        {                                                                        \
  |  |  435|  3.17k|            mbedtls_put_unaligned_uint32((data) + (offset), MBEDTLS_BSWAP32((uint32_t) (n))); \
  |  |  ------------------
  |  |  |  |  298|  3.17k|#define MBEDTLS_BSWAP32 __builtin_bswap32
  |  |  ------------------
  |  |  436|  3.17k|        }                                                                        \
  |  |  437|  3.17k|    }
  ------------------
  749|  3.17k|    MBEDTLS_PUT_UINT32_BE(ctx->state[3], output, 12);
  ------------------
  |  |  428|  3.17k|    {                                                                            \
  |  |  429|  3.17k|        if (MBEDTLS_IS_BIG_ENDIAN)                                               \
  |  |  ------------------
  |  |  |  |  398|  3.17k|#define MBEDTLS_IS_BIG_ENDIAN 0
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (398:31): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  430|  3.17k|        {                                                                        \
  |  |  431|      0|            mbedtls_put_unaligned_uint32((data) + (offset), (uint32_t) (n));     \
  |  |  432|      0|        }                                                                        \
  |  |  433|  3.17k|        else                                                                     \
  |  |  434|  3.17k|        {                                                                        \
  |  |  435|  3.17k|            mbedtls_put_unaligned_uint32((data) + (offset), MBEDTLS_BSWAP32((uint32_t) (n))); \
  |  |  ------------------
  |  |  |  |  298|  3.17k|#define MBEDTLS_BSWAP32 __builtin_bswap32
  |  |  ------------------
  |  |  436|  3.17k|        }                                                                        \
  |  |  437|  3.17k|    }
  ------------------
  750|  3.17k|    MBEDTLS_PUT_UINT32_BE(ctx->state[4], output, 16);
  ------------------
  |  |  428|  3.17k|    {                                                                            \
  |  |  429|  3.17k|        if (MBEDTLS_IS_BIG_ENDIAN)                                               \
  |  |  ------------------
  |  |  |  |  398|  3.17k|#define MBEDTLS_IS_BIG_ENDIAN 0
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (398:31): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  430|  3.17k|        {                                                                        \
  |  |  431|      0|            mbedtls_put_unaligned_uint32((data) + (offset), (uint32_t) (n));     \
  |  |  432|      0|        }                                                                        \
  |  |  433|  3.17k|        else                                                                     \
  |  |  434|  3.17k|        {                                                                        \
  |  |  435|  3.17k|            mbedtls_put_unaligned_uint32((data) + (offset), MBEDTLS_BSWAP32((uint32_t) (n))); \
  |  |  ------------------
  |  |  |  |  298|  3.17k|#define MBEDTLS_BSWAP32 __builtin_bswap32
  |  |  ------------------
  |  |  436|  3.17k|        }                                                                        \
  |  |  437|  3.17k|    }
  ------------------
  751|  3.17k|    MBEDTLS_PUT_UINT32_BE(ctx->state[5], output, 20);
  ------------------
  |  |  428|  3.17k|    {                                                                            \
  |  |  429|  3.17k|        if (MBEDTLS_IS_BIG_ENDIAN)                                               \
  |  |  ------------------
  |  |  |  |  398|  3.17k|#define MBEDTLS_IS_BIG_ENDIAN 0
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (398:31): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  430|  3.17k|        {                                                                        \
  |  |  431|      0|            mbedtls_put_unaligned_uint32((data) + (offset), (uint32_t) (n));     \
  |  |  432|      0|        }                                                                        \
  |  |  433|  3.17k|        else                                                                     \
  |  |  434|  3.17k|        {                                                                        \
  |  |  435|  3.17k|            mbedtls_put_unaligned_uint32((data) + (offset), MBEDTLS_BSWAP32((uint32_t) (n))); \
  |  |  ------------------
  |  |  |  |  298|  3.17k|#define MBEDTLS_BSWAP32 __builtin_bswap32
  |  |  ------------------
  |  |  436|  3.17k|        }                                                                        \
  |  |  437|  3.17k|    }
  ------------------
  752|  3.17k|    MBEDTLS_PUT_UINT32_BE(ctx->state[6], output, 24);
  ------------------
  |  |  428|  3.17k|    {                                                                            \
  |  |  429|  3.17k|        if (MBEDTLS_IS_BIG_ENDIAN)                                               \
  |  |  ------------------
  |  |  |  |  398|  3.17k|#define MBEDTLS_IS_BIG_ENDIAN 0
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (398:31): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  430|  3.17k|        {                                                                        \
  |  |  431|      0|            mbedtls_put_unaligned_uint32((data) + (offset), (uint32_t) (n));     \
  |  |  432|      0|        }                                                                        \
  |  |  433|  3.17k|        else                                                                     \
  |  |  434|  3.17k|        {                                                                        \
  |  |  435|  3.17k|            mbedtls_put_unaligned_uint32((data) + (offset), MBEDTLS_BSWAP32((uint32_t) (n))); \
  |  |  ------------------
  |  |  |  |  298|  3.17k|#define MBEDTLS_BSWAP32 __builtin_bswap32
  |  |  ------------------
  |  |  436|  3.17k|        }                                                                        \
  |  |  437|  3.17k|    }
  ------------------
  753|       |
  754|       |#if defined(MBEDTLS_SHA224_C)
  755|       |    truncated = ctx->is224;
  756|       |#endif
  757|  3.17k|    if (!truncated) {
  ------------------
  |  Branch (757:9): [True: 3.17k, False: 0]
  ------------------
  758|  3.17k|        MBEDTLS_PUT_UINT32_BE(ctx->state[7], output, 28);
  ------------------
  |  |  428|  3.17k|    {                                                                            \
  |  |  429|  3.17k|        if (MBEDTLS_IS_BIG_ENDIAN)                                               \
  |  |  ------------------
  |  |  |  |  398|  3.17k|#define MBEDTLS_IS_BIG_ENDIAN 0
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (398:31): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  430|  3.17k|        {                                                                        \
  |  |  431|      0|            mbedtls_put_unaligned_uint32((data) + (offset), (uint32_t) (n));     \
  |  |  432|      0|        }                                                                        \
  |  |  433|  3.17k|        else                                                                     \
  |  |  434|  3.17k|        {                                                                        \
  |  |  435|  3.17k|            mbedtls_put_unaligned_uint32((data) + (offset), MBEDTLS_BSWAP32((uint32_t) (n))); \
  |  |  ------------------
  |  |  |  |  298|  3.17k|#define MBEDTLS_BSWAP32 __builtin_bswap32
  |  |  ------------------
  |  |  436|  3.17k|        }                                                                        \
  |  |  437|  3.17k|    }
  ------------------
  759|  3.17k|    }
  760|       |
  761|  3.17k|    ret = 0;
  762|       |
  763|  3.17k|exit:
  764|  3.17k|    mbedtls_sha256_free(ctx);
  765|  3.17k|    return ret;
  766|  3.17k|}
mbedtls_sha256:
  777|  3.17k|{
  778|  3.17k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  3.17k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  779|  3.17k|    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|  3.17k|    if (is224 != 0) {
  ------------------
  |  Branch (786:9): [True: 0, False: 3.17k]
  ------------------
  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|  3.17k|    mbedtls_sha256_init(&ctx);
  796|       |
  797|  3.17k|    if ((ret = mbedtls_sha256_starts(&ctx, is224)) != 0) {
  ------------------
  |  Branch (797:9): [True: 0, False: 3.17k]
  ------------------
  798|      0|        goto exit;
  799|      0|    }
  800|       |
  801|  3.17k|    if ((ret = mbedtls_sha256_update(&ctx, input, ilen)) != 0) {
  ------------------
  |  Branch (801:9): [True: 0, False: 3.17k]
  ------------------
  802|      0|        goto exit;
  803|      0|    }
  804|       |
  805|  3.17k|    if ((ret = mbedtls_sha256_finish(&ctx, output)) != 0) {
  ------------------
  |  Branch (805:9): [True: 0, False: 3.17k]
  ------------------
  806|      0|        goto exit;
  807|      0|    }
  808|       |
  809|  3.17k|exit:
  810|  3.17k|    mbedtls_sha256_free(&ctx);
  811|       |
  812|  3.17k|    return ret;
  813|  3.17k|}
sha256.c:mbedtls_internal_sha256_process_many:
  584|  3.17k|{
  585|  3.17k|    size_t processed = 0;
  586|       |
  587|  21.1k|    while (len >= SHA256_BLOCK_SIZE) {
  ------------------
  |  |  223|  21.1k|#define SHA256_BLOCK_SIZE 64
  ------------------
  |  Branch (587:12): [True: 18.0k, False: 3.17k]
  ------------------
  588|  18.0k|        if (mbedtls_internal_sha256_process_c(ctx, data) != 0) {
  ------------------
  |  |  452|  18.0k|#define mbedtls_internal_sha256_process_c      mbedtls_internal_sha256_process
  ------------------
  |  Branch (588:13): [True: 0, False: 18.0k]
  ------------------
  589|      0|            return 0;
  590|      0|        }
  591|       |
  592|  18.0k|        data += SHA256_BLOCK_SIZE;
  ------------------
  |  |  223|  18.0k|#define SHA256_BLOCK_SIZE 64
  ------------------
  593|  18.0k|        len  -= SHA256_BLOCK_SIZE;
  ------------------
  |  |  223|  18.0k|#define SHA256_BLOCK_SIZE 64
  ------------------
  594|       |
  595|  18.0k|        processed += SHA256_BLOCK_SIZE;
  ------------------
  |  |  223|  18.0k|#define SHA256_BLOCK_SIZE 64
  ------------------
  596|  18.0k|    }
  597|       |
  598|  3.17k|    return processed;
  599|  3.17k|}

mbedtls_x509_get_serial:
   65|  16.8k|{
   66|  16.8k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  16.8k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
   67|       |
   68|  16.8k|    if ((end - *p) < 1) {
  ------------------
  |  Branch (68:9): [True: 0, False: 16.8k]
  ------------------
   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|  16.8k|    if (**p != (MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_PRIMITIVE | 2) &&
  ------------------
  |  |   83|  16.8k|#define MBEDTLS_ASN1_CONTEXT_SPECIFIC        0x80
  ------------------
                  if (**p != (MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_PRIMITIVE | 2) &&
  ------------------
  |  |   81|  16.8k|#define MBEDTLS_ASN1_PRIMITIVE               0x00
  ------------------
  |  Branch (73:9): [True: 16.8k, False: 0]
  ------------------
   74|  16.8k|        **p !=   MBEDTLS_ASN1_INTEGER) {
  ------------------
  |  |   65|  16.8k|#define MBEDTLS_ASN1_INTEGER                 0x02
  ------------------
  |  Branch (74:9): [True: 0, False: 16.8k]
  ------------------
   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|  16.8k|    serial->tag = *(*p)++;
   80|       |
   81|  16.8k|    if ((ret = mbedtls_asn1_get_len(p, end, &serial->len)) != 0) {
  ------------------
  |  Branch (81:9): [True: 0, False: 16.8k]
  ------------------
   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|  16.8k|    serial->p = *p;
   86|  16.8k|    *p += serial->len;
   87|       |
   88|  16.8k|    return 0;
   89|  16.8k|}
mbedtls_x509_get_alg:
  114|  33.7k|{
  115|  33.7k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  33.7k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  116|       |
  117|  33.7k|    if ((ret = mbedtls_asn1_get_alg(p, end, alg, params)) != 0) {
  ------------------
  |  Branch (117:9): [True: 0, False: 33.7k]
  ------------------
  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|  33.7k|    return 0;
  122|  33.7k|}
mbedtls_x509_get_name:
  500|  33.7k|{
  501|  33.7k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  33.7k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  502|  33.7k|    size_t set_len;
  503|  33.7k|    const unsigned char *end_set;
  504|  33.7k|    mbedtls_x509_name *head = cur;
  505|       |
  506|       |    /* don't use recursion, we'd risk stack overflow if not optimized */
  507|  33.7k|    while (1) {
  ------------------
  |  Branch (507:12): [Folded - Ignored]
  ------------------
  508|       |        /*
  509|       |         * parse SET
  510|       |         */
  511|  33.7k|        if ((ret = mbedtls_asn1_get_tag(p, end, &set_len,
  ------------------
  |  Branch (511:13): [True: 0, False: 33.7k]
  ------------------
  512|  33.7k|                                        MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SET)) != 0) {
  ------------------
  |  |   82|  33.7k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                      MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SET)) != 0) {
  ------------------
  |  |   73|  33.7k|#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|  33.7k|        end_set  = *p + set_len;
  518|       |
  519|  33.7k|        while (1) {
  ------------------
  |  Branch (519:16): [Folded - Ignored]
  ------------------
  520|  33.7k|            if ((ret = x509_get_attr_type_value(p, end_set, cur)) != 0) {
  ------------------
  |  Branch (520:17): [True: 0, False: 33.7k]
  ------------------
  521|      0|                goto error;
  522|      0|            }
  523|       |
  524|  33.7k|            if (*p == end_set) {
  ------------------
  |  Branch (524:17): [True: 33.7k, False: 0]
  ------------------
  525|  33.7k|                break;
  526|  33.7k|            }
  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|  33.7k|        if (*p == end) {
  ------------------
  |  Branch (544:13): [True: 33.7k, False: 0]
  ------------------
  545|  33.7k|            return 0;
  546|  33.7k|        }
  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|  33.7k|}
mbedtls_x509_get_time:
  651|  33.7k|{
  652|  33.7k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  33.7k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  653|  33.7k|    size_t len, year_len;
  654|  33.7k|    unsigned char tag;
  655|       |
  656|  33.7k|    if ((end - *p) < 1) {
  ------------------
  |  Branch (656:9): [True: 0, False: 33.7k]
  ------------------
  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|  33.7k|    tag = **p;
  662|       |
  663|  33.7k|    if (tag == MBEDTLS_ASN1_UTC_TIME) {
  ------------------
  |  |   77|  33.7k|#define MBEDTLS_ASN1_UTC_TIME                0x17
  ------------------
  |  Branch (663:9): [True: 33.7k, False: 0]
  ------------------
  664|  33.7k|        year_len = 2;
  665|  33.7k|    } 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|  33.7k|    (*p)++;
  673|  33.7k|    ret = mbedtls_asn1_get_len(p, end, &len);
  674|       |
  675|  33.7k|    if (ret != 0) {
  ------------------
  |  Branch (675:9): [True: 0, False: 33.7k]
  ------------------
  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|  33.7k|    if (len != year_len + 10 &&
  ------------------
  |  Branch (680:9): [True: 33.7k, False: 0]
  ------------------
  681|  33.7k|        !(len == year_len + 11 && (*p)[(len - 1)] == 'Z')) {
  ------------------
  |  Branch (681:11): [True: 33.7k, False: 0]
  |  Branch (681:35): [True: 33.7k, False: 0]
  ------------------
  682|      0|        return MBEDTLS_ERR_X509_INVALID_DATE;
  ------------------
  |  |   59|      0|#define MBEDTLS_ERR_X509_INVALID_DATE                     -0x2400
  ------------------
  683|      0|    }
  684|       |
  685|  33.7k|    (*p) += len;
  686|  33.7k|    return x509_parse_time(*p - len, tm, year_len);
  687|  33.7k|}
mbedtls_x509_get_sig:
  690|  16.8k|{
  691|  16.8k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  16.8k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  692|  16.8k|    size_t len;
  693|  16.8k|    int tag_type;
  694|       |
  695|  16.8k|    if ((end - *p) < 1) {
  ------------------
  |  Branch (695:9): [True: 0, False: 16.8k]
  ------------------
  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|  16.8k|    tag_type = **p;
  701|       |
  702|  16.8k|    if ((ret = mbedtls_asn1_get_bitstring_null(p, end, &len)) != 0) {
  ------------------
  |  Branch (702:9): [True: 0, False: 16.8k]
  ------------------
  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|  16.8k|    sig->tag = tag_type;
  707|  16.8k|    sig->len = len;
  708|  16.8k|    sig->p = *p;
  709|       |
  710|  16.8k|    *p += len;
  711|       |
  712|  16.8k|    return 0;
  713|  16.8k|}
mbedtls_x509_get_sig_alg:
  721|  16.8k|{
  722|  16.8k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  16.8k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  723|       |
  724|  16.8k|    if (*sig_opts != NULL) {
  ------------------
  |  Branch (724:9): [True: 0, False: 16.8k]
  ------------------
  725|      0|        return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
  ------------------
  |  |   75|      0|#define MBEDTLS_ERR_X509_BAD_INPUT_DATA                   -0x2800
  ------------------
  726|      0|    }
  727|       |
  728|  16.8k|    if ((ret = mbedtls_oid_get_sig_alg(sig_oid, md_alg, pk_alg)) != 0) {
  ------------------
  |  Branch (728:9): [True: 0, False: 16.8k]
  ------------------
  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|  16.8k|#if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
  733|  16.8k|    if (*pk_alg == MBEDTLS_PK_RSASSA_PSS) {
  ------------------
  |  Branch (733:9): [True: 0, False: 16.8k]
  ------------------
  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|  16.8k|#endif /* MBEDTLS_X509_RSASSA_PSS_SUPPORT */
  753|  16.8k|    {
  754|       |        /* Make sure parameters are absent or NULL */
  755|  16.8k|        if ((sig_params->tag != MBEDTLS_ASN1_NULL && sig_params->tag != 0) ||
  ------------------
  |  |   68|  33.7k|#define MBEDTLS_ASN1_NULL                    0x05
  ------------------
  |  Branch (755:14): [True: 16.8k, False: 0]
  |  Branch (755:54): [True: 0, False: 16.8k]
  ------------------
  756|  16.8k|            sig_params->len != 0) {
  ------------------
  |  Branch (756:13): [True: 0, False: 16.8k]
  ------------------
  757|      0|            return MBEDTLS_ERR_X509_INVALID_ALG;
  ------------------
  |  |   55|      0|#define MBEDTLS_ERR_X509_INVALID_ALG                      -0x2300
  ------------------
  758|      0|        }
  759|  16.8k|    }
  760|       |
  761|  16.8k|    return 0;
  762|  16.8k|}
mbedtls_x509_get_ext:
  770|  16.8k|{
  771|  16.8k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  16.8k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  772|  16.8k|    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|  16.8k|    ret = mbedtls_asn1_get_tag(p, end, &ext->len,
  778|  16.8k|                               MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | tag);
  ------------------
  |  |   83|  16.8k|#define MBEDTLS_ASN1_CONTEXT_SPECIFIC        0x80
  ------------------
                                             MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | tag);
  ------------------
  |  |   82|  16.8k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
  779|  16.8k|    if (ret != 0) {
  ------------------
  |  Branch (779:9): [True: 0, False: 16.8k]
  ------------------
  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|  16.8k|    ext->tag = MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | tag;
  ------------------
  |  |   83|  16.8k|#define MBEDTLS_ASN1_CONTEXT_SPECIFIC        0x80
  ------------------
                  ext->tag = MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | tag;
  ------------------
  |  |   82|  16.8k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
  784|  16.8k|    ext->p   = *p;
  785|  16.8k|    end      = *p + ext->len;
  786|       |
  787|       |    /*
  788|       |     * Extensions  ::=  SEQUENCE SIZE (1..MAX) OF Extension
  789|       |     */
  790|  16.8k|    if ((ret = mbedtls_asn1_get_tag(p, end, &len,
  ------------------
  |  Branch (790:9): [True: 0, False: 16.8k]
  ------------------
  791|  16.8k|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|  16.8k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|  16.8k|#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|  16.8k|    if (end != *p + len) {
  ------------------
  |  Branch (795:9): [True: 0, False: 16.8k]
  ------------------
  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|  16.8k|    return 0;
  801|  16.8k|}
mbedtls_x509_time_cmp:
 1038|  14.7k|{
 1039|  14.7k|    int x;
 1040|       |
 1041|  14.7k|    x = (((t1->year << 9) | (t1->mon << 5) | (t1->day)) -
 1042|  14.7k|         ((t2->year << 9) | (t2->mon << 5) | (t2->day)));
 1043|  14.7k|    if (x != 0) {
  ------------------
  |  Branch (1043:9): [True: 14.7k, False: 0]
  ------------------
 1044|  14.7k|        return x;
 1045|  14.7k|    }
 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|  14.7k|}
mbedtls_x509_time_gmtime:
 1054|  3.16k|{
 1055|  3.16k|    struct tm tm;
 1056|       |
 1057|  3.16k|    if (mbedtls_platform_gmtime_r(&tt, &tm) == NULL) {
  ------------------
  |  Branch (1057:9): [True: 0, False: 3.16k]
  ------------------
 1058|      0|        return -1;
 1059|      0|    }
 1060|       |
 1061|  3.16k|    now->year = tm.tm_year + 1900;
 1062|  3.16k|    now->mon  = tm.tm_mon  + 1;
 1063|  3.16k|    now->day  = tm.tm_mday;
 1064|  3.16k|    now->hour = tm.tm_hour;
 1065|  3.16k|    now->min  = tm.tm_min;
 1066|  3.16k|    now->sec  = tm.tm_sec;
 1067|  3.16k|    return 0;
 1068|  3.16k|}
mbedtls_x509_get_subject_alt_name_ext:
 1216|  11.6k|{
 1217|  11.6k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  11.6k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1218|  11.6k|    size_t tag_len;
 1219|  11.6k|    mbedtls_asn1_sequence *cur = subject_alt_name;
 1220|       |
 1221|  23.2k|    while (*p < end) {
  ------------------
  |  Branch (1221:12): [True: 11.6k, False: 11.6k]
  ------------------
 1222|  11.6k|        mbedtls_x509_subject_alternative_name tmp_san_name;
 1223|  11.6k|        mbedtls_x509_buf tmp_san_buf;
 1224|  11.6k|        memset(&tmp_san_name, 0, sizeof(tmp_san_name));
 1225|       |
 1226|  11.6k|        tmp_san_buf.tag = **p;
 1227|  11.6k|        (*p)++;
 1228|       |
 1229|  11.6k|        if ((ret = mbedtls_asn1_get_len(p, end, &tag_len)) != 0) {
  ------------------
  |  Branch (1229:13): [True: 0, False: 11.6k]
  ------------------
 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|  11.6k|        tmp_san_buf.p = *p;
 1234|  11.6k|        tmp_san_buf.len = tag_len;
 1235|       |
 1236|  11.6k|        if ((tmp_san_buf.tag & MBEDTLS_ASN1_TAG_CLASS_MASK) !=
  ------------------
  |  |  106|  11.6k|#define MBEDTLS_ASN1_TAG_CLASS_MASK          0xC0
  ------------------
  |  Branch (1236:13): [True: 0, False: 11.6k]
  ------------------
 1237|  11.6k|            MBEDTLS_ASN1_CONTEXT_SPECIFIC) {
  ------------------
  |  |   83|  11.6k|#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|  11.6k|        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|  11.6k|        if (ret != 0 && ret != MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE) {
  ------------------
  |  |   45|  11.6k|#define MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE              -0x2080
  ------------------
  |  Branch (1251:13): [True: 11.6k, False: 0]
  |  Branch (1251:25): [True: 0, False: 11.6k]
  ------------------
 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|  11.6k|        mbedtls_x509_free_subject_alt_name(&tmp_san_name);
 1258|       |        /* Allocate and assign next pointer */
 1259|  11.6k|        if (cur->buf.p != NULL) {
  ------------------
  |  Branch (1259:13): [True: 0, False: 11.6k]
  ------------------
 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|  11.6k|        cur->buf = tmp_san_buf;
 1275|  11.6k|        *p += tmp_san_buf.len;
 1276|  11.6k|    }
 1277|       |
 1278|       |    /* Set final sequence entry's next pointer to NULL */
 1279|  11.6k|    cur->next = NULL;
 1280|       |
 1281|  11.6k|    if (*p != end) {
  ------------------
  |  Branch (1281:9): [True: 0, False: 11.6k]
  ------------------
 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|  11.6k|    return 0;
 1287|  11.6k|}
mbedtls_x509_get_subject_alt_name:
 1320|  11.6k|{
 1321|  11.6k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  11.6k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1322|  11.6k|    size_t len;
 1323|       |
 1324|       |    /* Get main sequence tag */
 1325|  11.6k|    if ((ret = mbedtls_asn1_get_tag(p, end, &len,
  ------------------
  |  Branch (1325:9): [True: 0, False: 11.6k]
  ------------------
 1326|  11.6k|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|  11.6k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|  11.6k|#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|  11.6k|    if (*p + len != end) {
  ------------------
  |  Branch (1330:9): [True: 0, False: 11.6k]
  ------------------
 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|  11.6k|    return mbedtls_x509_get_subject_alt_name_ext(p, end, subject_alt_name);
 1336|  11.6k|}
mbedtls_x509_get_key_usage:
 1369|  13.7k|{
 1370|  13.7k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  13.7k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1371|  13.7k|    size_t i;
 1372|  13.7k|    mbedtls_x509_bitstring bs = { 0, 0, NULL };
 1373|       |
 1374|  13.7k|    if ((ret = mbedtls_asn1_get_bitstring(p, end, &bs)) != 0) {
  ------------------
  |  Branch (1374:9): [True: 0, False: 13.7k]
  ------------------
 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|  13.7k|    if (bs.len == 0) {
  ------------------
  |  Branch (1380:9): [True: 0, False: 13.7k]
  ------------------
 1381|      0|        *key_usage = 0;
 1382|      0|        return 0;
 1383|      0|    }
 1384|       |
 1385|       |    /* Get actual bitstring */
 1386|  13.7k|    *key_usage = 0;
 1387|  27.4k|    for (i = 0; i < bs.len && i < sizeof(unsigned int); i++) {
  ------------------
  |  Branch (1387:17): [True: 13.7k, False: 13.7k]
  |  Branch (1387:31): [True: 13.7k, False: 0]
  ------------------
 1388|  13.7k|        *key_usage |= (unsigned int) bs.p[i] << (8*i);
 1389|  13.7k|    }
 1390|       |
 1391|  13.7k|    return 0;
 1392|  13.7k|}
mbedtls_x509_parse_subject_alt_name:
 1396|  11.6k|{
 1397|  11.6k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  11.6k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1398|  11.6k|    switch (san_buf->tag &
 1399|  11.6k|            (MBEDTLS_ASN1_TAG_CLASS_MASK |
  ------------------
  |  |  106|  11.6k|#define MBEDTLS_ASN1_TAG_CLASS_MASK          0xC0
  ------------------
 1400|  11.6k|             MBEDTLS_ASN1_TAG_VALUE_MASK)) {
  ------------------
  |  |  108|  11.6k|#define MBEDTLS_ASN1_TAG_VALUE_MASK          0x1F
  ------------------
 1401|       |        /*
 1402|       |         * otherName
 1403|       |         */
 1404|  11.6k|        case (MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_X509_SAN_OTHER_NAME):
  ------------------
  |  |   83|  11.6k|#define MBEDTLS_ASN1_CONTEXT_SPECIFIC        0x80
  ------------------
                      case (MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_X509_SAN_OTHER_NAME):
  ------------------
  |  |  127|  11.6k|#define MBEDTLS_X509_SAN_OTHER_NAME                      0
  ------------------
  |  Branch (1404:9): [True: 11.6k, False: 0]
  ------------------
 1405|  11.6k|        {
 1406|  11.6k|            mbedtls_x509_san_other_name other_name;
 1407|       |
 1408|  11.6k|            ret = x509_get_other_name(san_buf, &other_name);
 1409|  11.6k|            if (ret != 0) {
  ------------------
  |  Branch (1409:17): [True: 11.6k, False: 0]
  ------------------
 1410|  11.6k|                return ret;
 1411|  11.6k|            }
 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: 11.6k]
  ------------------
 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: 11.6k]
  ------------------
 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: 11.6k]
  ------------------
 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: 11.6k]
  ------------------
 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: 11.6k]
  ------------------
 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: 11.6k]
  ------------------
 1498|      0|            return MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE;
  ------------------
  |  |   45|      0|#define MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE              -0x2080
  ------------------
 1499|  11.6k|    }
 1500|      0|    return 0;
 1501|  11.6k|}
mbedtls_x509_free_subject_alt_name:
 1504|  11.6k|{
 1505|  11.6k|    if (san->type == MBEDTLS_X509_SAN_DIRECTORY_NAME) {
  ------------------
  |  |  131|  11.6k|#define MBEDTLS_X509_SAN_DIRECTORY_NAME                  4
  ------------------
  |  Branch (1505:9): [True: 0, False: 11.6k]
  ------------------
 1506|      0|        mbedtls_asn1_free_named_data_list_shallow(san->san.directory_name.next);
 1507|      0|    }
 1508|  11.6k|}
x509.c:x509_get_attr_type_value:
  409|  33.7k|{
  410|  33.7k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  33.7k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  411|  33.7k|    size_t len;
  412|  33.7k|    mbedtls_x509_buf *oid;
  413|  33.7k|    mbedtls_x509_buf *val;
  414|       |
  415|  33.7k|    if ((ret = mbedtls_asn1_get_tag(p, end, &len,
  ------------------
  |  Branch (415:9): [True: 0, False: 33.7k]
  ------------------
  416|  33.7k|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|  33.7k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|  33.7k|#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|  33.7k|    end = *p + len;
  421|       |
  422|  33.7k|    if ((end - *p) < 1) {
  ------------------
  |  Branch (422:9): [True: 0, False: 33.7k]
  ------------------
  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|  33.7k|    oid = &cur->oid;
  428|  33.7k|    oid->tag = **p;
  429|       |
  430|  33.7k|    if ((ret = mbedtls_asn1_get_tag(p, end, &oid->len, MBEDTLS_ASN1_OID)) != 0) {
  ------------------
  |  |   69|  33.7k|#define MBEDTLS_ASN1_OID                     0x06
  ------------------
  |  Branch (430:9): [True: 0, False: 33.7k]
  ------------------
  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|  33.7k|    oid->p = *p;
  435|  33.7k|    *p += oid->len;
  436|       |
  437|  33.7k|    if ((end - *p) < 1) {
  ------------------
  |  Branch (437:9): [True: 0, False: 33.7k]
  ------------------
  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|  33.7k|    if (**p != MBEDTLS_ASN1_BMP_STRING && **p != MBEDTLS_ASN1_UTF8_STRING      &&
  ------------------
  |  |   80|  67.5k|#define MBEDTLS_ASN1_BMP_STRING              0x1E
  ------------------
                  if (**p != MBEDTLS_ASN1_BMP_STRING && **p != MBEDTLS_ASN1_UTF8_STRING      &&
  ------------------
  |  |   71|  67.5k|#define MBEDTLS_ASN1_UTF8_STRING             0x0C
  ------------------
  |  Branch (442:9): [True: 33.7k, False: 0]
  |  Branch (442:43): [True: 0, False: 33.7k]
  ------------------
  443|  33.7k|        **p != MBEDTLS_ASN1_T61_STRING && **p != MBEDTLS_ASN1_PRINTABLE_STRING &&
  ------------------
  |  |   75|  33.7k|#define MBEDTLS_ASN1_T61_STRING              0x14
  ------------------
                      **p != MBEDTLS_ASN1_T61_STRING && **p != MBEDTLS_ASN1_PRINTABLE_STRING &&
  ------------------
  |  |   74|  33.7k|#define MBEDTLS_ASN1_PRINTABLE_STRING        0x13
  ------------------
  |  Branch (443:9): [True: 0, False: 0]
  |  Branch (443:43): [True: 0, False: 0]
  ------------------
  444|  33.7k|        **p != MBEDTLS_ASN1_IA5_STRING && **p != MBEDTLS_ASN1_UNIVERSAL_STRING &&
  ------------------
  |  |   76|  33.7k|#define MBEDTLS_ASN1_IA5_STRING              0x16
  ------------------
                      **p != MBEDTLS_ASN1_IA5_STRING && **p != MBEDTLS_ASN1_UNIVERSAL_STRING &&
  ------------------
  |  |   79|  33.7k|#define MBEDTLS_ASN1_UNIVERSAL_STRING        0x1C
  ------------------
  |  Branch (444:9): [True: 0, False: 0]
  |  Branch (444:43): [True: 0, False: 0]
  ------------------
  445|  33.7k|        **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|  33.7k|    val = &cur->val;
  451|  33.7k|    val->tag = *(*p)++;
  452|       |
  453|  33.7k|    if ((ret = mbedtls_asn1_get_len(p, end, &val->len)) != 0) {
  ------------------
  |  Branch (453:9): [True: 0, False: 33.7k]
  ------------------
  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|  33.7k|    val->p = *p;
  458|  33.7k|    *p += val->len;
  459|       |
  460|  33.7k|    if (*p != end) {
  ------------------
  |  Branch (460:9): [True: 0, False: 33.7k]
  ------------------
  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|  33.7k|    cur->next = NULL;
  466|       |
  467|  33.7k|    return 0;
  468|  33.7k|}
x509.c:x509_parse_time:
  612|  33.7k|{
  613|  33.7k|    int x;
  614|       |
  615|       |    /*
  616|       |     * Parse year, month, day, hour, minute, second
  617|       |     */
  618|  33.7k|    tm->year = x509_parse2_int(p);
  619|  33.7k|    if (tm->year < 0) {
  ------------------
  |  Branch (619:9): [True: 0, False: 33.7k]
  ------------------
  620|      0|        return MBEDTLS_ERR_X509_INVALID_DATE;
  ------------------
  |  |   59|      0|#define MBEDTLS_ERR_X509_INVALID_DATE                     -0x2400
  ------------------
  621|      0|    }
  622|       |
  623|  33.7k|    if (4 == yearlen) {
  ------------------
  |  Branch (623:9): [True: 0, False: 33.7k]
  ------------------
  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|  33.7k|    } else {
  631|  33.7k|        x = (tm->year < 50) ? 2000 : 1900;
  ------------------
  |  Branch (631:13): [True: 33.7k, False: 0]
  ------------------
  632|  33.7k|    }
  633|  33.7k|    tm->year += x;
  634|       |
  635|  33.7k|    tm->mon  = x509_parse2_int(p + 2);
  636|  33.7k|    tm->day  = x509_parse2_int(p + 4);
  637|  33.7k|    tm->hour = x509_parse2_int(p + 6);
  638|  33.7k|    tm->min  = x509_parse2_int(p + 8);
  639|  33.7k|    tm->sec  = x509_parse2_int(p + 10);
  640|       |
  641|  33.7k|    return x509_date_is_valid(tm);
  642|  33.7k|}
x509.c:x509_parse2_int:
  600|   202k|{
  601|   202k|    uint32_t d1 = p[0] - '0';
  602|   202k|    uint32_t d2 = p[1] - '0';
  603|   202k|    return (d1 < 10 && d2 < 10) ? (int) (d1 * 10 + d2) : -1;
  ------------------
  |  Branch (603:13): [True: 202k, False: 0]
  |  Branch (603:24): [True: 202k, False: 0]
  ------------------
  604|   202k|}
x509.c:x509_date_is_valid:
  567|  33.7k|{
  568|  33.7k|    unsigned int month_days;
  569|  33.7k|    unsigned int year;
  570|  33.7k|    switch (t->mon) {
  571|  5.28k|        case 1: case 3: case 5: case 7: case 8: case 10: case 12:
  ------------------
  |  Branch (571:9): [True: 0, False: 33.7k]
  |  Branch (571:17): [True: 5.28k, False: 28.5k]
  |  Branch (571:25): [True: 0, False: 33.7k]
  |  Branch (571:33): [True: 0, False: 33.7k]
  |  Branch (571:41): [True: 0, False: 33.7k]
  |  Branch (571:49): [True: 0, False: 33.7k]
  |  Branch (571:58): [True: 0, False: 33.7k]
  ------------------
  572|  5.28k|            month_days = 31;
  573|  5.28k|            break;
  574|  28.5k|        case 4: case 6: case 9: case 11:
  ------------------
  |  Branch (574:9): [True: 5.28k, False: 28.5k]
  |  Branch (574:17): [True: 0, False: 33.7k]
  |  Branch (574:25): [True: 23.2k, False: 10.5k]
  |  Branch (574:33): [True: 0, False: 33.7k]
  ------------------
  575|  28.5k|            month_days = 30;
  576|  28.5k|            break;
  577|      0|        case 2:
  ------------------
  |  Branch (577:9): [True: 0, False: 33.7k]
  ------------------
  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: 33.7k]
  ------------------
  584|      0|            return MBEDTLS_ERR_X509_INVALID_DATE;
  ------------------
  |  |   59|      0|#define MBEDTLS_ERR_X509_INVALID_DATE                     -0x2400
  ------------------
  585|  33.7k|    }
  586|       |
  587|  33.7k|    if ((unsigned int) (t->day - 1) >= month_days ||      /* (1 - days in month) */
  ------------------
  |  Branch (587:9): [True: 0, False: 33.7k]
  ------------------
  588|       |        /* (unsigned int) (t->mon - 1) >= 12 || */  /* (1 - 12) checked above */
  589|  33.7k|        (unsigned int) t->year > 9999 ||         /* (0 - 9999) */
  ------------------
  |  Branch (589:9): [True: 0, False: 33.7k]
  ------------------
  590|  33.7k|        (unsigned int) t->hour > 23 ||           /* (0 - 23) */
  ------------------
  |  Branch (590:9): [True: 0, False: 33.7k]
  ------------------
  591|  33.7k|        (unsigned int) t->min  > 59 ||           /* (0 - 59) */
  ------------------
  |  Branch (591:9): [True: 0, False: 33.7k]
  ------------------
  592|  33.7k|        (unsigned int) t->sec  > 59) {           /* (0 - 59) */
  ------------------
  |  Branch (592:9): [True: 0, False: 33.7k]
  ------------------
  593|      0|        return MBEDTLS_ERR_X509_INVALID_DATE;
  ------------------
  |  |   59|      0|#define MBEDTLS_ERR_X509_INVALID_DATE                     -0x2400
  ------------------
  594|      0|    }
  595|       |
  596|  33.7k|    return 0;
  597|  33.7k|}
x509.c:x509_get_other_name:
 1128|  11.6k|{
 1129|  11.6k|    int ret = 0;
 1130|  11.6k|    size_t len;
 1131|  11.6k|    unsigned char *p = subject_alt_name->p;
 1132|  11.6k|    const unsigned char *end = p + subject_alt_name->len;
 1133|  11.6k|    mbedtls_x509_buf cur_oid;
 1134|       |
 1135|  11.6k|    if ((subject_alt_name->tag &
  ------------------
  |  Branch (1135:9): [True: 0, False: 11.6k]
  ------------------
 1136|  11.6k|         (MBEDTLS_ASN1_TAG_CLASS_MASK | MBEDTLS_ASN1_TAG_VALUE_MASK)) !=
  ------------------
  |  |  106|  11.6k|#define MBEDTLS_ASN1_TAG_CLASS_MASK          0xC0
  ------------------
                       (MBEDTLS_ASN1_TAG_CLASS_MASK | MBEDTLS_ASN1_TAG_VALUE_MASK)) !=
  ------------------
  |  |  108|  11.6k|#define MBEDTLS_ASN1_TAG_VALUE_MASK          0x1F
  ------------------
 1137|  11.6k|        (MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_X509_SAN_OTHER_NAME)) {
  ------------------
  |  |   83|  11.6k|#define MBEDTLS_ASN1_CONTEXT_SPECIFIC        0x80
  ------------------
                      (MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_X509_SAN_OTHER_NAME)) {
  ------------------
  |  |  127|  11.6k|#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|  11.6k|    if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
  ------------------
  |  Branch (1144:9): [True: 0, False: 11.6k]
  ------------------
 1145|  11.6k|                                    MBEDTLS_ASN1_OID)) != 0) {
  ------------------
  |  |   69|  11.6k|#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|  11.6k|    cur_oid.tag = MBEDTLS_ASN1_OID;
  ------------------
  |  |   69|  11.6k|#define MBEDTLS_ASN1_OID                     0x06
  ------------------
 1150|  11.6k|    cur_oid.p = p;
 1151|  11.6k|    cur_oid.len = len;
 1152|       |
 1153|       |    /*
 1154|       |     * Only HwModuleName is currently supported.
 1155|       |     */
 1156|  11.6k|    if (MBEDTLS_OID_CMP(MBEDTLS_OID_ON_HW_MODULE_NAME, &cur_oid) != 0) {
  ------------------
  |  |  122|  11.6k|    ((MBEDTLS_OID_SIZE(oid_str) != (oid_buf)->len) ||                \
  |  |  ------------------
  |  |  |  |  113|  11.6k|#define MBEDTLS_OID_SIZE(x) (sizeof(x) - 1)
  |  |  ------------------
  |  |  |  Branch (122:6): [True: 11.6k, False: 0]
  |  |  ------------------
  |  |  123|  11.6k|     memcmp((oid_str), (oid_buf)->p, (oid_buf)->len) != 0)
  |  |  ------------------
  |  |  |  Branch (123:6): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (1156:9): [True: 11.6k, False: 0]
  ------------------
 1157|  11.6k|        return MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE;
  ------------------
  |  |   45|  11.6k|#define MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE              -0x2080
  ------------------
 1158|  11.6k|    }
 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|  16.8k|{
 1387|  16.8k|    return mbedtls_x509_crt_parse_der_internal(chain, buf, buflen, 1, NULL, NULL);
 1388|  16.8k|}
mbedtls_x509_crt_check_key_usage:
 1932|  2.11k|{
 1933|  2.11k|    unsigned int usage_must, usage_may;
 1934|  2.11k|    unsigned int may_mask = MBEDTLS_X509_KU_ENCIPHER_ONLY
  ------------------
  |  |  148|  2.11k|#define MBEDTLS_X509_KU_ENCIPHER_ONLY                (0x01)  /* bit 7 */
  ------------------
 1935|  2.11k|                            | MBEDTLS_X509_KU_DECIPHER_ONLY;
  ------------------
  |  |  149|  2.11k|#define MBEDTLS_X509_KU_DECIPHER_ONLY              (0x8000)  /* bit 8 */
  ------------------
 1936|       |
 1937|  2.11k|    if ((crt->ext_types & MBEDTLS_X509_EXT_KEY_USAGE) == 0) {
  ------------------
  |  |  176|  2.11k|#define MBEDTLS_X509_EXT_KEY_USAGE                MBEDTLS_OID_X509_EXT_KEY_USAGE
  |  |  ------------------
  |  |  |  |   39|  2.11k|#define MBEDTLS_OID_X509_EXT_KEY_USAGE                   (1 << 2)
  |  |  ------------------
  ------------------
  |  Branch (1937:9): [True: 1.05k, False: 1.05k]
  ------------------
 1938|  1.05k|        return 0;
 1939|  1.05k|    }
 1940|       |
 1941|  1.05k|    usage_must = usage & ~may_mask;
 1942|       |
 1943|  1.05k|    if (((crt->key_usage & ~may_mask) & usage_must) != usage_must) {
  ------------------
  |  Branch (1943:9): [True: 0, False: 1.05k]
  ------------------
 1944|      0|        return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
  ------------------
  |  |   75|      0|#define MBEDTLS_ERR_X509_BAD_INPUT_DATA                   -0x2800
  ------------------
 1945|      0|    }
 1946|       |
 1947|  1.05k|    usage_may = usage & may_mask;
 1948|       |
 1949|  1.05k|    if (((crt->key_usage & may_mask) | usage_may) != usage_may) {
  ------------------
  |  Branch (1949:9): [True: 0, False: 1.05k]
  ------------------
 1950|      0|        return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
  ------------------
  |  |   75|      0|#define MBEDTLS_ERR_X509_BAD_INPUT_DATA                   -0x2800
  ------------------
 1951|      0|    }
 1952|       |
 1953|  1.05k|    return 0;
 1954|  1.05k|}
mbedtls_x509_crt_verify_with_profile:
 3175|  3.16k|{
 3176|  3.16k|    return x509_crt_verify_restartable_ca_cb(crt, trust_ca, ca_crl,
 3177|  3.16k|                                             NULL, NULL,
 3178|  3.16k|                                             profile, cn, flags,
 3179|  3.16k|                                             f_vrfy, p_vrfy, NULL);
 3180|  3.16k|}
mbedtls_x509_crt_init:
 3222|  16.8k|{
 3223|  16.8k|    memset(crt, 0, sizeof(mbedtls_x509_crt));
 3224|  16.8k|}
mbedtls_x509_crt_free:
 3230|  16.8k|{
 3231|  16.8k|    mbedtls_x509_crt *cert_cur = crt;
 3232|  16.8k|    mbedtls_x509_crt *cert_prv;
 3233|       |
 3234|  33.7k|    while (cert_cur != NULL) {
  ------------------
  |  Branch (3234:12): [True: 16.8k, False: 16.8k]
  ------------------
 3235|  16.8k|        mbedtls_pk_free(&cert_cur->pk);
 3236|       |
 3237|  16.8k|#if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
 3238|  16.8k|        mbedtls_free(cert_cur->sig_opts);
  ------------------
  |  |  143|  16.8k|#define mbedtls_free       MBEDTLS_PLATFORM_FREE_MACRO
  |  |  ------------------
  |  |  |  | 4095|  16.8k|#define MBEDTLS_PLATFORM_FREE_MACRO            my_free
  |  |  ------------------
  ------------------
 3239|  16.8k|#endif
 3240|       |
 3241|  16.8k|        mbedtls_asn1_free_named_data_list_shallow(cert_cur->issuer.next);
 3242|  16.8k|        mbedtls_asn1_free_named_data_list_shallow(cert_cur->subject.next);
 3243|  16.8k|        mbedtls_asn1_sequence_free(cert_cur->ext_key_usage.next);
 3244|  16.8k|        mbedtls_asn1_sequence_free(cert_cur->subject_alt_names.next);
 3245|  16.8k|        mbedtls_asn1_sequence_free(cert_cur->certificate_policies.next);
 3246|  16.8k|        mbedtls_asn1_sequence_free(cert_cur->authority_key_id.authorityCertIssuer.next);
 3247|       |
 3248|  16.8k|        if (cert_cur->raw.p != NULL && cert_cur->own_buffer) {
  ------------------
  |  Branch (3248:13): [True: 16.8k, False: 0]
  |  Branch (3248:40): [True: 16.8k, False: 0]
  ------------------
 3249|  16.8k|            mbedtls_zeroize_and_free(cert_cur->raw.p, cert_cur->raw.len);
 3250|  16.8k|        }
 3251|       |
 3252|  16.8k|        cert_prv = cert_cur;
 3253|  16.8k|        cert_cur = cert_cur->next;
 3254|       |
 3255|  16.8k|        mbedtls_platform_zeroize(cert_prv, sizeof(mbedtls_x509_crt));
 3256|  16.8k|        if (cert_prv != crt) {
  ------------------
  |  Branch (3256:13): [True: 0, False: 16.8k]
  ------------------
 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|  16.8k|    }
 3260|  16.8k|}
x509_crt.c:mbedtls_x509_crt_parse_der_internal:
 1319|  16.8k|{
 1320|  16.8k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  16.8k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1321|  16.8k|    mbedtls_x509_crt *crt = chain, *prev = NULL;
 1322|       |
 1323|       |    /*
 1324|       |     * Check for valid input
 1325|       |     */
 1326|  16.8k|    if (crt == NULL || buf == NULL) {
  ------------------
  |  Branch (1326:9): [True: 0, False: 16.8k]
  |  Branch (1326:24): [True: 0, False: 16.8k]
  ------------------
 1327|      0|        return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
  ------------------
  |  |   75|      0|#define MBEDTLS_ERR_X509_BAD_INPUT_DATA                   -0x2800
  ------------------
 1328|      0|    }
 1329|       |
 1330|  16.8k|    while (crt->version != 0 && crt->next != NULL) {
  ------------------
  |  Branch (1330:12): [True: 0, False: 16.8k]
  |  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|  16.8k|    if (crt->version != 0 && crt->next == NULL) {
  ------------------
  |  Branch (1338:9): [True: 0, False: 16.8k]
  |  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|  16.8k|    ret = x509_crt_parse_der_core(crt, buf, buflen, make_copy, cb, p_ctx);
 1351|  16.8k|    if (ret != 0) {
  ------------------
  |  Branch (1351:9): [True: 0, False: 16.8k]
  ------------------
 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|  16.8k|    return 0;
 1364|  16.8k|}
x509_crt.c:x509_crt_parse_der_core:
 1079|  16.8k|{
 1080|  16.8k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  16.8k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1081|  16.8k|    size_t len;
 1082|  16.8k|    unsigned char *p, *end, *crt_end;
 1083|  16.8k|    mbedtls_x509_buf sig_params1, sig_params2, sig_oid2;
 1084|       |
 1085|  16.8k|    memset(&sig_params1, 0, sizeof(mbedtls_x509_buf));
 1086|  16.8k|    memset(&sig_params2, 0, sizeof(mbedtls_x509_buf));
 1087|  16.8k|    memset(&sig_oid2, 0, sizeof(mbedtls_x509_buf));
 1088|       |
 1089|       |    /*
 1090|       |     * Check for valid input
 1091|       |     */
 1092|  16.8k|    if (crt == NULL || buf == NULL) {
  ------------------
  |  Branch (1092:9): [True: 0, False: 16.8k]
  |  Branch (1092:24): [True: 0, False: 16.8k]
  ------------------
 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|  16.8k|    p = (unsigned char *) buf;
 1098|  16.8k|    len = buflen;
 1099|  16.8k|    end = p + len;
 1100|       |
 1101|       |    /*
 1102|       |     * Certificate  ::=  SEQUENCE  {
 1103|       |     *      tbsCertificate       TBSCertificate,
 1104|       |     *      signatureAlgorithm   AlgorithmIdentifier,
 1105|       |     *      signatureValue       BIT STRING  }
 1106|       |     */
 1107|  16.8k|    if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
  ------------------
  |  Branch (1107:9): [True: 0, False: 16.8k]
  ------------------
 1108|  16.8k|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|  16.8k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|  16.8k|#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|  16.8k|    end = crt_end = p + len;
 1114|  16.8k|    crt->raw.len = (size_t) (crt_end - buf);
 1115|  16.8k|    if (make_copy != 0) {
  ------------------
  |  Branch (1115:9): [True: 16.8k, False: 0]
  ------------------
 1116|       |        /* Create and populate a new buffer for the raw field. */
 1117|  16.8k|        crt->raw.p = p = mbedtls_calloc(1, crt->raw.len);
  ------------------
  |  |  144|  16.8k|#define mbedtls_calloc     MBEDTLS_PLATFORM_CALLOC_MACRO
  |  |  ------------------
  |  |  |  | 4093|  16.8k|#define MBEDTLS_PLATFORM_CALLOC_MACRO        my_calloc
  |  |  ------------------
  ------------------
 1118|  16.8k|        if (crt->raw.p == NULL) {
  ------------------
  |  Branch (1118:13): [True: 0, False: 16.8k]
  ------------------
 1119|      0|            return MBEDTLS_ERR_X509_ALLOC_FAILED;
  ------------------
  |  |   77|      0|#define MBEDTLS_ERR_X509_ALLOC_FAILED                     -0x2880
  ------------------
 1120|      0|        }
 1121|       |
 1122|  16.8k|        memcpy(crt->raw.p, buf, crt->raw.len);
 1123|  16.8k|        crt->own_buffer = 1;
 1124|       |
 1125|  16.8k|        p += crt->raw.len - len;
 1126|  16.8k|        end = crt_end = p + len;
 1127|  16.8k|    } else {
 1128|      0|        crt->raw.p = (unsigned char *) buf;
 1129|      0|        crt->own_buffer = 0;
 1130|      0|    }
 1131|       |
 1132|       |    /*
 1133|       |     * TBSCertificate  ::=  SEQUENCE  {
 1134|       |     */
 1135|  16.8k|    crt->tbs.p = p;
 1136|       |
 1137|  16.8k|    if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
  ------------------
  |  Branch (1137:9): [True: 0, False: 16.8k]
  ------------------
 1138|  16.8k|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|  16.8k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|  16.8k|#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|  16.8k|    end = p + len;
 1144|  16.8k|    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|  16.8k|    if ((ret = x509_get_version(&p, end, &crt->version)) != 0 ||
  ------------------
  |  Branch (1153:9): [True: 0, False: 16.8k]
  ------------------
 1154|  16.8k|        (ret = mbedtls_x509_get_serial(&p, end, &crt->serial)) != 0 ||
  ------------------
  |  Branch (1154:9): [True: 0, False: 16.8k]
  ------------------
 1155|  16.8k|        (ret = mbedtls_x509_get_alg(&p, end, &crt->sig_oid,
  ------------------
  |  Branch (1155:9): [True: 0, False: 16.8k]
  ------------------
 1156|  16.8k|                                    &sig_params1)) != 0) {
 1157|      0|        mbedtls_x509_crt_free(crt);
 1158|      0|        return ret;
 1159|      0|    }
 1160|       |
 1161|  16.8k|    if (crt->version < 0 || crt->version > 2) {
  ------------------
  |  Branch (1161:9): [True: 0, False: 16.8k]
  |  Branch (1161:29): [True: 0, False: 16.8k]
  ------------------
 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|  16.8k|    crt->version++;
 1167|       |
 1168|  16.8k|    if ((ret = mbedtls_x509_get_sig_alg(&crt->sig_oid, &sig_params1,
  ------------------
  |  Branch (1168:9): [True: 0, False: 16.8k]
  ------------------
 1169|  16.8k|                                        &crt->sig_md, &crt->sig_pk,
 1170|  16.8k|                                        &crt->sig_opts)) != 0) {
 1171|      0|        mbedtls_x509_crt_free(crt);
 1172|      0|        return ret;
 1173|      0|    }
 1174|       |
 1175|       |    /*
 1176|       |     * issuer               Name
 1177|       |     */
 1178|  16.8k|    crt->issuer_raw.p = p;
 1179|       |
 1180|  16.8k|    if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
  ------------------
  |  Branch (1180:9): [True: 0, False: 16.8k]
  ------------------
 1181|  16.8k|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|  16.8k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|  16.8k|#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|  16.8k|    if ((ret = mbedtls_x509_get_name(&p, p + len, &crt->issuer)) != 0) {
  ------------------
  |  Branch (1186:9): [True: 0, False: 16.8k]
  ------------------
 1187|      0|        mbedtls_x509_crt_free(crt);
 1188|      0|        return ret;
 1189|      0|    }
 1190|       |
 1191|  16.8k|    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|  16.8k|    if ((ret = x509_get_dates(&p, end, &crt->valid_from,
  ------------------
  |  Branch (1199:9): [True: 0, False: 16.8k]
  ------------------
 1200|  16.8k|                              &crt->valid_to)) != 0) {
 1201|      0|        mbedtls_x509_crt_free(crt);
 1202|      0|        return ret;
 1203|      0|    }
 1204|       |
 1205|       |    /*
 1206|       |     * subject              Name
 1207|       |     */
 1208|  16.8k|    crt->subject_raw.p = p;
 1209|       |
 1210|  16.8k|    if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
  ------------------
  |  Branch (1210:9): [True: 0, False: 16.8k]
  ------------------
 1211|  16.8k|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|  16.8k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|  16.8k|#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|  16.8k|    if (len && (ret = mbedtls_x509_get_name(&p, p + len, &crt->subject)) != 0) {
  ------------------
  |  Branch (1216:9): [True: 16.8k, False: 0]
  |  Branch (1216:16): [True: 0, False: 16.8k]
  ------------------
 1217|      0|        mbedtls_x509_crt_free(crt);
 1218|      0|        return ret;
 1219|      0|    }
 1220|       |
 1221|  16.8k|    crt->subject_raw.len = (size_t) (p - crt->subject_raw.p);
 1222|       |
 1223|       |    /*
 1224|       |     * SubjectPublicKeyInfo
 1225|       |     */
 1226|  16.8k|    crt->pk_raw.p = p;
 1227|  16.8k|    if ((ret = mbedtls_pk_parse_subpubkey(&p, end, &crt->pk)) != 0) {
  ------------------
  |  Branch (1227:9): [True: 0, False: 16.8k]
  ------------------
 1228|      0|        mbedtls_x509_crt_free(crt);
 1229|      0|        return ret;
 1230|      0|    }
 1231|  16.8k|    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|  16.8k|    if (crt->version == 2 || crt->version == 3) {
  ------------------
  |  Branch (1241:9): [True: 0, False: 16.8k]
  |  Branch (1241:30): [True: 16.8k, False: 0]
  ------------------
 1242|  16.8k|        ret = x509_get_uid(&p, end, &crt->issuer_id,  1);
 1243|  16.8k|        if (ret != 0) {
  ------------------
  |  Branch (1243:13): [True: 0, False: 16.8k]
  ------------------
 1244|      0|            mbedtls_x509_crt_free(crt);
 1245|      0|            return ret;
 1246|      0|        }
 1247|  16.8k|    }
 1248|       |
 1249|  16.8k|    if (crt->version == 2 || crt->version == 3) {
  ------------------
  |  Branch (1249:9): [True: 0, False: 16.8k]
  |  Branch (1249:30): [True: 16.8k, False: 0]
  ------------------
 1250|  16.8k|        ret = x509_get_uid(&p, end, &crt->subject_id,  2);
 1251|  16.8k|        if (ret != 0) {
  ------------------
  |  Branch (1251:13): [True: 0, False: 16.8k]
  ------------------
 1252|      0|            mbedtls_x509_crt_free(crt);
 1253|      0|            return ret;
 1254|      0|        }
 1255|  16.8k|    }
 1256|       |
 1257|  16.8k|    if (crt->version == 3) {
  ------------------
  |  Branch (1257:9): [True: 16.8k, False: 0]
  ------------------
 1258|  16.8k|        ret = x509_get_crt_ext(&p, end, crt, cb, p_ctx);
 1259|  16.8k|        if (ret != 0) {
  ------------------
  |  Branch (1259:13): [True: 0, False: 16.8k]
  ------------------
 1260|      0|            mbedtls_x509_crt_free(crt);
 1261|      0|            return ret;
 1262|      0|        }
 1263|  16.8k|    }
 1264|       |
 1265|  16.8k|    if (p != end) {
  ------------------
  |  Branch (1265:9): [True: 0, False: 16.8k]
  ------------------
 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|  16.8k|    end = crt_end;
 1272|       |
 1273|       |    /*
 1274|       |     *  }
 1275|       |     *  -- end of TBSCertificate
 1276|       |     *
 1277|       |     *  signatureAlgorithm   AlgorithmIdentifier,
 1278|       |     *  signatureValue       BIT STRING
 1279|       |     */
 1280|  16.8k|    if ((ret = mbedtls_x509_get_alg(&p, end, &sig_oid2, &sig_params2)) != 0) {
  ------------------
  |  Branch (1280:9): [True: 0, False: 16.8k]
  ------------------
 1281|      0|        mbedtls_x509_crt_free(crt);
 1282|      0|        return ret;
 1283|      0|    }
 1284|       |
 1285|  16.8k|    if (crt->sig_oid.len != sig_oid2.len ||
  ------------------
  |  Branch (1285:9): [True: 0, False: 16.8k]
  ------------------
 1286|  16.8k|        memcmp(crt->sig_oid.p, sig_oid2.p, crt->sig_oid.len) != 0 ||
  ------------------
  |  Branch (1286:9): [True: 0, False: 16.8k]
  ------------------
 1287|  16.8k|        sig_params1.tag != sig_params2.tag ||
  ------------------
  |  Branch (1287:9): [True: 0, False: 16.8k]
  ------------------
 1288|  16.8k|        sig_params1.len != sig_params2.len ||
  ------------------
  |  Branch (1288:9): [True: 0, False: 16.8k]
  ------------------
 1289|  16.8k|        (sig_params1.len != 0 &&
  ------------------
  |  Branch (1289:10): [True: 0, False: 16.8k]
  ------------------
 1290|  16.8k|         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|  16.8k|    if ((ret = mbedtls_x509_get_sig(&p, end, &crt->sig)) != 0) {
  ------------------
  |  Branch (1295:9): [True: 0, False: 16.8k]
  ------------------
 1296|      0|        mbedtls_x509_crt_free(crt);
 1297|      0|        return ret;
 1298|      0|    }
 1299|       |
 1300|  16.8k|    if (p != end) {
  ------------------
  |  Branch (1300:9): [True: 0, False: 16.8k]
  ------------------
 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|  16.8k|    return 0;
 1307|  16.8k|}
x509_crt.c:x509_get_version:
  398|  16.8k|{
  399|  16.8k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  16.8k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  400|  16.8k|    size_t len;
  401|       |
  402|  16.8k|    if ((ret = mbedtls_asn1_get_tag(p, end, &len,
  ------------------
  |  Branch (402:9): [True: 0, False: 16.8k]
  ------------------
  403|  16.8k|                                    MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED |
  ------------------
  |  |   83|  16.8k|#define MBEDTLS_ASN1_CONTEXT_SPECIFIC        0x80
  ------------------
                                                  MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED |
  ------------------
  |  |   82|  16.8k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
  404|  16.8k|                                    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|  16.8k|    end = *p + len;
  414|       |
  415|  16.8k|    if ((ret = mbedtls_asn1_get_int(p, end, ver)) != 0) {
  ------------------
  |  Branch (415:9): [True: 0, False: 16.8k]
  ------------------
  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|  16.8k|    if (*p != end) {
  ------------------
  |  Branch (419:9): [True: 0, False: 16.8k]
  ------------------
  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|  16.8k|    return 0;
  425|  16.8k|}
x509_crt.c:x509_get_dates:
  436|  16.8k|{
  437|  16.8k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  16.8k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  438|  16.8k|    size_t len;
  439|       |
  440|  16.8k|    if ((ret = mbedtls_asn1_get_tag(p, end, &len,
  ------------------
  |  Branch (440:9): [True: 0, False: 16.8k]
  ------------------
  441|  16.8k|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|  16.8k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|  16.8k|#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|  16.8k|    end = *p + len;
  446|       |
  447|  16.8k|    if ((ret = mbedtls_x509_get_time(p, end, from)) != 0) {
  ------------------
  |  Branch (447:9): [True: 0, False: 16.8k]
  ------------------
  448|      0|        return ret;
  449|      0|    }
  450|       |
  451|  16.8k|    if ((ret = mbedtls_x509_get_time(p, end, to)) != 0) {
  ------------------
  |  Branch (451:9): [True: 0, False: 16.8k]
  ------------------
  452|      0|        return ret;
  453|      0|    }
  454|       |
  455|  16.8k|    if (*p != end) {
  ------------------
  |  Branch (455:9): [True: 0, False: 16.8k]
  ------------------
  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|  16.8k|    return 0;
  461|  16.8k|}
x509_crt.c:x509_get_uid:
  469|  33.7k|{
  470|  33.7k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  33.7k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  471|       |
  472|  33.7k|    if (*p == end) {
  ------------------
  |  Branch (472:9): [True: 0, False: 33.7k]
  ------------------
  473|      0|        return 0;
  474|      0|    }
  475|       |
  476|  33.7k|    uid->tag = **p;
  477|       |
  478|  33.7k|    if ((ret = mbedtls_asn1_get_tag(p, end, &uid->len,
  ------------------
  |  Branch (478:9): [True: 33.7k, False: 0]
  ------------------
  479|  33.7k|                                    MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED |
  ------------------
  |  |   83|  33.7k|#define MBEDTLS_ASN1_CONTEXT_SPECIFIC        0x80
  ------------------
                                                  MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED |
  ------------------
  |  |   82|  33.7k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
  480|  33.7k|                                    n)) != 0) {
  481|  33.7k|        if (ret == MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) {
  ------------------
  |  |   39|  33.7k|#define MBEDTLS_ERR_ASN1_UNEXPECTED_TAG                   -0x0062
  ------------------
  |  Branch (481:13): [True: 33.7k, False: 0]
  ------------------
  482|  33.7k|            return 0;
  483|  33.7k|        }
  484|       |
  485|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_FORMAT, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  486|  33.7k|    }
  487|       |
  488|      0|    uid->p = *p;
  489|      0|    *p += uid->len;
  490|       |
  491|      0|    return 0;
  492|  33.7k|}
x509_crt.c:x509_get_crt_ext:
  867|  16.8k|{
  868|  16.8k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  16.8k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  869|  16.8k|    size_t len;
  870|  16.8k|    unsigned char *end_ext_data, *start_ext_octet, *end_ext_octet;
  871|       |
  872|  16.8k|    if (*p == end) {
  ------------------
  |  Branch (872:9): [True: 0, False: 16.8k]
  ------------------
  873|      0|        return 0;
  874|      0|    }
  875|       |
  876|  16.8k|    if ((ret = mbedtls_x509_get_ext(p, end, &crt->v3_ext, 3)) != 0) {
  ------------------
  |  Branch (876:9): [True: 0, False: 16.8k]
  ------------------
  877|      0|        return ret;
  878|      0|    }
  879|       |
  880|  16.8k|    end = crt->v3_ext.p + crt->v3_ext.len;
  881|   104k|    while (*p < end) {
  ------------------
  |  Branch (881:12): [True: 87.6k, False: 16.8k]
  ------------------
  882|       |        /*
  883|       |         * Extension  ::=  SEQUENCE  {
  884|       |         *      extnID      OBJECT IDENTIFIER,
  885|       |         *      critical    BOOLEAN DEFAULT FALSE,
  886|       |         *      extnValue   OCTET STRING  }
  887|       |         */
  888|  87.6k|        mbedtls_x509_buf extn_oid = { 0, 0, NULL };
  889|  87.6k|        int is_critical = 0; /* DEFAULT FALSE */
  890|  87.6k|        int ext_type = 0;
  891|       |
  892|  87.6k|        if ((ret = mbedtls_asn1_get_tag(p, end, &len,
  ------------------
  |  Branch (892:13): [True: 0, False: 87.6k]
  ------------------
  893|  87.6k|                                        MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|  87.6k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                      MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|  87.6k|#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|  87.6k|        end_ext_data = *p + len;
  898|       |
  899|       |        /* Get extension ID */
  900|  87.6k|        if ((ret = mbedtls_asn1_get_tag(p, end_ext_data, &extn_oid.len,
  ------------------
  |  Branch (900:13): [True: 0, False: 87.6k]
  ------------------
  901|  87.6k|                                        MBEDTLS_ASN1_OID)) != 0) {
  ------------------
  |  |   69|  87.6k|#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|  87.6k|        extn_oid.tag = MBEDTLS_ASN1_OID;
  ------------------
  |  |   69|  87.6k|#define MBEDTLS_ASN1_OID                     0x06
  ------------------
  906|  87.6k|        extn_oid.p = *p;
  907|  87.6k|        *p += extn_oid.len;
  908|       |
  909|       |        /* Get optional critical */
  910|  87.6k|        if ((ret = mbedtls_asn1_get_bool(p, end_ext_data, &is_critical)) != 0 &&
  ------------------
  |  Branch (910:13): [True: 59.1k, False: 28.5k]
  ------------------
  911|  87.6k|            (ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG)) {
  ------------------
  |  |   39|  59.1k|#define MBEDTLS_ERR_ASN1_UNEXPECTED_TAG                   -0x0062
  ------------------
  |  Branch (911:13): [True: 0, False: 59.1k]
  ------------------
  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|  87.6k|        if ((ret = mbedtls_asn1_get_tag(p, end_ext_data, &len,
  ------------------
  |  Branch (916:13): [True: 0, False: 87.6k]
  ------------------
  917|  87.6k|                                        MBEDTLS_ASN1_OCTET_STRING)) != 0) {
  ------------------
  |  |   67|  87.6k|#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|  87.6k|        start_ext_octet = *p;
  922|  87.6k|        end_ext_octet = *p + len;
  923|       |
  924|  87.6k|        if (end_ext_octet != end_ext_data) {
  ------------------
  |  Branch (924:13): [True: 0, False: 87.6k]
  ------------------
  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|  87.6k|        ret = mbedtls_oid_get_x509_ext_type(&extn_oid, &ext_type);
  933|       |
  934|  87.6k|        if (ret != 0) {
  ------------------
  |  Branch (934:13): [True: 11.6k, False: 76.0k]
  ------------------
  935|       |            /* Give the callback (if any) a chance to handle the extension */
  936|  11.6k|            if (cb != NULL) {
  ------------------
  |  Branch (936:17): [True: 0, False: 11.6k]
  ------------------
  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|  11.6k|            *p = end_ext_octet;
  947|       |
  948|  11.6k|            if (is_critical) {
  ------------------
  |  Branch (948:17): [True: 0, False: 11.6k]
  ------------------
  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|  11.6k|            continue;
  954|  11.6k|        }
  955|       |
  956|       |        /* Forbid repeated extensions */
  957|  76.0k|        if ((crt->ext_types & ext_type) != 0) {
  ------------------
  |  Branch (957:13): [True: 0, False: 76.0k]
  ------------------
  958|      0|            return MBEDTLS_ERR_X509_INVALID_EXTENSIONS;
  ------------------
  |  |   63|      0|#define MBEDTLS_ERR_X509_INVALID_EXTENSIONS               -0x2500
  ------------------
  959|      0|        }
  960|       |
  961|  76.0k|        crt->ext_types |= ext_type;
  962|       |
  963|  76.0k|        switch (ext_type) {
  964|  16.8k|            case MBEDTLS_X509_EXT_BASIC_CONSTRAINTS:
  ------------------
  |  |  182|  16.8k|#define MBEDTLS_X509_EXT_BASIC_CONSTRAINTS        MBEDTLS_OID_X509_EXT_BASIC_CONSTRAINTS        /* Supported */
  |  |  ------------------
  |  |  |  |   45|  16.8k|#define MBEDTLS_OID_X509_EXT_BASIC_CONSTRAINTS           (1 << 8)
  |  |  ------------------
  ------------------
  |  Branch (964:13): [True: 16.8k, False: 59.1k]
  ------------------
  965|       |                /* Parse basic constraints */
  966|  16.8k|                if ((ret = x509_get_basic_constraints(p, end_ext_octet,
  ------------------
  |  Branch (966:21): [True: 0, False: 16.8k]
  ------------------
  967|  16.8k|                                                      &crt->ca_istrue, &crt->max_pathlen)) != 0) {
  968|      0|                    return ret;
  969|      0|                }
  970|  16.8k|                break;
  971|       |
  972|  16.8k|            case MBEDTLS_X509_EXT_KEY_USAGE:
  ------------------
  |  |  176|  13.7k|#define MBEDTLS_X509_EXT_KEY_USAGE                MBEDTLS_OID_X509_EXT_KEY_USAGE
  |  |  ------------------
  |  |  |  |   39|  13.7k|#define MBEDTLS_OID_X509_EXT_KEY_USAGE                   (1 << 2)
  |  |  ------------------
  ------------------
  |  Branch (972:13): [True: 13.7k, False: 62.3k]
  ------------------
  973|       |                /* Parse key usage */
  974|  13.7k|                if ((ret = mbedtls_x509_get_key_usage(p, end_ext_octet,
  ------------------
  |  Branch (974:21): [True: 0, False: 13.7k]
  ------------------
  975|  13.7k|                                                      &crt->key_usage)) != 0) {
  976|      0|                    return ret;
  977|      0|                }
  978|  13.7k|                break;
  979|       |
  980|  13.7k|            case MBEDTLS_X509_EXT_EXTENDED_KEY_USAGE:
  ------------------
  |  |  185|  13.7k|#define MBEDTLS_X509_EXT_EXTENDED_KEY_USAGE       MBEDTLS_OID_X509_EXT_EXTENDED_KEY_USAGE
  |  |  ------------------
  |  |  |  |   48|  13.7k|#define MBEDTLS_OID_X509_EXT_EXTENDED_KEY_USAGE          (1 << 11)
  |  |  ------------------
  ------------------
  |  Branch (980:13): [True: 13.7k, False: 62.3k]
  ------------------
  981|       |                /* Parse extended key usage */
  982|  13.7k|                if ((ret = x509_get_ext_key_usage(p, end_ext_octet,
  ------------------
  |  Branch (982:21): [True: 0, False: 13.7k]
  ------------------
  983|  13.7k|                                                  &crt->ext_key_usage)) != 0) {
  984|      0|                    return ret;
  985|      0|                }
  986|  13.7k|                break;
  987|       |
  988|  16.8k|            case MBEDTLS_X509_EXT_SUBJECT_KEY_IDENTIFIER:
  ------------------
  |  |  175|  16.8k|#define MBEDTLS_X509_EXT_SUBJECT_KEY_IDENTIFIER   MBEDTLS_OID_X509_EXT_SUBJECT_KEY_IDENTIFIER
  |  |  ------------------
  |  |  |  |   38|  16.8k|#define MBEDTLS_OID_X509_EXT_SUBJECT_KEY_IDENTIFIER      (1 << 1)
  |  |  ------------------
  ------------------
  |  Branch (988:13): [True: 16.8k, False: 59.1k]
  ------------------
  989|       |                /* Parse subject key identifier */
  990|  16.8k|                if ((ret = x509_get_subject_key_id(p, end_ext_data,
  ------------------
  |  Branch (990:21): [True: 0, False: 16.8k]
  ------------------
  991|  16.8k|                                                   &crt->subject_key_id)) != 0) {
  992|      0|                    return ret;
  993|      0|                }
  994|  16.8k|                break;
  995|       |
  996|  16.8k|            case MBEDTLS_X509_EXT_AUTHORITY_KEY_IDENTIFIER:
  ------------------
  |  |  174|  3.16k|#define MBEDTLS_X509_EXT_AUTHORITY_KEY_IDENTIFIER MBEDTLS_OID_X509_EXT_AUTHORITY_KEY_IDENTIFIER
  |  |  ------------------
  |  |  |  |   37|  3.16k|#define MBEDTLS_OID_X509_EXT_AUTHORITY_KEY_IDENTIFIER    (1 << 0)
  |  |  ------------------
  ------------------
  |  Branch (996:13): [True: 3.16k, False: 72.8k]
  ------------------
  997|       |                /* Parse authority key identifier */
  998|  3.16k|                if ((ret = x509_get_authority_key_id(p, end_ext_octet,
  ------------------
  |  Branch (998:21): [True: 0, False: 3.16k]
  ------------------
  999|  3.16k|                                                     &crt->authority_key_id)) != 0) {
 1000|      0|                    return ret;
 1001|      0|                }
 1002|  3.16k|                break;
 1003|  11.6k|            case MBEDTLS_X509_EXT_SUBJECT_ALT_NAME:
  ------------------
  |  |  179|  11.6k|#define MBEDTLS_X509_EXT_SUBJECT_ALT_NAME         MBEDTLS_OID_X509_EXT_SUBJECT_ALT_NAME         /* Supported (DNS) */
  |  |  ------------------
  |  |  |  |   42|  11.6k|#define MBEDTLS_OID_X509_EXT_SUBJECT_ALT_NAME            (1 << 5)
  |  |  ------------------
  ------------------
  |  Branch (1003:13): [True: 11.6k, False: 64.4k]
  ------------------
 1004|       |                /* Parse subject alt name
 1005|       |                 * SubjectAltName ::= GeneralNames
 1006|       |                 */
 1007|  11.6k|                if ((ret = mbedtls_x509_get_subject_alt_name(p, end_ext_octet,
  ------------------
  |  Branch (1007:21): [True: 0, False: 11.6k]
  ------------------
 1008|  11.6k|                                                             &crt->subject_alt_names)) != 0) {
 1009|      0|                    return ret;
 1010|      0|                }
 1011|  11.6k|                break;
 1012|       |
 1013|  11.6k|            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: 76.0k]
  ------------------
 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: 76.0k]
  ------------------
 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: 76.0k]
  ------------------
 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|  76.0k|        }
 1060|  76.0k|    }
 1061|       |
 1062|  16.8k|    if (*p != end) {
  ------------------
  |  Branch (1062:9): [True: 0, False: 16.8k]
  ------------------
 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|  16.8k|    return 0;
 1068|  16.8k|}
x509_crt.c:x509_get_basic_constraints:
  498|  16.8k|{
  499|  16.8k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  16.8k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  500|  16.8k|    size_t len;
  501|       |
  502|       |    /*
  503|       |     * BasicConstraints ::= SEQUENCE {
  504|       |     *      cA                      BOOLEAN DEFAULT FALSE,
  505|       |     *      pathLenConstraint       INTEGER (0..MAX) OPTIONAL }
  506|       |     */
  507|  16.8k|    *ca_istrue = 0; /* DEFAULT FALSE */
  508|  16.8k|    *max_pathlen = 0; /* endless */
  509|       |
  510|  16.8k|    if ((ret = mbedtls_asn1_get_tag(p, end, &len,
  ------------------
  |  Branch (510:9): [True: 0, False: 16.8k]
  ------------------
  511|  16.8k|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|  16.8k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|  16.8k|#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|  16.8k|    if (*p == end) {
  ------------------
  |  Branch (515:9): [True: 11.6k, False: 5.28k]
  ------------------
  516|  11.6k|        return 0;
  517|  11.6k|    }
  518|       |
  519|  5.28k|    if ((ret = mbedtls_asn1_get_bool(p, end, ca_istrue)) != 0) {
  ------------------
  |  Branch (519:9): [True: 0, False: 5.28k]
  ------------------
  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|  5.28k|    if (*p == end) {
  ------------------
  |  Branch (533:9): [True: 5.28k, False: 0]
  ------------------
  534|  5.28k|        return 0;
  535|  5.28k|    }
  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|  13.7k|{
  567|  13.7k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  13.7k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  568|       |
  569|  13.7k|    if ((ret = mbedtls_asn1_get_sequence_of(p, end, ext_key_usage, MBEDTLS_ASN1_OID)) != 0) {
  ------------------
  |  |   69|  13.7k|#define MBEDTLS_ASN1_OID                     0x06
  ------------------
  |  Branch (569:9): [True: 0, False: 13.7k]
  ------------------
  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|  13.7k|    if (ext_key_usage->buf.p == NULL) {
  ------------------
  |  Branch (574:9): [True: 0, False: 13.7k]
  ------------------
  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|  13.7k|    return 0;
  580|  13.7k|}
x509_crt.c:x509_get_subject_key_id:
  590|  16.8k|{
  591|  16.8k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  16.8k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  592|  16.8k|    size_t len = 0u;
  593|       |
  594|  16.8k|    if ((ret = mbedtls_asn1_get_tag(p, end, &len,
  ------------------
  |  Branch (594:9): [True: 0, False: 16.8k]
  ------------------
  595|  16.8k|                                    MBEDTLS_ASN1_OCTET_STRING)) != 0) {
  ------------------
  |  |   67|  16.8k|#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|  16.8k|    subject_key_id->len = len;
  600|  16.8k|    subject_key_id->tag = MBEDTLS_ASN1_OCTET_STRING;
  ------------------
  |  |   67|  16.8k|#define MBEDTLS_ASN1_OCTET_STRING            0x04
  ------------------
  601|  16.8k|    subject_key_id->p = *p;
  602|  16.8k|    *p += len;
  603|       |
  604|  16.8k|    if (*p != end) {
  ------------------
  |  Branch (604:9): [True: 0, False: 16.8k]
  ------------------
  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|  16.8k|    return 0;
  610|  16.8k|}
x509_crt.c:x509_get_authority_key_id:
  623|  3.16k|{
  624|  3.16k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  3.16k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  625|  3.16k|    size_t len = 0u;
  626|       |
  627|  3.16k|    if ((ret = mbedtls_asn1_get_tag(p, end, &len,
  ------------------
  |  Branch (627:9): [True: 0, False: 3.16k]
  ------------------
  628|  3.16k|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|  3.16k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|  3.16k|#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|  3.16k|    if (*p + len != end) {
  ------------------
  |  Branch (632:9): [True: 0, False: 3.16k]
  ------------------
  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|  3.16k|    ret = mbedtls_asn1_get_tag(p, end, &len,
  638|  3.16k|                               MBEDTLS_ASN1_CONTEXT_SPECIFIC);
  ------------------
  |  |   83|  3.16k|#define MBEDTLS_ASN1_CONTEXT_SPECIFIC        0x80
  ------------------
  639|       |
  640|       |    /* KeyIdentifier is an OPTIONAL field */
  641|  3.16k|    if (ret == 0) {
  ------------------
  |  Branch (641:9): [True: 3.16k, False: 0]
  ------------------
  642|  3.16k|        authority_key_id->keyIdentifier.len = len;
  643|  3.16k|        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|  3.16k|        authority_key_id->keyIdentifier.tag = MBEDTLS_ASN1_OCTET_STRING;
  ------------------
  |  |   67|  3.16k|#define MBEDTLS_ASN1_OCTET_STRING            0x04
  ------------------
  648|       |
  649|  3.16k|        *p += len;
  650|  3.16k|    } 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|  3.16k|    if (*p < end) {
  ------------------
  |  Branch (654:9): [True: 0, False: 3.16k]
  ------------------
  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|  3.16k|    if (*p != end) {
  ------------------
  |  Branch (682:9): [True: 0, False: 3.16k]
  ------------------
  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|  3.16k|    return 0;
  688|  3.16k|}
x509_crt.c:x509_crt_verify_restartable_ca_cb:
 3068|  3.16k|{
 3069|  3.16k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  3.16k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 3070|  3.16k|    mbedtls_pk_type_t pk_type;
 3071|  3.16k|    mbedtls_x509_crt_verify_chain ver_chain;
 3072|  3.16k|    uint32_t ee_flags;
 3073|       |
 3074|  3.16k|    *flags = 0;
 3075|  3.16k|    ee_flags = 0;
 3076|  3.16k|    x509_crt_verify_chain_reset(&ver_chain);
 3077|       |
 3078|  3.16k|    if (profile == NULL) {
  ------------------
  |  Branch (3078:9): [True: 0, False: 3.16k]
  ------------------
 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|  3.16k|    if (cn != NULL) {
  ------------------
  |  Branch (3084:9): [True: 0, False: 3.16k]
  ------------------
 3085|      0|        x509_crt_verify_name(crt, cn, &ee_flags);
 3086|      0|    }
 3087|       |
 3088|       |    /* Check the type and size of the key */
 3089|  3.16k|    pk_type = mbedtls_pk_get_type(&crt->pk);
 3090|       |
 3091|  3.16k|    if (x509_profile_check_pk_alg(profile, pk_type) != 0) {
  ------------------
  |  Branch (3091:9): [True: 0, False: 3.16k]
  ------------------
 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|  3.16k|    if (x509_profile_check_key(profile, &crt->pk) != 0) {
  ------------------
  |  Branch (3095:9): [True: 0, False: 3.16k]
  ------------------
 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|  3.16k|    ret = x509_crt_verify_chain(crt, trust_ca, ca_crl,
 3101|  3.16k|                                f_ca_cb, p_ca_cb, profile,
 3102|  3.16k|                                &ver_chain, rs_ctx);
 3103|       |
 3104|  3.16k|    if (ret != 0) {
  ------------------
  |  Branch (3104:9): [True: 0, False: 3.16k]
  ------------------
 3105|      0|        goto exit;
 3106|      0|    }
 3107|       |
 3108|       |    /* Merge end-entity flags */
 3109|  3.16k|    ver_chain.items[0].flags |= ee_flags;
 3110|       |
 3111|       |    /* Build final flags, calling callback on the way if any */
 3112|  3.16k|    ret = x509_crt_merge_flags_with_cb(flags, &ver_chain, f_vrfy, p_vrfy);
 3113|       |
 3114|  3.16k|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|  3.16k|#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
 3123|  3.16k|    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: 3.16k]
  |  Branch (3123:27): [True: 0, False: 0]
  ------------------
 3124|      0|        mbedtls_x509_crt_restart_free(rs_ctx);
 3125|      0|    }
 3126|  3.16k|#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|  3.16k|    if (ret == MBEDTLS_ERR_X509_CERT_VERIFY_FAILED) {
  ------------------
  |  |   71|  3.16k|#define MBEDTLS_ERR_X509_CERT_VERIFY_FAILED               -0x2700
  ------------------
  |  Branch (3131:9): [True: 0, False: 3.16k]
  ------------------
 3132|      0|        ret = MBEDTLS_ERR_X509_FATAL_ERROR;
  ------------------
  |  |   83|      0|#define MBEDTLS_ERR_X509_FATAL_ERROR                      -0x3000
  ------------------
 3133|      0|    }
 3134|       |
 3135|  3.16k|    if (ret != 0) {
  ------------------
  |  Branch (3135:9): [True: 0, False: 3.16k]
  ------------------
 3136|      0|        *flags = (uint32_t) -1;
 3137|      0|        return ret;
 3138|      0|    }
 3139|       |
 3140|  3.16k|    if (*flags != 0) {
  ------------------
  |  Branch (3140:9): [True: 0, False: 3.16k]
  ------------------
 3141|      0|        return MBEDTLS_ERR_X509_CERT_VERIFY_FAILED;
  ------------------
  |  |   71|      0|#define MBEDTLS_ERR_X509_CERT_VERIFY_FAILED               -0x2700
  ------------------
 3142|      0|    }
 3143|       |
 3144|  3.16k|    return 0;
 3145|  3.16k|}
x509_crt.c:x509_profile_check_pk_alg:
  193|  6.33k|{
  194|  6.33k|    if (pk_alg == MBEDTLS_PK_NONE) {
  ------------------
  |  Branch (194:9): [True: 0, False: 6.33k]
  ------------------
  195|      0|        return -1;
  196|      0|    }
  197|       |
  198|  6.33k|    if ((profile->allowed_pks & MBEDTLS_X509_ID_FLAG(pk_alg)) != 0) {
  ------------------
  |  |   98|  6.33k|#define MBEDTLS_X509_ID_FLAG(id)   (1 << ((id) - 1))
  ------------------
  |  Branch (198:9): [True: 6.33k, False: 0]
  ------------------
  199|  6.33k|        return 0;
  200|  6.33k|    }
  201|       |
  202|      0|    return -1;
  203|  6.33k|}
x509_crt.c:x509_profile_check_key:
  211|  5.28k|{
  212|  5.28k|    const mbedtls_pk_type_t pk_alg = mbedtls_pk_get_type(pk);
  213|       |
  214|  5.28k|#if defined(MBEDTLS_RSA_C)
  215|  5.28k|    if (pk_alg == MBEDTLS_PK_RSA || pk_alg == MBEDTLS_PK_RSASSA_PSS) {
  ------------------
  |  Branch (215:9): [True: 0, False: 5.28k]
  |  Branch (215:37): [True: 0, False: 5.28k]
  ------------------
  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|  5.28k|#endif /* MBEDTLS_RSA_C */
  223|       |
  224|  5.28k|#if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
  225|  5.28k|    if (pk_alg == MBEDTLS_PK_ECDSA ||
  ------------------
  |  Branch (225:9): [True: 0, False: 5.28k]
  ------------------
  226|  5.28k|        pk_alg == MBEDTLS_PK_ECKEY ||
  ------------------
  |  Branch (226:9): [True: 5.28k, False: 0]
  ------------------
  227|  5.28k|        pk_alg == MBEDTLS_PK_ECKEY_DH) {
  ------------------
  |  Branch (227:9): [True: 0, False: 0]
  ------------------
  228|  5.28k|        const mbedtls_ecp_group_id gid = mbedtls_pk_get_ec_group_id(pk);
  229|       |
  230|  5.28k|        if (gid == MBEDTLS_ECP_DP_NONE) {
  ------------------
  |  Branch (230:13): [True: 0, False: 5.28k]
  ------------------
  231|      0|            return -1;
  232|      0|        }
  233|       |
  234|  5.28k|        if ((profile->allowed_curves & MBEDTLS_X509_ID_FLAG(gid)) != 0) {
  ------------------
  |  |   98|  5.28k|#define MBEDTLS_X509_ID_FLAG(id)   (1 << ((id) - 1))
  ------------------
  |  Branch (234:13): [True: 5.28k, False: 0]
  ------------------
  235|  5.28k|            return 0;
  236|  5.28k|        }
  237|       |
  238|      0|        return -1;
  239|  5.28k|    }
  240|      0|#endif /* MBEDTLS_PK_HAVE_ECC_KEYS */
  241|       |
  242|      0|    return -1;
  243|  5.28k|}
x509_crt.c:x509_crt_verify_chain:
 2515|  3.16k|{
 2516|       |    /* Don't initialize any of those variables here, so that the compiler can
 2517|       |     * catch potential issues with jumping ahead when restarting */
 2518|  3.16k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  3.16k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 2519|  3.16k|    uint32_t *flags;
 2520|  3.16k|    mbedtls_x509_crt_verify_chain_item *cur;
 2521|  3.16k|    mbedtls_x509_crt *child;
 2522|  3.16k|    mbedtls_x509_crt *parent;
 2523|  3.16k|    int parent_is_trusted;
 2524|  3.16k|    int child_is_trusted;
 2525|  3.16k|    int signature_is_good;
 2526|  3.16k|    unsigned self_cnt;
 2527|  3.16k|    mbedtls_x509_crt *cur_trust_ca = NULL;
 2528|  3.16k|    mbedtls_x509_time now;
 2529|       |
 2530|  3.16k|#if defined(MBEDTLS_HAVE_TIME_DATE)
 2531|  3.16k|    if (mbedtls_x509_time_gmtime(mbedtls_time(NULL), &now) != 0) {
  ------------------
  |  |   71|  3.16k|#define mbedtls_time   time
  ------------------
  |  Branch (2531:9): [True: 0, False: 3.16k]
  ------------------
 2532|      0|        return MBEDTLS_ERR_X509_FATAL_ERROR;
  ------------------
  |  |   83|      0|#define MBEDTLS_ERR_X509_FATAL_ERROR                      -0x3000
  ------------------
 2533|      0|    }
 2534|  3.16k|#endif
 2535|       |
 2536|  3.16k|#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
 2537|       |    /* resume if we had an operation in progress */
 2538|  3.16k|    if (rs_ctx != NULL && rs_ctx->in_progress == x509_crt_rs_find_parent) {
  ------------------
  |  Branch (2538:9): [True: 0, False: 3.16k]
  |  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|  3.16k|#endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
 2551|       |
 2552|  3.16k|    child = crt;
 2553|  3.16k|    self_cnt = 0;
 2554|  3.16k|    parent_is_trusted = 0;
 2555|  3.16k|    child_is_trusted = 0;
 2556|       |
 2557|  5.28k|    while (1) {
  ------------------
  |  Branch (2557:12): [Folded - Ignored]
  ------------------
 2558|       |        /* Add certificate to the verification chain */
 2559|  5.28k|        cur = &ver_chain->items[ver_chain->len];
 2560|  5.28k|        cur->crt = child;
 2561|  5.28k|        cur->flags = 0;
 2562|  5.28k|        ver_chain->len++;
 2563|  5.28k|        flags = &cur->flags;
 2564|       |
 2565|  5.28k|#if defined(MBEDTLS_HAVE_TIME_DATE)
 2566|       |        /* Check time-validity (all certificates) */
 2567|  5.28k|        if (mbedtls_x509_time_cmp(&child->valid_to, &now) < 0) {
  ------------------
  |  Branch (2567:13): [True: 0, False: 5.28k]
  ------------------
 2568|      0|            *flags |= MBEDTLS_X509_BADCERT_EXPIRED;
  ------------------
  |  |   91|      0|#define MBEDTLS_X509_BADCERT_EXPIRED             0x01  /**< The certificate validity has expired. */
  ------------------
 2569|      0|        }
 2570|       |
 2571|  5.28k|        if (mbedtls_x509_time_cmp(&child->valid_from, &now) > 0) {
  ------------------
  |  Branch (2571:13): [True: 0, False: 5.28k]
  ------------------
 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|  5.28k|#endif
 2575|       |
 2576|       |        /* Stop here for trusted roots (but not for trusted EE certs) */
 2577|  5.28k|        if (child_is_trusted) {
  ------------------
  |  Branch (2577:13): [True: 2.11k, False: 3.16k]
  ------------------
 2578|  2.11k|            return 0;
 2579|  2.11k|        }
 2580|       |
 2581|       |        /* Check signature algorithm: MD & PK algs */
 2582|  3.16k|        if (x509_profile_check_md_alg(profile, child->sig_md) != 0) {
  ------------------
  |  Branch (2582:13): [True: 0, False: 3.16k]
  ------------------
 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|  3.16k|        if (x509_profile_check_pk_alg(profile, child->sig_pk) != 0) {
  ------------------
  |  Branch (2586:13): [True: 0, False: 3.16k]
  ------------------
 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|  3.16k|        if (ver_chain->len == 1 &&
  ------------------
  |  Branch (2591:13): [True: 3.16k, False: 0]
  ------------------
 2592|  3.16k|            x509_crt_check_ee_locally_trusted(child, trust_ca) == 0) {
  ------------------
  |  Branch (2592:13): [True: 1.05k, False: 2.11k]
  ------------------
 2593|  1.05k|            return 0;
 2594|  1.05k|        }
 2595|       |
 2596|  2.11k|#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
 2597|  2.11k|find_parent:
 2598|  2.11k|#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|  2.11k|        {
 2617|  2.11k|            ((void) f_ca_cb);
 2618|  2.11k|            ((void) p_ca_cb);
 2619|  2.11k|            cur_trust_ca = trust_ca;
 2620|  2.11k|        }
 2621|       |
 2622|       |        /* Look for a parent in trusted CAs or up the chain */
 2623|  2.11k|        ret = x509_crt_find_parent(child, cur_trust_ca, &parent,
 2624|  2.11k|                                   &parent_is_trusted, &signature_is_good,
 2625|  2.11k|                                   ver_chain->len - 1, self_cnt, rs_ctx,
 2626|  2.11k|                                   &now);
 2627|       |
 2628|  2.11k|#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
 2629|  2.11k|        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: 2.11k]
  |  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|  2.11k|        if (parent == NULL) {
  ------------------
  |  Branch (2642:13): [True: 0, False: 2.11k]
  ------------------
 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|  2.11k|        if (ver_chain->len != 1 &&
  ------------------
  |  Branch (2650:13): [True: 0, False: 2.11k]
  ------------------
 2651|  2.11k|            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|  2.11k|        if (!parent_is_trusted &&
  ------------------
  |  Branch (2657:13): [True: 0, False: 2.11k]
  ------------------
 2658|  2.11k|            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|  2.11k|        if (!signature_is_good) {
  ------------------
  |  Branch (2664:13): [True: 0, False: 2.11k]
  ------------------
 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|  2.11k|        if (x509_profile_check_key(profile, &parent->pk) != 0) {
  ------------------
  |  Branch (2669:13): [True: 0, False: 2.11k]
  ------------------
 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|  2.11k|#if defined(MBEDTLS_X509_CRL_PARSE_C)
 2674|       |        /* Check trusted CA's CRL for the given crt */
 2675|  2.11k|        *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|  2.11k|        child = parent;
 2682|  2.11k|        parent = NULL;
 2683|  2.11k|        child_is_trusted = parent_is_trusted;
 2684|  2.11k|        signature_is_good = 0;
 2685|  2.11k|    }
 2686|  3.16k|}
x509_crt.c:x509_profile_check_md_alg:
  175|  3.16k|{
  176|  3.16k|    if (md_alg == MBEDTLS_MD_NONE) {
  ------------------
  |  Branch (176:9): [True: 0, False: 3.16k]
  ------------------
  177|      0|        return -1;
  178|      0|    }
  179|       |
  180|  3.16k|    if ((profile->allowed_mds & MBEDTLS_X509_ID_FLAG(md_alg)) != 0) {
  ------------------
  |  |   98|  3.16k|#define MBEDTLS_X509_ID_FLAG(id)   (1 << ((id) - 1))
  ------------------
  |  Branch (180:9): [True: 3.16k, False: 0]
  ------------------
  181|  3.16k|        return 0;
  182|  3.16k|    }
  183|       |
  184|      0|    return -1;
  185|  3.16k|}
x509_crt.c:x509_crt_check_ee_locally_trusted:
 2446|  3.16k|{
 2447|  3.16k|    mbedtls_x509_crt *cur;
 2448|       |
 2449|       |    /* must be self-issued */
 2450|  3.16k|    if (x509_name_cmp(&crt->issuer, &crt->subject) != 0) {
  ------------------
  |  Branch (2450:9): [True: 2.11k, False: 1.05k]
  ------------------
 2451|  2.11k|        return -1;
 2452|  2.11k|    }
 2453|       |
 2454|       |    /* look for an exact match with trusted cert */
 2455|  1.05k|    for (cur = trust_ca; cur != NULL; cur = cur->next) {
  ------------------
  |  Branch (2455:26): [True: 1.05k, False: 0]
  ------------------
 2456|  1.05k|        if (crt->raw.len == cur->raw.len &&
  ------------------
  |  Branch (2456:13): [True: 1.05k, False: 0]
  ------------------
 2457|  1.05k|            memcmp(crt->raw.p, cur->raw.p, crt->raw.len) == 0) {
  ------------------
  |  Branch (2457:13): [True: 1.05k, False: 0]
  ------------------
 2458|  1.05k|            return 0;
 2459|  1.05k|        }
 2460|  1.05k|    }
 2461|       |
 2462|       |    /* too bad */
 2463|      0|    return -1;
 2464|  1.05k|}
x509_crt.c:x509_crt_find_parent:
 2387|  2.11k|{
 2388|  2.11k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  2.11k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 2389|  2.11k|    mbedtls_x509_crt *search_list;
 2390|       |
 2391|  2.11k|    *parent_is_trusted = 1;
 2392|       |
 2393|  2.11k|#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
 2394|       |    /* restore then clear saved state if we have some stored */
 2395|  2.11k|    if (rs_ctx != NULL && rs_ctx->parent_is_trusted != -1) {
  ------------------
  |  Branch (2395:9): [True: 0, False: 2.11k]
  |  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|  2.11k|#endif
 2400|       |
 2401|  2.11k|    while (1) {
  ------------------
  |  Branch (2401:12): [Folded - Ignored]
  ------------------
 2402|  2.11k|        search_list = *parent_is_trusted ? trust_ca : child->next;
  ------------------
  |  Branch (2402:23): [True: 2.11k, False: 0]
  ------------------
 2403|       |
 2404|  2.11k|        ret = x509_crt_find_parent_in(child, search_list,
 2405|  2.11k|                                      parent, signature_is_good,
 2406|  2.11k|                                      *parent_is_trusted,
 2407|  2.11k|                                      path_cnt, self_cnt, rs_ctx, now);
 2408|       |
 2409|  2.11k|#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
 2410|  2.11k|        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: 2.11k]
  |  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|  2.11k|        if (*parent != NULL || *parent_is_trusted == 0) {
  ------------------
  |  Branch (2420:13): [True: 2.11k, False: 0]
  |  Branch (2420:32): [True: 0, False: 0]
  ------------------
 2421|  2.11k|            break;
 2422|  2.11k|        }
 2423|       |
 2424|       |        /* prepare second iteration */
 2425|      0|        *parent_is_trusted = 0;
 2426|      0|    }
 2427|       |
 2428|       |    /* extra precaution against mistakes in the caller */
 2429|  2.11k|    if (*parent == NULL) {
  ------------------
  |  Branch (2429:9): [True: 0, False: 2.11k]
  ------------------
 2430|      0|        *parent_is_trusted = 0;
 2431|      0|        *signature_is_good = 0;
 2432|      0|    }
 2433|       |
 2434|  2.11k|    return 0;
 2435|  2.11k|}
x509_crt.c:x509_crt_find_parent_in:
 2264|  2.11k|{
 2265|  2.11k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  2.11k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 2266|  2.11k|    mbedtls_x509_crt *parent, *fallback_parent;
 2267|  2.11k|    int signature_is_good = 0, fallback_signature_is_good;
 2268|       |
 2269|  2.11k|#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
 2270|       |    /* did we have something in progress? */
 2271|  2.11k|    if (rs_ctx != NULL && rs_ctx->parent != NULL) {
  ------------------
  |  Branch (2271:9): [True: 0, False: 2.11k]
  |  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|  2.11k|#endif
 2286|       |
 2287|  2.11k|    fallback_parent = NULL;
 2288|  2.11k|    fallback_signature_is_good = 0;
 2289|       |
 2290|  2.11k|    for (parent = candidates; parent != NULL; parent = parent->next) {
  ------------------
  |  Branch (2290:31): [True: 2.11k, False: 0]
  ------------------
 2291|       |        /* basic parenting skills (name, CA bit, key usage) */
 2292|  2.11k|        if (x509_crt_check_parent(child, parent, top) != 0) {
  ------------------
  |  Branch (2292:13): [True: 0, False: 2.11k]
  ------------------
 2293|      0|            continue;
 2294|      0|        }
 2295|       |
 2296|       |        /* +1 because stored max_pathlen is 1 higher that the actual value */
 2297|  2.11k|        if (parent->max_pathlen > 0 &&
  ------------------
  |  Branch (2297:13): [True: 0, False: 2.11k]
  ------------------
 2298|  2.11k|            (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|  2.11k|#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
 2304|  2.11k|check_signature:
 2305|  2.11k|#endif
 2306|  2.11k|        ret = x509_crt_check_signature(child, parent, rs_ctx);
 2307|       |
 2308|  2.11k|#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
 2309|  2.11k|        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: 2.11k]
  |  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|  2.11k|        signature_is_good = ret == 0;
 2322|  2.11k|        if (top && !signature_is_good) {
  ------------------
  |  Branch (2322:13): [True: 2.11k, False: 0]
  |  Branch (2322:20): [True: 0, False: 2.11k]
  ------------------
 2323|      0|            continue;
 2324|      0|        }
 2325|       |
 2326|  2.11k|#if defined(MBEDTLS_HAVE_TIME_DATE)
 2327|       |        /* optional time check */
 2328|  2.11k|        if (mbedtls_x509_time_cmp(&parent->valid_to, now) < 0 ||    /* past */
  ------------------
  |  Branch (2328:13): [True: 0, False: 2.11k]
  ------------------
 2329|  2.11k|            mbedtls_x509_time_cmp(&parent->valid_from, now) > 0) {  /* future */
  ------------------
  |  Branch (2329:13): [True: 0, False: 2.11k]
  ------------------
 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|  2.11k|        *r_parent = parent;
 2342|  2.11k|        *r_signature_is_good = signature_is_good;
 2343|       |
 2344|  2.11k|        break;
 2345|  2.11k|    }
 2346|       |
 2347|  2.11k|    if (parent == NULL) {
  ------------------
  |  Branch (2347:9): [True: 0, False: 2.11k]
  ------------------
 2348|      0|        *r_parent = fallback_parent;
 2349|      0|        *r_signature_is_good = fallback_signature_is_good;
 2350|      0|    }
 2351|       |
 2352|  2.11k|    return 0;
 2353|  2.11k|}
x509_crt.c:x509_crt_check_parent:
 2183|  2.11k|{
 2184|  2.11k|    int need_ca_bit;
 2185|       |
 2186|       |    /* Parent must be the issuer */
 2187|  2.11k|    if (x509_name_cmp(&child->issuer, &parent->subject) != 0) {
  ------------------
  |  Branch (2187:9): [True: 0, False: 2.11k]
  ------------------
 2188|      0|        return -1;
 2189|      0|    }
 2190|       |
 2191|       |    /* Parent must have the basicConstraints CA bit set as a general rule */
 2192|  2.11k|    need_ca_bit = 1;
 2193|       |
 2194|       |    /* Exception: v1/v2 certificates that are locally trusted. */
 2195|  2.11k|    if (top && parent->version < 3) {
  ------------------
  |  Branch (2195:9): [True: 2.11k, False: 0]
  |  Branch (2195:16): [True: 0, False: 2.11k]
  ------------------
 2196|      0|        need_ca_bit = 0;
 2197|      0|    }
 2198|       |
 2199|  2.11k|    if (need_ca_bit && !parent->ca_istrue) {
  ------------------
  |  Branch (2199:9): [True: 2.11k, False: 0]
  |  Branch (2199:24): [True: 0, False: 2.11k]
  ------------------
 2200|      0|        return -1;
 2201|      0|    }
 2202|       |
 2203|  2.11k|    if (need_ca_bit &&
  ------------------
  |  Branch (2203:9): [True: 2.11k, False: 0]
  ------------------
 2204|  2.11k|        mbedtls_x509_crt_check_key_usage(parent, MBEDTLS_X509_KU_KEY_CERT_SIGN) != 0) {
  ------------------
  |  |  146|  2.11k|#define MBEDTLS_X509_KU_KEY_CERT_SIGN                (0x04)  /* bit 5 */
  ------------------
  |  Branch (2204:9): [True: 0, False: 2.11k]
  ------------------
 2205|      0|        return -1;
 2206|      0|    }
 2207|       |
 2208|  2.11k|    return 0;
 2209|  2.11k|}
x509_crt.c:x509_crt_check_signature:
 2127|  2.11k|{
 2128|  2.11k|    size_t hash_len;
 2129|  2.11k|    unsigned char hash[MBEDTLS_MD_MAX_SIZE];
 2130|  2.11k|#if !defined(MBEDTLS_USE_PSA_CRYPTO)
 2131|  2.11k|    const mbedtls_md_info_t *md_info;
 2132|  2.11k|    md_info = mbedtls_md_info_from_type(child->sig_md);
 2133|  2.11k|    hash_len = mbedtls_md_get_size(md_info);
 2134|       |
 2135|       |    /* Note: hash errors can happen only after an internal error */
 2136|  2.11k|    if (mbedtls_md(md_info, child->tbs.p, child->tbs.len, hash) != 0) {
  ------------------
  |  Branch (2136:9): [True: 0, False: 2.11k]
  ------------------
 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|  2.11k|    if (!mbedtls_pk_can_do(&parent->pk, child->sig_pk)) {
  ------------------
  |  Branch (2155:9): [True: 0, False: 2.11k]
  ------------------
 2156|      0|        return -1;
 2157|      0|    }
 2158|       |
 2159|  2.11k|#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
 2160|  2.11k|    if (rs_ctx != NULL && child->sig_pk == MBEDTLS_PK_ECDSA) {
  ------------------
  |  Branch (2160:9): [True: 0, False: 2.11k]
  |  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|  2.11k|    return mbedtls_pk_verify_ext(child->sig_pk, child->sig_opts, &parent->pk,
 2170|  2.11k|                                 child->sig_md, hash, hash_len,
 2171|  2.11k|                                 child->sig.p, child->sig.len);
 2172|  2.11k|}
x509_crt.c:x509_name_cmp:
  340|  5.28k|{
  341|       |    /* Avoid recursion, it might not be optimised by the compiler */
  342|  8.44k|    while (a != NULL || b != NULL) {
  ------------------
  |  Branch (342:12): [True: 5.28k, False: 3.16k]
  |  Branch (342:25): [True: 0, False: 3.16k]
  ------------------
  343|  5.28k|        if (a == NULL || b == NULL) {
  ------------------
  |  Branch (343:13): [True: 0, False: 5.28k]
  |  Branch (343:26): [True: 0, False: 5.28k]
  ------------------
  344|      0|            return -1;
  345|      0|        }
  346|       |
  347|       |        /* type */
  348|  5.28k|        if (a->oid.tag != b->oid.tag ||
  ------------------
  |  Branch (348:13): [True: 0, False: 5.28k]
  ------------------
  349|  5.28k|            a->oid.len != b->oid.len ||
  ------------------
  |  Branch (349:13): [True: 0, False: 5.28k]
  ------------------
  350|  5.28k|            memcmp(a->oid.p, b->oid.p, b->oid.len) != 0) {
  ------------------
  |  Branch (350:13): [True: 0, False: 5.28k]
  ------------------
  351|      0|            return -1;
  352|      0|        }
  353|       |
  354|       |        /* value */
  355|  5.28k|        if (x509_string_cmp(&a->val, &b->val) != 0) {
  ------------------
  |  Branch (355:13): [True: 2.11k, False: 3.16k]
  ------------------
  356|  2.11k|            return -1;
  357|  2.11k|        }
  358|       |
  359|       |        /* structure of the list of sets */
  360|  3.16k|        if (a->next_merged != b->next_merged) {
  ------------------
  |  Branch (360:13): [True: 0, False: 3.16k]
  ------------------
  361|      0|            return -1;
  362|      0|        }
  363|       |
  364|  3.16k|        a = a->next;
  365|  3.16k|        b = b->next;
  366|  3.16k|    }
  367|       |
  368|       |    /* a == NULL == b */
  369|  3.16k|    return 0;
  370|  5.28k|}
x509_crt.c:x509_string_cmp:
  312|  5.28k|{
  313|  5.28k|    if (a->tag == b->tag &&
  ------------------
  |  Branch (313:9): [True: 5.28k, False: 0]
  ------------------
  314|  5.28k|        a->len == b->len &&
  ------------------
  |  Branch (314:9): [True: 3.16k, False: 2.11k]
  ------------------
  315|  5.28k|        memcmp(a->p, b->p, b->len) == 0) {
  ------------------
  |  Branch (315:9): [True: 3.16k, False: 0]
  ------------------
  316|  3.16k|        return 0;
  317|  3.16k|    }
  318|       |
  319|  2.11k|    if ((a->tag == MBEDTLS_ASN1_UTF8_STRING || a->tag == MBEDTLS_ASN1_PRINTABLE_STRING) &&
  ------------------
  |  |   71|  4.22k|#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: 2.11k, False: 0]
  |  Branch (319:48): [True: 0, False: 0]
  ------------------
  320|  2.11k|        (b->tag == MBEDTLS_ASN1_UTF8_STRING || b->tag == MBEDTLS_ASN1_PRINTABLE_STRING) &&
  ------------------
  |  |   71|  4.22k|#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: 2.11k, False: 0]
  |  Branch (320:48): [True: 0, False: 0]
  ------------------
  321|  2.11k|        a->len == b->len &&
  ------------------
  |  Branch (321:9): [True: 0, False: 2.11k]
  ------------------
  322|  2.11k|        x509_memcasecmp(a->p, b->p, b->len) == 0) {
  ------------------
  |  Branch (322:9): [True: 0, False: 0]
  ------------------
  323|      0|        return 0;
  324|      0|    }
  325|       |
  326|  2.11k|    return -1;
  327|  2.11k|}
x509_crt.c:x509_crt_verifycrl:
 2014|  2.11k|{
 2015|  2.11k|    int flags = 0;
 2016|  2.11k|    unsigned char hash[MBEDTLS_MD_MAX_SIZE];
 2017|       |#if defined(MBEDTLS_USE_PSA_CRYPTO)
 2018|       |    psa_algorithm_t psa_algorithm;
 2019|       |#else
 2020|  2.11k|    const mbedtls_md_info_t *md_info;
 2021|  2.11k|#endif /* MBEDTLS_USE_PSA_CRYPTO */
 2022|  2.11k|    size_t hash_length;
 2023|       |
 2024|  2.11k|    if (ca == NULL) {
  ------------------
  |  Branch (2024:9): [True: 0, False: 2.11k]
  ------------------
 2025|      0|        return flags;
 2026|      0|    }
 2027|       |
 2028|  2.11k|    while (crl_list != NULL) {
  ------------------
  |  Branch (2028:12): [True: 0, False: 2.11k]
  ------------------
 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|  2.11k|    return flags;
 2118|  2.11k|}
x509_crt.c:x509_crt_merge_flags_with_cb:
 3016|  3.16k|{
 3017|  3.16k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  3.16k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 3018|  3.16k|    unsigned i;
 3019|  3.16k|    uint32_t cur_flags;
 3020|  3.16k|    const mbedtls_x509_crt_verify_chain_item *cur;
 3021|       |
 3022|  8.44k|    for (i = ver_chain->len; i != 0; --i) {
  ------------------
  |  Branch (3022:30): [True: 5.28k, False: 3.16k]
  ------------------
 3023|  5.28k|        cur = &ver_chain->items[i-1];
 3024|  5.28k|        cur_flags = cur->flags;
 3025|       |
 3026|  5.28k|        if (NULL != f_vrfy) {
  ------------------
  |  Branch (3026:13): [True: 0, False: 5.28k]
  ------------------
 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|  5.28k|        *flags |= cur_flags;
 3033|  5.28k|    }
 3034|       |
 3035|  3.16k|    return 0;
 3036|  3.16k|}
x509_crt.c:x509_crt_verify_chain_reset:
  377|  3.16k|{
  378|  3.16k|    size_t i;
  379|       |
  380|  34.8k|    for (i = 0; i < MBEDTLS_X509_MAX_VERIFY_CHAIN_SIZE; i++) {
  ------------------
  |  |  258|  34.8k|#define MBEDTLS_X509_MAX_VERIFY_CHAIN_SIZE  (MBEDTLS_X509_MAX_INTERMEDIATE_CA + 2)
  |  |  ------------------
  |  |  |  |   37|  34.8k|#define MBEDTLS_X509_MAX_INTERMEDIATE_CA   8
  |  |  ------------------
  ------------------
  |  Branch (380:17): [True: 31.6k, False: 3.16k]
  ------------------
  381|  31.6k|        ver_chain->items[i].crt = NULL;
  382|  31.6k|        ver_chain->items[i].flags = (uint32_t) -1;
  383|  31.6k|    }
  384|       |
  385|  3.16k|    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|  3.16k|}

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

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

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

libspdm_get_random_number_64:
   26|     60|{
   27|     60|    int fd;
   28|       |
   29|     60|    assert(rand_data != NULL);
   30|       |
   31|     60|    fd = open("/dev/urandom", O_RDONLY);
   32|     60|    if (fd < 0) {
  ------------------
  |  Branch (32:9): [True: 0, False: 60]
  ------------------
   33|      0|        printf("cannot open /dev/urandom\n");
   34|      0|        return false;
   35|      0|    }
   36|     60|    if (read(fd, rand_data, sizeof(*rand_data)) != sizeof(*rand_data)) {
  ------------------
  |  Branch (36:9): [True: 0, False: 60]
  ------------------
   37|      0|        printf("Cannot read /dev/urandom\n");
   38|      0|        close(fd);
   39|      0|        return false;
   40|      0|    }
   41|     60|    close(fd);
   42|       |
   43|     60|    return true;
   44|     60|}

libspdm_get_asym_get_private_key_from_pem:
   23|      3|{
   24|      3|    switch (base_asym_algo) {
   25|      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 (25:5): [True: 0, False: 3]
  ------------------
   26|      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 (26:5): [True: 0, False: 3]
  ------------------
   27|      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 (27:5): [True: 0, False: 3]
  ------------------
   28|      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 (28:5): [True: 0, False: 3]
  ------------------
   29|      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 (29:5): [True: 0, False: 3]
  ------------------
   30|      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 (30:5): [True: 0, False: 3]
  ------------------
   31|      0|#if (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT)
   32|      0|        return libspdm_rsa_get_private_key_from_pem;
   33|       |#else
   34|       |        LIBSPDM_ASSERT(false);
   35|       |        break;
   36|       |#endif
   37|      3|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
  ------------------
  |  |  375|      3|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256 0x00000010
  ------------------
  |  Branch (37:5): [True: 3, False: 0]
  ------------------
   38|      3|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
  ------------------
  |  |  378|      3|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384 0x00000080
  ------------------
  |  Branch (38:5): [True: 0, False: 3]
  ------------------
   39|      3|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
  ------------------
  |  |  379|      3|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521 0x00000100
  ------------------
  |  Branch (39:5): [True: 0, False: 3]
  ------------------
   40|      3|#if LIBSPDM_ECDSA_SUPPORT
   41|      3|        return libspdm_ec_get_private_key_from_pem;
   42|       |#else
   43|       |        LIBSPDM_ASSERT(false);
   44|       |        break;
   45|       |#endif
   46|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
  ------------------
  |  |  385|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519 0x00000400
  ------------------
  |  Branch (46:5): [True: 0, False: 3]
  ------------------
   47|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
  ------------------
  |  |  386|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448 0x00000800
  ------------------
  |  Branch (47:5): [True: 0, False: 3]
  ------------------
   48|       |#if (LIBSPDM_EDDSA_ED25519_SUPPORT) || (LIBSPDM_EDDSA_ED448_SUPPORT)
   49|       |        return libspdm_ecd_get_private_key_from_pem;
   50|       |#else
   51|      0|        LIBSPDM_ASSERT(false);
   52|      0|        break;
   53|      0|#endif
   54|      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 (54:5): [True: 0, False: 3]
  ------------------
   55|       |#if LIBSPDM_SM2_DSA_SUPPORT
   56|       |        return libspdm_sm2_get_private_key_from_pem;
   57|       |#else
   58|      0|        LIBSPDM_ASSERT(false);
   59|      0|        break;
   60|      0|#endif
   61|      0|    default:
  ------------------
  |  Branch (61:5): [True: 0, False: 3]
  ------------------
   62|      0|        LIBSPDM_ASSERT(false);
   63|      0|        break;
   64|      3|    }
   65|       |
   66|      0|    return NULL;
   67|      3|}
libspdm_asym_get_private_key_from_pem:
   87|      3|{
   88|      3|    libspdm_asym_get_private_key_from_pem_func asym_get_private_key_from_pem;
   89|      3|    asym_get_private_key_from_pem = libspdm_get_asym_get_private_key_from_pem(base_asym_algo);
   90|      3|    if (asym_get_private_key_from_pem == NULL) {
  ------------------
  |  Branch (90:9): [True: 0, False: 3]
  ------------------
   91|      0|        return false;
   92|      0|    }
   93|      3|    return asym_get_private_key_from_pem(pem_data, pem_size, password, context);
   94|      3|}

libspdm_challenge_opaque_data:
   34|      3|{
   35|      3|    size_t index;
   36|       |
   37|      3|    LIBSPDM_ASSERT(libspdm_secret_lib_challenge_opaque_data_size <= *opaque_data_size);
   38|       |
   39|      3|    *opaque_data_size = libspdm_secret_lib_challenge_opaque_data_size;
   40|       |
   41|      3|    for (index = 0; index < *opaque_data_size; index++)
  ------------------
  |  Branch (41:21): [True: 0, False: 3]
  ------------------
   42|      0|    {
   43|      0|        ((uint8_t *)opaque_data)[index] = (uint8_t)index;
   44|      0|    }
   45|       |
   46|      3|    return true;
   47|      3|}

libspdm_read_responder_private_key:
   24|      3|{
   25|      3|    bool res;
   26|      3|    char *file;
   27|       |
   28|      3|    switch (base_asym_algo) {
   29|      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 (29:5): [True: 0, False: 3]
  ------------------
   30|      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 (30:5): [True: 0, False: 3]
  ------------------
   31|      0|        file = "rsa2048/end_responder.key";
   32|      0|        break;
   33|      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 (33:5): [True: 0, False: 3]
  ------------------
   34|      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 (34:5): [True: 0, False: 3]
  ------------------
   35|      0|        file = "rsa3072/end_responder.key";
   36|      0|        break;
   37|      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 (37:5): [True: 0, False: 3]
  ------------------
   38|      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 (38:5): [True: 0, False: 3]
  ------------------
   39|      0|        file = "rsa4096/end_responder.key";
   40|      0|        break;
   41|      3|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
  ------------------
  |  |  375|      3|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256 0x00000010
  ------------------
  |  Branch (41:5): [True: 3, False: 0]
  ------------------
   42|      3|        file = "ecp256/end_responder.key";
   43|      3|        break;
   44|      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 (44:5): [True: 0, False: 3]
  ------------------
   45|      0|        file = "ecp384/end_responder.key";
   46|      0|        break;
   47|      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 (47:5): [True: 0, False: 3]
  ------------------
   48|      0|        file = "ecp521/end_responder.key";
   49|      0|        break;
   50|      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 (50:5): [True: 0, False: 3]
  ------------------
   51|      0|        file = "sm2/end_responder.key";
   52|      0|        break;
   53|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519:
  ------------------
  |  |  385|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED25519 0x00000400
  ------------------
  |  Branch (53:5): [True: 0, False: 3]
  ------------------
   54|      0|        file = "ed25519/end_responder.key";
   55|      0|        break;
   56|      0|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448:
  ------------------
  |  |  386|      0|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_EDDSA_ED448 0x00000800
  ------------------
  |  Branch (56:5): [True: 0, False: 3]
  ------------------
   57|      0|        file = "ed448/end_responder.key";
   58|      0|        break;
   59|      0|    default:
  ------------------
  |  Branch (59:5): [True: 0, False: 3]
  ------------------
   60|      0|        LIBSPDM_ASSERT(false);
   61|      0|        return false;
   62|      3|    }
   63|      3|    res = libspdm_read_input_file(file, data, size);
   64|      3|    return res;
   65|      3|}

libspdm_read_responder_public_certificate_chain:
  369|  1.05k|{
  370|  1.05k|    bool res;
  371|  1.05k|    void *file_data;
  372|  1.05k|    size_t file_size;
  373|  1.05k|    spdm_cert_chain_t *cert_chain;
  374|  1.05k|    size_t cert_chain_size;
  375|  1.05k|    char *file;
  376|  1.05k|    const uint8_t *root_cert;
  377|  1.05k|    size_t root_cert_len;
  378|  1.05k|    size_t digest_size;
  379|  1.05k|    bool is_requester_cert;
  380|  1.05k|    bool is_device_cert_model;
  381|       |
  382|  1.05k|    is_requester_cert = false;
  383|       |
  384|       |    /*default is true*/
  385|  1.05k|    is_device_cert_model = true;
  386|       |
  387|  1.05k|    *data = NULL;
  388|  1.05k|    *size = 0;
  389|  1.05k|    if (hash != NULL) {
  ------------------
  |  Branch (389:9): [True: 0, False: 1.05k]
  ------------------
  390|      0|        *hash = NULL;
  391|      0|    }
  392|  1.05k|    if (hash_size != NULL) {
  ------------------
  |  Branch (392:9): [True: 0, False: 1.05k]
  ------------------
  393|      0|        *hash_size = 0;
  394|      0|    }
  395|       |
  396|  1.05k|    if (base_asym_algo == 0) {
  ------------------
  |  Branch (396:9): [True: 0, False: 1.05k]
  ------------------
  397|      0|        return false;
  398|      0|    }
  399|       |
  400|  1.05k|    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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  411|      0|        file = "rsa4096/bundle_responder.certchain.der";
  412|      0|        break;
  413|  1.05k|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
  ------------------
  |  |  375|  1.05k|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256 0x00000010
  ------------------
  |  Branch (413:5): [True: 1.05k, False: 0]
  ------------------
  414|  1.05k|        file = "ecp256/bundle_responder.certchain.der";
  415|  1.05k|        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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  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: 1.05k]
  ------------------
  429|      0|        file = "ed448/bundle_responder.certchain.der";
  430|      0|        break;
  431|      0|    default:
  ------------------
  |  Branch (431:5): [True: 0, False: 1.05k]
  ------------------
  432|      0|        LIBSPDM_ASSERT(false);
  433|      0|        return false;
  434|  1.05k|    }
  435|  1.05k|    res = libspdm_read_input_file(file, &file_data, &file_size);
  436|  1.05k|    if (!res) {
  ------------------
  |  Branch (436:9): [True: 0, False: 1.05k]
  ------------------
  437|      0|        return res;
  438|      0|    }
  439|       |
  440|  1.05k|    digest_size = libspdm_get_hash_size(base_hash_algo);
  441|       |
  442|  1.05k|    cert_chain_size = sizeof(spdm_cert_chain_t) + digest_size + file_size;
  443|  1.05k|    cert_chain = (void *)malloc(cert_chain_size);
  444|  1.05k|    if (cert_chain == NULL) {
  ------------------
  |  Branch (444:9): [True: 0, False: 1.05k]
  ------------------
  445|      0|        free(file_data);
  446|      0|        return false;
  447|      0|    }
  448|  1.05k|    cert_chain->length = (uint16_t)cert_chain_size;
  449|  1.05k|    cert_chain->reserved = 0;
  450|       |
  451|  1.05k|    res = libspdm_verify_cert_chain_data(file_data, file_size,
  452|  1.05k|                                         base_asym_algo, base_hash_algo,
  453|  1.05k|                                         is_requester_cert, is_device_cert_model);
  454|  1.05k|    if (!res) {
  ------------------
  |  Branch (454:9): [True: 0, False: 1.05k]
  ------------------
  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|  1.05k|    res = libspdm_x509_get_cert_from_cert_chain(file_data, file_size, 0, &root_cert,
  464|  1.05k|                                                &root_cert_len);
  465|  1.05k|    if (!res) {
  ------------------
  |  Branch (465:9): [True: 0, False: 1.05k]
  ------------------
  466|      0|        free(file_data);
  467|      0|        free(cert_chain);
  468|      0|        return res;
  469|      0|    }
  470|       |
  471|  1.05k|    res = libspdm_hash_all(base_hash_algo, root_cert, root_cert_len,
  472|  1.05k|                           (uint8_t *)(cert_chain + 1));
  473|  1.05k|    if (!res) {
  ------------------
  |  Branch (473:9): [True: 0, False: 1.05k]
  ------------------
  474|      0|        free(file_data);
  475|      0|        free(cert_chain);
  476|      0|        return res;
  477|      0|    }
  478|  1.05k|    libspdm_copy_mem((uint8_t *)cert_chain + sizeof(spdm_cert_chain_t) + digest_size,
  479|  1.05k|                     cert_chain_size - (sizeof(spdm_cert_chain_t) + digest_size),
  480|  1.05k|                     file_data, file_size);
  481|       |
  482|  1.05k|    *data = cert_chain;
  483|  1.05k|    *size = cert_chain_size;
  484|  1.05k|    if (hash != NULL) {
  ------------------
  |  Branch (484:9): [True: 0, False: 1.05k]
  ------------------
  485|      0|        *hash = (cert_chain + 1);
  486|      0|    }
  487|  1.05k|    if (hash_size != NULL) {
  ------------------
  |  Branch (487:9): [True: 0, False: 1.05k]
  ------------------
  488|      0|        *hash_size = digest_size;
  489|      0|    }
  490|       |
  491|  1.05k|    free(file_data);
  492|  1.05k|    return true;
  493|  1.05k|}

libspdm_responder_data_sign:
  113|      3|{
  114|      3|    void *context;
  115|      3|    bool result;
  116|      3|#if !LIBSPDM_PRIVATE_KEY_MODE_RAW_KEY_ONLY
  117|      3|    if (g_private_key_mode) {
  ------------------
  |  Branch (117:9): [True: 3, False: 0]
  ------------------
  118|      3|        void *private_pem;
  119|      3|        size_t private_pem_size;
  120|       |
  121|      3|        result = libspdm_read_responder_private_key(
  122|      3|            base_asym_algo, &private_pem, &private_pem_size);
  123|      3|        if (!result) {
  ------------------
  |  Branch (123:13): [True: 0, False: 3]
  ------------------
  124|      0|            return false;
  125|      0|        }
  126|       |
  127|      3|        result = libspdm_asym_get_private_key_from_pem(
  128|      3|            base_asym_algo, private_pem, private_pem_size, NULL, &context);
  129|      3|        if (!result) {
  ------------------
  |  Branch (129:13): [True: 0, False: 3]
  ------------------
  130|      0|            libspdm_zero_mem(private_pem, private_pem_size);
  131|      0|            free(private_pem);
  132|      0|            return false;
  133|      0|        }
  134|       |
  135|      3|        if (is_data_hash) {
  ------------------
  |  Branch (135:13): [True: 3, False: 0]
  ------------------
  136|      3|            result = libspdm_asym_sign_hash(spdm_version, op_code, base_asym_algo, base_hash_algo,
  137|      3|                                            context,
  138|      3|                                            message, message_size, signature, sig_size);
  139|      3|        } else {
  140|      0|            result = libspdm_asym_sign(spdm_version, op_code, base_asym_algo,
  141|      0|                                       base_hash_algo, context,
  142|      0|                                       message, message_size,
  143|      0|                                       signature, sig_size);
  144|      0|        }
  145|      3|        libspdm_asym_free(base_asym_algo, context);
  146|      3|        libspdm_zero_mem(private_pem, private_pem_size);
  147|      3|        free(private_pem);
  148|      3|    } else {
  149|      0|#endif
  150|      0|    result = libspdm_get_responder_private_key_from_raw_data(base_asym_algo, &context);
  151|      0|    if (!result) {
  ------------------
  |  Branch (151:9): [True: 0, False: 0]
  ------------------
  152|      0|        return false;
  153|      0|    }
  154|       |
  155|      0|    if (is_data_hash) {
  ------------------
  |  Branch (155:9): [True: 0, False: 0]
  ------------------
  156|      0|        result = libspdm_asym_sign_hash(spdm_version, op_code, base_asym_algo, base_hash_algo,
  157|      0|                                        context,
  158|      0|                                        message, message_size, signature, sig_size);
  159|      0|    } else {
  160|      0|        result = libspdm_asym_sign(spdm_version, op_code, base_asym_algo,
  161|      0|                                   base_hash_algo, context,
  162|      0|                                   message, message_size,
  163|      0|                                   signature, sig_size);
  164|      0|    }
  165|      0|    libspdm_asym_free(base_asym_algo, context);
  166|      0|#if !LIBSPDM_PRIVATE_KEY_MODE_RAW_KEY_ONLY
  167|      0|}
  168|      3|#endif
  169|       |
  170|       |#if LIBSPDM_SECRET_LIB_SIGN_LITTLE_ENDIAN
  171|       |    if ((spdm_version >> SPDM_VERSION_NUMBER_SHIFT_BIT) <= SPDM_MESSAGE_VERSION_11) {
  172|       |        if (result) {
  173|       |            libspdm_copy_signature_swap_endian(
  174|       |                base_asym_algo, signature, *sig_size, signature, *sig_size);
  175|       |        }
  176|       |    }
  177|       |#endif
  178|       |
  179|      3|    return result;
  180|      3|}

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

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

libspdm_get_max_buffer_size:
   15|    264|{
   16|    264|    return LIBSPDM_MAX_SPDM_MSG_SIZE;
  ------------------
  |  |  101|    264|#define LIBSPDM_MAX_SPDM_MSG_SIZE 0x1200
  ------------------
   17|    264|}
libspdm_test_responder_challenge_case1:
   27|    132|{
   28|    132|    libspdm_test_context_t *spdm_test_context;
   29|    132|    libspdm_context_t *spdm_context;
   30|    132|    size_t response_size;
   31|    132|    uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
   32|    132|    void *data;
   33|    132|    size_t data_size;
   34|       |
   35|    132|    spdm_test_context = *State;
   36|    132|    spdm_context = spdm_test_context->spdm_context;
   37|       |
   38|    132|    spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
   39|    132|    spdm_context->local_context.capability.flags = 0;
   40|    132|    spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
  ------------------
  |  |  235|    132|#define SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP 0x00000004
  ------------------
   41|    132|    spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
   42|    132|    spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
   43|    132|    spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
   44|    132|    spdm_context->connection_info.algorithm.measurement_hash_algo =
   45|    132|        m_libspdm_use_measurement_hash_algo;
   46|    132|    spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
  ------------------
  |  |  111|    132|#define SPDM_MESSAGE_VERSION_11 0x11
  ------------------
   47|    132|                                            SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    132|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
   48|    132|    libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
   49|    132|                                                    m_libspdm_use_asym_algo, &data,
   50|    132|                                                    &data_size,
   51|    132|                                                    NULL, NULL);
   52|    132|    spdm_context->local_context.local_cert_chain_provision[0] = data;
   53|    132|    spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
   54|       |
   55|    132|    libspdm_secret_lib_challenge_opaque_data_size = 0;
   56|    132|    libspdm_reset_message_c(spdm_context);
   57|       |
   58|    132|    response_size = sizeof(response);
   59|       |
   60|    132|    libspdm_get_response_challenge_auth(spdm_context, spdm_test_context->test_buffer_size,
   61|    132|                                        spdm_test_context->test_buffer, &response_size, response);
   62|    132|    free(data);
   63|    132|}
libspdm_test_responder_challenge_case2:
   66|    132|{
   67|    132|    libspdm_test_context_t *spdm_test_context;
   68|    132|    libspdm_context_t *spdm_context;
   69|    132|    size_t response_size;
   70|    132|    uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
   71|    132|    void *data;
   72|    132|    size_t data_size;
   73|       |
   74|    132|    spdm_test_context = *State;
   75|    132|    spdm_context = spdm_test_context->spdm_context;
   76|       |
   77|    132|    spdm_context->response_state = LIBSPDM_RESPONSE_STATE_BUSY;
   78|    132|    spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
   79|    132|    spdm_context->local_context.capability.flags = 0;
   80|    132|    spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
  ------------------
  |  |  235|    132|#define SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP 0x00000004
  ------------------
   81|    132|    spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
   82|    132|    spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
   83|    132|    spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
   84|    132|    spdm_context->connection_info.algorithm.measurement_hash_algo =
   85|    132|        m_libspdm_use_measurement_hash_algo;
   86|    132|    spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
  ------------------
  |  |  111|    132|#define SPDM_MESSAGE_VERSION_11 0x11
  ------------------
   87|    132|                                            SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    132|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
   88|    132|    libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
   89|    132|                                                    m_libspdm_use_asym_algo, &data,
   90|    132|                                                    &data_size,
   91|    132|                                                    NULL, NULL);
   92|    132|    spdm_context->local_context.local_cert_chain_provision[0] = data;
   93|    132|    spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
   94|       |
   95|    132|    libspdm_secret_lib_challenge_opaque_data_size = 0;
   96|    132|    libspdm_reset_message_c(spdm_context);
   97|    132|    response_size = sizeof(response);
   98|       |
   99|    132|    libspdm_get_response_challenge_auth(spdm_context, spdm_test_context->test_buffer_size,
  100|    132|                                        spdm_test_context->test_buffer, &response_size, response);
  101|    132|    free(data);
  102|    132|}
libspdm_test_responder_challenge_case3:
  105|    132|{
  106|    132|    libspdm_test_context_t *spdm_test_context;
  107|    132|    libspdm_context_t *spdm_context;
  108|    132|    size_t response_size;
  109|    132|    uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
  110|    132|    void *data;
  111|    132|    size_t data_size;
  112|       |
  113|    132|    spdm_test_context = *State;
  114|    132|    spdm_context = spdm_test_context->spdm_context;
  115|       |
  116|    132|    spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
  117|    132|    spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NOT_STARTED;
  118|    132|    spdm_context->local_context.capability.flags = 0;
  119|    132|    spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
  ------------------
  |  |  235|    132|#define SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP 0x00000004
  ------------------
  120|    132|    spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
  121|    132|    spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
  122|    132|    spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
  123|    132|    spdm_context->connection_info.algorithm.measurement_hash_algo =
  124|    132|        m_libspdm_use_measurement_hash_algo;
  125|    132|    spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
  ------------------
  |  |  111|    132|#define SPDM_MESSAGE_VERSION_11 0x11
  ------------------
  126|    132|                                            SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    132|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
  127|    132|    libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
  128|    132|                                                    m_libspdm_use_asym_algo, &data,
  129|    132|                                                    &data_size,
  130|    132|                                                    NULL, NULL);
  131|    132|    spdm_context->local_context.local_cert_chain_provision[0] = data;
  132|    132|    spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
  133|       |
  134|    132|    libspdm_secret_lib_challenge_opaque_data_size = 0;
  135|    132|    libspdm_reset_message_c(spdm_context);
  136|       |
  137|    132|    response_size = sizeof(response);
  138|       |
  139|    132|    libspdm_get_response_challenge_auth(spdm_context, spdm_test_context->test_buffer_size,
  140|    132|                                        spdm_test_context->test_buffer, &response_size, response);
  141|    132|    free(data);
  142|    132|}
libspdm_test_responder_challenge_case4:
  145|    132|{
  146|    132|    libspdm_test_context_t *spdm_test_context;
  147|    132|    libspdm_context_t *spdm_context;
  148|    132|    size_t response_size;
  149|    132|    uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
  150|    132|    void *data;
  151|    132|    size_t data_size;
  152|    132|    spdm_test_context = *State;
  153|    132|    spdm_context = spdm_test_context->spdm_context;
  154|       |
  155|    132|    spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
  156|    132|    spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
  157|    132|    spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
  158|    132|    spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
  159|    132|    spdm_context->connection_info.algorithm.measurement_hash_algo =
  160|    132|        m_libspdm_use_measurement_hash_algo;
  161|    132|    spdm_context->local_context.capability.flags =
  162|    132|        SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
  ------------------
  |  |  250|    132|#define SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP 0x00000100
  ------------------
  163|    132|    spdm_context->connection_info.capability.flags =
  164|    132|        SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP |
  ------------------
  |  |  235|    132|#define SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP 0x00000004
  ------------------
  165|    132|        SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP |
  ------------------
  |  |  186|    132|#define SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP 0x00000004
  ------------------
  166|    132|        SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP |
  ------------------
  |  |  185|    132|#define SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP 0x00000002
  ------------------
  167|    132|        SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
  ------------------
  |  |  189|    132|#define SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP 0x00000100
  ------------------
  168|    132|    spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
  ------------------
  |  |  111|    132|#define SPDM_MESSAGE_VERSION_11 0x11
  ------------------
  169|    132|                                            SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    132|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
  170|    132|    libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
  171|    132|                                                    m_libspdm_use_asym_algo, &data,
  172|    132|                                                    &data_size,
  173|    132|                                                    NULL, NULL);
  174|    132|    spdm_context->local_context.local_cert_chain_provision[0] = data;
  175|    132|    spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
  176|       |
  177|    132|    libspdm_secret_lib_challenge_opaque_data_size = 0;
  178|    132|    spdm_context->local_context.basic_mut_auth_requested = 1;
  179|    132|    response_size = sizeof(response);
  180|    132|    libspdm_reset_message_c(spdm_context);
  181|    132|    libspdm_get_response_challenge_auth(spdm_context, spdm_test_context->test_buffer_size,
  182|    132|                                        spdm_test_context->test_buffer, &response_size, response);
  183|    132|    free(data);
  184|    132|}
libspdm_test_responder_challenge_case5:
  187|    132|{
  188|    132|    libspdm_test_context_t *spdm_test_context;
  189|    132|    libspdm_context_t *spdm_context;
  190|    132|    size_t response_size;
  191|    132|    uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
  192|    132|    void *data;
  193|    132|    size_t data_size;
  194|       |
  195|    132|    spdm_test_context = *State;
  196|    132|    spdm_context = spdm_test_context->spdm_context;
  197|       |
  198|    132|    spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
  199|    132|    spdm_context->local_context.capability.flags = 0;
  200|    132|    spdm_context->local_context.capability.flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP |
  ------------------
  |  |  235|    132|#define SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP 0x00000004
  ------------------
  201|    132|                                                   SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP;
  ------------------
  |  |  236|    132|#define SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP (0x00000008 | 0x00000010)
  ------------------
  202|    132|    spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
  203|    132|    spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
  204|    132|    spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
  205|    132|    spdm_context->connection_info.algorithm.measurement_hash_algo =
  206|    132|        m_libspdm_use_measurement_hash_algo;
  207|       |
  208|    132|    spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
  ------------------
  |  |  111|    132|#define SPDM_MESSAGE_VERSION_11 0x11
  ------------------
  209|    132|                                            SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    132|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
  210|    132|    libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
  211|    132|                                                    m_libspdm_use_asym_algo, &data,
  212|    132|                                                    &data_size,
  213|    132|                                                    NULL, NULL);
  214|    132|    spdm_context->local_context.local_cert_chain_provision[0] = data;
  215|    132|    spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
  216|       |
  217|    132|    libspdm_secret_lib_challenge_opaque_data_size = 0;
  218|    132|    libspdm_reset_message_c(spdm_context);
  219|       |
  220|    132|    response_size = sizeof(response);
  221|       |
  222|    132|    libspdm_get_response_challenge_auth(spdm_context, spdm_test_context->test_buffer_size,
  223|    132|                                        spdm_test_context->test_buffer, &response_size, response);
  224|    132|    free(data);
  225|    132|}
libspdm_test_responder_challenge_case6:
  228|    132|{
  229|    132|    libspdm_test_context_t *spdm_test_context;
  230|    132|    libspdm_context_t *spdm_context;
  231|    132|    size_t response_size;
  232|    132|    uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
  233|    132|    void *data;
  234|    132|    size_t data_size;
  235|       |
  236|    132|    spdm_test_context = *State;
  237|    132|    spdm_context = spdm_test_context->spdm_context;
  238|       |
  239|    132|    spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
  240|    132|    spdm_context->local_context.capability.flags =
  241|    132|        SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP |
  ------------------
  |  |  235|    132|#define SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP 0x00000004
  ------------------
  242|    132|        SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
  ------------------
  |  |  250|    132|#define SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP 0x00000100
  ------------------
  243|    132|    spdm_context->connection_info.capability.flags =
  244|    132|        SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PUB_KEY_ID_CAP |
  ------------------
  |  |  197|    132|#define SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PUB_KEY_ID_CAP 0x00010000
  ------------------
  245|    132|        SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP |
  ------------------
  |  |  186|    132|#define SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP 0x00000004
  ------------------
  246|    132|        SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP;
  ------------------
  |  |  189|    132|#define SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP 0x00000100
  ------------------
  247|    132|    spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
  248|    132|    spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
  249|    132|    spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
  250|    132|    spdm_context->connection_info.algorithm.measurement_hash_algo =
  251|    132|        m_libspdm_use_measurement_hash_algo;
  252|    132|    spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
  ------------------
  |  |  111|    132|#define SPDM_MESSAGE_VERSION_11 0x11
  ------------------
  253|    132|                                            SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    132|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
  254|    132|    libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
  255|    132|                                                    m_libspdm_use_asym_algo, &data,
  256|    132|                                                    &data_size,
  257|    132|                                                    NULL, NULL);
  258|    132|    spdm_context->local_context.local_cert_chain_provision[0] = data;
  259|    132|    spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
  260|       |
  261|    132|    libspdm_secret_lib_challenge_opaque_data_size = 0;
  262|    132|    spdm_context->local_context.basic_mut_auth_requested = 1;
  263|    132|    response_size = sizeof(response);
  264|    132|    libspdm_reset_message_c(spdm_context);
  265|    132|    libspdm_get_response_challenge_auth(spdm_context, spdm_test_context->test_buffer_size,
  266|    132|                                        spdm_test_context->test_buffer, &response_size, response);
  267|    132|    free(data);
  268|    132|}
libspdm_test_responder_challenge_case7:
  271|    132|{
  272|    132|    libspdm_test_context_t *spdm_test_context;
  273|    132|    libspdm_context_t *spdm_context;
  274|    132|    size_t response_size;
  275|    132|    uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
  276|    132|    void *data;
  277|    132|    size_t data_size;
  278|       |
  279|    132|    spdm_test_context = *State;
  280|    132|    spdm_context = spdm_test_context->spdm_context;
  281|       |
  282|    132|    spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
  283|    132|    spdm_context->local_context.capability.flags = 0;
  284|    132|    spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
  ------------------
  |  |  235|    132|#define SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP 0x00000004
  ------------------
  285|    132|    spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
  286|    132|    spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
  287|    132|    spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
  288|    132|    spdm_context->connection_info.algorithm.measurement_hash_algo =
  289|    132|        m_libspdm_use_measurement_hash_algo;
  290|    132|    spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
  ------------------
  |  |  112|    132|#define SPDM_MESSAGE_VERSION_12 0x12
  ------------------
  291|    132|                                            SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    132|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
  292|    132|    libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
  293|    132|                                                    m_libspdm_use_asym_algo, &data,
  294|    132|                                                    &data_size,
  295|    132|                                                    NULL, NULL);
  296|    132|    spdm_context->local_context.local_cert_chain_provision[0] = data;
  297|    132|    spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
  298|       |
  299|    132|    libspdm_secret_lib_challenge_opaque_data_size = 0;
  300|    132|    libspdm_reset_message_c(spdm_context);
  301|       |
  302|    132|    response_size = sizeof(response);
  303|       |
  304|    132|    libspdm_get_response_challenge_auth(spdm_context, spdm_test_context->test_buffer_size,
  305|    132|                                        spdm_test_context->test_buffer, &response_size, response);
  306|    132|    free(data);
  307|    132|}
libspdm_test_responder_challenge_case8:
  310|    132|{
  311|    132|    libspdm_test_context_t *spdm_test_context;
  312|    132|    libspdm_context_t *spdm_context;
  313|    132|    size_t response_size;
  314|    132|    uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
  315|    132|    void *data;
  316|    132|    size_t data_size;
  317|       |
  318|    132|    spdm_test_context = *State;
  319|    132|    spdm_context = spdm_test_context->spdm_context;
  320|       |
  321|    132|    spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
  322|    132|    spdm_context->local_context.capability.flags = 0;
  323|    132|    spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP;
  ------------------
  |  |  235|    132|#define SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP 0x00000004
  ------------------
  324|    132|    spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
  325|    132|    spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
  326|    132|    spdm_context->connection_info.algorithm.measurement_spec = m_libspdm_use_measurement_spec;
  327|    132|    spdm_context->connection_info.algorithm.measurement_hash_algo =
  328|    132|        m_libspdm_use_measurement_hash_algo;
  329|    132|    spdm_context->connection_info.multi_key_conn_rsp = true;
  330|       |
  331|    132|    spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
  ------------------
  |  |  113|    132|#define SPDM_MESSAGE_VERSION_13 0x13
  ------------------
  332|    132|                                            SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    132|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
  333|    132|    libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
  334|    132|                                                    m_libspdm_use_asym_algo, &data,
  335|    132|                                                    &data_size, NULL, NULL);
  336|    132|    spdm_context->local_context.local_cert_chain_provision[0] = data;
  337|    132|    spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
  338|       |
  339|    132|    libspdm_secret_lib_challenge_opaque_data_size = 0;
  340|    132|    libspdm_reset_message_c(spdm_context);
  341|       |#if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
  342|       |    spdm_context->transcript.message_m.buffer_size =
  343|       |        spdm_context->transcript.message_m.max_buffer_size;
  344|       |#endif
  345|       |
  346|  1.18k|    for (uint8_t i = 0; i < SPDM_MAX_SLOT_COUNT; i++) {
  ------------------
  |  |   18|  1.18k|#define SPDM_MAX_SLOT_COUNT 8
  ------------------
  |  Branch (346:25): [True: 1.05k, False: 132]
  ------------------
  347|  1.05k|        spdm_context->local_context.local_key_usage_bit_mask[i] =
  348|  1.05k|            SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE |
  ------------------
  |  |  603|  1.05k|#define SPDM_KEY_USAGE_BIT_MASK_KEY_EX_USE 0x0001
  ------------------
  349|  1.05k|            SPDM_KEY_USAGE_BIT_MASK_MEASUREMENT_USE;
  ------------------
  |  |  605|  1.05k|#define SPDM_KEY_USAGE_BIT_MASK_MEASUREMENT_USE 0x0004
  ------------------
  350|  1.05k|    }
  351|       |
  352|    132|    response_size = sizeof(response);
  353|    132|    libspdm_get_response_challenge_auth(spdm_context, spdm_test_context->test_buffer_size,
  354|    132|                                        spdm_test_context->test_buffer, &response_size, response);
  355|    132|    free(data);
  356|    132|}
libspdm_run_test_harness:
  359|    132|{
  360|    132|    void *State;
  361|    132|    spdm_message_header_t *spdm_request_header;
  362|    132|    libspdm_setup_test_context(&m_libspdm_responder_challenge_test_context);
  363|       |
  364|    132|    spdm_request_header = (spdm_message_header_t*)test_buffer;
  365|       |
  366|    132|    if (spdm_request_header->request_response_code != SPDM_CHALLENGE) {
  ------------------
  |  |   68|    132|#define SPDM_CHALLENGE 0x83
  ------------------
  |  Branch (366:9): [True: 131, False: 1]
  ------------------
  367|    131|        spdm_request_header->request_response_code = SPDM_CHALLENGE;
  ------------------
  |  |   68|    131|#define SPDM_CHALLENGE 0x83
  ------------------
  368|    131|    }
  369|       |
  370|    132|    m_libspdm_responder_challenge_test_context.test_buffer = test_buffer;
  371|    132|    m_libspdm_responder_challenge_test_context.test_buffer_size = test_buffer_size;
  372|       |
  373|       |    /* Success Case*/
  374|    132|    libspdm_unit_test_group_setup(&State);
  375|    132|    libspdm_test_responder_challenge_case1(&State);
  376|    132|    libspdm_unit_test_group_teardown(&State);
  377|       |
  378|       |    /* response_state: LIBSPDM_RESPONSE_STATE_BUSY*/
  379|    132|    libspdm_unit_test_group_setup(&State);
  380|    132|    libspdm_test_responder_challenge_case2(&State);
  381|    132|    libspdm_unit_test_group_teardown(&State);
  382|       |
  383|       |    /* connection_state Check*/
  384|    132|    libspdm_unit_test_group_setup(&State);
  385|    132|    libspdm_test_responder_challenge_case3(&State);
  386|    132|    libspdm_unit_test_group_teardown(&State);
  387|       |
  388|       |    /* Support Capabilities flag */
  389|    132|    libspdm_unit_test_group_setup(&State);
  390|    132|    libspdm_test_responder_challenge_case4(&State);
  391|    132|    libspdm_unit_test_group_teardown(&State);
  392|       |
  393|       |    /*  Capabilities flag: SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP*/
  394|    132|    libspdm_unit_test_group_setup(&State);
  395|    132|    libspdm_test_responder_challenge_case5(&State);
  396|    132|    libspdm_unit_test_group_teardown(&State);
  397|       |
  398|       |    /* basic_mut_auth_requested : 1 */
  399|    132|    libspdm_unit_test_group_setup(&State);
  400|    132|    libspdm_test_responder_challenge_case6(&State);
  401|    132|    libspdm_unit_test_group_teardown(&State);
  402|       |
  403|       |    /* V1.2 requester*/
  404|    132|    libspdm_unit_test_group_setup(&State);
  405|    132|    libspdm_test_responder_challenge_case7(&State);
  406|    132|    libspdm_unit_test_group_teardown(&State);
  407|       |
  408|       |    /* V1.3 requester*/
  409|    132|    libspdm_unit_test_group_setup(&State);
  410|    132|    libspdm_test_responder_challenge_case8(&State);
  411|    132|    libspdm_unit_test_group_teardown(&State);
  412|    132|}

