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

libspdm_session_info_init:
   18|    424|{
   19|    424|    libspdm_session_type_t session_type;
   20|    424|    uint32_t capabilities_flag;
   21|       |
   22|    424|    if (session_id != INVALID_SESSION_ID) {
  ------------------
  |  |   28|    424|#define INVALID_SESSION_ID 0
  ------------------
  |  Branch (22:9): [True: 423, False: 1]
  ------------------
   23|    423|        if (use_psk) {
  ------------------
  |  Branch (23:13): [True: 423, False: 0]
  ------------------
   24|    423|            LIBSPDM_ASSERT((spdm_context->max_psk_session_count == 0) ||
   25|    423|                           (spdm_context->current_psk_session_count <
   26|    423|                            spdm_context->max_psk_session_count));
   27|    423|            spdm_context->current_psk_session_count++;
   28|    423|        } else {
   29|      0|            LIBSPDM_ASSERT((spdm_context->max_dhe_session_count == 0) ||
   30|      0|                           (spdm_context->current_dhe_session_count <
   31|      0|                            spdm_context->max_dhe_session_count));
   32|      0|            spdm_context->current_dhe_session_count++;
   33|      0|        }
   34|    423|    } else {
   35|      1|        if (use_psk) {
  ------------------
  |  Branch (35:13): [True: 1, False: 0]
  ------------------
   36|      1|            if (spdm_context->current_psk_session_count > 0) {
  ------------------
  |  Branch (36:17): [True: 1, False: 0]
  ------------------
   37|      1|                spdm_context->current_psk_session_count--;
   38|      1|            }
   39|      1|        } else {
   40|      0|            if (spdm_context->current_dhe_session_count > 0) {
  ------------------
  |  Branch (40:17): [True: 0, False: 0]
  ------------------
   41|      0|                spdm_context->current_dhe_session_count--;
   42|      0|            }
   43|      0|        }
   44|      1|    }
   45|       |
   46|    424|    capabilities_flag = spdm_context->connection_info.capability.flags &
   47|    424|                        spdm_context->local_context.capability.flags;
   48|    424|    switch (capabilities_flag &
   49|    424|            (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP |
  ------------------
  |  |  187|    424|#define SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP 0x00000040
  ------------------
   50|    424|             SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP)) {
  ------------------
  |  |  188|    424|#define SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP 0x00000080
  ------------------
   51|    282|    case 0:
  ------------------
  |  Branch (51:5): [True: 282, False: 142]
  ------------------
   52|    282|        session_type = LIBSPDM_SESSION_TYPE_NONE;
   53|    282|        break;
   54|    142|    case (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP |
  ------------------
  |  |  187|    142|#define SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP 0x00000040
  ------------------
  |  Branch (54:5): [True: 142, False: 282]
  ------------------
   55|    142|          SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP):
  ------------------
  |  |  188|    142|#define SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP 0x00000080
  ------------------
   56|    142|        session_type = LIBSPDM_SESSION_TYPE_ENC_MAC;
   57|    142|        break;
   58|      0|    case SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP:
  ------------------
  |  |  188|      0|#define SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP 0x00000080
  ------------------
  |  Branch (58:5): [True: 0, False: 424]
  ------------------
   59|      0|        session_type = LIBSPDM_SESSION_TYPE_MAC_ONLY;
   60|      0|        break;
   61|      0|    default:
  ------------------
  |  Branch (61:5): [True: 0, False: 424]
  ------------------
   62|      0|        LIBSPDM_ASSERT(false);
   63|      0|        session_type = LIBSPDM_SESSION_TYPE_MAX;
   64|      0|        break;
   65|    424|    }
   66|       |
   67|    424|#if !(LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT)
   68|    424|    if (session_info->session_transcript.digest_context_th != NULL) {
  ------------------
  |  Branch (68:9): [True: 0, False: 424]
  ------------------
   69|      0|        libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
   70|      0|                           session_info->session_transcript.digest_context_th);
   71|      0|        session_info->session_transcript.digest_context_th = NULL;
   72|      0|    }
   73|    424|    if (session_info->session_transcript.digest_context_th_backup != NULL) {
  ------------------
  |  Branch (73:9): [True: 0, False: 424]
  ------------------
   74|      0|        libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
   75|      0|                           session_info->session_transcript.digest_context_th_backup);
   76|      0|        session_info->session_transcript.digest_context_th_backup = NULL;
   77|      0|    }
   78|    424|#endif
   79|       |
   80|    424|    libspdm_zero_mem (&(session_info->last_key_update_request), sizeof(spdm_key_update_request_t));
   81|    424|    libspdm_zero_mem(session_info, offsetof(libspdm_session_info_t, secured_message_context));
   82|    424|    libspdm_secured_message_init_context(session_info->secured_message_context);
   83|    424|    session_info->session_id = session_id;
   84|    424|    session_info->use_psk = use_psk;
   85|    424|    libspdm_secured_message_set_use_psk(session_info->secured_message_context, use_psk);
   86|    424|    libspdm_secured_message_set_session_type(session_info->secured_message_context, session_type);
   87|       |
   88|       |    /* DSP0277 1.2 explicitly specifies a little-endian sequence number. 1.0 and 1.1 leave it up to
   89|       |     * the Integrator to specify. */
   90|    424|    if ((spdm_context->connection_info.secured_message_version >> SPDM_VERSION_NUMBER_SHIFT_BIT) >=
  ------------------
  |  |  140|    424|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
  |  Branch (90:9): [True: 0, False: 424]
  ------------------
   91|    424|        SECURED_SPDM_VERSION_12) {
  ------------------
  |  |   59|    424|#define SECURED_SPDM_VERSION_12 0x12
  ------------------
   92|      0|        libspdm_secured_message_set_sequence_number_endian(
   93|      0|            session_info->secured_message_context,
   94|      0|            LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_LITTLE_DEC_LITTLE);
  ------------------
  |  |  251|      0|#define LIBSPDM_DATA_SESSION_SEQ_NUM_ENC_LITTLE_DEC_LITTLE 0
  ------------------
   95|    424|    } else {
   96|    424|        libspdm_secured_message_set_sequence_number_endian(session_info->secured_message_context,
   97|    424|                                                           spdm_context->sequence_number_endian);
   98|    424|    }
   99|       |
  100|    424|    libspdm_secured_message_set_max_spdm_session_sequence_number(
  101|    424|        session_info->secured_message_context, spdm_context->max_spdm_session_sequence_number);
  102|    424|    libspdm_secured_message_set_algorithms(
  103|    424|        session_info->secured_message_context,
  104|    424|        spdm_context->connection_info.version,
  105|    424|        spdm_context->connection_info.secured_message_version,
  106|    424|        spdm_context->connection_info.algorithm.base_hash_algo,
  107|    424|        spdm_context->connection_info.algorithm.dhe_named_group,
  108|    424|        spdm_context->connection_info.algorithm.aead_cipher_suite,
  109|    424|        spdm_context->connection_info.algorithm.key_schedule);
  110|    424|    session_info->session_transcript.message_encap_d.max_buffer_size =
  111|    424|        sizeof(session_info->session_transcript.message_encap_d.buffer);
  112|       |#if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
  113|       |    session_info->session_transcript.message_k.max_buffer_size =
  114|       |        sizeof(session_info->session_transcript.message_k.buffer);
  115|       |    session_info->session_transcript.message_f.max_buffer_size =
  116|       |        sizeof(session_info->session_transcript.message_f.buffer);
  117|       |    session_info->session_transcript.message_m.max_buffer_size =
  118|       |        sizeof(session_info->session_transcript.message_m.buffer);
  119|       |    session_info->session_transcript.message_e.max_buffer_size =
  120|       |        sizeof(session_info->session_transcript.message_e.buffer);
  121|       |    session_info->session_transcript.message_encap_e.max_buffer_size =
  122|       |        sizeof(session_info->session_transcript.message_encap_e.buffer);
  123|       |#endif
  124|    424|}
libspdm_get_session_info_via_session_id:
  147|    423|{
  148|    423|    libspdm_context_t *context;
  149|    423|    libspdm_session_info_t *session_info;
  150|    423|    size_t index;
  151|       |
  152|    423|    if (session_id == INVALID_SESSION_ID) {
  ------------------
  |  |   28|    423|#define INVALID_SESSION_ID 0
  ------------------
  |  Branch (152:9): [True: 0, False: 423]
  ------------------
  153|      0|        LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR,
  154|      0|                       "libspdm_get_session_info_via_session_id - Invalid session_id\n"));
  155|      0|        LIBSPDM_ASSERT(false);
  156|      0|        return NULL;
  157|      0|    }
  158|       |
  159|    423|    context = spdm_context;
  160|       |
  161|    423|    session_info = (libspdm_session_info_t *)context->session_info;
  162|    423|    for (index = 0; index < LIBSPDM_MAX_SESSION_COUNT; index++) {
  ------------------
  |  |  198|    423|#define LIBSPDM_MAX_SESSION_COUNT 4
  ------------------
  |  Branch (162:21): [True: 423, False: 0]
  ------------------
  163|    423|        if (session_info[index].session_id == session_id) {
  ------------------
  |  Branch (163:13): [True: 423, False: 0]
  ------------------
  164|    423|            return &session_info[index];
  165|    423|        }
  166|    423|    }
  167|       |
  168|      0|    LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR,
  169|      0|                   "libspdm_get_session_info_via_session_id - not found session_id\n"));
  170|      0|    return NULL;
  171|    423|}
libspdm_free_session_id:
  278|      1|{
  279|      1|    libspdm_session_info_t *session_info;
  280|      1|    size_t index;
  281|       |
  282|      1|    if (session_id == INVALID_SESSION_ID) {
  ------------------
  |  |   28|      1|#define INVALID_SESSION_ID 0
  ------------------
  |  Branch (282:9): [True: 0, False: 1]
  ------------------
  283|      0|        LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR, "libspdm_free_session_id - Invalid session_id\n"));
  284|      0|        LIBSPDM_ASSERT(false);
  285|      0|        return;
  286|      0|    }
  287|       |
  288|      1|    if (spdm_context->latest_session_id == session_id) {
  ------------------
  |  Branch (288:9): [True: 1, False: 0]
  ------------------
  289|      1|        spdm_context->latest_session_id = INVALID_SESSION_ID;
  ------------------
  |  |   28|      1|#define INVALID_SESSION_ID 0
  ------------------
  290|      1|    }
  291|       |
  292|      1|    session_info = spdm_context->session_info;
  293|      1|    for (index = 0; index < LIBSPDM_MAX_SESSION_COUNT; index++) {
  ------------------
  |  |  198|      1|#define LIBSPDM_MAX_SESSION_COUNT 4
  ------------------
  |  Branch (293:21): [True: 1, False: 0]
  ------------------
  294|      1|        if (session_info[index].session_id == session_id) {
  ------------------
  |  Branch (294:13): [True: 1, False: 0]
  ------------------
  295|      1|            libspdm_session_info_init(spdm_context,
  296|      1|                                      &session_info[index],
  297|      1|                                      INVALID_SESSION_ID,
  ------------------
  |  |   28|      1|#define INVALID_SESSION_ID 0
  ------------------
  298|      1|                                      session_info[index].use_psk);
  299|      1|            return;
  300|      1|        }
  301|      1|    }
  302|       |
  303|      0|    LIBSPDM_DEBUG((LIBSPDM_DEBUG_ERROR, "libspdm_free_session_id - MAX session_id\n"));
  304|      0|    LIBSPDM_ASSERT(false);
  305|      0|}

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

libspdm_asym_free:
  362|    282|{
  363|    282|    if (context == NULL) {
  ------------------
  |  Branch (363:9): [True: 0, False: 282]
  ------------------
  364|      0|        return;
  365|      0|    }
  366|    282|    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: 282]
  ------------------
  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: 282]
  ------------------
  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: 282]
  ------------------
  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: 282]
  ------------------
  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: 282]
  ------------------
  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: 282]
  ------------------
  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|    282|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
  ------------------
  |  |  375|    282|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256 0x00000010
  ------------------
  |  Branch (379:5): [True: 282, False: 0]
  ------------------
  380|    282|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
  ------------------
  |  |  378|    282|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384 0x00000080
  ------------------
  |  Branch (380:5): [True: 0, False: 282]
  ------------------
  381|    282|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
  ------------------
  |  |  379|    282|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521 0x00000100
  ------------------
  |  Branch (381:5): [True: 0, False: 282]
  ------------------
  382|    282|#if LIBSPDM_ECDSA_SUPPORT
  383|    282|        libspdm_ec_free(context);
  384|       |#else
  385|       |        LIBSPDM_ASSERT(false);
  386|       |#endif
  387|    282|        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: 282]
  ------------------
  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: 282]
  ------------------
  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: 282]
  ------------------
  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: 282]
  ------------------
  404|      0|        LIBSPDM_ASSERT(false);
  405|      0|        break;
  406|    282|    }
  407|    282|}

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

libspdm_get_hash_size:
   10|    706|{
   11|    706|    switch (base_hash_algo) {
   12|    706|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
  ------------------
  |  |  391|    706|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256 0x00000001
  ------------------
  |  Branch (12:5): [True: 706, False: 0]
  ------------------
   13|    706|#if LIBSPDM_SHA256_SUPPORT
   14|    706|        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: 706]
  ------------------
   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: 706]
  ------------------
   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: 706]
  ------------------
   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: 706]
  ------------------
   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: 706]
  ------------------
   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: 706]
  ------------------
   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: 706]
  ------------------
   55|      0|        return 0;
   56|    706|    }
   57|    706|}
libspdm_hash_all:
  435|    282|{
  436|    282|    switch (base_hash_algo) {
  437|    282|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
  ------------------
  |  |  391|    282|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256 0x00000001
  ------------------
  |  Branch (437:5): [True: 282, False: 0]
  ------------------
  438|    282|#if LIBSPDM_SHA256_SUPPORT
  439|    282|        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: 282]
  ------------------
  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: 282]
  ------------------
  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: 282]
  ------------------
  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: 282]
  ------------------
  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: 282]
  ------------------
  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: 282]
  ------------------
  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: 282]
  ------------------
  487|      0|        LIBSPDM_ASSERT(false);
  488|      0|        return false;
  489|    282|    }
  490|    282|}

libspdm_hkdf_expand:
   72|    564|{
   73|    564|    switch (base_hash_algo) {
   74|    564|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256:
  ------------------
  |  |  391|    564|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_256 0x00000001
  ------------------
  |  Branch (74:5): [True: 564, False: 0]
  ------------------
   75|    564|#if LIBSPDM_SHA256_SUPPORT
   76|    564|        return libspdm_hkdf_sha256_expand(prk, prk_size, info, info_size, out, out_size);
   77|       |#else
   78|       |        LIBSPDM_ASSERT(false);
   79|       |        return false;
   80|       |#endif
   81|      0|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384:
  ------------------
  |  |  392|      0|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_384 0x00000002
  ------------------
  |  Branch (81:5): [True: 0, False: 564]
  ------------------
   82|      0|#if LIBSPDM_SHA384_SUPPORT
   83|      0|        return libspdm_hkdf_sha384_expand(prk, prk_size, info, info_size, out, out_size);
   84|       |#else
   85|       |        LIBSPDM_ASSERT(false);
   86|       |        return false;
   87|       |#endif
   88|      0|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512:
  ------------------
  |  |  393|      0|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA_512 0x00000004
  ------------------
  |  Branch (88:5): [True: 0, False: 564]
  ------------------
   89|      0|#if LIBSPDM_SHA512_SUPPORT
   90|      0|        return libspdm_hkdf_sha512_expand(prk, prk_size, info, info_size, out, out_size);
   91|       |#else
   92|       |        LIBSPDM_ASSERT(false);
   93|       |        return false;
   94|       |#endif
   95|      0|    case SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_256:
  ------------------
  |  |  394|      0|#define SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_SHA3_256 0x00000008
  ------------------
  |  Branch (95:5): [True: 0, False: 564]
  ------------------
   96|      0|#if LIBSPDM_SHA3_256_SUPPORT
   97|      0|        return libspdm_hkdf_sha3_256_expand(prk, prk_size, info, info_size, out, out_size);
   98|       |#else
   99|       |        LIBSPDM_ASSERT(false);
  100|       |        return false;
  101|       |#endif
  102|      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 (102:5): [True: 0, False: 564]
  ------------------
  103|      0|#if LIBSPDM_SHA3_384_SUPPORT
  104|      0|        return libspdm_hkdf_sha3_384_expand(prk, prk_size, info, info_size, out, out_size);
  105|       |#else
  106|       |        LIBSPDM_ASSERT(false);
  107|       |        return false;
  108|       |#endif
  109|      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 (109:5): [True: 0, False: 564]
  ------------------
  110|      0|#if LIBSPDM_SHA3_512_SUPPORT
  111|      0|        return libspdm_hkdf_sha3_512_expand(prk, prk_size, info, info_size, out, out_size);
  112|       |#else
  113|       |        LIBSPDM_ASSERT(false);
  114|       |        return false;
  115|       |#endif
  116|      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 (116:5): [True: 0, False: 564]
  ------------------
  117|       |#if LIBSPDM_SM3_256_SUPPORT
  118|       |        return libspdm_hkdf_sm3_256_expand(prk, prk_size, info, info_size, out, out_size);
  119|       |#else
  120|      0|        LIBSPDM_ASSERT(false);
  121|      0|        return false;
  122|      0|#endif
  123|      0|    default:
  ------------------
  |  Branch (123:5): [True: 0, False: 564]
  ------------------
  124|      0|        LIBSPDM_ASSERT(false);
  125|      0|        return false;
  126|    564|    }
  127|    564|}

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

libspdm_get_encap_request_key_update:
   29|    282|{
   30|    282|    spdm_key_update_request_t *spdm_request;
   31|    282|    uint32_t session_id;
   32|    282|    libspdm_session_info_t *session_info;
   33|    282|    libspdm_session_state_t session_state;
   34|    282|    bool result;
   35|       |
   36|    282|    spdm_context->encap_context.last_encap_request_size = 0;
   37|       |
   38|    282|    if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_11) {
  ------------------
  |  |  111|    282|#define SPDM_MESSAGE_VERSION_11 0x11
  ------------------
  |  Branch (38:9): [True: 0, False: 282]
  ------------------
   39|      0|        return LIBSPDM_STATUS_UNSUPPORTED_CAP;
  ------------------
  |  |   78|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0002)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
   40|      0|    }
   41|       |
   42|    282|    if (!libspdm_is_capabilities_flag_supported(
  ------------------
  |  Branch (42:9): [True: 0, False: 282]
  ------------------
   43|    282|            spdm_context, false,
   44|    282|            SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP,
  ------------------
  |  |  195|    282|#define SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP 0x00004000
  ------------------
   45|    282|            SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_UPD_CAP)) {
  ------------------
  |  |  257|    282|#define SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_UPD_CAP 0x00004000
  ------------------
   46|      0|        return LIBSPDM_STATUS_UNSUPPORTED_CAP;
  ------------------
  |  |   78|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0002)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
   47|      0|    }
   48|       |
   49|    282|    if (!spdm_context->last_spdm_request_session_id_valid) {
  ------------------
  |  Branch (49:9): [True: 0, False: 282]
  ------------------
   50|      0|        return LIBSPDM_STATUS_UNSUPPORTED_CAP;
  ------------------
  |  |   78|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0002)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
   51|      0|    }
   52|    282|    session_id = spdm_context->last_spdm_request_session_id;
   53|    282|    session_info =
   54|    282|        libspdm_get_session_info_via_session_id(spdm_context, session_id);
   55|    282|    if (session_info == NULL) {
  ------------------
  |  Branch (55:9): [True: 0, False: 282]
  ------------------
   56|      0|        return LIBSPDM_STATUS_UNSUPPORTED_CAP;
  ------------------
  |  |   78|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0002)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
   57|      0|    }
   58|    282|    session_state = libspdm_secured_message_get_session_state(
   59|    282|        session_info->secured_message_context);
   60|    282|    if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) {
  ------------------
  |  Branch (60:9): [True: 0, False: 282]
  ------------------
   61|      0|        return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
  ------------------
  |  |   82|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0003)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
   62|      0|    }
   63|       |
   64|    282|    LIBSPDM_ASSERT(*encap_request_size >= sizeof(spdm_key_update_request_t));
   65|    282|    *encap_request_size = sizeof(spdm_key_update_request_t);
   66|       |
   67|    282|    spdm_request = encap_request;
   68|       |
   69|    282|    spdm_request->header.spdm_version = libspdm_get_connection_version (spdm_context);
   70|    282|    spdm_request->header.request_response_code = SPDM_KEY_UPDATE;
  ------------------
  |  |   82|    282|#define SPDM_KEY_UPDATE 0xE9
  ------------------
   71|       |
   72|    282|    libspdm_reset_message_buffer_via_request_code(spdm_context, session_info,
   73|    282|                                                  spdm_request->header.request_response_code);
   74|       |
   75|    282|    if (spdm_context->encap_context.last_encap_request_header
  ------------------
  |  Branch (75:9): [True: 141, False: 141]
  ------------------
   76|    282|        .request_response_code != SPDM_KEY_UPDATE) {
  ------------------
  |  |   82|    282|#define SPDM_KEY_UPDATE 0xE9
  ------------------
   77|    141|        spdm_request->header.param1 =
   78|    141|            SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY;
  ------------------
  |  | 1108|    141|#define SPDM_KEY_UPDATE_OPERATIONS_TABLE_UPDATE_KEY 1
  ------------------
   79|    141|        spdm_request->header.param2 = 0;
   80|    141|        if(!libspdm_get_random_number(sizeof(spdm_request->header.param2),
  ------------------
  |  Branch (80:12): [True: 0, False: 141]
  ------------------
   81|    141|                                      &spdm_request->header.param2)) {
   82|      0|            return LIBSPDM_STATUS_LOW_ENTROPY;
  ------------------
  |  |  204|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_RNG, 0x0000)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
   83|      0|        }
   84|    141|    } else {
   85|    141|        spdm_request->header.param1 =
   86|    141|            SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY;
  ------------------
  |  | 1110|    141|#define SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY 3
  ------------------
   87|    141|        spdm_request->header.param2 = 1;
   88|    141|        if(!libspdm_get_random_number(sizeof(spdm_request->header.param2),
  ------------------
  |  Branch (88:12): [True: 0, False: 141]
  ------------------
   89|    141|                                      &spdm_request->header.param2)) {
   90|      0|            return LIBSPDM_STATUS_LOW_ENTROPY;
  ------------------
  |  |  204|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_RNG, 0x0000)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
   91|      0|        }
   92|       |
   93|       |        /* Create new key*/
   94|    141|        LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
   95|    141|                       "libspdm_create_update_session_data_key[%x] Responder\n",
   96|    141|                       session_id));
   97|    141|        result = libspdm_create_update_session_data_key(
   98|    141|            session_info->secured_message_context,
   99|    141|            LIBSPDM_KEY_UPDATE_ACTION_RESPONDER);
  100|    141|        if (!result) {
  ------------------
  |  Branch (100:13): [True: 0, False: 141]
  ------------------
  101|      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)))
  |  |  ------------------
  ------------------
  102|      0|        }
  103|    141|        libspdm_trigger_key_update_callback(
  104|    141|            spdm_context, session_id, LIBSPDM_KEY_UPDATE_OPERATION_CREATE_UPDATE,
  105|    141|            LIBSPDM_KEY_UPDATE_ACTION_RESPONDER);
  106|       |
  107|    141|        LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
  108|    141|                       "libspdm_activate_update_session_data_key[%x] Responder new\n",
  109|    141|                       session_id));
  110|    141|        result = libspdm_activate_update_session_data_key(
  111|    141|            session_info->secured_message_context,
  112|    141|            LIBSPDM_KEY_UPDATE_ACTION_RESPONDER, true);
  113|    141|        if (!result) {
  ------------------
  |  Branch (113:13): [True: 0, False: 141]
  ------------------
  114|      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)))
  |  |  ------------------
  ------------------
  115|      0|        }
  116|    141|        libspdm_trigger_key_update_callback(
  117|    141|            spdm_context, session_id, LIBSPDM_KEY_UPDATE_OPERATION_COMMIT_UPDATE,
  118|    141|            LIBSPDM_KEY_UPDATE_ACTION_RESPONDER);
  119|    141|    }
  120|       |
  121|    282|    libspdm_copy_mem(&spdm_context->encap_context.last_encap_request_header,
  122|    282|                     sizeof(spdm_context->encap_context.last_encap_request_header),
  123|    282|                     &spdm_request->header, sizeof(spdm_message_header_t));
  124|    282|    spdm_context->encap_context.last_encap_request_size =
  125|    282|        *encap_request_size;
  126|       |
  127|    282|    return LIBSPDM_STATUS_SUCCESS;
  ------------------
  |  |   59|    282|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_SUCCESS, LIBSPDM_SOURCE_SUCCESS, 0x0000)
  |  |  ------------------
  |  |  |  |   55|    282|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  128|    282|}
libspdm_process_encap_response_key_update:
  145|    141|{
  146|    141|    spdm_key_update_request_t *spdm_request;
  147|    141|    const spdm_key_update_response_t *spdm_response;
  148|    141|    size_t spdm_response_size;
  149|    141|    uint32_t session_id;
  150|    141|    libspdm_session_info_t *session_info;
  151|    141|    libspdm_session_state_t session_state;
  152|       |
  153|    141|    if (!spdm_context->last_spdm_request_session_id_valid) {
  ------------------
  |  Branch (153:9): [True: 0, False: 141]
  ------------------
  154|      0|        return LIBSPDM_STATUS_UNSUPPORTED_CAP;
  ------------------
  |  |   78|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0002)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  155|      0|    }
  156|    141|    session_id = spdm_context->last_spdm_request_session_id;
  157|    141|    session_info =
  158|    141|        libspdm_get_session_info_via_session_id(spdm_context, session_id);
  159|    141|    if (session_info == NULL) {
  ------------------
  |  Branch (159:9): [True: 0, False: 141]
  ------------------
  160|      0|        return LIBSPDM_STATUS_UNSUPPORTED_CAP;
  ------------------
  |  |   78|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0002)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  161|      0|    }
  162|    141|    session_state = libspdm_secured_message_get_session_state(
  163|    141|        session_info->secured_message_context);
  164|    141|    if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) {
  ------------------
  |  Branch (164:9): [True: 0, False: 141]
  ------------------
  165|      0|        return LIBSPDM_STATUS_UNSUPPORTED_CAP;
  ------------------
  |  |   78|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0002)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  166|      0|    }
  167|       |
  168|    141|    spdm_request =
  169|    141|        (void *)&spdm_context->encap_context.last_encap_request_header;
  170|       |
  171|    141|    spdm_response = encap_response;
  172|    141|    spdm_response_size = encap_response_size;
  173|       |
  174|    141|    if (spdm_response->header.spdm_version != libspdm_get_connection_version (spdm_context)) {
  ------------------
  |  Branch (174:9): [True: 26, False: 115]
  ------------------
  175|     26|        return LIBSPDM_STATUS_INVALID_MSG_FIELD;
  ------------------
  |  |   90|     26|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0005)
  |  |  ------------------
  |  |  |  |   55|     26|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  176|     26|    }
  177|       |
  178|    115|    if (spdm_response->header.request_response_code == SPDM_ERROR) {
  ------------------
  |  |   37|    115|#define SPDM_ERROR 0x7F
  ------------------
  |  Branch (178:9): [True: 14, False: 101]
  ------------------
  179|     14|        if (spdm_response->header.param1 == SPDM_ERROR_CODE_DECRYPT_ERROR) {
  ------------------
  |  |  866|     14|#define SPDM_ERROR_CODE_DECRYPT_ERROR 0x06
  ------------------
  |  Branch (179:13): [True: 1, False: 13]
  ------------------
  180|      1|            libspdm_free_session_id(spdm_context, session_id);
  181|      1|            return LIBSPDM_STATUS_SESSION_MSG_ERROR;
  ------------------
  |  |  130|      1|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x000f)
  |  |  ------------------
  |  |  |  |   55|      1|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  182|      1|        }
  183|     14|    }
  184|       |
  185|       |    /* this message can only be in secured session
  186|       |     * thus don't need to consider transport layer padding, just check its exact size */
  187|    114|    if ((spdm_response_size != sizeof(spdm_key_update_response_t)) ||
  ------------------
  |  Branch (187:9): [True: 65, False: 49]
  ------------------
  188|    114|        (spdm_response->header.request_response_code !=
  ------------------
  |  Branch (188:9): [True: 25, False: 24]
  ------------------
  189|     49|         SPDM_KEY_UPDATE_ACK) ||
  ------------------
  |  |   45|     49|#define SPDM_KEY_UPDATE_ACK 0x69
  ------------------
  190|    114|        (spdm_response->header.param1 != spdm_request->header.param1) ||
  ------------------
  |  Branch (190:9): [True: 11, False: 13]
  ------------------
  191|    114|        (spdm_response->header.param2 != spdm_request->header.param2)) {
  ------------------
  |  Branch (191:9): [True: 12, False: 1]
  ------------------
  192|    113|        if (spdm_request->header.param1 !=
  ------------------
  |  Branch (192:13): [True: 113, False: 0]
  ------------------
  193|    113|            SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY) {
  ------------------
  |  | 1110|    113|#define SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY 3
  ------------------
  194|    113|            LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "libspdm_key_update[%x] failed\n",
  195|    113|                           session_id));
  196|    113|        } else {
  197|      0|            LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "SpdmVerifyKey[%x] failed\n",
  198|      0|                           session_id));
  199|      0|        }
  200|    113|        return LIBSPDM_STATUS_INVALID_MSG_FIELD;
  ------------------
  |  |   90|    113|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0005)
  |  |  ------------------
  |  |  |  |   55|    113|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  201|    113|    }
  202|       |
  203|      1|    if (spdm_request->header.param1 !=
  ------------------
  |  Branch (203:9): [True: 1, False: 0]
  ------------------
  204|      1|        SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY) {
  ------------------
  |  | 1110|      1|#define SPDM_KEY_UPDATE_OPERATIONS_TABLE_VERIFY_NEW_KEY 3
  ------------------
  205|      1|        LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "libspdm_key_update[%x] success\n",
  206|      1|                       session_id));
  207|      1|        *need_continue = true;
  208|      1|    } else {
  209|      0|        LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "SpdmVerifyKey[%x] Success\n", session_id));
  210|      0|        *need_continue = false;
  211|      0|    }
  212|       |
  213|      1|    return LIBSPDM_STATUS_SUCCESS;
  ------------------
  |  |   59|      1|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_SUCCESS, LIBSPDM_SOURCE_SUCCESS, 0x0000)
  |  |  ------------------
  |  |  |  |   55|      1|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  214|    114|}

libspdm_init_key_update_encap_state:
  185|    141|{
  186|    141|    libspdm_context_t *context;
  187|       |
  188|    141|    context = spdm_context;
  189|       |
  190|    141|    context->encap_context.current_request_op_code = 0x00;
  191|    141|    context->encap_context.request_id = 0;
  192|    141|    context->encap_context.last_encap_request_size = 0;
  193|    141|    libspdm_zero_mem(&context->encap_context.last_encap_request_header,
  194|    141|                     sizeof(context->encap_context.last_encap_request_header));
  195|    141|    context->response_state = LIBSPDM_RESPONSE_STATE_PROCESSING_ENCAP;
  196|       |
  197|    141|    libspdm_reset_message_mut_b(context);
  198|    141|    libspdm_reset_message_mut_c(context);
  199|       |
  200|    141|    libspdm_zero_mem(context->encap_context.request_op_code_sequence,
  201|    141|                     sizeof(context->encap_context.request_op_code_sequence));
  202|    141|    context->encap_context.request_op_code_count = 1;
  203|    141|    context->encap_context.request_op_code_sequence[0] = SPDM_KEY_UPDATE;
  ------------------
  |  |   82|    141|#define SPDM_KEY_UPDATE 0xE9
  ------------------
  204|    141|}

libspdm_trigger_key_update_callback:
  402|    282|{
  403|    282|    libspdm_context_t *context;
  404|       |
  405|    282|    context = spdm_context;
  406|    282|    if (context->spdm_key_update_callback != NULL) {
  ------------------
  |  Branch (406:9): [True: 0, False: 282]
  ------------------
  407|      0|        ((libspdm_key_update_callback_func)
  408|      0|         context->spdm_key_update_callback)(context, session_id, key_update_op, key_update_action);
  409|      0|    }
  410|    282|}

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

libspdm_bin_concat:
   25|    564|{
   26|    564|    size_t final_size;
   27|       |
   28|       |    /* The correct version characters (1.1 or 1.2) will replace the x.x. */
   29|    564|    #define LIBSPDM_BIN_CONCAT_LABEL "spdmx.x "
   30|       |
   31|    564|    final_size = sizeof(uint16_t) + sizeof(LIBSPDM_BIN_CONCAT_LABEL) - 1 + label_size;
  ------------------
  |  |   29|    564|    #define LIBSPDM_BIN_CONCAT_LABEL "spdmx.x "
  ------------------
   32|    564|    if (context != NULL) {
  ------------------
  |  Branch (32:9): [True: 0, False: 564]
  ------------------
   33|      0|        final_size += hash_size;
   34|      0|    }
   35|       |
   36|    564|    LIBSPDM_ASSERT(*out_bin_size >= final_size);
   37|       |
   38|    564|    *out_bin_size = final_size;
   39|       |
   40|    564|    libspdm_copy_mem(out_bin, *out_bin_size, &length, sizeof(uint16_t));
   41|    564|    libspdm_copy_mem(out_bin + sizeof(uint16_t), *out_bin_size - sizeof(uint16_t),
   42|    564|                     LIBSPDM_BIN_CONCAT_LABEL, sizeof(LIBSPDM_BIN_CONCAT_LABEL) - 1);
  ------------------
  |  |   29|    564|    #define LIBSPDM_BIN_CONCAT_LABEL "spdmx.x "
  ------------------
                                   LIBSPDM_BIN_CONCAT_LABEL, sizeof(LIBSPDM_BIN_CONCAT_LABEL) - 1);
  ------------------
  |  |   29|    564|    #define LIBSPDM_BIN_CONCAT_LABEL "spdmx.x "
  ------------------
   43|       |
   44|       |    /* Patch the version. */
   45|    564|    out_bin[6] = (char)('0' + ((spdm_version >> 12) & 0xF));
   46|    564|    out_bin[8] = (char)('0' + ((spdm_version >> 8) & 0xF));
   47|    564|    libspdm_copy_mem(out_bin + sizeof(uint16_t) + sizeof(LIBSPDM_BIN_CONCAT_LABEL) - 1,
  ------------------
  |  |   29|    564|    #define LIBSPDM_BIN_CONCAT_LABEL "spdmx.x "
  ------------------
   48|    564|                     *out_bin_size - (sizeof(uint16_t) + sizeof(LIBSPDM_BIN_CONCAT_LABEL) - 1),
  ------------------
  |  |   29|    564|    #define LIBSPDM_BIN_CONCAT_LABEL "spdmx.x "
  ------------------
   49|    564|                     label, label_size);
   50|       |
   51|    564|    if (context != NULL) {
  ------------------
  |  Branch (51:9): [True: 0, False: 564]
  ------------------
   52|      0|        libspdm_copy_mem(out_bin + sizeof(uint16_t) + sizeof(LIBSPDM_BIN_CONCAT_LABEL) -
  ------------------
  |  |   29|      0|    #define LIBSPDM_BIN_CONCAT_LABEL "spdmx.x "
  ------------------
   53|      0|                         1 + label_size,
   54|      0|                         *out_bin_size - (sizeof(uint16_t) + sizeof(LIBSPDM_BIN_CONCAT_LABEL) -
  ------------------
  |  |   29|      0|    #define LIBSPDM_BIN_CONCAT_LABEL "spdmx.x "
  ------------------
   55|      0|                                          1 + label_size), context, hash_size);
   56|      0|    }
   57|       |
   58|    564|    #undef LIBSPDM_BIN_CONCAT_LABEL
   59|    564|}
libspdm_generate_aead_key_and_iv:
   74|    141|{
   75|    141|    bool status;
   76|    141|    size_t hash_size;
   77|    141|    size_t key_length;
   78|    141|    size_t iv_length;
   79|    141|    uint8_t bin_str5[128];
   80|    141|    size_t bin_str5_size;
   81|    141|    uint8_t bin_str6[128];
   82|    141|    size_t bin_str6_size;
   83|       |
   84|    141|    hash_size = secured_message_context->hash_size;
   85|    141|    key_length = secured_message_context->aead_key_size;
   86|    141|    iv_length = secured_message_context->aead_iv_size;
   87|       |
   88|    141|    bin_str5_size = sizeof(bin_str5);
   89|    141|    libspdm_bin_concat(secured_message_context->version,
   90|    141|                       SPDM_BIN_STR_5_LABEL, sizeof(SPDM_BIN_STR_5_LABEL) - 1,
  ------------------
  |  | 1504|    141|#define SPDM_BIN_STR_5_LABEL "key"
  ------------------
                                     SPDM_BIN_STR_5_LABEL, sizeof(SPDM_BIN_STR_5_LABEL) - 1,
  ------------------
  |  | 1504|    141|#define SPDM_BIN_STR_5_LABEL "key"
  ------------------
   91|    141|                       NULL, (uint16_t)key_length, hash_size, bin_str5,
   92|    141|                       &bin_str5_size);
   93|       |
   94|    141|    LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "bin_str5 (0x%zx):\n", bin_str5_size));
   95|    141|    LIBSPDM_INTERNAL_DUMP_HEX(bin_str5, bin_str5_size);
   96|    141|    status = libspdm_hkdf_expand(secured_message_context->base_hash_algo,
   97|    141|                                 major_secret, hash_size, bin_str5,
   98|    141|                                 bin_str5_size, key, key_length);
   99|    141|    if (!status) {
  ------------------
  |  Branch (99:9): [True: 0, False: 141]
  ------------------
  100|      0|        return false;
  101|      0|    }
  102|    141|    LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "key (0x%zx) - ", key_length));
  103|    141|    LIBSPDM_INTERNAL_DUMP_DATA(key, key_length);
  104|    141|    LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
  105|       |
  106|    141|    bin_str6_size = sizeof(bin_str6);
  107|    141|    libspdm_bin_concat(secured_message_context->version,
  108|    141|                       SPDM_BIN_STR_6_LABEL, sizeof(SPDM_BIN_STR_6_LABEL) - 1,
  ------------------
  |  | 1505|    141|#define SPDM_BIN_STR_6_LABEL "iv"
  ------------------
                                     SPDM_BIN_STR_6_LABEL, sizeof(SPDM_BIN_STR_6_LABEL) - 1,
  ------------------
  |  | 1505|    141|#define SPDM_BIN_STR_6_LABEL "iv"
  ------------------
  109|    141|                       NULL, (uint16_t)iv_length, hash_size, bin_str6,
  110|    141|                       &bin_str6_size);
  111|       |
  112|    141|    LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "bin_str6 (0x%zx):\n", bin_str6_size));
  113|    141|    LIBSPDM_INTERNAL_DUMP_HEX(bin_str6, bin_str6_size);
  114|    141|    status = libspdm_hkdf_expand(secured_message_context->base_hash_algo,
  115|    141|                                 major_secret, hash_size, bin_str6,
  116|    141|                                 bin_str6_size, iv, iv_length);
  117|    141|    if (!status) {
  ------------------
  |  Branch (117:9): [True: 0, False: 141]
  ------------------
  118|      0|        return false;
  119|      0|    }
  120|    141|    LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "iv (0x%zx) - ", iv_length));
  121|    141|    LIBSPDM_INTERNAL_DUMP_DATA(iv, iv_length);
  122|    141|    LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
  123|       |
  124|    141|    return true;
  125|    141|}
libspdm_create_update_session_data_key:
  577|    141|{
  578|    141|    bool status;
  579|    141|    size_t hash_size;
  580|    141|    uint8_t bin_str9[128];
  581|    141|    size_t bin_str9_size;
  582|    141|    libspdm_secured_message_context_t *secured_message_context;
  583|       |
  584|    141|    secured_message_context = spdm_secured_message_context;
  585|       |
  586|    141|    hash_size = secured_message_context->hash_size;
  587|       |
  588|    141|    bin_str9_size = sizeof(bin_str9);
  589|    141|    libspdm_bin_concat(secured_message_context->version,
  590|    141|                       SPDM_BIN_STR_9_LABEL, sizeof(SPDM_BIN_STR_9_LABEL) - 1,
  ------------------
  |  | 1508|    141|#define SPDM_BIN_STR_9_LABEL "traffic upd"
  ------------------
                                     SPDM_BIN_STR_9_LABEL, sizeof(SPDM_BIN_STR_9_LABEL) - 1,
  ------------------
  |  | 1508|    141|#define SPDM_BIN_STR_9_LABEL "traffic upd"
  ------------------
  591|    141|                       NULL, (uint16_t)hash_size, hash_size, bin_str9,
  592|    141|                       &bin_str9_size);
  593|       |
  594|    141|    LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "bin_str9 (0x%zx):\n", bin_str9_size));
  595|    141|    LIBSPDM_INTERNAL_DUMP_HEX(bin_str9, bin_str9_size);
  596|       |
  597|    141|    if (action == LIBSPDM_KEY_UPDATE_ACTION_REQUESTER) {
  ------------------
  |  Branch (597:9): [True: 0, False: 141]
  ------------------
  598|      0|        libspdm_copy_mem(&secured_message_context->application_secret_backup
  599|      0|                         .request_data_secret,
  600|      0|                         sizeof(secured_message_context->application_secret_backup
  601|      0|                                .request_data_secret),
  602|      0|                         &secured_message_context->application_secret
  603|      0|                         .request_data_secret,
  604|      0|                         LIBSPDM_MAX_HASH_SIZE);
  ------------------
  |  |   65|      0|#define LIBSPDM_MAX_HASH_SIZE 64
  ------------------
  605|      0|        libspdm_copy_mem(&secured_message_context->application_secret_backup
  606|      0|                         .request_data_encryption_key,
  607|      0|                         sizeof(secured_message_context->application_secret_backup
  608|      0|                                .request_data_encryption_key),
  609|      0|                         &secured_message_context->application_secret
  610|      0|                         .request_data_encryption_key,
  611|      0|                         LIBSPDM_MAX_AEAD_KEY_SIZE);
  ------------------
  |  |   73|      0|#define LIBSPDM_MAX_AEAD_KEY_SIZE 32
  ------------------
  612|      0|        libspdm_copy_mem(&secured_message_context->application_secret_backup
  613|      0|                         .request_data_salt,
  614|      0|                         sizeof(secured_message_context->application_secret_backup
  615|      0|                                .request_data_salt),
  616|      0|                         &secured_message_context->application_secret
  617|      0|                         .request_data_salt,
  618|      0|                         LIBSPDM_MAX_AEAD_IV_SIZE);
  ------------------
  |  |   74|      0|#define LIBSPDM_MAX_AEAD_IV_SIZE 12
  ------------------
  619|      0|        secured_message_context->application_secret_backup
  620|      0|        .request_data_sequence_number =
  621|      0|            secured_message_context->application_secret.request_data_sequence_number;
  622|       |
  623|      0|        status = libspdm_hkdf_expand(
  624|      0|            secured_message_context->base_hash_algo,
  625|      0|            secured_message_context->application_secret.request_data_secret,
  626|      0|            hash_size, bin_str9, bin_str9_size,
  627|      0|            secured_message_context->application_secret.request_data_secret,
  628|      0|            hash_size);
  629|      0|        if (!status) {
  ------------------
  |  Branch (629:13): [True: 0, False: 0]
  ------------------
  630|      0|            return false;
  631|      0|        }
  632|      0|        LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "RequestDataSecretUpdate (0x%zx) - ", hash_size));
  633|      0|        LIBSPDM_INTERNAL_DUMP_DATA(secured_message_context->application_secret.request_data_secret,
  634|      0|                                   hash_size);
  635|      0|        LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
  636|       |
  637|      0|        status = libspdm_generate_aead_key_and_iv(
  638|      0|            secured_message_context,
  639|      0|            secured_message_context->application_secret.request_data_secret,
  640|      0|            secured_message_context->application_secret.request_data_encryption_key,
  641|      0|            secured_message_context->application_secret.request_data_salt);
  642|      0|        if (!status) {
  ------------------
  |  Branch (642:13): [True: 0, False: 0]
  ------------------
  643|      0|            return status;
  644|      0|        }
  645|      0|        secured_message_context->application_secret.request_data_sequence_number = 0;
  646|       |
  647|      0|        secured_message_context->requester_backup_valid = true;
  648|    141|    } else if (action == LIBSPDM_KEY_UPDATE_ACTION_RESPONDER) {
  ------------------
  |  Branch (648:16): [True: 141, False: 0]
  ------------------
  649|    141|        libspdm_copy_mem(&secured_message_context->application_secret_backup
  650|    141|                         .response_data_secret,
  651|    141|                         sizeof(secured_message_context->application_secret_backup
  652|    141|                                .response_data_secret),
  653|    141|                         &secured_message_context->application_secret
  654|    141|                         .response_data_secret,
  655|    141|                         LIBSPDM_MAX_HASH_SIZE);
  ------------------
  |  |   65|    141|#define LIBSPDM_MAX_HASH_SIZE 64
  ------------------
  656|    141|        libspdm_copy_mem(&secured_message_context->application_secret_backup
  657|    141|                         .response_data_encryption_key,
  658|    141|                         sizeof(secured_message_context->application_secret_backup
  659|    141|                                .response_data_encryption_key),
  660|    141|                         &secured_message_context->application_secret
  661|    141|                         .response_data_encryption_key,
  662|    141|                         LIBSPDM_MAX_AEAD_KEY_SIZE);
  ------------------
  |  |   73|    141|#define LIBSPDM_MAX_AEAD_KEY_SIZE 32
  ------------------
  663|    141|        libspdm_copy_mem(&secured_message_context->application_secret_backup
  664|    141|                         .response_data_salt,
  665|    141|                         sizeof(secured_message_context->application_secret_backup
  666|    141|                                .response_data_salt),
  667|    141|                         &secured_message_context->application_secret
  668|    141|                         .response_data_salt,
  669|    141|                         LIBSPDM_MAX_AEAD_IV_SIZE);
  ------------------
  |  |   74|    141|#define LIBSPDM_MAX_AEAD_IV_SIZE 12
  ------------------
  670|    141|        secured_message_context->application_secret_backup
  671|    141|        .response_data_sequence_number =
  672|    141|            secured_message_context->application_secret.response_data_sequence_number;
  673|       |
  674|    141|        status = libspdm_hkdf_expand(
  675|    141|            secured_message_context->base_hash_algo,
  676|    141|            secured_message_context->application_secret.response_data_secret,
  677|    141|            hash_size, bin_str9, bin_str9_size,
  678|    141|            secured_message_context->application_secret.response_data_secret,
  679|    141|            hash_size);
  680|    141|        if (!status) {
  ------------------
  |  Branch (680:13): [True: 0, False: 141]
  ------------------
  681|      0|            return false;
  682|      0|        }
  683|    141|        LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "ResponseDataSecretUpdate (0x%zx) - ",
  684|    141|                       hash_size));
  685|    141|        LIBSPDM_INTERNAL_DUMP_DATA(secured_message_context->application_secret.response_data_secret,
  686|    141|                                   hash_size);
  687|    141|        LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
  688|       |
  689|    141|        status = libspdm_generate_aead_key_and_iv(
  690|    141|            secured_message_context,
  691|    141|            secured_message_context->application_secret.response_data_secret,
  692|    141|            secured_message_context->application_secret.response_data_encryption_key,
  693|    141|            secured_message_context->application_secret.response_data_salt);
  694|    141|        if (!status) {
  ------------------
  |  Branch (694:13): [True: 0, False: 141]
  ------------------
  695|      0|            return status;
  696|      0|        }
  697|    141|        secured_message_context->application_secret.response_data_sequence_number = 0;
  698|       |
  699|    141|        secured_message_context->responder_backup_valid = true;
  700|    141|    } else {
  701|      0|        return false;
  702|      0|    }
  703|       |
  704|    141|    return true;
  705|    141|}
libspdm_clear_handshake_secret:
  708|    423|{
  709|    423|    libspdm_secured_message_context_t *secured_message_context;
  710|       |
  711|    423|    secured_message_context = spdm_secured_message_context;
  712|       |
  713|    423|    libspdm_zero_mem(secured_message_context->master_secret.handshake_secret,
  714|    423|                     LIBSPDM_MAX_HASH_SIZE);
  ------------------
  |  |   65|    423|#define LIBSPDM_MAX_HASH_SIZE 64
  ------------------
  715|    423|    libspdm_zero_mem(&(secured_message_context->handshake_secret),
  716|    423|                     sizeof(libspdm_session_info_struct_handshake_secret_t));
  717|       |
  718|    423|    secured_message_context->requester_backup_valid = false;
  719|    423|    secured_message_context->responder_backup_valid = false;
  720|    423|}
libspdm_clear_master_secret:
  723|    423|{
  724|    423|    libspdm_secured_message_context_t *secured_message_context;
  725|       |
  726|    423|    secured_message_context = spdm_secured_message_context;
  727|       |
  728|    423|    libspdm_zero_mem(secured_message_context->master_secret.master_secret, LIBSPDM_MAX_HASH_SIZE);
  ------------------
  |  |   65|    423|#define LIBSPDM_MAX_HASH_SIZE 64
  ------------------
  729|    423|}
libspdm_activate_update_session_data_key:
  743|    141|{
  744|    141|    libspdm_secured_message_context_t *secured_message_context;
  745|       |
  746|    141|    secured_message_context = spdm_secured_message_context;
  747|       |
  748|    141|    if (!use_new_key) {
  ------------------
  |  Branch (748:9): [True: 0, False: 141]
  ------------------
  749|      0|        if ((action == LIBSPDM_KEY_UPDATE_ACTION_REQUESTER) &&
  ------------------
  |  Branch (749:13): [True: 0, False: 0]
  ------------------
  750|      0|            secured_message_context->requester_backup_valid) {
  ------------------
  |  Branch (750:13): [True: 0, False: 0]
  ------------------
  751|      0|            libspdm_copy_mem(&secured_message_context->application_secret
  752|      0|                             .request_data_secret,
  753|      0|                             sizeof(secured_message_context->application_secret
  754|      0|                                    .request_data_secret),
  755|      0|                             &secured_message_context
  756|      0|                             ->application_secret_backup
  757|      0|                             .request_data_secret,
  758|      0|                             LIBSPDM_MAX_HASH_SIZE);
  ------------------
  |  |   65|      0|#define LIBSPDM_MAX_HASH_SIZE 64
  ------------------
  759|      0|            libspdm_copy_mem(&secured_message_context->application_secret
  760|      0|                             .request_data_encryption_key,
  761|      0|                             sizeof(secured_message_context->application_secret
  762|      0|                                    .request_data_encryption_key),
  763|      0|                             &secured_message_context
  764|      0|                             ->application_secret_backup
  765|      0|                             .request_data_encryption_key,
  766|      0|                             LIBSPDM_MAX_AEAD_KEY_SIZE);
  ------------------
  |  |   73|      0|#define LIBSPDM_MAX_AEAD_KEY_SIZE 32
  ------------------
  767|      0|            libspdm_copy_mem(&secured_message_context->application_secret
  768|      0|                             .request_data_salt,
  769|      0|                             sizeof(secured_message_context->application_secret
  770|      0|                                    .request_data_salt),
  771|      0|                             &secured_message_context
  772|      0|                             ->application_secret_backup
  773|      0|                             .request_data_salt,
  774|      0|                             LIBSPDM_MAX_AEAD_IV_SIZE);
  ------------------
  |  |   74|      0|#define LIBSPDM_MAX_AEAD_IV_SIZE 12
  ------------------
  775|      0|            secured_message_context->application_secret
  776|      0|            .request_data_sequence_number =
  777|      0|                secured_message_context->application_secret_backup.request_data_sequence_number;
  778|      0|        } else if ((action == LIBSPDM_KEY_UPDATE_ACTION_RESPONDER) &&
  ------------------
  |  Branch (778:20): [True: 0, False: 0]
  ------------------
  779|      0|                   secured_message_context->responder_backup_valid) {
  ------------------
  |  Branch (779:20): [True: 0, False: 0]
  ------------------
  780|      0|            libspdm_copy_mem(&secured_message_context->application_secret
  781|      0|                             .response_data_secret,
  782|      0|                             sizeof(secured_message_context->application_secret
  783|      0|                                    .response_data_secret),
  784|      0|                             &secured_message_context
  785|      0|                             ->application_secret_backup
  786|      0|                             .response_data_secret,
  787|      0|                             LIBSPDM_MAX_HASH_SIZE);
  ------------------
  |  |   65|      0|#define LIBSPDM_MAX_HASH_SIZE 64
  ------------------
  788|      0|            libspdm_copy_mem(&secured_message_context->application_secret
  789|      0|                             .response_data_encryption_key,
  790|      0|                             sizeof(secured_message_context->application_secret
  791|      0|                                    .response_data_encryption_key),
  792|      0|                             &secured_message_context
  793|      0|                             ->application_secret_backup
  794|      0|                             .response_data_encryption_key,
  795|      0|                             LIBSPDM_MAX_AEAD_KEY_SIZE);
  ------------------
  |  |   73|      0|#define LIBSPDM_MAX_AEAD_KEY_SIZE 32
  ------------------
  796|      0|            libspdm_copy_mem(&secured_message_context->application_secret
  797|      0|                             .response_data_salt,
  798|      0|                             sizeof(secured_message_context->application_secret
  799|      0|                                    .response_data_salt),
  800|      0|                             &secured_message_context
  801|      0|                             ->application_secret_backup
  802|      0|                             .response_data_salt,
  803|      0|                             LIBSPDM_MAX_AEAD_IV_SIZE);
  ------------------
  |  |   74|      0|#define LIBSPDM_MAX_AEAD_IV_SIZE 12
  ------------------
  804|      0|            secured_message_context->application_secret.response_data_sequence_number =
  805|      0|                secured_message_context->application_secret_backup.response_data_sequence_number;
  806|      0|        }
  807|      0|    }
  808|       |
  809|    141|    if (action == LIBSPDM_KEY_UPDATE_ACTION_REQUESTER) {
  ------------------
  |  Branch (809:9): [True: 0, False: 141]
  ------------------
  810|      0|        libspdm_zero_mem(&secured_message_context->application_secret_backup.request_data_secret,
  811|      0|                         LIBSPDM_MAX_HASH_SIZE);
  ------------------
  |  |   65|      0|#define LIBSPDM_MAX_HASH_SIZE 64
  ------------------
  812|      0|        libspdm_zero_mem(&secured_message_context->application_secret_backup
  813|      0|                         .request_data_encryption_key,
  814|      0|                         LIBSPDM_MAX_AEAD_KEY_SIZE);
  ------------------
  |  |   73|      0|#define LIBSPDM_MAX_AEAD_KEY_SIZE 32
  ------------------
  815|      0|        libspdm_zero_mem(&secured_message_context->application_secret_backup.request_data_salt,
  816|      0|                         LIBSPDM_MAX_AEAD_IV_SIZE);
  ------------------
  |  |   74|      0|#define LIBSPDM_MAX_AEAD_IV_SIZE 12
  ------------------
  817|      0|        secured_message_context->application_secret_backup.request_data_sequence_number = 0;
  818|      0|        secured_message_context->requester_backup_valid = false;
  819|    141|    } else if (action == LIBSPDM_KEY_UPDATE_ACTION_RESPONDER) {
  ------------------
  |  Branch (819:16): [True: 141, False: 0]
  ------------------
  820|    141|        libspdm_zero_mem(&secured_message_context->application_secret_backup.response_data_secret,
  821|    141|                         LIBSPDM_MAX_HASH_SIZE);
  ------------------
  |  |   65|    141|#define LIBSPDM_MAX_HASH_SIZE 64
  ------------------
  822|    141|        libspdm_zero_mem(&secured_message_context->application_secret_backup
  823|    141|                         .response_data_encryption_key,
  824|    141|                         LIBSPDM_MAX_AEAD_KEY_SIZE);
  ------------------
  |  |   73|    141|#define LIBSPDM_MAX_AEAD_KEY_SIZE 32
  ------------------
  825|    141|        libspdm_zero_mem(&secured_message_context->application_secret_backup.response_data_salt,
  826|    141|                         LIBSPDM_MAX_AEAD_IV_SIZE);
  ------------------
  |  |   74|    141|#define LIBSPDM_MAX_AEAD_IV_SIZE 12
  ------------------
  827|    141|        secured_message_context->application_secret_backup.response_data_sequence_number = 0;
  828|    141|        secured_message_context->responder_backup_valid = false;
  829|    141|    }
  830|       |
  831|    141|    return true;
  832|    141|}

libspdm_sha256_hash_all:
  197|    282|{
  198|    282|    int ret;
  199|       |
  200|    282|    if (hash_value == NULL) {
  ------------------
  |  Branch (200:9): [True: 0, False: 282]
  ------------------
  201|      0|        return false;
  202|      0|    }
  203|    282|    if (data == NULL && data_size != 0) {
  ------------------
  |  Branch (203:9): [True: 0, False: 282]
  |  Branch (203:25): [True: 0, False: 0]
  ------------------
  204|      0|        return false;
  205|      0|    }
  206|    282|    if (data_size > INT_MAX) {
  ------------------
  |  Branch (206:9): [True: 0, False: 282]
  ------------------
  207|      0|        return false;
  208|      0|    }
  209|       |
  210|    282|    ret = mbedtls_sha256(data, data_size, hash_value, false);
  211|    282|    if (ret != 0) {
  ------------------
  |  Branch (211:9): [True: 0, False: 282]
  ------------------
  212|      0|        return false;
  213|      0|    }
  214|    282|    return true;
  215|    282|}

hkdf_md_expand:
  138|    564|{
  139|    564|    const mbedtls_md_info_t *md;
  140|    564|    int ret;
  141|    564|    size_t md_size;
  142|       |
  143|    564|    if (prk == NULL || info == NULL || out == NULL || prk_size > INT_MAX ||
  ------------------
  |  Branch (143:9): [True: 0, False: 564]
  |  Branch (143:24): [True: 0, False: 564]
  |  Branch (143:40): [True: 0, False: 564]
  |  Branch (143:55): [True: 0, False: 564]
  ------------------
  144|    564|        info_size > INT_MAX || out_size > INT_MAX) {
  ------------------
  |  Branch (144:9): [True: 0, False: 564]
  |  Branch (144:32): [True: 0, False: 564]
  ------------------
  145|      0|        return false;
  146|      0|    }
  147|       |
  148|    564|    switch (md_type) {
  149|    564|    case MBEDTLS_MD_SHA256:
  ------------------
  |  Branch (149:5): [True: 564, False: 0]
  ------------------
  150|    564|        md_size = LIBSPDM_SHA256_DIGEST_SIZE;
  ------------------
  |  |   11|    564|#define LIBSPDM_SHA256_DIGEST_SIZE 32
  ------------------
  151|    564|        break;
  152|      0|    case MBEDTLS_MD_SHA384:
  ------------------
  |  Branch (152:5): [True: 0, False: 564]
  ------------------
  153|      0|        md_size = LIBSPDM_SHA384_DIGEST_SIZE;
  ------------------
  |  |   14|      0|#define LIBSPDM_SHA384_DIGEST_SIZE 48
  ------------------
  154|      0|        break;
  155|      0|    case MBEDTLS_MD_SHA512:
  ------------------
  |  Branch (155:5): [True: 0, False: 564]
  ------------------
  156|      0|        md_size = LIBSPDM_SHA512_DIGEST_SIZE;
  ------------------
  |  |   17|      0|#define LIBSPDM_SHA512_DIGEST_SIZE 64
  ------------------
  157|      0|        break;
  158|      0|    default:
  ------------------
  |  Branch (158:5): [True: 0, False: 564]
  ------------------
  159|      0|        LIBSPDM_ASSERT(false);
  160|      0|        return false;
  161|    564|    }
  162|    564|    if (prk_size != md_size) {
  ------------------
  |  Branch (162:9): [True: 0, False: 564]
  ------------------
  163|      0|        return false;
  164|      0|    }
  165|       |
  166|    564|    md = mbedtls_md_info_from_type(md_type);
  167|    564|    LIBSPDM_ASSERT(md != NULL);
  168|       |
  169|    564|    ret = mbedtls_hkdf_expand(md, prk, (uint32_t)prk_size, info,
  170|    564|                              (uint32_t)info_size, out, (uint32_t)out_size);
  171|    564|    if (ret != 0) {
  ------------------
  |  Branch (171:9): [True: 0, False: 564]
  ------------------
  172|      0|        return false;
  173|      0|    }
  174|       |
  175|    564|    return true;
  176|    564|}
libspdm_hkdf_sha256_expand:
  243|    564|{
  244|    564|    return hkdf_md_expand(MBEDTLS_MD_SHA256, prk, prk_size, info, info_size,
  245|    564|                          out, out_size);
  246|    564|}

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

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

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

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

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

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

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

md.c:mbedtls_get_unaligned_uint64:
  220|  4.51k|{
  221|  4.51k|    uint64_t r;
  222|       |#if defined(UINT_UNALIGNED)
  223|       |    mbedtls_uint64_unaligned_t *p64 = (mbedtls_uint64_unaligned_t *) p;
  224|       |    r = *p64;
  225|       |#elif defined(UINT_UNALIGNED_STRUCT)
  226|       |    mbedtls_uint64_unaligned_t *p64 = (mbedtls_uint64_unaligned_t *) p;
  227|       |    r = p64->x;
  228|       |#else
  229|  4.51k|    memcpy(&r, p, sizeof(r));
  230|  4.51k|#endif
  231|  4.51k|    return r;
  232|  4.51k|}
md.c:mbedtls_put_unaligned_uint64:
  247|  2.25k|{
  248|       |#if defined(UINT_UNALIGNED)
  249|       |    mbedtls_uint64_unaligned_t *p64 = (mbedtls_uint64_unaligned_t *) p;
  250|       |    *p64 = x;
  251|       |#elif defined(UINT_UNALIGNED_STRUCT)
  252|       |    mbedtls_uint64_unaligned_t *p64 = (mbedtls_uint64_unaligned_t *) p;
  253|       |    p64->x = x;
  254|       |#else
  255|  2.25k|    memcpy(p, &x, sizeof(x));
  256|  2.25k|#endif
  257|  2.25k|}
sha256.c:mbedtls_get_unaligned_uint32:
  168|   108k|{
  169|   108k|    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|   108k|    memcpy(&r, p, sizeof(r));
  178|   108k|#endif
  179|   108k|    return r;
  180|   108k|}
sha256.c:mbedtls_put_unaligned_uint32:
  195|  14.1k|{
  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|  14.1k|    memcpy(p, &x, sizeof(x));
  204|  14.1k|#endif
  205|  14.1k|}

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

mbedtls_mpi_safe_cond_assign:
  121|  1.61M|{
  122|  1.61M|    int ret = 0;
  123|       |
  124|  1.61M|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, Y->n));
  ------------------
  |  |   41|  1.61M|    do                           \
  |  |   42|  1.61M|    {                            \
  |  |   43|  1.61M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.61M]
  |  |  ------------------
  |  |   44|  1.61M|        goto cleanup;        \
  |  |   45|  1.61M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  125|       |
  126|  1.61M|    {
  127|  1.61M|        mbedtls_ct_condition_t do_assign = mbedtls_ct_bool(assign);
  128|       |
  129|  1.61M|        X->s = mbedtls_ct_mpi_sign_if(do_assign, Y->s, X->s);
  130|       |
  131|  1.61M|        mbedtls_mpi_core_cond_assign(X->p, Y->p, Y->n, do_assign);
  132|       |
  133|  1.61M|        mbedtls_ct_condition_t do_not_assign = mbedtls_ct_bool_not(do_assign);
  134|  1.61M|        for (size_t i = Y->n; i < X->n; i++) {
  ------------------
  |  Branch (134:31): [True: 5.64k, False: 1.61M]
  ------------------
  135|  5.64k|            X->p[i] = mbedtls_ct_mpi_uint_if_else_0(do_not_assign, X->p[i]);
  136|  5.64k|        }
  137|  1.61M|    }
  138|       |
  139|  1.61M|cleanup:
  140|  1.61M|    return ret;
  141|  1.61M|}
mbedtls_mpi_init:
  182|  4.71M|{
  183|  4.71M|    X->s = 1;
  184|  4.71M|    X->n = 0;
  185|  4.71M|    X->p = NULL;
  186|  4.71M|}
mbedtls_mpi_free:
  192|  4.67M|{
  193|  4.67M|    if (X == NULL) {
  ------------------
  |  Branch (193:9): [True: 0, False: 4.67M]
  ------------------
  194|      0|        return;
  195|      0|    }
  196|       |
  197|  4.67M|    if (X->p != NULL) {
  ------------------
  |  Branch (197:9): [True: 809k, False: 3.86M]
  ------------------
  198|   809k|        mbedtls_mpi_zeroize_and_free(X->p, X->n);
  ------------------
  |  |  176|   809k|#define mbedtls_mpi_zeroize_and_free(v, n) mbedtls_zeroize_and_free(v, ciL * (n))
  |  |  ------------------
  |  |  |  |   79|   809k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  199|   809k|    }
  200|       |
  201|  4.67M|    X->s = 1;
  202|  4.67M|    X->n = 0;
  203|  4.67M|    X->p = NULL;
  204|  4.67M|}
mbedtls_mpi_grow:
  210|  17.7M|{
  211|  17.7M|    mbedtls_mpi_uint *p;
  212|       |
  213|  17.7M|    if (nblimbs > MBEDTLS_MPI_MAX_LIMBS) {
  ------------------
  |  |   50|  17.7M|#define MBEDTLS_MPI_MAX_LIMBS                             10000
  ------------------
  |  Branch (213:9): [True: 0, False: 17.7M]
  ------------------
  214|      0|        return MBEDTLS_ERR_MPI_ALLOC_FAILED;
  ------------------
  |  |   38|      0|#define MBEDTLS_ERR_MPI_ALLOC_FAILED                      -0x0010
  ------------------
  215|      0|    }
  216|       |
  217|  17.7M|    if (X->n < nblimbs) {
  ------------------
  |  Branch (217:9): [True: 900k, False: 16.8M]
  ------------------
  218|   900k|        if ((p = (mbedtls_mpi_uint *) mbedtls_calloc(nblimbs, ciL)) == NULL) {
  ------------------
  |  |  144|   900k|#define mbedtls_calloc     MBEDTLS_PLATFORM_CALLOC_MACRO
  |  |  ------------------
  |  |  |  | 4093|   900k|#define MBEDTLS_PLATFORM_CALLOC_MACRO        my_calloc
  |  |  ------------------
  ------------------
                      if ((p = (mbedtls_mpi_uint *) mbedtls_calloc(nblimbs, ciL)) == NULL) {
  ------------------
  |  |   79|   900k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  |  Branch (218:13): [True: 0, False: 900k]
  ------------------
  219|      0|            return MBEDTLS_ERR_MPI_ALLOC_FAILED;
  ------------------
  |  |   38|      0|#define MBEDTLS_ERR_MPI_ALLOC_FAILED                      -0x0010
  ------------------
  220|      0|        }
  221|       |
  222|   900k|        if (X->p != NULL) {
  ------------------
  |  Branch (222:13): [True: 90.8k, False: 809k]
  ------------------
  223|  90.8k|            memcpy(p, X->p, X->n * ciL);
  ------------------
  |  |   79|  90.8k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  224|  90.8k|            mbedtls_mpi_zeroize_and_free(X->p, X->n);
  ------------------
  |  |  176|  90.8k|#define mbedtls_mpi_zeroize_and_free(v, n) mbedtls_zeroize_and_free(v, ciL * (n))
  |  |  ------------------
  |  |  |  |   79|  90.8k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  225|  90.8k|        }
  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|   900k|        X->n = (unsigned short) nblimbs;
  230|   900k|        X->p = p;
  231|   900k|    }
  232|       |
  233|  17.7M|    return 0;
  234|  17.7M|}
mbedtls_mpi_shrink:
  241|  11.2k|{
  242|  11.2k|    mbedtls_mpi_uint *p;
  243|  11.2k|    size_t i;
  244|       |
  245|  11.2k|    if (nblimbs > MBEDTLS_MPI_MAX_LIMBS) {
  ------------------
  |  |   50|  11.2k|#define MBEDTLS_MPI_MAX_LIMBS                             10000
  ------------------
  |  Branch (245:9): [True: 0, False: 11.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|  11.2k|    if (X->n <= nblimbs) {
  ------------------
  |  Branch (250:9): [True: 0, False: 11.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|  67.6k|    for (i = X->n - 1; i > 0; i--) {
  ------------------
  |  Branch (255:24): [True: 67.6k, False: 0]
  ------------------
  256|  67.6k|        if (X->p[i] != 0) {
  ------------------
  |  Branch (256:13): [True: 11.2k, False: 56.4k]
  ------------------
  257|  11.2k|            break;
  258|  11.2k|        }
  259|  67.6k|    }
  260|  11.2k|    i++;
  261|       |
  262|  11.2k|    if (i < nblimbs) {
  ------------------
  |  Branch (262:9): [True: 0, False: 11.2k]
  ------------------
  263|      0|        i = nblimbs;
  264|      0|    }
  265|       |
  266|  11.2k|    if ((p = (mbedtls_mpi_uint *) mbedtls_calloc(i, ciL)) == NULL) {
  ------------------
  |  |  144|  11.2k|#define mbedtls_calloc     MBEDTLS_PLATFORM_CALLOC_MACRO
  |  |  ------------------
  |  |  |  | 4093|  11.2k|#define MBEDTLS_PLATFORM_CALLOC_MACRO        my_calloc
  |  |  ------------------
  ------------------
                  if ((p = (mbedtls_mpi_uint *) mbedtls_calloc(i, ciL)) == NULL) {
  ------------------
  |  |   79|  11.2k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  |  Branch (266:9): [True: 0, False: 11.2k]
  ------------------
  267|      0|        return MBEDTLS_ERR_MPI_ALLOC_FAILED;
  ------------------
  |  |   38|      0|#define MBEDTLS_ERR_MPI_ALLOC_FAILED                      -0x0010
  ------------------
  268|      0|    }
  269|       |
  270|  11.2k|    if (X->p != NULL) {
  ------------------
  |  Branch (270:9): [True: 11.2k, False: 0]
  ------------------
  271|  11.2k|        memcpy(p, X->p, i * ciL);
  ------------------
  |  |   79|  11.2k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  272|  11.2k|        mbedtls_mpi_zeroize_and_free(X->p, X->n);
  ------------------
  |  |  176|  11.2k|#define mbedtls_mpi_zeroize_and_free(v, n) mbedtls_zeroize_and_free(v, ciL * (n))
  |  |  ------------------
  |  |  |  |   79|  11.2k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  273|  11.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|  11.2k|    X->n = (unsigned short) i;
  278|  11.2k|    X->p = p;
  279|       |
  280|  11.2k|    return 0;
  281|  11.2k|}
mbedtls_mpi_copy:
  308|  1.62M|{
  309|  1.62M|    int ret = 0;
  310|  1.62M|    size_t i;
  311|       |
  312|  1.62M|    if (X == Y) {
  ------------------
  |  Branch (312:9): [True: 7.33k, False: 1.61M]
  ------------------
  313|  7.33k|        return 0;
  314|  7.33k|    }
  315|       |
  316|  1.61M|    if (Y->n == 0) {
  ------------------
  |  Branch (316:9): [True: 282, False: 1.61M]
  ------------------
  317|    282|        if (X->n != 0) {
  ------------------
  |  Branch (317:13): [True: 0, False: 282]
  ------------------
  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|    282|        return 0;
  322|    282|    }
  323|       |
  324|  8.96M|    for (i = Y->n - 1; i > 0; i--) {
  ------------------
  |  Branch (324:24): [True: 8.96M, False: 9.30k]
  ------------------
  325|  8.96M|        if (Y->p[i] != 0) {
  ------------------
  |  Branch (325:13): [True: 1.60M, False: 7.35M]
  ------------------
  326|  1.60M|            break;
  327|  1.60M|        }
  328|  8.96M|    }
  329|  1.61M|    i++;
  330|       |
  331|  1.61M|    X->s = Y->s;
  332|       |
  333|  1.61M|    if (X->n < i) {
  ------------------
  |  Branch (333:9): [True: 672k, False: 943k]
  ------------------
  334|   672k|        MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, i));
  ------------------
  |  |   41|   672k|    do                           \
  |  |   42|   672k|    {                            \
  |  |   43|   672k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 672k]
  |  |  ------------------
  |  |   44|   672k|        goto cleanup;        \
  |  |   45|   672k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  335|   943k|    } else {
  336|   943k|        memset(X->p + i, 0, (X->n - i) * ciL);
  ------------------
  |  |   79|   943k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  337|   943k|    }
  338|       |
  339|  1.61M|    memcpy(X->p, Y->p, i * ciL);
  ------------------
  |  |   79|  1.61M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  340|       |
  341|  1.61M|cleanup:
  342|       |
  343|  1.61M|    return ret;
  344|  1.61M|}
mbedtls_mpi_lset:
  378|  2.31M|{
  379|  2.31M|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  2.31M|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  380|       |
  381|  2.31M|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, 1));
  ------------------
  |  |   41|  2.31M|    do                           \
  |  |   42|  2.31M|    {                            \
  |  |   43|  2.31M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.31M]
  |  |  ------------------
  |  |   44|  2.31M|        goto cleanup;        \
  |  |   45|  2.31M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  382|  2.31M|    memset(X->p, 0, X->n * ciL);
  ------------------
  |  |   79|  2.31M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  383|       |
  384|  2.31M|    X->p[0] = mpi_sint_abs(z);
  385|  2.31M|    X->s    = TO_SIGN(z);
  ------------------
  |  |  372|  2.31M|#define TO_SIGN(x) ((mbedtls_mpi_sint) (((mbedtls_mpi_uint) x) >> (biL - 1)) * -2 + 1)
  |  |  ------------------
  |  |  |  |   80|  2.31M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  |  |  ------------------
  |  |  |  |  |  |   79|  2.31M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  386|       |
  387|  2.31M|cleanup:
  388|       |
  389|  2.31M|    return ret;
  390|  2.31M|}
mbedtls_mpi_get_bit:
  396|   296k|{
  397|   296k|    if (X->n * biL <= pos) {
  ------------------
  |  |   80|   296k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|   296k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  |  Branch (397:9): [True: 2.25k, False: 294k]
  ------------------
  398|  2.25k|        return 0;
  399|  2.25k|    }
  400|       |
  401|   294k|    return (X->p[pos / biL] >> (pos % biL)) & 0x01;
  ------------------
  |  |   80|   294k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|   294k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
                  return (X->p[pos / biL] >> (pos % biL)) & 0x01;
  ------------------
  |  |   80|   294k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|   294k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  402|   296k|}
mbedtls_mpi_lsb:
  437|  1.23M|{
  438|  1.23M|    size_t i;
  439|       |
  440|  1.23M|#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|  1.23M|#endif
  449|       |
  450|  1.23M|#if defined(mbedtls_mpi_uint_ctz)
  451|  1.23M|    for (i = 0; i < X->n; i++) {
  ------------------
  |  Branch (451:17): [True: 1.23M, False: 0]
  ------------------
  452|  1.23M|        if (X->p[i] != 0) {
  ------------------
  |  Branch (452:13): [True: 1.23M, False: 0]
  ------------------
  453|  1.23M|            return i * biL + mbedtls_mpi_uint_ctz(X->p[i]);
  ------------------
  |  |   80|  1.23M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  1.23M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
                          return i * biL + mbedtls_mpi_uint_ctz(X->p[i]);
  ------------------
  |  |  444|  1.23M|    #define mbedtls_mpi_uint_ctz __builtin_ctzl
  ------------------
  454|  1.23M|        }
  455|  1.23M|    }
  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|  1.23M|}
mbedtls_mpi_bitlen:
  474|  3.01M|{
  475|  3.01M|    return mbedtls_mpi_core_bitlen(X->p, X->n);
  476|  3.01M|}
mbedtls_mpi_size:
  482|  4.51k|{
  483|  4.51k|    return (mbedtls_mpi_bitlen(X) + 7) >> 3;
  484|  4.51k|}
mbedtls_mpi_read_binary:
  821|  10.7k|{
  822|  10.7k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  10.7k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  823|  10.7k|    const size_t limbs = CHARS_TO_LIMBS(buflen);
  ------------------
  |  |   88|  10.7k|#define CHARS_TO_LIMBS(i) ((i) / ciL + ((i) % ciL != 0))
  |  |  ------------------
  |  |  |  |   79|  10.7k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  |  |               #define CHARS_TO_LIMBS(i) ((i) / ciL + ((i) % ciL != 0))
  |  |  ------------------
  |  |  |  |   79|  10.7k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  824|       |
  825|       |    /* Ensure that target MPI has exactly the necessary number of limbs */
  826|  10.7k|    MBEDTLS_MPI_CHK(mbedtls_mpi_resize_clear(X, limbs));
  ------------------
  |  |   41|  10.7k|    do                           \
  |  |   42|  10.7k|    {                            \
  |  |   43|  10.7k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 10.7k]
  |  |  ------------------
  |  |   44|  10.7k|        goto cleanup;        \
  |  |   45|  10.7k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  827|       |
  828|  10.7k|    MBEDTLS_MPI_CHK(mbedtls_mpi_core_read_be(X->p, X->n, buf, buflen));
  ------------------
  |  |   41|  10.7k|    do                           \
  |  |   42|  10.7k|    {                            \
  |  |   43|  10.7k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 10.7k]
  |  |  ------------------
  |  |   44|  10.7k|        goto cleanup;        \
  |  |   45|  10.7k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  829|       |
  830|  10.7k|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|  10.7k|    return ret;
  838|  10.7k|}
mbedtls_mpi_shift_l:
  862|   776k|{
  863|   776k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|   776k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  864|   776k|    size_t i;
  865|       |
  866|   776k|    i = mbedtls_mpi_bitlen(X) + count;
  867|       |
  868|   776k|    if (X->n * biL < i) {
  ------------------
  |  |   80|   776k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|   776k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  |  Branch (868:9): [True: 3.38k, False: 772k]
  ------------------
  869|  3.38k|        MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, BITS_TO_LIMBS(i)));
  ------------------
  |  |   41|  3.38k|    do                           \
  |  |   42|  3.38k|    {                            \
  |  |   43|  3.38k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3.38k]
  |  |  ------------------
  |  |   44|  3.38k|        goto cleanup;        \
  |  |   45|  3.38k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  870|  3.38k|    }
  871|       |
  872|   776k|    ret = 0;
  873|       |
  874|   776k|    mbedtls_mpi_core_shift_l(X->p, X->n, count);
  875|   776k|cleanup:
  876|       |
  877|   776k|    return ret;
  878|   776k|}
mbedtls_mpi_shift_r:
  884|  5.48M|{
  885|  5.48M|    if (X->n != 0) {
  ------------------
  |  Branch (885:9): [True: 5.48M, False: 0]
  ------------------
  886|  5.48M|        mbedtls_mpi_core_shift_r(X->p, X->n, count);
  887|  5.48M|    }
  888|  5.48M|    return 0;
  889|  5.48M|}
mbedtls_mpi_cmp_abs:
  895|  5.49M|{
  896|  5.49M|    size_t i, j;
  897|       |
  898|  24.9M|    for (i = X->n; i > 0; i--) {
  ------------------
  |  Branch (898:20): [True: 24.8M, False: 5.35k]
  ------------------
  899|  24.8M|        if (X->p[i - 1] != 0) {
  ------------------
  |  Branch (899:13): [True: 5.49M, False: 19.4M]
  ------------------
  900|  5.49M|            break;
  901|  5.49M|        }
  902|  24.8M|    }
  903|       |
  904|  13.4M|    for (j = Y->n; j > 0; j--) {
  ------------------
  |  Branch (904:20): [True: 13.4M, False: 1.41k]
  ------------------
  905|  13.4M|        if (Y->p[j - 1] != 0) {
  ------------------
  |  Branch (905:13): [True: 5.49M, False: 7.95M]
  ------------------
  906|  5.49M|            break;
  907|  5.49M|        }
  908|  13.4M|    }
  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|  5.49M|    if (i > j) {
  ------------------
  |  Branch (913:9): [True: 562k, False: 4.93M]
  ------------------
  914|   562k|        return 1;
  915|   562k|    }
  916|  4.93M|    if (j > i) {
  ------------------
  |  Branch (916:9): [True: 9.87k, False: 4.92M]
  ------------------
  917|  9.87k|        return -1;
  918|  9.87k|    }
  919|       |
  920|  4.95M|    for (; i > 0; i--) {
  ------------------
  |  Branch (920:12): [True: 4.94M, False: 7.89k]
  ------------------
  921|  4.94M|        if (X->p[i - 1] > Y->p[i - 1]) {
  ------------------
  |  Branch (921:13): [True: 1.64M, False: 3.29M]
  ------------------
  922|  1.64M|            return 1;
  923|  1.64M|        }
  924|  3.29M|        if (X->p[i - 1] < Y->p[i - 1]) {
  ------------------
  |  Branch (924:13): [True: 3.27M, False: 26.7k]
  ------------------
  925|  3.27M|            return -1;
  926|  3.27M|        }
  927|  3.29M|    }
  928|       |
  929|  7.89k|    return 0;
  930|  4.92M|}
mbedtls_mpi_cmp_mpi:
  936|  9.69M|{
  937|  9.69M|    size_t i, j;
  938|       |
  939|  45.9M|    for (i = X->n; i > 0; i--) {
  ------------------
  |  Branch (939:20): [True: 45.9M, False: 6.76k]
  ------------------
  940|  45.9M|        if (X->p[i - 1] != 0) {
  ------------------
  |  Branch (940:13): [True: 9.69M, False: 36.2M]
  ------------------
  941|  9.69M|            break;
  942|  9.69M|        }
  943|  45.9M|    }
  944|       |
  945|  15.5M|    for (j = Y->n; j > 0; j--) {
  ------------------
  |  Branch (945:20): [True: 11.5M, False: 3.97M]
  ------------------
  946|  11.5M|        if (Y->p[j - 1] != 0) {
  ------------------
  |  Branch (946:13): [True: 5.71M, False: 5.86M]
  ------------------
  947|  5.71M|            break;
  948|  5.71M|        }
  949|  11.5M|    }
  950|       |
  951|  9.69M|    if (i == 0 && j == 0) {
  ------------------
  |  Branch (951:9): [True: 6.76k, False: 9.69M]
  |  Branch (951:19): [True: 6.76k, False: 0]
  ------------------
  952|  6.76k|        return 0;
  953|  6.76k|    }
  954|       |
  955|  9.69M|    if (i > j) {
  ------------------
  |  Branch (955:9): [True: 5.03M, False: 4.66M]
  ------------------
  956|  5.03M|        return X->s;
  957|  5.03M|    }
  958|  4.66M|    if (j > i) {
  ------------------
  |  Branch (958:9): [True: 24.2k, False: 4.63M]
  ------------------
  959|  24.2k|        return -Y->s;
  960|  24.2k|    }
  961|       |
  962|  4.63M|    if (X->s > 0 && Y->s < 0) {
  ------------------
  |  Branch (962:9): [True: 4.63M, False: 0]
  |  Branch (962:21): [True: 0, False: 4.63M]
  ------------------
  963|      0|        return 1;
  964|      0|    }
  965|  4.63M|    if (Y->s > 0 && X->s < 0) {
  ------------------
  |  Branch (965:9): [True: 4.63M, False: 0]
  |  Branch (965:21): [True: 0, False: 4.63M]
  ------------------
  966|      0|        return -1;
  967|      0|    }
  968|       |
  969|  4.76M|    for (; i > 0; i--) {
  ------------------
  |  Branch (969:12): [True: 4.66M, False: 93.0k]
  ------------------
  970|  4.66M|        if (X->p[i - 1] > Y->p[i - 1]) {
  ------------------
  |  Branch (970:13): [True: 606k, False: 4.06M]
  ------------------
  971|   606k|            return X->s;
  972|   606k|        }
  973|  4.06M|        if (X->p[i - 1] < Y->p[i - 1]) {
  ------------------
  |  Branch (973:13): [True: 3.93M, False: 124k]
  ------------------
  974|  3.93M|            return -X->s;
  975|  3.93M|        }
  976|  4.06M|    }
  977|       |
  978|  93.0k|    return 0;
  979|  4.63M|}
mbedtls_mpi_cmp_int:
  985|  4.06M|{
  986|  4.06M|    mbedtls_mpi Y;
  987|  4.06M|    mbedtls_mpi_uint p[1];
  988|       |
  989|  4.06M|    *p  = mpi_sint_abs(z);
  990|  4.06M|    Y.s = TO_SIGN(z);
  ------------------
  |  |  372|  4.06M|#define TO_SIGN(x) ((mbedtls_mpi_sint) (((mbedtls_mpi_uint) x) >> (biL - 1)) * -2 + 1)
  |  |  ------------------
  |  |  |  |   80|  4.06M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  |  |  ------------------
  |  |  |  |  |  |   79|  4.06M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  991|  4.06M|    Y.n = 1;
  992|  4.06M|    Y.p = p;
  993|       |
  994|  4.06M|    return mbedtls_mpi_cmp_mpi(X, &Y);
  995|  4.06M|}
mbedtls_mpi_add_abs:
 1001|  1.37M|{
 1002|  1.37M|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  1.37M|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1003|  1.37M|    size_t j;
 1004|  1.37M|    mbedtls_mpi_uint *p;
 1005|  1.37M|    mbedtls_mpi_uint c;
 1006|       |
 1007|  1.37M|    if (X == B) {
  ------------------
  |  Branch (1007:9): [True: 0, False: 1.37M]
  ------------------
 1008|      0|        const mbedtls_mpi *T = A; A = X; B = T;
 1009|      0|    }
 1010|       |
 1011|  1.37M|    if (X != A) {
  ------------------
  |  Branch (1011:9): [True: 173k, False: 1.20M]
  ------------------
 1012|   173k|        MBEDTLS_MPI_CHK(mbedtls_mpi_copy(X, A));
  ------------------
  |  |   41|   173k|    do                           \
  |  |   42|   173k|    {                            \
  |  |   43|   173k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 173k]
  |  |  ------------------
  |  |   44|   173k|        goto cleanup;        \
  |  |   45|   173k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1013|   173k|    }
 1014|       |
 1015|       |    /*
 1016|       |     * X must always be positive as a result of unsigned additions.
 1017|       |     */
 1018|  1.37M|    X->s = 1;
 1019|       |
 1020|  2.53M|    for (j = B->n; j > 0; j--) {
  ------------------
  |  Branch (1020:20): [True: 2.53M, False: 282]
  ------------------
 1021|  2.53M|        if (B->p[j - 1] != 0) {
  ------------------
  |  Branch (1021:13): [True: 1.37M, False: 1.16M]
  ------------------
 1022|  1.37M|            break;
 1023|  1.37M|        }
 1024|  2.53M|    }
 1025|       |
 1026|       |    /* Exit early to avoid undefined behavior on NULL+0 when X->n == 0
 1027|       |     * and B is 0 (of any size). */
 1028|  1.37M|    if (j == 0) {
  ------------------
  |  Branch (1028:9): [True: 282, False: 1.37M]
  ------------------
 1029|    282|        return 0;
 1030|    282|    }
 1031|       |
 1032|  1.37M|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, j));
  ------------------
  |  |   41|  1.37M|    do                           \
  |  |   42|  1.37M|    {                            \
  |  |   43|  1.37M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.37M]
  |  |  ------------------
  |  |   44|  1.37M|        goto cleanup;        \
  |  |   45|  1.37M|    } 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|  1.37M|    p = X->p;
 1037|       |
 1038|  1.37M|    c = mbedtls_mpi_core_add(p, p, B->p, j);
 1039|       |
 1040|  1.37M|    p += j;
 1041|       |
 1042|       |    /* Now propagate any carry */
 1043|       |
 1044|  1.97M|    while (c != 0) {
  ------------------
  |  Branch (1044:12): [True: 605k, False: 1.37M]
  ------------------
 1045|   605k|        if (j >= X->n) {
  ------------------
  |  Branch (1045:13): [True: 6.48k, False: 598k]
  ------------------
 1046|  6.48k|            MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, j + 1));
  ------------------
  |  |   41|  6.48k|    do                           \
  |  |   42|  6.48k|    {                            \
  |  |   43|  6.48k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 6.48k]
  |  |  ------------------
  |  |   44|  6.48k|        goto cleanup;        \
  |  |   45|  6.48k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1047|  6.48k|            p = X->p + j;
 1048|  6.48k|        }
 1049|       |
 1050|   605k|        *p += c; c = (*p < c); j++; p++;
 1051|   605k|    }
 1052|       |
 1053|  1.37M|cleanup:
 1054|       |
 1055|  1.37M|    return ret;
 1056|  1.37M|}
mbedtls_mpi_sub_abs:
 1062|  7.13M|{
 1063|  7.13M|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  7.13M|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1064|  7.13M|    size_t n;
 1065|  7.13M|    mbedtls_mpi_uint carry;
 1066|       |
 1067|  25.6M|    for (n = B->n; n > 0; n--) {
  ------------------
  |  Branch (1067:20): [True: 25.6M, False: 6.76k]
  ------------------
 1068|  25.6M|        if (B->p[n - 1] != 0) {
  ------------------
  |  Branch (1068:13): [True: 7.12M, False: 18.5M]
  ------------------
 1069|  7.12M|            break;
 1070|  7.12M|        }
 1071|  25.6M|    }
 1072|  7.13M|    if (n > A->n) {
  ------------------
  |  Branch (1072:9): [True: 0, False: 7.13M]
  ------------------
 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|  7.13M|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, A->n));
  ------------------
  |  |   41|  7.13M|    do                           \
  |  |   42|  7.13M|    {                            \
  |  |   43|  7.13M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 7.13M]
  |  |  ------------------
  |  |   44|  7.13M|        goto cleanup;        \
  |  |   45|  7.13M|    } 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|  7.13M|    if (A->n > n && A != X) {
  ------------------
  |  Branch (1083:9): [True: 4.33M, False: 2.80M]
  |  Branch (1083:21): [True: 1.01M, False: 3.31M]
  ------------------
 1084|  1.01M|        memcpy(X->p + n, A->p + n, (A->n - n) * ciL);
  ------------------
  |  |   79|  1.01M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
 1085|  1.01M|    }
 1086|  7.13M|    if (X->n > A->n) {
  ------------------
  |  Branch (1086:9): [True: 2.26M, False: 4.87M]
  ------------------
 1087|  2.26M|        memset(X->p + A->n, 0, (X->n - A->n) * ciL);
  ------------------
  |  |   79|  2.26M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
 1088|  2.26M|    }
 1089|       |
 1090|  7.13M|    carry = mbedtls_mpi_core_sub(X->p, A->p, B->p, n);
 1091|  7.13M|    if (carry != 0) {
  ------------------
  |  Branch (1091:9): [True: 1.58M, False: 5.55M]
  ------------------
 1092|       |        /* Propagate the carry through the rest of X. */
 1093|  1.58M|        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|  1.58M|        if (carry != 0) {
  ------------------
  |  Branch (1096:13): [True: 0, False: 1.58M]
  ------------------
 1097|      0|            ret = MBEDTLS_ERR_MPI_NEGATIVE_VALUE;
  ------------------
  |  |   32|      0|#define MBEDTLS_ERR_MPI_NEGATIVE_VALUE                    -0x000A
  ------------------
 1098|      0|            goto cleanup;
 1099|      0|        }
 1100|  1.58M|    }
 1101|       |
 1102|       |    /* X should always be positive as a result of unsigned subtractions. */
 1103|  7.13M|    X->s = 1;
 1104|       |
 1105|  7.13M|cleanup:
 1106|  7.13M|    return ret;
 1107|  7.13M|}
mbedtls_mpi_add_mpi:
 1146|  3.13M|{
 1147|  3.13M|    return add_sub_mpi(X, A, B, 1);
 1148|  3.13M|}
mbedtls_mpi_sub_mpi:
 1154|  3.72M|{
 1155|  3.72M|    return add_sub_mpi(X, A, B, -1);
 1156|  3.72M|}
mbedtls_mpi_sub_int:
 1178|  5.64k|{
 1179|  5.64k|    mbedtls_mpi B;
 1180|  5.64k|    mbedtls_mpi_uint p[1];
 1181|       |
 1182|  5.64k|    p[0] = mpi_sint_abs(b);
 1183|  5.64k|    B.s = TO_SIGN(b);
  ------------------
  |  |  372|  5.64k|#define TO_SIGN(x) ((mbedtls_mpi_sint) (((mbedtls_mpi_uint) x) >> (biL - 1)) * -2 + 1)
  |  |  ------------------
  |  |  |  |   80|  5.64k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  |  |  ------------------
  |  |  |  |  |  |   79|  5.64k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1184|  5.64k|    B.n = 1;
 1185|  5.64k|    B.p = p;
 1186|       |
 1187|  5.64k|    return mbedtls_mpi_sub_mpi(X, A, &B);
 1188|  5.64k|}
mbedtls_mpi_mul_mpi:
 1194|  2.21M|{
 1195|  2.21M|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  2.21M|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1196|  2.21M|    size_t i, j;
 1197|  2.21M|    mbedtls_mpi TA, TB;
 1198|  2.21M|    int result_is_zero = 0;
 1199|       |
 1200|  2.21M|    mbedtls_mpi_init(&TA);
 1201|  2.21M|    mbedtls_mpi_init(&TB);
 1202|       |
 1203|  2.21M|    if (X == A) {
  ------------------
  |  Branch (1203:9): [True: 623k, False: 1.59M]
  ------------------
 1204|   623k|        MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TA, A)); A = &TA;
  ------------------
  |  |   41|   623k|    do                           \
  |  |   42|   623k|    {                            \
  |  |   43|   623k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 623k]
  |  |  ------------------
  |  |   44|   623k|        goto cleanup;        \
  |  |   45|   623k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1205|   623k|    }
 1206|  2.21M|    if (X == B) {
  ------------------
  |  Branch (1206:9): [True: 7.33k, False: 2.21M]
  ------------------
 1207|  7.33k|        MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TB, B)); B = &TB;
  ------------------
  |  |   41|  7.33k|    do                           \
  |  |   42|  7.33k|    {                            \
  |  |   43|  7.33k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 7.33k]
  |  |  ------------------
  |  |   44|  7.33k|        goto cleanup;        \
  |  |   45|  7.33k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1208|  7.33k|    }
 1209|       |
 1210|  7.48M|    for (i = A->n; i > 0; i--) {
  ------------------
  |  Branch (1210:20): [True: 7.48M, False: 0]
  ------------------
 1211|  7.48M|        if (A->p[i - 1] != 0) {
  ------------------
  |  Branch (1211:13): [True: 2.21M, False: 5.26M]
  ------------------
 1212|  2.21M|            break;
 1213|  2.21M|        }
 1214|  7.48M|    }
 1215|  2.21M|    if (i == 0) {
  ------------------
  |  Branch (1215:9): [True: 0, False: 2.21M]
  ------------------
 1216|      0|        result_is_zero = 1;
 1217|      0|    }
 1218|       |
 1219|  9.89M|    for (j = B->n; j > 0; j--) {
  ------------------
  |  Branch (1219:20): [True: 9.89M, False: 0]
  ------------------
 1220|  9.89M|        if (B->p[j - 1] != 0) {
  ------------------
  |  Branch (1220:13): [True: 2.21M, False: 7.67M]
  ------------------
 1221|  2.21M|            break;
 1222|  2.21M|        }
 1223|  9.89M|    }
 1224|  2.21M|    if (j == 0) {
  ------------------
  |  Branch (1224:9): [True: 0, False: 2.21M]
  ------------------
 1225|      0|        result_is_zero = 1;
 1226|      0|    }
 1227|       |
 1228|  2.21M|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, i + j));
  ------------------
  |  |   41|  2.21M|    do                           \
  |  |   42|  2.21M|    {                            \
  |  |   43|  2.21M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.21M]
  |  |  ------------------
  |  |   44|  2.21M|        goto cleanup;        \
  |  |   45|  2.21M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1229|  2.21M|    MBEDTLS_MPI_CHK(mbedtls_mpi_lset(X, 0));
  ------------------
  |  |   41|  2.21M|    do                           \
  |  |   42|  2.21M|    {                            \
  |  |   43|  2.21M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.21M]
  |  |  ------------------
  |  |   44|  2.21M|        goto cleanup;        \
  |  |   45|  2.21M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1230|       |
 1231|  2.21M|    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|  2.21M|    if (result_is_zero) {
  ------------------
  |  Branch (1237:9): [True: 0, False: 2.21M]
  ------------------
 1238|      0|        X->s = 1;
 1239|  2.21M|    } else {
 1240|  2.21M|        X->s = A->s * B->s;
 1241|  2.21M|    }
 1242|       |
 1243|  2.21M|cleanup:
 1244|       |
 1245|  2.21M|    mbedtls_mpi_free(&TB); mbedtls_mpi_free(&TA);
 1246|       |
 1247|  2.21M|    return ret;
 1248|  2.21M|}
mbedtls_mpi_mul_int:
 1254|   184k|{
 1255|   184k|    size_t n = A->n;
 1256|  1.12M|    while (n > 0 && A->p[n - 1] == 0) {
  ------------------
  |  Branch (1256:12): [True: 1.12M, False: 0]
  |  Branch (1256:21): [True: 940k, False: 184k]
  ------------------
 1257|   940k|        --n;
 1258|   940k|    }
 1259|       |
 1260|       |    /* The general method below doesn't work if b==0. */
 1261|   184k|    if (b == 0 || n == 0) {
  ------------------
  |  Branch (1261:9): [True: 0, False: 184k]
  |  Branch (1261:19): [True: 0, False: 184k]
  ------------------
 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|   184k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|   184k|#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|   184k|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, n + 1));
  ------------------
  |  |   41|   184k|    do                           \
  |  |   42|   184k|    {                            \
  |  |   43|   184k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 184k]
  |  |  ------------------
  |  |   44|   184k|        goto cleanup;        \
  |  |   45|   184k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1279|   184k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(X, A));
  ------------------
  |  |   41|   184k|    do                           \
  |  |   42|   184k|    {                            \
  |  |   43|   184k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 184k]
  |  |  ------------------
  |  |   44|   184k|        goto cleanup;        \
  |  |   45|   184k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1280|   184k|    mbedtls_mpi_core_mla(X->p, X->n, A->p, n, b - 1);
 1281|       |
 1282|   184k|cleanup:
 1283|   184k|    return ret;
 1284|   184k|}
mbedtls_mpi_div_mpi:
 1395|  5.07k|{
 1396|  5.07k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  5.07k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1397|  5.07k|    size_t i, n, t, k;
 1398|  5.07k|    mbedtls_mpi X, Y, Z, T1, T2;
 1399|  5.07k|    mbedtls_mpi_uint TP2[3];
 1400|       |
 1401|  5.07k|    if (mbedtls_mpi_cmp_int(B, 0) == 0) {
  ------------------
  |  Branch (1401:9): [True: 0, False: 5.07k]
  ------------------
 1402|      0|        return MBEDTLS_ERR_MPI_DIVISION_BY_ZERO;
  ------------------
  |  |   34|      0|#define MBEDTLS_ERR_MPI_DIVISION_BY_ZERO                  -0x000C
  ------------------
 1403|      0|    }
 1404|       |
 1405|  5.07k|    mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y); mbedtls_mpi_init(&Z);
 1406|  5.07k|    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|  5.07k|    T2.s = 1;
 1415|  5.07k|    T2.n = sizeof(TP2) / sizeof(*TP2);
 1416|  5.07k|    T2.p = TP2;
 1417|       |
 1418|  5.07k|    if (mbedtls_mpi_cmp_abs(A, B) < 0) {
  ------------------
  |  Branch (1418:9): [True: 3.94k, False: 1.12k]
  ------------------
 1419|  3.94k|        if (Q != NULL) {
  ------------------
  |  Branch (1419:13): [True: 0, False: 3.94k]
  ------------------
 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|  3.94k|        if (R != NULL) {
  ------------------
  |  Branch (1422:13): [True: 3.94k, False: 0]
  ------------------
 1423|  3.94k|            MBEDTLS_MPI_CHK(mbedtls_mpi_copy(R, A));
  ------------------
  |  |   41|  3.94k|    do                           \
  |  |   42|  3.94k|    {                            \
  |  |   43|  3.94k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3.94k]
  |  |  ------------------
  |  |   44|  3.94k|        goto cleanup;        \
  |  |   45|  3.94k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1424|  3.94k|        }
 1425|  3.94k|        return 0;
 1426|  3.94k|    }
 1427|       |
 1428|  1.12k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&X, A));
  ------------------
  |  |   41|  1.12k|    do                           \
  |  |   42|  1.12k|    {                            \
  |  |   43|  1.12k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.12k]
  |  |  ------------------
  |  |   44|  1.12k|        goto cleanup;        \
  |  |   45|  1.12k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1429|  1.12k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&Y, B));
  ------------------
  |  |   41|  1.12k|    do                           \
  |  |   42|  1.12k|    {                            \
  |  |   43|  1.12k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.12k]
  |  |  ------------------
  |  |   44|  1.12k|        goto cleanup;        \
  |  |   45|  1.12k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1430|  1.12k|    X.s = Y.s = 1;
 1431|       |
 1432|  1.12k|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(&Z, A->n + 2));
  ------------------
  |  |   41|  1.12k|    do                           \
  |  |   42|  1.12k|    {                            \
  |  |   43|  1.12k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.12k]
  |  |  ------------------
  |  |   44|  1.12k|        goto cleanup;        \
  |  |   45|  1.12k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1433|  1.12k|    MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&Z,  0));
  ------------------
  |  |   41|  1.12k|    do                           \
  |  |   42|  1.12k|    {                            \
  |  |   43|  1.12k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.12k]
  |  |  ------------------
  |  |   44|  1.12k|        goto cleanup;        \
  |  |   45|  1.12k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1434|  1.12k|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(&T1, A->n + 2));
  ------------------
  |  |   41|  1.12k|    do                           \
  |  |   42|  1.12k|    {                            \
  |  |   43|  1.12k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.12k]
  |  |  ------------------
  |  |   44|  1.12k|        goto cleanup;        \
  |  |   45|  1.12k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1435|       |
 1436|  1.12k|    k = mbedtls_mpi_bitlen(&Y) % biL;
  ------------------
  |  |   80|  1.12k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  1.12k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
 1437|  1.12k|    if (k < biL - 1) {
  ------------------
  |  |   80|  1.12k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  1.12k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  |  Branch (1437:9): [True: 1.12k, False: 0]
  ------------------
 1438|  1.12k|        k = biL - 1 - k;
  ------------------
  |  |   80|  1.12k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  1.12k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
 1439|  1.12k|        MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&X, k));
  ------------------
  |  |   41|  1.12k|    do                           \
  |  |   42|  1.12k|    {                            \
  |  |   43|  1.12k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.12k]
  |  |  ------------------
  |  |   44|  1.12k|        goto cleanup;        \
  |  |   45|  1.12k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1440|  1.12k|        MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&Y, k));
  ------------------
  |  |   41|  1.12k|    do                           \
  |  |   42|  1.12k|    {                            \
  |  |   43|  1.12k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.12k]
  |  |  ------------------
  |  |   44|  1.12k|        goto cleanup;        \
  |  |   45|  1.12k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1441|  1.12k|    } else {
 1442|      0|        k = 0;
 1443|      0|    }
 1444|       |
 1445|  1.12k|    n = X.n - 1;
 1446|  1.12k|    t = Y.n - 1;
 1447|  1.12k|    MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&Y, biL * (n - t)));
  ------------------
  |  |   41|  1.12k|    do                           \
  |  |   42|  1.12k|    {                            \
  |  |   43|  1.12k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.12k]
  |  |  ------------------
  |  |   44|  1.12k|        goto cleanup;        \
  |  |   45|  1.12k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1448|       |
 1449|  1.12k|    while (mbedtls_mpi_cmp_mpi(&X, &Y) >= 0) {
  ------------------
  |  Branch (1449:12): [True: 0, False: 1.12k]
  ------------------
 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|  1.12k|    MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&Y, biL * (n - t)));
  ------------------
  |  |   41|  1.12k|    do                           \
  |  |   42|  1.12k|    {                            \
  |  |   43|  1.12k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.12k]
  |  |  ------------------
  |  |   44|  1.12k|        goto cleanup;        \
  |  |   45|  1.12k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1454|       |
 1455|  5.64k|    for (i = n; i > t; i--) {
  ------------------
  |  Branch (1455:17): [True: 4.51k, False: 1.12k]
  ------------------
 1456|  4.51k|        if (X.p[i] >= Y.p[t]) {
  ------------------
  |  Branch (1456:13): [True: 0, False: 4.51k]
  ------------------
 1457|      0|            Z.p[i - t - 1] = ~(mbedtls_mpi_uint) 0u;
 1458|  4.51k|        } else {
 1459|  4.51k|            Z.p[i - t - 1] = mbedtls_int_div_int(X.p[i], X.p[i - 1],
 1460|  4.51k|                                                 Y.p[t], NULL);
 1461|  4.51k|        }
 1462|       |
 1463|  4.51k|        T2.p[0] = (i < 2) ? 0 : X.p[i - 2];
  ------------------
  |  Branch (1463:19): [True: 0, False: 4.51k]
  ------------------
 1464|  4.51k|        T2.p[1] = (i < 1) ? 0 : X.p[i - 1];
  ------------------
  |  Branch (1464:19): [True: 0, False: 4.51k]
  ------------------
 1465|  4.51k|        T2.p[2] = X.p[i];
 1466|       |
 1467|  4.51k|        Z.p[i - t - 1]++;
 1468|  6.76k|        do {
 1469|  6.76k|            Z.p[i - t - 1]--;
 1470|       |
 1471|  6.76k|            MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&T1, 0));
  ------------------
  |  |   41|  6.76k|    do                           \
  |  |   42|  6.76k|    {                            \
  |  |   43|  6.76k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 6.76k]
  |  |  ------------------
  |  |   44|  6.76k|        goto cleanup;        \
  |  |   45|  6.76k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1472|  6.76k|            T1.p[0] = (t < 1) ? 0 : Y.p[t - 1];
  ------------------
  |  Branch (1472:23): [True: 0, False: 6.76k]
  ------------------
 1473|  6.76k|            T1.p[1] = Y.p[t];
 1474|  6.76k|            MBEDTLS_MPI_CHK(mbedtls_mpi_mul_int(&T1, &T1, Z.p[i - t - 1]));
  ------------------
  |  |   41|  6.76k|    do                           \
  |  |   42|  6.76k|    {                            \
  |  |   43|  6.76k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 6.76k]
  |  |  ------------------
  |  |   44|  6.76k|        goto cleanup;        \
  |  |   45|  6.76k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1475|  6.76k|        } while (mbedtls_mpi_cmp_mpi(&T1, &T2) > 0);
  ------------------
  |  Branch (1475:18): [True: 2.25k, False: 4.51k]
  ------------------
 1476|       |
 1477|  4.51k|        MBEDTLS_MPI_CHK(mbedtls_mpi_mul_int(&T1, &Y, Z.p[i - t - 1]));
  ------------------
  |  |   41|  4.51k|    do                           \
  |  |   42|  4.51k|    {                            \
  |  |   43|  4.51k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.51k]
  |  |  ------------------
  |  |   44|  4.51k|        goto cleanup;        \
  |  |   45|  4.51k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1478|  4.51k|        MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&T1,  biL * (i - t - 1)));
  ------------------
  |  |   41|  4.51k|    do                           \
  |  |   42|  4.51k|    {                            \
  |  |   43|  4.51k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.51k]
  |  |  ------------------
  |  |   44|  4.51k|        goto cleanup;        \
  |  |   45|  4.51k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1479|  4.51k|        MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&X, &X, &T1));
  ------------------
  |  |   41|  4.51k|    do                           \
  |  |   42|  4.51k|    {                            \
  |  |   43|  4.51k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.51k]
  |  |  ------------------
  |  |   44|  4.51k|        goto cleanup;        \
  |  |   45|  4.51k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1480|       |
 1481|  4.51k|        if (mbedtls_mpi_cmp_int(&X, 0) < 0) {
  ------------------
  |  Branch (1481:13): [True: 0, False: 4.51k]
  ------------------
 1482|      0|            MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&T1, &Y));
  ------------------
  |  |   41|      0|    do                           \
  |  |   42|      0|    {                            \
  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  ------------------
  |  |   44|      0|        goto cleanup;        \
  |  |   45|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1483|      0|            MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&T1, biL * (i - t - 1)));
  ------------------
  |  |   41|      0|    do                           \
  |  |   42|      0|    {                            \
  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  ------------------
  |  |   44|      0|        goto cleanup;        \
  |  |   45|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1484|      0|            MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&X, &X, &T1));
  ------------------
  |  |   41|      0|    do                           \
  |  |   42|      0|    {                            \
  |  |   43|      0|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 0]
  |  |  ------------------
  |  |   44|      0|        goto cleanup;        \
  |  |   45|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1485|      0|            Z.p[i - t - 1]--;
 1486|      0|        }
 1487|  4.51k|    }
 1488|       |
 1489|  1.12k|    if (Q != NULL) {
  ------------------
  |  Branch (1489:9): [True: 0, False: 1.12k]
  ------------------
 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|  1.12k|    if (R != NULL) {
  ------------------
  |  Branch (1494:9): [True: 1.12k, False: 0]
  ------------------
 1495|  1.12k|        MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&X, k));
  ------------------
  |  |   41|  1.12k|    do                           \
  |  |   42|  1.12k|    {                            \
  |  |   43|  1.12k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.12k]
  |  |  ------------------
  |  |   44|  1.12k|        goto cleanup;        \
  |  |   45|  1.12k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1496|  1.12k|        X.s = A->s;
 1497|  1.12k|        MBEDTLS_MPI_CHK(mbedtls_mpi_copy(R, &X));
  ------------------
  |  |   41|  1.12k|    do                           \
  |  |   42|  1.12k|    {                            \
  |  |   43|  1.12k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.12k]
  |  |  ------------------
  |  |   44|  1.12k|        goto cleanup;        \
  |  |   45|  1.12k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1498|       |
 1499|  1.12k|        if (mbedtls_mpi_cmp_int(R, 0) == 0) {
  ------------------
  |  Branch (1499:13): [True: 0, False: 1.12k]
  ------------------
 1500|      0|            R->s = 1;
 1501|      0|        }
 1502|  1.12k|    }
 1503|       |
 1504|  1.12k|cleanup:
 1505|       |
 1506|  1.12k|    mbedtls_mpi_free(&X); mbedtls_mpi_free(&Y); mbedtls_mpi_free(&Z);
 1507|  1.12k|    mbedtls_mpi_free(&T1);
 1508|  1.12k|    mbedtls_platform_zeroize(TP2, sizeof(TP2));
 1509|       |
 1510|  1.12k|    return ret;
 1511|  1.12k|}
mbedtls_mpi_mod_mpi:
 1535|  5.07k|{
 1536|  5.07k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  5.07k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1537|       |
 1538|  5.07k|    if (mbedtls_mpi_cmp_int(B, 0) < 0) {
  ------------------
  |  Branch (1538:9): [True: 0, False: 5.07k]
  ------------------
 1539|      0|        return MBEDTLS_ERR_MPI_NEGATIVE_VALUE;
  ------------------
  |  |   32|      0|#define MBEDTLS_ERR_MPI_NEGATIVE_VALUE                    -0x000A
  ------------------
 1540|      0|    }
 1541|       |
 1542|  5.07k|    MBEDTLS_MPI_CHK(mbedtls_mpi_div_mpi(NULL, R, A, B));
  ------------------
  |  |   41|  5.07k|    do                           \
  |  |   42|  5.07k|    {                            \
  |  |   43|  5.07k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 5.07k]
  |  |  ------------------
  |  |   44|  5.07k|        goto cleanup;        \
  |  |   45|  5.07k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1543|       |
 1544|  5.07k|    while (mbedtls_mpi_cmp_int(R, 0) < 0) {
  ------------------
  |  Branch (1544:12): [True: 0, False: 5.07k]
  ------------------
 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|  5.07k|    while (mbedtls_mpi_cmp_mpi(R, B) >= 0) {
  ------------------
  |  Branch (1548:12): [True: 0, False: 5.07k]
  ------------------
 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|  5.07k|cleanup:
 1553|       |
 1554|  5.07k|    return ret;
 1555|  5.07k|}
mbedtls_mpi_gcd:
 1750|  3.38k|{
 1751|  3.38k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  3.38k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1752|  3.38k|    size_t lz, lzt;
 1753|  3.38k|    mbedtls_mpi TA, TB;
 1754|       |
 1755|  3.38k|    mbedtls_mpi_init(&TA); mbedtls_mpi_init(&TB);
 1756|       |
 1757|  3.38k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TA, A));
  ------------------
  |  |   41|  3.38k|    do                           \
  |  |   42|  3.38k|    {                            \
  |  |   43|  3.38k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3.38k]
  |  |  ------------------
  |  |   44|  3.38k|        goto cleanup;        \
  |  |   45|  3.38k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1758|  3.38k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TB, B));
  ------------------
  |  |   41|  3.38k|    do                           \
  |  |   42|  3.38k|    {                            \
  |  |   43|  3.38k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3.38k]
  |  |  ------------------
  |  |   44|  3.38k|        goto cleanup;        \
  |  |   45|  3.38k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1759|       |
 1760|  3.38k|    lz = mbedtls_mpi_lsb(&TA);
 1761|  3.38k|    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|  3.38k|    if (lzt == 0 && mbedtls_mpi_get_bit(&TB, 0) == 0) {
  ------------------
  |  Branch (1767:9): [True: 3.38k, False: 0]
  |  Branch (1767:21): [True: 0, False: 3.38k]
  ------------------
 1768|      0|        ret = mbedtls_mpi_copy(G, A);
 1769|      0|        goto cleanup;
 1770|      0|    }
 1771|       |
 1772|  3.38k|    if (lzt < lz) {
  ------------------
  |  Branch (1772:9): [True: 1.97k, False: 1.41k]
  ------------------
 1773|  1.97k|        lz = lzt;
 1774|  1.97k|    }
 1775|       |
 1776|  3.38k|    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|   615k|    while (mbedtls_mpi_cmp_int(&TA, 0) != 0) {
  ------------------
  |  Branch (1811:12): [True: 611k, False: 3.38k]
  ------------------
 1812|       |        /* Divisions by 2 preserve the invariant (I). */
 1813|   611k|        MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TA, mbedtls_mpi_lsb(&TA)));
  ------------------
  |  |   41|   611k|    do                           \
  |  |   42|   611k|    {                            \
  |  |   43|   611k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 611k]
  |  |  ------------------
  |  |   44|   611k|        goto cleanup;        \
  |  |   45|   611k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1814|   611k|        MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TB, mbedtls_mpi_lsb(&TB)));
  ------------------
  |  |   41|   611k|    do                           \
  |  |   42|   611k|    {                            \
  |  |   43|   611k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 611k]
  |  |  ------------------
  |  |   44|   611k|        goto cleanup;        \
  |  |   45|   611k|    } 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|   611k|        if (mbedtls_mpi_cmp_mpi(&TA, &TB) >= 0) {
  ------------------
  |  Branch (1823:13): [True: 313k, False: 298k]
  ------------------
 1824|   313k|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs(&TA, &TA, &TB));
  ------------------
  |  |   41|   313k|    do                           \
  |  |   42|   313k|    {                            \
  |  |   43|   313k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 313k]
  |  |  ------------------
  |  |   44|   313k|        goto cleanup;        \
  |  |   45|   313k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1825|   313k|            MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TA, 1));
  ------------------
  |  |   41|   313k|    do                           \
  |  |   42|   313k|    {                            \
  |  |   43|   313k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 313k]
  |  |  ------------------
  |  |   44|   313k|        goto cleanup;        \
  |  |   45|   313k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1826|   313k|        } else {
 1827|   298k|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs(&TB, &TB, &TA));
  ------------------
  |  |   41|   298k|    do                           \
  |  |   42|   298k|    {                            \
  |  |   43|   298k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 298k]
  |  |  ------------------
  |  |   44|   298k|        goto cleanup;        \
  |  |   45|   298k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1828|   298k|            MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TB, 1));
  ------------------
  |  |   41|   298k|    do                           \
  |  |   42|   298k|    {                            \
  |  |   43|   298k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 298k]
  |  |  ------------------
  |  |   44|   298k|        goto cleanup;        \
  |  |   45|   298k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1829|   298k|        }
 1830|       |        /* Note that one of TA or TB is still odd. */
 1831|   611k|    }
 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|  3.38k|    MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&TB, lz));
  ------------------
  |  |   41|  3.38k|    do                           \
  |  |   42|  3.38k|    {                            \
  |  |   43|  3.38k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3.38k]
  |  |  ------------------
  |  |   44|  3.38k|        goto cleanup;        \
  |  |   45|  3.38k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1843|  3.38k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(G, &TB));
  ------------------
  |  |   41|  3.38k|    do                           \
  |  |   42|  3.38k|    {                            \
  |  |   43|  3.38k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3.38k]
  |  |  ------------------
  |  |   44|  3.38k|        goto cleanup;        \
  |  |   45|  3.38k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1844|       |
 1845|  3.38k|cleanup:
 1846|       |
 1847|  3.38k|    mbedtls_mpi_free(&TA); mbedtls_mpi_free(&TB);
 1848|       |
 1849|  3.38k|    return ret;
 1850|  3.38k|}
mbedtls_mpi_inv_mod:
 1905|  3.38k|{
 1906|  3.38k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  3.38k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1907|  3.38k|    mbedtls_mpi G, TA, TU, U1, U2, TB, TV, V1, V2;
 1908|       |
 1909|  3.38k|    if (mbedtls_mpi_cmp_int(N, 1) <= 0) {
  ------------------
  |  Branch (1909:9): [True: 0, False: 3.38k]
  ------------------
 1910|      0|        return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MPI_BAD_INPUT_DATA                    -0x0004
  ------------------
 1911|      0|    }
 1912|       |
 1913|  3.38k|    mbedtls_mpi_init(&TA); mbedtls_mpi_init(&TU); mbedtls_mpi_init(&U1); mbedtls_mpi_init(&U2);
 1914|  3.38k|    mbedtls_mpi_init(&G); mbedtls_mpi_init(&TB); mbedtls_mpi_init(&TV);
 1915|  3.38k|    mbedtls_mpi_init(&V1); mbedtls_mpi_init(&V2);
 1916|       |
 1917|  3.38k|    MBEDTLS_MPI_CHK(mbedtls_mpi_gcd(&G, A, N));
  ------------------
  |  |   41|  3.38k|    do                           \
  |  |   42|  3.38k|    {                            \
  |  |   43|  3.38k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3.38k]
  |  |  ------------------
  |  |   44|  3.38k|        goto cleanup;        \
  |  |   45|  3.38k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1918|       |
 1919|  3.38k|    if (mbedtls_mpi_cmp_int(&G, 1) != 0) {
  ------------------
  |  Branch (1919:9): [True: 0, False: 3.38k]
  ------------------
 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|  3.38k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&TA, A, N));
  ------------------
  |  |   41|  3.38k|    do                           \
  |  |   42|  3.38k|    {                            \
  |  |   43|  3.38k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3.38k]
  |  |  ------------------
  |  |   44|  3.38k|        goto cleanup;        \
  |  |   45|  3.38k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1925|  3.38k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TU, &TA));
  ------------------
  |  |   41|  3.38k|    do                           \
  |  |   42|  3.38k|    {                            \
  |  |   43|  3.38k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3.38k]
  |  |  ------------------
  |  |   44|  3.38k|        goto cleanup;        \
  |  |   45|  3.38k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1926|  3.38k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TB, N));
  ------------------
  |  |   41|  3.38k|    do                           \
  |  |   42|  3.38k|    {                            \
  |  |   43|  3.38k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3.38k]
  |  |  ------------------
  |  |   44|  3.38k|        goto cleanup;        \
  |  |   45|  3.38k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1927|  3.38k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TV, N));
  ------------------
  |  |   41|  3.38k|    do                           \
  |  |   42|  3.38k|    {                            \
  |  |   43|  3.38k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3.38k]
  |  |  ------------------
  |  |   44|  3.38k|        goto cleanup;        \
  |  |   45|  3.38k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1928|       |
 1929|  3.38k|    MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&U1, 1));
  ------------------
  |  |   41|  3.38k|    do                           \
  |  |   42|  3.38k|    {                            \
  |  |   43|  3.38k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3.38k]
  |  |  ------------------
  |  |   44|  3.38k|        goto cleanup;        \
  |  |   45|  3.38k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1930|  3.38k|    MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&U2, 0));
  ------------------
  |  |   41|  3.38k|    do                           \
  |  |   42|  3.38k|    {                            \
  |  |   43|  3.38k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3.38k]
  |  |  ------------------
  |  |   44|  3.38k|        goto cleanup;        \
  |  |   45|  3.38k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1931|  3.38k|    MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&V1, 0));
  ------------------
  |  |   41|  3.38k|    do                           \
  |  |   42|  3.38k|    {                            \
  |  |   43|  3.38k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3.38k]
  |  |  ------------------
  |  |   44|  3.38k|        goto cleanup;        \
  |  |   45|  3.38k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1932|  3.38k|    MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&V2, 1));
  ------------------
  |  |   41|  3.38k|    do                           \
  |  |   42|  3.38k|    {                            \
  |  |   43|  3.38k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3.38k]
  |  |  ------------------
  |  |   44|  3.38k|        goto cleanup;        \
  |  |   45|  3.38k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1933|       |
 1934|   611k|    do {
 1935|  1.22M|        while ((TU.p[0] & 1) == 0) {
  ------------------
  |  Branch (1935:16): [True: 615k, False: 611k]
  ------------------
 1936|   615k|            MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TU, 1));
  ------------------
  |  |   41|   615k|    do                           \
  |  |   42|   615k|    {                            \
  |  |   43|   615k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 615k]
  |  |  ------------------
  |  |   44|   615k|        goto cleanup;        \
  |  |   45|   615k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1937|       |
 1938|   615k|            if ((U1.p[0] & 1) != 0 || (U2.p[0] & 1) != 0) {
  ------------------
  |  Branch (1938:17): [True: 254k, False: 360k]
  |  Branch (1938:39): [True: 0, False: 360k]
  ------------------
 1939|   254k|                MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&U1, &U1, &TB));
  ------------------
  |  |   41|   254k|    do                           \
  |  |   42|   254k|    {                            \
  |  |   43|   254k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 254k]
  |  |  ------------------
  |  |   44|   254k|        goto cleanup;        \
  |  |   45|   254k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1940|   254k|                MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&U2, &U2, &TA));
  ------------------
  |  |   41|   254k|    do                           \
  |  |   42|   254k|    {                            \
  |  |   43|   254k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 254k]
  |  |  ------------------
  |  |   44|   254k|        goto cleanup;        \
  |  |   45|   254k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1941|   254k|            }
 1942|       |
 1943|   615k|            MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&U1, 1));
  ------------------
  |  |   41|   615k|    do                           \
  |  |   42|   615k|    {                            \
  |  |   43|   615k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 615k]
  |  |  ------------------
  |  |   44|   615k|        goto cleanup;        \
  |  |   45|   615k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1944|   615k|            MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&U2, 1));
  ------------------
  |  |   41|   615k|    do                           \
  |  |   42|   615k|    {                            \
  |  |   43|   615k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 615k]
  |  |  ------------------
  |  |   44|   615k|        goto cleanup;        \
  |  |   45|   615k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1945|   615k|        }
 1946|       |
 1947|  1.21M|        while ((TV.p[0] & 1) == 0) {
  ------------------
  |  Branch (1947:16): [True: 601k, False: 611k]
  ------------------
 1948|   601k|            MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TV, 1));
  ------------------
  |  |   41|   601k|    do                           \
  |  |   42|   601k|    {                            \
  |  |   43|   601k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 601k]
  |  |  ------------------
  |  |   44|   601k|        goto cleanup;        \
  |  |   45|   601k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1949|       |
 1950|   601k|            if ((V1.p[0] & 1) != 0 || (V2.p[0] & 1) != 0) {
  ------------------
  |  Branch (1950:17): [True: 268k, False: 333k]
  |  Branch (1950:39): [True: 0, False: 333k]
  ------------------
 1951|   268k|                MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&V1, &V1, &TB));
  ------------------
  |  |   41|   268k|    do                           \
  |  |   42|   268k|    {                            \
  |  |   43|   268k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 268k]
  |  |  ------------------
  |  |   44|   268k|        goto cleanup;        \
  |  |   45|   268k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1952|   268k|                MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&V2, &V2, &TA));
  ------------------
  |  |   41|   268k|    do                           \
  |  |   42|   268k|    {                            \
  |  |   43|   268k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 268k]
  |  |  ------------------
  |  |   44|   268k|        goto cleanup;        \
  |  |   45|   268k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1953|   268k|            }
 1954|       |
 1955|   601k|            MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&V1, 1));
  ------------------
  |  |   41|   601k|    do                           \
  |  |   42|   601k|    {                            \
  |  |   43|   601k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 601k]
  |  |  ------------------
  |  |   44|   601k|        goto cleanup;        \
  |  |   45|   601k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1956|   601k|            MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&V2, 1));
  ------------------
  |  |   41|   601k|    do                           \
  |  |   42|   601k|    {                            \
  |  |   43|   601k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 601k]
  |  |  ------------------
  |  |   44|   601k|        goto cleanup;        \
  |  |   45|   601k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1957|   601k|        }
 1958|       |
 1959|   611k|        if (mbedtls_mpi_cmp_mpi(&TU, &TV) >= 0) {
  ------------------
  |  Branch (1959:13): [True: 313k, False: 298k]
  ------------------
 1960|   313k|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&TU, &TU, &TV));
  ------------------
  |  |   41|   313k|    do                           \
  |  |   42|   313k|    {                            \
  |  |   43|   313k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 313k]
  |  |  ------------------
  |  |   44|   313k|        goto cleanup;        \
  |  |   45|   313k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1961|   313k|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&U1, &U1, &V1));
  ------------------
  |  |   41|   313k|    do                           \
  |  |   42|   313k|    {                            \
  |  |   43|   313k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 313k]
  |  |  ------------------
  |  |   44|   313k|        goto cleanup;        \
  |  |   45|   313k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1962|   313k|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&U2, &U2, &V2));
  ------------------
  |  |   41|   313k|    do                           \
  |  |   42|   313k|    {                            \
  |  |   43|   313k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 313k]
  |  |  ------------------
  |  |   44|   313k|        goto cleanup;        \
  |  |   45|   313k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1963|   313k|        } else {
 1964|   298k|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&TV, &TV, &TU));
  ------------------
  |  |   41|   298k|    do                           \
  |  |   42|   298k|    {                            \
  |  |   43|   298k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 298k]
  |  |  ------------------
  |  |   44|   298k|        goto cleanup;        \
  |  |   45|   298k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1965|   298k|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&V1, &V1, &U1));
  ------------------
  |  |   41|   298k|    do                           \
  |  |   42|   298k|    {                            \
  |  |   43|   298k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 298k]
  |  |  ------------------
  |  |   44|   298k|        goto cleanup;        \
  |  |   45|   298k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1966|   298k|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&V2, &V2, &U2));
  ------------------
  |  |   41|   298k|    do                           \
  |  |   42|   298k|    {                            \
  |  |   43|   298k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 298k]
  |  |  ------------------
  |  |   44|   298k|        goto cleanup;        \
  |  |   45|   298k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1967|   298k|        }
 1968|   611k|    } while (mbedtls_mpi_cmp_int(&TU, 0) != 0);
  ------------------
  |  Branch (1968:14): [True: 608k, False: 3.38k]
  ------------------
 1969|       |
 1970|  3.66k|    while (mbedtls_mpi_cmp_int(&V1, 0) < 0) {
  ------------------
  |  Branch (1970:12): [True: 282, False: 3.38k]
  ------------------
 1971|    282|        MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&V1, &V1, N));
  ------------------
  |  |   41|    282|    do                           \
  |  |   42|    282|    {                            \
  |  |   43|    282|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 282]
  |  |  ------------------
  |  |   44|    282|        goto cleanup;        \
  |  |   45|    282|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1972|    282|    }
 1973|       |
 1974|  3.38k|    while (mbedtls_mpi_cmp_mpi(&V1, N) >= 0) {
  ------------------
  |  Branch (1974:12): [True: 0, False: 3.38k]
  ------------------
 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|  3.38k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(X, &V1));
  ------------------
  |  |   41|  3.38k|    do                           \
  |  |   42|  3.38k|    {                            \
  |  |   43|  3.38k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3.38k]
  |  |  ------------------
  |  |   44|  3.38k|        goto cleanup;        \
  |  |   45|  3.38k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1979|       |
 1980|  3.38k|cleanup:
 1981|       |
 1982|  3.38k|    mbedtls_mpi_free(&TA); mbedtls_mpi_free(&TU); mbedtls_mpi_free(&U1); mbedtls_mpi_free(&U2);
 1983|  3.38k|    mbedtls_mpi_free(&G); mbedtls_mpi_free(&TB); mbedtls_mpi_free(&TV);
 1984|  3.38k|    mbedtls_mpi_free(&V1); mbedtls_mpi_free(&V2);
 1985|       |
 1986|  3.38k|    return ret;
 1987|  3.38k|}
bignum.c:mbedtls_ct_mpi_sign_if:
   50|  1.61M|{
   51|  1.61M|    return (signed short) mbedtls_ct_uint_if(cond, sign1 + 1, sign2 + 1) - 1;
   52|  1.61M|}
bignum.c:mpi_sint_abs:
  359|  6.39M|{
  360|  6.39M|    if (z >= 0) {
  ------------------
  |  Branch (360:9): [True: 6.39M, False: 1.12k]
  ------------------
  361|  6.39M|        return z;
  362|  6.39M|    }
  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|  1.12k|    return (mbedtls_mpi_uint) 0 - (mbedtls_mpi_uint) z;
  368|  6.39M|}
bignum.c:mbedtls_mpi_resize_clear:
  285|  10.7k|{
  286|  10.7k|    if (limbs == 0) {
  ------------------
  |  Branch (286:9): [True: 0, False: 10.7k]
  ------------------
  287|      0|        mbedtls_mpi_free(X);
  288|      0|        return 0;
  289|  10.7k|    } else if (X->n == limbs) {
  ------------------
  |  Branch (289:16): [True: 0, False: 10.7k]
  ------------------
  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|  10.7k|    } else {
  294|  10.7k|        mbedtls_mpi_free(X);
  295|  10.7k|        return mbedtls_mpi_grow(X, limbs);
  296|  10.7k|    }
  297|  10.7k|}
bignum.c:add_sub_mpi:
 1115|  6.86M|{
 1116|  6.86M|    int ret, s;
 1117|       |
 1118|  6.86M|    s = A->s;
 1119|  6.86M|    if (A->s * B->s * flip_B < 0) {
  ------------------
  |  Branch (1119:9): [True: 5.49M, False: 1.37M]
  ------------------
 1120|  5.49M|        int cmp = mbedtls_mpi_cmp_abs(A, B);
 1121|  5.49M|        if (cmp >= 0) {
  ------------------
  |  Branch (1121:13): [True: 2.21M, False: 3.27M]
  ------------------
 1122|  2.21M|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs(X, A, B));
  ------------------
  |  |   41|  2.21M|    do                           \
  |  |   42|  2.21M|    {                            \
  |  |   43|  2.21M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.21M]
  |  |  ------------------
  |  |   44|  2.21M|        goto cleanup;        \
  |  |   45|  2.21M|    } 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|  2.21M|            X->s = cmp == 0 ? 1 : s;
  ------------------
  |  Branch (1126:20): [True: 7.89k, False: 2.20M]
  ------------------
 1127|  3.27M|        } else {
 1128|  3.27M|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs(X, B, A));
  ------------------
  |  |   41|  3.27M|    do                           \
  |  |   42|  3.27M|    {                            \
  |  |   43|  3.27M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3.27M]
  |  |  ------------------
  |  |   44|  3.27M|        goto cleanup;        \
  |  |   45|  3.27M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1129|       |            /* Since |A| < |B|, the sign is the opposite of A. */
 1130|  3.27M|            X->s = -s;
 1131|  3.27M|        }
 1132|  5.49M|    } else {
 1133|  1.37M|        MBEDTLS_MPI_CHK(mbedtls_mpi_add_abs(X, A, B));
  ------------------
  |  |   41|  1.37M|    do                           \
  |  |   42|  1.37M|    {                            \
  |  |   43|  1.37M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.37M]
  |  |  ------------------
  |  |   44|  1.37M|        goto cleanup;        \
  |  |   45|  1.37M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1134|  1.37M|        X->s = s;
 1135|  1.37M|    }
 1136|       |
 1137|  6.86M|cleanup:
 1138|       |
 1139|  6.86M|    return ret;
 1140|  6.86M|}
bignum.c:mbedtls_int_div_int:
 1294|  4.51k|{
 1295|  4.51k|#if defined(MBEDTLS_HAVE_UDBL)
 1296|  4.51k|    mbedtls_t_udbl dividend, quotient;
 1297|       |#else
 1298|       |    const mbedtls_mpi_uint radix = (mbedtls_mpi_uint) 1 << biH;
 1299|       |    const mbedtls_mpi_uint uint_halfword_mask = ((mbedtls_mpi_uint) 1 << biH) - 1;
 1300|       |    mbedtls_mpi_uint d0, d1, q0, q1, rAX, r0, quotient;
 1301|       |    mbedtls_mpi_uint u0_msw, u0_lsw;
 1302|       |    size_t s;
 1303|       |#endif
 1304|       |
 1305|       |    /*
 1306|       |     * Check for overflow
 1307|       |     */
 1308|  4.51k|    if (0 == d || u1 >= d) {
  ------------------
  |  Branch (1308:9): [True: 0, False: 4.51k]
  |  Branch (1308:19): [True: 0, False: 4.51k]
  ------------------
 1309|      0|        if (r != NULL) {
  ------------------
  |  Branch (1309:13): [True: 0, False: 0]
  ------------------
 1310|      0|            *r = ~(mbedtls_mpi_uint) 0u;
 1311|      0|        }
 1312|       |
 1313|      0|        return ~(mbedtls_mpi_uint) 0u;
 1314|      0|    }
 1315|       |
 1316|  4.51k|#if defined(MBEDTLS_HAVE_UDBL)
 1317|  4.51k|    dividend  = (mbedtls_t_udbl) u1 << biL;
  ------------------
  |  |   80|  4.51k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  4.51k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
 1318|  4.51k|    dividend |= (mbedtls_t_udbl) u0;
 1319|  4.51k|    quotient = dividend / d;
 1320|  4.51k|    if (quotient > ((mbedtls_t_udbl) 1 << biL) - 1) {
  ------------------
  |  |   80|  4.51k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  4.51k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  |  Branch (1320:9): [True: 0, False: 4.51k]
  ------------------
 1321|      0|        quotient = ((mbedtls_t_udbl) 1 << biL) - 1;
  ------------------
  |  |   80|      0|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|      0|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
 1322|      0|    }
 1323|       |
 1324|  4.51k|    if (r != NULL) {
  ------------------
  |  Branch (1324:9): [True: 0, False: 4.51k]
  ------------------
 1325|      0|        *r = (mbedtls_mpi_uint) (dividend - (quotient * d));
 1326|      0|    }
 1327|       |
 1328|  4.51k|    return (mbedtls_mpi_uint) quotient;
 1329|       |#else
 1330|       |
 1331|       |    /*
 1332|       |     * Algorithm D, Section 4.3.1 - The Art of Computer Programming
 1333|       |     *   Vol. 2 - Seminumerical Algorithms, Knuth
 1334|       |     */
 1335|       |
 1336|       |    /*
 1337|       |     * Normalize the divisor, d, and dividend, u0, u1
 1338|       |     */
 1339|       |    s = mbedtls_mpi_core_clz(d);
 1340|       |    d = d << s;
 1341|       |
 1342|       |    u1 = u1 << s;
 1343|       |    u1 |= (u0 >> (biL - s)) & (-(mbedtls_mpi_sint) s >> (biL - 1));
 1344|       |    u0 =  u0 << s;
 1345|       |
 1346|       |    d1 = d >> biH;
 1347|       |    d0 = d & uint_halfword_mask;
 1348|       |
 1349|       |    u0_msw = u0 >> biH;
 1350|       |    u0_lsw = u0 & uint_halfword_mask;
 1351|       |
 1352|       |    /*
 1353|       |     * Find the first quotient and remainder
 1354|       |     */
 1355|       |    q1 = u1 / d1;
 1356|       |    r0 = u1 - d1 * q1;
 1357|       |
 1358|       |    while (q1 >= radix || (q1 * d0 > radix * r0 + u0_msw)) {
 1359|       |        q1 -= 1;
 1360|       |        r0 += d1;
 1361|       |
 1362|       |        if (r0 >= radix) {
 1363|       |            break;
 1364|       |        }
 1365|       |    }
 1366|       |
 1367|       |    rAX = (u1 * radix) + (u0_msw - q1 * d);
 1368|       |    q0 = rAX / d1;
 1369|       |    r0 = rAX - q0 * d1;
 1370|       |
 1371|       |    while (q0 >= radix || (q0 * d0 > radix * r0 + u0_lsw)) {
 1372|       |        q0 -= 1;
 1373|       |        r0 += d1;
 1374|       |
 1375|       |        if (r0 >= radix) {
 1376|       |            break;
 1377|       |        }
 1378|       |    }
 1379|       |
 1380|       |    if (r != NULL) {
 1381|       |        *r = (rAX * radix + u0_lsw - q0 * d) >> s;
 1382|       |    }
 1383|       |
 1384|       |    quotient = q1 * radix + q0;
 1385|       |
 1386|       |    return quotient;
 1387|       |#endif
 1388|  4.51k|}

mbedtls_mpi_core_clz:
   25|  3.01M|{
   26|  3.01M|#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|  3.01M|#endif
   35|  3.01M|#if defined(core_clz)
   36|  3.01M|    return (size_t) core_clz(a);
  ------------------
  |  |   30|  3.01M|    #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|  3.01M|}
mbedtls_mpi_core_bitlen:
   54|  3.01M|{
   55|  3.01M|    int i;
   56|  3.01M|    size_t j;
   57|       |
   58|  9.09M|    for (i = ((int) A_limbs) - 1; i >= 0; i--) {
  ------------------
  |  Branch (58:35): [True: 9.09M, False: 0]
  ------------------
   59|  9.09M|        if (A[i] != 0) {
  ------------------
  |  Branch (59:13): [True: 3.01M, False: 6.08M]
  ------------------
   60|  3.01M|            j = biL - mbedtls_mpi_core_clz(A[i]);
  ------------------
  |  |   80|  3.01M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  3.01M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
   61|  3.01M|            return (i * biL) + j;
  ------------------
  |  |   80|  3.01M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  3.01M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
   62|  3.01M|        }
   63|  9.09M|    }
   64|       |
   65|      0|    return 0;
   66|  3.01M|}
mbedtls_mpi_core_bigendian_to_host:
   84|  10.7k|{
   85|  10.7k|    mbedtls_mpi_uint *cur_limb_left;
   86|  10.7k|    mbedtls_mpi_uint *cur_limb_right;
   87|  10.7k|    if (A_limbs == 0) {
  ------------------
  |  Branch (87:9): [True: 0, False: 10.7k]
  ------------------
   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|  10.7k|    for (cur_limb_left = A, cur_limb_right = A + (A_limbs - 1);
  101|  32.7k|         cur_limb_left <= cur_limb_right;
  ------------------
  |  Branch (101:10): [True: 21.9k, False: 10.7k]
  ------------------
  102|  21.9k|         cur_limb_left++, cur_limb_right--) {
  103|  21.9k|        mbedtls_mpi_uint tmp;
  104|       |        /* Note that if cur_limb_left == cur_limb_right,
  105|       |         * this code effectively swaps the bytes only once. */
  106|  21.9k|        tmp             = mpi_bigendian_to_host(*cur_limb_left);
  107|  21.9k|        *cur_limb_left  = mpi_bigendian_to_host(*cur_limb_right);
  108|  21.9k|        *cur_limb_right = tmp;
  109|  21.9k|    }
  110|  10.7k|}
mbedtls_mpi_core_cond_assign:
  172|  1.61M|{
  173|  1.61M|    if (X == A) {
  ------------------
  |  Branch (173:9): [True: 0, False: 1.61M]
  ------------------
  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|  8.05M|    for (size_t i = 0; i < limbs; i++) {
  ------------------
  |  Branch (182:24): [True: 6.44M, False: 1.61M]
  ------------------
  183|  6.44M|        X[i] = mbedtls_ct_mpi_uint_if(assign, A[i], X[i]);
  184|  6.44M|    }
  185|  1.61M|}
mbedtls_mpi_core_read_be:
  230|  10.7k|{
  231|  10.7k|    const size_t limbs = CHARS_TO_LIMBS(input_length);
  ------------------
  |  |   88|  10.7k|#define CHARS_TO_LIMBS(i) ((i) / ciL + ((i) % ciL != 0))
  |  |  ------------------
  |  |  |  |   79|  10.7k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  |  |               #define CHARS_TO_LIMBS(i) ((i) / ciL + ((i) % ciL != 0))
  |  |  ------------------
  |  |  |  |   79|  10.7k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  232|       |
  233|  10.7k|    if (X_limbs < limbs) {
  ------------------
  |  Branch (233:9): [True: 0, False: 10.7k]
  ------------------
  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|  10.7k|    if (X_limbs == 0) {
  ------------------
  |  Branch (239:9): [True: 0, False: 10.7k]
  ------------------
  240|      0|        return 0;
  241|      0|    }
  242|       |
  243|  10.7k|    memset(X, 0, X_limbs * ciL);
  ------------------
  |  |   79|  10.7k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  244|       |
  245|       |    /* memcpy() with (NULL, 0) is undefined behaviour */
  246|  10.7k|    if (input_length != 0) {
  ------------------
  |  Branch (246:9): [True: 10.7k, False: 0]
  ------------------
  247|  10.7k|        size_t overhead = (X_limbs * ciL) - input_length;
  ------------------
  |  |   79|  10.7k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  248|  10.7k|        unsigned char *Xp = (unsigned char *) X;
  249|  10.7k|        memcpy(Xp + overhead, input, input_length);
  250|  10.7k|    }
  251|       |
  252|  10.7k|    mbedtls_mpi_core_bigendian_to_host(X, X_limbs);
  253|       |
  254|  10.7k|    return 0;
  255|  10.7k|}
mbedtls_mpi_core_shift_r:
  332|  5.48M|{
  333|  5.48M|    size_t i, v0, v1;
  334|  5.48M|    mbedtls_mpi_uint r0 = 0, r1;
  335|       |
  336|  5.48M|    v0 = count /  biL;
  ------------------
  |  |   80|  5.48M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  5.48M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  337|  5.48M|    v1 = count & (biL - 1);
  ------------------
  |  |   80|  5.48M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  5.48M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  338|       |
  339|  5.48M|    if (v0 > limbs || (v0 == limbs && v1 > 0)) {
  ------------------
  |  Branch (339:9): [True: 0, False: 5.48M]
  |  Branch (339:24): [True: 0, False: 5.48M]
  |  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|  5.48M|    if (v0 > 0) {
  ------------------
  |  Branch (347:9): [True: 1.12k, False: 5.48M]
  ------------------
  348|  6.76k|        for (i = 0; i < limbs - v0; i++) {
  ------------------
  |  Branch (348:21): [True: 5.64k, False: 1.12k]
  ------------------
  349|  5.64k|            X[i] = X[i + v0];
  350|  5.64k|        }
  351|       |
  352|  5.64k|        for (; i < limbs; i++) {
  ------------------
  |  Branch (352:16): [True: 4.51k, False: 1.12k]
  ------------------
  353|  4.51k|            X[i] = 0;
  354|  4.51k|        }
  355|  1.12k|    }
  356|       |
  357|       |    /*
  358|       |     * shift by count % limb_size
  359|       |     */
  360|  5.48M|    if (v1 > 0) {
  ------------------
  |  Branch (360:9): [True: 4.57M, False: 918k]
  ------------------
  361|  24.6M|        for (i = limbs; i > 0; i--) {
  ------------------
  |  Branch (361:25): [True: 20.0M, False: 4.57M]
  ------------------
  362|  20.0M|            r1 = X[i - 1] << (biL - v1);
  ------------------
  |  |   80|  20.0M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  20.0M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  363|  20.0M|            X[i - 1] >>= v1;
  364|  20.0M|            X[i - 1] |= r0;
  365|  20.0M|            r0 = r1;
  366|  20.0M|        }
  367|  4.57M|    }
  368|  5.48M|}
mbedtls_mpi_core_shift_l:
  372|   776k|{
  373|   776k|    size_t i, v0, v1;
  374|   776k|    mbedtls_mpi_uint r0 = 0, r1;
  375|       |
  376|   776k|    v0 = count / (biL);
  ------------------
  |  |   80|   776k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|   776k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  377|   776k|    v1 = count & (biL - 1);
  ------------------
  |  |   80|   776k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|   776k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  378|       |
  379|       |    /*
  380|       |     * shift by count / limb_size
  381|       |     */
  382|   776k|    if (v0 > 0) {
  ------------------
  |  Branch (382:9): [True: 4.51k, False: 771k]
  ------------------
  383|  37.2k|        for (i = limbs; i > v0; i--) {
  ------------------
  |  Branch (383:25): [True: 32.7k, False: 4.51k]
  ------------------
  384|  32.7k|            X[i - 1] = X[i - v0 - 1];
  385|  32.7k|        }
  386|       |
  387|  15.7k|        for (; i > 0; i--) {
  ------------------
  |  Branch (387:16): [True: 11.2k, False: 4.51k]
  ------------------
  388|  11.2k|            X[i - 1] = 0;
  389|  11.2k|        }
  390|  4.51k|    }
  391|       |
  392|       |    /*
  393|       |     * shift by count % limb_size
  394|       |     */
  395|   776k|    if (v1 > 0) {
  ------------------
  |  Branch (395:9): [True: 767k, False: 9.02k]
  ------------------
  396|  7.66M|        for (i = v0; i < limbs; i++) {
  ------------------
  |  Branch (396:22): [True: 6.89M, False: 767k]
  ------------------
  397|  6.89M|            r1 = X[i] >> (biL - v1);
  ------------------
  |  |   80|  6.89M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  6.89M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  398|  6.89M|            X[i] <<= v1;
  399|  6.89M|            X[i] |= r0;
  400|  6.89M|            r0 = r1;
  401|  6.89M|        }
  402|   767k|    }
  403|   776k|}
mbedtls_mpi_core_add:
  409|  1.37M|{
  410|  1.37M|    mbedtls_mpi_uint c = 0;
  411|       |
  412|  6.87M|    for (size_t i = 0; i < limbs; i++) {
  ------------------
  |  Branch (412:24): [True: 5.49M, False: 1.37M]
  ------------------
  413|  5.49M|        mbedtls_mpi_uint t = c + A[i];
  414|  5.49M|        c = (t < A[i]);
  415|  5.49M|        t += B[i];
  416|  5.49M|        c += (t < B[i]);
  417|  5.49M|        X[i] = t;
  418|  5.49M|    }
  419|       |
  420|  1.37M|    return c;
  421|  1.37M|}
mbedtls_mpi_core_sub:
  448|  7.13M|{
  449|  7.13M|    mbedtls_mpi_uint c = 0;
  450|       |
  451|  33.7M|    for (size_t i = 0; i < limbs; i++) {
  ------------------
  |  Branch (451:24): [True: 26.6M, False: 7.13M]
  ------------------
  452|  26.6M|        mbedtls_mpi_uint z = (A[i] < c);
  453|  26.6M|        mbedtls_mpi_uint t = A[i] - c;
  454|  26.6M|        c = (t < B[i]) + z;
  455|  26.6M|        X[i] = t - B[i];
  456|  26.6M|    }
  457|       |
  458|  7.13M|    return c;
  459|  7.13M|}
mbedtls_mpi_core_mla:
  464|  9.04M|{
  465|  9.04M|    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|  9.04M|    if (d_len < s_len) {
  ------------------
  |  Branch (471:9): [True: 0, False: 9.04M]
  ------------------
  472|      0|        s_len = d_len;
  473|      0|    }
  474|  9.04M|    size_t excess_len = d_len - s_len;
  475|  9.04M|    size_t steps_x8 = s_len / 8;
  476|  9.04M|    size_t steps_x1 = s_len & 7;
  477|       |
  478|  9.04M|    while (steps_x8--) {
  ------------------
  |  Branch (478:12): [True: 0, False: 9.04M]
  ------------------
  479|      0|        MULADDC_X8_INIT
  ------------------
  |  | 1088|      0|#define MULADDC_X8_INIT MULADDC_X4_INIT
  |  |  ------------------
  |  |  |  | 1082|      0|#define MULADDC_X4_INIT MULADDC_X2_INIT
  |  |  |  |  ------------------
  |  |  |  |  |  | 1076|      0|#define MULADDC_X2_INIT MULADDC_X1_INIT
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  216|      0|    asm(                                    \
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  321|      0|#define asm __asm__
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  217|      0|        "xorq   %%r8, %%r8\n"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  480|      0|        MULADDC_X8_CORE
  481|      0|            MULADDC_X8_STOP
  ------------------
  |  | 1089|      0|#define MULADDC_X8_STOP MULADDC_X4_STOP
  |  |  ------------------
  |  |  |  | 1083|      0|#define MULADDC_X4_STOP MULADDC_X2_STOP
  |  |  |  |  ------------------
  |  |  |  |  |  | 1077|      0|#define MULADDC_X2_STOP MULADDC_X1_STOP
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  232|      0|        : "+c" (c), "+D" (d), "+S" (s), "+m" (*(uint64_t (*)[16]) d) \
  |  |  |  |  |  |  |  |  233|      0|        : "b" (b), "m" (*(const uint64_t (*)[16]) s)                 \
  |  |  |  |  |  |  |  |  234|      0|        : "rax", "rdx", "r8"                                         \
  |  |  |  |  |  |  |  |  235|      0|    );
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  482|      0|    }
  483|       |
  484|  45.0M|    while (steps_x1--) {
  ------------------
  |  Branch (484:12): [True: 36.0M, False: 9.04M]
  ------------------
  485|  36.0M|        MULADDC_X1_INIT
  ------------------
  |  |  216|  36.0M|    asm(                                    \
  |  |  ------------------
  |  |  |  |  321|  36.0M|#define asm __asm__
  |  |  ------------------
  |  |  217|  36.0M|        "xorq   %%r8, %%r8\n"
  ------------------
  486|  36.0M|        MULADDC_X1_CORE
  487|  36.0M|            MULADDC_X1_STOP
  ------------------
  |  |  232|  36.0M|        : "+c" (c), "+D" (d), "+S" (s), "+m" (*(uint64_t (*)[16]) d) \
  |  |  233|  36.0M|        : "b" (b), "m" (*(const uint64_t (*)[16]) s)                 \
  |  |  234|  36.0M|        : "rax", "rdx", "r8"                                         \
  |  |  235|  36.0M|    );
  ------------------
  488|  36.0M|    }
  489|       |
  490|  18.4M|    while (excess_len--) {
  ------------------
  |  Branch (490:12): [True: 9.36M, False: 9.04M]
  ------------------
  491|  9.36M|        *d += c;
  492|  9.36M|        c = (*d < c);
  493|  9.36M|        d++;
  494|  9.36M|    }
  495|       |
  496|  9.04M|    return c;
  497|  9.04M|}
mbedtls_mpi_core_mul:
  502|  2.21M|{
  503|  2.21M|    memset(X, 0, (A_limbs + B_limbs) * ciL);
  ------------------
  |  |   79|  2.21M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  504|       |
  505|  11.0M|    for (size_t i = 0; i < B_limbs; i++) {
  ------------------
  |  Branch (505:24): [True: 8.85M, False: 2.21M]
  ------------------
  506|  8.85M|        (void) mbedtls_mpi_core_mla(X + i, A_limbs + 1, A, A_limbs, B[i]);
  507|  8.85M|    }
  508|  2.21M|}
mbedtls_mpi_core_sub_int:
  973|  1.58M|{
  974|  8.94M|    for (size_t i = 0; i < limbs; i++) {
  ------------------
  |  Branch (974:24): [True: 7.35M, False: 1.58M]
  ------------------
  975|  7.35M|        mbedtls_mpi_uint s = A[i];
  976|  7.35M|        mbedtls_mpi_uint t = s - c;
  977|  7.35M|        c = (t > s);
  978|  7.35M|        X[i] = t;
  979|  7.35M|    }
  980|       |
  981|  1.58M|    return c;
  982|  1.58M|}
bignum_core.c:mpi_bigendian_to_host:
   69|  43.9k|{
   70|  43.9k|    if (MBEDTLS_IS_BIG_ENDIAN) {
  ------------------
  |  |  398|  43.9k|#define MBEDTLS_IS_BIG_ENDIAN 0
  |  |  ------------------
  |  |  |  Branch (398:31): [Folded - Ignored]
  |  |  ------------------
  ------------------
   71|       |        /* Nothing to do on bigendian systems. */
   72|      0|        return a;
   73|  43.9k|    } else {
   74|       |#if defined(MBEDTLS_HAVE_INT32)
   75|       |        return (mbedtls_mpi_uint) MBEDTLS_BSWAP32(a);
   76|       |#elif defined(MBEDTLS_HAVE_INT64)
   77|  43.9k|        return (mbedtls_mpi_uint) MBEDTLS_BSWAP64(a);
  ------------------
  |  |  301|  43.9k|#define MBEDTLS_BSWAP64 __builtin_bswap64
  ------------------
   78|  43.9k|#endif
   79|  43.9k|    }
   80|  43.9k|}

md.c:mbedtls_xor:
  190|    564|{
  191|    564|    size_t i = 0;
  192|    564|#if defined(MBEDTLS_EFFICIENT_UNALIGNED_ACCESS)
  193|       |#if defined(MBEDTLS_HAVE_NEON_INTRINSICS) && \
  194|       |    (!(defined(MBEDTLS_COMPILER_IS_GCC) && MBEDTLS_GCC_VERSION < 70300))
  195|       |    /* Old GCC versions generate a warning here, so disable the NEON path for these compilers */
  196|       |    for (; (i + 16) <= n; i += 16) {
  197|       |        uint8x16_t v1 = vld1q_u8(a + i);
  198|       |        uint8x16_t v2 = vld1q_u8(b + i);
  199|       |        uint8x16_t x = veorq_u8(v1, v2);
  200|       |        vst1q_u8(r + i, x);
  201|       |    }
  202|       |#if defined(__IAR_SYSTEMS_ICC__)
  203|       |    /* This if statement helps some compilers (e.g., IAR) optimise out the byte-by-byte tail case
  204|       |     * where n is a constant multiple of 16.
  205|       |     * For other compilers (e.g. recent gcc and clang) it makes no difference if n is a compile-time
  206|       |     * constant, and is a very small perf regression if n is not a compile-time constant. */
  207|       |    if (n % 16 == 0) {
  208|       |        return;
  209|       |    }
  210|       |#endif
  211|       |#elif defined(MBEDTLS_ARCH_IS_X64) || defined(MBEDTLS_ARCH_IS_ARM64)
  212|       |    /* This codepath probably only makes sense on architectures with 64-bit registers */
  213|  2.82k|    for (; (i + 8) <= n; i += 8) {
  ------------------
  |  Branch (213:12): [True: 2.25k, False: 564]
  ------------------
  214|  2.25k|        uint64_t x = mbedtls_get_unaligned_uint64(a + i) ^ mbedtls_get_unaligned_uint64(b + i);
  215|  2.25k|        mbedtls_put_unaligned_uint64(r + i, x);
  216|  2.25k|    }
  217|       |#if defined(__IAR_SYSTEMS_ICC__)
  218|       |    if (n % 8 == 0) {
  219|       |        return;
  220|       |    }
  221|       |#endif
  222|       |#else
  223|       |    for (; (i + 4) <= n; i += 4) {
  224|       |        uint32_t x = mbedtls_get_unaligned_uint32(a + i) ^ mbedtls_get_unaligned_uint32(b + i);
  225|       |        mbedtls_put_unaligned_uint32(r + i, x);
  226|       |    }
  227|       |#if defined(__IAR_SYSTEMS_ICC__)
  228|       |    if (n % 4 == 0) {
  229|       |        return;
  230|       |    }
  231|       |#endif
  232|       |#endif
  233|    564|#endif
  234|    564|    for (; i < n; i++) {
  ------------------
  |  Branch (234:12): [True: 0, False: 564]
  ------------------
  235|      0|        r[i] = a[i] ^ b[i];
  236|      0|    }
  237|    564|}

bignum.c:mbedtls_ct_bool:
  136|  1.61M|{
  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|  1.61M|    asm volatile ("mov  %[x], %[s]                                \n\t"
  ------------------
  |  |  321|  1.61M|#define asm __asm__
  ------------------
  175|  1.61M|                  "neg  %[s]                                      \n\t"
  176|  1.61M|                  "or   %[x], %[s]                                \n\t"
  177|  1.61M|                  "sar  $63, %[s]                                 \n\t"
  178|  1.61M|                  :
  179|  1.61M|                  [s] "=&a" (s)
  180|  1.61M|                  :
  181|  1.61M|                  [x] "D" (x)
  182|  1.61M|                  :
  183|  1.61M|                  );
  184|  1.61M|    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|  1.61M|}
bignum.c:mbedtls_ct_bool_not:
  547|  1.61M|{
  548|  1.61M|    return (mbedtls_ct_condition_t) (~x);
  549|  1.61M|}
bignum.c:mbedtls_ct_uint_if:
  436|  1.61M|{
  437|  1.61M|    return (unsigned) mbedtls_ct_if(condition, (mbedtls_ct_uint_t) if1, (mbedtls_ct_uint_t) if0);
  438|  1.61M|}
bignum.c:mbedtls_ct_if:
  223|  1.61M|{
  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|  1.61M|    asm volatile ("and  %[condition], %[if1]                      \n\t"
  ------------------
  |  |  321|  1.61M|#define asm __asm__
  ------------------
  255|  1.61M|                  "not  %[condition]                              \n\t"
  256|  1.61M|                  "and  %[condition], %[if0]                      \n\t"
  257|  1.61M|                  "or   %[if1], %[if0]                            \n\t"
  258|  1.61M|                  :
  259|  1.61M|                  [condition] "+&D" (condition),
  260|  1.61M|                  [if1] "+&S" (if1),
  261|  1.61M|                  [if0] "+&a" (if0)
  262|  1.61M|                  :
  263|  1.61M|                  :
  264|  1.61M|                  );
  265|  1.61M|    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|  1.61M|}
bignum.c:mbedtls_ct_mpi_uint_if_else_0:
  481|  5.64k|{
  482|  5.64k|    return (mbedtls_mpi_uint) (condition & if1);
  483|  5.64k|}
bignum_core.c:mbedtls_ct_mpi_uint_if:
  453|  6.44M|{
  454|  6.44M|    return (mbedtls_mpi_uint) mbedtls_ct_if(condition,
  455|  6.44M|                                            (mbedtls_ct_uint_t) if1,
  456|  6.44M|                                            (mbedtls_ct_uint_t) if0);
  457|  6.44M|}
bignum_core.c:mbedtls_ct_if:
  223|  6.44M|{
  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.44M|    asm volatile ("and  %[condition], %[if1]                      \n\t"
  ------------------
  |  |  321|  6.44M|#define asm __asm__
  ------------------
  255|  6.44M|                  "not  %[condition]                              \n\t"
  256|  6.44M|                  "and  %[condition], %[if0]                      \n\t"
  257|  6.44M|                  "or   %[if1], %[if0]                            \n\t"
  258|  6.44M|                  :
  259|  6.44M|                  [condition] "+&D" (condition),
  260|  6.44M|                  [if1] "+&S" (if1),
  261|  6.44M|                  [if0] "+&a" (if0)
  262|  6.44M|                  :
  263|  6.44M|                  :
  264|  6.44M|                  );
  265|  6.44M|    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.44M|}

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

mbedtls_ecdsa_can_do:
  226|    564|{
  227|    564|    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: 564]
  ------------------
  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: 564]
  ------------------
  233|      0|#endif
  234|    564|        default: return 1;
  ------------------
  |  Branch (234:9): [True: 564, False: 0]
  ------------------
  235|    564|    }
  236|    564|}
mbedtls_ecdsa_verify_restartable:
  494|    564|{
  495|    564|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|    564|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  496|    564|    mbedtls_mpi e, s_inv, u1, u2;
  497|    564|    mbedtls_ecp_point R;
  498|    564|    mbedtls_mpi *pu1 = &u1, *pu2 = &u2;
  499|       |
  500|    564|    mbedtls_ecp_point_init(&R);
  501|    564|    mbedtls_mpi_init(&e); mbedtls_mpi_init(&s_inv);
  502|    564|    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|    564|    if (!mbedtls_ecdsa_can_do(grp->id) || grp->N.p == NULL) {
  ------------------
  |  Branch (505:9): [True: 0, False: 564]
  |  Branch (505:43): [True: 0, False: 564]
  ------------------
  506|      0|        return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
  507|      0|    }
  508|       |
  509|    564|    ECDSA_RS_ENTER(ver);
  ------------------
  |  |  153|    564|#define ECDSA_RS_ENTER(SUB)   do {                                 \
  |  |  154|    564|        /* reset ops count for this call if top-level */                 \
  |  |  155|    564|        if (rs_ctx != NULL && rs_ctx->ecp.depth++ == 0)                 \
  |  |  ------------------
  |  |  |  Branch (155:13): [True: 0, False: 564]
  |  |  |  Branch (155:31): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|    564|        rs_ctx->ecp.ops_done = 0;                                    \
  |  |  157|    564|                                                                     \
  |  |  158|    564|        /* set up our own sub-context if needed */                       \
  |  |  159|    564|        if (mbedtls_ecp_restart_is_enabled() &&                          \
  |  |  ------------------
  |  |  |  Branch (159:13): [True: 0, False: 564]
  |  |  ------------------
  |  |  160|    564|            rs_ctx != NULL && rs_ctx->SUB == NULL)                      \
  |  |  ------------------
  |  |  |  Branch (160:13): [True: 0, False: 0]
  |  |  |  Branch (160:31): [True: 0, False: 0]
  |  |  ------------------
  |  |  161|    564|        {                                                                \
  |  |  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|    564|} while (0)
  |  |  ------------------
  |  |  |  Branch (168:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
  510|       |
  511|    564|#if defined(MBEDTLS_ECP_RESTARTABLE)
  512|    564|    if (rs_ctx != NULL && rs_ctx->ver != NULL) {
  ------------------
  |  Branch (512:9): [True: 0, False: 564]
  |  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|    564|#endif /* MBEDTLS_ECP_RESTARTABLE */
  523|       |
  524|       |    /*
  525|       |     * Step 1: make sure r and s are in range 1..n-1
  526|       |     */
  527|    564|    if (mbedtls_mpi_cmp_int(r, 1) < 0 || mbedtls_mpi_cmp_mpi(r, &grp->N) >= 0 ||
  ------------------
  |  Branch (527:9): [True: 0, False: 564]
  |  Branch (527:42): [True: 0, False: 564]
  ------------------
  528|    564|        mbedtls_mpi_cmp_int(s, 1) < 0 || mbedtls_mpi_cmp_mpi(s, &grp->N) >= 0) {
  ------------------
  |  Branch (528:9): [True: 0, False: 564]
  |  Branch (528:42): [True: 0, False: 564]
  ------------------
  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|    564|    MBEDTLS_MPI_CHK(derive_mpi(grp, &e, buf, blen));
  ------------------
  |  |   41|    564|    do                           \
  |  |   42|    564|    {                            \
  |  |   43|    564|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 564]
  |  |  ------------------
  |  |   44|    564|        goto cleanup;        \
  |  |   45|    564|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  537|       |
  538|       |    /*
  539|       |     * Step 4: u1 = e / s mod n, u2 = r / s mod n
  540|       |     */
  541|    564|    ECDSA_BUDGET(MBEDTLS_ECP_OPS_CHK + MBEDTLS_ECP_OPS_INV + 2);
  ------------------
  |  |  150|    564|    MBEDTLS_MPI_CHK(mbedtls_ecp_check_budget(grp, ECDSA_RS_ECP, ops));
  |  |  ------------------
  |  |  |  |   41|    564|    do                           \
  |  |  |  |   42|    564|    {                            \
  |  |  |  |   43|  1.12k|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 564]
  |  |  |  |  |  Branch (43:21): [True: 564, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   44|    564|        goto cleanup;        \
  |  |  |  |   45|    564|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  542|       |
  543|    564|    MBEDTLS_MPI_CHK(mbedtls_mpi_inv_mod(&s_inv, s, &grp->N));
  ------------------
  |  |   41|    564|    do                           \
  |  |   42|    564|    {                            \
  |  |   43|    564|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 564]
  |  |  ------------------
  |  |   44|    564|        goto cleanup;        \
  |  |   45|    564|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  544|       |
  545|    564|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(pu1, &e, &s_inv));
  ------------------
  |  |   41|    564|    do                           \
  |  |   42|    564|    {                            \
  |  |   43|    564|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 564]
  |  |  ------------------
  |  |   44|    564|        goto cleanup;        \
  |  |   45|    564|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  546|    564|    MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(pu1, pu1, &grp->N));
  ------------------
  |  |   41|    564|    do                           \
  |  |   42|    564|    {                            \
  |  |   43|    564|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 564]
  |  |  ------------------
  |  |   44|    564|        goto cleanup;        \
  |  |   45|    564|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  547|       |
  548|    564|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(pu2, r, &s_inv));
  ------------------
  |  |   41|    564|    do                           \
  |  |   42|    564|    {                            \
  |  |   43|    564|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 564]
  |  |  ------------------
  |  |   44|    564|        goto cleanup;        \
  |  |   45|    564|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  549|    564|    MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(pu2, pu2, &grp->N));
  ------------------
  |  |   41|    564|    do                           \
  |  |   42|    564|    {                            \
  |  |   43|    564|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 564]
  |  |  ------------------
  |  |   44|    564|        goto cleanup;        \
  |  |   45|    564|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  550|       |
  551|    564|#if defined(MBEDTLS_ECP_RESTARTABLE)
  552|    564|    if (rs_ctx != NULL && rs_ctx->ver != NULL) {
  ------------------
  |  Branch (552:9): [True: 0, False: 564]
  |  Branch (552:27): [True: 0, False: 0]
  ------------------
  553|      0|        rs_ctx->ver->state = ecdsa_ver_muladd;
  554|      0|    }
  555|       |
  556|    564|muladd:
  557|    564|#endif
  558|       |    /*
  559|       |     * Step 5: R = u1 G + u2 Q
  560|       |     */
  561|    564|    MBEDTLS_MPI_CHK(mbedtls_ecp_muladd_restartable(grp,
  ------------------
  |  |   41|    564|    do                           \
  |  |   42|    564|    {                            \
  |  |   43|  1.12k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 564]
  |  |  |  Branch (43:21): [True: 564, False: 0]
  |  |  ------------------
  |  |   44|    564|        goto cleanup;        \
  |  |   45|    564|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  562|    564|                                                   &R, pu1, &grp->G, pu2, Q, ECDSA_RS_ECP));
  563|       |
  564|    564|    if (mbedtls_ecp_is_zero(&R)) {
  ------------------
  |  Branch (564:9): [True: 0, False: 564]
  ------------------
  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|    564|    MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&R.X, &R.X, &grp->N));
  ------------------
  |  |   41|    564|    do                           \
  |  |   42|    564|    {                            \
  |  |   43|    564|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 564]
  |  |  ------------------
  |  |   44|    564|        goto cleanup;        \
  |  |   45|    564|    } 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|    564|    if (mbedtls_mpi_cmp_mpi(&R.X, r) != 0) {
  ------------------
  |  Branch (578:9): [True: 0, False: 564]
  ------------------
  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|    564|cleanup:
  584|    564|    mbedtls_ecp_point_free(&R);
  585|    564|    mbedtls_mpi_free(&e); mbedtls_mpi_free(&s_inv);
  586|    564|    mbedtls_mpi_free(&u1); mbedtls_mpi_free(&u2);
  587|       |
  588|    564|    ECDSA_RS_LEAVE(ver);
  ------------------
  |  |  171|    564|#define ECDSA_RS_LEAVE(SUB)   do {                                 \
  |  |  172|    564|        /* clear our sub-context when not in progress (done or error) */ \
  |  |  173|    564|        if (rs_ctx != NULL && rs_ctx->SUB != NULL &&                     \
  |  |  ------------------
  |  |  |  Branch (173:13): [True: 0, False: 564]
  |  |  |  Branch (173:31): [True: 0, False: 0]
  |  |  ------------------
  |  |  174|    564|            ret != MBEDTLS_ERR_ECP_IN_PROGRESS)                         \
  |  |  ------------------
  |  |  |  |   51|      0|#define MBEDTLS_ERR_ECP_IN_PROGRESS                       -0x4B00
  |  |  ------------------
  |  |  |  Branch (174:13): [True: 0, False: 0]
  |  |  ------------------
  |  |  175|    564|        {                                                                \
  |  |  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|    564|                                                                     \
  |  |  181|    564|        if (rs_ctx != NULL)                                             \
  |  |  ------------------
  |  |  |  Branch (181:13): [True: 0, False: 564]
  |  |  ------------------
  |  |  182|    564|        rs_ctx->ecp.depth--;                                         \
  |  |  183|    564|} while (0)
  |  |  ------------------
  |  |  |  Branch (183:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
  589|       |
  590|    564|    return ret;
  591|    564|}
mbedtls_ecdsa_read_signature:
  706|    564|{
  707|    564|    return mbedtls_ecdsa_read_signature_restartable(
  708|    564|        ctx, hash, hlen, sig, slen, NULL);
  709|    564|}
mbedtls_ecdsa_read_signature_restartable:
  718|    564|{
  719|    564|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|    564|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  720|    564|    unsigned char *p = (unsigned char *) sig;
  721|    564|    const unsigned char *end = sig + slen;
  722|    564|    size_t len;
  723|    564|    mbedtls_mpi r, s;
  724|    564|    mbedtls_mpi_init(&r);
  725|    564|    mbedtls_mpi_init(&s);
  726|       |
  727|    564|    if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
  ------------------
  |  Branch (727:9): [True: 0, False: 564]
  ------------------
  728|    564|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|    564|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|    564|#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|    564|    if (p + len != end) {
  ------------------
  |  Branch (733:9): [True: 0, False: 564]
  ------------------
  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|    564|    if ((ret = mbedtls_asn1_get_mpi(&p, end, &r)) != 0 ||
  ------------------
  |  Branch (739:9): [True: 0, False: 564]
  ------------------
  740|    564|        (ret = mbedtls_asn1_get_mpi(&p, end, &s)) != 0) {
  ------------------
  |  Branch (740:9): [True: 0, False: 564]
  ------------------
  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|    564|    if ((ret = mbedtls_ecdsa_verify_restartable(&ctx->grp, hash, hlen,
  ------------------
  |  Branch (752:9): [True: 0, False: 564]
  ------------------
  753|    564|                                                &ctx->Q, &r, &s, rs_ctx)) != 0) {
  754|      0|        goto cleanup;
  755|      0|    }
  756|    564|#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|    564|    if (p != end) {
  ------------------
  |  Branch (761:9): [True: 0, False: 564]
  ------------------
  762|      0|        ret = MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH;
  ------------------
  |  |   49|      0|#define MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH                  -0x4C00
  ------------------
  763|      0|    }
  764|       |
  765|    564|cleanup:
  766|    564|    mbedtls_mpi_free(&r);
  767|    564|    mbedtls_mpi_free(&s);
  768|       |
  769|    564|    return ret;
  770|    564|}
ecdsa.c:derive_mpi:
  205|    564|{
  206|    564|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|    564|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  207|    564|    size_t n_size = (grp->nbits + 7) / 8;
  208|    564|    size_t use_size = blen > n_size ? n_size : blen;
  ------------------
  |  Branch (208:23): [True: 0, False: 564]
  ------------------
  209|       |
  210|    564|    MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(x, buf, use_size));
  ------------------
  |  |   41|    564|    do                           \
  |  |   42|    564|    {                            \
  |  |   43|    564|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 564]
  |  |  ------------------
  |  |   44|    564|        goto cleanup;        \
  |  |   45|    564|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  211|    564|    if (use_size * 8 > grp->nbits) {
  ------------------
  |  Branch (211:9): [True: 0, False: 564]
  ------------------
  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|    564|    if (mbedtls_mpi_cmp_mpi(x, &grp->N) >= 0) {
  ------------------
  |  Branch (216:9): [True: 0, False: 564]
  ------------------
  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|    564|cleanup:
  221|    564|    return ret;
  222|    564|}

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

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

mbedtls_hkdf_expand:
   66|    564|{
   67|    564|    size_t hash_len;
   68|    564|    size_t where = 0;
   69|    564|    size_t n;
   70|    564|    size_t t_len = 0;
   71|    564|    size_t i;
   72|    564|    int ret = 0;
   73|    564|    mbedtls_md_context_t ctx;
   74|    564|    unsigned char t[MBEDTLS_MD_MAX_SIZE];
   75|       |
   76|    564|    if (okm == NULL) {
  ------------------
  |  Branch (76:9): [True: 0, False: 564]
  ------------------
   77|      0|        return MBEDTLS_ERR_HKDF_BAD_INPUT_DATA;
  ------------------
  |  |   25|      0|#define MBEDTLS_ERR_HKDF_BAD_INPUT_DATA  -0x5F80
  ------------------
   78|      0|    }
   79|       |
   80|    564|    hash_len = mbedtls_md_get_size(md);
   81|       |
   82|    564|    if (prk_len < hash_len || hash_len == 0) {
  ------------------
  |  Branch (82:9): [True: 0, False: 564]
  |  Branch (82:31): [True: 0, False: 564]
  ------------------
   83|      0|        return MBEDTLS_ERR_HKDF_BAD_INPUT_DATA;
  ------------------
  |  |   25|      0|#define MBEDTLS_ERR_HKDF_BAD_INPUT_DATA  -0x5F80
  ------------------
   84|      0|    }
   85|       |
   86|    564|    if (info == NULL) {
  ------------------
  |  Branch (86:9): [True: 0, False: 564]
  ------------------
   87|      0|        info = (const unsigned char *) "";
   88|      0|        info_len = 0;
   89|      0|    }
   90|       |
   91|    564|    n = okm_len / hash_len;
   92|       |
   93|    564|    if (okm_len % hash_len != 0) {
  ------------------
  |  Branch (93:9): [True: 0, False: 564]
  ------------------
   94|      0|        n++;
   95|      0|    }
   96|       |
   97|       |    /*
   98|       |     * Per RFC 5869 Section 2.3, okm_len must not exceed
   99|       |     * 255 times the hash length
  100|       |     */
  101|    564|    if (n > 255) {
  ------------------
  |  Branch (101:9): [True: 0, False: 564]
  ------------------
  102|      0|        return MBEDTLS_ERR_HKDF_BAD_INPUT_DATA;
  ------------------
  |  |   25|      0|#define MBEDTLS_ERR_HKDF_BAD_INPUT_DATA  -0x5F80
  ------------------
  103|      0|    }
  104|       |
  105|    564|    mbedtls_md_init(&ctx);
  106|       |
  107|    564|    if ((ret = mbedtls_md_setup(&ctx, md, 1)) != 0) {
  ------------------
  |  Branch (107:9): [True: 0, False: 564]
  ------------------
  108|      0|        goto exit;
  109|      0|    }
  110|       |
  111|    564|    memset(t, 0, hash_len);
  112|       |
  113|       |    /*
  114|       |     * Compute T = T(1) | T(2) | T(3) | ... | T(N)
  115|       |     * Where T(N) is defined in RFC 5869 Section 2.3
  116|       |     */
  117|    846|    for (i = 1; i <= n; i++) {
  ------------------
  |  Branch (117:17): [True: 282, False: 564]
  ------------------
  118|    282|        size_t num_to_copy;
  119|    282|        unsigned char c = i & 0xff;
  120|       |
  121|    282|        ret = mbedtls_md_hmac_starts(&ctx, prk, prk_len);
  122|    282|        if (ret != 0) {
  ------------------
  |  Branch (122:13): [True: 0, False: 282]
  ------------------
  123|      0|            goto exit;
  124|      0|        }
  125|       |
  126|    282|        ret = mbedtls_md_hmac_update(&ctx, t, t_len);
  127|    282|        if (ret != 0) {
  ------------------
  |  Branch (127:13): [True: 0, False: 282]
  ------------------
  128|      0|            goto exit;
  129|      0|        }
  130|       |
  131|    282|        ret = mbedtls_md_hmac_update(&ctx, info, info_len);
  132|    282|        if (ret != 0) {
  ------------------
  |  Branch (132:13): [True: 0, False: 282]
  ------------------
  133|      0|            goto exit;
  134|      0|        }
  135|       |
  136|       |        /* The constant concatenated to the end of each T(n) is a single octet.
  137|       |         * */
  138|    282|        ret = mbedtls_md_hmac_update(&ctx, &c, 1);
  139|    282|        if (ret != 0) {
  ------------------
  |  Branch (139:13): [True: 0, False: 282]
  ------------------
  140|      0|            goto exit;
  141|      0|        }
  142|       |
  143|    282|        ret = mbedtls_md_hmac_finish(&ctx, t);
  144|    282|        if (ret != 0) {
  ------------------
  |  Branch (144:13): [True: 0, False: 282]
  ------------------
  145|      0|            goto exit;
  146|      0|        }
  147|       |
  148|    282|        num_to_copy = i != n ? hash_len : okm_len - where;
  ------------------
  |  Branch (148:23): [True: 0, False: 282]
  ------------------
  149|    282|        memcpy(okm + where, t, num_to_copy);
  150|    282|        where += hash_len;
  151|    282|        t_len = hash_len;
  152|    282|    }
  153|       |
  154|    564|exit:
  155|    564|    mbedtls_md_free(&ctx);
  156|    564|    mbedtls_platform_zeroize(t, sizeof(t));
  157|       |
  158|    564|    return ret;
  159|    564|}

mbedtls_md_info_from_type:
  140|  1.12k|{
  141|  1.12k|    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|  1.12k|        case MBEDTLS_MD_SHA256:
  ------------------
  |  Branch (159:9): [True: 1.12k, False: 0]
  ------------------
  160|  1.12k|            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: 1.12k]
  ------------------
  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: 1.12k]
  ------------------
  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: 1.12k]
  ------------------
  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: 1.12k]
  ------------------
  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: 1.12k]
  ------------------
  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: 1.12k]
  ------------------
  184|      0|            return &mbedtls_sha3_512_info;
  185|      0|#endif
  186|      0|        default:
  ------------------
  |  Branch (186:9): [True: 0, False: 1.12k]
  ------------------
  187|      0|            return NULL;
  188|  1.12k|    }
  189|  1.12k|}
mbedtls_md_init:
  256|    564|{
  257|       |    /* Note: this sets engine (if present) to MBEDTLS_MD_ENGINE_LEGACY */
  258|    564|    memset(ctx, 0, sizeof(mbedtls_md_context_t));
  259|    564|}
mbedtls_md_free:
  262|    564|{
  263|    564|    if (ctx == NULL || ctx->md_info == NULL) {
  ------------------
  |  Branch (263:9): [True: 0, False: 564]
  |  Branch (263:24): [True: 0, False: 564]
  ------------------
  264|      0|        return;
  265|      0|    }
  266|       |
  267|    564|    if (ctx->md_ctx != NULL) {
  ------------------
  |  Branch (267:9): [True: 564, False: 0]
  ------------------
  268|       |#if defined(MBEDTLS_MD_SOME_PSA)
  269|       |        if (ctx->engine == MBEDTLS_MD_ENGINE_PSA) {
  270|       |            psa_hash_abort(ctx->md_ctx);
  271|       |        } else
  272|       |#endif
  273|    564|        switch (ctx->md_info->type) {
  274|       |#if defined(MBEDTLS_MD5_C)
  275|       |            case MBEDTLS_MD_MD5:
  276|       |                mbedtls_md5_free(ctx->md_ctx);
  277|       |                break;
  278|       |#endif
  279|       |#if defined(MBEDTLS_RIPEMD160_C)
  280|       |            case MBEDTLS_MD_RIPEMD160:
  281|       |                mbedtls_ripemd160_free(ctx->md_ctx);
  282|       |                break;
  283|       |#endif
  284|       |#if defined(MBEDTLS_SHA1_C)
  285|       |            case MBEDTLS_MD_SHA1:
  286|       |                mbedtls_sha1_free(ctx->md_ctx);
  287|       |                break;
  288|       |#endif
  289|       |#if defined(MBEDTLS_SHA224_C)
  290|       |            case MBEDTLS_MD_SHA224:
  291|       |                mbedtls_sha256_free(ctx->md_ctx);
  292|       |                break;
  293|       |#endif
  294|      0|#if defined(MBEDTLS_SHA256_C)
  295|    564|            case MBEDTLS_MD_SHA256:
  ------------------
  |  Branch (295:13): [True: 564, False: 0]
  ------------------
  296|    564|                mbedtls_sha256_free(ctx->md_ctx);
  297|    564|                break;
  298|      0|#endif
  299|      0|#if defined(MBEDTLS_SHA384_C)
  300|      0|            case MBEDTLS_MD_SHA384:
  ------------------
  |  Branch (300:13): [True: 0, False: 564]
  ------------------
  301|      0|                mbedtls_sha512_free(ctx->md_ctx);
  302|      0|                break;
  303|      0|#endif
  304|      0|#if defined(MBEDTLS_SHA512_C)
  305|      0|            case MBEDTLS_MD_SHA512:
  ------------------
  |  Branch (305:13): [True: 0, False: 564]
  ------------------
  306|      0|                mbedtls_sha512_free(ctx->md_ctx);
  307|      0|                break;
  308|      0|#endif
  309|      0|#if defined(MBEDTLS_SHA3_C)
  310|      0|            case MBEDTLS_MD_SHA3_224:
  ------------------
  |  Branch (310:13): [True: 0, False: 564]
  ------------------
  311|      0|            case MBEDTLS_MD_SHA3_256:
  ------------------
  |  Branch (311:13): [True: 0, False: 564]
  ------------------
  312|      0|            case MBEDTLS_MD_SHA3_384:
  ------------------
  |  Branch (312:13): [True: 0, False: 564]
  ------------------
  313|      0|            case MBEDTLS_MD_SHA3_512:
  ------------------
  |  Branch (313:13): [True: 0, False: 564]
  ------------------
  314|      0|                mbedtls_sha3_free(ctx->md_ctx);
  315|      0|                break;
  316|      0|#endif
  317|      0|            default:
  ------------------
  |  Branch (317:13): [True: 0, False: 564]
  ------------------
  318|       |                /* Shouldn't happen */
  319|      0|                break;
  320|    564|        }
  321|    564|        mbedtls_free(ctx->md_ctx);
  ------------------
  |  |  143|    564|#define mbedtls_free       MBEDTLS_PLATFORM_FREE_MACRO
  |  |  ------------------
  |  |  |  | 4095|    564|#define MBEDTLS_PLATFORM_FREE_MACRO            my_free
  |  |  ------------------
  ------------------
  322|    564|    }
  323|       |
  324|    564|#if defined(MBEDTLS_MD_C)
  325|    564|    if (ctx->hmac_ctx != NULL) {
  ------------------
  |  Branch (325:9): [True: 564, False: 0]
  ------------------
  326|    564|        mbedtls_zeroize_and_free(ctx->hmac_ctx,
  327|    564|                                 2 * ctx->md_info->block_size);
  328|    564|    }
  329|    564|#endif
  330|       |
  331|    564|    mbedtls_platform_zeroize(ctx, sizeof(mbedtls_md_context_t));
  332|    564|}
mbedtls_md_setup:
  419|    564|{
  420|    564|#if defined(MBEDTLS_MD_C)
  421|    564|    if (ctx == NULL) {
  ------------------
  |  Branch (421:9): [True: 0, False: 564]
  ------------------
  422|      0|        return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MD_BAD_INPUT_DATA                     -0x5100
  ------------------
  423|      0|    }
  424|    564|#endif
  425|    564|    if (md_info == NULL) {
  ------------------
  |  Branch (425:9): [True: 0, False: 564]
  ------------------
  426|      0|        return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MD_BAD_INPUT_DATA                     -0x5100
  ------------------
  427|      0|    }
  428|       |
  429|    564|    ctx->md_info = md_info;
  430|    564|    ctx->md_ctx = NULL;
  431|    564|#if defined(MBEDTLS_MD_C)
  432|    564|    ctx->hmac_ctx = NULL;
  433|       |#else
  434|       |    if (hmac != 0) {
  435|       |        return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
  436|       |    }
  437|       |#endif
  438|       |
  439|       |#if defined(MBEDTLS_MD_SOME_PSA)
  440|       |    if (md_can_use_psa(ctx->md_info)) {
  441|       |        ctx->md_ctx = mbedtls_calloc(1, sizeof(psa_hash_operation_t));
  442|       |        if (ctx->md_ctx == NULL) {
  443|       |            return MBEDTLS_ERR_MD_ALLOC_FAILED;
  444|       |        }
  445|       |        ctx->engine = MBEDTLS_MD_ENGINE_PSA;
  446|       |    } else
  447|       |#endif
  448|    564|    switch (md_info->type) {
  449|       |#if defined(MBEDTLS_MD5_C)
  450|       |        case MBEDTLS_MD_MD5:
  451|       |            ALLOC(md5);
  452|       |            break;
  453|       |#endif
  454|       |#if defined(MBEDTLS_RIPEMD160_C)
  455|       |        case MBEDTLS_MD_RIPEMD160:
  456|       |            ALLOC(ripemd160);
  457|       |            break;
  458|       |#endif
  459|       |#if defined(MBEDTLS_SHA1_C)
  460|       |        case MBEDTLS_MD_SHA1:
  461|       |            ALLOC(sha1);
  462|       |            break;
  463|       |#endif
  464|       |#if defined(MBEDTLS_SHA224_C)
  465|       |        case MBEDTLS_MD_SHA224:
  466|       |            ALLOC(sha256);
  467|       |            break;
  468|       |#endif
  469|      0|#if defined(MBEDTLS_SHA256_C)
  470|    564|        case MBEDTLS_MD_SHA256:
  ------------------
  |  Branch (470:9): [True: 564, False: 0]
  ------------------
  471|    564|            ALLOC(sha256);
  ------------------
  |  |  410|    564|    do {                                                                \
  |  |  411|    564|        ctx->md_ctx = mbedtls_calloc(1, sizeof(mbedtls_##type##_context)); \
  |  |  ------------------
  |  |  |  |  144|    564|#define mbedtls_calloc     MBEDTLS_PLATFORM_CALLOC_MACRO
  |  |  |  |  ------------------
  |  |  |  |  |  | 4093|    564|#define MBEDTLS_PLATFORM_CALLOC_MACRO        my_calloc
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  412|    564|        if (ctx->md_ctx == NULL)                                       \
  |  |  ------------------
  |  |  |  Branch (412:13): [True: 0, False: 564]
  |  |  ------------------
  |  |  413|    564|        return MBEDTLS_ERR_MD_ALLOC_FAILED;                      \
  |  |  ------------------
  |  |  |  |   28|      0|#define MBEDTLS_ERR_MD_ALLOC_FAILED                       -0x5180
  |  |  ------------------
  |  |  414|    564|        mbedtls_##type##_init(ctx->md_ctx);                           \
  |  |  415|    564|    }                                                                   \
  |  |  416|    564|    while (0)
  |  |  ------------------
  |  |  |  Branch (416:12): [Folded - Ignored]
  |  |  ------------------
  ------------------
  472|    564|            break;
  473|    564|#endif
  474|    564|#if defined(MBEDTLS_SHA384_C)
  475|    564|        case MBEDTLS_MD_SHA384:
  ------------------
  |  Branch (475:9): [True: 0, False: 564]
  ------------------
  476|      0|            ALLOC(sha512);
  ------------------
  |  |  410|      0|    do {                                                                \
  |  |  411|      0|        ctx->md_ctx = mbedtls_calloc(1, sizeof(mbedtls_##type##_context)); \
  |  |  ------------------
  |  |  |  |  144|      0|#define mbedtls_calloc     MBEDTLS_PLATFORM_CALLOC_MACRO
  |  |  |  |  ------------------
  |  |  |  |  |  | 4093|      0|#define MBEDTLS_PLATFORM_CALLOC_MACRO        my_calloc
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  412|      0|        if (ctx->md_ctx == NULL)                                       \
  |  |  ------------------
  |  |  |  Branch (412:13): [True: 0, False: 0]
  |  |  ------------------
  |  |  413|      0|        return MBEDTLS_ERR_MD_ALLOC_FAILED;                      \
  |  |  ------------------
  |  |  |  |   28|      0|#define MBEDTLS_ERR_MD_ALLOC_FAILED                       -0x5180
  |  |  ------------------
  |  |  414|      0|        mbedtls_##type##_init(ctx->md_ctx);                           \
  |  |  415|      0|    }                                                                   \
  |  |  416|      0|    while (0)
  |  |  ------------------
  |  |  |  Branch (416:12): [Folded - Ignored]
  |  |  ------------------
  ------------------
  477|      0|            break;
  478|      0|#endif
  479|      0|#if defined(MBEDTLS_SHA512_C)
  480|      0|        case MBEDTLS_MD_SHA512:
  ------------------
  |  Branch (480:9): [True: 0, False: 564]
  ------------------
  481|      0|            ALLOC(sha512);
  ------------------
  |  |  410|      0|    do {                                                                \
  |  |  411|      0|        ctx->md_ctx = mbedtls_calloc(1, sizeof(mbedtls_##type##_context)); \
  |  |  ------------------
  |  |  |  |  144|      0|#define mbedtls_calloc     MBEDTLS_PLATFORM_CALLOC_MACRO
  |  |  |  |  ------------------
  |  |  |  |  |  | 4093|      0|#define MBEDTLS_PLATFORM_CALLOC_MACRO        my_calloc
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  412|      0|        if (ctx->md_ctx == NULL)                                       \
  |  |  ------------------
  |  |  |  Branch (412:13): [True: 0, False: 0]
  |  |  ------------------
  |  |  413|      0|        return MBEDTLS_ERR_MD_ALLOC_FAILED;                      \
  |  |  ------------------
  |  |  |  |   28|      0|#define MBEDTLS_ERR_MD_ALLOC_FAILED                       -0x5180
  |  |  ------------------
  |  |  414|      0|        mbedtls_##type##_init(ctx->md_ctx);                           \
  |  |  415|      0|    }                                                                   \
  |  |  416|      0|    while (0)
  |  |  ------------------
  |  |  |  Branch (416:12): [Folded - Ignored]
  |  |  ------------------
  ------------------
  482|      0|            break;
  483|      0|#endif
  484|      0|#if defined(MBEDTLS_SHA3_C)
  485|      0|        case MBEDTLS_MD_SHA3_224:
  ------------------
  |  Branch (485:9): [True: 0, False: 564]
  ------------------
  486|      0|        case MBEDTLS_MD_SHA3_256:
  ------------------
  |  Branch (486:9): [True: 0, False: 564]
  ------------------
  487|      0|        case MBEDTLS_MD_SHA3_384:
  ------------------
  |  Branch (487:9): [True: 0, False: 564]
  ------------------
  488|      0|        case MBEDTLS_MD_SHA3_512:
  ------------------
  |  Branch (488:9): [True: 0, False: 564]
  ------------------
  489|      0|            ALLOC(sha3);
  ------------------
  |  |  410|      0|    do {                                                                \
  |  |  411|      0|        ctx->md_ctx = mbedtls_calloc(1, sizeof(mbedtls_##type##_context)); \
  |  |  ------------------
  |  |  |  |  144|      0|#define mbedtls_calloc     MBEDTLS_PLATFORM_CALLOC_MACRO
  |  |  |  |  ------------------
  |  |  |  |  |  | 4093|      0|#define MBEDTLS_PLATFORM_CALLOC_MACRO        my_calloc
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  412|      0|        if (ctx->md_ctx == NULL)                                       \
  |  |  ------------------
  |  |  |  Branch (412:13): [True: 0, False: 0]
  |  |  ------------------
  |  |  413|      0|        return MBEDTLS_ERR_MD_ALLOC_FAILED;                      \
  |  |  ------------------
  |  |  |  |   28|      0|#define MBEDTLS_ERR_MD_ALLOC_FAILED                       -0x5180
  |  |  ------------------
  |  |  414|      0|        mbedtls_##type##_init(ctx->md_ctx);                           \
  |  |  415|      0|    }                                                                   \
  |  |  416|      0|    while (0)
  |  |  ------------------
  |  |  |  Branch (416:12): [Folded - Ignored]
  |  |  ------------------
  ------------------
  490|      0|            break;
  491|      0|#endif
  492|      0|        default:
  ------------------
  |  Branch (492:9): [True: 0, False: 564]
  ------------------
  493|      0|            return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MD_BAD_INPUT_DATA                     -0x5100
  ------------------
  494|    564|    }
  495|       |
  496|    564|#if defined(MBEDTLS_MD_C)
  497|    564|    if (hmac != 0) {
  ------------------
  |  Branch (497:9): [True: 564, False: 0]
  ------------------
  498|    564|        ctx->hmac_ctx = mbedtls_calloc(2, md_info->block_size);
  ------------------
  |  |  144|    564|#define mbedtls_calloc     MBEDTLS_PLATFORM_CALLOC_MACRO
  |  |  ------------------
  |  |  |  | 4093|    564|#define MBEDTLS_PLATFORM_CALLOC_MACRO        my_calloc
  |  |  ------------------
  ------------------
  499|    564|        if (ctx->hmac_ctx == NULL) {
  ------------------
  |  Branch (499:13): [True: 0, False: 564]
  ------------------
  500|      0|            mbedtls_md_free(ctx);
  501|      0|            return MBEDTLS_ERR_MD_ALLOC_FAILED;
  ------------------
  |  |   28|      0|#define MBEDTLS_ERR_MD_ALLOC_FAILED                       -0x5180
  ------------------
  502|      0|        }
  503|    564|    }
  504|    564|#endif
  505|       |
  506|    564|    return 0;
  507|    564|}
mbedtls_md_starts:
  511|    564|{
  512|    564|#if defined(MBEDTLS_MD_C)
  513|    564|    if (ctx == NULL || ctx->md_info == NULL) {
  ------------------
  |  Branch (513:9): [True: 0, False: 564]
  |  Branch (513:24): [True: 0, False: 564]
  ------------------
  514|      0|        return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MD_BAD_INPUT_DATA                     -0x5100
  ------------------
  515|      0|    }
  516|    564|#endif
  517|       |
  518|       |#if defined(MBEDTLS_MD_SOME_PSA)
  519|       |    if (ctx->engine == MBEDTLS_MD_ENGINE_PSA) {
  520|       |        psa_algorithm_t alg = psa_alg_of_md(ctx->md_info);
  521|       |        psa_hash_abort(ctx->md_ctx);
  522|       |        psa_status_t status = psa_hash_setup(ctx->md_ctx, alg);
  523|       |        return mbedtls_md_error_from_psa(status);
  524|       |    }
  525|       |#endif
  526|       |
  527|    564|    switch (ctx->md_info->type) {
  528|       |#if defined(MBEDTLS_MD5_C)
  529|       |        case MBEDTLS_MD_MD5:
  530|       |            return mbedtls_md5_starts(ctx->md_ctx);
  531|       |#endif
  532|       |#if defined(MBEDTLS_RIPEMD160_C)
  533|       |        case MBEDTLS_MD_RIPEMD160:
  534|       |            return mbedtls_ripemd160_starts(ctx->md_ctx);
  535|       |#endif
  536|       |#if defined(MBEDTLS_SHA1_C)
  537|       |        case MBEDTLS_MD_SHA1:
  538|       |            return mbedtls_sha1_starts(ctx->md_ctx);
  539|       |#endif
  540|       |#if defined(MBEDTLS_SHA224_C)
  541|       |        case MBEDTLS_MD_SHA224:
  542|       |            return mbedtls_sha256_starts(ctx->md_ctx, 1);
  543|       |#endif
  544|      0|#if defined(MBEDTLS_SHA256_C)
  545|    564|        case MBEDTLS_MD_SHA256:
  ------------------
  |  Branch (545:9): [True: 564, False: 0]
  ------------------
  546|    564|            return mbedtls_sha256_starts(ctx->md_ctx, 0);
  547|      0|#endif
  548|      0|#if defined(MBEDTLS_SHA384_C)
  549|      0|        case MBEDTLS_MD_SHA384:
  ------------------
  |  Branch (549:9): [True: 0, False: 564]
  ------------------
  550|      0|            return mbedtls_sha512_starts(ctx->md_ctx, 1);
  551|      0|#endif
  552|      0|#if defined(MBEDTLS_SHA512_C)
  553|      0|        case MBEDTLS_MD_SHA512:
  ------------------
  |  Branch (553:9): [True: 0, False: 564]
  ------------------
  554|      0|            return mbedtls_sha512_starts(ctx->md_ctx, 0);
  555|      0|#endif
  556|      0|#if defined(MBEDTLS_SHA3_C)
  557|      0|        case MBEDTLS_MD_SHA3_224:
  ------------------
  |  Branch (557:9): [True: 0, False: 564]
  ------------------
  558|      0|            return mbedtls_sha3_starts(ctx->md_ctx, MBEDTLS_SHA3_224);
  559|      0|        case MBEDTLS_MD_SHA3_256:
  ------------------
  |  Branch (559:9): [True: 0, False: 564]
  ------------------
  560|      0|            return mbedtls_sha3_starts(ctx->md_ctx, MBEDTLS_SHA3_256);
  561|      0|        case MBEDTLS_MD_SHA3_384:
  ------------------
  |  Branch (561:9): [True: 0, False: 564]
  ------------------
  562|      0|            return mbedtls_sha3_starts(ctx->md_ctx, MBEDTLS_SHA3_384);
  563|      0|        case MBEDTLS_MD_SHA3_512:
  ------------------
  |  Branch (563:9): [True: 0, False: 564]
  ------------------
  564|      0|            return mbedtls_sha3_starts(ctx->md_ctx, MBEDTLS_SHA3_512);
  565|      0|#endif
  566|      0|        default:
  ------------------
  |  Branch (566:9): [True: 0, False: 564]
  ------------------
  567|      0|            return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MD_BAD_INPUT_DATA                     -0x5100
  ------------------
  568|    564|    }
  569|    564|}
mbedtls_md_update:
  572|  1.69k|{
  573|  1.69k|#if defined(MBEDTLS_MD_C)
  574|  1.69k|    if (ctx == NULL || ctx->md_info == NULL) {
  ------------------
  |  Branch (574:9): [True: 0, False: 1.69k]
  |  Branch (574:24): [True: 0, False: 1.69k]
  ------------------
  575|      0|        return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MD_BAD_INPUT_DATA                     -0x5100
  ------------------
  576|      0|    }
  577|  1.69k|#endif
  578|       |
  579|       |#if defined(MBEDTLS_MD_SOME_PSA)
  580|       |    if (ctx->engine == MBEDTLS_MD_ENGINE_PSA) {
  581|       |        psa_status_t status = psa_hash_update(ctx->md_ctx, input, ilen);
  582|       |        return mbedtls_md_error_from_psa(status);
  583|       |    }
  584|       |#endif
  585|       |
  586|  1.69k|    switch (ctx->md_info->type) {
  587|       |#if defined(MBEDTLS_MD5_C)
  588|       |        case MBEDTLS_MD_MD5:
  589|       |            return mbedtls_md5_update(ctx->md_ctx, input, ilen);
  590|       |#endif
  591|       |#if defined(MBEDTLS_RIPEMD160_C)
  592|       |        case MBEDTLS_MD_RIPEMD160:
  593|       |            return mbedtls_ripemd160_update(ctx->md_ctx, input, ilen);
  594|       |#endif
  595|       |#if defined(MBEDTLS_SHA1_C)
  596|       |        case MBEDTLS_MD_SHA1:
  597|       |            return mbedtls_sha1_update(ctx->md_ctx, input, ilen);
  598|       |#endif
  599|       |#if defined(MBEDTLS_SHA224_C)
  600|       |        case MBEDTLS_MD_SHA224:
  601|       |            return mbedtls_sha256_update(ctx->md_ctx, input, ilen);
  602|       |#endif
  603|      0|#if defined(MBEDTLS_SHA256_C)
  604|  1.69k|        case MBEDTLS_MD_SHA256:
  ------------------
  |  Branch (604:9): [True: 1.69k, False: 0]
  ------------------
  605|  1.69k|            return mbedtls_sha256_update(ctx->md_ctx, input, ilen);
  606|      0|#endif
  607|      0|#if defined(MBEDTLS_SHA384_C)
  608|      0|        case MBEDTLS_MD_SHA384:
  ------------------
  |  Branch (608:9): [True: 0, False: 1.69k]
  ------------------
  609|      0|            return mbedtls_sha512_update(ctx->md_ctx, input, ilen);
  610|      0|#endif
  611|      0|#if defined(MBEDTLS_SHA512_C)
  612|      0|        case MBEDTLS_MD_SHA512:
  ------------------
  |  Branch (612:9): [True: 0, False: 1.69k]
  ------------------
  613|      0|            return mbedtls_sha512_update(ctx->md_ctx, input, ilen);
  614|      0|#endif
  615|      0|#if defined(MBEDTLS_SHA3_C)
  616|      0|        case MBEDTLS_MD_SHA3_224:
  ------------------
  |  Branch (616:9): [True: 0, False: 1.69k]
  ------------------
  617|      0|        case MBEDTLS_MD_SHA3_256:
  ------------------
  |  Branch (617:9): [True: 0, False: 1.69k]
  ------------------
  618|      0|        case MBEDTLS_MD_SHA3_384:
  ------------------
  |  Branch (618:9): [True: 0, False: 1.69k]
  ------------------
  619|      0|        case MBEDTLS_MD_SHA3_512:
  ------------------
  |  Branch (619:9): [True: 0, False: 1.69k]
  ------------------
  620|      0|            return mbedtls_sha3_update(ctx->md_ctx, input, ilen);
  621|      0|#endif
  622|      0|        default:
  ------------------
  |  Branch (622:9): [True: 0, False: 1.69k]
  ------------------
  623|      0|            return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MD_BAD_INPUT_DATA                     -0x5100
  ------------------
  624|  1.69k|    }
  625|  1.69k|}
mbedtls_md_finish:
  628|    564|{
  629|    564|#if defined(MBEDTLS_MD_C)
  630|    564|    if (ctx == NULL || ctx->md_info == NULL) {
  ------------------
  |  Branch (630:9): [True: 0, False: 564]
  |  Branch (630:24): [True: 0, False: 564]
  ------------------
  631|      0|        return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MD_BAD_INPUT_DATA                     -0x5100
  ------------------
  632|      0|    }
  633|    564|#endif
  634|       |
  635|       |#if defined(MBEDTLS_MD_SOME_PSA)
  636|       |    if (ctx->engine == MBEDTLS_MD_ENGINE_PSA) {
  637|       |        size_t size = ctx->md_info->size;
  638|       |        psa_status_t status = psa_hash_finish(ctx->md_ctx,
  639|       |                                              output, size, &size);
  640|       |        return mbedtls_md_error_from_psa(status);
  641|       |    }
  642|       |#endif
  643|       |
  644|    564|    switch (ctx->md_info->type) {
  645|       |#if defined(MBEDTLS_MD5_C)
  646|       |        case MBEDTLS_MD_MD5:
  647|       |            return mbedtls_md5_finish(ctx->md_ctx, output);
  648|       |#endif
  649|       |#if defined(MBEDTLS_RIPEMD160_C)
  650|       |        case MBEDTLS_MD_RIPEMD160:
  651|       |            return mbedtls_ripemd160_finish(ctx->md_ctx, output);
  652|       |#endif
  653|       |#if defined(MBEDTLS_SHA1_C)
  654|       |        case MBEDTLS_MD_SHA1:
  655|       |            return mbedtls_sha1_finish(ctx->md_ctx, output);
  656|       |#endif
  657|       |#if defined(MBEDTLS_SHA224_C)
  658|       |        case MBEDTLS_MD_SHA224:
  659|       |            return mbedtls_sha256_finish(ctx->md_ctx, output);
  660|       |#endif
  661|      0|#if defined(MBEDTLS_SHA256_C)
  662|    564|        case MBEDTLS_MD_SHA256:
  ------------------
  |  Branch (662:9): [True: 564, False: 0]
  ------------------
  663|    564|            return mbedtls_sha256_finish(ctx->md_ctx, output);
  664|      0|#endif
  665|      0|#if defined(MBEDTLS_SHA384_C)
  666|      0|        case MBEDTLS_MD_SHA384:
  ------------------
  |  Branch (666:9): [True: 0, False: 564]
  ------------------
  667|      0|            return mbedtls_sha512_finish(ctx->md_ctx, output);
  668|      0|#endif
  669|      0|#if defined(MBEDTLS_SHA512_C)
  670|      0|        case MBEDTLS_MD_SHA512:
  ------------------
  |  Branch (670:9): [True: 0, False: 564]
  ------------------
  671|      0|            return mbedtls_sha512_finish(ctx->md_ctx, output);
  672|      0|#endif
  673|      0|#if defined(MBEDTLS_SHA3_C)
  674|      0|        case MBEDTLS_MD_SHA3_224:
  ------------------
  |  Branch (674:9): [True: 0, False: 564]
  ------------------
  675|      0|        case MBEDTLS_MD_SHA3_256:
  ------------------
  |  Branch (675:9): [True: 0, False: 564]
  ------------------
  676|      0|        case MBEDTLS_MD_SHA3_384:
  ------------------
  |  Branch (676:9): [True: 0, False: 564]
  ------------------
  677|      0|        case MBEDTLS_MD_SHA3_512:
  ------------------
  |  Branch (677:9): [True: 0, False: 564]
  ------------------
  678|      0|            return mbedtls_sha3_finish(ctx->md_ctx, output, ctx->md_info->size);
  679|      0|#endif
  680|      0|        default:
  ------------------
  |  Branch (680:9): [True: 0, False: 564]
  ------------------
  681|      0|            return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MD_BAD_INPUT_DATA                     -0x5100
  ------------------
  682|    564|    }
  683|    564|}
mbedtls_md:
  687|    564|{
  688|    564|    if (md_info == NULL) {
  ------------------
  |  Branch (688:9): [True: 0, False: 564]
  ------------------
  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|    564|    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|    564|        case MBEDTLS_MD_SHA256:
  ------------------
  |  Branch (720:9): [True: 564, False: 0]
  ------------------
  721|    564|            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: 564]
  ------------------
  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: 564]
  ------------------
  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: 564]
  ------------------
  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: 564]
  ------------------
  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: 564]
  ------------------
  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: 564]
  ------------------
  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: 564]
  ------------------
  742|      0|            return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MD_BAD_INPUT_DATA                     -0x5100
  ------------------
  743|    564|    }
  744|    564|}
mbedtls_md_get_size:
  747|  1.12k|{
  748|  1.12k|    if (md_info == NULL) {
  ------------------
  |  Branch (748:9): [True: 0, False: 1.12k]
  ------------------
  749|      0|        return 0;
  750|      0|    }
  751|       |
  752|  1.12k|    return md_info->size;
  753|  1.12k|}
mbedtls_md_hmac_starts:
  970|    282|{
  971|    282|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|    282|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  972|    282|    unsigned char sum[MBEDTLS_MD_MAX_SIZE];
  973|    282|    unsigned char *ipad, *opad;
  974|       |
  975|    282|    if (ctx == NULL || ctx->md_info == NULL || ctx->hmac_ctx == NULL) {
  ------------------
  |  Branch (975:9): [True: 0, False: 282]
  |  Branch (975:24): [True: 0, False: 282]
  |  Branch (975:48): [True: 0, False: 282]
  ------------------
  976|      0|        return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MD_BAD_INPUT_DATA                     -0x5100
  ------------------
  977|      0|    }
  978|       |
  979|    282|    if (keylen > (size_t) ctx->md_info->block_size) {
  ------------------
  |  Branch (979:9): [True: 0, False: 282]
  ------------------
  980|      0|        if ((ret = mbedtls_md_starts(ctx)) != 0) {
  ------------------
  |  Branch (980:13): [True: 0, False: 0]
  ------------------
  981|      0|            goto cleanup;
  982|      0|        }
  983|      0|        if ((ret = mbedtls_md_update(ctx, key, keylen)) != 0) {
  ------------------
  |  Branch (983:13): [True: 0, False: 0]
  ------------------
  984|      0|            goto cleanup;
  985|      0|        }
  986|      0|        if ((ret = mbedtls_md_finish(ctx, sum)) != 0) {
  ------------------
  |  Branch (986:13): [True: 0, False: 0]
  ------------------
  987|      0|            goto cleanup;
  988|      0|        }
  989|       |
  990|      0|        keylen = ctx->md_info->size;
  991|      0|        key = sum;
  992|      0|    }
  993|       |
  994|    282|    ipad = (unsigned char *) ctx->hmac_ctx;
  995|    282|    opad = (unsigned char *) ctx->hmac_ctx + ctx->md_info->block_size;
  996|       |
  997|    282|    memset(ipad, 0x36, ctx->md_info->block_size);
  998|    282|    memset(opad, 0x5C, ctx->md_info->block_size);
  999|       |
 1000|    282|    mbedtls_xor(ipad, ipad, key, keylen);
 1001|    282|    mbedtls_xor(opad, opad, key, keylen);
 1002|       |
 1003|    282|    if ((ret = mbedtls_md_starts(ctx)) != 0) {
  ------------------
  |  Branch (1003:9): [True: 0, False: 282]
  ------------------
 1004|      0|        goto cleanup;
 1005|      0|    }
 1006|    282|    if ((ret = mbedtls_md_update(ctx, ipad,
  ------------------
  |  Branch (1006:9): [True: 0, False: 282]
  ------------------
 1007|    282|                                 ctx->md_info->block_size)) != 0) {
 1008|      0|        goto cleanup;
 1009|      0|    }
 1010|       |
 1011|    282|cleanup:
 1012|    282|    mbedtls_platform_zeroize(sum, sizeof(sum));
 1013|       |
 1014|    282|    return ret;
 1015|    282|}
mbedtls_md_hmac_update:
 1018|    846|{
 1019|    846|    if (ctx == NULL || ctx->md_info == NULL || ctx->hmac_ctx == NULL) {
  ------------------
  |  Branch (1019:9): [True: 0, False: 846]
  |  Branch (1019:24): [True: 0, False: 846]
  |  Branch (1019:48): [True: 0, False: 846]
  ------------------
 1020|      0|        return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MD_BAD_INPUT_DATA                     -0x5100
  ------------------
 1021|      0|    }
 1022|       |
 1023|    846|    return mbedtls_md_update(ctx, input, ilen);
 1024|    846|}
mbedtls_md_hmac_finish:
 1027|    282|{
 1028|    282|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|    282|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1029|    282|    unsigned char tmp[MBEDTLS_MD_MAX_SIZE];
 1030|    282|    unsigned char *opad;
 1031|       |
 1032|    282|    if (ctx == NULL || ctx->md_info == NULL || ctx->hmac_ctx == NULL) {
  ------------------
  |  Branch (1032:9): [True: 0, False: 282]
  |  Branch (1032:24): [True: 0, False: 282]
  |  Branch (1032:48): [True: 0, False: 282]
  ------------------
 1033|      0|        return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MD_BAD_INPUT_DATA                     -0x5100
  ------------------
 1034|      0|    }
 1035|       |
 1036|    282|    opad = (unsigned char *) ctx->hmac_ctx + ctx->md_info->block_size;
 1037|       |
 1038|    282|    if ((ret = mbedtls_md_finish(ctx, tmp)) != 0) {
  ------------------
  |  Branch (1038:9): [True: 0, False: 282]
  ------------------
 1039|      0|        return ret;
 1040|      0|    }
 1041|    282|    if ((ret = mbedtls_md_starts(ctx)) != 0) {
  ------------------
  |  Branch (1041:9): [True: 0, False: 282]
  ------------------
 1042|      0|        return ret;
 1043|      0|    }
 1044|    282|    if ((ret = mbedtls_md_update(ctx, opad,
  ------------------
  |  Branch (1044:9): [True: 0, False: 282]
  ------------------
 1045|    282|                                 ctx->md_info->block_size)) != 0) {
 1046|      0|        return ret;
 1047|      0|    }
 1048|    282|    if ((ret = mbedtls_md_update(ctx, tmp,
  ------------------
  |  Branch (1048:9): [True: 0, False: 282]
  ------------------
 1049|    282|                                 ctx->md_info->size)) != 0) {
 1050|      0|        return ret;
 1051|      0|    }
 1052|    282|    return mbedtls_md_finish(ctx, output);
 1053|    282|}

mbedtls_oid_get_x509_ext_type:
   84|  23.4k|    {                                                                       \
   85|  23.4k|        const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1(oid);        \
   86|  23.4k|        if (data == NULL) return MBEDTLS_ERR_OID_NOT_FOUND;            \
  ------------------
  |  |   28|  3.10k|#define MBEDTLS_ERR_OID_NOT_FOUND                         -0x002E
  ------------------
  |  Branch (86:13): [True: 3.10k, False: 20.3k]
  ------------------
   87|  23.4k|        *ATTR1 = data->ATTR1;                                               \
   88|  20.3k|        return 0;                                                        \
   89|  23.4k|    }
mbedtls_oid_get_sig_alg:
   99|  4.51k|    {                                                                           \
  100|  4.51k|        const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1(oid);            \
  101|  4.51k|        if (data == NULL) return MBEDTLS_ERR_OID_NOT_FOUND;                 \
  ------------------
  |  |   28|      0|#define MBEDTLS_ERR_OID_NOT_FOUND                         -0x002E
  ------------------
  |  Branch (101:13): [True: 0, False: 4.51k]
  ------------------
  102|  4.51k|        *(ATTR1) = data->ATTR1;                                                 \
  103|  4.51k|        *(ATTR2) = data->ATTR2;                                                 \
  104|  4.51k|        return 0;                                                            \
  105|  4.51k|    }
mbedtls_oid_get_pk_alg:
   84|  4.51k|    {                                                                       \
   85|  4.51k|        const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1(oid);        \
   86|  4.51k|        if (data == NULL) return MBEDTLS_ERR_OID_NOT_FOUND;            \
  ------------------
  |  |   28|      0|#define MBEDTLS_ERR_OID_NOT_FOUND                         -0x002E
  ------------------
  |  Branch (86:13): [True: 0, False: 4.51k]
  ------------------
   87|  4.51k|        *ATTR1 = data->ATTR1;                                               \
   88|  4.51k|        return 0;                                                        \
   89|  4.51k|    }
mbedtls_oid_get_ec_grp:
   84|  4.51k|    {                                                                       \
   85|  4.51k|        const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1(oid);        \
   86|  4.51k|        if (data == NULL) return MBEDTLS_ERR_OID_NOT_FOUND;            \
  ------------------
  |  |   28|      0|#define MBEDTLS_ERR_OID_NOT_FOUND                         -0x002E
  ------------------
  |  Branch (86:13): [True: 0, False: 4.51k]
  ------------------
   87|  4.51k|        *ATTR1 = data->ATTR1;                                               \
   88|  4.51k|        return 0;                                                        \
   89|  4.51k|    }
oid.c:oid_x509_ext_from_asn1:
   47|  23.4k|    {                                                                   \
   48|  23.4k|        const TYPE_T *p = (LIST);                                       \
   49|  23.4k|        const mbedtls_oid_descriptor_t *cur =                           \
   50|  23.4k|            (const mbedtls_oid_descriptor_t *) p;                       \
   51|  23.4k|        if (p == NULL || oid == NULL) return NULL;                  \
  ------------------
  |  Branch (51:13): [True: 0, False: 23.4k]
  |  Branch (51:26): [True: 0, False: 23.4k]
  ------------------
   52|   101k|        while (cur->asn1 != NULL) {                                    \
  ------------------
  |  Branch (52:16): [True: 98.4k, False: 3.10k]
  ------------------
   53|  98.4k|            if (cur->asn1_len == oid->len &&                            \
  ------------------
  |  Branch (53:17): [True: 68.2k, False: 30.1k]
  ------------------
   54|  98.4k|                memcmp(cur->asn1, oid->p, oid->len) == 0) {          \
  ------------------
  |  Branch (54:17): [True: 20.3k, False: 47.9k]
  ------------------
   55|  20.3k|                return p;                                            \
   56|  20.3k|            }                                                           \
   57|  98.4k|            p++;                                                        \
   58|  78.1k|            cur = (const mbedtls_oid_descriptor_t *) p;                 \
   59|  78.1k|        }                                                               \
   60|  23.4k|        return NULL;                                                 \
   61|  23.4k|    }
oid.c:oid_sig_alg_from_asn1:
   47|  4.51k|    {                                                                   \
   48|  4.51k|        const TYPE_T *p = (LIST);                                       \
   49|  4.51k|        const mbedtls_oid_descriptor_t *cur =                           \
   50|  4.51k|            (const mbedtls_oid_descriptor_t *) p;                       \
   51|  4.51k|        if (p == NULL || oid == NULL) return NULL;                  \
  ------------------
  |  Branch (51:13): [True: 0, False: 4.51k]
  |  Branch (51:26): [True: 0, False: 4.51k]
  ------------------
   52|  18.0k|        while (cur->asn1 != NULL) {                                    \
  ------------------
  |  Branch (52:16): [True: 18.0k, False: 0]
  ------------------
   53|  18.0k|            if (cur->asn1_len == oid->len &&                            \
  ------------------
  |  Branch (53:17): [True: 4.51k, False: 13.5k]
  ------------------
   54|  18.0k|                memcmp(cur->asn1, oid->p, oid->len) == 0) {          \
  ------------------
  |  Branch (54:17): [True: 4.51k, False: 0]
  ------------------
   55|  4.51k|                return p;                                            \
   56|  4.51k|            }                                                           \
   57|  18.0k|            p++;                                                        \
   58|  13.5k|            cur = (const mbedtls_oid_descriptor_t *) p;                 \
   59|  13.5k|        }                                                               \
   60|  4.51k|        return NULL;                                                 \
   61|  4.51k|    }
oid.c:oid_pk_alg_from_asn1:
   47|  4.51k|    {                                                                   \
   48|  4.51k|        const TYPE_T *p = (LIST);                                       \
   49|  4.51k|        const mbedtls_oid_descriptor_t *cur =                           \
   50|  4.51k|            (const mbedtls_oid_descriptor_t *) p;                       \
   51|  4.51k|        if (p == NULL || oid == NULL) return NULL;                  \
  ------------------
  |  Branch (51:13): [True: 0, False: 4.51k]
  |  Branch (51:26): [True: 0, False: 4.51k]
  ------------------
   52|  9.02k|        while (cur->asn1 != NULL) {                                    \
  ------------------
  |  Branch (52:16): [True: 9.02k, False: 0]
  ------------------
   53|  9.02k|            if (cur->asn1_len == oid->len &&                            \
  ------------------
  |  Branch (53:17): [True: 4.51k, False: 4.51k]
  ------------------
   54|  9.02k|                memcmp(cur->asn1, oid->p, oid->len) == 0) {          \
  ------------------
  |  Branch (54:17): [True: 4.51k, False: 0]
  ------------------
   55|  4.51k|                return p;                                            \
   56|  4.51k|            }                                                           \
   57|  9.02k|            p++;                                                        \
   58|  4.51k|            cur = (const mbedtls_oid_descriptor_t *) p;                 \
   59|  4.51k|        }                                                               \
   60|  4.51k|        return NULL;                                                 \
   61|  4.51k|    }
oid.c:oid_grp_id_from_asn1:
   47|  4.51k|    {                                                                   \
   48|  4.51k|        const TYPE_T *p = (LIST);                                       \
   49|  4.51k|        const mbedtls_oid_descriptor_t *cur =                           \
   50|  4.51k|            (const mbedtls_oid_descriptor_t *) p;                       \
   51|  4.51k|        if (p == NULL || oid == NULL) return NULL;                  \
  ------------------
  |  Branch (51:13): [True: 0, False: 4.51k]
  |  Branch (51:26): [True: 0, False: 4.51k]
  ------------------
   52|  13.5k|        while (cur->asn1 != NULL) {                                    \
  ------------------
  |  Branch (52:16): [True: 13.5k, False: 0]
  ------------------
   53|  13.5k|            if (cur->asn1_len == oid->len &&                            \
  ------------------
  |  Branch (53:17): [True: 9.02k, False: 4.51k]
  ------------------
   54|  13.5k|                memcmp(cur->asn1, oid->p, oid->len) == 0) {          \
  ------------------
  |  Branch (54:17): [True: 4.51k, False: 4.51k]
  ------------------
   55|  4.51k|                return p;                                            \
   56|  4.51k|            }                                                           \
   57|  13.5k|            p++;                                                        \
   58|  9.02k|            cur = (const mbedtls_oid_descriptor_t *) p;                 \
   59|  9.02k|        }                                                               \
   60|  4.51k|        return NULL;                                                 \
   61|  4.51k|    }

mbedtls_pk_free:
   64|  4.51k|{
   65|  4.51k|    if (ctx == NULL) {
  ------------------
  |  Branch (65:9): [True: 0, False: 4.51k]
  ------------------
   66|      0|        return;
   67|      0|    }
   68|       |
   69|  4.51k|    if ((ctx->pk_info != NULL) && (ctx->pk_info->ctx_free_func != NULL)) {
  ------------------
  |  Branch (69:9): [True: 4.51k, False: 0]
  |  Branch (69:35): [True: 4.51k, False: 0]
  ------------------
   70|  4.51k|        ctx->pk_info->ctx_free_func(ctx->pk_ctx);
   71|  4.51k|    }
   72|       |
   73|       |#if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
   74|       |    /* The ownership of the priv_id key for opaque keys is external of the PK
   75|       |     * module. It's the user responsibility to clear it after use. */
   76|       |    if ((ctx->pk_info != NULL) && (ctx->pk_info->type != MBEDTLS_PK_OPAQUE)) {
   77|       |        psa_destroy_key(ctx->priv_id);
   78|       |    }
   79|       |#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
   80|       |
   81|  4.51k|    mbedtls_platform_zeroize(ctx, sizeof(mbedtls_pk_context));
   82|  4.51k|}
mbedtls_pk_info_from_type:
  115|  4.51k|{
  116|  4.51k|    switch (pk_type) {
  117|      0|#if defined(MBEDTLS_RSA_C)
  118|      0|        case MBEDTLS_PK_RSA:
  ------------------
  |  Branch (118:9): [True: 0, False: 4.51k]
  ------------------
  119|      0|            return &mbedtls_rsa_info;
  120|      0|#endif /* MBEDTLS_RSA_C */
  121|      0|#if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
  122|  4.51k|        case MBEDTLS_PK_ECKEY:
  ------------------
  |  Branch (122:9): [True: 4.51k, False: 0]
  ------------------
  123|  4.51k|            return &mbedtls_eckey_info;
  124|      0|        case MBEDTLS_PK_ECKEY_DH:
  ------------------
  |  Branch (124:9): [True: 0, False: 4.51k]
  ------------------
  125|      0|            return &mbedtls_eckeydh_info;
  126|      0|#endif /* MBEDTLS_PK_HAVE_ECC_KEYS */
  127|      0|#if defined(MBEDTLS_PK_CAN_ECDSA_SOME)
  128|      0|        case MBEDTLS_PK_ECDSA:
  ------------------
  |  Branch (128:9): [True: 0, False: 4.51k]
  ------------------
  129|      0|            return &mbedtls_ecdsa_info;
  130|      0|#endif /* MBEDTLS_PK_CAN_ECDSA_SOME */
  131|       |        /* MBEDTLS_PK_RSA_ALT omitted on purpose */
  132|      0|        default:
  ------------------
  |  Branch (132:9): [True: 0, False: 4.51k]
  ------------------
  133|      0|            return NULL;
  134|  4.51k|    }
  135|  4.51k|}
mbedtls_pk_setup:
  141|  4.51k|{
  142|  4.51k|    if (info == NULL || ctx->pk_info != NULL) {
  ------------------
  |  Branch (142:9): [True: 0, False: 4.51k]
  |  Branch (142:25): [True: 0, False: 4.51k]
  ------------------
  143|      0|        return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
  ------------------
  |  |   40|      0|#define MBEDTLS_ERR_PK_BAD_INPUT_DATA      -0x3E80
  ------------------
  144|      0|    }
  145|       |
  146|  4.51k|    if ((info->ctx_alloc_func != NULL) &&
  ------------------
  |  Branch (146:9): [True: 4.51k, False: 0]
  ------------------
  147|  4.51k|        ((ctx->pk_ctx = info->ctx_alloc_func()) == NULL)) {
  ------------------
  |  Branch (147:9): [True: 0, False: 4.51k]
  ------------------
  148|      0|        return MBEDTLS_ERR_PK_ALLOC_FAILED;
  ------------------
  |  |   36|      0|#define MBEDTLS_ERR_PK_ALLOC_FAILED        -0x3F80
  ------------------
  149|      0|    }
  150|       |
  151|  4.51k|    ctx->pk_info = info;
  152|       |
  153|  4.51k|    return 0;
  154|  4.51k|}
mbedtls_pk_can_do:
  232|  1.12k|{
  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|  1.12k|    if (ctx == NULL || ctx->pk_info == NULL) {
  ------------------
  |  Branch (236:9): [True: 0, False: 1.12k]
  |  Branch (236:24): [True: 0, False: 1.12k]
  ------------------
  237|      0|        return 0;
  238|      0|    }
  239|       |
  240|  1.12k|    return ctx->pk_info->can_do(type);
  241|  1.12k|}
mbedtls_pk_verify_restartable:
 1047|    564|{
 1048|    564|    if ((md_alg != MBEDTLS_MD_NONE || hash_len != 0) && hash == NULL) {
  ------------------
  |  Branch (1048:10): [True: 564, False: 0]
  |  Branch (1048:39): [True: 0, False: 0]
  |  Branch (1048:57): [True: 0, False: 564]
  ------------------
 1049|      0|        return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
  ------------------
  |  |   40|      0|#define MBEDTLS_ERR_PK_BAD_INPUT_DATA      -0x3E80
  ------------------
 1050|      0|    }
 1051|       |
 1052|    564|    if (ctx->pk_info == NULL ||
  ------------------
  |  Branch (1052:9): [True: 0, False: 564]
  ------------------
 1053|    564|        pk_hashlen_helper(md_alg, &hash_len) != 0) {
  ------------------
  |  Branch (1053:9): [True: 0, False: 564]
  ------------------
 1054|      0|        return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
  ------------------
  |  |   40|      0|#define MBEDTLS_ERR_PK_BAD_INPUT_DATA      -0x3E80
  ------------------
 1055|      0|    }
 1056|       |
 1057|    564|#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
 1058|       |    /* optimization: use non-restartable version if restart disabled */
 1059|    564|    if (rs_ctx != NULL &&
  ------------------
  |  Branch (1059:9): [True: 0, False: 564]
  ------------------
 1060|    564|        mbedtls_ecp_restart_is_enabled() &&
  ------------------
  |  Branch (1060:9): [True: 0, False: 0]
  ------------------
 1061|    564|        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|    564|    if (ctx->pk_info->verify_func == NULL) {
  ------------------
  |  Branch (1081:9): [True: 0, False: 564]
  ------------------
 1082|      0|        return MBEDTLS_ERR_PK_TYPE_MISMATCH;
  ------------------
  |  |   38|      0|#define MBEDTLS_ERR_PK_TYPE_MISMATCH       -0x3F00
  ------------------
 1083|      0|    }
 1084|       |
 1085|    564|    return ctx->pk_info->verify_func(ctx, md_alg, hash, hash_len,
 1086|    564|                                     sig, sig_len);
 1087|    564|}
mbedtls_pk_verify:
 1095|    564|{
 1096|    564|    return mbedtls_pk_verify_restartable(ctx, md_alg, hash, hash_len,
 1097|    564|                                         sig, sig_len, NULL);
 1098|    564|}
mbedtls_pk_verify_ext:
 1107|    564|{
 1108|    564|    if ((md_alg != MBEDTLS_MD_NONE || hash_len != 0) && hash == NULL) {
  ------------------
  |  Branch (1108:10): [True: 564, False: 0]
  |  Branch (1108:39): [True: 0, False: 0]
  |  Branch (1108:57): [True: 0, False: 564]
  ------------------
 1109|      0|        return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
  ------------------
  |  |   40|      0|#define MBEDTLS_ERR_PK_BAD_INPUT_DATA      -0x3E80
  ------------------
 1110|      0|    }
 1111|       |
 1112|    564|    if (ctx->pk_info == NULL) {
  ------------------
  |  Branch (1112:9): [True: 0, False: 564]
  ------------------
 1113|      0|        return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
  ------------------
  |  |   40|      0|#define MBEDTLS_ERR_PK_BAD_INPUT_DATA      -0x3E80
  ------------------
 1114|      0|    }
 1115|       |
 1116|    564|    if (!mbedtls_pk_can_do(ctx, type)) {
  ------------------
  |  Branch (1116:9): [True: 0, False: 564]
  ------------------
 1117|      0|        return MBEDTLS_ERR_PK_TYPE_MISMATCH;
  ------------------
  |  |   38|      0|#define MBEDTLS_ERR_PK_TYPE_MISMATCH       -0x3F00
  ------------------
 1118|      0|    }
 1119|       |
 1120|    564|    if (type != MBEDTLS_PK_RSASSA_PSS) {
  ------------------
  |  Branch (1120:9): [True: 564, False: 0]
  ------------------
 1121|       |        /* General case: no options */
 1122|    564|        if (options != NULL) {
  ------------------
  |  Branch (1122:13): [True: 0, False: 564]
  ------------------
 1123|      0|            return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
  ------------------
  |  |   40|      0|#define MBEDTLS_ERR_PK_BAD_INPUT_DATA      -0x3E80
  ------------------
 1124|      0|        }
 1125|       |
 1126|    564|        return mbedtls_pk_verify(ctx, md_alg, hash, hash_len, sig, sig_len);
 1127|    564|    }
 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|  13.2k|{
 1500|  13.2k|    if (ctx == NULL || ctx->pk_info == NULL) {
  ------------------
  |  Branch (1500:9): [True: 0, False: 13.2k]
  |  Branch (1500:24): [True: 0, False: 13.2k]
  ------------------
 1501|      0|        return MBEDTLS_PK_NONE;
 1502|      0|    }
 1503|       |
 1504|  13.2k|    return ctx->pk_info->type;
 1505|  13.2k|}
pk.c:pk_hashlen_helper:
  998|    564|{
  999|    564|    if (*hash_len != 0) {
  ------------------
  |  Branch (999:9): [True: 564, False: 0]
  ------------------
 1000|    564|        return 0;
 1001|    564|    }
 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|  4.51k|{
   19|       |#if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
   20|       |    size_t ec_bits;
   21|       |    psa_ecc_family_t ec_family = mbedtls_ecc_group_to_psa(grp_id, &ec_bits);
   22|       |
   23|       |    /* group may already be initialized; if so, make sure IDs match */
   24|       |    if ((pk->ec_family != 0 && pk->ec_family != ec_family) ||
   25|       |        (pk->ec_bits != 0 && pk->ec_bits != ec_bits)) {
   26|       |        return MBEDTLS_ERR_PK_KEY_INVALID_FORMAT;
   27|       |    }
   28|       |
   29|       |    /* set group */
   30|       |    pk->ec_family = ec_family;
   31|       |    pk->ec_bits = ec_bits;
   32|       |
   33|       |    return 0;
   34|       |#else /* MBEDTLS_PK_USE_PSA_EC_DATA */
   35|  4.51k|    mbedtls_ecp_keypair *ecp = mbedtls_pk_ec_rw(*pk);
   36|       |
   37|       |    /* grp may already be initialized; if so, make sure IDs match */
   38|  4.51k|    if (mbedtls_pk_ec_ro(*pk)->grp.id != MBEDTLS_ECP_DP_NONE &&
  ------------------
  |  Branch (38:9): [True: 0, False: 4.51k]
  ------------------
   39|  4.51k|        mbedtls_pk_ec_ro(*pk)->grp.id != grp_id) {
  ------------------
  |  Branch (39:9): [True: 0, False: 0]
  ------------------
   40|      0|        return MBEDTLS_ERR_PK_KEY_INVALID_FORMAT;
  ------------------
  |  |   46|      0|#define MBEDTLS_ERR_PK_KEY_INVALID_FORMAT  -0x3D00
  ------------------
   41|      0|    }
   42|       |
   43|       |    /* set group */
   44|  4.51k|    return mbedtls_ecp_group_load(&(ecp->grp), grp_id);
   45|  4.51k|#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
   46|  4.51k|}
mbedtls_pk_ecc_set_pubkey:
  205|  4.51k|{
  206|       |#if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
  207|       |
  208|       |    /* Load the key */
  209|       |    if (!PSA_ECC_FAMILY_IS_WEIERSTRASS(pk->ec_family) || *pub == 0x04) {
  210|       |        /* Format directly supported by PSA:
  211|       |         * - non-Weierstrass curves that only have one format;
  212|       |         * - uncompressed format for Weierstrass curves. */
  213|       |        if (pub_len > sizeof(pk->pub_raw)) {
  214|       |            return MBEDTLS_ERR_PK_BUFFER_TOO_SMALL;
  215|       |        }
  216|       |        memcpy(pk->pub_raw, pub, pub_len);
  217|       |        pk->pub_raw_len = pub_len;
  218|       |    } else {
  219|       |        /* Other format, try the fallback */
  220|       |        int ret = pk_ecc_set_pubkey_psa_ecp_fallback(pk, pub, pub_len);
  221|       |        if (ret != 0) {
  222|       |            return ret;
  223|       |        }
  224|       |    }
  225|       |
  226|       |    /* Validate the key by trying to import it */
  227|       |    mbedtls_svc_key_id_t key_id = MBEDTLS_SVC_KEY_ID_INIT;
  228|       |    psa_key_attributes_t key_attrs = PSA_KEY_ATTRIBUTES_INIT;
  229|       |
  230|       |    psa_set_key_usage_flags(&key_attrs, 0);
  231|       |    psa_set_key_type(&key_attrs, PSA_KEY_TYPE_ECC_PUBLIC_KEY(pk->ec_family));
  232|       |    psa_set_key_bits(&key_attrs, pk->ec_bits);
  233|       |
  234|       |    if ((psa_import_key(&key_attrs, pk->pub_raw, pk->pub_raw_len,
  235|       |                        &key_id) != PSA_SUCCESS) ||
  236|       |        (psa_destroy_key(key_id) != PSA_SUCCESS)) {
  237|       |        return MBEDTLS_ERR_PK_INVALID_PUBKEY;
  238|       |    }
  239|       |
  240|       |    return 0;
  241|       |
  242|       |#else /* MBEDTLS_PK_USE_PSA_EC_DATA */
  243|       |
  244|  4.51k|    int ret;
  245|  4.51k|    mbedtls_ecp_keypair *ec_key = (mbedtls_ecp_keypair *) pk->pk_ctx;
  246|  4.51k|    ret = mbedtls_ecp_point_read_binary(&ec_key->grp, &ec_key->Q, pub, pub_len);
  247|  4.51k|    if (ret != 0) {
  ------------------
  |  Branch (247:9): [True: 0, False: 4.51k]
  ------------------
  248|      0|        return ret;
  249|      0|    }
  250|  4.51k|    return mbedtls_ecp_check_pubkey(&ec_key->grp, &ec_key->Q);
  251|       |
  252|  4.51k|#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
  253|  4.51k|}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

libspdm_get_max_buffer_size:
   93|    282|{
   94|    282|    return LIBSPDM_MAX_SPDM_MSG_SIZE;
  ------------------
  |  |  101|    282|#define LIBSPDM_MAX_SPDM_MSG_SIZE 0x1200
  ------------------
   95|    282|}
libspdm_test_process_encap_response_key_update_case1:
  103|    141|{
  104|    141|    libspdm_test_context_t *spdm_test_context;
  105|    141|    libspdm_context_t *spdm_context;
  106|    141|    uint32_t session_id;
  107|    141|    bool need_continue;
  108|    141|    libspdm_session_info_t *session_info;
  109|    141|    libspdm_secured_message_context_t *secured_message_context;
  110|    141|    uint8_t m_req_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
  111|    141|    uint8_t m_rsp_secret_buffer[LIBSPDM_MAX_HASH_SIZE];
  112|       |
  113|    141|    spdm_test_context = *State;
  114|    141|    spdm_context = spdm_test_context->spdm_context;
  115|       |
  116|    141|    libspdm_set_standard_key_update_test_state(spdm_context, &session_id);
  117|       |
  118|    141|    session_info = &spdm_context->session_info[0];
  119|    141|    secured_message_context = session_info->secured_message_context;
  120|       |
  121|    141|    libspdm_set_standard_key_update_test_secrets(session_info->secured_message_context,
  122|    141|                                                 m_rsp_secret_buffer, (uint8_t)(0xFF),
  123|    141|                                                 m_req_secret_buffer, (uint8_t)(0xEE));
  124|       |
  125|    141|    libspdm_compute_secret_update(spdm_context->connection_info.version,
  126|    141|                                  secured_message_context->hash_size, m_req_secret_buffer,
  127|    141|                                  m_req_secret_buffer, secured_message_context->hash_size);
  128|       |
  129|    141|    libspdm_init_key_update_encap_state(spdm_context);
  130|       |
  131|    141|    libspdm_process_encap_response_key_update(spdm_context, spdm_test_context->test_buffer_size,
  132|    141|                                              spdm_test_context->test_buffer, &need_continue);
  133|    141|}
libspdm_test_get_encap_request_key_update_case1:
  136|    141|{
  137|    141|    libspdm_test_context_t *spdm_test_context;
  138|    141|    spdm_key_update_request_t *spdm_request;
  139|    141|    libspdm_context_t *spdm_context;
  140|    141|    size_t encap_request_size;
  141|    141|    void *data;
  142|    141|    size_t data_size;
  143|    141|    uint32_t session_id;
  144|    141|    libspdm_session_info_t *session_info;
  145|       |
  146|    141|    spdm_test_context = *State;
  147|    141|    spdm_context = spdm_test_context->spdm_context;
  148|    141|    encap_request_size = spdm_test_context->test_buffer_size;
  149|       |
  150|    141|    if (encap_request_size < sizeof(spdm_key_update_request_t)) {
  ------------------
  |  Branch (150:9): [True: 0, False: 141]
  ------------------
  151|      0|        encap_request_size = sizeof(spdm_key_update_request_t);
  152|      0|    }
  153|    141|    spdm_request = malloc(encap_request_size);
  154|       |
  155|    141|    spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
  156|    141|    spdm_context->connection_info.capability.flags |=
  157|    141|        SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP;
  ------------------
  |  |  195|    141|#define SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP 0x00004000
  ------------------
  158|    141|    spdm_context->local_context.capability.flags |=
  159|    141|        SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_UPD_CAP;
  ------------------
  |  |  257|    141|#define SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_UPD_CAP 0x00004000
  ------------------
  160|    141|    spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
  ------------------
  |  |  111|    141|#define SPDM_MESSAGE_VERSION_11 0x11
  ------------------
  161|    141|                                            SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    141|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
  162|    141|    libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
  163|    141|                                                    m_libspdm_use_asym_algo, &data,
  164|    141|                                                    &data_size,
  165|    141|                                                    NULL, NULL);
  166|    141|    spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
  167|    141|    spdm_context->local_context.local_cert_chain_provision[0] = data;
  168|    141|    spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
  169|    141|    spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
  170|    141|    libspdm_reset_message_b(spdm_context);
  171|       |
  172|    141|    session_id = 0xFFFFFFFF;
  173|    141|    spdm_context->latest_session_id = session_id;
  174|    141|    spdm_context->last_spdm_request_session_id_valid = true;
  175|    141|    spdm_context->last_spdm_request_session_id = session_id;
  176|    141|    session_info = &spdm_context->session_info[0];
  177|    141|    libspdm_session_info_init(spdm_context, session_info, session_id, true);
  178|    141|    libspdm_secured_message_set_session_state(session_info->secured_message_context,
  179|    141|                                              LIBSPDM_SESSION_STATE_ESTABLISHED);
  180|    141|    libspdm_get_encap_request_key_update(spdm_context, &encap_request_size, spdm_request);
  181|    141|    free(spdm_request);
  182|    141|    free(data);
  183|    141|}
libspdm_test_get_encap_request_key_update_case2:
  186|    141|{
  187|    141|    libspdm_test_context_t *spdm_test_context;
  188|    141|    spdm_key_update_request_t *spdm_request;
  189|    141|    libspdm_context_t *spdm_context;
  190|    141|    size_t encap_request_size;
  191|    141|    void *data;
  192|    141|    size_t data_size;
  193|    141|    uint32_t session_id;
  194|    141|    libspdm_session_info_t *session_info;
  195|       |
  196|    141|    spdm_test_context = *State;
  197|    141|    spdm_context = spdm_test_context->spdm_context;
  198|    141|    encap_request_size = spdm_test_context->test_buffer_size;
  199|       |
  200|    141|    if (encap_request_size < sizeof(spdm_key_update_request_t)) {
  ------------------
  |  Branch (200:9): [True: 0, False: 141]
  ------------------
  201|      0|        encap_request_size = sizeof(spdm_key_update_request_t);
  202|      0|    }
  203|    141|    spdm_request = malloc(encap_request_size);
  204|       |
  205|    141|    spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
  206|    141|    spdm_context->connection_info.capability.flags |=
  207|    141|        SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP;
  ------------------
  |  |  195|    141|#define SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP 0x00004000
  ------------------
  208|    141|    spdm_context->local_context.capability.flags |=
  209|    141|        SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_UPD_CAP;
  ------------------
  |  |  257|    141|#define SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_UPD_CAP 0x00004000
  ------------------
  210|    141|    spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
  ------------------
  |  |  111|    141|#define SPDM_MESSAGE_VERSION_11 0x11
  ------------------
  211|    141|                                            SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    141|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
  212|    141|    libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
  213|    141|                                                    m_libspdm_use_asym_algo, &data,
  214|    141|                                                    &data_size,
  215|    141|                                                    NULL, NULL);
  216|    141|    spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
  217|    141|    spdm_context->local_context.local_cert_chain_provision[0] = data;
  218|    141|    spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
  219|    141|    spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
  220|    141|    libspdm_reset_message_b(spdm_context);
  221|       |
  222|    141|    spdm_context->encap_context.last_encap_request_header.request_response_code = SPDM_KEY_UPDATE;
  ------------------
  |  |   82|    141|#define SPDM_KEY_UPDATE 0xE9
  ------------------
  223|       |
  224|    141|    session_id = 0xFFFFFFFF;
  225|    141|    spdm_context->latest_session_id = session_id;
  226|    141|    spdm_context->last_spdm_request_session_id_valid = true;
  227|    141|    spdm_context->last_spdm_request_session_id = session_id;
  228|    141|    session_info = &spdm_context->session_info[0];
  229|    141|    libspdm_session_info_init(spdm_context, session_info, session_id, true);
  230|    141|    libspdm_secured_message_set_session_state(session_info->secured_message_context,
  231|    141|                                              LIBSPDM_SESSION_STATE_ESTABLISHED);
  232|    141|    libspdm_get_encap_request_key_update(spdm_context, &encap_request_size, spdm_request);
  233|    141|    free(spdm_request);
  234|    141|    free(data);
  235|    141|}
libspdm_run_test_harness:
  238|    141|{
  239|    141|    void *State;
  240|       |
  241|    141|    libspdm_setup_test_context(&m_libspdm_responder_encap_get_digests_test_context);
  242|       |
  243|    141|    m_libspdm_responder_encap_get_digests_test_context.test_buffer = test_buffer;
  244|    141|    m_libspdm_responder_encap_get_digests_test_context.test_buffer_size = test_buffer_size;
  245|       |
  246|       |    /* Success Case */
  247|    141|    libspdm_unit_test_group_setup(&State);
  248|    141|    libspdm_test_process_encap_response_key_update_case1(&State);
  249|    141|    libspdm_unit_test_group_teardown(&State);
  250|       |
  251|       |    /* Success Case */
  252|    141|    libspdm_unit_test_group_setup(&State);
  253|    141|    libspdm_test_get_encap_request_key_update_case1(&State);
  254|    141|    libspdm_unit_test_group_teardown(&State);
  255|       |
  256|       |    /* request_response_code: SPDM_KEY_UPDATE */
  257|    141|    libspdm_unit_test_group_setup(&State);
  258|    141|    libspdm_test_get_encap_request_key_update_case2(&State);
  259|    141|    libspdm_unit_test_group_teardown(&State);
  260|    141|}
encap_key_update.c:libspdm_set_standard_key_update_test_state:
   16|    141|{
   17|    141|    libspdm_session_info_t *session_info;
   18|       |
   19|    141|    spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
   20|    141|    spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
   21|    141|    spdm_context->connection_info.capability.flags |=
   22|    141|        SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_UPD_CAP;
  ------------------
  |  |  257|    141|#define SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_UPD_CAP 0x00004000
  ------------------
   23|    141|    spdm_context->connection_info.capability.flags |=
   24|    141|        SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
  ------------------
  |  |  248|    141|#define SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP 0x00000040
  ------------------
   25|    141|    spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
  ------------------
  |  |  249|    141|#define SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP 0x00000080
  ------------------
   26|    141|    spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP;
  ------------------
  |  |  195|    141|#define SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP 0x00004000
  ------------------
   27|    141|    spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
  ------------------
  |  |  187|    141|#define SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP 0x00000040
  ------------------
   28|    141|    spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
  ------------------
  |  |  188|    141|#define SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP 0x00000080
  ------------------
   29|       |
   30|    141|    spdm_context->transcript.message_a.buffer_size = 0;
   31|    141|    spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
   32|    141|    spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
   33|    141|    spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
   34|    141|    spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
   35|       |
   36|    141|    *session_id = 0xFFFFFFFF;
   37|    141|    spdm_context->latest_session_id = *session_id;
   38|    141|    spdm_context->last_spdm_request_session_id_valid = true;
   39|    141|    spdm_context->last_spdm_request_session_id = *session_id;
   40|    141|    session_info = &spdm_context->session_info[0];
   41|    141|    libspdm_session_info_init(spdm_context, session_info, *session_id, true);
   42|    141|    libspdm_secured_message_set_session_state(session_info->secured_message_context,
   43|    141|                                              LIBSPDM_SESSION_STATE_ESTABLISHED);
   44|    141|}
encap_key_update.c:libspdm_set_standard_key_update_test_secrets:
   50|    141|{
   51|    141|    libspdm_set_mem(m_rsp_secret_buffer, secured_message_context->hash_size, rsp_secret_fill);
   52|    141|    libspdm_set_mem(m_req_secret_buffer, secured_message_context->hash_size, req_secret_fill);
   53|       |
   54|    141|    libspdm_copy_mem(secured_message_context->application_secret.response_data_secret,
   55|    141|                     sizeof(secured_message_context->application_secret.response_data_secret),
   56|    141|                     m_rsp_secret_buffer, secured_message_context->aead_key_size);
   57|    141|    libspdm_copy_mem(secured_message_context->application_secret.request_data_secret,
   58|    141|                     sizeof(secured_message_context->application_secret.request_data_secret),
   59|    141|                     m_req_secret_buffer, secured_message_context->aead_key_size);
   60|       |
   61|    141|    libspdm_set_mem(secured_message_context->application_secret.response_data_encryption_key,
   62|    141|                    secured_message_context->aead_key_size, (uint8_t)(0xFF));
   63|    141|    libspdm_set_mem(secured_message_context->application_secret.response_data_salt,
   64|    141|                    secured_message_context->aead_iv_size, (uint8_t)(0xFF));
   65|       |
   66|    141|    libspdm_set_mem(secured_message_context->application_secret.request_data_encryption_key,
   67|    141|                    secured_message_context->aead_key_size, (uint8_t)(0xEE));
   68|    141|    libspdm_set_mem(secured_message_context->application_secret.request_data_salt,
   69|    141|                    secured_message_context->aead_iv_size, (uint8_t)(0xEE));
   70|       |
   71|    141|    secured_message_context->application_secret.response_data_sequence_number = 0;
   72|    141|    secured_message_context->application_secret.request_data_sequence_number = 0;
   73|    141|}
encap_key_update.c:libspdm_compute_secret_update:
   78|    141|{
   79|    141|    uint8_t bin_str9[128];
   80|    141|    size_t bin_str9_size;
   81|       |
   82|    141|    bin_str9_size = sizeof(bin_str9);
   83|    141|    libspdm_bin_concat(spdm_version,
   84|    141|                       SPDM_BIN_STR_9_LABEL, sizeof(SPDM_BIN_STR_9_LABEL) - 1,
  ------------------
  |  | 1508|    141|#define SPDM_BIN_STR_9_LABEL "traffic upd"
  ------------------
                                     SPDM_BIN_STR_9_LABEL, sizeof(SPDM_BIN_STR_9_LABEL) - 1,
  ------------------
  |  | 1508|    141|#define SPDM_BIN_STR_9_LABEL "traffic upd"
  ------------------
   85|    141|                       NULL, (uint16_t)hash_size, hash_size, bin_str9,
   86|    141|                       &bin_str9_size);
   87|       |
   88|    141|    libspdm_hkdf_expand(m_libspdm_use_hash_algo, in_secret, hash_size, bin_str9, bin_str9_size,
   89|    141|                        out_secret, out_secret_size);
   90|    141|}

