libspdm_get_scratch_buffer_secure_message_capacity:
   17|  8.38k|uint32_t libspdm_get_scratch_buffer_secure_message_capacity(libspdm_context_t *spdm_context) {
   18|  8.38k|    return spdm_context->local_context.capability.max_spdm_msg_size +
   19|  8.38k|           spdm_context->local_context.capability.transport_header_size +
   20|  8.38k|           spdm_context->local_context.capability.transport_tail_size;
   21|  8.38k|}
libspdm_get_scratch_buffer_large_message_capacity:
   28|  8.38k|uint32_t libspdm_get_scratch_buffer_large_message_capacity(libspdm_context_t *spdm_context) {
   29|  8.38k|    return spdm_context->local_context.capability.max_spdm_msg_size;
   30|  8.38k|}
libspdm_get_scratch_buffer_sender_receiver_capacity:
   43|  8.38k|uint32_t libspdm_get_scratch_buffer_sender_receiver_capacity(libspdm_context_t *spdm_context) {
   44|  8.38k|    return spdm_context->local_context.capability.max_spdm_msg_size +
   45|  8.38k|           spdm_context->local_context.capability.transport_header_size +
   46|  8.38k|           spdm_context->local_context.capability.transport_tail_size;
   47|  8.38k|}
libspdm_get_scratch_buffer_large_sender_receiver_capacity:
   58|  8.38k|{
   59|  8.38k|    return spdm_context->local_context.capability.max_spdm_msg_size +
   60|  8.38k|           spdm_context->local_context.capability.transport_header_size +
   61|  8.38k|           spdm_context->local_context.capability.transport_tail_size;
   62|  8.38k|}
libspdm_get_scratch_buffer_last_spdm_request_offset:
   66|  2.79k|uint32_t libspdm_get_scratch_buffer_last_spdm_request_offset(libspdm_context_t *spdm_context) {
   67|  2.79k|    return 0 +
   68|  2.79k|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
   69|  2.79k|           libspdm_get_scratch_buffer_secure_message_capacity(spdm_context) +
   70|  2.79k|           libspdm_get_scratch_buffer_large_message_capacity(spdm_context) +
   71|  2.79k|#endif
   72|  2.79k|           libspdm_get_scratch_buffer_sender_receiver_capacity(spdm_context) +
   73|  2.79k|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
   74|  2.79k|           libspdm_get_scratch_buffer_large_sender_receiver_capacity(spdm_context) +
   75|  2.79k|#endif
   76|  2.79k|           0;
   77|  2.79k|}
libspdm_get_scratch_buffer_last_spdm_request_capacity:
   79|  5.59k|uint32_t libspdm_get_scratch_buffer_last_spdm_request_capacity(libspdm_context_t *spdm_context) {
   80|  5.59k|    return spdm_context->local_context.capability.max_spdm_msg_size;
   81|  5.59k|}
libspdm_get_scratch_buffer_cache_spdm_request_offset:
   85|  2.79k|uint32_t libspdm_get_scratch_buffer_cache_spdm_request_offset(libspdm_context_t *spdm_context) {
   86|  2.79k|    return 0 +
   87|  2.79k|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
   88|  2.79k|           libspdm_get_scratch_buffer_secure_message_capacity(spdm_context) +
   89|  2.79k|           libspdm_get_scratch_buffer_large_message_capacity(spdm_context) +
   90|  2.79k|#endif
   91|  2.79k|           libspdm_get_scratch_buffer_sender_receiver_capacity(spdm_context) +
   92|  2.79k|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
   93|  2.79k|           libspdm_get_scratch_buffer_large_sender_receiver_capacity(spdm_context) +
   94|  2.79k|#endif
   95|  2.79k|           libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context) +
   96|  2.79k|           0;
   97|  2.79k|}
libspdm_get_scratch_buffer_cache_spdm_request_capacity:
   99|  2.79k|uint32_t libspdm_get_scratch_buffer_cache_spdm_request_capacity(libspdm_context_t *spdm_context) {
  100|  2.79k|    return spdm_context->local_context.capability.max_spdm_msg_size;
  101|  2.79k|}
libspdm_get_scratch_buffer_capacity:
  105|  2.79k|uint32_t libspdm_get_scratch_buffer_capacity(libspdm_context_t *spdm_context) {
  106|  2.79k|    return 0 +
  107|  2.79k|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
  108|  2.79k|           libspdm_get_scratch_buffer_secure_message_capacity(spdm_context) +
  109|  2.79k|           libspdm_get_scratch_buffer_large_message_capacity(spdm_context) +
  110|  2.79k|#endif
  111|  2.79k|           libspdm_get_scratch_buffer_sender_receiver_capacity(spdm_context) +
  112|  2.79k|#if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
  113|  2.79k|           libspdm_get_scratch_buffer_large_sender_receiver_capacity(spdm_context) +
  114|  2.79k|#endif
  115|  2.79k|           libspdm_get_scratch_buffer_last_spdm_request_capacity(spdm_context) +
  116|  2.79k|#if LIBSPDM_RESPOND_IF_READY_SUPPORT
  117|  2.79k|           libspdm_get_scratch_buffer_cache_spdm_request_capacity(spdm_context) +
  118|  2.79k|#endif
  119|  2.79k|           0;
  120|  2.79k|}
libspdm_reset_message_b:
 1280|  1.39k|{
 1281|       |#if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
 1282|       |    libspdm_reset_managed_buffer(&spdm_context->transcript.message_b);
 1283|       |#else
 1284|  1.39k|    if (spdm_context->transcript.digest_context_m1m2 != NULL) {
  ------------------
  |  Branch (1284:9): [True: 0, False: 1.39k]
  ------------------
 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|  1.39k|#endif
 1290|  1.39k|}
libspdm_reset_message_mut_b:
 1316|  2.79k|{
 1317|       |#if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
 1318|       |    libspdm_reset_managed_buffer(&spdm_context->transcript.message_mut_b);
 1319|       |#else
 1320|  2.79k|    if (spdm_context->transcript.digest_context_mut_m1m2 != NULL) {
  ------------------
  |  Branch (1320:9): [True: 1.64k, False: 1.15k]
  ------------------
 1321|  1.64k|        libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
 1322|  1.64k|                           spdm_context->transcript.digest_context_mut_m1m2);
 1323|  1.64k|        spdm_context->transcript.digest_context_mut_m1m2 = NULL;
 1324|  1.64k|    }
 1325|  2.79k|#endif
 1326|  2.79k|}
libspdm_append_message_mut_b:
 1762|  1.64k|{
 1763|       |#if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
 1764|       |    return libspdm_append_managed_buffer(&spdm_context->transcript.message_mut_b,
 1765|       |                                         message, message_size);
 1766|       |#else
 1767|  1.64k|    {
 1768|  1.64k|        bool result;
 1769|       |
 1770|  1.64k|        if (spdm_context->transcript.digest_context_mut_m1m2 == NULL) {
  ------------------
  |  Branch (1770:13): [True: 1.64k, False: 0]
  ------------------
 1771|  1.64k|            spdm_context->transcript.digest_context_mut_m1m2 = libspdm_hash_new (
 1772|  1.64k|                spdm_context->connection_info.algorithm.base_hash_algo);
 1773|  1.64k|            if (spdm_context->transcript.digest_context_mut_m1m2 == NULL) {
  ------------------
  |  Branch (1773:17): [True: 0, False: 1.64k]
  ------------------
 1774|      0|                return LIBSPDM_STATUS_CRYPTO_ERROR;
  ------------------
  |  |  156|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CRYPTO, 0x0000)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
 1775|      0|            }
 1776|  1.64k|            result = libspdm_hash_init (spdm_context->connection_info.algorithm.base_hash_algo,
 1777|  1.64k|                                        spdm_context->transcript.digest_context_mut_m1m2);
 1778|  1.64k|            if (!result) {
  ------------------
  |  Branch (1778:17): [True: 0, False: 1.64k]
  ------------------
 1779|      0|                libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
 1780|      0|                                   spdm_context->transcript.digest_context_mut_m1m2);
 1781|      0|                spdm_context->transcript.digest_context_mut_m1m2 = NULL;
 1782|      0|                return LIBSPDM_STATUS_CRYPTO_ERROR;
  ------------------
  |  |  156|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CRYPTO, 0x0000)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
 1783|      0|            }
 1784|  1.64k|            if ((spdm_context->connection_info.version >> SPDM_VERSION_NUMBER_SHIFT_BIT) >
  ------------------
  |  |  140|  1.64k|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
  |  Branch (1784:17): [True: 0, False: 1.64k]
  ------------------
 1785|  1.64k|                SPDM_MESSAGE_VERSION_11) {
  ------------------
  |  |  111|  1.64k|#define SPDM_MESSAGE_VERSION_11 0x11
  ------------------
 1786|       |
 1787|       |                /* Need append VCA since 1.2 script */
 1788|      0|                result = libspdm_hash_update (
 1789|      0|                    spdm_context->connection_info.algorithm.base_hash_algo,
 1790|      0|                    spdm_context->transcript.digest_context_mut_m1m2,
 1791|      0|                    libspdm_get_managed_buffer(&spdm_context->transcript.message_a),
 1792|      0|                    libspdm_get_managed_buffer_size(&spdm_context->transcript.
 1793|      0|                                                    message_a));
 1794|      0|                if (!result) {
  ------------------
  |  Branch (1794:21): [True: 0, False: 0]
  ------------------
 1795|      0|                    libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
 1796|      0|                                       spdm_context->transcript.digest_context_mut_m1m2);
 1797|      0|                    spdm_context->transcript.digest_context_mut_m1m2 = NULL;
 1798|      0|                    return LIBSPDM_STATUS_CRYPTO_ERROR;
  ------------------
  |  |  156|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CRYPTO, 0x0000)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
 1799|      0|                }
 1800|      0|            }
 1801|  1.64k|        }
 1802|       |
 1803|  1.64k|        result = libspdm_hash_update (spdm_context->connection_info.algorithm.base_hash_algo,
 1804|  1.64k|                                      spdm_context->transcript.digest_context_mut_m1m2, message,
 1805|  1.64k|                                      message_size);
 1806|  1.64k|        if (!result) {
  ------------------
  |  Branch (1806:13): [True: 0, False: 1.64k]
  ------------------
 1807|      0|            libspdm_hash_free (spdm_context->connection_info.algorithm.base_hash_algo,
 1808|      0|                               spdm_context->transcript.digest_context_mut_m1m2);
 1809|      0|            spdm_context->transcript.digest_context_mut_m1m2 = NULL;
 1810|      0|            return LIBSPDM_STATUS_CRYPTO_ERROR;
  ------------------
  |  |  156|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CRYPTO, 0x0000)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
 1811|      0|        }
 1812|       |
 1813|  1.64k|        return LIBSPDM_STATUS_SUCCESS;
  ------------------
  |  |   59|  1.64k|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_SUCCESS, LIBSPDM_SOURCE_SUCCESS, 0x0000)
  |  |  ------------------
  |  |  |  |   55|  1.64k|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
 1814|  1.64k|    }
 1815|  1.64k|#endif
 1816|  1.64k|}
libspdm_get_connection_version:
 2632|  2.79k|{
 2633|  2.79k|    return (uint8_t)(spdm_context->connection_info.version >> SPDM_VERSION_NUMBER_SHIFT_BIT);
  ------------------
  |  |  140|  2.79k|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 2634|  2.79k|}
libspdm_register_device_io_func:
 2720|  2.79k|{
 2721|  2.79k|    libspdm_context_t *context;
 2722|       |
 2723|  2.79k|    context = spdm_context;
 2724|  2.79k|    context->send_message = send_message;
 2725|  2.79k|    context->receive_message = receive_message;
 2726|  2.79k|}
libspdm_register_device_buffer_func:
 2779|  2.79k|{
 2780|  2.79k|    libspdm_context_t *context;
 2781|       |
 2782|  2.79k|    context = spdm_context;
 2783|  2.79k|    context->sender_buffer_size = sender_buffer_size;
 2784|  2.79k|    context->receiver_buffer_size = receiver_buffer_size;
 2785|  2.79k|    context->acquire_sender_buffer = acquire_sender_buffer;
 2786|  2.79k|    context->release_sender_buffer = release_sender_buffer;
 2787|  2.79k|    context->acquire_receiver_buffer = acquire_receiver_buffer;
 2788|  2.79k|    context->release_receiver_buffer = release_receiver_buffer;
 2789|       |
 2790|  2.79k|    LIBSPDM_ASSERT (sender_buffer_size >=
 2791|  2.79k|                    context->local_context.capability.transport_header_size +
 2792|  2.79k|                    context->local_context.capability.transport_tail_size);
 2793|  2.79k|    sender_buffer_size -= (context->local_context.capability.transport_header_size +
 2794|  2.79k|                           context->local_context.capability.transport_tail_size);
 2795|  2.79k|    LIBSPDM_ASSERT (sender_buffer_size >= SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12);
 2796|  2.79k|    context->local_context.capability.sender_data_transfer_size = sender_buffer_size;
 2797|       |
 2798|  2.79k|    LIBSPDM_ASSERT(receiver_buffer_size >=
 2799|  2.79k|                   context->local_context.capability.transport_header_size +
 2800|  2.79k|                   context->local_context.capability.transport_tail_size);
 2801|  2.79k|    receiver_buffer_size -= (context->local_context.capability.transport_header_size +
 2802|  2.79k|                             context->local_context.capability.transport_tail_size);
 2803|  2.79k|    LIBSPDM_ASSERT (receiver_buffer_size >= SPDM_MIN_DATA_TRANSFER_SIZE_VERSION_12);
 2804|  2.79k|    context->local_context.capability.data_transfer_size = receiver_buffer_size;
 2805|  2.79k|}
libspdm_register_transport_layer_func:
 2823|  2.79k|{
 2824|  2.79k|    libspdm_context_t *context;
 2825|       |
 2826|  2.79k|    context = spdm_context;
 2827|       |
 2828|       |    /* fix the data_transfer_size if it is set before */
 2829|  2.79k|    if ((context->local_context.capability.data_transfer_size != 0) &&
  ------------------
  |  Branch (2829:9): [True: 0, False: 2.79k]
  ------------------
 2830|  2.79k|        (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|  2.79k|    if ((context->local_context.capability.sender_data_transfer_size != 0) &&
  ------------------
  |  Branch (2836:9): [True: 0, False: 2.79k]
  ------------------
 2837|  2.79k|        (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|  2.79k|    context->local_context.capability.max_spdm_msg_size = max_spdm_msg_size;
 2845|  2.79k|    context->local_context.capability.transport_header_size = transport_header_size;
 2846|  2.79k|    context->local_context.capability.transport_tail_size = transport_tail_size;
 2847|  2.79k|    context->transport_encode_message = transport_encode_message;
 2848|  2.79k|    context->transport_decode_message = transport_decode_message;
 2849|  2.79k|}
libspdm_register_verify_spdm_cert_chain_func:
 2868|    699|{
 2869|    699|    libspdm_context_t *context;
 2870|       |
 2871|    699|    context = spdm_context;
 2872|    699|    context->local_context.verify_peer_spdm_cert_chain = verify_spdm_cert_chain;
 2873|    699|}
libspdm_get_sizeof_required_scratch_buffer:
 2886|  2.79k|{
 2887|  2.79k|    libspdm_context_t *context;
 2888|  2.79k|    size_t scratch_buffer_size;
 2889|       |
 2890|  2.79k|    context = spdm_context;
 2891|  2.79k|    LIBSPDM_ASSERT (context->local_context.capability.max_spdm_msg_size != 0);
 2892|       |
 2893|  2.79k|    scratch_buffer_size = libspdm_get_scratch_buffer_capacity(context);
 2894|  2.79k|    return scratch_buffer_size;
 2895|  2.79k|}
libspdm_set_scratch_buffer:
 2911|  2.79k|{
 2912|  2.79k|    libspdm_context_t *context;
 2913|       |
 2914|  2.79k|    context = spdm_context;
 2915|  2.79k|    LIBSPDM_ASSERT (context->local_context.capability.max_spdm_msg_size != 0);
 2916|  2.79k|    LIBSPDM_ASSERT (scratch_buffer_size >= libspdm_get_scratch_buffer_capacity(spdm_context));
 2917|  2.79k|    context->scratch_buffer = scratch_buffer;
 2918|  2.79k|    context->scratch_buffer_size = scratch_buffer_size;
 2919|  2.79k|    context->last_spdm_request = (uint8_t *)scratch_buffer +
 2920|  2.79k|                                 libspdm_get_scratch_buffer_last_spdm_request_offset(spdm_context);
 2921|  2.79k|#if LIBSPDM_RESPOND_IF_READY_SUPPORT
 2922|  2.79k|    context->cache_spdm_request = (uint8_t *)scratch_buffer +
 2923|  2.79k|                                  libspdm_get_scratch_buffer_cache_spdm_request_offset(spdm_context);
 2924|  2.79k|#endif
 2925|  2.79k|}
libspdm_init_context_with_secured_context:
 3240|  2.79k|{
 3241|  2.79k|    libspdm_context_t *context;
 3242|  2.79k|    size_t index;
 3243|       |
 3244|  2.79k|    LIBSPDM_ASSERT(spdm_context != NULL);
 3245|  2.79k|    LIBSPDM_ASSERT(secured_contexts != NULL);
 3246|  2.79k|    LIBSPDM_ASSERT(num_secured_contexts == LIBSPDM_MAX_SESSION_COUNT);
 3247|       |
 3248|  2.79k|    context = spdm_context;
 3249|  2.79k|    libspdm_zero_mem(context, sizeof(libspdm_context_t));
 3250|  2.79k|    context->version = LIBSPDM_CONTEXT_STRUCT_VERSION;
  ------------------
  |  |  527|  2.79k|#define LIBSPDM_CONTEXT_STRUCT_VERSION 0x3
  ------------------
 3251|  2.79k|    context->transcript.message_a.max_buffer_size =
 3252|  2.79k|        sizeof(context->transcript.message_a.buffer);
 3253|  2.79k|    context->transcript.message_d.max_buffer_size =
 3254|  2.79k|        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|  2.79k|    context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
 3272|  2.79k|    context->local_context.version.spdm_version_count = SPDM_MAX_VERSION_COUNT;
  ------------------
  |  |   17|  2.79k|#define SPDM_MAX_VERSION_COUNT 4
  ------------------
 3273|  2.79k|    context->local_context.version.spdm_version[0] = SPDM_MESSAGE_VERSION_10 <<
  ------------------
  |  |  110|  2.79k|#define SPDM_MESSAGE_VERSION_10 0x10
  ------------------
 3274|  2.79k|                                                     SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|  2.79k|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3275|  2.79k|    context->local_context.version.spdm_version[1] = SPDM_MESSAGE_VERSION_11 <<
  ------------------
  |  |  111|  2.79k|#define SPDM_MESSAGE_VERSION_11 0x11
  ------------------
 3276|  2.79k|                                                     SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|  2.79k|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3277|  2.79k|    context->local_context.version.spdm_version[2] = SPDM_MESSAGE_VERSION_12 <<
  ------------------
  |  |  112|  2.79k|#define SPDM_MESSAGE_VERSION_12 0x12
  ------------------
 3278|  2.79k|                                                     SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|  2.79k|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3279|  2.79k|    context->local_context.version.spdm_version[3] = SPDM_MESSAGE_VERSION_13 <<
  ------------------
  |  |  113|  2.79k|#define SPDM_MESSAGE_VERSION_13 0x13
  ------------------
 3280|  2.79k|                                                     SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|  2.79k|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3281|  2.79k|    context->local_context.secured_message_version.spdm_version_count =
 3282|  2.79k|        SECURED_SPDM_MAX_VERSION_COUNT;
  ------------------
  |  |   55|  2.79k|#define SECURED_SPDM_MAX_VERSION_COUNT 3
  ------------------
 3283|  2.79k|    context->local_context.secured_message_version.spdm_version[0] =
 3284|  2.79k|        SECURED_SPDM_VERSION_10 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |   57|  2.79k|#define SECURED_SPDM_VERSION_10 0x10
  ------------------
                      SECURED_SPDM_VERSION_10 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|  2.79k|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3285|  2.79k|    context->local_context.secured_message_version.spdm_version[1] =
 3286|  2.79k|        SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |   58|  2.79k|#define SECURED_SPDM_VERSION_11 0x11
  ------------------
                      SECURED_SPDM_VERSION_11 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|  2.79k|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3287|  2.79k|    context->local_context.secured_message_version.spdm_version[2] =
 3288|  2.79k|        SECURED_SPDM_VERSION_12 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |   59|  2.79k|#define SECURED_SPDM_VERSION_12 0x12
  ------------------
                      SECURED_SPDM_VERSION_12 << SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|  2.79k|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
 3289|  2.79k|    context->local_context.capability.st1 = SPDM_ST1_VALUE_US;
  ------------------
  |  | 1514|  2.79k|#define SPDM_ST1_VALUE_US 100000
  ------------------
 3290|       |
 3291|  2.79k|    context->mut_auth_cert_chain_buffer_size = 0;
 3292|       |
 3293|  2.79k|    context->max_spdm_session_sequence_number = LIBSPDM_MAX_SPDM_SESSION_SEQUENCE_NUMBER;
  ------------------
  |  |   39|  2.79k|#define LIBSPDM_MAX_SPDM_SESSION_SEQUENCE_NUMBER 0xFFFFFFFFFFFFFFFFull
  ------------------
 3294|       |
 3295|  2.79k|    context->latest_session_id = INVALID_SESSION_ID;
  ------------------
  |  |   28|  2.79k|#define INVALID_SESSION_ID 0
  ------------------
 3296|  2.79k|    context->last_spdm_request_session_id = INVALID_SESSION_ID;
  ------------------
  |  |   28|  2.79k|#define INVALID_SESSION_ID 0
  ------------------
 3297|  2.79k|    context->last_spdm_request_session_id_valid = false;
 3298|  2.79k|    context->last_spdm_request_size = 0;
 3299|       |
 3300|       |    /* To be updated in libspdm_register_device_buffer_func */
 3301|  2.79k|    context->local_context.capability.data_transfer_size = 0;
 3302|  2.79k|    context->local_context.capability.sender_data_transfer_size = 0;
 3303|  2.79k|    context->local_context.capability.max_spdm_msg_size = 0;
 3304|       |
 3305|  13.9k|    for (index = 0; index < num_secured_contexts; index++) {
  ------------------
  |  Branch (3305:21): [True: 11.1k, False: 2.79k]
  ------------------
 3306|  11.1k|        if (secured_contexts[index] == NULL) {
  ------------------
  |  Branch (3306:13): [True: 0, False: 11.1k]
  ------------------
 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|  11.1k|        context->session_info[index].secured_message_context = secured_contexts[index];
 3311|  11.1k|        libspdm_secured_message_init_context(
 3312|  11.1k|            context->session_info[index].secured_message_context);
 3313|  11.1k|    }
 3314|       |
 3315|  2.79k|    return LIBSPDM_STATUS_SUCCESS;
  ------------------
  |  |   59|  2.79k|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_SUCCESS, LIBSPDM_SOURCE_SUCCESS, 0x0000)
  |  |  ------------------
  |  |  |  |   55|  2.79k|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
 3316|  2.79k|}
libspdm_init_context:
 3331|  2.79k|{
 3332|  2.79k|    libspdm_context_t *context;
 3333|  2.79k|    void *secured_context;
 3334|  2.79k|    void *secured_contexts[LIBSPDM_MAX_SESSION_COUNT];
 3335|  2.79k|    size_t secured_context_size;
 3336|  2.79k|    size_t index;
 3337|       |
 3338|  2.79k|    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|  2.79k|    context = spdm_context;
 3343|  2.79k|    secured_context = (void *)((size_t)(context + 1));
 3344|  2.79k|    secured_context_size = libspdm_secured_message_get_context_size();
 3345|       |
 3346|  13.9k|    for (index = 0; index < LIBSPDM_MAX_SESSION_COUNT; index++)
  ------------------
  |  |  198|  13.9k|#define LIBSPDM_MAX_SESSION_COUNT 4
  ------------------
  |  Branch (3346:21): [True: 11.1k, False: 2.79k]
  ------------------
 3347|  11.1k|    {
 3348|  11.1k|        secured_contexts[index] = (uint8_t *)secured_context + secured_context_size * index;
 3349|  11.1k|    }
 3350|       |
 3351|  2.79k|    return libspdm_init_context_with_secured_context(spdm_context,
 3352|  2.79k|                                                     secured_contexts,
 3353|  2.79k|                                                     LIBSPDM_MAX_SESSION_COUNT);
  ------------------
  |  |  198|  2.79k|#define LIBSPDM_MAX_SESSION_COUNT 4
  ------------------
 3354|  2.79k|}
libspdm_get_context_size:
 3467|  2.79k|{
 3468|  2.79k|    size_t size;
 3469|       |
 3470|  2.79k|    size = sizeof(libspdm_context_t) +
 3471|  2.79k|           libspdm_secured_message_get_context_size() * LIBSPDM_MAX_SESSION_COUNT;
  ------------------
  |  |  198|  2.79k|#define LIBSPDM_MAX_SESSION_COUNT 4
  ------------------
 3472|  2.79k|    LIBSPDM_ASSERT (size == LIBSPDM_CONTEXT_SIZE_ALL);
 3473|  2.79k|    return size;
 3474|  2.79k|}

libspdm_verify_peer_cert_chain_buffer_integrity:
  787|    727|{
  788|    727|    bool result;
  789|    727|    bool is_device_cert_model;
  790|    727|    bool is_requester;
  791|       |
  792|    727|    is_requester = spdm_context->local_context.is_requester;
  793|       |
  794|    727|    is_device_cert_model = false;
  795|       |    /* Responder does not determine Requester's certificate model */
  796|    727|    if (is_requester) {
  ------------------
  |  Branch (796:9): [True: 0, False: 727]
  ------------------
  797|      0|        if((spdm_context->connection_info.capability.flags &
  ------------------
  |  Branch (797:12): [True: 0, False: 0]
  ------------------
  798|      0|            SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ALIAS_CERT_CAP) == 0) {
  ------------------
  |  |  275|      0|#define SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ALIAS_CERT_CAP 0x00040000
  ------------------
  799|      0|            is_device_cert_model = true;
  800|      0|        }
  801|      0|    }
  802|       |
  803|    727|    if (is_requester) {
  ------------------
  |  Branch (803:9): [True: 0, False: 727]
  ------------------
  804|      0|        result = libspdm_verify_certificate_chain_buffer(
  805|      0|            spdm_context->connection_info.algorithm.base_hash_algo,
  806|      0|            spdm_context->connection_info.algorithm.base_asym_algo,
  807|      0|            cert_chain_buffer, cert_chain_buffer_size,
  808|      0|            false, is_device_cert_model);
  809|    727|    } else {
  810|    727|        result = libspdm_verify_certificate_chain_buffer(
  811|    727|            spdm_context->connection_info.algorithm.base_hash_algo,
  812|    727|            spdm_context->connection_info.algorithm.req_base_asym_alg,
  813|    727|            cert_chain_buffer, cert_chain_buffer_size,
  814|    727|            true, is_device_cert_model);
  815|    727|    }
  816|       |
  817|    727|    return result;
  818|    727|}

libspdm_asym_free:
  362|  4.89k|{
  363|  4.89k|    if (context == NULL) {
  ------------------
  |  Branch (363:9): [True: 1.58k, False: 3.31k]
  ------------------
  364|  1.58k|        return;
  365|  1.58k|    }
  366|  3.31k|    switch (base_asym_algo) {
  367|  2.61k|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
  ------------------
  |  |  371|  2.61k|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048 0x00000001
  ------------------
  |  Branch (367:5): [True: 2.61k, False: 699]
  ------------------
  368|  2.61k|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
  ------------------
  |  |  373|  2.61k|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072 0x00000004
  ------------------
  |  Branch (368:5): [True: 0, False: 3.31k]
  ------------------
  369|  2.61k|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
  ------------------
  |  |  376|  2.61k|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096 0x00000020
  ------------------
  |  Branch (369:5): [True: 0, False: 3.31k]
  ------------------
  370|  2.61k|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
  ------------------
  |  |  372|  2.61k|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048 0x00000002
  ------------------
  |  Branch (370:5): [True: 0, False: 3.31k]
  ------------------
  371|  2.61k|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
  ------------------
  |  |  374|  2.61k|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072 0x00000008
  ------------------
  |  Branch (371:5): [True: 0, False: 3.31k]
  ------------------
  372|  2.61k|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
  ------------------
  |  |  377|  2.61k|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096 0x00000040
  ------------------
  |  Branch (372:5): [True: 0, False: 3.31k]
  ------------------
  373|  2.61k|#if (LIBSPDM_RSA_SSA_SUPPORT) || (LIBSPDM_RSA_PSS_SUPPORT)
  374|  2.61k|        libspdm_rsa_free(context);
  375|       |#else
  376|       |        LIBSPDM_ASSERT(false);
  377|       |#endif
  378|  2.61k|        break;
  379|    699|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
  ------------------
  |  |  375|    699|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256 0x00000010
  ------------------
  |  Branch (379:5): [True: 699, False: 2.61k]
  ------------------
  380|    699|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
  ------------------
  |  |  378|    699|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384 0x00000080
  ------------------
  |  Branch (380:5): [True: 0, False: 3.31k]
  ------------------
  381|    699|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
  ------------------
  |  |  379|    699|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521 0x00000100
  ------------------
  |  Branch (381:5): [True: 0, False: 3.31k]
  ------------------
  382|    699|#if LIBSPDM_ECDSA_SUPPORT
  383|    699|        libspdm_ec_free(context);
  384|       |#else
  385|       |        LIBSPDM_ASSERT(false);
  386|       |#endif
  387|    699|        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: 3.31k]
  ------------------
  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: 3.31k]
  ------------------
  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: 3.31k]
  ------------------
  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: 3.31k]
  ------------------
  404|      0|        LIBSPDM_ASSERT(false);
  405|      0|        break;
  406|  3.31k|    }
  407|  3.31k|}

libspdm_asym_get_public_key_from_x509:
  220|  3.36k|{
  221|  3.36k|    libspdm_asym_get_public_key_from_x509_func get_public_key_from_x509_function;
  222|  3.36k|    get_public_key_from_x509_function = libspdm_get_asym_get_public_key_from_x509(base_asym_algo);
  223|  3.36k|    if (get_public_key_from_x509_function == NULL) {
  ------------------
  |  Branch (223:9): [True: 0, False: 3.36k]
  ------------------
  224|      0|        return false;
  225|      0|    }
  226|  3.36k|    return get_public_key_from_x509_function(cert, cert_size, context);
  227|  3.36k|}
libspdm_x509_common_certificate_check:
 1071|  2.79k|{
 1072|  2.79k|    uint8_t end_cert_from[64];
 1073|  2.79k|    size_t end_cert_from_len;
 1074|  2.79k|    uint8_t end_cert_to[64];
 1075|  2.79k|    size_t end_cert_to_len;
 1076|  2.79k|    size_t asn1_buffer_len;
 1077|  2.79k|    bool status;
 1078|  2.79k|    size_t cert_version;
 1079|  2.79k|    void *context;
 1080|       |#if LIBSPDM_ADDITIONAL_CHECK_CERT
 1081|       |    size_t signature_algo_oid_size;
 1082|       |#endif /* LIBSPDM_ADDITIONAL_CHECK_CERT */
 1083|       |
 1084|  2.79k|    if (cert == NULL || cert_size == 0) {
  ------------------
  |  Branch (1084:9): [True: 0, False: 2.79k]
  |  Branch (1084:25): [True: 0, False: 2.79k]
  ------------------
 1085|      0|        return false;
 1086|      0|    }
 1087|       |
 1088|  2.79k|    status = true;
 1089|  2.79k|    context = NULL;
 1090|  2.79k|    end_cert_from_len = 64;
 1091|  2.79k|    end_cert_to_len = 64;
 1092|       |
 1093|       |    /* 1. version*/
 1094|  2.79k|    cert_version = 0;
 1095|  2.79k|    status = libspdm_x509_get_version(cert, cert_size, &cert_version);
 1096|  2.79k|    if (!status) {
  ------------------
  |  Branch (1096:9): [True: 0, False: 2.79k]
  ------------------
 1097|      0|        goto cleanup;
 1098|      0|    }
 1099|  2.79k|    if (cert_version != 2) {
  ------------------
  |  Branch (1099:9): [True: 0, False: 2.79k]
  ------------------
 1100|      0|        status = false;
 1101|      0|        goto cleanup;
 1102|      0|    }
 1103|       |
 1104|       |    /* 2. serial_number*/
 1105|  2.79k|    asn1_buffer_len = 0;
 1106|  2.79k|    status = libspdm_x509_get_serial_number(cert, cert_size, NULL, &asn1_buffer_len);
 1107|  2.79k|    if (asn1_buffer_len == 0) {
  ------------------
  |  Branch (1107:9): [True: 0, False: 2.79k]
  ------------------
 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|  2.79k|    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: 2.79k, False: 0]
  |  Branch (1134:22): [True: 0, False: 0]
  ------------------
 1135|  2.79k|        status = libspdm_verify_cert_subject_public_key_info(cert, cert_size, base_asym_algo);
 1136|  2.79k|        if (!status) {
  ------------------
  |  Branch (1136:13): [True: 0, False: 2.79k]
  ------------------
 1137|      0|            goto cleanup;
 1138|      0|        }
 1139|  2.79k|    }
 1140|       |
 1141|       |    /* 5. issuer_name*/
 1142|  2.79k|    asn1_buffer_len = 0;
 1143|  2.79k|    status = libspdm_x509_get_issuer_name(cert, cert_size, NULL, &asn1_buffer_len);
 1144|  2.79k|    if (status) {
  ------------------
  |  Branch (1144:9): [True: 0, False: 2.79k]
  ------------------
 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|  2.79k|    } else {
 1151|  2.79k|        if (asn1_buffer_len == 0) {
  ------------------
  |  Branch (1151:13): [True: 0, False: 2.79k]
  ------------------
 1152|      0|            status = false;
 1153|      0|            goto cleanup;
 1154|      0|        }
 1155|  2.79k|    }
 1156|       |
 1157|       |    /* 6. subject_name*/
 1158|  2.79k|    asn1_buffer_len = 0;
 1159|  2.79k|    status = libspdm_x509_get_subject_name(cert, cert_size, NULL, &asn1_buffer_len);
 1160|  2.79k|    if (status) {
  ------------------
  |  Branch (1160:9): [True: 0, False: 2.79k]
  ------------------
 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|  2.79k|    } else {
 1167|  2.79k|        if (asn1_buffer_len == 0) {
  ------------------
  |  Branch (1167:13): [True: 0, False: 2.79k]
  ------------------
 1168|      0|            status = false;
 1169|      0|            goto cleanup;
 1170|      0|        }
 1171|  2.79k|    }
 1172|       |
 1173|       |    /* 7. validity*/
 1174|  2.79k|    status = libspdm_x509_get_validity(cert, cert_size, end_cert_from,
 1175|  2.79k|                                       &end_cert_from_len, end_cert_to,
 1176|  2.79k|                                       &end_cert_to_len);
 1177|  2.79k|    if (status) {
  ------------------
  |  Branch (1177:9): [True: 2.79k, False: 0]
  ------------------
 1178|  2.79k|        if ((end_cert_from_len == 0) &&
  ------------------
  |  Branch (1178:13): [True: 0, False: 2.79k]
  ------------------
 1179|  2.79k|            (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|  2.79k|    } 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|  2.79k|    if (end_cert_from_len != 0) {
  ------------------
  |  Branch (1190:9): [True: 2.79k, False: 0]
  ------------------
 1191|  2.79k|        status = libspdm_internal_x509_date_time_check(
 1192|  2.79k|            end_cert_from, end_cert_from_len, end_cert_to, end_cert_to_len);
 1193|  2.79k|        if (!status) {
  ------------------
  |  Branch (1193:13): [True: 0, False: 2.79k]
  ------------------
 1194|      0|            goto cleanup;
 1195|      0|        }
 1196|  2.79k|    }
 1197|       |
 1198|       |    /* 8. subject_public_key*/
 1199|  2.79k|    status = libspdm_asym_get_public_key_from_x509(base_asym_algo, cert, cert_size, &context);
 1200|  2.79k|    if (!status) {
  ------------------
  |  Branch (1200:9): [True: 0, False: 2.79k]
  ------------------
 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|  2.79k|    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: 2.79k, False: 0]
  |  Branch (1208:22): [True: 0, False: 0]
  ------------------
 1209|  2.79k|        size_t value = 0;
 1210|       |
 1211|  2.79k|        status = libspdm_x509_get_key_usage(cert, cert_size, &value);
 1212|  2.79k|        if (!status) {
  ------------------
  |  Branch (1212:13): [True: 0, False: 2.79k]
  ------------------
 1213|      0|            goto cleanup;
 1214|  2.79k|        } else {
 1215|  2.79k|            if (value == 0) {
  ------------------
  |  Branch (1215:17): [True: 0, False: 2.79k]
  ------------------
 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|  2.79k|            } else {
 1221|  2.79k|                if ((LIBSPDM_CRYPTO_X509_KU_DIGITAL_SIGNATURE & value) == 0) {
  ------------------
  |  |   62|  2.79k|#define LIBSPDM_CRYPTO_X509_KU_DIGITAL_SIGNATURE 0x80
  ------------------
  |  Branch (1221:21): [True: 0, False: 2.79k]
  ------------------
 1222|      0|                    status = false;
 1223|      0|                    goto cleanup;
 1224|      0|                }
 1225|  2.79k|            }
 1226|  2.79k|        }
 1227|  2.79k|    }
 1228|       |
 1229|       |    /* 10. verify spdm defined extended key usage*/
 1230|  2.79k|    status = libspdm_verify_leaf_cert_spdm_eku(cert, cert_size, is_requester_cert);
 1231|  2.79k|    if (!status) {
  ------------------
  |  Branch (1231:9): [True: 0, False: 2.79k]
  ------------------
 1232|      0|        goto cleanup;
 1233|      0|    }
 1234|       |
 1235|  2.79k|    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: 2.79k, False: 0]
  |  Branch (1235:24): [True: 0, False: 0]
  ------------------
 1236|       |        /* 11. verify spdm defined extension*/
 1237|  2.79k|        status = libspdm_verify_leaf_cert_spdm_extension(cert, cert_size,
 1238|  2.79k|                                                         is_requester_cert, cert_model);
 1239|  2.79k|        if (!status) {
  ------------------
  |  Branch (1239:13): [True: 0, False: 2.79k]
  ------------------
 1240|      0|            goto cleanup;
 1241|      0|        }
 1242|  2.79k|    }
 1243|       |
 1244|  2.79k|cleanup:
 1245|  2.79k|    libspdm_asym_free(base_asym_algo, context);
 1246|  2.79k|    return status;
 1247|  2.79k|}
libspdm_x509_certificate_check:
 1268|  2.79k|{
 1269|  2.79k|    bool status;
 1270|  2.79k|    uint8_t cert_model;
 1271|       |
 1272|  2.79k|    if (is_device_cert_model) {
  ------------------
  |  Branch (1272:9): [True: 2.79k, False: 0]
  ------------------
 1273|  2.79k|        cert_model = SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT;
  ------------------
  |  |  598|  2.79k|#define SPDM_CERTIFICATE_INFO_CERT_MODEL_DEVICE_CERT 0x1
  ------------------
 1274|  2.79k|    } 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|  2.79k|    status = libspdm_x509_common_certificate_check(cert, cert_size, base_asym_algo,
 1279|  2.79k|                                                   base_hash_algo, is_requester,
 1280|  2.79k|                                                   cert_model, false);
 1281|  2.79k|    if (!status) {
  ------------------
  |  Branch (1281:9): [True: 0, False: 2.79k]
  ------------------
 1282|      0|        return false;
 1283|      0|    }
 1284|       |
 1285|       |    /* verify basic constraints: the leaf cert always is ca:false in get_cert*/
 1286|  2.79k|    status = libspdm_verify_leaf_cert_basic_constraints(cert, cert_size, false);
 1287|  2.79k|    return status;
 1288|  2.79k|}
libspdm_verify_cert_chain_data:
 1669|  2.79k|{
 1670|  2.79k|    const uint8_t *root_cert_buffer;
 1671|  2.79k|    size_t root_cert_buffer_size;
 1672|  2.79k|    const uint8_t *leaf_cert_buffer;
 1673|  2.79k|    size_t leaf_cert_buffer_size;
 1674|       |
 1675|  2.79k|    if (cert_chain_data_size >
  ------------------
  |  Branch (1675:9): [True: 0, False: 2.79k]
  ------------------
 1676|  2.79k|        0xFFFF - (sizeof(spdm_cert_chain_t) + LIBSPDM_MAX_HASH_SIZE)) {
  ------------------
  |  |   65|  2.79k|#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|  2.79k|    if (!libspdm_x509_get_cert_from_cert_chain(
  ------------------
  |  Branch (1682:9): [True: 0, False: 2.79k]
  ------------------
 1683|  2.79k|            cert_chain_data, cert_chain_data_size, 0, &root_cert_buffer,
 1684|  2.79k|            &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|  2.79k|    if (!libspdm_x509_verify_cert_chain(root_cert_buffer, root_cert_buffer_size,
  ------------------
  |  Branch (1690:9): [True: 0, False: 2.79k]
  ------------------
 1691|  2.79k|                                        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|  2.79k|    if (!libspdm_x509_get_cert_from_cert_chain(
  ------------------
  |  Branch (1697:9): [True: 0, False: 2.79k]
  ------------------
 1698|  2.79k|            cert_chain_data, cert_chain_data_size, -1,
 1699|  2.79k|            &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|  2.79k|    if (!libspdm_x509_certificate_check(leaf_cert_buffer, leaf_cert_buffer_size,
  ------------------
  |  Branch (1705:9): [True: 0, False: 2.79k]
  ------------------
 1706|  2.79k|                                        base_asym_algo, base_hash_algo,
 1707|  2.79k|                                        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|  2.79k|    return true;
 1714|  2.79k|}
libspdm_verify_certificate_chain_buffer:
 1826|    727|{
 1827|    727|    const uint8_t *cert_chain_data;
 1828|    727|    size_t cert_chain_data_size;
 1829|    727|    const uint8_t *first_cert_buffer;
 1830|    727|    size_t first_cert_buffer_size;
 1831|    727|    size_t hash_size;
 1832|    727|    uint8_t calc_root_cert_hash[LIBSPDM_MAX_HASH_SIZE];
 1833|    727|    const uint8_t *leaf_cert_buffer;
 1834|    727|    size_t leaf_cert_buffer_size;
 1835|    727|    bool result;
 1836|    727|    const spdm_cert_chain_t *cert_chain_header;
 1837|       |
 1838|    727|    hash_size = libspdm_get_hash_size(base_hash_algo);
 1839|       |
 1840|    727|    if (cert_chain_buffer_size <= sizeof(spdm_cert_chain_t) + hash_size) {
  ------------------
  |  Branch (1840:9): [True: 0, False: 727]
  ------------------
 1841|      0|        LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
 1842|      0|                       "!!! VerifyCertificateChainBuffer - FAIL (buffer too small) !!!\n"));
 1843|      0|        return false;
 1844|      0|    }
 1845|       |
 1846|    727|    cert_chain_header = cert_chain_buffer;
 1847|    727|    if (cert_chain_header->length != cert_chain_buffer_size) {
  ------------------
  |  Branch (1847:9): [True: 727, False: 0]
  ------------------
 1848|    727|        LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
 1849|    727|                       "!!! VerifyCertificateChainBuffer - FAIL (cert_chain->length mismatch) !!!\n"));
 1850|    727|        return false;
 1851|    727|    }
 1852|       |
 1853|      0|    cert_chain_data = (const uint8_t *)cert_chain_buffer + sizeof(spdm_cert_chain_t) + hash_size;
 1854|      0|    cert_chain_data_size = cert_chain_buffer_size - sizeof(spdm_cert_chain_t) - hash_size;
 1855|      0|    if (!libspdm_x509_get_cert_from_cert_chain(
  ------------------
  |  Branch (1855:9): [True: 0, False: 0]
  ------------------
 1856|      0|            cert_chain_data, cert_chain_data_size, 0, &first_cert_buffer,
 1857|      0|            &first_cert_buffer_size)) {
 1858|      0|        LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
 1859|      0|                       "!!! VerifyCertificateChainBuffer - FAIL (get root certificate failed)!!!\n"));
 1860|      0|        return false;
 1861|      0|    }
 1862|       |
 1863|      0|    if (libspdm_is_root_certificate(first_cert_buffer, first_cert_buffer_size)) {
  ------------------
  |  Branch (1863:9): [True: 0, False: 0]
  ------------------
 1864|      0|        result = libspdm_hash_all(base_hash_algo, first_cert_buffer, first_cert_buffer_size,
 1865|      0|                                  calc_root_cert_hash);
 1866|      0|        if (!result) {
  ------------------
  |  Branch (1866:13): [True: 0, False: 0]
  ------------------
 1867|      0|            LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
 1868|      0|                           "!!! VerifyCertificateChainBuffer - FAIL (hash calculation fail) !!!\n"));
 1869|      0|            return false;
 1870|      0|        }
 1871|      0|        if (!libspdm_consttime_is_mem_equal((const uint8_t *)cert_chain_buffer +
  ------------------
  |  Branch (1871:13): [True: 0, False: 0]
  ------------------
 1872|      0|                                            sizeof(spdm_cert_chain_t),
 1873|      0|                                            calc_root_cert_hash, hash_size)) {
 1874|      0|            LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
 1875|      0|                           "!!! VerifyCertificateChainBuffer - FAIL (cert root hash mismatch) !!!\n"));
 1876|      0|            return false;
 1877|      0|        }
 1878|      0|        LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
 1879|      0|                       "!!! VerifyCertificateChainBuffer - PASS (cert root hash match) !!!\n"));
 1880|      0|    }
 1881|       |
 1882|       |    /*If the number of certificates in the certificate chain is more than 1,
 1883|       |     * other certificates need to be verified.*/
 1884|      0|    if (cert_chain_data_size > first_cert_buffer_size) {
  ------------------
  |  Branch (1884:9): [True: 0, False: 0]
  ------------------
 1885|      0|        if (!libspdm_x509_verify_cert_chain(first_cert_buffer, first_cert_buffer_size,
  ------------------
  |  Branch (1885:13): [True: 0, False: 0]
  ------------------
 1886|      0|                                            cert_chain_data + first_cert_buffer_size,
 1887|      0|                                            cert_chain_data_size - first_cert_buffer_size)) {
 1888|      0|            LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
 1889|      0|                           "!!! VerifyCertificateChainBuffer - FAIL (cert chain verify failed)!!!\n"));
 1890|      0|            return false;
 1891|      0|        }
 1892|      0|    }
 1893|       |
 1894|      0|    if (!libspdm_x509_get_cert_from_cert_chain(
  ------------------
  |  Branch (1894:9): [True: 0, False: 0]
  ------------------
 1895|      0|            cert_chain_data, cert_chain_data_size, -1,
 1896|      0|            &leaf_cert_buffer, &leaf_cert_buffer_size)) {
 1897|      0|        LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
 1898|      0|                       "!!! VerifyCertificateChainBuffer - FAIL (get leaf certificate failed)!!!\n"));
 1899|      0|        return false;
 1900|      0|    }
 1901|       |
 1902|      0|    if (!libspdm_x509_certificate_check(leaf_cert_buffer, leaf_cert_buffer_size,
  ------------------
  |  Branch (1902:9): [True: 0, False: 0]
  ------------------
 1903|      0|                                        base_asym_algo, base_hash_algo,
 1904|      0|                                        is_requester_cert, is_device_cert_model)) {
 1905|      0|        LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO,
 1906|      0|                       "!!! VerifyCertificateChainBuffer - FAIL (leaf certificate check failed)!!!\n"));
 1907|      0|        return false;
 1908|      0|    }
 1909|       |
 1910|      0|    return true;
 1911|      0|}
libspdm_get_leaf_cert_public_key_from_cert_chain:
 1918|    568|{
 1919|    568|    size_t hash_size;
 1920|    568|    const uint8_t *cert_buffer;
 1921|    568|    size_t cert_buffer_size;
 1922|    568|    bool result;
 1923|       |
 1924|    568|    hash_size = libspdm_get_hash_size(base_hash_algo);
 1925|       |
 1926|    568|    cert_chain_data = cert_chain_data + sizeof(spdm_cert_chain_t) + hash_size;
 1927|    568|    cert_chain_data_size = cert_chain_data_size - (sizeof(spdm_cert_chain_t) + hash_size);
 1928|       |
 1929|       |    /* Get leaf cert from cert chain */
 1930|    568|    result = libspdm_x509_get_cert_from_cert_chain(cert_chain_data,
 1931|    568|                                                   cert_chain_data_size, -1,
 1932|    568|                                                   &cert_buffer, &cert_buffer_size);
 1933|    568|    if (!result) {
  ------------------
  |  Branch (1933:9): [True: 0, False: 568]
  ------------------
 1934|      0|        return false;
 1935|      0|    }
 1936|       |
 1937|    568|    result = libspdm_asym_get_public_key_from_x509(
 1938|    568|        base_asym_alg,
 1939|    568|        cert_buffer, cert_buffer_size, public_key);
 1940|    568|    if (!result) {
  ------------------
  |  Branch (1940:9): [True: 54, False: 514]
  ------------------
 1941|     54|        return false;
 1942|     54|    }
 1943|       |
 1944|    514|    return true;
 1945|    568|}
libspdm_crypt_cert.c:libspdm_get_asym_get_public_key_from_x509:
  124|  3.36k|{
  125|  3.36k|    switch (base_asym_algo) {
  126|  2.66k|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
  ------------------
  |  |  371|  2.66k|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048 0x00000001
  ------------------
  |  Branch (126:5): [True: 2.66k, False: 699]
  ------------------
  127|  2.66k|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
  ------------------
  |  |  373|  2.66k|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072 0x00000004
  ------------------
  |  Branch (127:5): [True: 0, False: 3.36k]
  ------------------
  128|  2.66k|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
  ------------------
  |  |  376|  2.66k|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096 0x00000020
  ------------------
  |  Branch (128:5): [True: 0, False: 3.36k]
  ------------------
  129|  2.66k|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
  ------------------
  |  |  372|  2.66k|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048 0x00000002
  ------------------
  |  Branch (129:5): [True: 0, False: 3.36k]
  ------------------
  130|  2.66k|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
  ------------------
  |  |  374|  2.66k|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072 0x00000008
  ------------------
  |  Branch (130:5): [True: 0, False: 3.36k]
  ------------------
  131|  2.66k|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
  ------------------
  |  |  377|  2.66k|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096 0x00000040
  ------------------
  |  Branch (131:5): [True: 0, False: 3.36k]
  ------------------
  132|  2.66k|#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|  2.66k|        return libspdm_rsa_get_public_key_from_x509;
  152|       |#else
  153|       |        LIBSPDM_ASSERT(false);
  154|       |        break;
  155|       |#endif
  156|    699|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
  ------------------
  |  |  375|    699|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256 0x00000010
  ------------------
  |  Branch (156:5): [True: 699, False: 2.66k]
  ------------------
  157|    699|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
  ------------------
  |  |  378|    699|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384 0x00000080
  ------------------
  |  Branch (157:5): [True: 0, False: 3.36k]
  ------------------
  158|    699|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
  ------------------
  |  |  379|    699|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521 0x00000100
  ------------------
  |  Branch (158:5): [True: 0, False: 3.36k]
  ------------------
  159|    699|#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|    699|        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: 3.36k]
  ------------------
  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: 3.36k]
  ------------------
  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: 3.36k]
  ------------------
  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: 3.36k]
  ------------------
  196|      0|        LIBSPDM_ASSERT(false);
  197|      0|        break;
  198|  3.36k|    }
  199|       |
  200|      0|    return NULL;
  201|  3.36k|}
libspdm_crypt_cert.c:libspdm_verify_cert_subject_public_key_info:
  693|  2.79k|{
  694|  2.79k|    size_t oid_len;
  695|  2.79k|    bool status;
  696|       |
  697|       |    /*public key encrypt algo OID from cert*/
  698|  2.79k|    uint8_t cert_public_key_crypt_algo_oid[LIBSPDM_MAX_ENCRYPTION_ALGO_OID_LEN];
  699|       |    /*public key encrypt algo OID from libspdm stored*/
  700|  2.79k|    uint8_t libspdm_public_key_crypt_algo_oid[LIBSPDM_MAX_ENCRYPTION_ALGO_OID_LEN];
  701|  2.79k|    uint8_t libspdm_public_key_crypt_algo_oid_other[LIBSPDM_MAX_ENCRYPTION_ALGO_OID_LEN];
  702|       |
  703|  2.79k|    libspdm_zero_mem(libspdm_public_key_crypt_algo_oid, LIBSPDM_MAX_ENCRYPTION_ALGO_OID_LEN);
  ------------------
  |  |   32|  2.79k|#define LIBSPDM_MAX_ENCRYPTION_ALGO_OID_LEN 10
  ------------------
  704|  2.79k|    libspdm_zero_mem(libspdm_public_key_crypt_algo_oid_other, LIBSPDM_MAX_ENCRYPTION_ALGO_OID_LEN);
  ------------------
  |  |   32|  2.79k|#define LIBSPDM_MAX_ENCRYPTION_ALGO_OID_LEN 10
  ------------------
  705|       |
  706|       |    /*work around: skip the sm2*/
  707|  2.79k|    if (base_asym_algo == SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256) {
  ------------------
  |  |  384|  2.79k|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_SM2_ECC_SM2_P256 0x00000200
  ------------------
  |  Branch (707:9): [True: 0, False: 2.79k]
  ------------------
  708|      0|        return true;
  709|      0|    }
  710|       |
  711|  2.79k|    oid_len = libspdm_get_public_key_algo_OID_len(base_asym_algo);
  712|  2.79k|    if(oid_len == 0) {
  ------------------
  |  Branch (712:8): [True: 0, False: 2.79k]
  ------------------
  713|      0|        return false;
  714|      0|    }
  715|       |    /*get public key encrypt algo OID from libspdm stored*/
  716|  2.79k|    status = libspdm_get_public_key_algo_OID(base_asym_algo,
  717|  2.79k|                                             libspdm_public_key_crypt_algo_oid,
  718|  2.79k|                                             libspdm_public_key_crypt_algo_oid_other);
  719|  2.79k|    if (!status) {
  ------------------
  |  Branch (719:9): [True: 0, False: 2.79k]
  ------------------
  720|      0|        return status;
  721|      0|    }
  722|       |
  723|       |    /*get public key encrypt algo OID from cert*/
  724|  2.79k|    status = libspdm_get_public_key_oid(cert, cert_size, cert_public_key_crypt_algo_oid, oid_len,
  725|  2.79k|                                        base_asym_algo);
  726|  2.79k|    if (!status || (!libspdm_consttime_is_mem_equal(cert_public_key_crypt_algo_oid,
  ------------------
  |  Branch (726:9): [True: 0, False: 2.79k]
  |  Branch (726:21): [True: 0, False: 2.79k]
  ------------------
  727|  2.79k|                                                    libspdm_public_key_crypt_algo_oid, oid_len) &&
  728|  2.79k|                    !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|  2.79k|    return status;
  735|  2.79k|}
libspdm_crypt_cert.c:libspdm_get_public_key_algo_OID_len:
  329|  5.59k|{
  330|  5.59k|    switch (base_asym_algo) {
  331|  4.19k|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
  ------------------
  |  |  371|  4.19k|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048 0x00000001
  ------------------
  |  Branch (331:5): [True: 4.19k, False: 1.39k]
  ------------------
  332|  4.19k|#if LIBSPDM_RSA_SSA_2048_SUPPORT
  333|  4.19k|        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: 5.59k]
  ------------------
  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: 5.59k]
  ------------------
  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: 5.59k]
  ------------------
  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: 5.59k]
  ------------------
  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: 5.59k]
  ------------------
  362|      0|#if LIBSPDM_RSA_PSS_4096_SUPPORT
  363|      0|        return 4;
  364|       |#else
  365|       |        return 0;
  366|       |#endif
  367|  1.39k|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
  ------------------
  |  |  375|  1.39k|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256 0x00000010
  ------------------
  |  Branch (367:5): [True: 1.39k, False: 4.19k]
  ------------------
  368|  1.39k|#if LIBSPDM_ECDSA_P256_SUPPORT
  369|  1.39k|        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: 5.59k]
  ------------------
  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: 5.59k]
  ------------------
  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: 5.59k]
  ------------------
  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: 5.59k]
  ------------------
  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: 5.59k]
  ------------------
  398|      0|        LIBSPDM_ASSERT(false);
  399|      0|        return 0;
  400|  5.59k|    }
  401|  5.59k|}
libspdm_crypt_cert.c:libspdm_get_public_key_algo_OID:
  416|  2.79k|{
  417|  2.79k|    uint32_t oid_len;
  418|  2.79k|    oid_len = libspdm_get_public_key_algo_OID_len(base_asym_algo);
  419|  2.79k|    if(oid_len == 0) {
  ------------------
  |  Branch (419:8): [True: 0, False: 2.79k]
  ------------------
  420|      0|        return false;
  421|      0|    }
  422|       |
  423|  2.79k|    switch (base_asym_algo) {
  424|  2.09k|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
  ------------------
  |  |  371|  2.09k|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048 0x00000001
  ------------------
  |  Branch (424:5): [True: 2.09k, False: 699]
  ------------------
  425|  2.09k|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048: {
  ------------------
  |  |  372|  2.09k|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048 0x00000002
  ------------------
  |  Branch (425:5): [True: 0, False: 2.79k]
  ------------------
  426|  2.09k|#if (LIBSPDM_RSA_SSA_2048_SUPPORT) || (LIBSPDM_RSA_PSS_2048_SUPPORT)
  427|  2.09k|        uint8_t encry_algo_oid_rsa2048[] = KEY_ENCRY_ALGO_RSA2048_FLAG;
  ------------------
  |  |   46|  2.09k|#define KEY_ENCRY_ALGO_RSA2048_FLAG {0x02, 0x82, 0x01, 0x01}
  ------------------
  428|  2.09k|        uint8_t encry_algo_oid_rsa2048_ohter[] = KEY_ENCRY_ALGO_RSA2048_FLAG_OTHER;
  ------------------
  |  |   48|  2.09k|#define KEY_ENCRY_ALGO_RSA2048_FLAG_OTHER {0x02, 0x82, 0x01, 0x00}
  ------------------
  429|  2.09k|        libspdm_copy_mem(oid, oid_len, encry_algo_oid_rsa2048, oid_len);
  430|  2.09k|        libspdm_copy_mem(oid_other, oid_len, encry_algo_oid_rsa2048_ohter, oid_len);
  431|  2.09k|        return true;
  432|       |#else
  433|       |        return false;
  434|       |#endif
  435|  2.09k|    }
  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: 2.79k]
  ------------------
  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: 2.79k]
  ------------------
  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: 2.79k]
  ------------------
  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: 2.79k]
  ------------------
  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|    699|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256: {
  ------------------
  |  |  375|    699|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256 0x00000010
  ------------------
  |  Branch (461:5): [True: 699, False: 2.09k]
  ------------------
  462|    699|#if LIBSPDM_ECDSA_P256_SUPPORT
  463|    699|        uint8_t encry_algo_oid_ecc256[] = KEY_ENCRY_ALGO_ECC256_OID;
  ------------------
  |  |   70|    699|#define KEY_ENCRY_ALGO_ECC256_OID {0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07}
  ------------------
  464|    699|        libspdm_copy_mem(oid, oid_len, encry_algo_oid_ecc256, oid_len);
  465|    699|        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: 2.79k]
  ------------------
  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: 2.79k]
  ------------------
  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: 2.79k]
  ------------------
  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: 2.79k]
  ------------------
  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: 2.79k]
  ------------------
  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: 2.79k]
  ------------------
  515|      0|        LIBSPDM_ASSERT(false);
  516|      0|        return false;
  517|  2.79k|    }
  518|  2.79k|}
libspdm_crypt_cert.c:libspdm_get_public_key_oid:
  534|  2.79k|{
  535|  2.79k|    bool ret;
  536|  2.79k|    uint8_t *ptr;
  537|  2.79k|    int32_t length;
  538|  2.79k|    size_t obj_len;
  539|  2.79k|    uint8_t *end;
  540|  2.79k|    uint8_t index;
  541|  2.79k|    uint8_t sequence_time;
  542|       |
  543|  2.79k|    length = (int32_t)cert_size;
  544|  2.79k|    ptr = (uint8_t*)(size_t)cert;
  545|  2.79k|    obj_len = 0;
  546|  2.79k|    end = ptr + length;
  547|  2.79k|    ret = true;
  548|       |
  549|       |    /* TBSCertificate have 5 sequence before subjectPublicKeyInfo*/
  550|  2.79k|    sequence_time = 5;
  551|       |
  552|       |    /*all cert sequence*/
  553|  2.79k|    ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
  554|  2.79k|                               LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   80|  2.79k|#define LIBSPDM_CRYPTO_ASN1_SEQUENCE 0x10
  ------------------
                                             LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   90|  2.79k|#define LIBSPDM_CRYPTO_ASN1_CONSTRUCTED 0x20
  ------------------
  555|  2.79k|    if (!ret) {
  ------------------
  |  Branch (555:9): [True: 0, False: 2.79k]
  ------------------
  556|      0|        return false;
  557|      0|    }
  558|       |
  559|       |    /*TBSCertificate sequence*/
  560|  2.79k|    ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
  561|  2.79k|                               LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   80|  2.79k|#define LIBSPDM_CRYPTO_ASN1_SEQUENCE 0x10
  ------------------
                                             LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   90|  2.79k|#define LIBSPDM_CRYPTO_ASN1_CONSTRUCTED 0x20
  ------------------
  562|  2.79k|    if (!ret) {
  ------------------
  |  Branch (562:9): [True: 0, False: 2.79k]
  ------------------
  563|      0|        return false;
  564|      0|    }
  565|       |
  566|  2.79k|    end = ptr + obj_len;
  567|       |    /*version*/
  568|  2.79k|    ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
  569|  2.79k|                               LIBSPDM_CRYPTO_ASN1_CONTEXT_SPECIFIC |
  ------------------
  |  |   91|  2.79k|#define LIBSPDM_CRYPTO_ASN1_CONTEXT_SPECIFIC 0x80
  ------------------
  570|  2.79k|                               LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   90|  2.79k|#define LIBSPDM_CRYPTO_ASN1_CONSTRUCTED 0x20
  ------------------
  571|  2.79k|    if (!ret) {
  ------------------
  |  Branch (571:9): [True: 0, False: 2.79k]
  ------------------
  572|      0|        return false;
  573|      0|    }
  574|       |
  575|  2.79k|    ptr += obj_len;
  576|       |    /*serialNumber*/
  577|  2.79k|    ret = libspdm_asn1_get_tag(&ptr, end, &obj_len, LIBSPDM_CRYPTO_ASN1_INTEGER);
  ------------------
  |  |   74|  2.79k|#define LIBSPDM_CRYPTO_ASN1_INTEGER 0x02
  ------------------
  578|  2.79k|    if (!ret) {
  ------------------
  |  Branch (578:9): [True: 0, False: 2.79k]
  ------------------
  579|      0|        return false;
  580|      0|    }
  581|       |
  582|       |    /**
  583|       |     * signature AlgorithmIdentifier,
  584|       |     * issuer Name,
  585|       |     * validity Validity,
  586|       |     * subject Name,
  587|       |     * subjectPublicKeyInfo
  588|       |     **/
  589|  16.7k|    for (index = 0; index < sequence_time; index++) {
  ------------------
  |  Branch (589:21): [True: 13.9k, False: 2.79k]
  ------------------
  590|  13.9k|        ptr += obj_len;
  591|  13.9k|        ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
  592|  13.9k|                                   LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   80|  13.9k|#define LIBSPDM_CRYPTO_ASN1_SEQUENCE 0x10
  ------------------
                                                 LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   90|  13.9k|#define LIBSPDM_CRYPTO_ASN1_CONSTRUCTED 0x20
  ------------------
  593|  13.9k|        if (!ret) {
  ------------------
  |  Branch (593:13): [True: 0, False: 13.9k]
  ------------------
  594|      0|            return false;
  595|      0|        }
  596|  13.9k|    }
  597|       |
  598|  2.79k|    switch (base_asym_algo)
  599|  2.79k|    {
  600|  2.09k|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048:
  ------------------
  |  |  371|  2.09k|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048 0x00000001
  ------------------
  |  Branch (600:5): [True: 2.09k, False: 699]
  ------------------
  601|  2.09k|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048:
  ------------------
  |  |  372|  2.09k|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_2048 0x00000002
  ------------------
  |  Branch (601:5): [True: 0, False: 2.79k]
  ------------------
  602|  2.09k|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072:
  ------------------
  |  |  373|  2.09k|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_3072 0x00000004
  ------------------
  |  Branch (602:5): [True: 0, False: 2.79k]
  ------------------
  603|  2.09k|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072:
  ------------------
  |  |  374|  2.09k|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_3072 0x00000008
  ------------------
  |  Branch (603:5): [True: 0, False: 2.79k]
  ------------------
  604|  2.09k|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096:
  ------------------
  |  |  376|  2.09k|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_4096 0x00000020
  ------------------
  |  Branch (604:5): [True: 0, False: 2.79k]
  ------------------
  605|  2.09k|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096:
  ------------------
  |  |  377|  2.09k|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSAPSS_4096 0x00000040
  ------------------
  |  Branch (605:5): [True: 0, False: 2.79k]
  ------------------
  606|  2.09k|        ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
  607|  2.09k|                                   LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   80|  2.09k|#define LIBSPDM_CRYPTO_ASN1_SEQUENCE 0x10
  ------------------
                                                 LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   90|  2.09k|#define LIBSPDM_CRYPTO_ASN1_CONSTRUCTED 0x20
  ------------------
  608|  2.09k|        if (!ret) {
  ------------------
  |  Branch (608:13): [True: 0, False: 2.09k]
  ------------------
  609|      0|            return false;
  610|      0|        }
  611|       |
  612|  2.09k|        ptr += obj_len;
  613|  2.09k|        ret = libspdm_asn1_get_tag(&ptr, end, &obj_len, LIBSPDM_CRYPTO_ASN1_BIT_STRING);
  ------------------
  |  |   75|  2.09k|#define LIBSPDM_CRYPTO_ASN1_BIT_STRING 0x03
  ------------------
  614|  2.09k|        if (!ret) {
  ------------------
  |  Branch (614:13): [True: 0, False: 2.09k]
  ------------------
  615|      0|            return false;
  616|      0|        }
  617|       |
  618|       |        /*get rsa key len*/
  619|  2.09k|        ptr++;
  620|  2.09k|        ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
  621|  2.09k|                                   LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   80|  2.09k|#define LIBSPDM_CRYPTO_ASN1_SEQUENCE 0x10
  ------------------
                                                 LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   90|  2.09k|#define LIBSPDM_CRYPTO_ASN1_CONSTRUCTED 0x20
  ------------------
  622|  2.09k|        if (!ret) {
  ------------------
  |  Branch (622:13): [True: 0, False: 2.09k]
  ------------------
  623|      0|            return false;
  624|      0|        }
  625|  2.09k|        libspdm_copy_mem(oid, oid_size, ptr, oid_size);
  626|  2.09k|        break;
  627|    699|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256:
  ------------------
  |  |  375|    699|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256 0x00000010
  ------------------
  |  Branch (627:5): [True: 699, False: 2.09k]
  ------------------
  628|    699|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384:
  ------------------
  |  |  378|    699|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384 0x00000080
  ------------------
  |  Branch (628:5): [True: 0, False: 2.79k]
  ------------------
  629|    699|    case SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521:
  ------------------
  |  |  379|    699|#define SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521 0x00000100
  ------------------
  |  Branch (629:5): [True: 0, False: 2.79k]
  ------------------
  630|    699|        ret = libspdm_asn1_get_tag(&ptr, end, &obj_len,
  631|    699|                                   LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   80|    699|#define LIBSPDM_CRYPTO_ASN1_SEQUENCE 0x10
  ------------------
                                                 LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   90|    699|#define LIBSPDM_CRYPTO_ASN1_CONSTRUCTED 0x20
  ------------------
  632|    699|        if (!ret) {
  ------------------
  |  Branch (632:13): [True: 0, False: 699]
  ------------------
  633|      0|            return false;
  634|      0|        }
  635|    699|        ret = libspdm_asn1_get_tag(&ptr, end, &obj_len, LIBSPDM_CRYPTO_ASN1_OID);
  ------------------
  |  |   78|    699|#define LIBSPDM_CRYPTO_ASN1_OID 0x06
  ------------------
  636|    699|        if (!ret) {
  ------------------
  |  Branch (636:13): [True: 0, False: 699]
  ------------------
  637|      0|            return false;
  638|      0|        }
  639|       |
  640|       |        /*get ecc second oid*/
  641|    699|        ptr +=obj_len;
  642|    699|        ret = libspdm_asn1_get_tag(&ptr, end, &obj_len, LIBSPDM_CRYPTO_ASN1_OID);
  ------------------
  |  |   78|    699|#define LIBSPDM_CRYPTO_ASN1_OID 0x06
  ------------------
  643|    699|        if (!ret) {
  ------------------
  |  Branch (643:13): [True: 0, False: 699]
  ------------------
  644|      0|            return false;
  645|      0|        }
  646|       |
  647|    699|        if (oid_size != obj_len) {
  ------------------
  |  Branch (647:13): [True: 0, False: 699]
  ------------------
  648|      0|            return false;
  649|      0|        }
  650|       |
  651|    699|        libspdm_copy_mem(oid, oid_size, ptr, obj_len);
  652|    699|        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: 2.79k]
  ------------------
  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: 2.79k]
  ------------------
  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: 2.79k]
  ------------------
  674|      0|        LIBSPDM_ASSERT(false);
  675|      0|        return false;
  676|  2.79k|    }
  677|       |
  678|  2.79k|    return true;
  679|  2.79k|}
libspdm_crypt_cert.c:libspdm_internal_x509_date_time_check:
  285|  2.79k|{
  286|  2.79k|    int32_t ret;
  287|  2.79k|    bool status;
  288|  2.79k|    uint8_t f0[64];
  289|  2.79k|    uint8_t t0[64];
  290|  2.79k|    size_t f0_size;
  291|  2.79k|    size_t t0_size;
  292|       |
  293|  2.79k|    f0_size = 64;
  294|  2.79k|    t0_size = 64;
  295|       |
  296|  2.79k|    status = libspdm_x509_set_date_time("19700101000000Z", f0, &f0_size);
  297|  2.79k|    if (!status) {
  ------------------
  |  Branch (297:9): [True: 0, False: 2.79k]
  ------------------
  298|      0|        return false;
  299|      0|    }
  300|       |
  301|  2.79k|    status = libspdm_x509_set_date_time("99991231235959Z", t0, &t0_size);
  302|  2.79k|    if (!status) {
  ------------------
  |  Branch (302:9): [True: 0, False: 2.79k]
  ------------------
  303|      0|        return false;
  304|      0|    }
  305|       |
  306|       |    /* from >= f0*/
  307|  2.79k|    ret = libspdm_x509_compare_date_time(from, f0);
  308|  2.79k|    if (ret < 0) {
  ------------------
  |  Branch (308:9): [True: 0, False: 2.79k]
  ------------------
  309|      0|        return false;
  310|      0|    }
  311|       |
  312|       |    /* to <= t0*/
  313|  2.79k|    ret = libspdm_x509_compare_date_time(t0, to);
  314|  2.79k|    if (ret < 0) {
  ------------------
  |  Branch (314:9): [True: 0, False: 2.79k]
  ------------------
  315|      0|        return false;
  316|      0|    }
  317|       |
  318|  2.79k|    return true;
  319|  2.79k|}
libspdm_crypt_cert.c:libspdm_verify_leaf_cert_spdm_eku:
  887|  2.79k|{
  888|  2.79k|    bool status;
  889|  2.79k|    uint8_t eku[256];
  890|  2.79k|    size_t eku_size;
  891|  2.79k|    bool req_auth_oid_find_success;
  892|  2.79k|    bool rsp_auth_oid_find_success;
  893|  2.79k|    uint8_t *ptr;
  894|  2.79k|    size_t obj_len;
  895|       |
  896|       |    /* SPDM defined OID */
  897|  2.79k|    uint8_t eku_requester_auth_oid[] = SPDM_OID_DMTF_EKU_REQUESTER_AUTH;
  ------------------
  |  | 1533|  2.79k|    { /*0x06, 0x0A,*/ 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1C, 0x82, 0x12, 0x04 }
  ------------------
  898|  2.79k|    uint8_t eku_responder_auth_oid[] = SPDM_OID_DMTF_EKU_RESPONDER_AUTH;
  ------------------
  |  | 1530|  2.79k|    { /*0x06, 0x0A,*/ 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1C, 0x82, 0x12, 0x03 }
  ------------------
  899|       |
  900|  2.79k|    eku_size = sizeof(eku);
  901|  2.79k|    status = libspdm_x509_get_extended_key_usage(cert, cert_size, eku, &eku_size);
  902|  2.79k|    if (!status) {
  ------------------
  |  Branch (902:9): [True: 0, False: 2.79k]
  ------------------
  903|      0|        return false;
  904|  2.79k|    } else if (eku_size == 0) {
  ------------------
  |  Branch (904:16): [True: 0, False: 2.79k]
  ------------------
  905|       |        /* eku is not present in cert */
  906|      0|        return true;
  907|      0|    }
  908|       |
  909|  2.79k|    ptr = eku;
  910|  2.79k|    obj_len = 0;
  911|  2.79k|    req_auth_oid_find_success = false;
  912|  2.79k|    rsp_auth_oid_find_success = false;
  913|       |
  914|  2.79k|    status = libspdm_asn1_get_tag(&ptr, eku + eku_size, &obj_len,
  915|  2.79k|                                  LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   80|  2.79k|#define LIBSPDM_CRYPTO_ASN1_SEQUENCE 0x10
  ------------------
                                                LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   90|  2.79k|#define LIBSPDM_CRYPTO_ASN1_CONSTRUCTED 0x20
  ------------------
  916|  2.79k|    if (!status) {
  ------------------
  |  Branch (916:9): [True: 0, False: 2.79k]
  ------------------
  917|      0|        return false;
  918|      0|    }
  919|       |
  920|  11.1k|    while(ptr < eku + eku_size) {
  ------------------
  |  Branch (920:11): [True: 8.38k, False: 2.79k]
  ------------------
  921|  8.38k|        status = libspdm_asn1_get_tag(&ptr, eku + eku_size, &obj_len, LIBSPDM_CRYPTO_ASN1_OID);
  ------------------
  |  |   78|  8.38k|#define LIBSPDM_CRYPTO_ASN1_OID 0x06
  ------------------
  922|  8.38k|        if (!status) {
  ------------------
  |  Branch (922:13): [True: 0, False: 8.38k]
  ------------------
  923|      0|            return false;
  924|      0|        }
  925|       |
  926|  8.38k|        if ((obj_len == sizeof(eku_requester_auth_oid)) &&
  ------------------
  |  Branch (926:13): [True: 0, False: 8.38k]
  ------------------
  927|  8.38k|            (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|  8.38k|        if ((obj_len == sizeof(eku_responder_auth_oid)) &&
  ------------------
  |  Branch (931:13): [True: 0, False: 8.38k]
  ------------------
  932|  8.38k|            (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|  8.38k|        ptr += obj_len;
  938|  8.38k|    }
  939|       |
  940|  2.79k|    if (ptr != eku + eku_size) {
  ------------------
  |  Branch (940:9): [True: 0, False: 2.79k]
  ------------------
  941|      0|        return false;
  942|      0|    }
  943|       |
  944|  2.79k|    if (is_requester_cert) {
  ------------------
  |  Branch (944:9): [True: 0, False: 2.79k]
  ------------------
  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|  2.79k|    } else {
  950|       |        /* it should not only contain requester auth oid */
  951|  2.79k|        if (req_auth_oid_find_success && !rsp_auth_oid_find_success) {
  ------------------
  |  Branch (951:13): [True: 0, False: 2.79k]
  |  Branch (951:42): [True: 0, False: 0]
  ------------------
  952|      0|            return false;
  953|      0|        }
  954|  2.79k|    }
  955|       |
  956|  2.79k|    return true;
  957|  2.79k|}
libspdm_crypt_cert.c:libspdm_verify_leaf_cert_spdm_extension:
  973|  2.79k|{
  974|  2.79k|    bool status;
  975|  2.79k|    bool find_sucessful;
  976|  2.79k|    uint8_t spdm_extension[LIBSPDM_MAX_EXTENSION_LEN];
  977|  2.79k|    size_t len;
  978|  2.79k|    uint8_t *ptr;
  979|  2.79k|    uint8_t *temptr;
  980|  2.79k|    size_t obj_len;
  981|       |
  982|       |    /* SPDM defined OID */
  983|  2.79k|    uint8_t oid_spdm_extension[] = SPDM_OID_DMTF_SPDM_EXTENSION;
  ------------------
  |  | 1539|  2.79k|    { /*0x06, 0x0A,*/ 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1C, 0x82, 0x12, 0x06 }
  ------------------
  984|  2.79k|    uint8_t hardware_identity_oid[] = SPDM_OID_DMTF_HARDWARE_IDENTITY;
  ------------------
  |  | 1527|  2.79k|    { /*0x06, 0x0A,*/ 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1C, 0x82, 0x12, 0x02 }
  ------------------
  985|       |
  986|  2.79k|    len = LIBSPDM_MAX_EXTENSION_LEN;
  ------------------
  |  |   23|  2.79k|#define LIBSPDM_MAX_EXTENSION_LEN 30
  ------------------
  987|       |
  988|  2.79k|    if (cert == NULL || cert_size == 0) {
  ------------------
  |  Branch (988:9): [True: 0, False: 2.79k]
  |  Branch (988:25): [True: 0, False: 2.79k]
  ------------------
  989|      0|        return false;
  990|      0|    }
  991|       |
  992|  2.79k|    status = libspdm_x509_get_extension_data(cert, cert_size,
  993|  2.79k|                                             (const uint8_t *)oid_spdm_extension,
  994|  2.79k|                                             sizeof(oid_spdm_extension),
  995|  2.79k|                                             spdm_extension,
  996|  2.79k|                                             &len);
  997|  2.79k|    if (!status) {
  ------------------
  |  Branch (997:9): [True: 0, False: 2.79k]
  ------------------
  998|      0|        return false;
  999|  2.79k|    } else if(len == 0) {
  ------------------
  |  Branch (999:15): [True: 0, False: 2.79k]
  ------------------
 1000|      0|        return true;
 1001|      0|    }
 1002|       |
 1003|       |    /*find the spdm hardware identity OID*/
 1004|  2.79k|    find_sucessful = false;
 1005|  2.79k|    ptr = spdm_extension;
 1006|  2.79k|    obj_len = 0;
 1007|       |
 1008|       |    /*id-spdm-cert-oids ::= SEQUENCE SIZE (1..MAX) OF id-spdm-cert-oid*/
 1009|  2.79k|    status = libspdm_asn1_get_tag(
 1010|  2.79k|        &ptr, spdm_extension + len, &obj_len,
 1011|  2.79k|        LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   80|  2.79k|#define LIBSPDM_CRYPTO_ASN1_SEQUENCE 0x10
  ------------------
                      LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   90|  2.79k|#define LIBSPDM_CRYPTO_ASN1_CONSTRUCTED 0x20
  ------------------
 1012|  2.79k|    if (!status) {
  ------------------
  |  Branch (1012:9): [True: 0, False: 2.79k]
  ------------------
 1013|      0|        return false;
 1014|      0|    }
 1015|       |
 1016|  5.59k|    while(ptr < spdm_extension + len) {
  ------------------
  |  Branch (1016:11): [True: 2.79k, False: 2.79k]
  ------------------
 1017|  2.79k|        status = libspdm_asn1_get_tag(
 1018|  2.79k|            &ptr, spdm_extension + len, &obj_len,
 1019|  2.79k|            LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   80|  2.79k|#define LIBSPDM_CRYPTO_ASN1_SEQUENCE 0x10
  ------------------
                          LIBSPDM_CRYPTO_ASN1_SEQUENCE | LIBSPDM_CRYPTO_ASN1_CONSTRUCTED);
  ------------------
  |  |   90|  2.79k|#define LIBSPDM_CRYPTO_ASN1_CONSTRUCTED 0x20
  ------------------
 1020|  2.79k|        if (!status) {
  ------------------
  |  Branch (1020:13): [True: 0, False: 2.79k]
  ------------------
 1021|      0|            return false;
 1022|      0|        }
 1023|       |
 1024|  2.79k|        temptr = ptr + obj_len;
 1025|  2.79k|        status = libspdm_asn1_get_tag(
 1026|  2.79k|            &ptr, spdm_extension + len, &obj_len, LIBSPDM_CRYPTO_ASN1_OID);
  ------------------
  |  |   78|  2.79k|#define LIBSPDM_CRYPTO_ASN1_OID 0x06
  ------------------
 1027|  2.79k|        if (!status) {
  ------------------
  |  Branch (1027:13): [True: 0, False: 2.79k]
  ------------------
 1028|      0|            return false;
 1029|      0|        }
 1030|  2.79k|        if ((obj_len == sizeof(hardware_identity_oid)) &&
  ------------------
  |  Branch (1030:13): [True: 2.79k, False: 0]
  ------------------
 1031|  2.79k|            (libspdm_consttime_is_mem_equal(ptr, hardware_identity_oid,
  ------------------
  |  Branch (1031:13): [True: 2.79k, False: 0]
  ------------------
 1032|  2.79k|                                            sizeof(hardware_identity_oid)))) {
 1033|  2.79k|            find_sucessful = true;
 1034|  2.79k|        }
 1035|  2.79k|        ptr = temptr;
 1036|  2.79k|    }
 1037|       |
 1038|  2.79k|    if (ptr != spdm_extension + len) {
  ------------------
  |  Branch (1038:9): [True: 0, False: 2.79k]
  ------------------
 1039|      0|        return false;
 1040|      0|    }
 1041|       |
 1042|       |    /* Responder does not determine Requester's certificate model */
 1043|  2.79k|    if (!is_requester_cert) {
  ------------------
  |  Branch (1043:9): [True: 2.79k, False: 0]
  ------------------
 1044|  2.79k|        if ((find_sucessful) && (cert_model == SPDM_CERTIFICATE_INFO_CERT_MODEL_ALIAS_CERT)) {
  ------------------
  |  |  599|  2.79k|#define SPDM_CERTIFICATE_INFO_CERT_MODEL_ALIAS_CERT 0x2
  ------------------
  |  Branch (1044:13): [True: 2.79k, False: 0]
  |  Branch (1044:33): [True: 0, False: 2.79k]
  ------------------
 1045|       |            /* Hardware_identity_OID is found in alias cert model */
 1046|      0|            return false;
 1047|      0|        }
 1048|  2.79k|    }
 1049|       |
 1050|  2.79k|    return true;
 1051|  2.79k|}
libspdm_crypt_cert.c:libspdm_verify_leaf_cert_basic_constraints:
  750|  2.79k|{
  751|  2.79k|    bool status;
  752|       |    /*basic_constraints from cert*/
  753|  2.79k|    uint8_t cert_basic_constraints[LIBSPDM_MAX_BASIC_CONSTRAINTS_CA_LEN];
  754|  2.79k|    size_t len;
  755|       |
  756|  2.79k|    uint8_t basic_constraints_false_case1[] = BASIC_CONSTRAINTS_STRING_FALSE_CASE1;
  ------------------
  |  |   92|  2.79k|#define BASIC_CONSTRAINTS_STRING_FALSE_CASE1 {0x30, 0x00}
  ------------------
  757|  2.79k|    uint8_t basic_constraints_false_case2[] = BASIC_CONSTRAINTS_STRING_FALSE_CASE2;
  ------------------
  |  |   95|  2.79k|#define BASIC_CONSTRAINTS_STRING_FALSE_CASE2 {0x30, 0x03, 0x01, 0x01, 0x00}
  ------------------
  758|       |
  759|  2.79k|    len = LIBSPDM_MAX_BASIC_CONSTRAINTS_CA_LEN;
  ------------------
  |  |   37|  2.79k|#define LIBSPDM_MAX_BASIC_CONSTRAINTS_CA_LEN 10
  ------------------
  760|       |
  761|  2.79k|    status = libspdm_x509_get_extended_basic_constraints(cert, cert_size,
  762|  2.79k|                                                         cert_basic_constraints, &len);
  763|  2.79k|    if (!status) {
  ------------------
  |  Branch (763:9): [True: 0, False: 2.79k]
  ------------------
  764|      0|        return false;
  765|  2.79k|    } else if (len == 0) {
  ------------------
  |  Branch (765:16): [True: 0, False: 2.79k]
  ------------------
  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|  2.79k|    if ((len == sizeof(basic_constraints_false_case1)) &&
  ------------------
  |  Branch (774:9): [True: 2.79k, False: 0]
  ------------------
  775|  2.79k|        (libspdm_consttime_is_mem_equal(cert_basic_constraints,
  ------------------
  |  Branch (775:9): [True: 2.79k, False: 0]
  ------------------
  776|  2.79k|                                        basic_constraints_false_case1,
  777|  2.79k|                                        sizeof(basic_constraints_false_case1)))) {
  778|  2.79k|        return true;
  779|  2.79k|    }
  780|       |
  781|      0|    if ((len == sizeof(basic_constraints_false_case2)) &&
  ------------------
  |  Branch (781:9): [True: 0, False: 0]
  ------------------
  782|      0|        (libspdm_consttime_is_mem_equal(cert_basic_constraints,
  ------------------
  |  Branch (782:9): [True: 0, False: 0]
  ------------------
  783|      0|                                        basic_constraints_false_case2,
  784|      0|                                        sizeof(basic_constraints_false_case2)))) {
  785|      0|        return true;
  786|      0|    }
  787|       |
  788|      0|    return false;
  789|      0|}

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

libspdm_get_encap_request_get_certificate:
   15|    699|{
   16|    699|    spdm_get_certificate_request_t *spdm_request;
   17|    699|    libspdm_return_t status;
   18|       |
   19|    699|    spdm_context->encap_context.last_encap_request_size = 0;
   20|       |
   21|    699|    if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_11) {
  ------------------
  |  |  111|    699|#define SPDM_MESSAGE_VERSION_11 0x11
  ------------------
  |  Branch (21:9): [True: 699, False: 0]
  ------------------
   22|    699|        return LIBSPDM_STATUS_UNSUPPORTED_CAP;
  ------------------
  |  |   78|    699|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0002)
  |  |  ------------------
  |  |  |  |   55|    699|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
   23|    699|    }
   24|       |
   25|      0|    if (!libspdm_is_capabilities_flag_supported(
  ------------------
  |  Branch (25:9): [True: 0, False: 0]
  ------------------
   26|      0|            spdm_context, false,
   27|      0|            SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP, 0)) {
  ------------------
  |  |  185|      0|#define SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP 0x00000002
  ------------------
   28|      0|        return LIBSPDM_STATUS_UNSUPPORTED_CAP;
  ------------------
  |  |   78|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0002)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
   29|      0|    }
   30|       |
   31|      0|    LIBSPDM_ASSERT(*encap_request_size >= sizeof(spdm_get_certificate_request_t));
   32|      0|    *encap_request_size = sizeof(spdm_get_certificate_request_t);
   33|       |
   34|      0|    spdm_request = encap_request;
   35|       |
   36|      0|    spdm_request->header.spdm_version = libspdm_get_connection_version (spdm_context);
   37|      0|    spdm_request->header.request_response_code = SPDM_GET_CERTIFICATE;
  ------------------
  |  |   67|      0|#define SPDM_GET_CERTIFICATE 0x82
  ------------------
   38|      0|    spdm_request->header.param1 = spdm_context->encap_context.req_slot_id;
   39|      0|    spdm_request->header.param2 = 0;
   40|      0|    spdm_request->offset = (uint16_t)spdm_context->mut_auth_cert_chain_buffer_size;
   41|      0|    spdm_request->length = LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN;
  ------------------
  |  |  217|      0|#define LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN 1024
  ------------------
   42|      0|    LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "request (offset 0x%x, size 0x%x):\n",
   43|      0|                   spdm_request->offset, spdm_request->length));
   44|       |
   45|      0|    libspdm_reset_message_buffer_via_request_code(spdm_context, NULL,
   46|      0|                                                  spdm_request->header.request_response_code);
   47|       |
   48|       |    /* Cache data*/
   49|      0|    status = libspdm_append_message_mut_b(spdm_context, spdm_request, *encap_request_size);
   50|      0|    if (LIBSPDM_STATUS_IS_ERROR(status)) {
  ------------------
  |  |   30|      0|    (LIBSPDM_STATUS_SEVERITY(status) == LIBSPDM_SEVERITY_ERROR)
  |  |  ------------------
  |  |  |  |   37|      0|#define LIBSPDM_STATUS_SEVERITY(status) (((status) >> 28) & 0xf)
  |  |  ------------------
  |  |                   (LIBSPDM_STATUS_SEVERITY(status) == LIBSPDM_SEVERITY_ERROR)
  |  |  ------------------
  |  |  |  |   44|      0|#define LIBSPDM_SEVERITY_ERROR 0x8
  |  |  ------------------
  |  |  |  Branch (30:5): [True: 0, False: 0]
  |  |  ------------------
  ------------------
   51|      0|        return LIBSPDM_STATUS_BUFFER_FULL;
  ------------------
  |  |  118|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x000c)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
   52|      0|    }
   53|       |
   54|      0|    libspdm_copy_mem(&spdm_context->encap_context.last_encap_request_header,
   55|      0|                     sizeof(spdm_context->encap_context.last_encap_request_header),
   56|      0|                     &spdm_request->header, sizeof(spdm_message_header_t));
   57|      0|    spdm_context->encap_context.last_encap_request_size = *encap_request_size;
   58|       |
   59|      0|    return LIBSPDM_STATUS_SUCCESS;
  ------------------
  |  |   59|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_SUCCESS, LIBSPDM_SOURCE_SUCCESS, 0x0000)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
   60|      0|}
libspdm_process_encap_response_certificate:
   65|  2.09k|{
   66|  2.09k|    const spdm_certificate_response_t *spdm_response;
   67|  2.09k|    size_t spdm_response_size;
   68|  2.09k|    bool result;
   69|  2.09k|    libspdm_return_t status;
   70|  2.09k|    uint16_t request_offset;
   71|  2.09k|    uint8_t slot_id;
   72|  2.09k|    uint8_t *cert_chain_buffer;
   73|  2.09k|    size_t cert_chain_buffer_size;
   74|  2.09k|    size_t cert_chain_buffer_max_size;
   75|  2.09k|    uint8_t cert_model;
   76|       |
   77|  2.09k|    spdm_response = encap_response;
   78|  2.09k|    spdm_response_size = encap_response_size;
   79|       |
   80|  2.09k|    cert_chain_buffer = (uint8_t *)spdm_context->mut_auth_cert_chain_buffer;
   81|  2.09k|    cert_chain_buffer_size = spdm_context->mut_auth_cert_chain_buffer_size;
   82|  2.09k|    cert_chain_buffer_max_size = spdm_context->mut_auth_cert_chain_buffer_max_size;
   83|       |
   84|  2.09k|    if (spdm_response_size < sizeof(spdm_message_header_t)) {
  ------------------
  |  Branch (84:9): [True: 0, False: 2.09k]
  ------------------
   85|      0|        return LIBSPDM_STATUS_INVALID_MSG_SIZE;
  ------------------
  |  |   94|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0006)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
   86|      0|    }
   87|  2.09k|    if (spdm_response->header.spdm_version != libspdm_get_connection_version (spdm_context)) {
  ------------------
  |  Branch (87:9): [True: 156, False: 1.94k]
  ------------------
   88|    156|        return LIBSPDM_STATUS_INVALID_MSG_FIELD;
  ------------------
  |  |   90|    156|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0005)
  |  |  ------------------
  |  |  |  |   55|    156|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
   89|    156|    }
   90|  1.94k|    if (spdm_response->header.request_response_code == SPDM_ERROR) {
  ------------------
  |  |   37|  1.94k|#define SPDM_ERROR 0x7F
  ------------------
  |  Branch (90:9): [True: 39, False: 1.90k]
  ------------------
   91|     39|        status = libspdm_handle_encap_error_response_main(
   92|     39|            spdm_context, spdm_response->header.param1);
   93|     39|        if (LIBSPDM_STATUS_IS_ERROR(status)) {
  ------------------
  |  |   30|     39|    (LIBSPDM_STATUS_SEVERITY(status) == LIBSPDM_SEVERITY_ERROR)
  |  |  ------------------
  |  |  |  |   37|     39|#define LIBSPDM_STATUS_SEVERITY(status) (((status) >> 28) & 0xf)
  |  |  ------------------
  |  |                   (LIBSPDM_STATUS_SEVERITY(status) == LIBSPDM_SEVERITY_ERROR)
  |  |  ------------------
  |  |  |  |   44|     39|#define LIBSPDM_SEVERITY_ERROR 0x8
  |  |  ------------------
  |  |  |  Branch (30:5): [True: 39, False: 0]
  |  |  ------------------
  ------------------
   94|     39|            return status;
   95|     39|        }
   96|  1.90k|    } else if (spdm_response->header.request_response_code != SPDM_CERTIFICATE) {
  ------------------
  |  |   30|  1.90k|#define SPDM_CERTIFICATE 0x02
  ------------------
  |  Branch (96:16): [True: 42, False: 1.86k]
  ------------------
   97|     42|        return LIBSPDM_STATUS_INVALID_MSG_FIELD;
  ------------------
  |  |   90|     42|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0005)
  |  |  ------------------
  |  |  |  |   55|     42|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
   98|     42|    }
   99|  1.86k|    if (encap_response_size < sizeof(spdm_certificate_response_t)) {
  ------------------
  |  Branch (99:9): [True: 3, False: 1.85k]
  ------------------
  100|      3|        return LIBSPDM_STATUS_INVALID_MSG_SIZE;
  ------------------
  |  |   94|      3|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0006)
  |  |  ------------------
  |  |  |  |   55|      3|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  101|      3|    }
  102|  1.85k|    if ((spdm_response->portion_length > LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN) ||
  ------------------
  |  |  217|  1.85k|#define LIBSPDM_MAX_CERT_CHAIN_BLOCK_LEN 1024
  ------------------
  |  Branch (102:9): [True: 21, False: 1.83k]
  ------------------
  103|  1.85k|        (spdm_response->portion_length == 0)) {
  ------------------
  |  Branch (103:9): [True: 9, False: 1.82k]
  ------------------
  104|     30|        return LIBSPDM_STATUS_INVALID_MSG_FIELD;
  ------------------
  |  |   90|     30|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0005)
  |  |  ------------------
  |  |  |  |   55|     30|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  105|     30|    }
  106|       |
  107|  1.82k|    request_offset = (uint16_t)cert_chain_buffer_size;
  108|       |
  109|  1.82k|    if (spdm_response->portion_length > 0xFFFF - request_offset) {
  ------------------
  |  Branch (109:9): [True: 0, False: 1.82k]
  ------------------
  110|      0|        return LIBSPDM_STATUS_INVALID_MSG_FIELD;
  ------------------
  |  |   90|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0005)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  111|      0|    }
  112|  1.82k|    if (spdm_response->remainder_length > 0xFFFF - request_offset - spdm_response->portion_length) {
  ------------------
  |  Branch (112:9): [True: 71, False: 1.75k]
  ------------------
  113|     71|        return LIBSPDM_STATUS_INVALID_MSG_FIELD;
  ------------------
  |  |   90|     71|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0005)
  |  |  ------------------
  |  |  |  |   55|     71|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  114|     71|    }
  115|  1.75k|    if (request_offset == 0) {
  ------------------
  |  Branch (115:9): [True: 0, False: 1.75k]
  ------------------
  116|      0|        spdm_context->encap_context.cert_chain_total_len = spdm_response->portion_length +
  117|      0|                                                           spdm_response->remainder_length;
  118|  1.75k|    } else if (spdm_context->encap_context.cert_chain_total_len !=
  ------------------
  |  Branch (118:16): [True: 0, False: 1.75k]
  ------------------
  119|  1.75k|               request_offset + spdm_response->portion_length + spdm_response->remainder_length) {
  120|      0|        return LIBSPDM_STATUS_INVALID_MSG_FIELD;
  ------------------
  |  |   90|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0005)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  121|      0|    }
  122|  1.75k|    slot_id = spdm_context->encap_context.req_slot_id;
  123|  1.75k|    if ((spdm_response->header.param1 & SPDM_CERTIFICATE_RESPONSE_SLOT_ID_MASK) != slot_id) {
  ------------------
  |  |  642|  1.75k|#define SPDM_CERTIFICATE_RESPONSE_SLOT_ID_MASK 0xF
  ------------------
  |  Branch (123:9): [True: 31, False: 1.72k]
  ------------------
  124|     31|        return LIBSPDM_STATUS_INVALID_MSG_FIELD;
  ------------------
  |  |   90|     31|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0005)
  |  |  ------------------
  |  |  |  |   55|     31|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  125|     31|    }
  126|  1.72k|    if (spdm_response->header.spdm_version >= SPDM_MESSAGE_VERSION_13) {
  ------------------
  |  |  113|  1.72k|#define SPDM_MESSAGE_VERSION_13 0x13
  ------------------
  |  Branch (126:9): [True: 0, False: 1.72k]
  ------------------
  127|      0|        LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "cert_info - 0x%02x\n",
  128|      0|                       spdm_response->header.param2));
  129|      0|        cert_model = spdm_response->header.param2 &
  130|      0|                     SPDM_CERTIFICATE_RESPONSE_ATTRIBUTES_CERTIFICATE_INFO_MASK;
  ------------------
  |  |  645|      0|#define SPDM_CERTIFICATE_RESPONSE_ATTRIBUTES_CERTIFICATE_INFO_MASK 0x7
  ------------------
  131|      0|        if (spdm_context->connection_info.multi_key_conn_req) {
  ------------------
  |  Branch (131:13): [True: 0, False: 0]
  ------------------
  132|      0|            if (cert_model > SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT) {
  ------------------
  |  |  600|      0|#define SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT 0x3
  ------------------
  |  Branch (132:17): [True: 0, False: 0]
  ------------------
  133|      0|                return LIBSPDM_STATUS_INVALID_MSG_FIELD;
  ------------------
  |  |   90|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0005)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  134|      0|            }
  135|      0|            if ((slot_id == 0) &&
  ------------------
  |  Branch (135:17): [True: 0, False: 0]
  ------------------
  136|      0|                (cert_model == SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT)) {
  ------------------
  |  |  600|      0|#define SPDM_CERTIFICATE_INFO_CERT_MODEL_GENERIC_CERT 0x3
  ------------------
  |  Branch (136:17): [True: 0, False: 0]
  ------------------
  137|      0|                return LIBSPDM_STATUS_INVALID_MSG_FIELD;
  ------------------
  |  |   90|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0005)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  138|      0|            }
  139|      0|            if ((cert_model == SPDM_CERTIFICATE_INFO_CERT_MODEL_NONE) &&
  ------------------
  |  |  597|      0|#define SPDM_CERTIFICATE_INFO_CERT_MODEL_NONE 0x0
  ------------------
  |  Branch (139:17): [True: 0, False: 0]
  ------------------
  140|      0|                (spdm_response->portion_length != 0)) {
  ------------------
  |  Branch (140:17): [True: 0, False: 0]
  ------------------
  141|      0|                return LIBSPDM_STATUS_INVALID_MSG_FIELD;
  ------------------
  |  |   90|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0005)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  142|      0|            }
  143|      0|        } else {
  144|      0|            if (cert_model != SPDM_CERTIFICATE_INFO_CERT_MODEL_NONE) {
  ------------------
  |  |  597|      0|#define SPDM_CERTIFICATE_INFO_CERT_MODEL_NONE 0x0
  ------------------
  |  Branch (144:17): [True: 0, False: 0]
  ------------------
  145|      0|                return LIBSPDM_STATUS_INVALID_MSG_FIELD;
  ------------------
  |  |   90|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0005)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  146|      0|            }
  147|      0|        }
  148|      0|        if (spdm_context->connection_info.peer_cert_info[slot_id] ==
  ------------------
  |  Branch (148:13): [True: 0, False: 0]
  ------------------
  149|      0|            SPDM_CERTIFICATE_INFO_CERT_MODEL_NONE) {
  ------------------
  |  |  597|      0|#define SPDM_CERTIFICATE_INFO_CERT_MODEL_NONE 0x0
  ------------------
  150|      0|            spdm_context->connection_info.peer_cert_info[slot_id] = cert_model;
  151|      0|        } else if (spdm_context->connection_info.peer_cert_info[slot_id] != cert_model) {
  ------------------
  |  Branch (151:20): [True: 0, False: 0]
  ------------------
  152|      0|            return LIBSPDM_STATUS_INVALID_MSG_FIELD;
  ------------------
  |  |   90|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0005)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  153|      0|        }
  154|      0|    }
  155|       |
  156|  1.72k|    if (spdm_response_size < sizeof(spdm_certificate_response_t) + spdm_response->portion_length) {
  ------------------
  |  Branch (156:9): [True: 79, False: 1.64k]
  ------------------
  157|     79|        return LIBSPDM_STATUS_INVALID_MSG_SIZE;
  ------------------
  |  |   94|     79|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x0006)
  |  |  ------------------
  |  |  |  |   55|     79|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  158|     79|    }
  159|  1.64k|    spdm_response_size = sizeof(spdm_certificate_response_t) + spdm_response->portion_length;
  160|       |
  161|       |    /* Cache data*/
  162|       |
  163|  1.64k|    status = libspdm_append_message_mut_b(spdm_context, spdm_response, spdm_response_size);
  164|  1.64k|    if (LIBSPDM_STATUS_IS_ERROR(status)) {
  ------------------
  |  |   30|  1.64k|    (LIBSPDM_STATUS_SEVERITY(status) == LIBSPDM_SEVERITY_ERROR)
  |  |  ------------------
  |  |  |  |   37|  1.64k|#define LIBSPDM_STATUS_SEVERITY(status) (((status) >> 28) & 0xf)
  |  |  ------------------
  |  |                   (LIBSPDM_STATUS_SEVERITY(status) == LIBSPDM_SEVERITY_ERROR)
  |  |  ------------------
  |  |  |  |   44|  1.64k|#define LIBSPDM_SEVERITY_ERROR 0x8
  |  |  ------------------
  |  |  |  Branch (30:5): [True: 0, False: 1.64k]
  |  |  ------------------
  ------------------
  165|      0|        return LIBSPDM_STATUS_BUFFER_FULL;
  ------------------
  |  |  118|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x000c)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  166|      0|    }
  167|       |
  168|  1.64k|    LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "Certificate (offset 0x%x, size 0x%x):\n",
  169|  1.64k|                   request_offset, spdm_response->portion_length));
  170|  1.64k|    LIBSPDM_INTERNAL_DUMP_HEX((const void *)(spdm_response + 1), spdm_response->portion_length);
  171|       |
  172|  1.64k|    if ((cert_chain_buffer_size + spdm_response->portion_length) > cert_chain_buffer_max_size) {
  ------------------
  |  Branch (172:9): [True: 0, False: 1.64k]
  ------------------
  173|      0|        return LIBSPDM_STATUS_BUFFER_FULL;
  ------------------
  |  |  118|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CORE, 0x000c)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  174|      0|    }
  175|       |
  176|  1.64k|    libspdm_copy_mem(cert_chain_buffer + cert_chain_buffer_size,
  177|  1.64k|                     cert_chain_buffer_max_size - cert_chain_buffer_size,
  178|  1.64k|                     (const void *)(spdm_response + 1), spdm_response->portion_length);
  179|       |
  180|  1.64k|    cert_chain_buffer_size += spdm_response->portion_length;
  181|  1.64k|    spdm_context->mut_auth_cert_chain_buffer_size = cert_chain_buffer_size;
  182|       |
  183|  1.64k|    if (spdm_response->remainder_length != 0) {
  ------------------
  |  Branch (183:9): [True: 351, False: 1.29k]
  ------------------
  184|    351|        *need_continue = true;
  185|       |
  186|    351|        return LIBSPDM_STATUS_SUCCESS;
  ------------------
  |  |   59|    351|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_SUCCESS, LIBSPDM_SOURCE_SUCCESS, 0x0000)
  |  |  ------------------
  |  |  |  |   55|    351|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  187|    351|    }
  188|       |
  189|  1.29k|    *need_continue = false;
  190|       |
  191|  1.29k|    if (spdm_context->local_context.verify_peer_spdm_cert_chain != NULL) {
  ------------------
  |  Branch (191:9): [True: 568, False: 727]
  ------------------
  192|    568|        result = spdm_context->local_context.verify_peer_spdm_cert_chain (
  193|    568|            spdm_context, spdm_context->encap_context.req_slot_id,
  194|    568|            cert_chain_buffer_size, cert_chain_buffer, NULL, NULL);
  195|    568|        if (!result) {
  ------------------
  |  Branch (195:13): [True: 0, False: 568]
  ------------------
  196|      0|            return LIBSPDM_STATUS_VERIF_FAIL;
  ------------------
  |  |  160|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CRYPTO, 0x0001)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  197|      0|        }
  198|    727|    } else {
  199|    727|        result = libspdm_verify_peer_cert_chain_buffer_integrity(
  200|    727|            spdm_context, cert_chain_buffer, cert_chain_buffer_size);
  201|    727|        if (!result) {
  ------------------
  |  Branch (201:13): [True: 727, False: 0]
  ------------------
  202|    727|            return LIBSPDM_STATUS_VERIF_FAIL;
  ------------------
  |  |  160|    727|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CRYPTO, 0x0001)
  |  |  ------------------
  |  |  |  |   55|    727|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  203|    727|        }
  204|       |
  205|       |        /*verify peer cert chain authority*/
  206|      0|        result = libspdm_verify_peer_cert_chain_buffer_authority(
  207|      0|            spdm_context, cert_chain_buffer, cert_chain_buffer_size, NULL, NULL);
  208|      0|        if (!result) {
  ------------------
  |  Branch (208:13): [True: 0, False: 0]
  ------------------
  209|      0|            status = LIBSPDM_STATUS_VERIF_NO_AUTHORITY;
  ------------------
  |  |  168|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_WARNING, LIBSPDM_SOURCE_CRYPTO, 0x0003)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  210|      0|        }
  211|      0|    }
  212|       |
  213|    568|    spdm_context->connection_info.peer_used_cert_chain_slot_id =
  214|    568|        spdm_context->encap_context.req_slot_id;
  215|    568|    slot_id = spdm_context->encap_context.req_slot_id;
  216|    568|    LIBSPDM_ASSERT(slot_id < SPDM_MAX_SLOT_COUNT);
  217|       |#if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
  218|       |    spdm_context->connection_info.peer_used_cert_chain[slot_id].buffer_size =
  219|       |        cert_chain_buffer_size;
  220|       |
  221|       |    libspdm_copy_mem(spdm_context->connection_info.peer_used_cert_chain[slot_id].buffer,
  222|       |                     sizeof(spdm_context->connection_info.peer_used_cert_chain[slot_id].buffer),
  223|       |                     cert_chain_buffer, cert_chain_buffer_size);
  224|       |#else
  225|    568|    result = libspdm_hash_all(
  226|    568|        spdm_context->connection_info.algorithm.base_hash_algo,
  227|    568|        cert_chain_buffer, cert_chain_buffer_size,
  228|    568|        spdm_context->connection_info.peer_used_cert_chain[slot_id].buffer_hash);
  229|    568|    if (!result) {
  ------------------
  |  Branch (229:9): [True: 0, False: 568]
  ------------------
  230|      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)))
  |  |  ------------------
  ------------------
  231|      0|    }
  232|    568|    spdm_context->connection_info.peer_used_cert_chain[slot_id].buffer_hash_size =
  233|    568|        libspdm_get_hash_size(spdm_context->connection_info.algorithm.base_hash_algo);
  234|       |
  235|    568|    result = libspdm_get_leaf_cert_public_key_from_cert_chain(
  236|    568|        spdm_context->connection_info.algorithm.base_hash_algo,
  237|    568|        spdm_context->connection_info.algorithm.req_base_asym_alg,
  238|    568|        cert_chain_buffer, cert_chain_buffer_size,
  239|    568|        &spdm_context->connection_info.peer_used_cert_chain[slot_id].leaf_cert_public_key);
  240|    568|    if (!result) {
  ------------------
  |  Branch (240:9): [True: 54, False: 514]
  ------------------
  241|     54|        return LIBSPDM_STATUS_INVALID_CERT;
  ------------------
  |  |  178|     54|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_ERROR, LIBSPDM_SOURCE_CERT_PARSE, 0x0000)
  |  |  ------------------
  |  |  |  |   55|     54|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  242|     54|    }
  243|    514|#endif
  244|    514|    if (status != LIBSPDM_STATUS_VERIF_NO_AUTHORITY) {
  ------------------
  |  |  168|    514|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_WARNING, LIBSPDM_SOURCE_CRYPTO, 0x0003)
  |  |  ------------------
  |  |  |  |   55|    514|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  |  Branch (244:9): [True: 514, False: 0]
  ------------------
  245|    514|        return LIBSPDM_STATUS_SUCCESS;
  ------------------
  |  |   59|    514|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_SUCCESS, LIBSPDM_SOURCE_SUCCESS, 0x0000)
  |  |  ------------------
  |  |  |  |   55|    514|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  246|    514|    } else {
  247|      0|        return LIBSPDM_STATUS_VERIF_NO_AUTHORITY;
  ------------------
  |  |  168|      0|    LIBSPDM_STATUS_CONSTRUCT(LIBSPDM_SEVERITY_WARNING, LIBSPDM_SOURCE_CRYPTO, 0x0003)
  |  |  ------------------
  |  |  |  |   55|      0|    ((libspdm_return_t)(((severity) << 28) | ((source) << 16) | (code)))
  |  |  ------------------
  ------------------
  248|      0|    }
  249|    514|}

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

libspdm_register_cert_chain_buffer:
  900|  2.09k|{
  901|  2.09k|    libspdm_context_t *context;
  902|       |
  903|  2.09k|    LIBSPDM_ASSERT(spdm_context != NULL);
  904|       |
  905|  2.09k|    context = spdm_context;
  906|  2.09k|    context->mut_auth_cert_chain_buffer = cert_chain_buffer;
  907|  2.09k|    context->mut_auth_cert_chain_buffer_max_size = cert_chain_buffer_max_size;
  908|  2.09k|    context->mut_auth_cert_chain_buffer_size = 0;
  909|  2.09k|}

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

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

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

libspdm_rsa_new:
   32|  2.61k|{
   33|  2.61k|    void *rsa_context;
   34|       |
   35|  2.61k|    rsa_context = allocate_zero_pool(sizeof(mbedtls_rsa_context));
   36|  2.61k|    if (rsa_context == NULL) {
  ------------------
  |  Branch (36:9): [True: 0, False: 2.61k]
  ------------------
   37|      0|        return rsa_context;
   38|      0|    }
   39|       |
   40|  2.61k|    mbedtls_rsa_init(rsa_context);
   41|       |
   42|  2.61k|    return rsa_context;
   43|  2.61k|}
libspdm_rsa_free:
   52|  2.61k|{
   53|  2.61k|    mbedtls_rsa_free(rsa_context);
   54|  2.61k|    free_pool(rsa_context);
   55|  2.61k|}

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

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

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

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

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

x509_crt.c:mbedtls_error_add:
  144|     54|{
  145|       |#if defined(MBEDTLS_TEST_HOOKS)
  146|       |    if (*mbedtls_test_hook_error_add != NULL) {
  147|       |        (*mbedtls_test_hook_error_add)(high, low, file, line);
  148|       |    }
  149|       |#endif
  150|     54|    (void) file;
  151|     54|    (void) line;
  152|       |
  153|     54|    return high + low;
  154|     54|}

rsa.c:mbedtls_md_get_size_from_type:
  247|  4.19k|{
  248|  4.19k|    return mbedtls_md_get_size(mbedtls_md_info_from_type(md_type));
  249|  4.19k|}

x509.c:mbedtls_pk_rsa:
 1038|  2.61k|{
 1039|  2.61k|    switch (mbedtls_pk_get_type(&pk)) {
 1040|  2.61k|        case MBEDTLS_PK_RSA:
  ------------------
  |  Branch (1040:9): [True: 2.61k, False: 0]
  ------------------
 1041|  2.61k|            return (mbedtls_rsa_context *) (pk).MBEDTLS_PRIVATE(pk_ctx);
  ------------------
  |  |   15|  2.61k|#define MBEDTLS_PRIVATE(member) private_##member
  ------------------
 1042|      0|        default:
  ------------------
  |  Branch (1042:9): [True: 0, False: 2.61k]
  ------------------
 1043|      0|            return NULL;
 1044|  2.61k|    }
 1045|  2.61k|}
x509.c:mbedtls_pk_ec:
 1061|    699|{
 1062|    699|    switch (mbedtls_pk_get_type(&pk)) {
 1063|    699|        case MBEDTLS_PK_ECKEY:
  ------------------
  |  Branch (1063:9): [True: 699, False: 0]
  ------------------
 1064|    699|        case MBEDTLS_PK_ECKEY_DH:
  ------------------
  |  Branch (1064:9): [True: 0, False: 699]
  ------------------
 1065|    699|        case MBEDTLS_PK_ECDSA:
  ------------------
  |  Branch (1065:9): [True: 0, False: 699]
  ------------------
 1066|    699|            return (mbedtls_ecp_keypair *) (pk).MBEDTLS_PRIVATE(pk_ctx);
  ------------------
  |  |   15|    699|#define MBEDTLS_PRIVATE(member) private_##member
  ------------------
 1067|      0|        default:
  ------------------
  |  Branch (1067:9): [True: 0, False: 699]
  ------------------
 1068|      0|            return NULL;
 1069|    699|    }
 1070|    699|}
pkparse.c:mbedtls_pk_rsa:
 1038|  34.0k|{
 1039|  34.0k|    switch (mbedtls_pk_get_type(&pk)) {
 1040|  34.0k|        case MBEDTLS_PK_RSA:
  ------------------
  |  Branch (1040:9): [True: 34.0k, False: 0]
  ------------------
 1041|  34.0k|            return (mbedtls_rsa_context *) (pk).MBEDTLS_PRIVATE(pk_ctx);
  ------------------
  |  |   17|  34.0k|#define MBEDTLS_PRIVATE(member) member
  ------------------
 1042|      0|        default:
  ------------------
  |  Branch (1042:9): [True: 0, False: 34.0k]
  ------------------
 1043|      0|            return NULL;
 1044|  34.0k|    }
 1045|  34.0k|}

constant_time.c:mbedtls_get_unaligned_uint64:
  220|  17.6M|{
  221|  17.6M|    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|  17.6M|    memcpy(&r, p, sizeof(r));
  230|  17.6M|#endif
  231|  17.6M|    return r;
  232|  17.6M|}
constant_time.c:mbedtls_put_unaligned_uint64:
  247|  8.84M|{
  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|  8.84M|    memcpy(p, &x, sizeof(x));
  256|  8.84M|#endif
  257|  8.84M|}
sha256.c:mbedtls_get_unaligned_uint32:
  168|  2.22M|{
  169|  2.22M|    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|  2.22M|    memcpy(&r, p, sizeof(r));
  178|  2.22M|#endif
  179|  2.22M|    return r;
  180|  2.22M|}
sha256.c:mbedtls_put_unaligned_uint32:
  195|  89.5k|{
  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|  89.5k|    memcpy(p, &x, sizeof(x));
  204|  89.5k|#endif
  205|  89.5k|}

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

mbedtls_mpi_safe_cond_assign:
  121|  3.99M|{
  122|  3.99M|    int ret = 0;
  123|       |
  124|  3.99M|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, Y->n));
  ------------------
  |  |   41|  3.99M|    do                           \
  |  |   42|  3.99M|    {                            \
  |  |   43|  3.99M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3.99M]
  |  |  ------------------
  |  |   44|  3.99M|        goto cleanup;        \
  |  |   45|  3.99M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  125|       |
  126|  3.99M|    {
  127|  3.99M|        mbedtls_ct_condition_t do_assign = mbedtls_ct_bool(assign);
  128|       |
  129|  3.99M|        X->s = mbedtls_ct_mpi_sign_if(do_assign, Y->s, X->s);
  130|       |
  131|  3.99M|        mbedtls_mpi_core_cond_assign(X->p, Y->p, Y->n, do_assign);
  132|       |
  133|  3.99M|        mbedtls_ct_condition_t do_not_assign = mbedtls_ct_bool_not(do_assign);
  134|  4.00M|        for (size_t i = Y->n; i < X->n; i++) {
  ------------------
  |  Branch (134:31): [True: 13.9k, False: 3.99M]
  ------------------
  135|  13.9k|            X->p[i] = mbedtls_ct_mpi_uint_if_else_0(do_not_assign, X->p[i]);
  136|  13.9k|        }
  137|  3.99M|    }
  138|       |
  139|  3.99M|cleanup:
  140|  3.99M|    return ret;
  141|  3.99M|}
mbedtls_mpi_init:
  182|  11.7M|{
  183|  11.7M|    X->s = 1;
  184|  11.7M|    X->n = 0;
  185|  11.7M|    X->p = NULL;
  186|  11.7M|}
mbedtls_mpi_free:
  192|  12.1M|{
  193|  12.1M|    if (X == NULL) {
  ------------------
  |  Branch (193:9): [True: 0, False: 12.1M]
  ------------------
  194|      0|        return;
  195|      0|    }
  196|       |
  197|  12.1M|    if (X->p != NULL) {
  ------------------
  |  Branch (197:9): [True: 2.10M, False: 10.0M]
  ------------------
  198|  2.10M|        mbedtls_mpi_zeroize_and_free(X->p, X->n);
  ------------------
  |  |  176|  2.10M|#define mbedtls_mpi_zeroize_and_free(v, n) mbedtls_zeroize_and_free(v, ciL * (n))
  |  |  ------------------
  |  |  |  |   79|  2.10M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  199|  2.10M|    }
  200|       |
  201|  12.1M|    X->s = 1;
  202|  12.1M|    X->n = 0;
  203|  12.1M|    X->p = NULL;
  204|  12.1M|}
mbedtls_mpi_grow:
  210|  45.4M|{
  211|  45.4M|    mbedtls_mpi_uint *p;
  212|       |
  213|  45.4M|    if (nblimbs > MBEDTLS_MPI_MAX_LIMBS) {
  ------------------
  |  |   50|  45.4M|#define MBEDTLS_MPI_MAX_LIMBS                             10000
  ------------------
  |  Branch (213:9): [True: 0, False: 45.4M]
  ------------------
  214|      0|        return MBEDTLS_ERR_MPI_ALLOC_FAILED;
  ------------------
  |  |   38|      0|#define MBEDTLS_ERR_MPI_ALLOC_FAILED                      -0x0010
  ------------------
  215|      0|    }
  216|       |
  217|  45.4M|    if (X->n < nblimbs) {
  ------------------
  |  Branch (217:9): [True: 2.34M, False: 43.1M]
  ------------------
  218|  2.34M|        if ((p = (mbedtls_mpi_uint *) mbedtls_calloc(nblimbs, ciL)) == NULL) {
  ------------------
  |  |  144|  2.34M|#define mbedtls_calloc     MBEDTLS_PLATFORM_CALLOC_MACRO
  |  |  ------------------
  |  |  |  | 4093|  2.34M|#define MBEDTLS_PLATFORM_CALLOC_MACRO        my_calloc
  |  |  ------------------
  ------------------
                      if ((p = (mbedtls_mpi_uint *) mbedtls_calloc(nblimbs, ciL)) == NULL) {
  ------------------
  |  |   79|  2.34M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  |  Branch (218:13): [True: 0, False: 2.34M]
  ------------------
  219|      0|            return MBEDTLS_ERR_MPI_ALLOC_FAILED;
  ------------------
  |  |   38|      0|#define MBEDTLS_ERR_MPI_ALLOC_FAILED                      -0x0010
  ------------------
  220|      0|        }
  221|       |
  222|  2.34M|        if (X->p != NULL) {
  ------------------
  |  Branch (222:13): [True: 241k, False: 2.10M]
  ------------------
  223|   241k|            memcpy(p, X->p, X->n * ciL);
  ------------------
  |  |   79|   241k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  224|   241k|            mbedtls_mpi_zeroize_and_free(X->p, X->n);
  ------------------
  |  |  176|   241k|#define mbedtls_mpi_zeroize_and_free(v, n) mbedtls_zeroize_and_free(v, ciL * (n))
  |  |  ------------------
  |  |  |  |   79|   241k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  225|   241k|        }
  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|  2.34M|        X->n = (unsigned short) nblimbs;
  230|  2.34M|        X->p = p;
  231|  2.34M|    }
  232|       |
  233|  45.4M|    return 0;
  234|  45.4M|}
mbedtls_mpi_shrink:
  241|  32.1k|{
  242|  32.1k|    mbedtls_mpi_uint *p;
  243|  32.1k|    size_t i;
  244|       |
  245|  32.1k|    if (nblimbs > MBEDTLS_MPI_MAX_LIMBS) {
  ------------------
  |  |   50|  32.1k|#define MBEDTLS_MPI_MAX_LIMBS                             10000
  ------------------
  |  Branch (245:9): [True: 0, False: 32.1k]
  ------------------
  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|  32.1k|    if (X->n <= nblimbs) {
  ------------------
  |  Branch (250:9): [True: 0, False: 32.1k]
  ------------------
  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|   419k|    for (i = X->n - 1; i > 0; i--) {
  ------------------
  |  Branch (255:24): [True: 419k, False: 0]
  ------------------
  256|   419k|        if (X->p[i] != 0) {
  ------------------
  |  Branch (256:13): [True: 32.1k, False: 387k]
  ------------------
  257|  32.1k|            break;
  258|  32.1k|        }
  259|   419k|    }
  260|  32.1k|    i++;
  261|       |
  262|  32.1k|    if (i < nblimbs) {
  ------------------
  |  Branch (262:9): [True: 4.19k, False: 27.9k]
  ------------------
  263|  4.19k|        i = nblimbs;
  264|  4.19k|    }
  265|       |
  266|  32.1k|    if ((p = (mbedtls_mpi_uint *) mbedtls_calloc(i, ciL)) == NULL) {
  ------------------
  |  |  144|  32.1k|#define mbedtls_calloc     MBEDTLS_PLATFORM_CALLOC_MACRO
  |  |  ------------------
  |  |  |  | 4093|  32.1k|#define MBEDTLS_PLATFORM_CALLOC_MACRO        my_calloc
  |  |  ------------------
  ------------------
                  if ((p = (mbedtls_mpi_uint *) mbedtls_calloc(i, ciL)) == NULL) {
  ------------------
  |  |   79|  32.1k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  |  Branch (266:9): [True: 0, False: 32.1k]
  ------------------
  267|      0|        return MBEDTLS_ERR_MPI_ALLOC_FAILED;
  ------------------
  |  |   38|      0|#define MBEDTLS_ERR_MPI_ALLOC_FAILED                      -0x0010
  ------------------
  268|      0|    }
  269|       |
  270|  32.1k|    if (X->p != NULL) {
  ------------------
  |  Branch (270:9): [True: 32.1k, False: 0]
  ------------------
  271|  32.1k|        memcpy(p, X->p, i * ciL);
  ------------------
  |  |   79|  32.1k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  272|  32.1k|        mbedtls_mpi_zeroize_and_free(X->p, X->n);
  ------------------
  |  |  176|  32.1k|#define mbedtls_mpi_zeroize_and_free(v, n) mbedtls_zeroize_and_free(v, ciL * (n))
  |  |  ------------------
  |  |  |  |   79|  32.1k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  273|  32.1k|    }
  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|  32.1k|    X->n = (unsigned short) i;
  278|  32.1k|    X->p = p;
  279|       |
  280|  32.1k|    return 0;
  281|  32.1k|}
mbedtls_mpi_copy:
  308|  4.74M|{
  309|  4.74M|    int ret = 0;
  310|  4.74M|    size_t i;
  311|       |
  312|  4.74M|    if (X == Y) {
  ------------------
  |  Branch (312:9): [True: 450k, False: 4.29M]
  ------------------
  313|   450k|        return 0;
  314|   450k|    }
  315|       |
  316|  4.29M|    if (Y->n == 0) {
  ------------------
  |  Branch (316:9): [True: 29.4k, False: 4.26M]
  ------------------
  317|  29.4k|        if (X->n != 0) {
  ------------------
  |  Branch (317:13): [True: 0, False: 29.4k]
  ------------------
  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|  29.4k|        return 0;
  322|  29.4k|    }
  323|       |
  324|  37.1M|    for (i = Y->n - 1; i > 0; i--) {
  ------------------
  |  Branch (324:24): [True: 37.0M, False: 25.6k]
  ------------------
  325|  37.0M|        if (Y->p[i] != 0) {
  ------------------
  |  Branch (325:13): [True: 4.23M, False: 32.8M]
  ------------------
  326|  4.23M|            break;
  327|  4.23M|        }
  328|  37.0M|    }
  329|  4.26M|    i++;
  330|       |
  331|  4.26M|    X->s = Y->s;
  332|       |
  333|  4.26M|    if (X->n < i) {
  ------------------
  |  Branch (333:9): [True: 1.68M, False: 2.58M]
  ------------------
  334|  1.68M|        MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, i));
  ------------------
  |  |   41|  1.68M|    do                           \
  |  |   42|  1.68M|    {                            \
  |  |   43|  1.68M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.68M]
  |  |  ------------------
  |  |   44|  1.68M|        goto cleanup;        \
  |  |   45|  1.68M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  335|  2.58M|    } else {
  336|  2.58M|        memset(X->p + i, 0, (X->n - i) * ciL);
  ------------------
  |  |   79|  2.58M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  337|  2.58M|    }
  338|       |
  339|  4.26M|    memcpy(X->p, Y->p, i * ciL);
  ------------------
  |  |   79|  4.26M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  340|       |
  341|  4.26M|cleanup:
  342|       |
  343|  4.26M|    return ret;
  344|  4.26M|}
mbedtls_mpi_lset:
  378|  6.18M|{
  379|  6.18M|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  6.18M|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  380|       |
  381|  6.18M|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, 1));
  ------------------
  |  |   41|  6.18M|    do                           \
  |  |   42|  6.18M|    {                            \
  |  |   43|  6.18M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 6.18M]
  |  |  ------------------
  |  |   44|  6.18M|        goto cleanup;        \
  |  |   45|  6.18M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  382|  6.18M|    memset(X->p, 0, X->n * ciL);
  ------------------
  |  |   79|  6.18M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  383|       |
  384|  6.18M|    X->p[0] = mpi_sint_abs(z);
  385|  6.18M|    X->s    = TO_SIGN(z);
  ------------------
  |  |  372|  6.18M|#define TO_SIGN(x) ((mbedtls_mpi_sint) (((mbedtls_mpi_uint) x) >> (biL - 1)) * -2 + 1)
  |  |  ------------------
  |  |  |  |   80|  6.18M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  |  |  ------------------
  |  |  |  |  |  |   79|  6.18M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  386|       |
  387|  6.18M|cleanup:
  388|       |
  389|  6.18M|    return ret;
  390|  6.18M|}
mbedtls_mpi_get_bit:
  396|   841k|{
  397|   841k|    if (X->n * biL <= pos) {
  ------------------
  |  |   80|   841k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|   841k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  |  Branch (397:9): [True: 5.59k, False: 836k]
  ------------------
  398|  5.59k|        return 0;
  399|  5.59k|    }
  400|       |
  401|   836k|    return (X->p[pos / biL] >> (pos % biL)) & 0x01;
  ------------------
  |  |   80|   836k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|   836k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
                  return (X->p[pos / biL] >> (pos % biL)) & 0x01;
  ------------------
  |  |   80|   836k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|   836k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  402|   841k|}
mbedtls_mpi_lsb:
  437|  3.04M|{
  438|  3.04M|    size_t i;
  439|       |
  440|  3.04M|#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|  3.04M|#endif
  449|       |
  450|  3.04M|#if defined(mbedtls_mpi_uint_ctz)
  451|  3.04M|    for (i = 0; i < X->n; i++) {
  ------------------
  |  Branch (451:17): [True: 3.04M, False: 0]
  ------------------
  452|  3.04M|        if (X->p[i] != 0) {
  ------------------
  |  Branch (452:13): [True: 3.04M, False: 0]
  ------------------
  453|  3.04M|            return i * biL + mbedtls_mpi_uint_ctz(X->p[i]);
  ------------------
  |  |   80|  3.04M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  3.04M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
                          return i * biL + mbedtls_mpi_uint_ctz(X->p[i]);
  ------------------
  |  |  444|  3.04M|    #define mbedtls_mpi_uint_ctz __builtin_ctzl
  ------------------
  454|  3.04M|        }
  455|  3.04M|    }
  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|  3.04M|}
mbedtls_mpi_bitlen:
  474|  7.91M|{
  475|  7.91M|    return mbedtls_mpi_core_bitlen(X->p, X->n);
  476|  7.91M|}
mbedtls_mpi_size:
  482|   117k|{
  483|   117k|    return (mbedtls_mpi_bitlen(X) + 7) >> 3;
  484|   117k|}
mbedtls_mpi_read_binary:
  821|  98.8k|{
  822|  98.8k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  98.8k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  823|  98.8k|    const size_t limbs = CHARS_TO_LIMBS(buflen);
  ------------------
  |  |   88|  98.8k|#define CHARS_TO_LIMBS(i) ((i) / ciL + ((i) % ciL != 0))
  |  |  ------------------
  |  |  |  |   79|  98.8k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  |  |               #define CHARS_TO_LIMBS(i) ((i) / ciL + ((i) % ciL != 0))
  |  |  ------------------
  |  |  |  |   79|  98.8k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  824|       |
  825|       |    /* Ensure that target MPI has exactly the necessary number of limbs */
  826|  98.8k|    MBEDTLS_MPI_CHK(mbedtls_mpi_resize_clear(X, limbs));
  ------------------
  |  |   41|  98.8k|    do                           \
  |  |   42|  98.8k|    {                            \
  |  |   43|  98.8k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 98.8k]
  |  |  ------------------
  |  |   44|  98.8k|        goto cleanup;        \
  |  |   45|  98.8k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  827|       |
  828|  98.8k|    MBEDTLS_MPI_CHK(mbedtls_mpi_core_read_be(X->p, X->n, buf, buflen));
  ------------------
  |  |   41|  98.8k|    do                           \
  |  |   42|  98.8k|    {                            \
  |  |   43|  98.8k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 98.8k]
  |  |  ------------------
  |  |   44|  98.8k|        goto cleanup;        \
  |  |   45|  98.8k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  829|       |
  830|  98.8k|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|  98.8k|    return ret;
  838|  98.8k|}
mbedtls_mpi_write_binary:
  854|  4.19k|{
  855|  4.19k|    return mbedtls_mpi_core_write_be(X->p, X->n, buf, buflen);
  856|  4.19k|}
mbedtls_mpi_shift_l:
  862|  2.18M|{
  863|  2.18M|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  2.18M|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  864|  2.18M|    size_t i;
  865|       |
  866|  2.18M|    i = mbedtls_mpi_bitlen(X) + count;
  867|       |
  868|  2.18M|    if (X->n * biL < i) {
  ------------------
  |  |   80|  2.18M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  2.18M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  |  Branch (868:9): [True: 20.9k, False: 2.16M]
  ------------------
  869|  20.9k|        MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, BITS_TO_LIMBS(i)));
  ------------------
  |  |   41|  20.9k|    do                           \
  |  |   42|  20.9k|    {                            \
  |  |   43|  20.9k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 20.9k]
  |  |  ------------------
  |  |   44|  20.9k|        goto cleanup;        \
  |  |   45|  20.9k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  870|  20.9k|    }
  871|       |
  872|  2.18M|    ret = 0;
  873|       |
  874|  2.18M|    mbedtls_mpi_core_shift_l(X->p, X->n, count);
  875|  2.18M|cleanup:
  876|       |
  877|  2.18M|    return ret;
  878|  2.18M|}
mbedtls_mpi_shift_r:
  884|  13.6M|{
  885|  13.6M|    if (X->n != 0) {
  ------------------
  |  Branch (885:9): [True: 13.6M, False: 0]
  ------------------
  886|  13.6M|        mbedtls_mpi_core_shift_r(X->p, X->n, count);
  887|  13.6M|    }
  888|  13.6M|    return 0;
  889|  13.6M|}
mbedtls_mpi_cmp_abs:
  895|  13.8M|{
  896|  13.8M|    size_t i, j;
  897|       |
  898|  69.0M|    for (i = X->n; i > 0; i--) {
  ------------------
  |  Branch (898:20): [True: 69.0M, False: 13.2k]
  ------------------
  899|  69.0M|        if (X->p[i - 1] != 0) {
  ------------------
  |  Branch (899:13): [True: 13.8M, False: 55.1M]
  ------------------
  900|  13.8M|            break;
  901|  13.8M|        }
  902|  69.0M|    }
  903|       |
  904|  41.1M|    for (j = Y->n; j > 0; j--) {
  ------------------
  |  Branch (904:20): [True: 41.1M, False: 3.49k]
  ------------------
  905|  41.1M|        if (Y->p[j - 1] != 0) {
  ------------------
  |  Branch (905:13): [True: 13.8M, False: 27.2M]
  ------------------
  906|  13.8M|            break;
  907|  13.8M|        }
  908|  41.1M|    }
  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|  13.8M|    if (i > j) {
  ------------------
  |  Branch (913:9): [True: 1.39M, False: 12.4M]
  ------------------
  914|  1.39M|        return 1;
  915|  1.39M|    }
  916|  12.4M|    if (j > i) {
  ------------------
  |  Branch (916:9): [True: 24.4k, False: 12.4M]
  ------------------
  917|  24.4k|        return -1;
  918|  24.4k|    }
  919|       |
  920|  12.7M|    for (; i > 0; i--) {
  ------------------
  |  Branch (920:12): [True: 12.6M, False: 19.5k]
  ------------------
  921|  12.6M|        if (X->p[i - 1] > Y->p[i - 1]) {
  ------------------
  |  Branch (921:13): [True: 4.32M, False: 8.36M]
  ------------------
  922|  4.32M|            return 1;
  923|  4.32M|        }
  924|  8.36M|        if (X->p[i - 1] < Y->p[i - 1]) {
  ------------------
  |  Branch (924:13): [True: 8.10M, False: 259k]
  ------------------
  925|  8.10M|            return -1;
  926|  8.10M|        }
  927|  8.36M|    }
  928|       |
  929|  19.5k|    return 0;
  930|  12.4M|}
mbedtls_mpi_cmp_mpi:
  936|  25.2M|{
  937|  25.2M|    size_t i, j;
  938|       |
  939|   170M|    for (i = X->n; i > 0; i--) {
  ------------------
  |  Branch (939:20): [True: 170M, False: 221k]
  ------------------
  940|   170M|        if (X->p[i - 1] != 0) {
  ------------------
  |  Branch (940:13): [True: 24.9M, False: 145M]
  ------------------
  941|  24.9M|            break;
  942|  24.9M|        }
  943|   170M|    }
  944|       |
  945|  40.4M|    for (j = Y->n; j > 0; j--) {
  ------------------
  |  Branch (945:20): [True: 29.9M, False: 10.5M]
  ------------------
  946|  29.9M|        if (Y->p[j - 1] != 0) {
  ------------------
  |  Branch (946:13): [True: 14.6M, False: 15.2M]
  ------------------
  947|  14.6M|            break;
  948|  14.6M|        }
  949|  29.9M|    }
  950|       |
  951|  25.2M|    if (i == 0 && j == 0) {
  ------------------
  |  Branch (951:9): [True: 221k, False: 24.9M]
  |  Branch (951:19): [True: 221k, False: 0]
  ------------------
  952|   221k|        return 0;
  953|   221k|    }
  954|       |
  955|  24.9M|    if (i > j) {
  ------------------
  |  Branch (955:9): [True: 12.9M, False: 12.0M]
  ------------------
  956|  12.9M|        return X->s;
  957|  12.9M|    }
  958|  12.0M|    if (j > i) {
  ------------------
  |  Branch (958:9): [True: 94.1k, False: 11.9M]
  ------------------
  959|  94.1k|        return -Y->s;
  960|  94.1k|    }
  961|       |
  962|  11.9M|    if (X->s > 0 && Y->s < 0) {
  ------------------
  |  Branch (962:9): [True: 11.9M, False: 0]
  |  Branch (962:21): [True: 0, False: 11.9M]
  ------------------
  963|      0|        return 1;
  964|      0|    }
  965|  11.9M|    if (Y->s > 0 && X->s < 0) {
  ------------------
  |  Branch (965:9): [True: 11.9M, False: 0]
  |  Branch (965:21): [True: 0, False: 11.9M]
  ------------------
  966|      0|        return -1;
  967|      0|    }
  968|       |
  969|  12.5M|    for (; i > 0; i--) {
  ------------------
  |  Branch (969:12): [True: 12.3M, False: 230k]
  ------------------
  970|  12.3M|        if (X->p[i - 1] > Y->p[i - 1]) {
  ------------------
  |  Branch (970:13): [True: 1.69M, False: 10.6M]
  ------------------
  971|  1.69M|            return X->s;
  972|  1.69M|        }
  973|  10.6M|        if (X->p[i - 1] < Y->p[i - 1]) {
  ------------------
  |  Branch (973:13): [True: 10.0M, False: 620k]
  ------------------
  974|  10.0M|            return -X->s;
  975|  10.0M|        }
  976|  10.6M|    }
  977|       |
  978|   230k|    return 0;
  979|  11.9M|}
mbedtls_mpi_cmp_int:
  985|  10.7M|{
  986|  10.7M|    mbedtls_mpi Y;
  987|  10.7M|    mbedtls_mpi_uint p[1];
  988|       |
  989|  10.7M|    *p  = mpi_sint_abs(z);
  990|  10.7M|    Y.s = TO_SIGN(z);
  ------------------
  |  |  372|  10.7M|#define TO_SIGN(x) ((mbedtls_mpi_sint) (((mbedtls_mpi_uint) x) >> (biL - 1)) * -2 + 1)
  |  |  ------------------
  |  |  |  |   80|  10.7M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  |  |  ------------------
  |  |  |  |  |  |   79|  10.7M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  991|  10.7M|    Y.n = 1;
  992|  10.7M|    Y.p = p;
  993|       |
  994|  10.7M|    return mbedtls_mpi_cmp_mpi(X, &Y);
  995|  10.7M|}
mbedtls_mpi_add_abs:
 1001|  3.40M|{
 1002|  3.40M|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  3.40M|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1003|  3.40M|    size_t j;
 1004|  3.40M|    mbedtls_mpi_uint *p;
 1005|  3.40M|    mbedtls_mpi_uint c;
 1006|       |
 1007|  3.40M|    if (X == B) {
  ------------------
  |  Branch (1007:9): [True: 0, False: 3.40M]
  ------------------
 1008|      0|        const mbedtls_mpi *T = A; A = X; B = T;
 1009|      0|    }
 1010|       |
 1011|  3.40M|    if (X != A) {
  ------------------
  |  Branch (1011:9): [True: 430k, False: 2.97M]
  ------------------
 1012|   430k|        MBEDTLS_MPI_CHK(mbedtls_mpi_copy(X, A));
  ------------------
  |  |   41|   430k|    do                           \
  |  |   42|   430k|    {                            \
  |  |   43|   430k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 430k]
  |  |  ------------------
  |  |   44|   430k|        goto cleanup;        \
  |  |   45|   430k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1013|   430k|    }
 1014|       |
 1015|       |    /*
 1016|       |     * X must always be positive as a result of unsigned additions.
 1017|       |     */
 1018|  3.40M|    X->s = 1;
 1019|       |
 1020|  6.28M|    for (j = B->n; j > 0; j--) {
  ------------------
  |  Branch (1020:20): [True: 6.28M, False: 699]
  ------------------
 1021|  6.28M|        if (B->p[j - 1] != 0) {
  ------------------
  |  Branch (1021:13): [True: 3.40M, False: 2.88M]
  ------------------
 1022|  3.40M|            break;
 1023|  3.40M|        }
 1024|  6.28M|    }
 1025|       |
 1026|       |    /* Exit early to avoid undefined behavior on NULL+0 when X->n == 0
 1027|       |     * and B is 0 (of any size). */
 1028|  3.40M|    if (j == 0) {
  ------------------
  |  Branch (1028:9): [True: 699, False: 3.40M]
  ------------------
 1029|    699|        return 0;
 1030|    699|    }
 1031|       |
 1032|  3.40M|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, j));
  ------------------
  |  |   41|  3.40M|    do                           \
  |  |   42|  3.40M|    {                            \
  |  |   43|  3.40M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3.40M]
  |  |  ------------------
  |  |   44|  3.40M|        goto cleanup;        \
  |  |   45|  3.40M|    } 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|  3.40M|    p = X->p;
 1037|       |
 1038|  3.40M|    c = mbedtls_mpi_core_add(p, p, B->p, j);
 1039|       |
 1040|  3.40M|    p += j;
 1041|       |
 1042|       |    /* Now propagate any carry */
 1043|       |
 1044|  4.90M|    while (c != 0) {
  ------------------
  |  Branch (1044:12): [True: 1.50M, False: 3.40M]
  ------------------
 1045|  1.50M|        if (j >= X->n) {
  ------------------
  |  Branch (1045:13): [True: 16.0k, False: 1.48M]
  ------------------
 1046|  16.0k|            MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, j + 1));
  ------------------
  |  |   41|  16.0k|    do                           \
  |  |   42|  16.0k|    {                            \
  |  |   43|  16.0k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 16.0k]
  |  |  ------------------
  |  |   44|  16.0k|        goto cleanup;        \
  |  |   45|  16.0k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1047|  16.0k|            p = X->p + j;
 1048|  16.0k|        }
 1049|       |
 1050|  1.50M|        *p += c; c = (*p < c); j++; p++;
 1051|  1.50M|    }
 1052|       |
 1053|  3.40M|cleanup:
 1054|       |
 1055|  3.40M|    return ret;
 1056|  3.40M|}
mbedtls_mpi_sub_abs:
 1062|  17.9M|{
 1063|  17.9M|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  17.9M|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1064|  17.9M|    size_t n;
 1065|  17.9M|    mbedtls_mpi_uint carry;
 1066|       |
 1067|  71.3M|    for (n = B->n; n > 0; n--) {
  ------------------
  |  Branch (1067:20): [True: 71.3M, False: 16.7k]
  ------------------
 1068|  71.3M|        if (B->p[n - 1] != 0) {
  ------------------
  |  Branch (1068:13): [True: 17.9M, False: 53.4M]
  ------------------
 1069|  17.9M|            break;
 1070|  17.9M|        }
 1071|  71.3M|    }
 1072|  17.9M|    if (n > A->n) {
  ------------------
  |  Branch (1072:9): [True: 0, False: 17.9M]
  ------------------
 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|  17.9M|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, A->n));
  ------------------
  |  |   41|  17.9M|    do                           \
  |  |   42|  17.9M|    {                            \
  |  |   43|  17.9M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 17.9M]
  |  |  ------------------
  |  |   44|  17.9M|        goto cleanup;        \
  |  |   45|  17.9M|    } 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|  17.9M|    if (A->n > n && A != X) {
  ------------------
  |  Branch (1083:9): [True: 10.9M, False: 6.95M]
  |  Branch (1083:21): [True: 2.52M, False: 8.45M]
  ------------------
 1084|  2.52M|        memcpy(X->p + n, A->p + n, (A->n - n) * ciL);
  ------------------
  |  |   79|  2.52M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
 1085|  2.52M|    }
 1086|  17.9M|    if (X->n > A->n) {
  ------------------
  |  Branch (1086:9): [True: 5.61M, False: 12.3M]
  ------------------
 1087|  5.61M|        memset(X->p + A->n, 0, (X->n - A->n) * ciL);
  ------------------
  |  |   79|  5.61M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
 1088|  5.61M|    }
 1089|       |
 1090|  17.9M|    carry = mbedtls_mpi_core_sub(X->p, A->p, B->p, n);
 1091|  17.9M|    if (carry != 0) {
  ------------------
  |  Branch (1091:9): [True: 3.92M, False: 14.0M]
  ------------------
 1092|       |        /* Propagate the carry through the rest of X. */
 1093|  3.92M|        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|  3.92M|        if (carry != 0) {
  ------------------
  |  Branch (1096:13): [True: 0, False: 3.92M]
  ------------------
 1097|      0|            ret = MBEDTLS_ERR_MPI_NEGATIVE_VALUE;
  ------------------
  |  |   32|      0|#define MBEDTLS_ERR_MPI_NEGATIVE_VALUE                    -0x000A
  ------------------
 1098|      0|            goto cleanup;
 1099|      0|        }
 1100|  3.92M|    }
 1101|       |
 1102|       |    /* X should always be positive as a result of unsigned subtractions. */
 1103|  17.9M|    X->s = 1;
 1104|       |
 1105|  17.9M|cleanup:
 1106|  17.9M|    return ret;
 1107|  17.9M|}
mbedtls_mpi_add_mpi:
 1146|  7.78M|{
 1147|  7.78M|    return add_sub_mpi(X, A, B, 1);
 1148|  7.78M|}
mbedtls_mpi_sub_mpi:
 1154|  9.48M|{
 1155|  9.48M|    return add_sub_mpi(X, A, B, -1);
 1156|  9.48M|}
mbedtls_mpi_sub_int:
 1178|  13.9k|{
 1179|  13.9k|    mbedtls_mpi B;
 1180|  13.9k|    mbedtls_mpi_uint p[1];
 1181|       |
 1182|  13.9k|    p[0] = mpi_sint_abs(b);
 1183|  13.9k|    B.s = TO_SIGN(b);
  ------------------
  |  |  372|  13.9k|#define TO_SIGN(x) ((mbedtls_mpi_sint) (((mbedtls_mpi_uint) x) >> (biL - 1)) * -2 + 1)
  |  |  ------------------
  |  |  |  |   80|  13.9k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  |  |  ------------------
  |  |  |  |  |  |   79|  13.9k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1184|  13.9k|    B.n = 1;
 1185|  13.9k|    B.p = p;
 1186|       |
 1187|  13.9k|    return mbedtls_mpi_sub_mpi(X, A, &B);
 1188|  13.9k|}
mbedtls_mpi_mul_mpi:
 1194|  5.50M|{
 1195|  5.50M|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  5.50M|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1196|  5.50M|    size_t i, j;
 1197|  5.50M|    mbedtls_mpi TA, TB;
 1198|  5.50M|    int result_is_zero = 0;
 1199|       |
 1200|  5.50M|    mbedtls_mpi_init(&TA);
 1201|  5.50M|    mbedtls_mpi_init(&TB);
 1202|       |
 1203|  5.50M|    if (X == A) {
  ------------------
  |  Branch (1203:9): [True: 1.54M, False: 3.95M]
  ------------------
 1204|  1.54M|        MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TA, A)); A = &TA;
  ------------------
  |  |   41|  1.54M|    do                           \
  |  |   42|  1.54M|    {                            \
  |  |   43|  1.54M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.54M]
  |  |  ------------------
  |  |   44|  1.54M|        goto cleanup;        \
  |  |   45|  1.54M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1205|  1.54M|    }
 1206|  5.50M|    if (X == B) {
  ------------------
  |  Branch (1206:9): [True: 18.1k, False: 5.48M]
  ------------------
 1207|  18.1k|        MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TB, B)); B = &TB;
  ------------------
  |  |   41|  18.1k|    do                           \
  |  |   42|  18.1k|    {                            \
  |  |   43|  18.1k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 18.1k]
  |  |  ------------------
  |  |   44|  18.1k|        goto cleanup;        \
  |  |   45|  18.1k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1208|  18.1k|    }
 1209|       |
 1210|  18.5M|    for (i = A->n; i > 0; i--) {
  ------------------
  |  Branch (1210:20): [True: 18.5M, False: 0]
  ------------------
 1211|  18.5M|        if (A->p[i - 1] != 0) {
  ------------------
  |  Branch (1211:13): [True: 5.50M, False: 13.0M]
  ------------------
 1212|  5.50M|            break;
 1213|  5.50M|        }
 1214|  18.5M|    }
 1215|  5.50M|    if (i == 0) {
  ------------------
  |  Branch (1215:9): [True: 0, False: 5.50M]
  ------------------
 1216|      0|        result_is_zero = 1;
 1217|      0|    }
 1218|       |
 1219|  24.5M|    for (j = B->n; j > 0; j--) {
  ------------------
  |  Branch (1219:20): [True: 24.5M, False: 0]
  ------------------
 1220|  24.5M|        if (B->p[j - 1] != 0) {
  ------------------
  |  Branch (1220:13): [True: 5.50M, False: 19.0M]
  ------------------
 1221|  5.50M|            break;
 1222|  5.50M|        }
 1223|  24.5M|    }
 1224|  5.50M|    if (j == 0) {
  ------------------
  |  Branch (1224:9): [True: 0, False: 5.50M]
  ------------------
 1225|      0|        result_is_zero = 1;
 1226|      0|    }
 1227|       |
 1228|  5.50M|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, i + j));
  ------------------
  |  |   41|  5.50M|    do                           \
  |  |   42|  5.50M|    {                            \
  |  |   43|  5.50M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 5.50M]
  |  |  ------------------
  |  |   44|  5.50M|        goto cleanup;        \
  |  |   45|  5.50M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1229|  5.50M|    MBEDTLS_MPI_CHK(mbedtls_mpi_lset(X, 0));
  ------------------
  |  |   41|  5.50M|    do                           \
  |  |   42|  5.50M|    {                            \
  |  |   43|  5.50M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 5.50M]
  |  |  ------------------
  |  |   44|  5.50M|        goto cleanup;        \
  |  |   45|  5.50M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1230|       |
 1231|  5.50M|    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|  5.50M|    if (result_is_zero) {
  ------------------
  |  Branch (1237:9): [True: 0, False: 5.50M]
  ------------------
 1238|      0|        X->s = 1;
 1239|  5.50M|    } else {
 1240|  5.50M|        X->s = A->s * B->s;
 1241|  5.50M|    }
 1242|       |
 1243|  5.50M|cleanup:
 1244|       |
 1245|  5.50M|    mbedtls_mpi_free(&TB); mbedtls_mpi_free(&TA);
 1246|       |
 1247|  5.50M|    return ret;
 1248|  5.50M|}
mbedtls_mpi_mul_int:
 1254|  1.12M|{
 1255|  1.12M|    size_t n = A->n;
 1256|  65.7M|    while (n > 0 && A->p[n - 1] == 0) {
  ------------------
  |  Branch (1256:12): [True: 65.7M, False: 0]
  |  Branch (1256:21): [True: 64.6M, False: 1.12M]
  ------------------
 1257|  64.6M|        --n;
 1258|  64.6M|    }
 1259|       |
 1260|       |    /* The general method below doesn't work if b==0. */
 1261|  1.12M|    if (b == 0 || n == 0) {
  ------------------
  |  Branch (1261:9): [True: 0, False: 1.12M]
  |  Branch (1261:19): [True: 0, False: 1.12M]
  ------------------
 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|  1.12M|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  1.12M|#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|  1.12M|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, n + 1));
  ------------------
  |  |   41|  1.12M|    do                           \
  |  |   42|  1.12M|    {                            \
  |  |   43|  1.12M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.12M]
  |  |  ------------------
  |  |   44|  1.12M|        goto cleanup;        \
  |  |   45|  1.12M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1279|  1.12M|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(X, A));
  ------------------
  |  |   41|  1.12M|    do                           \
  |  |   42|  1.12M|    {                            \
  |  |   43|  1.12M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.12M]
  |  |  ------------------
  |  |   44|  1.12M|        goto cleanup;        \
  |  |   45|  1.12M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1280|  1.12M|    mbedtls_mpi_core_mla(X->p, X->n, A->p, n, b - 1);
 1281|       |
 1282|  1.12M|cleanup:
 1283|  1.12M|    return ret;
 1284|  1.12M|}
mbedtls_mpi_div_mpi:
 1395|  16.7k|{
 1396|  16.7k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  16.7k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1397|  16.7k|    size_t i, n, t, k;
 1398|  16.7k|    mbedtls_mpi X, Y, Z, T1, T2;
 1399|  16.7k|    mbedtls_mpi_uint TP2[3];
 1400|       |
 1401|  16.7k|    if (mbedtls_mpi_cmp_int(B, 0) == 0) {
  ------------------
  |  Branch (1401:9): [True: 0, False: 16.7k]
  ------------------
 1402|      0|        return MBEDTLS_ERR_MPI_DIVISION_BY_ZERO;
  ------------------
  |  |   34|      0|#define MBEDTLS_ERR_MPI_DIVISION_BY_ZERO                  -0x000C
  ------------------
 1403|      0|    }
 1404|       |
 1405|  16.7k|    mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y); mbedtls_mpi_init(&Z);
 1406|  16.7k|    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|  16.7k|    T2.s = 1;
 1415|  16.7k|    T2.n = sizeof(TP2) / sizeof(*TP2);
 1416|  16.7k|    T2.p = TP2;
 1417|       |
 1418|  16.7k|    if (mbedtls_mpi_cmp_abs(A, B) < 0) {
  ------------------
  |  Branch (1418:9): [True: 9.78k, False: 6.99k]
  ------------------
 1419|  9.78k|        if (Q != NULL) {
  ------------------
  |  Branch (1419:13): [True: 0, False: 9.78k]
  ------------------
 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|  9.78k|        if (R != NULL) {
  ------------------
  |  Branch (1422:13): [True: 9.78k, False: 0]
  ------------------
 1423|  9.78k|            MBEDTLS_MPI_CHK(mbedtls_mpi_copy(R, A));
  ------------------
  |  |   41|  9.78k|    do                           \
  |  |   42|  9.78k|    {                            \
  |  |   43|  9.78k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 9.78k]
  |  |  ------------------
  |  |   44|  9.78k|        goto cleanup;        \
  |  |   45|  9.78k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1424|  9.78k|        }
 1425|  9.78k|        return 0;
 1426|  9.78k|    }
 1427|       |
 1428|  6.99k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&X, A));
  ------------------
  |  |   41|  6.99k|    do                           \
  |  |   42|  6.99k|    {                            \
  |  |   43|  6.99k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 6.99k]
  |  |  ------------------
  |  |   44|  6.99k|        goto cleanup;        \
  |  |   45|  6.99k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1429|  6.99k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&Y, B));
  ------------------
  |  |   41|  6.99k|    do                           \
  |  |   42|  6.99k|    {                            \
  |  |   43|  6.99k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 6.99k]
  |  |  ------------------
  |  |   44|  6.99k|        goto cleanup;        \
  |  |   45|  6.99k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1430|  6.99k|    X.s = Y.s = 1;
 1431|       |
 1432|  6.99k|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(&Z, A->n + 2));
  ------------------
  |  |   41|  6.99k|    do                           \
  |  |   42|  6.99k|    {                            \
  |  |   43|  6.99k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 6.99k]
  |  |  ------------------
  |  |   44|  6.99k|        goto cleanup;        \
  |  |   45|  6.99k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1433|  6.99k|    MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&Z,  0));
  ------------------
  |  |   41|  6.99k|    do                           \
  |  |   42|  6.99k|    {                            \
  |  |   43|  6.99k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 6.99k]
  |  |  ------------------
  |  |   44|  6.99k|        goto cleanup;        \
  |  |   45|  6.99k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1434|  6.99k|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(&T1, A->n + 2));
  ------------------
  |  |   41|  6.99k|    do                           \
  |  |   42|  6.99k|    {                            \
  |  |   43|  6.99k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 6.99k]
  |  |  ------------------
  |  |   44|  6.99k|        goto cleanup;        \
  |  |   45|  6.99k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1435|       |
 1436|  6.99k|    k = mbedtls_mpi_bitlen(&Y) % biL;
  ------------------
  |  |   80|  6.99k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  6.99k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
 1437|  6.99k|    if (k < biL - 1) {
  ------------------
  |  |   80|  6.99k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  6.99k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  |  Branch (1437:9): [True: 6.99k, False: 0]
  ------------------
 1438|  6.99k|        k = biL - 1 - k;
  ------------------
  |  |   80|  6.99k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  6.99k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
 1439|  6.99k|        MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&X, k));
  ------------------
  |  |   41|  6.99k|    do                           \
  |  |   42|  6.99k|    {                            \
  |  |   43|  6.99k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 6.99k]
  |  |  ------------------
  |  |   44|  6.99k|        goto cleanup;        \
  |  |   45|  6.99k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1440|  6.99k|        MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&Y, k));
  ------------------
  |  |   41|  6.99k|    do                           \
  |  |   42|  6.99k|    {                            \
  |  |   43|  6.99k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 6.99k]
  |  |  ------------------
  |  |   44|  6.99k|        goto cleanup;        \
  |  |   45|  6.99k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1441|  6.99k|    } else {
 1442|      0|        k = 0;
 1443|      0|    }
 1444|       |
 1445|  6.99k|    n = X.n - 1;
 1446|  6.99k|    t = Y.n - 1;
 1447|  6.99k|    MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&Y, biL * (n - t)));
  ------------------
  |  |   41|  6.99k|    do                           \
  |  |   42|  6.99k|    {                            \
  |  |   43|  6.99k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 6.99k]
  |  |  ------------------
  |  |   44|  6.99k|        goto cleanup;        \
  |  |   45|  6.99k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1448|       |
 1449|  11.1k|    while (mbedtls_mpi_cmp_mpi(&X, &Y) >= 0) {
  ------------------
  |  Branch (1449:12): [True: 4.19k, False: 6.99k]
  ------------------
 1450|  4.19k|        Z.p[n - t]++;
 1451|  4.19k|        MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&X, &X, &Y));
  ------------------
  |  |   41|  4.19k|    do                           \
  |  |   42|  4.19k|    {                            \
  |  |   43|  4.19k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.19k]
  |  |  ------------------
  |  |   44|  4.19k|        goto cleanup;        \
  |  |   45|  4.19k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1452|  4.19k|    }
 1453|  6.99k|    MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&Y, biL * (n - t)));
  ------------------
  |  |   41|  6.99k|    do                           \
  |  |   42|  6.99k|    {                            \
  |  |   43|  6.99k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 6.99k]
  |  |  ------------------
  |  |   44|  6.99k|        goto cleanup;        \
  |  |   45|  6.99k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1454|       |
 1455|   261k|    for (i = n; i > t; i--) {
  ------------------
  |  Branch (1455:17): [True: 254k, False: 6.99k]
  ------------------
 1456|   254k|        if (X.p[i] >= Y.p[t]) {
  ------------------
  |  Branch (1456:13): [True: 0, False: 254k]
  ------------------
 1457|      0|            Z.p[i - t - 1] = ~(mbedtls_mpi_uint) 0u;
 1458|   254k|        } else {
 1459|   254k|            Z.p[i - t - 1] = mbedtls_int_div_int(X.p[i], X.p[i - 1],
 1460|   254k|                                                 Y.p[t], NULL);
 1461|   254k|        }
 1462|       |
 1463|   254k|        T2.p[0] = (i < 2) ? 0 : X.p[i - 2];
  ------------------
  |  Branch (1463:19): [True: 0, False: 254k]
  ------------------
 1464|   254k|        T2.p[1] = (i < 1) ? 0 : X.p[i - 1];
  ------------------
  |  Branch (1464:19): [True: 0, False: 254k]
  ------------------
 1465|   254k|        T2.p[2] = X.p[i];
 1466|       |
 1467|   254k|        Z.p[i - t - 1]++;
 1468|   444k|        do {
 1469|   444k|            Z.p[i - t - 1]--;
 1470|       |
 1471|   444k|            MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&T1, 0));
  ------------------
  |  |   41|   444k|    do                           \
  |  |   42|   444k|    {                            \
  |  |   43|   444k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 444k]
  |  |  ------------------
  |  |   44|   444k|        goto cleanup;        \
  |  |   45|   444k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1472|   444k|            T1.p[0] = (t < 1) ? 0 : Y.p[t - 1];
  ------------------
  |  Branch (1472:23): [True: 0, False: 444k]
  ------------------
 1473|   444k|            T1.p[1] = Y.p[t];
 1474|   444k|            MBEDTLS_MPI_CHK(mbedtls_mpi_mul_int(&T1, &T1, Z.p[i - t - 1]));
  ------------------
  |  |   41|   444k|    do                           \
  |  |   42|   444k|    {                            \
  |  |   43|   444k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 444k]
  |  |  ------------------
  |  |   44|   444k|        goto cleanup;        \
  |  |   45|   444k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1475|   444k|        } while (mbedtls_mpi_cmp_mpi(&T1, &T2) > 0);
  ------------------
  |  Branch (1475:18): [True: 190k, False: 254k]
  ------------------
 1476|       |
 1477|   254k|        MBEDTLS_MPI_CHK(mbedtls_mpi_mul_int(&T1, &Y, Z.p[i - t - 1]));
  ------------------
  |  |   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]
  |  |  ------------------
  ------------------
 1478|   254k|        MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&T1,  biL * (i - t - 1)));
  ------------------
  |  |   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]
  |  |  ------------------
  ------------------
 1479|   254k|        MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&X, &X, &T1));
  ------------------
  |  |   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]
  |  |  ------------------
  ------------------
 1480|       |
 1481|   254k|        if (mbedtls_mpi_cmp_int(&X, 0) < 0) {
  ------------------
  |  Branch (1481:13): [True: 0, False: 254k]
  ------------------
 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|   254k|    }
 1488|       |
 1489|  6.99k|    if (Q != NULL) {
  ------------------
  |  Branch (1489:9): [True: 0, False: 6.99k]
  ------------------
 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|  6.99k|    if (R != NULL) {
  ------------------
  |  Branch (1494:9): [True: 6.99k, False: 0]
  ------------------
 1495|  6.99k|        MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&X, k));
  ------------------
  |  |   41|  6.99k|    do                           \
  |  |   42|  6.99k|    {                            \
  |  |   43|  6.99k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 6.99k]
  |  |  ------------------
  |  |   44|  6.99k|        goto cleanup;        \
  |  |   45|  6.99k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1496|  6.99k|        X.s = A->s;
 1497|  6.99k|        MBEDTLS_MPI_CHK(mbedtls_mpi_copy(R, &X));
  ------------------
  |  |   41|  6.99k|    do                           \
  |  |   42|  6.99k|    {                            \
  |  |   43|  6.99k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 6.99k]
  |  |  ------------------
  |  |   44|  6.99k|        goto cleanup;        \
  |  |   45|  6.99k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1498|       |
 1499|  6.99k|        if (mbedtls_mpi_cmp_int(R, 0) == 0) {
  ------------------
  |  Branch (1499:13): [True: 0, False: 6.99k]
  ------------------
 1500|      0|            R->s = 1;
 1501|      0|        }
 1502|  6.99k|    }
 1503|       |
 1504|  6.99k|cleanup:
 1505|       |
 1506|  6.99k|    mbedtls_mpi_free(&X); mbedtls_mpi_free(&Y); mbedtls_mpi_free(&Z);
 1507|  6.99k|    mbedtls_mpi_free(&T1);
 1508|  6.99k|    mbedtls_platform_zeroize(TP2, sizeof(TP2));
 1509|       |
 1510|  6.99k|    return ret;
 1511|  6.99k|}
mbedtls_mpi_mod_mpi:
 1535|  16.7k|{
 1536|  16.7k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  16.7k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1537|       |
 1538|  16.7k|    if (mbedtls_mpi_cmp_int(B, 0) < 0) {
  ------------------
  |  Branch (1538:9): [True: 0, False: 16.7k]
  ------------------
 1539|      0|        return MBEDTLS_ERR_MPI_NEGATIVE_VALUE;
  ------------------
  |  |   32|      0|#define MBEDTLS_ERR_MPI_NEGATIVE_VALUE                    -0x000A
  ------------------
 1540|      0|    }
 1541|       |
 1542|  16.7k|    MBEDTLS_MPI_CHK(mbedtls_mpi_div_mpi(NULL, R, A, B));
  ------------------
  |  |   41|  16.7k|    do                           \
  |  |   42|  16.7k|    {                            \
  |  |   43|  16.7k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 16.7k]
  |  |  ------------------
  |  |   44|  16.7k|        goto cleanup;        \
  |  |   45|  16.7k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1543|       |
 1544|  16.7k|    while (mbedtls_mpi_cmp_int(R, 0) < 0) {
  ------------------
  |  Branch (1544:12): [True: 0, False: 16.7k]
  ------------------
 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|  16.7k|    while (mbedtls_mpi_cmp_mpi(R, B) >= 0) {
  ------------------
  |  Branch (1548:12): [True: 0, False: 16.7k]
  ------------------
 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|  16.7k|cleanup:
 1553|       |
 1554|  16.7k|    return ret;
 1555|  16.7k|}
mbedtls_mpi_exp_mod_unsafe:
 1742|  4.19k|{
 1743|  4.19k|    return mbedtls_mpi_exp_mod_optionally_safe(X, A, E, MBEDTLS_MPI_IS_PUBLIC, N, prec_RR);
  ------------------
  |  |  111|  4.19k|#define MBEDTLS_MPI_IS_PUBLIC  0x2a2a2a2a
  ------------------
 1744|  4.19k|}
mbedtls_mpi_gcd:
 1750|  8.38k|{
 1751|  8.38k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  8.38k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1752|  8.38k|    size_t lz, lzt;
 1753|  8.38k|    mbedtls_mpi TA, TB;
 1754|       |
 1755|  8.38k|    mbedtls_mpi_init(&TA); mbedtls_mpi_init(&TB);
 1756|       |
 1757|  8.38k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TA, A));
  ------------------
  |  |   41|  8.38k|    do                           \
  |  |   42|  8.38k|    {                            \
  |  |   43|  8.38k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 8.38k]
  |  |  ------------------
  |  |   44|  8.38k|        goto cleanup;        \
  |  |   45|  8.38k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1758|  8.38k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TB, B));
  ------------------
  |  |   41|  8.38k|    do                           \
  |  |   42|  8.38k|    {                            \
  |  |   43|  8.38k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 8.38k]
  |  |  ------------------
  |  |   44|  8.38k|        goto cleanup;        \
  |  |   45|  8.38k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1759|       |
 1760|  8.38k|    lz = mbedtls_mpi_lsb(&TA);
 1761|  8.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|  8.38k|    if (lzt == 0 && mbedtls_mpi_get_bit(&TB, 0) == 0) {
  ------------------
  |  Branch (1767:9): [True: 8.38k, False: 0]
  |  Branch (1767:21): [True: 0, False: 8.38k]
  ------------------
 1768|      0|        ret = mbedtls_mpi_copy(G, A);
 1769|      0|        goto cleanup;
 1770|      0|    }
 1771|       |
 1772|  8.38k|    if (lzt < lz) {
  ------------------
  |  Branch (1772:9): [True: 4.89k, False: 3.49k]
  ------------------
 1773|  4.89k|        lz = lzt;
 1774|  4.89k|    }
 1775|       |
 1776|  8.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|  1.52M|    while (mbedtls_mpi_cmp_int(&TA, 0) != 0) {
  ------------------
  |  Branch (1811:12): [True: 1.51M, False: 8.38k]
  ------------------
 1812|       |        /* Divisions by 2 preserve the invariant (I). */
 1813|  1.51M|        MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TA, mbedtls_mpi_lsb(&TA)));
  ------------------
  |  |   41|  1.51M|    do                           \
  |  |   42|  1.51M|    {                            \
  |  |   43|  1.51M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.51M]
  |  |  ------------------
  |  |   44|  1.51M|        goto cleanup;        \
  |  |   45|  1.51M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1814|  1.51M|        MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TB, mbedtls_mpi_lsb(&TB)));
  ------------------
  |  |   41|  1.51M|    do                           \
  |  |   42|  1.51M|    {                            \
  |  |   43|  1.51M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.51M]
  |  |  ------------------
  |  |   44|  1.51M|        goto cleanup;        \
  |  |   45|  1.51M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 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|  1.51M|        if (mbedtls_mpi_cmp_mpi(&TA, &TB) >= 0) {
  ------------------
  |  Branch (1823:13): [True: 777k, False: 738k]
  ------------------
 1824|   777k|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs(&TA, &TA, &TB));
  ------------------
  |  |   41|   777k|    do                           \
  |  |   42|   777k|    {                            \
  |  |   43|   777k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 777k]
  |  |  ------------------
  |  |   44|   777k|        goto cleanup;        \
  |  |   45|   777k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1825|   777k|            MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TA, 1));
  ------------------
  |  |   41|   777k|    do                           \
  |  |   42|   777k|    {                            \
  |  |   43|   777k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 777k]
  |  |  ------------------
  |  |   44|   777k|        goto cleanup;        \
  |  |   45|   777k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1826|   777k|        } else {
 1827|   738k|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs(&TB, &TB, &TA));
  ------------------
  |  |   41|   738k|    do                           \
  |  |   42|   738k|    {                            \
  |  |   43|   738k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 738k]
  |  |  ------------------
  |  |   44|   738k|        goto cleanup;        \
  |  |   45|   738k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1828|   738k|            MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TB, 1));
  ------------------
  |  |   41|   738k|    do                           \
  |  |   42|   738k|    {                            \
  |  |   43|   738k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 738k]
  |  |  ------------------
  |  |   44|   738k|        goto cleanup;        \
  |  |   45|   738k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1829|   738k|        }
 1830|       |        /* Note that one of TA or TB is still odd. */
 1831|  1.51M|    }
 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|  8.38k|    MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&TB, lz));
  ------------------
  |  |   41|  8.38k|    do                           \
  |  |   42|  8.38k|    {                            \
  |  |   43|  8.38k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 8.38k]
  |  |  ------------------
  |  |   44|  8.38k|        goto cleanup;        \
  |  |   45|  8.38k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1843|  8.38k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(G, &TB));
  ------------------
  |  |   41|  8.38k|    do                           \
  |  |   42|  8.38k|    {                            \
  |  |   43|  8.38k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 8.38k]
  |  |  ------------------
  |  |   44|  8.38k|        goto cleanup;        \
  |  |   45|  8.38k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1844|       |
 1845|  8.38k|cleanup:
 1846|       |
 1847|  8.38k|    mbedtls_mpi_free(&TA); mbedtls_mpi_free(&TB);
 1848|       |
 1849|  8.38k|    return ret;
 1850|  8.38k|}
mbedtls_mpi_inv_mod:
 1905|  8.38k|{
 1906|  8.38k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  8.38k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1907|  8.38k|    mbedtls_mpi G, TA, TU, U1, U2, TB, TV, V1, V2;
 1908|       |
 1909|  8.38k|    if (mbedtls_mpi_cmp_int(N, 1) <= 0) {
  ------------------
  |  Branch (1909:9): [True: 0, False: 8.38k]
  ------------------
 1910|      0|        return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MPI_BAD_INPUT_DATA                    -0x0004
  ------------------
 1911|      0|    }
 1912|       |
 1913|  8.38k|    mbedtls_mpi_init(&TA); mbedtls_mpi_init(&TU); mbedtls_mpi_init(&U1); mbedtls_mpi_init(&U2);
 1914|  8.38k|    mbedtls_mpi_init(&G); mbedtls_mpi_init(&TB); mbedtls_mpi_init(&TV);
 1915|  8.38k|    mbedtls_mpi_init(&V1); mbedtls_mpi_init(&V2);
 1916|       |
 1917|  8.38k|    MBEDTLS_MPI_CHK(mbedtls_mpi_gcd(&G, A, N));
  ------------------
  |  |   41|  8.38k|    do                           \
  |  |   42|  8.38k|    {                            \
  |  |   43|  8.38k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 8.38k]
  |  |  ------------------
  |  |   44|  8.38k|        goto cleanup;        \
  |  |   45|  8.38k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1918|       |
 1919|  8.38k|    if (mbedtls_mpi_cmp_int(&G, 1) != 0) {
  ------------------
  |  Branch (1919:9): [True: 0, False: 8.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|  8.38k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&TA, A, N));
  ------------------
  |  |   41|  8.38k|    do                           \
  |  |   42|  8.38k|    {                            \
  |  |   43|  8.38k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 8.38k]
  |  |  ------------------
  |  |   44|  8.38k|        goto cleanup;        \
  |  |   45|  8.38k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1925|  8.38k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TU, &TA));
  ------------------
  |  |   41|  8.38k|    do                           \
  |  |   42|  8.38k|    {                            \
  |  |   43|  8.38k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 8.38k]
  |  |  ------------------
  |  |   44|  8.38k|        goto cleanup;        \
  |  |   45|  8.38k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1926|  8.38k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TB, N));
  ------------------
  |  |   41|  8.38k|    do                           \
  |  |   42|  8.38k|    {                            \
  |  |   43|  8.38k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 8.38k]
  |  |  ------------------
  |  |   44|  8.38k|        goto cleanup;        \
  |  |   45|  8.38k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1927|  8.38k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TV, N));
  ------------------
  |  |   41|  8.38k|    do                           \
  |  |   42|  8.38k|    {                            \
  |  |   43|  8.38k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 8.38k]
  |  |  ------------------
  |  |   44|  8.38k|        goto cleanup;        \
  |  |   45|  8.38k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1928|       |
 1929|  8.38k|    MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&U1, 1));
  ------------------
  |  |   41|  8.38k|    do                           \
  |  |   42|  8.38k|    {                            \
  |  |   43|  8.38k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 8.38k]
  |  |  ------------------
  |  |   44|  8.38k|        goto cleanup;        \
  |  |   45|  8.38k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1930|  8.38k|    MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&U2, 0));
  ------------------
  |  |   41|  8.38k|    do                           \
  |  |   42|  8.38k|    {                            \
  |  |   43|  8.38k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 8.38k]
  |  |  ------------------
  |  |   44|  8.38k|        goto cleanup;        \
  |  |   45|  8.38k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1931|  8.38k|    MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&V1, 0));
  ------------------
  |  |   41|  8.38k|    do                           \
  |  |   42|  8.38k|    {                            \
  |  |   43|  8.38k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 8.38k]
  |  |  ------------------
  |  |   44|  8.38k|        goto cleanup;        \
  |  |   45|  8.38k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1932|  8.38k|    MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&V2, 1));
  ------------------
  |  |   41|  8.38k|    do                           \
  |  |   42|  8.38k|    {                            \
  |  |   43|  8.38k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 8.38k]
  |  |  ------------------
  |  |   44|  8.38k|        goto cleanup;        \
  |  |   45|  8.38k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1933|       |
 1934|  1.51M|    do {
 1935|  3.04M|        while ((TU.p[0] & 1) == 0) {
  ------------------
  |  Branch (1935:16): [True: 1.52M, False: 1.51M]
  ------------------
 1936|  1.52M|            MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TU, 1));
  ------------------
  |  |   41|  1.52M|    do                           \
  |  |   42|  1.52M|    {                            \
  |  |   43|  1.52M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.52M]
  |  |  ------------------
  |  |   44|  1.52M|        goto cleanup;        \
  |  |   45|  1.52M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1937|       |
 1938|  1.52M|            if ((U1.p[0] & 1) != 0 || (U2.p[0] & 1) != 0) {
  ------------------
  |  Branch (1938:17): [True: 631k, False: 893k]
  |  Branch (1938:39): [True: 0, False: 893k]
  ------------------
 1939|   631k|                MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&U1, &U1, &TB));
  ------------------
  |  |   41|   631k|    do                           \
  |  |   42|   631k|    {                            \
  |  |   43|   631k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 631k]
  |  |  ------------------
  |  |   44|   631k|        goto cleanup;        \
  |  |   45|   631k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1940|   631k|                MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&U2, &U2, &TA));
  ------------------
  |  |   41|   631k|    do                           \
  |  |   42|   631k|    {                            \
  |  |   43|   631k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 631k]
  |  |  ------------------
  |  |   44|   631k|        goto cleanup;        \
  |  |   45|   631k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1941|   631k|            }
 1942|       |
 1943|  1.52M|            MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&U1, 1));
  ------------------
  |  |   41|  1.52M|    do                           \
  |  |   42|  1.52M|    {                            \
  |  |   43|  1.52M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.52M]
  |  |  ------------------
  |  |   44|  1.52M|        goto cleanup;        \
  |  |   45|  1.52M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1944|  1.52M|            MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&U2, 1));
  ------------------
  |  |   41|  1.52M|    do                           \
  |  |   42|  1.52M|    {                            \
  |  |   43|  1.52M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.52M]
  |  |  ------------------
  |  |   44|  1.52M|        goto cleanup;        \
  |  |   45|  1.52M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1945|  1.52M|        }
 1946|       |
 1947|  3.00M|        while ((TV.p[0] & 1) == 0) {
  ------------------
  |  Branch (1947:16): [True: 1.49M, False: 1.51M]
  ------------------
 1948|  1.49M|            MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TV, 1));
  ------------------
  |  |   41|  1.49M|    do                           \
  |  |   42|  1.49M|    {                            \
  |  |   43|  1.49M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.49M]
  |  |  ------------------
  |  |   44|  1.49M|        goto cleanup;        \
  |  |   45|  1.49M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1949|       |
 1950|  1.49M|            if ((V1.p[0] & 1) != 0 || (V2.p[0] & 1) != 0) {
  ------------------
  |  Branch (1950:17): [True: 666k, False: 825k]
  |  Branch (1950:39): [True: 0, False: 825k]
  ------------------
 1951|   666k|                MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&V1, &V1, &TB));
  ------------------
  |  |   41|   666k|    do                           \
  |  |   42|   666k|    {                            \
  |  |   43|   666k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 666k]
  |  |  ------------------
  |  |   44|   666k|        goto cleanup;        \
  |  |   45|   666k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1952|   666k|                MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&V2, &V2, &TA));
  ------------------
  |  |   41|   666k|    do                           \
  |  |   42|   666k|    {                            \
  |  |   43|   666k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 666k]
  |  |  ------------------
  |  |   44|   666k|        goto cleanup;        \
  |  |   45|   666k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1953|   666k|            }
 1954|       |
 1955|  1.49M|            MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&V1, 1));
  ------------------
  |  |   41|  1.49M|    do                           \
  |  |   42|  1.49M|    {                            \
  |  |   43|  1.49M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.49M]
  |  |  ------------------
  |  |   44|  1.49M|        goto cleanup;        \
  |  |   45|  1.49M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1956|  1.49M|            MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&V2, 1));
  ------------------
  |  |   41|  1.49M|    do                           \
  |  |   42|  1.49M|    {                            \
  |  |   43|  1.49M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1.49M]
  |  |  ------------------
  |  |   44|  1.49M|        goto cleanup;        \
  |  |   45|  1.49M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1957|  1.49M|        }
 1958|       |
 1959|  1.51M|        if (mbedtls_mpi_cmp_mpi(&TU, &TV) >= 0) {
  ------------------
  |  Branch (1959:13): [True: 777k, False: 738k]
  ------------------
 1960|   777k|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&TU, &TU, &TV));
  ------------------
  |  |   41|   777k|    do                           \
  |  |   42|   777k|    {                            \
  |  |   43|   777k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 777k]
  |  |  ------------------
  |  |   44|   777k|        goto cleanup;        \
  |  |   45|   777k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1961|   777k|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&U1, &U1, &V1));
  ------------------
  |  |   41|   777k|    do                           \
  |  |   42|   777k|    {                            \
  |  |   43|   777k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 777k]
  |  |  ------------------
  |  |   44|   777k|        goto cleanup;        \
  |  |   45|   777k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1962|   777k|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&U2, &U2, &V2));
  ------------------
  |  |   41|   777k|    do                           \
  |  |   42|   777k|    {                            \
  |  |   43|   777k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 777k]
  |  |  ------------------
  |  |   44|   777k|        goto cleanup;        \
  |  |   45|   777k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1963|   777k|        } else {
 1964|   738k|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&TV, &TV, &TU));
  ------------------
  |  |   41|   738k|    do                           \
  |  |   42|   738k|    {                            \
  |  |   43|   738k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 738k]
  |  |  ------------------
  |  |   44|   738k|        goto cleanup;        \
  |  |   45|   738k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1965|   738k|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&V1, &V1, &U1));
  ------------------
  |  |   41|   738k|    do                           \
  |  |   42|   738k|    {                            \
  |  |   43|   738k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 738k]
  |  |  ------------------
  |  |   44|   738k|        goto cleanup;        \
  |  |   45|   738k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1966|   738k|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&V2, &V2, &U2));
  ------------------
  |  |   41|   738k|    do                           \
  |  |   42|   738k|    {                            \
  |  |   43|   738k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 738k]
  |  |  ------------------
  |  |   44|   738k|        goto cleanup;        \
  |  |   45|   738k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1967|   738k|        }
 1968|  1.51M|    } while (mbedtls_mpi_cmp_int(&TU, 0) != 0);
  ------------------
  |  Branch (1968:14): [True: 1.50M, False: 8.38k]
  ------------------
 1969|       |
 1970|  9.08k|    while (mbedtls_mpi_cmp_int(&V1, 0) < 0) {
  ------------------
  |  Branch (1970:12): [True: 699, False: 8.38k]
  ------------------
 1971|    699|        MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&V1, &V1, N));
  ------------------
  |  |   41|    699|    do                           \
  |  |   42|    699|    {                            \
  |  |   43|    699|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 699]
  |  |  ------------------
  |  |   44|    699|        goto cleanup;        \
  |  |   45|    699|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1972|    699|    }
 1973|       |
 1974|  8.38k|    while (mbedtls_mpi_cmp_mpi(&V1, N) >= 0) {
  ------------------
  |  Branch (1974:12): [True: 0, False: 8.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|  8.38k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(X, &V1));
  ------------------
  |  |   41|  8.38k|    do                           \
  |  |   42|  8.38k|    {                            \
  |  |   43|  8.38k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 8.38k]
  |  |  ------------------
  |  |   44|  8.38k|        goto cleanup;        \
  |  |   45|  8.38k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1979|       |
 1980|  8.38k|cleanup:
 1981|       |
 1982|  8.38k|    mbedtls_mpi_free(&TA); mbedtls_mpi_free(&TU); mbedtls_mpi_free(&U1); mbedtls_mpi_free(&U2);
 1983|  8.38k|    mbedtls_mpi_free(&G); mbedtls_mpi_free(&TB); mbedtls_mpi_free(&TV);
 1984|  8.38k|    mbedtls_mpi_free(&V1); mbedtls_mpi_free(&V2);
 1985|       |
 1986|  8.38k|    return ret;
 1987|  8.38k|}
bignum.c:mbedtls_ct_mpi_sign_if:
   50|  3.99M|{
   51|  3.99M|    return (signed short) mbedtls_ct_uint_if(cond, sign1 + 1, sign2 + 1) - 1;
   52|  3.99M|}
bignum.c:mpi_sint_abs:
  359|  16.9M|{
  360|  16.9M|    if (z >= 0) {
  ------------------
  |  Branch (360:9): [True: 16.9M, False: 2.79k]
  ------------------
  361|  16.9M|        return z;
  362|  16.9M|    }
  363|       |    /* Take care to handle the most negative value (-2^(biL-1)) correctly.
  364|       |     * A naive -z would have undefined behavior.
  365|       |     * Write this in a way that makes popular compilers happy (GCC, Clang,
  366|       |     * MSVC). */
  367|  2.79k|    return (mbedtls_mpi_uint) 0 - (mbedtls_mpi_uint) z;
  368|  16.9M|}
bignum.c:mbedtls_mpi_resize_clear:
  285|  98.8k|{
  286|  98.8k|    if (limbs == 0) {
  ------------------
  |  Branch (286:9): [True: 0, False: 98.8k]
  ------------------
  287|      0|        mbedtls_mpi_free(X);
  288|      0|        return 0;
  289|  98.8k|    } else if (X->n == limbs) {
  ------------------
  |  Branch (289:16): [True: 0, False: 98.8k]
  ------------------
  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|  98.8k|    } else {
  294|  98.8k|        mbedtls_mpi_free(X);
  295|  98.8k|        return mbedtls_mpi_grow(X, limbs);
  296|  98.8k|    }
  297|  98.8k|}
bignum.c:add_sub_mpi:
 1115|  17.2M|{
 1116|  17.2M|    int ret, s;
 1117|       |
 1118|  17.2M|    s = A->s;
 1119|  17.2M|    if (A->s * B->s * flip_B < 0) {
  ------------------
  |  Branch (1119:9): [True: 13.8M, False: 3.40M]
  ------------------
 1120|  13.8M|        int cmp = mbedtls_mpi_cmp_abs(A, B);
 1121|  13.8M|        if (cmp >= 0) {
  ------------------
  |  Branch (1121:13): [True: 5.73M, False: 8.12M]
  ------------------
 1122|  5.73M|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs(X, A, B));
  ------------------
  |  |   41|  5.73M|    do                           \
  |  |   42|  5.73M|    {                            \
  |  |   43|  5.73M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 5.73M]
  |  |  ------------------
  |  |   44|  5.73M|        goto cleanup;        \
  |  |   45|  5.73M|    } 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|  5.73M|            X->s = cmp == 0 ? 1 : s;
  ------------------
  |  Branch (1126:20): [True: 19.5k, False: 5.71M]
  ------------------
 1127|  8.12M|        } else {
 1128|  8.12M|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs(X, B, A));
  ------------------
  |  |   41|  8.12M|    do                           \
  |  |   42|  8.12M|    {                            \
  |  |   43|  8.12M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 8.12M]
  |  |  ------------------
  |  |   44|  8.12M|        goto cleanup;        \
  |  |   45|  8.12M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1129|       |            /* Since |A| < |B|, the sign is the opposite of A. */
 1130|  8.12M|            X->s = -s;
 1131|  8.12M|        }
 1132|  13.8M|    } else {
 1133|  3.40M|        MBEDTLS_MPI_CHK(mbedtls_mpi_add_abs(X, A, B));
  ------------------
  |  |   41|  3.40M|    do                           \
  |  |   42|  3.40M|    {                            \
  |  |   43|  3.40M|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3.40M]
  |  |  ------------------
  |  |   44|  3.40M|        goto cleanup;        \
  |  |   45|  3.40M|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1134|  3.40M|        X->s = s;
 1135|  3.40M|    }
 1136|       |
 1137|  17.2M|cleanup:
 1138|       |
 1139|  17.2M|    return ret;
 1140|  17.2M|}
bignum.c:mbedtls_int_div_int:
 1294|   254k|{
 1295|   254k|#if defined(MBEDTLS_HAVE_UDBL)
 1296|   254k|    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|   254k|    if (0 == d || u1 >= d) {
  ------------------
  |  Branch (1308:9): [True: 0, False: 254k]
  |  Branch (1308:19): [True: 0, False: 254k]
  ------------------
 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|   254k|#if defined(MBEDTLS_HAVE_UDBL)
 1317|   254k|    dividend  = (mbedtls_t_udbl) u1 << biL;
  ------------------
  |  |   80|   254k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|   254k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
 1318|   254k|    dividend |= (mbedtls_t_udbl) u0;
 1319|   254k|    quotient = dividend / d;
 1320|   254k|    if (quotient > ((mbedtls_t_udbl) 1 << biL) - 1) {
  ------------------
  |  |   80|   254k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|   254k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  |  Branch (1320:9): [True: 0, False: 254k]
  ------------------
 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|   254k|    if (r != NULL) {
  ------------------
  |  Branch (1324:9): [True: 0, False: 254k]
  ------------------
 1325|      0|        *r = (mbedtls_mpi_uint) (dividend - (quotient * d));
 1326|      0|    }
 1327|       |
 1328|   254k|    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|   254k|}
bignum.c:mbedtls_mpi_exp_mod_optionally_safe:
 1621|  4.19k|{
 1622|  4.19k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  4.19k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1623|       |
 1624|  4.19k|    if (mbedtls_mpi_cmp_int(N, 0) <= 0 || (N->p[0] & 1) == 0) {
  ------------------
  |  Branch (1624:9): [True: 0, False: 4.19k]
  |  Branch (1624:43): [True: 0, False: 4.19k]
  ------------------
 1625|      0|        return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MPI_BAD_INPUT_DATA                    -0x0004
  ------------------
 1626|      0|    }
 1627|       |
 1628|  4.19k|    if (mbedtls_mpi_cmp_int(E, 0) < 0) {
  ------------------
  |  Branch (1628:9): [True: 0, False: 4.19k]
  ------------------
 1629|      0|        return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MPI_BAD_INPUT_DATA                    -0x0004
  ------------------
 1630|      0|    }
 1631|       |
 1632|  4.19k|    if (mbedtls_mpi_bitlen(E) > MBEDTLS_MPI_MAX_BITS ||
  ------------------
  |  |   76|  8.38k|#define MBEDTLS_MPI_MAX_BITS                              (8 * MBEDTLS_MPI_MAX_SIZE)      /**< Maximum number of bits for usable MPIs. */
  |  |  ------------------
  |  |  |  |   73|  4.19k|#define MBEDTLS_MPI_MAX_SIZE                              1024     /**< Maximum number of bytes for usable MPIs. */
  |  |  ------------------
  ------------------
  |  Branch (1632:9): [True: 0, False: 4.19k]
  ------------------
 1633|  4.19k|        mbedtls_mpi_bitlen(N) > MBEDTLS_MPI_MAX_BITS) {
  ------------------
  |  |   76|  4.19k|#define MBEDTLS_MPI_MAX_BITS                              (8 * MBEDTLS_MPI_MAX_SIZE)      /**< Maximum number of bits for usable MPIs. */
  |  |  ------------------
  |  |  |  |   73|  4.19k|#define MBEDTLS_MPI_MAX_SIZE                              1024     /**< Maximum number of bytes for usable MPIs. */
  |  |  ------------------
  ------------------
  |  Branch (1633:9): [True: 0, False: 4.19k]
  ------------------
 1634|      0|        return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MPI_BAD_INPUT_DATA                    -0x0004
  ------------------
 1635|      0|    }
 1636|       |
 1637|       |    /*
 1638|       |     * Ensure that the exponent that we are passing to the core is not NULL.
 1639|       |     */
 1640|  4.19k|    if (E->n == 0) {
  ------------------
  |  Branch (1640:9): [True: 0, False: 4.19k]
  ------------------
 1641|      0|        ret = mbedtls_mpi_lset(X, 1);
 1642|      0|        return ret;
 1643|      0|    }
 1644|       |
 1645|       |    /*
 1646|       |     * Allocate working memory for mbedtls_mpi_core_exp_mod()
 1647|       |     */
 1648|  4.19k|    size_t T_limbs = mbedtls_mpi_core_exp_mod_working_limbs(N->n, E->n);
 1649|  4.19k|    mbedtls_mpi_uint *T = (mbedtls_mpi_uint *) mbedtls_calloc(T_limbs, sizeof(mbedtls_mpi_uint));
  ------------------
  |  |  144|  4.19k|#define mbedtls_calloc     MBEDTLS_PLATFORM_CALLOC_MACRO
  |  |  ------------------
  |  |  |  | 4093|  4.19k|#define MBEDTLS_PLATFORM_CALLOC_MACRO        my_calloc
  |  |  ------------------
  ------------------
 1650|  4.19k|    if (T == NULL) {
  ------------------
  |  Branch (1650:9): [True: 0, False: 4.19k]
  ------------------
 1651|      0|        return MBEDTLS_ERR_MPI_ALLOC_FAILED;
  ------------------
  |  |   38|      0|#define MBEDTLS_ERR_MPI_ALLOC_FAILED                      -0x0010
  ------------------
 1652|      0|    }
 1653|       |
 1654|  4.19k|    mbedtls_mpi RR;
 1655|  4.19k|    mbedtls_mpi_init(&RR);
 1656|       |
 1657|       |    /*
 1658|       |     * If 1st call, pre-compute R^2 mod N
 1659|       |     */
 1660|  4.19k|    if (prec_RR == NULL || prec_RR->p == NULL) {
  ------------------
  |  Branch (1660:9): [True: 0, False: 4.19k]
  |  Branch (1660:28): [True: 4.19k, False: 0]
  ------------------
 1661|  4.19k|        MBEDTLS_MPI_CHK(mbedtls_mpi_core_get_mont_r2_unsafe(&RR, N));
  ------------------
  |  |   41|  4.19k|    do                           \
  |  |   42|  4.19k|    {                            \
  |  |   43|  4.19k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.19k]
  |  |  ------------------
  |  |   44|  4.19k|        goto cleanup;        \
  |  |   45|  4.19k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1662|       |
 1663|  4.19k|        if (prec_RR != NULL) {
  ------------------
  |  Branch (1663:13): [True: 4.19k, False: 0]
  ------------------
 1664|  4.19k|            *prec_RR = RR;
 1665|  4.19k|        }
 1666|  4.19k|    } else {
 1667|      0|        MBEDTLS_MPI_CHK(mbedtls_mpi_grow(prec_RR, N->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]
  |  |  ------------------
  ------------------
 1668|      0|        RR = *prec_RR;
 1669|      0|    }
 1670|       |
 1671|       |    /*
 1672|       |     * To preserve constness we need to make a copy of A. Using X for this to
 1673|       |     * save memory.
 1674|       |     */
 1675|  4.19k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(X, A));
  ------------------
  |  |   41|  4.19k|    do                           \
  |  |   42|  4.19k|    {                            \
  |  |   43|  4.19k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.19k]
  |  |  ------------------
  |  |   44|  4.19k|        goto cleanup;        \
  |  |   45|  4.19k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1676|       |
 1677|       |    /*
 1678|       |     * Compensate for negative A (and correct at the end).
 1679|       |     */
 1680|  4.19k|    X->s = 1;
 1681|       |
 1682|       |    /*
 1683|       |     * Make sure that X is in a form that is safe for consumption by
 1684|       |     * the core functions.
 1685|       |     *
 1686|       |     * - The core functions will not touch the limbs of X above N->n. The
 1687|       |     *   result will be correct if those limbs are 0, which the mod call
 1688|       |     *   ensures.
 1689|       |     * - Also, X must have at least as many limbs as N for the calls to the
 1690|       |     *   core functions.
 1691|       |     */
 1692|  4.19k|    if (mbedtls_mpi_cmp_mpi(X, N) >= 0) {
  ------------------
  |  Branch (1692:9): [True: 0, False: 4.19k]
  ------------------
 1693|      0|        MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(X, X, 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]
  |  |  ------------------
  ------------------
 1694|      0|    }
 1695|  4.19k|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, N->n));
  ------------------
  |  |   41|  4.19k|    do                           \
  |  |   42|  4.19k|    {                            \
  |  |   43|  4.19k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.19k]
  |  |  ------------------
  |  |   44|  4.19k|        goto cleanup;        \
  |  |   45|  4.19k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1696|       |
 1697|       |    /*
 1698|       |     * Convert to and from Montgomery around mbedtls_mpi_core_exp_mod().
 1699|       |     */
 1700|  4.19k|    {
 1701|  4.19k|        mbedtls_mpi_uint mm = mbedtls_mpi_core_montmul_init(N->p);
 1702|  4.19k|        mbedtls_mpi_core_to_mont_rep(X->p, X->p, N->p, N->n, mm, RR.p, T);
 1703|  4.19k|        if (E_public == MBEDTLS_MPI_IS_PUBLIC) {
  ------------------
  |  |  111|  4.19k|#define MBEDTLS_MPI_IS_PUBLIC  0x2a2a2a2a
  ------------------
  |  Branch (1703:13): [True: 4.19k, False: 0]
  ------------------
 1704|  4.19k|            mbedtls_mpi_core_exp_mod_unsafe(X->p, X->p, N->p, N->n, E->p, E->n, RR.p, T);
 1705|  4.19k|        } else {
 1706|      0|            mbedtls_mpi_core_exp_mod(X->p, X->p, N->p, N->n, E->p, E->n, RR.p, T);
 1707|      0|        }
 1708|  4.19k|        mbedtls_mpi_core_from_mont_rep(X->p, X->p, N->p, N->n, mm, T);
 1709|  4.19k|    }
 1710|       |
 1711|       |    /*
 1712|       |     * Correct for negative A.
 1713|       |     */
 1714|  4.19k|    if (A->s == -1 && (E->p[0] & 1) != 0) {
  ------------------
  |  Branch (1714:9): [True: 0, False: 4.19k]
  |  Branch (1714:23): [True: 0, False: 0]
  ------------------
 1715|      0|        mbedtls_ct_condition_t is_x_non_zero = mbedtls_mpi_core_check_zero_ct(X->p, X->n);
 1716|      0|        X->s = mbedtls_ct_mpi_sign_if(is_x_non_zero, -1, 1);
 1717|       |
 1718|      0|        MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(X, N, 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]
  |  |  ------------------
  ------------------
 1719|      0|    }
 1720|       |
 1721|  4.19k|cleanup:
 1722|       |
 1723|  4.19k|    mbedtls_mpi_zeroize_and_free(T, T_limbs);
  ------------------
  |  |  176|  4.19k|#define mbedtls_mpi_zeroize_and_free(v, n) mbedtls_zeroize_and_free(v, ciL * (n))
  |  |  ------------------
  |  |  |  |   79|  4.19k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
 1724|       |
 1725|  4.19k|    if (prec_RR == NULL || prec_RR->p == NULL) {
  ------------------
  |  Branch (1725:9): [True: 0, False: 4.19k]
  |  Branch (1725:28): [True: 0, False: 4.19k]
  ------------------
 1726|      0|        mbedtls_mpi_free(&RR);
 1727|      0|    }
 1728|       |
 1729|  4.19k|    return ret;
 1730|  4.19k|}

mbedtls_mpi_core_clz:
   25|  7.92M|{
   26|  7.92M|#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|  7.92M|#endif
   35|  7.92M|#if defined(core_clz)
   36|  7.92M|    return (size_t) core_clz(a);
  ------------------
  |  |   30|  7.92M|    #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|  7.92M|}
mbedtls_mpi_core_bitlen:
   54|  7.92M|{
   55|  7.92M|    int i;
   56|  7.92M|    size_t j;
   57|       |
   58|  37.7M|    for (i = ((int) A_limbs) - 1; i >= 0; i--) {
  ------------------
  |  Branch (58:35): [True: 37.7M, False: 0]
  ------------------
   59|  37.7M|        if (A[i] != 0) {
  ------------------
  |  Branch (59:13): [True: 7.92M, False: 29.8M]
  ------------------
   60|  7.92M|            j = biL - mbedtls_mpi_core_clz(A[i]);
  ------------------
  |  |   80|  7.92M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  7.92M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
   61|  7.92M|            return (i * biL) + j;
  ------------------
  |  |   80|  7.92M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  7.92M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
   62|  7.92M|        }
   63|  37.7M|    }
   64|       |
   65|      0|    return 0;
   66|  7.92M|}
mbedtls_mpi_core_bigendian_to_host:
   84|  98.8k|{
   85|  98.8k|    mbedtls_mpi_uint *cur_limb_left;
   86|  98.8k|    mbedtls_mpi_uint *cur_limb_right;
   87|  98.8k|    if (A_limbs == 0) {
  ------------------
  |  Branch (87:9): [True: 0, False: 98.8k]
  ------------------
   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|  98.8k|    for (cur_limb_left = A, cur_limb_right = A + (A_limbs - 1);
  101|  1.01M|         cur_limb_left <= cur_limb_right;
  ------------------
  |  Branch (101:10): [True: 919k, False: 98.8k]
  ------------------
  102|   919k|         cur_limb_left++, cur_limb_right--) {
  103|   919k|        mbedtls_mpi_uint tmp;
  104|       |        /* Note that if cur_limb_left == cur_limb_right,
  105|       |         * this code effectively swaps the bytes only once. */
  106|   919k|        tmp             = mpi_bigendian_to_host(*cur_limb_left);
  107|   919k|        *cur_limb_left  = mpi_bigendian_to_host(*cur_limb_right);
  108|   919k|        *cur_limb_right = tmp;
  109|   919k|    }
  110|  98.8k|}
mbedtls_mpi_core_cond_assign:
  172|  3.99M|{
  173|  3.99M|    if (X == A) {
  ------------------
  |  Branch (173:9): [True: 0, False: 3.99M]
  ------------------
  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|  19.9M|    for (size_t i = 0; i < limbs; i++) {
  ------------------
  |  Branch (182:24): [True: 15.9M, False: 3.99M]
  ------------------
  183|  15.9M|        X[i] = mbedtls_ct_mpi_uint_if(assign, A[i], X[i]);
  184|  15.9M|    }
  185|  3.99M|}
mbedtls_mpi_core_read_be:
  230|  98.8k|{
  231|  98.8k|    const size_t limbs = CHARS_TO_LIMBS(input_length);
  ------------------
  |  |   88|  98.8k|#define CHARS_TO_LIMBS(i) ((i) / ciL + ((i) % ciL != 0))
  |  |  ------------------
  |  |  |  |   79|  98.8k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  |  |               #define CHARS_TO_LIMBS(i) ((i) / ciL + ((i) % ciL != 0))
  |  |  ------------------
  |  |  |  |   79|  98.8k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  232|       |
  233|  98.8k|    if (X_limbs < limbs) {
  ------------------
  |  Branch (233:9): [True: 0, False: 98.8k]
  ------------------
  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|  98.8k|    if (X_limbs == 0) {
  ------------------
  |  Branch (239:9): [True: 0, False: 98.8k]
  ------------------
  240|      0|        return 0;
  241|      0|    }
  242|       |
  243|  98.8k|    memset(X, 0, X_limbs * ciL);
  ------------------
  |  |   79|  98.8k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  244|       |
  245|       |    /* memcpy() with (NULL, 0) is undefined behaviour */
  246|  98.8k|    if (input_length != 0) {
  ------------------
  |  Branch (246:9): [True: 98.8k, False: 0]
  ------------------
  247|  98.8k|        size_t overhead = (X_limbs * ciL) - input_length;
  ------------------
  |  |   79|  98.8k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  248|  98.8k|        unsigned char *Xp = (unsigned char *) X;
  249|  98.8k|        memcpy(Xp + overhead, input, input_length);
  250|  98.8k|    }
  251|       |
  252|  98.8k|    mbedtls_mpi_core_bigendian_to_host(X, X_limbs);
  253|       |
  254|  98.8k|    return 0;
  255|  98.8k|}
mbedtls_mpi_core_write_be:
  295|  4.19k|{
  296|  4.19k|    size_t stored_bytes;
  297|  4.19k|    size_t bytes_to_copy;
  298|  4.19k|    unsigned char *p;
  299|       |
  300|  4.19k|    stored_bytes = X_limbs * ciL;
  ------------------
  |  |   79|  4.19k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  301|       |
  302|  4.19k|    if (stored_bytes < output_length) {
  ------------------
  |  Branch (302:9): [True: 0, False: 4.19k]
  ------------------
  303|       |        /* There is enough space in the output buffer. Write initial
  304|       |         * null bytes and record the position at which to start
  305|       |         * writing the significant bytes. In this case, the execution
  306|       |         * trace of this function does not depend on the value of the
  307|       |         * number. */
  308|      0|        bytes_to_copy = stored_bytes;
  309|      0|        p = output + output_length - stored_bytes;
  310|      0|        memset(output, 0, output_length - stored_bytes);
  311|  4.19k|    } else {
  312|       |        /* The output buffer is smaller than the allocated size of X.
  313|       |         * However X may fit if its leading bytes are zero. */
  314|  4.19k|        bytes_to_copy = output_length;
  315|  4.19k|        p = output;
  316|  37.7k|        for (size_t i = bytes_to_copy; i < stored_bytes; i++) {
  ------------------
  |  Branch (316:40): [True: 33.5k, False: 4.19k]
  ------------------
  317|  33.5k|            if (GET_BYTE(X, i) != 0) {
  ------------------
  |  |   91|  33.5k|    (((X)[(i) / ciL] >> (((i) % ciL) * 8)) & 0xff)
  |  |  ------------------
  |  |  |  |   79|  33.5k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  |  |                   (((X)[(i) / ciL] >> (((i) % ciL) * 8)) & 0xff)
  |  |  ------------------
  |  |  |  |   79|  33.5k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  |  Branch (317:17): [True: 0, False: 33.5k]
  ------------------
  318|      0|                return MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL;
  ------------------
  |  |   30|      0|#define MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL                  -0x0008
  ------------------
  319|      0|            }
  320|  33.5k|        }
  321|  4.19k|    }
  322|       |
  323|  1.88M|    for (size_t i = 0; i < bytes_to_copy; i++) {
  ------------------
  |  Branch (323:24): [True: 1.87M, False: 4.19k]
  ------------------
  324|  1.87M|        p[bytes_to_copy - i - 1] = GET_BYTE(X, i);
  ------------------
  |  |   91|  1.87M|    (((X)[(i) / ciL] >> (((i) % ciL) * 8)) & 0xff)
  |  |  ------------------
  |  |  |  |   79|  1.87M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  |  |                   (((X)[(i) / ciL] >> (((i) % ciL) * 8)) & 0xff)
  |  |  ------------------
  |  |  |  |   79|  1.87M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  325|  1.87M|    }
  326|       |
  327|  4.19k|    return 0;
  328|  4.19k|}
mbedtls_mpi_core_shift_r:
  332|  13.6M|{
  333|  13.6M|    size_t i, v0, v1;
  334|  13.6M|    mbedtls_mpi_uint r0 = 0, r1;
  335|       |
  336|  13.6M|    v0 = count /  biL;
  ------------------
  |  |   80|  13.6M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  13.6M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  337|  13.6M|    v1 = count & (biL - 1);
  ------------------
  |  |   80|  13.6M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  13.6M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  338|       |
  339|  13.6M|    if (v0 > limbs || (v0 == limbs && v1 > 0)) {
  ------------------
  |  Branch (339:9): [True: 0, False: 13.6M]
  |  Branch (339:24): [True: 0, False: 13.6M]
  |  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|  13.6M|    if (v0 > 0) {
  ------------------
  |  Branch (347:9): [True: 6.99k, False: 13.6M]
  ------------------
  348|   260k|        for (i = 0; i < limbs - v0; i++) {
  ------------------
  |  Branch (348:21): [True: 253k, False: 6.99k]
  ------------------
  349|   253k|            X[i] = X[i + v0];
  350|   253k|        }
  351|       |
  352|   261k|        for (; i < limbs; i++) {
  ------------------
  |  Branch (352:16): [True: 254k, False: 6.99k]
  ------------------
  353|   254k|            X[i] = 0;
  354|   254k|        }
  355|  6.99k|    }
  356|       |
  357|       |    /*
  358|       |     * shift by count % limb_size
  359|       |     */
  360|  13.6M|    if (v1 > 0) {
  ------------------
  |  Branch (360:9): [True: 11.3M, False: 2.28M]
  ------------------
  361|  61.4M|        for (i = limbs; i > 0; i--) {
  ------------------
  |  Branch (361:25): [True: 50.1M, False: 11.3M]
  ------------------
  362|  50.1M|            r1 = X[i - 1] << (biL - v1);
  ------------------
  |  |   80|  50.1M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  50.1M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  363|  50.1M|            X[i - 1] >>= v1;
  364|  50.1M|            X[i - 1] |= r0;
  365|  50.1M|            r0 = r1;
  366|  50.1M|        }
  367|  11.3M|    }
  368|  13.6M|}
mbedtls_mpi_core_shift_l:
  372|  2.18M|{
  373|  2.18M|    size_t i, v0, v1;
  374|  2.18M|    mbedtls_mpi_uint r0 = 0, r1;
  375|       |
  376|  2.18M|    v0 = count / (biL);
  ------------------
  |  |   80|  2.18M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  2.18M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  377|  2.18M|    v1 = count & (biL - 1);
  ------------------
  |  |   80|  2.18M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  2.18M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  378|       |
  379|       |    /*
  380|       |     * shift by count / limb_size
  381|       |     */
  382|  2.18M|    if (v0 > 0) {
  ------------------
  |  Branch (382:9): [True: 258k, False: 1.92M]
  ------------------
  383|  22.0M|        for (i = limbs; i > v0; i--) {
  ------------------
  |  Branch (383:25): [True: 21.7M, False: 258k]
  ------------------
  384|  21.7M|            X[i - 1] = X[i - v0 - 1];
  385|  21.7M|        }
  386|       |
  387|  8.07M|        for (; i > 0; i--) {
  ------------------
  |  Branch (387:16): [True: 7.81M, False: 258k]
  ------------------
  388|  7.81M|            X[i - 1] = 0;
  389|  7.81M|        }
  390|   258k|    }
  391|       |
  392|       |    /*
  393|       |     * shift by count % limb_size
  394|       |     */
  395|  2.18M|    if (v1 > 0) {
  ------------------
  |  Branch (395:9): [True: 1.90M, False: 274k]
  ------------------
  396|  19.7M|        for (i = v0; i < limbs; i++) {
  ------------------
  |  Branch (396:22): [True: 17.8M, False: 1.90M]
  ------------------
  397|  17.8M|            r1 = X[i] >> (biL - v1);
  ------------------
  |  |   80|  17.8M|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  17.8M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  398|  17.8M|            X[i] <<= v1;
  399|  17.8M|            X[i] |= r0;
  400|  17.8M|            r0 = r1;
  401|  17.8M|        }
  402|  1.90M|    }
  403|  2.18M|}
mbedtls_mpi_core_add:
  409|  3.40M|{
  410|  3.40M|    mbedtls_mpi_uint c = 0;
  411|       |
  412|  17.0M|    for (size_t i = 0; i < limbs; i++) {
  ------------------
  |  Branch (412:24): [True: 13.6M, False: 3.40M]
  ------------------
  413|  13.6M|        mbedtls_mpi_uint t = c + A[i];
  414|  13.6M|        c = (t < A[i]);
  415|  13.6M|        t += B[i];
  416|  13.6M|        c += (t < B[i]);
  417|  13.6M|        X[i] = t;
  418|  13.6M|    }
  419|       |
  420|  3.40M|    return c;
  421|  3.40M|}
mbedtls_mpi_core_sub:
  448|  18.0M|{
  449|  18.0M|    mbedtls_mpi_uint c = 0;
  450|       |
  451|   114M|    for (size_t i = 0; i < limbs; i++) {
  ------------------
  |  Branch (451:24): [True: 96.7M, False: 18.0M]
  ------------------
  452|  96.7M|        mbedtls_mpi_uint z = (A[i] < c);
  453|  96.7M|        mbedtls_mpi_uint t = A[i] - c;
  454|  96.7M|        c = (t < B[i]) + z;
  455|  96.7M|        X[i] = t - B[i];
  456|  96.7M|    }
  457|       |
  458|  18.0M|    return c;
  459|  18.0M|}
mbedtls_mpi_core_mla:
  464|  40.7M|{
  465|  40.7M|    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|  40.7M|    if (d_len < s_len) {
  ------------------
  |  Branch (471:9): [True: 0, False: 40.7M]
  ------------------
  472|      0|        s_len = d_len;
  473|      0|    }
  474|  40.7M|    size_t excess_len = d_len - s_len;
  475|  40.7M|    size_t steps_x8 = s_len / 8;
  476|  40.7M|    size_t steps_x1 = s_len & 7;
  477|       |
  478|   167M|    while (steps_x8--) {
  ------------------
  |  Branch (478:12): [True: 126M, False: 40.7M]
  ------------------
  479|   126M|        MULADDC_X8_INIT
  ------------------
  |  | 1088|   126M|#define MULADDC_X8_INIT MULADDC_X4_INIT
  |  |  ------------------
  |  |  |  | 1082|   126M|#define MULADDC_X4_INIT MULADDC_X2_INIT
  |  |  |  |  ------------------
  |  |  |  |  |  | 1076|   126M|#define MULADDC_X2_INIT MULADDC_X1_INIT
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  216|   126M|    asm(                                    \
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  321|   126M|#define asm __asm__
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  217|   126M|        "xorq   %%r8, %%r8\n"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  480|   126M|        MULADDC_X8_CORE
  481|   126M|            MULADDC_X8_STOP
  ------------------
  |  | 1089|   126M|#define MULADDC_X8_STOP MULADDC_X4_STOP
  |  |  ------------------
  |  |  |  | 1083|   126M|#define MULADDC_X4_STOP MULADDC_X2_STOP
  |  |  |  |  ------------------
  |  |  |  |  |  | 1077|   126M|#define MULADDC_X2_STOP MULADDC_X1_STOP
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  232|   126M|        : "+c" (c), "+D" (d), "+S" (s), "+m" (*(uint64_t (*)[16]) d) \
  |  |  |  |  |  |  |  |  233|   126M|        : "b" (b), "m" (*(const uint64_t (*)[16]) s)                 \
  |  |  |  |  |  |  |  |  234|   126M|        : "rax", "rdx", "r8"                                         \
  |  |  |  |  |  |  |  |  235|   126M|    );
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  482|   126M|    }
  483|       |
  484|   148M|    while (steps_x1--) {
  ------------------
  |  Branch (484:12): [True: 108M, False: 40.7M]
  ------------------
  485|   108M|        MULADDC_X1_INIT
  ------------------
  |  |  216|   108M|    asm(                                    \
  |  |  ------------------
  |  |  |  |  321|   108M|#define asm __asm__
  |  |  ------------------
  |  |  217|   108M|        "xorq   %%r8, %%r8\n"
  ------------------
  486|   108M|        MULADDC_X1_CORE
  487|   108M|            MULADDC_X1_STOP
  ------------------
  |  |  232|   108M|        : "+c" (c), "+D" (d), "+S" (s), "+m" (*(uint64_t (*)[16]) d) \
  |  |  233|   108M|        : "b" (b), "m" (*(const uint64_t (*)[16]) s)                 \
  |  |  234|   108M|        : "rax", "rdx", "r8"                                         \
  |  |  235|   108M|    );
  ------------------
  488|   108M|    }
  489|       |
  490|   175M|    while (excess_len--) {
  ------------------
  |  Branch (490:12): [True: 135M, False: 40.7M]
  ------------------
  491|   135M|        *d += c;
  492|   135M|        c = (*d < c);
  493|   135M|        d++;
  494|   135M|    }
  495|       |
  496|  40.7M|    return c;
  497|  40.7M|}
mbedtls_mpi_core_mul:
  502|  5.50M|{
  503|  5.50M|    memset(X, 0, (A_limbs + B_limbs) * ciL);
  ------------------
  |  |   79|  5.50M|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  504|       |
  505|  27.4M|    for (size_t i = 0; i < B_limbs; i++) {
  ------------------
  |  Branch (505:24): [True: 21.9M, False: 5.50M]
  ------------------
  506|  21.9M|        (void) mbedtls_mpi_core_mla(X + i, A_limbs + 1, A, A_limbs, B[i]);
  507|  21.9M|    }
  508|  5.50M|}
mbedtls_mpi_core_montmul_init:
  514|  8.38k|{
  515|  8.38k|    mbedtls_mpi_uint x = N[0];
  516|       |
  517|  8.38k|    x += ((N[0] + 2) & 4) << 1;
  518|       |
  519|  41.9k|    for (unsigned int i = biL; i >= 8; i /= 2) {
  ------------------
  |  |   80|  8.38k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  8.38k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  |  Branch (519:32): [True: 33.5k, False: 8.38k]
  ------------------
  520|  33.5k|        x *= (2 - (N[0] * x));
  521|  33.5k|    }
  522|       |
  523|  8.38k|    return ~x + 1;
  524|  8.38k|}
mbedtls_mpi_core_montmul:
  534|   155k|{
  535|   155k|    memset(T, 0, (2 * AN_limbs + 1) * ciL);
  ------------------
  |  |   79|   155k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  536|       |
  537|  9.00M|    for (size_t i = 0; i < AN_limbs; i++) {
  ------------------
  |  Branch (537:24): [True: 8.84M, False: 155k]
  ------------------
  538|       |        /* T = (T + u0*B + u1*N) / 2^biL */
  539|  8.84M|        mbedtls_mpi_uint u0 = A[i];
  540|  8.84M|        mbedtls_mpi_uint u1 = (T[0] + u0 * B[0]) * mm;
  541|       |
  542|  8.84M|        (void) mbedtls_mpi_core_mla(T, AN_limbs + 2, B, B_limbs, u0);
  543|  8.84M|        (void) mbedtls_mpi_core_mla(T, AN_limbs + 2, N, AN_limbs, u1);
  544|       |
  545|  8.84M|        T++;
  546|  8.84M|    }
  547|       |
  548|       |    /*
  549|       |     * The result we want is (T >= N) ? T - N : T.
  550|       |     *
  551|       |     * For better constant-time properties in this function, we always do the
  552|       |     * subtraction, with the result in X.
  553|       |     *
  554|       |     * We also look to see if there was any carry in the final additions in the
  555|       |     * loop above.
  556|       |     */
  557|       |
  558|   155k|    mbedtls_mpi_uint carry  = T[AN_limbs];
  559|   155k|    mbedtls_mpi_uint borrow = mbedtls_mpi_core_sub(X, T, N, AN_limbs);
  560|       |
  561|       |    /*
  562|       |     * Using R as the Montgomery radix (auxiliary modulus) i.e. 2^(biL*AN_limbs):
  563|       |     *
  564|       |     * T can be in one of 3 ranges:
  565|       |     *
  566|       |     * 1) T < N      : (carry, borrow) = (0, 1): we want T
  567|       |     * 2) N <= T < R : (carry, borrow) = (0, 0): we want X
  568|       |     * 3) T >= R     : (carry, borrow) = (1, 1): we want X
  569|       |     *
  570|       |     * and (carry, borrow) = (1, 0) can't happen.
  571|       |     *
  572|       |     * So the correct return value is already in X if (carry ^ borrow) = 0,
  573|       |     * but is in (the lower AN_limbs limbs of) T if (carry ^ borrow) = 1.
  574|       |     */
  575|   155k|    mbedtls_ct_memcpy_if(mbedtls_ct_bool(carry ^ borrow),
  576|   155k|                         (unsigned char *) X,
  577|   155k|                         (unsigned char *) T,
  578|   155k|                         NULL,
  579|   155k|                         AN_limbs * sizeof(mbedtls_mpi_uint));
  580|   155k|}
mbedtls_mpi_core_get_mont_r2_unsafe:
  584|  4.19k|{
  585|  4.19k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  4.19k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  586|       |
  587|  4.19k|    MBEDTLS_MPI_CHK(mbedtls_mpi_lset(X, 1));
  ------------------
  |  |   41|  4.19k|    do                           \
  |  |   42|  4.19k|    {                            \
  |  |   43|  4.19k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.19k]
  |  |  ------------------
  |  |   44|  4.19k|        goto cleanup;        \
  |  |   45|  4.19k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  588|  4.19k|    MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(X, N->n * 2 * biL));
  ------------------
  |  |   41|  4.19k|    do                           \
  |  |   42|  4.19k|    {                            \
  |  |   43|  4.19k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.19k]
  |  |  ------------------
  |  |   44|  4.19k|        goto cleanup;        \
  |  |   45|  4.19k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  589|  4.19k|    MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(X, X, N));
  ------------------
  |  |   41|  4.19k|    do                           \
  |  |   42|  4.19k|    {                            \
  |  |   43|  4.19k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.19k]
  |  |  ------------------
  |  |   44|  4.19k|        goto cleanup;        \
  |  |   45|  4.19k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  590|  4.19k|    MBEDTLS_MPI_CHK(mbedtls_mpi_shrink(X, N->n));
  ------------------
  |  |   41|  4.19k|    do                           \
  |  |   42|  4.19k|    {                            \
  |  |   43|  4.19k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.19k]
  |  |  ------------------
  |  |   44|  4.19k|        goto cleanup;        \
  |  |   45|  4.19k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  591|       |
  592|  4.19k|cleanup:
  593|  4.19k|    return ret;
  594|  4.19k|}
mbedtls_mpi_core_exp_mod_working_limbs:
  710|  4.19k|{
  711|  4.19k|    const size_t wsize = exp_mod_get_window_size(E_limbs * biL);
  ------------------
  |  |   80|  4.19k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  4.19k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  712|  4.19k|    const size_t welem = ((size_t) 1) << wsize;
  713|       |
  714|       |    /* How big does each part of the working memory pool need to be? */
  715|  4.19k|    const size_t table_limbs   = welem * AN_limbs;
  716|  4.19k|    const size_t select_limbs  = AN_limbs;
  717|  4.19k|    const size_t temp_limbs    = 2 * AN_limbs + 1;
  718|       |
  719|  4.19k|    return table_limbs + select_limbs + temp_limbs;
  720|  4.19k|}
mbedtls_mpi_core_exp_mod_unsafe:
  957|  4.19k|{
  958|  4.19k|    mbedtls_mpi_core_exp_mod_optionally_safe(X,
  959|  4.19k|                                             A,
  960|  4.19k|                                             N,
  961|  4.19k|                                             AN_limbs,
  962|  4.19k|                                             E,
  963|  4.19k|                                             E_limbs,
  964|  4.19k|                                             MBEDTLS_MPI_IS_PUBLIC,
  ------------------
  |  |  111|  4.19k|#define MBEDTLS_MPI_IS_PUBLIC  0x2a2a2a2a
  ------------------
  965|  4.19k|                                             RR,
  966|  4.19k|                                             T);
  967|  4.19k|}
mbedtls_mpi_core_sub_int:
  973|  3.92M|{
  974|  22.1M|    for (size_t i = 0; i < limbs; i++) {
  ------------------
  |  Branch (974:24): [True: 18.2M, False: 3.92M]
  ------------------
  975|  18.2M|        mbedtls_mpi_uint s = A[i];
  976|  18.2M|        mbedtls_mpi_uint t = s - c;
  977|  18.2M|        c = (t > s);
  978|  18.2M|        X[i] = t;
  979|  18.2M|    }
  980|       |
  981|  3.92M|    return c;
  982|  3.92M|}
mbedtls_mpi_core_to_mont_rep:
 1004|  4.19k|{
 1005|  4.19k|    mbedtls_mpi_core_montmul(X, A, rr, AN_limbs, N, AN_limbs, mm, T);
 1006|  4.19k|}
mbedtls_mpi_core_from_mont_rep:
 1014|  4.19k|{
 1015|  4.19k|    const mbedtls_mpi_uint Rinv = 1;    /* 1/R in Mont. rep => 1 */
 1016|       |
 1017|  4.19k|    mbedtls_mpi_core_montmul(X, A, &Rinv, 1, N, AN_limbs, mm, T);
 1018|  4.19k|}
bignum_core.c:mpi_bigendian_to_host:
   69|  1.83M|{
   70|  1.83M|    if (MBEDTLS_IS_BIG_ENDIAN) {
  ------------------
  |  |  398|  1.83M|#define MBEDTLS_IS_BIG_ENDIAN 0
  |  |  ------------------
  |  |  |  Branch (398:31): [Folded - Ignored]
  |  |  ------------------
  ------------------
   71|       |        /* Nothing to do on bigendian systems. */
   72|      0|        return a;
   73|  1.83M|    } else {
   74|       |#if defined(MBEDTLS_HAVE_INT32)
   75|       |        return (mbedtls_mpi_uint) MBEDTLS_BSWAP32(a);
   76|       |#elif defined(MBEDTLS_HAVE_INT64)
   77|  1.83M|        return (mbedtls_mpi_uint) MBEDTLS_BSWAP64(a);
  ------------------
  |  |  301|  1.83M|#define MBEDTLS_BSWAP64 __builtin_bswap64
  ------------------
   78|  1.83M|#endif
   79|  1.83M|    }
   80|  1.83M|}
bignum_core.c:exp_mod_get_window_size:
  696|  8.38k|{
  697|       |#if MBEDTLS_MPI_WINDOW_SIZE >= 6
  698|       |    return (Ebits > 671) ? 6 : (Ebits > 239) ? 5 : (Ebits >  79) ? 4 : 1;
  699|       |#elif MBEDTLS_MPI_WINDOW_SIZE == 5
  700|       |    return (Ebits > 239) ? 5 : (Ebits >  79) ? 4 : 1;
  701|       |#elif MBEDTLS_MPI_WINDOW_SIZE > 1
  702|  8.38k|    return (Ebits >  79) ? MBEDTLS_MPI_WINDOW_SIZE : 1;
  ------------------
  |  |   62|      0|#define MBEDTLS_MPI_WINDOW_SIZE                           3        /**< Maximum window size used. */
  ------------------
  |  Branch (702:12): [True: 0, False: 8.38k]
  ------------------
  703|       |#else
  704|       |    (void) Ebits;
  705|       |    return 1;
  706|       |#endif
  707|  8.38k|}
bignum_core.c:mbedtls_mpi_core_exp_mod_optionally_safe:
  856|  4.19k|{
  857|       |    /* We'll process the bits of E from most significant
  858|       |     * (limb_index=E_limbs-1, E_bit_index=biL-1) to least significant
  859|       |     * (limb_index=0, E_bit_index=0). */
  860|  4.19k|    size_t E_limb_index;
  861|  4.19k|    size_t E_bit_index;
  862|  4.19k|    exp_mod_calc_first_bit_optionally_safe(E, E_limbs, E_public,
  863|  4.19k|                                           &E_limb_index, &E_bit_index);
  864|       |
  865|  4.19k|    const size_t wsize = exp_mod_get_window_size(E_limb_index * biL);
  ------------------
  |  |   80|  4.19k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  4.19k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  866|  4.19k|    const size_t welem = ((size_t) 1) << wsize;
  867|       |
  868|       |    /* This is how we will use the temporary storage T, which must have space
  869|       |     * for table_limbs, select_limbs and (2 * AN_limbs + 1) for montmul. */
  870|  4.19k|    const size_t table_limbs  = welem * AN_limbs;
  871|  4.19k|    const size_t select_limbs = AN_limbs;
  872|       |
  873|       |    /* Pointers to specific parts of the temporary working memory pool */
  874|  4.19k|    mbedtls_mpi_uint *const Wtable  = T;
  875|  4.19k|    mbedtls_mpi_uint *const Wselect = Wtable  +  table_limbs;
  876|  4.19k|    mbedtls_mpi_uint *const temp    = Wselect + select_limbs;
  877|       |
  878|       |    /*
  879|       |     * Window precomputation
  880|       |     */
  881|       |
  882|  4.19k|    const mbedtls_mpi_uint mm = mbedtls_mpi_core_montmul_init(N);
  883|       |
  884|       |    /* Set Wtable[i] = A^i (in Montgomery representation) */
  885|  4.19k|    exp_mod_precompute_window(A, N, AN_limbs,
  886|  4.19k|                              mm, RR,
  887|  4.19k|                              welem, Wtable, temp);
  888|       |
  889|       |    /*
  890|       |     * Fixed window exponentiation
  891|       |     */
  892|       |
  893|       |    /* X = 1 (in Montgomery presentation) initially */
  894|  4.19k|    memcpy(X, Wtable, AN_limbs * ciL);
  ------------------
  |  |   79|  4.19k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  895|       |
  896|       |    /* At any given time, window contains window_bits bits from E.
  897|       |     * window_bits can go up to wsize. */
  898|  4.19k|    size_t window_bits = 0;
  899|  4.19k|    mbedtls_mpi_uint window = 0;
  900|       |
  901|  71.2k|    do {
  902|       |        /* Square */
  903|  71.2k|        mbedtls_mpi_core_montmul(X, X, X, AN_limbs, N, AN_limbs, mm, temp);
  904|       |
  905|       |        /* Move to the next bit of the exponent */
  906|  71.2k|        if (E_bit_index == 0) {
  ------------------
  |  Branch (906:13): [True: 0, False: 71.2k]
  ------------------
  907|      0|            --E_limb_index;
  908|      0|            E_bit_index = biL - 1;
  ------------------
  |  |   80|      0|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|      0|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  909|  71.2k|        } else {
  910|  71.2k|            --E_bit_index;
  911|  71.2k|        }
  912|       |        /* Insert next exponent bit into window */
  913|  71.2k|        ++window_bits;
  914|  71.2k|        window <<= 1;
  915|  71.2k|        window |= (E[E_limb_index] >> E_bit_index) & 1;
  916|       |
  917|       |        /* Clear window if it's full. Also clear the window at the end,
  918|       |         * when we've finished processing the exponent. */
  919|  71.2k|        if (window_bits == wsize ||
  ------------------
  |  Branch (919:13): [True: 71.2k, False: 0]
  ------------------
  920|  71.2k|            (E_bit_index == 0 && E_limb_index == 0)) {
  ------------------
  |  Branch (920:14): [True: 0, False: 0]
  |  Branch (920:34): [True: 0, False: 0]
  ------------------
  921|       |
  922|  71.2k|            exp_mod_table_lookup_optionally_safe(Wselect, Wtable, AN_limbs, welem,
  923|  71.2k|                                                 window, E_public);
  924|       |            /* Multiply X by the selected element. */
  925|  71.2k|            mbedtls_mpi_core_montmul(X, X, Wselect, AN_limbs, N, AN_limbs, mm,
  926|  71.2k|                                     temp);
  927|  71.2k|            window = 0;
  928|  71.2k|            window_bits = 0;
  929|  71.2k|        }
  930|  71.2k|    } while (!(E_bit_index == 0 && E_limb_index == 0));
  ------------------
  |  Branch (930:16): [True: 4.19k, False: 67.1k]
  |  Branch (930:36): [True: 4.19k, False: 0]
  ------------------
  931|  4.19k|}
bignum_core.c:exp_mod_calc_first_bit_optionally_safe:
  766|  4.19k|{
  767|  4.19k|    if (E_public == MBEDTLS_MPI_IS_PUBLIC) {
  ------------------
  |  |  111|  4.19k|#define MBEDTLS_MPI_IS_PUBLIC  0x2a2a2a2a
  ------------------
  |  Branch (767:9): [True: 4.19k, False: 0]
  ------------------
  768|       |        /*
  769|       |         * Skip leading zero bits.
  770|       |         */
  771|  4.19k|        size_t E_bits = mbedtls_mpi_core_bitlen(E, E_limbs);
  772|  4.19k|        if (E_bits == 0) {
  ------------------
  |  Branch (772:13): [True: 0, False: 4.19k]
  ------------------
  773|       |            /*
  774|       |             * If E is 0 mbedtls_mpi_core_bitlen() returns 0. Even if that is the case, we will want
  775|       |             * to represent it as a single 0 bit and as such the bitlength will be 1.
  776|       |             */
  777|      0|            E_bits = 1;
  778|      0|        }
  779|       |
  780|  4.19k|        *E_limb_index = E_bits / biL;
  ------------------
  |  |   80|  4.19k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  4.19k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  781|  4.19k|        *E_bit_index = E_bits % biL;
  ------------------
  |  |   80|  4.19k|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   79|  4.19k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  782|       |
  783|       |#if defined(MBEDTLS_TEST_HOOKS) && !defined(MBEDTLS_THREADING_C)
  784|       |        mbedtls_mpi_optionally_safe_codepath = MBEDTLS_MPI_IS_PUBLIC;
  785|       |#endif
  786|  4.19k|    } else {
  787|       |        /*
  788|       |         * Here we need to be constant time with respect to E and can't do anything better than
  789|       |         * start at the first allocated bit.
  790|       |         */
  791|      0|        *E_limb_index = E_limbs;
  792|      0|        *E_bit_index = 0;
  793|       |#if defined(MBEDTLS_TEST_HOOKS) && !defined(MBEDTLS_THREADING_C)
  794|       |        // Only mark the codepath safe if there wasn't an unsafe codepath before
  795|       |        if (mbedtls_mpi_optionally_safe_codepath != MBEDTLS_MPI_IS_PUBLIC) {
  796|       |            mbedtls_mpi_optionally_safe_codepath = MBEDTLS_MPI_IS_SECRET;
  797|       |        }
  798|       |#endif
  799|      0|    }
  800|  4.19k|}
bignum_core.c:exp_mod_precompute_window:
  730|  4.19k|{
  731|       |    /* W[0] = 1 (in Montgomery presentation) */
  732|  4.19k|    memset(Wtable, 0, AN_limbs * ciL);
  ------------------
  |  |   79|  4.19k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  733|  4.19k|    Wtable[0] = 1;
  734|  4.19k|    mbedtls_mpi_core_montmul(Wtable, Wtable, RR, AN_limbs, N, AN_limbs, mm, temp);
  735|       |
  736|       |    /* W[1] = A (already in Montgomery presentation) */
  737|  4.19k|    mbedtls_mpi_uint *W1 = Wtable + AN_limbs;
  738|  4.19k|    memcpy(W1, A, AN_limbs * ciL);
  ------------------
  |  |   79|  4.19k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  739|       |
  740|       |    /* W[i+1] = W[i] * W[1], i >= 2 */
  741|  4.19k|    mbedtls_mpi_uint *Wprev = W1;
  742|  4.19k|    for (size_t i = 2; i < welem; i++) {
  ------------------
  |  Branch (742:24): [True: 0, False: 4.19k]
  ------------------
  743|      0|        mbedtls_mpi_uint *Wcur = Wprev + AN_limbs;
  744|      0|        mbedtls_mpi_core_montmul(Wcur, Wprev, W1, AN_limbs, N, AN_limbs, mm, temp);
  745|      0|        Wprev = Wcur;
  746|      0|    }
  747|  4.19k|}
bignum_core.c:exp_mod_table_lookup_optionally_safe:
  812|  71.2k|{
  813|  71.2k|    if (window_public == MBEDTLS_MPI_IS_PUBLIC) {
  ------------------
  |  |  111|  71.2k|#define MBEDTLS_MPI_IS_PUBLIC  0x2a2a2a2a
  ------------------
  |  Branch (813:9): [True: 71.2k, False: 0]
  ------------------
  814|  71.2k|        memcpy(Wselect, Wtable + window * AN_limbs, AN_limbs * ciL);
  ------------------
  |  |   79|  71.2k|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  815|       |#if defined(MBEDTLS_TEST_HOOKS) && !defined(MBEDTLS_THREADING_C)
  816|       |        mbedtls_mpi_optionally_safe_codepath = MBEDTLS_MPI_IS_PUBLIC;
  817|       |#endif
  818|  71.2k|    } else {
  819|       |        /* Select Wtable[window] without leaking window through
  820|       |         * memory access patterns. */
  821|      0|        mbedtls_mpi_core_ct_uint_table_lookup(Wselect, Wtable,
  822|      0|                                              AN_limbs, welem, window);
  823|       |#if defined(MBEDTLS_TEST_HOOKS) && !defined(MBEDTLS_THREADING_C)
  824|       |        // Only mark the codepath safe if there wasn't an unsafe codepath before
  825|       |        if (mbedtls_mpi_optionally_safe_codepath != MBEDTLS_MPI_IS_PUBLIC) {
  826|       |            mbedtls_mpi_optionally_safe_codepath = MBEDTLS_MPI_IS_SECRET;
  827|       |        }
  828|       |#endif
  829|      0|    }
  830|  71.2k|}

mbedtls_ct_memcmp:
   71|  4.19k|{
   72|  4.19k|    size_t i = 0;
   73|       |    /*
   74|       |     * `A` and `B` are cast to volatile to ensure that the compiler
   75|       |     * generates code that always fully reads both buffers.
   76|       |     * Otherwise it could generate a test to exit early if `diff` has all
   77|       |     * bits set early in the loop.
   78|       |     */
   79|  4.19k|    volatile const unsigned char *A = (volatile const unsigned char *) a;
   80|  4.19k|    volatile const unsigned char *B = (volatile const unsigned char *) b;
   81|  4.19k|    uint32_t diff = 0;
   82|       |
   83|       |#if defined(MBEDTLS_EFFICIENT_UNALIGNED_VOLATILE_ACCESS)
   84|       |    for (; (i + 4) <= n; i += 4) {
   85|       |        uint32_t x = mbedtls_get_unaligned_volatile_uint32(A + i);
   86|       |        uint32_t y = mbedtls_get_unaligned_volatile_uint32(B + i);
   87|       |        diff |= x ^ y;
   88|       |    }
   89|       |#endif
   90|       |
   91|  1.88M|    for (; i < n; i++) {
  ------------------
  |  Branch (91:12): [True: 1.87M, False: 4.19k]
  ------------------
   92|       |        /* Read volatile data in order before computing diff.
   93|       |         * This avoids IAR compiler warning:
   94|       |         * 'the order of volatile accesses is undefined ..' */
   95|  1.87M|        unsigned char x = A[i], y = B[i];
   96|  1.87M|        diff |= x ^ y;
   97|  1.87M|    }
   98|       |
   99|       |
  100|       |#if (INT_MAX < INT32_MAX)
  101|       |    /* We don't support int smaller than 32-bits, but if someone tried to build
  102|       |     * with this configuration, there is a risk that, for differing data, the
  103|       |     * only bits set in diff are in the top 16-bits, and would be lost by a
  104|       |     * simple cast from uint32 to int.
  105|       |     * This would have significant security implications, so protect against it. */
  106|       |#error "mbedtls_ct_memcmp() requires minimum 32-bit ints"
  107|       |#else
  108|       |    /* The bit-twiddling ensures that when we cast uint32_t to int, we are casting
  109|       |     * a value that is in the range 0..INT_MAX - a value larger than this would
  110|       |     * result in implementation defined behaviour.
  111|       |     *
  112|       |     * This ensures that the value returned by the function is non-zero iff
  113|       |     * diff is non-zero.
  114|       |     */
  115|  4.19k|    return (int) ((diff & 0xffff) | (diff >> 16));
  116|  4.19k|#endif
  117|  4.19k|}
mbedtls_ct_memcpy_if:
  175|   155k|{
  176|   155k|#if defined(MBEDTLS_CT_SIZE_64)
  177|   155k|    const uint64_t mask     = (uint64_t) condition;
  178|   155k|    const uint64_t not_mask = (uint64_t) ~mbedtls_ct_compiler_opaque(condition);
  179|       |#else
  180|       |    const uint32_t mask     = (uint32_t) condition;
  181|       |    const uint32_t not_mask = (uint32_t) ~mbedtls_ct_compiler_opaque(condition);
  182|       |#endif
  183|       |
  184|       |    /* If src2 is NULL, setup src2 so that we read from the destination address.
  185|       |     *
  186|       |     * This means that if src2 == NULL && condition is false, the result will be a
  187|       |     * no-op because we read from dest and write the same data back into dest.
  188|       |     */
  189|   155k|    if (src2 == NULL) {
  ------------------
  |  Branch (189:9): [True: 155k, False: 0]
  ------------------
  190|   155k|        src2 = dest;
  191|   155k|    }
  192|       |
  193|       |    /* dest[i] = c1 == c2 ? src[i] : dest[i] */
  194|   155k|    size_t i = 0;
  195|   155k|#if defined(MBEDTLS_EFFICIENT_UNALIGNED_ACCESS)
  196|   155k|#if defined(MBEDTLS_CT_SIZE_64)
  197|  9.00M|    for (; (i + 8) <= len; i += 8) {
  ------------------
  |  Branch (197:12): [True: 8.84M, False: 155k]
  ------------------
  198|  8.84M|        uint64_t a = mbedtls_get_unaligned_uint64(src1 + i) & mask;
  199|  8.84M|        uint64_t b = mbedtls_get_unaligned_uint64(src2 + i) & not_mask;
  200|  8.84M|        mbedtls_put_unaligned_uint64(dest + i, a | b);
  201|  8.84M|    }
  202|       |#else
  203|       |    for (; (i + 4) <= len; i += 4) {
  204|       |        uint32_t a = mbedtls_get_unaligned_uint32(src1 + i) & mask;
  205|       |        uint32_t b = mbedtls_get_unaligned_uint32(src2 + i) & not_mask;
  206|       |        mbedtls_put_unaligned_uint32(dest + i, a | b);
  207|       |    }
  208|       |#endif /* defined(MBEDTLS_CT_SIZE_64) */
  209|   155k|#endif /* MBEDTLS_EFFICIENT_UNALIGNED_ACCESS */
  210|   155k|    for (; i < len; i++) {
  ------------------
  |  Branch (210:12): [True: 0, False: 155k]
  ------------------
  211|      0|        dest[i] = (src1[i] & mask) | (src2[i] & not_mask);
  212|      0|    }
  213|   155k|}

bignum.c:mbedtls_ct_bool:
  136|  3.99M|{
  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|  3.99M|    asm volatile ("mov  %[x], %[s]                                \n\t"
  ------------------
  |  |  321|  3.99M|#define asm __asm__
  ------------------
  175|  3.99M|                  "neg  %[s]                                      \n\t"
  176|  3.99M|                  "or   %[x], %[s]                                \n\t"
  177|  3.99M|                  "sar  $63, %[s]                                 \n\t"
  178|  3.99M|                  :
  179|  3.99M|                  [s] "=&a" (s)
  180|  3.99M|                  :
  181|  3.99M|                  [x] "D" (x)
  182|  3.99M|                  :
  183|  3.99M|                  );
  184|  3.99M|    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|  3.99M|}
bignum.c:mbedtls_ct_bool_not:
  547|  3.99M|{
  548|  3.99M|    return (mbedtls_ct_condition_t) (~x);
  549|  3.99M|}
bignum.c:mbedtls_ct_uint_if:
  436|  3.99M|{
  437|  3.99M|    return (unsigned) mbedtls_ct_if(condition, (mbedtls_ct_uint_t) if1, (mbedtls_ct_uint_t) if0);
  438|  3.99M|}
bignum.c:mbedtls_ct_if:
  223|  3.99M|{
  224|       |#if defined(MBEDTLS_CT_AARCH64_ASM) && (defined(MBEDTLS_CT_SIZE_32) || defined(MBEDTLS_CT_SIZE_64))
  225|       |    asm volatile ("and %x[if1], %x[if1], %x[condition]            \n\t"
  226|       |                  "mvn %x[condition], %x[condition]               \n\t"
  227|       |                  "and %x[condition], %x[condition], %x[if0]      \n\t"
  228|       |                  "orr %x[condition], %x[if1], %x[condition]"
  229|       |                  :
  230|       |                  [condition] "+&r" (condition),
  231|       |                  [if1] "+&r" (if1)
  232|       |                  :
  233|       |                  [if0] "r" (if0)
  234|       |                  :
  235|       |                  );
  236|       |    return (mbedtls_ct_uint_t) condition;
  237|       |#elif defined(MBEDTLS_CT_ARM_ASM) && defined(MBEDTLS_CT_SIZE_32)
  238|       |    asm volatile (".syntax unified                                \n\t"
  239|       |                  "ands %[if1], %[if1], %[condition]              \n\t"
  240|       |                  "mvns %[condition], %[condition]                \n\t"
  241|       |                  "ands %[condition], %[condition], %[if0]        \n\t"
  242|       |                  "orrs %[condition], %[if1], %[condition]        \n\t"
  243|       |                  RESTORE_ASM_SYNTAX
  244|       |                  :
  245|       |                  [condition] "+&l" (condition),
  246|       |                  [if1] "+&l" (if1)
  247|       |                  :
  248|       |                  [if0] "l" (if0)
  249|       |                  :
  250|       |                  "cc"
  251|       |                  );
  252|       |    return (mbedtls_ct_uint_t) condition;
  253|       |#elif defined(MBEDTLS_CT_X86_64_ASM) && (defined(MBEDTLS_CT_SIZE_32) || defined(MBEDTLS_CT_SIZE_64))
  254|  3.99M|    asm volatile ("and  %[condition], %[if1]                      \n\t"
  ------------------
  |  |  321|  3.99M|#define asm __asm__
  ------------------
  255|  3.99M|                  "not  %[condition]                              \n\t"
  256|  3.99M|                  "and  %[condition], %[if0]                      \n\t"
  257|  3.99M|                  "or   %[if1], %[if0]                            \n\t"
  258|  3.99M|                  :
  259|  3.99M|                  [condition] "+&D" (condition),
  260|  3.99M|                  [if1] "+&S" (if1),
  261|  3.99M|                  [if0] "+&a" (if0)
  262|  3.99M|                  :
  263|  3.99M|                  :
  264|  3.99M|                  );
  265|  3.99M|    return if0;
  266|       |#elif defined(MBEDTLS_CT_X86_ASM) && defined(MBEDTLS_CT_SIZE_32)
  267|       |    asm volatile ("and %[condition], %[if1]                       \n\t"
  268|       |                  "not %[condition]                               \n\t"
  269|       |                  "and %[if0], %[condition]                       \n\t"
  270|       |                  "or %[condition], %[if1]                        \n\t"
  271|       |                  :
  272|       |                  [condition] "+&c" (condition),
  273|       |                  [if1] "+&a" (if1)
  274|       |                  :
  275|       |                  [if0] "b" (if0)
  276|       |                  :
  277|       |                  );
  278|       |    return if1;
  279|       |#else
  280|       |    mbedtls_ct_condition_t not_cond =
  281|       |        (mbedtls_ct_condition_t) (~mbedtls_ct_compiler_opaque(condition));
  282|       |    return (mbedtls_ct_uint_t) ((condition & if1) | (not_cond & if0));
  283|       |#endif
  284|  3.99M|}
bignum.c:mbedtls_ct_mpi_uint_if_else_0:
  481|  13.9k|{
  482|  13.9k|    return (mbedtls_mpi_uint) (condition & if1);
  483|  13.9k|}
bignum_core.c:mbedtls_ct_bool:
  136|   155k|{
  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|   155k|    asm volatile ("mov  %[x], %[s]                                \n\t"
  ------------------
  |  |  321|   155k|#define asm __asm__
  ------------------
  175|   155k|                  "neg  %[s]                                      \n\t"
  176|   155k|                  "or   %[x], %[s]                                \n\t"
  177|   155k|                  "sar  $63, %[s]                                 \n\t"
  178|   155k|                  :
  179|   155k|                  [s] "=&a" (s)
  180|   155k|                  :
  181|   155k|                  [x] "D" (x)
  182|   155k|                  :
  183|   155k|                  );
  184|   155k|    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|   155k|}
bignum_core.c:mbedtls_ct_mpi_uint_if:
  453|  15.9M|{
  454|  15.9M|    return (mbedtls_mpi_uint) mbedtls_ct_if(condition,
  455|  15.9M|                                            (mbedtls_ct_uint_t) if1,
  456|  15.9M|                                            (mbedtls_ct_uint_t) if0);
  457|  15.9M|}
bignum_core.c:mbedtls_ct_if:
  223|  15.9M|{
  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|  15.9M|    asm volatile ("and  %[condition], %[if1]                      \n\t"
  ------------------
  |  |  321|  15.9M|#define asm __asm__
  ------------------
  255|  15.9M|                  "not  %[condition]                              \n\t"
  256|  15.9M|                  "and  %[condition], %[if0]                      \n\t"
  257|  15.9M|                  "or   %[if1], %[if0]                            \n\t"
  258|  15.9M|                  :
  259|  15.9M|                  [condition] "+&D" (condition),
  260|  15.9M|                  [if1] "+&S" (if1),
  261|  15.9M|                  [if0] "+&a" (if0)
  262|  15.9M|                  :
  263|  15.9M|                  :
  264|  15.9M|                  );
  265|  15.9M|    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|  15.9M|}
constant_time.c:mbedtls_ct_compiler_opaque:
  101|   155k|{
  102|   155k|#if defined(MBEDTLS_CT_ASM)
  103|   155k|    asm volatile ("" : [x] "+r" (x) :);
  ------------------
  |  |  321|   155k|#define asm __asm__
  ------------------
  104|   155k|    return x;
  105|       |#else
  106|       |    return x ^ mbedtls_ct_zero;
  107|       |#endif
  108|   155k|}

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

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

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

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

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

mbedtls_oid_get_x509_ext_type:
   84|   235k|    {                                                                       \
   85|   235k|        const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1(oid);        \
   86|   235k|        if (data == NULL) return MBEDTLS_ERR_OID_NOT_FOUND;            \
  ------------------
  |  |   28|  31.2k|#define MBEDTLS_ERR_OID_NOT_FOUND                         -0x002E
  ------------------
  |  Branch (86:13): [True: 31.2k, False: 203k]
  ------------------
   87|   235k|        *ATTR1 = data->ATTR1;                                               \
   88|   203k|        return 0;                                                        \
   89|   235k|    }
mbedtls_oid_get_sig_alg:
   99|  45.2k|    {                                                                           \
  100|  45.2k|        const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1(oid);            \
  101|  45.2k|        if (data == NULL) return MBEDTLS_ERR_OID_NOT_FOUND;                 \
  ------------------
  |  |   28|      0|#define MBEDTLS_ERR_OID_NOT_FOUND                         -0x002E
  ------------------
  |  Branch (101:13): [True: 0, False: 45.2k]
  ------------------
  102|  45.2k|        *(ATTR1) = data->ATTR1;                                                 \
  103|  45.2k|        *(ATTR2) = data->ATTR2;                                                 \
  104|  45.2k|        return 0;                                                            \
  105|  45.2k|    }
mbedtls_oid_get_pk_alg:
   84|  45.2k|    {                                                                       \
   85|  45.2k|        const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1(oid);        \
   86|  45.2k|        if (data == NULL) return MBEDTLS_ERR_OID_NOT_FOUND;            \
  ------------------
  |  |   28|      0|#define MBEDTLS_ERR_OID_NOT_FOUND                         -0x002E
  ------------------
  |  Branch (86:13): [True: 0, False: 45.2k]
  ------------------
   87|  45.2k|        *ATTR1 = data->ATTR1;                                               \
   88|  45.2k|        return 0;                                                        \
   89|  45.2k|    }
mbedtls_oid_get_ec_grp:
   84|  11.1k|    {                                                                       \
   85|  11.1k|        const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1(oid);        \
   86|  11.1k|        if (data == NULL) return MBEDTLS_ERR_OID_NOT_FOUND;            \
  ------------------
  |  |   28|      0|#define MBEDTLS_ERR_OID_NOT_FOUND                         -0x002E
  ------------------
  |  Branch (86:13): [True: 0, False: 11.1k]
  ------------------
   87|  11.1k|        *ATTR1 = data->ATTR1;                                               \
   88|  11.1k|        return 0;                                                        \
   89|  11.1k|    }
mbedtls_oid_get_oid_by_md:
  113|  4.19k|    {                                                                           \
  114|  4.19k|        const TYPE_T *cur = (LIST);                                             \
  115|  4.19k|        while (cur->descriptor.asn1 != NULL) {                                 \
  ------------------
  |  Branch (115:16): [True: 4.19k, False: 0]
  ------------------
  116|  4.19k|            if (cur->ATTR1 == (ATTR1)) {                                       \
  ------------------
  |  Branch (116:17): [True: 4.19k, False: 0]
  ------------------
  117|  4.19k|                *oid = cur->descriptor.asn1;                                    \
  118|  4.19k|                *olen = cur->descriptor.asn1_len;                               \
  119|  4.19k|                return 0;                                                    \
  120|  4.19k|            }                                                                   \
  121|  4.19k|            cur++;                                                              \
  122|      0|        }                                                                       \
  123|  4.19k|        return MBEDTLS_ERR_OID_NOT_FOUND;                                    \
  ------------------
  |  |   28|      0|#define MBEDTLS_ERR_OID_NOT_FOUND                         -0x002E
  ------------------
  124|  4.19k|    }
oid.c:oid_x509_ext_from_asn1:
   47|   235k|    {                                                                   \
   48|   235k|        const TYPE_T *p = (LIST);                                       \
   49|   235k|        const mbedtls_oid_descriptor_t *cur =                           \
   50|   235k|            (const mbedtls_oid_descriptor_t *) p;                       \
   51|   235k|        if (p == NULL || oid == NULL) return NULL;                  \
  ------------------
  |  Branch (51:13): [True: 0, False: 235k]
  |  Branch (51:26): [True: 0, False: 235k]
  ------------------
   52|  1.01M|        while (cur->asn1 != NULL) {                                    \
  ------------------
  |  Branch (52:16): [True: 988k, False: 31.2k]
  ------------------
   53|   988k|            if (cur->asn1_len == oid->len &&                            \
  ------------------
  |  Branch (53:17): [True: 684k, False: 303k]
  ------------------
   54|   988k|                memcmp(cur->asn1, oid->p, oid->len) == 0) {          \
  ------------------
  |  Branch (54:17): [True: 203k, False: 480k]
  ------------------
   55|   203k|                return p;                                            \
   56|   203k|            }                                                           \
   57|   988k|            p++;                                                        \
   58|   784k|            cur = (const mbedtls_oid_descriptor_t *) p;                 \
   59|   784k|        }                                                               \
   60|   235k|        return NULL;                                                 \
   61|   235k|    }
oid.c:oid_sig_alg_from_asn1:
   47|  45.2k|    {                                                                   \
   48|  45.2k|        const TYPE_T *p = (LIST);                                       \
   49|  45.2k|        const mbedtls_oid_descriptor_t *cur =                           \
   50|  45.2k|            (const mbedtls_oid_descriptor_t *) p;                       \
   51|  45.2k|        if (p == NULL || oid == NULL) return NULL;                  \
  ------------------
  |  Branch (51:13): [True: 0, False: 45.2k]
  |  Branch (51:26): [True: 0, False: 45.2k]
  ------------------
   52|  78.8k|        while (cur->asn1 != NULL) {                                    \
  ------------------
  |  Branch (52:16): [True: 78.8k, False: 0]
  ------------------
   53|  78.8k|            if (cur->asn1_len == oid->len &&                            \
  ------------------
  |  Branch (53:17): [True: 45.2k, False: 33.5k]
  ------------------
   54|  78.8k|                memcmp(cur->asn1, oid->p, oid->len) == 0) {          \
  ------------------
  |  Branch (54:17): [True: 45.2k, False: 0]
  ------------------
   55|  45.2k|                return p;                                            \
   56|  45.2k|            }                                                           \
   57|  78.8k|            p++;                                                        \
   58|  33.5k|            cur = (const mbedtls_oid_descriptor_t *) p;                 \
   59|  33.5k|        }                                                               \
   60|  45.2k|        return NULL;                                                 \
   61|  45.2k|    }
oid.c:oid_pk_alg_from_asn1:
   47|  45.2k|    {                                                                   \
   48|  45.2k|        const TYPE_T *p = (LIST);                                       \
   49|  45.2k|        const mbedtls_oid_descriptor_t *cur =                           \
   50|  45.2k|            (const mbedtls_oid_descriptor_t *) p;                       \
   51|  45.2k|        if (p == NULL || oid == NULL) return NULL;                  \
  ------------------
  |  Branch (51:13): [True: 0, False: 45.2k]
  |  Branch (51:26): [True: 0, False: 45.2k]
  ------------------
   52|  56.4k|        while (cur->asn1 != NULL) {                                    \
  ------------------
  |  Branch (52:16): [True: 56.4k, False: 0]
  ------------------
   53|  56.4k|            if (cur->asn1_len == oid->len &&                            \
  ------------------
  |  Branch (53:17): [True: 45.2k, False: 11.1k]
  ------------------
   54|  56.4k|                memcmp(cur->asn1, oid->p, oid->len) == 0) {          \
  ------------------
  |  Branch (54:17): [True: 45.2k, False: 0]
  ------------------
   55|  45.2k|                return p;                                            \
   56|  45.2k|            }                                                           \
   57|  56.4k|            p++;                                                        \
   58|  11.1k|            cur = (const mbedtls_oid_descriptor_t *) p;                 \
   59|  11.1k|        }                                                               \
   60|  45.2k|        return NULL;                                                 \
   61|  45.2k|    }
oid.c:oid_grp_id_from_asn1:
   47|  11.1k|    {                                                                   \
   48|  11.1k|        const TYPE_T *p = (LIST);                                       \
   49|  11.1k|        const mbedtls_oid_descriptor_t *cur =                           \
   50|  11.1k|            (const mbedtls_oid_descriptor_t *) p;                       \
   51|  11.1k|        if (p == NULL || oid == NULL) return NULL;                  \
  ------------------
  |  Branch (51:13): [True: 0, False: 11.1k]
  |  Branch (51:26): [True: 0, False: 11.1k]
  ------------------
   52|  33.5k|        while (cur->asn1 != NULL) {                                    \
  ------------------
  |  Branch (52:16): [True: 33.5k, False: 0]
  ------------------
   53|  33.5k|            if (cur->asn1_len == oid->len &&                            \
  ------------------
  |  Branch (53:17): [True: 22.3k, False: 11.1k]
  ------------------
   54|  33.5k|                memcmp(cur->asn1, oid->p, oid->len) == 0) {          \
  ------------------
  |  Branch (54:17): [True: 11.1k, False: 11.1k]
  ------------------
   55|  11.1k|                return p;                                            \
   56|  11.1k|            }                                                           \
   57|  33.5k|            p++;                                                        \
   58|  22.3k|            cur = (const mbedtls_oid_descriptor_t *) p;                 \
   59|  22.3k|        }                                                               \
   60|  11.1k|        return NULL;                                                 \
   61|  11.1k|    }

mbedtls_pk_free:
   64|  45.3k|{
   65|  45.3k|    if (ctx == NULL) {
  ------------------
  |  Branch (65:9): [True: 0, False: 45.3k]
  ------------------
   66|      0|        return;
   67|      0|    }
   68|       |
   69|  45.3k|    if ((ctx->pk_info != NULL) && (ctx->pk_info->ctx_free_func != NULL)) {
  ------------------
  |  Branch (69:9): [True: 45.2k, False: 54]
  |  Branch (69:35): [True: 45.2k, False: 0]
  ------------------
   70|  45.2k|        ctx->pk_info->ctx_free_func(ctx->pk_ctx);
   71|  45.2k|    }
   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|  45.3k|    mbedtls_platform_zeroize(ctx, sizeof(mbedtls_pk_context));
   82|  45.3k|}
mbedtls_pk_info_from_type:
  115|  45.2k|{
  116|  45.2k|    switch (pk_type) {
  117|      0|#if defined(MBEDTLS_RSA_C)
  118|  34.0k|        case MBEDTLS_PK_RSA:
  ------------------
  |  Branch (118:9): [True: 34.0k, False: 11.1k]
  ------------------
  119|  34.0k|            return &mbedtls_rsa_info;
  120|      0|#endif /* MBEDTLS_RSA_C */
  121|      0|#if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
  122|  11.1k|        case MBEDTLS_PK_ECKEY:
  ------------------
  |  Branch (122:9): [True: 11.1k, False: 34.0k]
  ------------------
  123|  11.1k|            return &mbedtls_eckey_info;
  124|      0|        case MBEDTLS_PK_ECKEY_DH:
  ------------------
  |  Branch (124:9): [True: 0, False: 45.2k]
  ------------------
  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: 45.2k]
  ------------------
  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: 45.2k]
  ------------------
  133|      0|            return NULL;
  134|  45.2k|    }
  135|  45.2k|}
mbedtls_pk_setup:
  141|  45.2k|{
  142|  45.2k|    if (info == NULL || ctx->pk_info != NULL) {
  ------------------
  |  Branch (142:9): [True: 0, False: 45.2k]
  |  Branch (142:25): [True: 0, False: 45.2k]
  ------------------
  143|      0|        return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
  ------------------
  |  |   40|      0|#define MBEDTLS_ERR_PK_BAD_INPUT_DATA      -0x3E80
  ------------------
  144|      0|    }
  145|       |
  146|  45.2k|    if ((info->ctx_alloc_func != NULL) &&
  ------------------
  |  Branch (146:9): [True: 45.2k, False: 0]
  ------------------
  147|  45.2k|        ((ctx->pk_ctx = info->ctx_alloc_func()) == NULL)) {
  ------------------
  |  Branch (147:9): [True: 0, False: 45.2k]
  ------------------
  148|      0|        return MBEDTLS_ERR_PK_ALLOC_FAILED;
  ------------------
  |  |   36|      0|#define MBEDTLS_ERR_PK_ALLOC_FAILED        -0x3F80
  ------------------
  149|      0|    }
  150|       |
  151|  45.2k|    ctx->pk_info = info;
  152|       |
  153|  45.2k|    return 0;
  154|  45.2k|}
mbedtls_pk_can_do:
  232|  11.1k|{
  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|  11.1k|    if (ctx == NULL || ctx->pk_info == NULL) {
  ------------------
  |  Branch (236:9): [True: 0, False: 11.1k]
  |  Branch (236:24): [True: 0, False: 11.1k]
  ------------------
  237|      0|        return 0;
  238|      0|    }
  239|       |
  240|  11.1k|    return ctx->pk_info->can_do(type);
  241|  11.1k|}
mbedtls_pk_verify_restartable:
 1047|  5.59k|{
 1048|  5.59k|    if ((md_alg != MBEDTLS_MD_NONE || hash_len != 0) && hash == NULL) {
  ------------------
  |  Branch (1048:10): [True: 5.59k, False: 0]
  |  Branch (1048:39): [True: 0, False: 0]
  |  Branch (1048:57): [True: 0, False: 5.59k]
  ------------------
 1049|      0|        return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
  ------------------
  |  |   40|      0|#define MBEDTLS_ERR_PK_BAD_INPUT_DATA      -0x3E80
  ------------------
 1050|      0|    }
 1051|       |
 1052|  5.59k|    if (ctx->pk_info == NULL ||
  ------------------
  |  Branch (1052:9): [True: 0, False: 5.59k]
  ------------------
 1053|  5.59k|        pk_hashlen_helper(md_alg, &hash_len) != 0) {
  ------------------
  |  Branch (1053:9): [True: 0, False: 5.59k]
  ------------------
 1054|      0|        return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
  ------------------
  |  |   40|      0|#define MBEDTLS_ERR_PK_BAD_INPUT_DATA      -0x3E80
  ------------------
 1055|      0|    }
 1056|       |
 1057|  5.59k|#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
 1058|       |    /* optimization: use non-restartable version if restart disabled */
 1059|  5.59k|    if (rs_ctx != NULL &&
  ------------------
  |  Branch (1059:9): [True: 0, False: 5.59k]
  ------------------
 1060|  5.59k|        mbedtls_ecp_restart_is_enabled() &&
  ------------------
  |  Branch (1060:9): [True: 0, False: 0]
  ------------------
 1061|  5.59k|        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|  5.59k|    if (ctx->pk_info->verify_func == NULL) {
  ------------------
  |  Branch (1081:9): [True: 0, False: 5.59k]
  ------------------
 1082|      0|        return MBEDTLS_ERR_PK_TYPE_MISMATCH;
  ------------------
  |  |   38|      0|#define MBEDTLS_ERR_PK_TYPE_MISMATCH       -0x3F00
  ------------------
 1083|      0|    }
 1084|       |
 1085|  5.59k|    return ctx->pk_info->verify_func(ctx, md_alg, hash, hash_len,
 1086|  5.59k|                                     sig, sig_len);
 1087|  5.59k|}
mbedtls_pk_verify:
 1095|  5.59k|{
 1096|  5.59k|    return mbedtls_pk_verify_restartable(ctx, md_alg, hash, hash_len,
 1097|  5.59k|                                         sig, sig_len, NULL);
 1098|  5.59k|}
mbedtls_pk_verify_ext:
 1107|  5.59k|{
 1108|  5.59k|    if ((md_alg != MBEDTLS_MD_NONE || hash_len != 0) && hash == NULL) {
  ------------------
  |  Branch (1108:10): [True: 5.59k, False: 0]
  |  Branch (1108:39): [True: 0, False: 0]
  |  Branch (1108:57): [True: 0, False: 5.59k]
  ------------------
 1109|      0|        return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
  ------------------
  |  |   40|      0|#define MBEDTLS_ERR_PK_BAD_INPUT_DATA      -0x3E80
  ------------------
 1110|      0|    }
 1111|       |
 1112|  5.59k|    if (ctx->pk_info == NULL) {
  ------------------
  |  Branch (1112:9): [True: 0, False: 5.59k]
  ------------------
 1113|      0|        return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
  ------------------
  |  |   40|      0|#define MBEDTLS_ERR_PK_BAD_INPUT_DATA      -0x3E80
  ------------------
 1114|      0|    }
 1115|       |
 1116|  5.59k|    if (!mbedtls_pk_can_do(ctx, type)) {
  ------------------
  |  Branch (1116:9): [True: 0, False: 5.59k]
  ------------------
 1117|      0|        return MBEDTLS_ERR_PK_TYPE_MISMATCH;
  ------------------
  |  |   38|      0|#define MBEDTLS_ERR_PK_TYPE_MISMATCH       -0x3F00
  ------------------
 1118|      0|    }
 1119|       |
 1120|  5.59k|    if (type != MBEDTLS_PK_RSASSA_PSS) {
  ------------------
  |  Branch (1120:9): [True: 5.59k, False: 0]
  ------------------
 1121|       |        /* General case: no options */
 1122|  5.59k|        if (options != NULL) {
  ------------------
  |  Branch (1122:13): [True: 0, False: 5.59k]
  ------------------
 1123|      0|            return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
  ------------------
  |  |   40|      0|#define MBEDTLS_ERR_PK_BAD_INPUT_DATA      -0x3E80
  ------------------
 1124|      0|        }
 1125|       |
 1126|  5.59k|        return mbedtls_pk_verify(ctx, md_alg, hash, hash_len, sig, sig_len);
 1127|  5.59k|    }
 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_bitlen:
 1456|  10.4k|{
 1457|       |    /* For backward compatibility, accept NULL or a context that
 1458|       |     * isn't set up yet, and return a fake value that should be safe. */
 1459|  10.4k|    if (ctx == NULL || ctx->pk_info == NULL) {
  ------------------
  |  Branch (1459:9): [True: 0, False: 10.4k]
  |  Branch (1459:24): [True: 0, False: 10.4k]
  ------------------
 1460|      0|        return 0;
 1461|      0|    }
 1462|       |
 1463|  10.4k|    return ctx->pk_info->get_bitlen((mbedtls_pk_context *) ctx);
 1464|  10.4k|}
mbedtls_pk_get_type:
 1499|  88.9k|{
 1500|  88.9k|    if (ctx == NULL || ctx->pk_info == NULL) {
  ------------------
  |  Branch (1500:9): [True: 0, False: 88.9k]
  |  Branch (1500:24): [True: 0, False: 88.9k]
  ------------------
 1501|      0|        return MBEDTLS_PK_NONE;
 1502|      0|    }
 1503|       |
 1504|  88.9k|    return ctx->pk_info->type;
 1505|  88.9k|}
pk.c:pk_hashlen_helper:
  998|  5.59k|{
  999|  5.59k|    if (*hash_len != 0) {
  ------------------
  |  Branch (999:9): [True: 5.59k, False: 0]
  ------------------
 1000|  5.59k|        return 0;
 1001|  5.59k|    }
 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|  11.1k|{
   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|  11.1k|    mbedtls_ecp_keypair *ecp = mbedtls_pk_ec_rw(*pk);
   36|       |
   37|       |    /* grp may already be initialized; if so, make sure IDs match */
   38|  11.1k|    if (mbedtls_pk_ec_ro(*pk)->grp.id != MBEDTLS_ECP_DP_NONE &&
  ------------------
  |  Branch (38:9): [True: 0, False: 11.1k]
  ------------------
   39|  11.1k|        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|  11.1k|    return mbedtls_ecp_group_load(&(ecp->grp), grp_id);
   45|  11.1k|#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
   46|  11.1k|}
mbedtls_pk_ecc_set_pubkey:
  205|  11.1k|{
  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|  11.1k|    int ret;
  245|  11.1k|    mbedtls_ecp_keypair *ec_key = (mbedtls_ecp_keypair *) pk->pk_ctx;
  246|  11.1k|    ret = mbedtls_ecp_point_read_binary(&ec_key->grp, &ec_key->Q, pub, pub_len);
  247|  11.1k|    if (ret != 0) {
  ------------------
  |  Branch (247:9): [True: 0, False: 11.1k]
  ------------------
  248|      0|        return ret;
  249|      0|    }
  250|  11.1k|    return mbedtls_ecp_check_pubkey(&ec_key->grp, &ec_key->Q);
  251|       |
  252|  11.1k|#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
  253|  11.1k|}

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

pk_wrap.c:rsa_get_bitlen:
   59|  10.4k|{
   60|  10.4k|    const mbedtls_rsa_context *rsa = (const mbedtls_rsa_context *) pk->pk_ctx;
   61|  10.4k|    return mbedtls_rsa_get_bitlen(rsa);
   62|  10.4k|}
pk_wrap.c:rsa_can_do:
   53|  8.38k|{
   54|  8.38k|    return type == MBEDTLS_PK_RSA ||
  ------------------
  |  Branch (54:12): [True: 8.38k, False: 0]
  ------------------
   55|  8.38k|           type == MBEDTLS_PK_RSASSA_PSS;
  ------------------
  |  Branch (55:12): [True: 0, False: 0]
  ------------------
   56|  8.38k|}
pk_wrap.c:rsa_verify_wrap:
  133|  4.19k|{
  134|  4.19k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  4.19k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  135|  4.19k|    mbedtls_rsa_context *rsa = (mbedtls_rsa_context *) pk->pk_ctx;
  136|  4.19k|    size_t rsa_len = mbedtls_rsa_get_len(rsa);
  137|       |
  138|  4.19k|#if SIZE_MAX > UINT_MAX
  139|  4.19k|    if (md_alg == MBEDTLS_MD_NONE && UINT_MAX < hash_len) {
  ------------------
  |  Branch (139:9): [True: 0, False: 4.19k]
  |  Branch (139:38): [True: 0, False: 0]
  ------------------
  140|      0|        return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
  ------------------
  |  |   40|      0|#define MBEDTLS_ERR_PK_BAD_INPUT_DATA      -0x3E80
  ------------------
  141|      0|    }
  142|  4.19k|#endif
  143|       |
  144|  4.19k|    if (sig_len < rsa_len) {
  ------------------
  |  Branch (144:9): [True: 0, False: 4.19k]
  ------------------
  145|      0|        return MBEDTLS_ERR_RSA_VERIFY_FAILED;
  ------------------
  |  |   45|      0|#define MBEDTLS_ERR_RSA_VERIFY_FAILED                     -0x4380
  ------------------
  146|      0|    }
  147|       |
  148|  4.19k|    if ((ret = mbedtls_rsa_pkcs1_verify(rsa, md_alg,
  ------------------
  |  Branch (148:9): [True: 0, False: 4.19k]
  ------------------
  149|  4.19k|                                        (unsigned int) hash_len,
  150|  4.19k|                                        hash, sig)) != 0) {
  151|      0|        return ret;
  152|      0|    }
  153|       |
  154|       |    /* The buffer contains a valid signature followed by extra data.
  155|       |     * We have a special error code for that so that so that callers can
  156|       |     * use mbedtls_pk_verify() to check "Does the buffer start with a
  157|       |     * valid signature?" and not just "Does the buffer contain a valid
  158|       |     * signature?". */
  159|  4.19k|    if (sig_len > rsa_len) {
  ------------------
  |  Branch (159:9): [True: 0, False: 4.19k]
  ------------------
  160|      0|        return MBEDTLS_ERR_PK_SIG_LEN_MISMATCH;
  ------------------
  |  |   62|      0|#define MBEDTLS_ERR_PK_SIG_LEN_MISMATCH    -0x3900
  ------------------
  161|      0|    }
  162|       |
  163|  4.19k|    return 0;
  164|  4.19k|}
pk_wrap.c:rsa_alloc_wrap:
  455|  34.0k|{
  456|  34.0k|    void *ctx = mbedtls_calloc(1, sizeof(mbedtls_rsa_context));
  ------------------
  |  |  144|  34.0k|#define mbedtls_calloc     MBEDTLS_PLATFORM_CALLOC_MACRO
  |  |  ------------------
  |  |  |  | 4093|  34.0k|#define MBEDTLS_PLATFORM_CALLOC_MACRO        my_calloc
  |  |  ------------------
  ------------------
  457|       |
  458|  34.0k|    if (ctx != NULL) {
  ------------------
  |  Branch (458:9): [True: 34.0k, False: 0]
  ------------------
  459|  34.0k|        mbedtls_rsa_init((mbedtls_rsa_context *) ctx);
  460|  34.0k|    }
  461|       |
  462|  34.0k|    return ctx;
  463|  34.0k|}
pk_wrap.c:rsa_free_wrap:
  466|  34.0k|{
  467|  34.0k|    mbedtls_rsa_free((mbedtls_rsa_context *) ctx);
  468|  34.0k|    mbedtls_free(ctx);
  ------------------
  |  |  143|  34.0k|#define mbedtls_free       MBEDTLS_PLATFORM_FREE_MACRO
  |  |  ------------------
  |  |  |  | 4095|  34.0k|#define MBEDTLS_PLATFORM_FREE_MACRO            my_free
  |  |  ------------------
  ------------------
  469|  34.0k|}
pk_wrap.c:eckey_can_do:
  519|  2.79k|{
  520|  2.79k|    return type == MBEDTLS_PK_ECKEY ||
  ------------------
  |  Branch (520:12): [True: 0, False: 2.79k]
  ------------------
  521|  2.79k|           type == MBEDTLS_PK_ECKEY_DH ||
  ------------------
  |  Branch (521:12): [True: 0, False: 2.79k]
  ------------------
  522|  2.79k|           type == MBEDTLS_PK_ECDSA;
  ------------------
  |  Branch (522:12): [True: 2.79k, False: 0]
  ------------------
  523|  2.79k|}
pk_wrap.c:ecdsa_verify_wrap:
  674|  1.39k|{
  675|  1.39k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  1.39k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  676|  1.39k|    ((void) md_alg);
  677|       |
  678|  1.39k|    ret = mbedtls_ecdsa_read_signature((mbedtls_ecdsa_context *) pk->pk_ctx,
  679|  1.39k|                                       hash, hash_len, sig, sig_len);
  680|       |
  681|  1.39k|    if (ret == MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH) {
  ------------------
  |  |   49|  1.39k|#define MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH                  -0x4C00
  ------------------
  |  Branch (681:9): [True: 0, False: 1.39k]
  ------------------
  682|      0|        return MBEDTLS_ERR_PK_SIG_LEN_MISMATCH;
  ------------------
  |  |   62|      0|#define MBEDTLS_ERR_PK_SIG_LEN_MISMATCH    -0x3900
  ------------------
  683|      0|    }
  684|       |
  685|  1.39k|    return ret;
  686|  1.39k|}
pk_wrap.c:eckey_alloc_wrap:
 1082|  11.1k|{
 1083|  11.1k|    void *ctx = mbedtls_calloc(1, sizeof(mbedtls_ecp_keypair));
  ------------------
  |  |  144|  11.1k|#define mbedtls_calloc     MBEDTLS_PLATFORM_CALLOC_MACRO
  |  |  ------------------
  |  |  |  | 4093|  11.1k|#define MBEDTLS_PLATFORM_CALLOC_MACRO        my_calloc
  |  |  ------------------
  ------------------
 1084|       |
 1085|  11.1k|    if (ctx != NULL) {
  ------------------
  |  Branch (1085:9): [True: 11.1k, False: 0]
  ------------------
 1086|  11.1k|        mbedtls_ecp_keypair_init(ctx);
 1087|  11.1k|    }
 1088|       |
 1089|  11.1k|    return ctx;
 1090|  11.1k|}
pk_wrap.c:eckey_free_wrap:
 1093|  11.1k|{
 1094|  11.1k|    mbedtls_ecp_keypair_free((mbedtls_ecp_keypair *) ctx);
 1095|  11.1k|    mbedtls_free(ctx);
  ------------------
  |  |  143|  11.1k|#define mbedtls_free       MBEDTLS_PLATFORM_FREE_MACRO
  |  |  ------------------
  |  |  |  | 4095|  11.1k|#define MBEDTLS_PLATFORM_FREE_MACRO            my_free
  |  |  ------------------
  ------------------
 1096|  11.1k|}

mbedtls_pk_parse_subpubkey:
  519|  45.2k|{
  520|  45.2k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  45.2k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  521|  45.2k|    size_t len;
  522|  45.2k|    mbedtls_asn1_buf alg_params;
  523|  45.2k|    mbedtls_pk_type_t pk_alg = MBEDTLS_PK_NONE;
  524|  45.2k|    mbedtls_ecp_group_id ec_grp_id = MBEDTLS_ECP_DP_NONE;
  525|  45.2k|    const mbedtls_pk_info_t *pk_info;
  526|       |
  527|  45.2k|    if ((ret = mbedtls_asn1_get_tag(p, end, &len,
  ------------------
  |  Branch (527:9): [True: 0, False: 45.2k]
  ------------------
  528|  45.2k|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|  45.2k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|  45.2k|#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|  45.2k|    end = *p + len;
  533|       |
  534|  45.2k|    if ((ret = pk_get_pk_alg(p, end, &pk_alg, &alg_params, &ec_grp_id)) != 0) {
  ------------------
  |  Branch (534:9): [True: 0, False: 45.2k]
  ------------------
  535|      0|        return ret;
  536|      0|    }
  537|       |
  538|  45.2k|    if ((ret = mbedtls_asn1_get_bitstring_null(p, end, &len)) != 0) {
  ------------------
  |  Branch (538:9): [True: 0, False: 45.2k]
  ------------------
  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|  45.2k|    if (*p + len != end) {
  ------------------
  |  Branch (542:9): [True: 0, False: 45.2k]
  ------------------
  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|  45.2k|    if ((pk_info = mbedtls_pk_info_from_type(pk_alg)) == NULL) {
  ------------------
  |  Branch (547:9): [True: 0, False: 45.2k]
  ------------------
  548|      0|        return MBEDTLS_ERR_PK_UNKNOWN_PK_ALG;
  ------------------
  |  |   48|      0|#define MBEDTLS_ERR_PK_UNKNOWN_PK_ALG      -0x3C80
  ------------------
  549|      0|    }
  550|       |
  551|  45.2k|    if ((ret = mbedtls_pk_setup(pk, pk_info)) != 0) {
  ------------------
  |  Branch (551:9): [True: 0, False: 45.2k]
  ------------------
  552|      0|        return ret;
  553|      0|    }
  554|       |
  555|  45.2k|#if defined(MBEDTLS_RSA_C)
  556|  45.2k|    if (pk_alg == MBEDTLS_PK_RSA) {
  ------------------
  |  Branch (556:9): [True: 34.0k, False: 11.1k]
  ------------------
  557|  34.0k|        ret = mbedtls_rsa_parse_pubkey(mbedtls_pk_rsa(*pk), *p, (size_t) (end - *p));
  558|  34.0k|        if (ret == 0) {
  ------------------
  |  Branch (558:13): [True: 34.0k, False: 0]
  ------------------
  559|       |            /* On success all the input has been consumed by the parsing function. */
  560|  34.0k|            *p += end - *p;
  561|  34.0k|        } 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|  34.0k|    } else
  569|  11.1k|#endif /* MBEDTLS_RSA_C */
  570|  11.1k|#if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
  571|  11.1k|    if (pk_alg == MBEDTLS_PK_ECKEY_DH || pk_alg == MBEDTLS_PK_ECKEY) {
  ------------------
  |  Branch (571:9): [True: 0, False: 11.1k]
  |  Branch (571:42): [True: 11.1k, False: 0]
  ------------------
  572|  11.1k|#if defined(MBEDTLS_PK_HAVE_RFC8410_CURVES)
  573|  11.1k|        if (MBEDTLS_PK_IS_RFC8410_GROUP_ID(ec_grp_id)) {
  ------------------
  |  |  122|  11.1k|    ((id == MBEDTLS_ECP_DP_CURVE25519) || (id == MBEDTLS_ECP_DP_CURVE448))
  |  |  ------------------
  |  |  |  Branch (122:6): [True: 0, False: 11.1k]
  |  |  |  Branch (122:43): [True: 0, False: 11.1k]
  |  |  ------------------
  ------------------
  574|      0|            ret = pk_use_ecparams_rfc8410(&alg_params, ec_grp_id, pk);
  575|      0|        } else
  576|  11.1k|#endif
  577|  11.1k|        {
  578|  11.1k|            ret = pk_use_ecparams(&alg_params, pk);
  579|  11.1k|        }
  580|  11.1k|        if (ret == 0) {
  ------------------
  |  Branch (580:13): [True: 11.1k, False: 0]
  ------------------
  581|  11.1k|            ret = mbedtls_pk_ecc_set_pubkey(pk, *p, (size_t) (end - *p));
  582|  11.1k|            *p += end - *p;
  583|  11.1k|        }
  584|  11.1k|    } 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|  45.2k|    if (ret == 0 && *p != end) {
  ------------------
  |  Branch (588:9): [True: 45.2k, False: 0]
  |  Branch (588:21): [True: 0, False: 45.2k]
  ------------------
  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|  45.2k|    if (ret != 0) {
  ------------------
  |  Branch (593:9): [True: 0, False: 45.2k]
  ------------------
  594|      0|        mbedtls_pk_free(pk);
  595|      0|    }
  596|       |
  597|  45.2k|    return ret;
  598|  45.2k|}
pkparse.c:pk_get_pk_alg:
  475|  45.2k|{
  476|  45.2k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  45.2k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  477|  45.2k|    mbedtls_asn1_buf alg_oid;
  478|       |
  479|  45.2k|    memset(params, 0, sizeof(mbedtls_asn1_buf));
  480|       |
  481|  45.2k|    if ((ret = mbedtls_asn1_get_alg(p, end, &alg_oid, params)) != 0) {
  ------------------
  |  Branch (481:9): [True: 0, False: 45.2k]
  ------------------
  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|  45.2k|    ret = mbedtls_oid_get_pk_alg(&alg_oid, pk_alg);
  486|  45.2k|#if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
  487|  45.2k|    if (ret == MBEDTLS_ERR_OID_NOT_FOUND) {
  ------------------
  |  |   28|  45.2k|#define MBEDTLS_ERR_OID_NOT_FOUND                         -0x002E
  ------------------
  |  Branch (487:9): [True: 0, False: 45.2k]
  ------------------
  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|  45.2k|    if (ret != 0) {
  ------------------
  |  Branch (496:9): [True: 0, False: 45.2k]
  ------------------
  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|  45.2k|    if (*pk_alg == MBEDTLS_PK_RSA &&
  ------------------
  |  Branch (503:9): [True: 34.0k, False: 11.1k]
  ------------------
  504|  45.2k|        ((params->tag != MBEDTLS_ASN1_NULL && params->tag != 0) ||
  ------------------
  |  |   68|  68.1k|#define MBEDTLS_ASN1_NULL                    0x05
  ------------------
  |  Branch (504:11): [True: 0, False: 34.0k]
  |  Branch (504:47): [True: 0, False: 0]
  ------------------
  505|  34.0k|         params->len != 0)) {
  ------------------
  |  Branch (505:10): [True: 0, False: 34.0k]
  ------------------
  506|      0|        return MBEDTLS_ERR_PK_INVALID_ALG;
  ------------------
  |  |   56|      0|#define MBEDTLS_ERR_PK_INVALID_ALG         -0x3A80
  ------------------
  507|      0|    }
  508|       |
  509|  45.2k|    return 0;
  510|  45.2k|}
pkparse.c:pk_use_ecparams:
  390|  11.1k|{
  391|  11.1k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  11.1k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  392|  11.1k|    mbedtls_ecp_group_id grp_id;
  393|       |
  394|  11.1k|    if (params->tag == MBEDTLS_ASN1_OID) {
  ------------------
  |  |   69|  11.1k|#define MBEDTLS_ASN1_OID                     0x06
  ------------------
  |  Branch (394:9): [True: 11.1k, False: 0]
  ------------------
  395|  11.1k|        if (mbedtls_oid_get_ec_grp(params, &grp_id) != 0) {
  ------------------
  |  Branch (395:13): [True: 0, False: 11.1k]
  ------------------
  396|      0|            return MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE;
  ------------------
  |  |   58|      0|#define MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE -0x3A00
  ------------------
  397|      0|        }
  398|  11.1k|    } 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|  11.1k|    return mbedtls_pk_ecc_set_group(pk, grp_id);
  406|  11.1k|}

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

mbedtls_rsa_parse_pubkey:
  228|  34.0k|{
  229|  34.0k|    unsigned char *p = (unsigned char *) key;
  230|  34.0k|    unsigned char *end = (unsigned char *) (key + keylen);
  231|  34.0k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  34.0k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  232|  34.0k|    size_t len;
  233|       |
  234|       |    /*
  235|       |     *  RSAPublicKey ::= SEQUENCE {
  236|       |     *      modulus           INTEGER,  -- n
  237|       |     *      publicExponent    INTEGER   -- e
  238|       |     *  }
  239|       |     */
  240|       |
  241|  34.0k|    if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
  ------------------
  |  Branch (241:9): [True: 0, False: 34.0k]
  ------------------
  242|  34.0k|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|  34.0k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|  34.0k|#define MBEDTLS_ASN1_SEQUENCE                0x10
  ------------------
  243|      0|        return ret;
  244|      0|    }
  245|       |
  246|  34.0k|    if (end != p + len) {
  ------------------
  |  Branch (246:9): [True: 0, False: 34.0k]
  ------------------
  247|      0|        return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
  ------------------
  |  |   33|      0|#define MBEDTLS_ERR_RSA_BAD_INPUT_DATA                    -0x4080
  ------------------
  248|      0|    }
  249|       |
  250|       |    /* Import N */
  251|  34.0k|    if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_INTEGER)) != 0) {
  ------------------
  |  |   65|  34.0k|#define MBEDTLS_ASN1_INTEGER                 0x02
  ------------------
  |  Branch (251:9): [True: 0, False: 34.0k]
  ------------------
  252|      0|        return ret;
  253|      0|    }
  254|       |
  255|  34.0k|    if ((ret = mbedtls_rsa_import_raw(rsa, p, len, NULL, 0, NULL, 0,
  ------------------
  |  Branch (255:9): [True: 0, False: 34.0k]
  ------------------
  256|  34.0k|                                      NULL, 0, NULL, 0)) != 0) {
  257|      0|        return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
  ------------------
  |  |   33|      0|#define MBEDTLS_ERR_RSA_BAD_INPUT_DATA                    -0x4080
  ------------------
  258|      0|    }
  259|       |
  260|  34.0k|    p += len;
  261|       |
  262|       |    /* Import E */
  263|  34.0k|    if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_INTEGER)) != 0) {
  ------------------
  |  |   65|  34.0k|#define MBEDTLS_ASN1_INTEGER                 0x02
  ------------------
  |  Branch (263:9): [True: 0, False: 34.0k]
  ------------------
  264|      0|        return ret;
  265|      0|    }
  266|       |
  267|  34.0k|    if ((ret = mbedtls_rsa_import_raw(rsa, NULL, 0, NULL, 0, NULL, 0,
  ------------------
  |  Branch (267:9): [True: 0, False: 34.0k]
  ------------------
  268|  34.0k|                                      NULL, 0, p, len)) != 0) {
  269|      0|        return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
  ------------------
  |  |   33|      0|#define MBEDTLS_ERR_RSA_BAD_INPUT_DATA                    -0x4080
  ------------------
  270|      0|    }
  271|       |
  272|  34.0k|    p += len;
  273|       |
  274|  34.0k|    if (mbedtls_rsa_complete(rsa) != 0 ||
  ------------------
  |  Branch (274:9): [True: 0, False: 34.0k]
  ------------------
  275|  34.0k|        mbedtls_rsa_check_pubkey(rsa) != 0) {
  ------------------
  |  Branch (275:9): [True: 0, False: 34.0k]
  ------------------
  276|      0|        return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
  ------------------
  |  |   33|      0|#define MBEDTLS_ERR_RSA_BAD_INPUT_DATA                    -0x4080
  ------------------
  277|      0|    }
  278|       |
  279|  34.0k|    if (p != end) {
  ------------------
  |  Branch (279:9): [True: 0, False: 34.0k]
  ------------------
  280|      0|        return MBEDTLS_ERR_ASN1_LENGTH_MISMATCH;
  ------------------
  |  |   43|      0|#define MBEDTLS_ERR_ASN1_LENGTH_MISMATCH                  -0x0066
  ------------------
  281|      0|    }
  282|       |
  283|  34.0k|    return 0;
  284|  34.0k|}
mbedtls_rsa_import_raw:
  600|  68.1k|{
  601|  68.1k|    int ret = 0;
  602|       |
  603|  68.1k|    if (N != NULL) {
  ------------------
  |  Branch (603:9): [True: 34.0k, False: 34.0k]
  ------------------
  604|  34.0k|        MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&ctx->N, N, N_len));
  ------------------
  |  |   41|  34.0k|    do                           \
  |  |   42|  34.0k|    {                            \
  |  |   43|  34.0k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 34.0k]
  |  |  ------------------
  |  |   44|  34.0k|        goto cleanup;        \
  |  |   45|  34.0k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  605|  34.0k|        ctx->len = mbedtls_mpi_size(&ctx->N);
  606|  34.0k|    }
  607|       |
  608|  68.1k|    if (P != NULL) {
  ------------------
  |  Branch (608:9): [True: 0, False: 68.1k]
  ------------------
  609|      0|        MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&ctx->P, P, P_len));
  ------------------
  |  |   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]
  |  |  ------------------
  ------------------
  610|      0|    }
  611|       |
  612|  68.1k|    if (Q != NULL) {
  ------------------
  |  Branch (612:9): [True: 0, False: 68.1k]
  ------------------
  613|      0|        MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&ctx->Q, Q, Q_len));
  ------------------
  |  |   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]
  |  |  ------------------
  ------------------
  614|      0|    }
  615|       |
  616|  68.1k|    if (D != NULL) {
  ------------------
  |  Branch (616:9): [True: 0, False: 68.1k]
  ------------------
  617|      0|        MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&ctx->D, D, D_len));
  ------------------
  |  |   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]
  |  |  ------------------
  ------------------
  618|      0|    }
  619|       |
  620|  68.1k|    if (E != NULL) {
  ------------------
  |  Branch (620:9): [True: 34.0k, False: 34.0k]
  ------------------
  621|  34.0k|        MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&ctx->E, E, E_len));
  ------------------
  |  |   41|  34.0k|    do                           \
  |  |   42|  34.0k|    {                            \
  |  |   43|  34.0k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 34.0k]
  |  |  ------------------
  |  |   44|  34.0k|        goto cleanup;        \
  |  |   45|  34.0k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  622|  34.0k|    }
  623|       |
  624|  68.1k|cleanup:
  625|       |
  626|  68.1k|    if (ret != 0) {
  ------------------
  |  Branch (626:9): [True: 0, False: 68.1k]
  ------------------
  627|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  628|      0|    }
  629|       |
  630|  68.1k|    return 0;
  631|  68.1k|}
mbedtls_rsa_complete:
  723|  34.0k|{
  724|  34.0k|    int ret = 0;
  725|  34.0k|    int have_N, have_P, have_Q, have_D, have_E;
  726|  34.0k|#if !defined(MBEDTLS_RSA_NO_CRT)
  727|  34.0k|    int have_DP, have_DQ, have_QP;
  728|  34.0k|#endif
  729|  34.0k|    int n_missing, pq_missing, d_missing, is_pub, is_priv;
  730|       |
  731|  34.0k|    have_N = (mbedtls_mpi_cmp_int(&ctx->N, 0) != 0);
  732|  34.0k|    have_P = (mbedtls_mpi_cmp_int(&ctx->P, 0) != 0);
  733|  34.0k|    have_Q = (mbedtls_mpi_cmp_int(&ctx->Q, 0) != 0);
  734|  34.0k|    have_D = (mbedtls_mpi_cmp_int(&ctx->D, 0) != 0);
  735|  34.0k|    have_E = (mbedtls_mpi_cmp_int(&ctx->E, 0) != 0);
  736|       |
  737|  34.0k|#if !defined(MBEDTLS_RSA_NO_CRT)
  738|  34.0k|    have_DP = (mbedtls_mpi_cmp_int(&ctx->DP, 0) != 0);
  739|  34.0k|    have_DQ = (mbedtls_mpi_cmp_int(&ctx->DQ, 0) != 0);
  740|  34.0k|    have_QP = (mbedtls_mpi_cmp_int(&ctx->QP, 0) != 0);
  741|  34.0k|#endif
  742|       |
  743|       |    /*
  744|       |     * Check whether provided parameters are enough
  745|       |     * to deduce all others. The following incomplete
  746|       |     * parameter sets for private keys are supported:
  747|       |     *
  748|       |     * (1) P, Q missing.
  749|       |     * (2) D and potentially N missing.
  750|       |     *
  751|       |     */
  752|       |
  753|  34.0k|    n_missing  =              have_P &&  have_Q &&  have_D && have_E;
  ------------------
  |  Branch (753:31): [True: 0, False: 34.0k]
  |  Branch (753:42): [True: 0, False: 0]
  |  Branch (753:53): [True: 0, False: 0]
  |  Branch (753:63): [True: 0, False: 0]
  ------------------
  754|  34.0k|    pq_missing =   have_N && !have_P && !have_Q &&  have_D && have_E;
  ------------------
  |  Branch (754:20): [True: 34.0k, False: 0]
  |  Branch (754:30): [True: 34.0k, False: 0]
  |  Branch (754:41): [True: 34.0k, False: 0]
  |  Branch (754:53): [True: 0, False: 34.0k]
  |  Branch (754:63): [True: 0, False: 0]
  ------------------
  755|  34.0k|    d_missing  =              have_P &&  have_Q && !have_D && have_E;
  ------------------
  |  Branch (755:31): [True: 0, False: 34.0k]
  |  Branch (755:42): [True: 0, False: 0]
  |  Branch (755:52): [True: 0, False: 0]
  |  Branch (755:63): [True: 0, False: 0]
  ------------------
  756|  34.0k|    is_pub     =   have_N && !have_P && !have_Q && !have_D && have_E;
  ------------------
  |  Branch (756:20): [True: 34.0k, False: 0]
  |  Branch (756:30): [True: 34.0k, False: 0]
  |  Branch (756:41): [True: 34.0k, False: 0]
  |  Branch (756:52): [True: 34.0k, False: 0]
  |  Branch (756:63): [True: 34.0k, False: 0]
  ------------------
  757|       |
  758|       |    /* These three alternatives are mutually exclusive */
  759|  34.0k|    is_priv = n_missing || pq_missing || d_missing;
  ------------------
  |  Branch (759:15): [True: 0, False: 34.0k]
  |  Branch (759:28): [True: 0, False: 34.0k]
  |  Branch (759:42): [True: 0, False: 34.0k]
  ------------------
  760|       |
  761|  34.0k|    if (!is_priv && !is_pub) {
  ------------------
  |  Branch (761:9): [True: 34.0k, False: 0]
  |  Branch (761:21): [True: 0, False: 34.0k]
  ------------------
  762|      0|        return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
  ------------------
  |  |   33|      0|#define MBEDTLS_ERR_RSA_BAD_INPUT_DATA                    -0x4080
  ------------------
  763|      0|    }
  764|       |
  765|       |    /*
  766|       |     * Step 1: Deduce N if P, Q are provided.
  767|       |     */
  768|       |
  769|  34.0k|    if (!have_N && have_P && have_Q) {
  ------------------
  |  Branch (769:9): [True: 0, False: 34.0k]
  |  Branch (769:20): [True: 0, False: 0]
  |  Branch (769:30): [True: 0, False: 0]
  ------------------
  770|      0|        if ((ret = mbedtls_mpi_mul_mpi(&ctx->N, &ctx->P,
  ------------------
  |  Branch (770:13): [True: 0, False: 0]
  ------------------
  771|      0|                                       &ctx->Q)) != 0) {
  772|      0|            return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  773|      0|        }
  774|       |
  775|      0|        ctx->len = mbedtls_mpi_size(&ctx->N);
  776|      0|    }
  777|       |
  778|       |    /*
  779|       |     * Step 2: Deduce and verify all remaining core parameters.
  780|       |     */
  781|       |
  782|  34.0k|    if (pq_missing) {
  ------------------
  |  Branch (782:9): [True: 0, False: 34.0k]
  ------------------
  783|      0|        ret = mbedtls_rsa_deduce_primes(&ctx->N, &ctx->E, &ctx->D,
  784|      0|                                        &ctx->P, &ctx->Q);
  785|      0|        if (ret != 0) {
  ------------------
  |  Branch (785:13): [True: 0, False: 0]
  ------------------
  786|      0|            return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  787|      0|        }
  788|       |
  789|  34.0k|    } else if (d_missing) {
  ------------------
  |  Branch (789:16): [True: 0, False: 34.0k]
  ------------------
  790|      0|        if ((ret = mbedtls_rsa_deduce_private_exponent(&ctx->P,
  ------------------
  |  Branch (790:13): [True: 0, False: 0]
  ------------------
  791|      0|                                                       &ctx->Q,
  792|      0|                                                       &ctx->E,
  793|      0|                                                       &ctx->D)) != 0) {
  794|      0|            return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  795|      0|        }
  796|      0|    }
  797|       |
  798|       |    /*
  799|       |     * Step 3: Deduce all additional parameters specific
  800|       |     *         to our current RSA implementation.
  801|       |     */
  802|       |
  803|  34.0k|#if !defined(MBEDTLS_RSA_NO_CRT)
  804|  34.0k|    if (is_priv && !(have_DP && have_DQ && have_QP)) {
  ------------------
  |  Branch (804:9): [True: 0, False: 34.0k]
  |  Branch (804:22): [True: 0, False: 0]
  |  Branch (804:33): [True: 0, False: 0]
  |  Branch (804:44): [True: 0, False: 0]
  ------------------
  805|      0|        ret = mbedtls_rsa_deduce_crt(&ctx->P,  &ctx->Q,  &ctx->D,
  806|      0|                                     &ctx->DP, &ctx->DQ, &ctx->QP);
  807|      0|        if (ret != 0) {
  ------------------
  |  Branch (807:13): [True: 0, False: 0]
  ------------------
  808|      0|            return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  809|      0|        }
  810|      0|    }
  811|  34.0k|#endif /* MBEDTLS_RSA_NO_CRT */
  812|       |
  813|       |    /*
  814|       |     * Step 3: Basic sanity checks
  815|       |     */
  816|       |
  817|  34.0k|    return rsa_check_context(ctx, is_priv, 1);
  818|  34.0k|}
mbedtls_rsa_init:
  954|  36.6k|{
  955|  36.6k|    memset(ctx, 0, sizeof(mbedtls_rsa_context));
  956|       |
  957|  36.6k|    ctx->padding = MBEDTLS_RSA_PKCS_V15;
  ------------------
  |  |   55|  36.6k|#define MBEDTLS_RSA_PKCS_V15    0 /**< Use PKCS#1 v1.5 encoding. */
  ------------------
  958|  36.6k|    ctx->hash_id = MBEDTLS_MD_NONE;
  959|       |
  960|       |#if defined(MBEDTLS_THREADING_C)
  961|       |    /* Set ctx->ver to nonzero to indicate that the mutex has been
  962|       |     * initialized and will need to be freed. */
  963|       |    ctx->ver = 1;
  964|       |    mbedtls_mutex_init(&ctx->mutex);
  965|       |#endif
  966|  36.6k|}
mbedtls_rsa_get_bitlen:
 1024|  10.4k|{
 1025|  10.4k|    return mbedtls_mpi_bitlen(&ctx->N);
 1026|  10.4k|}
mbedtls_rsa_get_len:
 1032|  4.19k|{
 1033|  4.19k|    return ctx->len;
 1034|  4.19k|}
mbedtls_rsa_check_pubkey:
 1170|  34.0k|{
 1171|  34.0k|    if (rsa_check_context(ctx, 0 /* public */, 0 /* no blinding */) != 0) {
  ------------------
  |  Branch (1171:9): [True: 0, False: 34.0k]
  ------------------
 1172|      0|        return MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
  ------------------
  |  |   39|      0|#define MBEDTLS_ERR_RSA_KEY_CHECK_FAILED                  -0x4200
  ------------------
 1173|      0|    }
 1174|       |
 1175|  34.0k|    if (mbedtls_mpi_bitlen(&ctx->N) < 128) {
  ------------------
  |  Branch (1175:9): [True: 0, False: 34.0k]
  ------------------
 1176|      0|        return MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
  ------------------
  |  |   39|      0|#define MBEDTLS_ERR_RSA_KEY_CHECK_FAILED                  -0x4200
  ------------------
 1177|      0|    }
 1178|       |
 1179|  34.0k|    if (mbedtls_mpi_get_bit(&ctx->E, 0) == 0 ||
  ------------------
  |  Branch (1179:9): [True: 0, False: 34.0k]
  ------------------
 1180|  34.0k|        mbedtls_mpi_bitlen(&ctx->E)     < 2  ||
  ------------------
  |  Branch (1180:9): [True: 0, False: 34.0k]
  ------------------
 1181|  34.0k|        mbedtls_mpi_cmp_mpi(&ctx->E, &ctx->N) >= 0) {
  ------------------
  |  Branch (1181:9): [True: 0, False: 34.0k]
  ------------------
 1182|      0|        return MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
  ------------------
  |  |   39|      0|#define MBEDTLS_ERR_RSA_KEY_CHECK_FAILED                  -0x4200
  ------------------
 1183|      0|    }
 1184|       |
 1185|  34.0k|    return 0;
 1186|  34.0k|}
mbedtls_rsa_public:
 1238|  4.19k|{
 1239|  4.19k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  4.19k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1240|  4.19k|    size_t olen;
 1241|  4.19k|    mbedtls_mpi T;
 1242|       |
 1243|  4.19k|    if (rsa_check_context(ctx, 0 /* public */, 0 /* no blinding */)) {
  ------------------
  |  Branch (1243:9): [True: 0, False: 4.19k]
  ------------------
 1244|      0|        return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
  ------------------
  |  |   33|      0|#define MBEDTLS_ERR_RSA_BAD_INPUT_DATA                    -0x4080
  ------------------
 1245|      0|    }
 1246|       |
 1247|  4.19k|    mbedtls_mpi_init(&T);
 1248|       |
 1249|       |#if defined(MBEDTLS_THREADING_C)
 1250|       |    if ((ret = mbedtls_mutex_lock(&ctx->mutex)) != 0) {
 1251|       |        return ret;
 1252|       |    }
 1253|       |#endif
 1254|       |
 1255|  4.19k|    MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&T, input, ctx->len));
  ------------------
  |  |   41|  4.19k|    do                           \
  |  |   42|  4.19k|    {                            \
  |  |   43|  4.19k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.19k]
  |  |  ------------------
  |  |   44|  4.19k|        goto cleanup;        \
  |  |   45|  4.19k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1256|       |
 1257|  4.19k|    if (mbedtls_mpi_cmp_mpi(&T, &ctx->N) >= 0) {
  ------------------
  |  Branch (1257:9): [True: 0, False: 4.19k]
  ------------------
 1258|      0|        ret = MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MPI_BAD_INPUT_DATA                    -0x0004
  ------------------
 1259|      0|        goto cleanup;
 1260|      0|    }
 1261|       |
 1262|  4.19k|    olen = ctx->len;
 1263|  4.19k|    MBEDTLS_MPI_CHK(mbedtls_mpi_exp_mod_unsafe(&T, &T, &ctx->E, &ctx->N, &ctx->RN));
  ------------------
  |  |   41|  4.19k|    do                           \
  |  |   42|  4.19k|    {                            \
  |  |   43|  4.19k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.19k]
  |  |  ------------------
  |  |   44|  4.19k|        goto cleanup;        \
  |  |   45|  4.19k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1264|  4.19k|    MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(&T, output, olen));
  ------------------
  |  |   41|  4.19k|    do                           \
  |  |   42|  4.19k|    {                            \
  |  |   43|  4.19k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4.19k]
  |  |  ------------------
  |  |   44|  4.19k|        goto cleanup;        \
  |  |   45|  4.19k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1265|       |
 1266|  4.19k|cleanup:
 1267|       |#if defined(MBEDTLS_THREADING_C)
 1268|       |    if (mbedtls_mutex_unlock(&ctx->mutex) != 0) {
 1269|       |        return MBEDTLS_ERR_THREADING_MUTEX_ERROR;
 1270|       |    }
 1271|       |#endif
 1272|       |
 1273|  4.19k|    mbedtls_mpi_free(&T);
 1274|       |
 1275|  4.19k|    if (ret != 0) {
  ------------------
  |  Branch (1275:9): [True: 0, False: 4.19k]
  ------------------
 1276|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_RSA_PUBLIC_FAILED, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
 1277|      0|    }
 1278|       |
 1279|  4.19k|    return 0;
 1280|  4.19k|}
mbedtls_rsa_rsassa_pkcs1_v15_verify:
 2680|  4.19k|{
 2681|  4.19k|    int ret = 0;
 2682|  4.19k|    size_t sig_len;
 2683|  4.19k|    unsigned char *encoded = NULL, *encoded_expected = NULL;
 2684|       |
 2685|  4.19k|    if ((md_alg != MBEDTLS_MD_NONE || hashlen != 0) && hash == NULL) {
  ------------------
  |  Branch (2685:10): [True: 4.19k, False: 0]
  |  Branch (2685:39): [True: 0, False: 0]
  |  Branch (2685:56): [True: 0, False: 4.19k]
  ------------------
 2686|      0|        return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
  ------------------
  |  |   33|      0|#define MBEDTLS_ERR_RSA_BAD_INPUT_DATA                    -0x4080
  ------------------
 2687|      0|    }
 2688|       |
 2689|  4.19k|    sig_len = ctx->len;
 2690|       |
 2691|       |    /*
 2692|       |     * Prepare expected PKCS1 v1.5 encoding of hash.
 2693|       |     */
 2694|       |
 2695|  4.19k|    if ((encoded          = mbedtls_calloc(1, sig_len)) == NULL ||
  ------------------
  |  |  144|  4.19k|#define mbedtls_calloc     MBEDTLS_PLATFORM_CALLOC_MACRO
  |  |  ------------------
  |  |  |  | 4093|  4.19k|#define MBEDTLS_PLATFORM_CALLOC_MACRO        my_calloc
  |  |  ------------------
  ------------------
  |  Branch (2695:9): [True: 0, False: 4.19k]
  ------------------
 2696|  4.19k|        (encoded_expected = mbedtls_calloc(1, sig_len)) == NULL) {
  ------------------
  |  |  144|  4.19k|#define mbedtls_calloc     MBEDTLS_PLATFORM_CALLOC_MACRO
  |  |  ------------------
  |  |  |  | 4093|  4.19k|#define MBEDTLS_PLATFORM_CALLOC_MACRO        my_calloc
  |  |  ------------------
  ------------------
  |  Branch (2696:9): [True: 0, False: 4.19k]
  ------------------
 2697|      0|        ret = MBEDTLS_ERR_MPI_ALLOC_FAILED;
  ------------------
  |  |   38|      0|#define MBEDTLS_ERR_MPI_ALLOC_FAILED                      -0x0010
  ------------------
 2698|      0|        goto cleanup;
 2699|      0|    }
 2700|       |
 2701|  4.19k|    if ((ret = rsa_rsassa_pkcs1_v15_encode(md_alg, hashlen, hash, sig_len,
  ------------------
  |  Branch (2701:9): [True: 0, False: 4.19k]
  ------------------
 2702|  4.19k|                                           encoded_expected)) != 0) {
 2703|      0|        goto cleanup;
 2704|      0|    }
 2705|       |
 2706|       |    /*
 2707|       |     * Apply RSA primitive to get what should be PKCS1 encoded hash.
 2708|       |     */
 2709|       |
 2710|  4.19k|    ret = mbedtls_rsa_public(ctx, sig, encoded);
 2711|  4.19k|    if (ret != 0) {
  ------------------
  |  Branch (2711:9): [True: 0, False: 4.19k]
  ------------------
 2712|      0|        goto cleanup;
 2713|      0|    }
 2714|       |
 2715|       |    /*
 2716|       |     * Compare
 2717|       |     */
 2718|       |
 2719|  4.19k|    if ((ret = mbedtls_ct_memcmp(encoded, encoded_expected,
  ------------------
  |  Branch (2719:9): [True: 0, False: 4.19k]
  ------------------
 2720|  4.19k|                                 sig_len)) != 0) {
 2721|      0|        ret = MBEDTLS_ERR_RSA_VERIFY_FAILED;
  ------------------
  |  |   45|      0|#define MBEDTLS_ERR_RSA_VERIFY_FAILED                     -0x4380
  ------------------
 2722|      0|        goto cleanup;
 2723|      0|    }
 2724|       |
 2725|  4.19k|cleanup:
 2726|       |
 2727|  4.19k|    if (encoded != NULL) {
  ------------------
  |  Branch (2727:9): [True: 4.19k, False: 0]
  ------------------
 2728|  4.19k|        mbedtls_zeroize_and_free(encoded, sig_len);
 2729|  4.19k|    }
 2730|       |
 2731|  4.19k|    if (encoded_expected != NULL) {
  ------------------
  |  Branch (2731:9): [True: 4.19k, False: 0]
  ------------------
 2732|  4.19k|        mbedtls_zeroize_and_free(encoded_expected, sig_len);
 2733|  4.19k|    }
 2734|       |
 2735|  4.19k|    return ret;
 2736|  4.19k|}
mbedtls_rsa_pkcs1_verify:
 2747|  4.19k|{
 2748|  4.19k|    if ((md_alg != MBEDTLS_MD_NONE || hashlen != 0) && hash == NULL) {
  ------------------
  |  Branch (2748:10): [True: 4.19k, False: 0]
  |  Branch (2748:39): [True: 0, False: 0]
  |  Branch (2748:56): [True: 0, False: 4.19k]
  ------------------
 2749|      0|        return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
  ------------------
  |  |   33|      0|#define MBEDTLS_ERR_RSA_BAD_INPUT_DATA                    -0x4080
  ------------------
 2750|      0|    }
 2751|       |
 2752|  4.19k|    switch (ctx->padding) {
 2753|      0|#if defined(MBEDTLS_PKCS1_V15)
 2754|  4.19k|        case MBEDTLS_RSA_PKCS_V15:
  ------------------
  |  |   55|  4.19k|#define MBEDTLS_RSA_PKCS_V15    0 /**< Use PKCS#1 v1.5 encoding. */
  ------------------
  |  Branch (2754:9): [True: 4.19k, False: 0]
  ------------------
 2755|  4.19k|            return mbedtls_rsa_rsassa_pkcs1_v15_verify(ctx, md_alg,
 2756|  4.19k|                                                       hashlen, hash, sig);
 2757|      0|#endif
 2758|       |
 2759|      0|#if defined(MBEDTLS_PKCS1_V21)
 2760|      0|        case MBEDTLS_RSA_PKCS_V21:
  ------------------
  |  |   56|      0|#define MBEDTLS_RSA_PKCS_V21    1 /**< Use PKCS#1 v2.1 encoding. */
  ------------------
  |  Branch (2760:9): [True: 0, False: 4.19k]
  ------------------
 2761|      0|            return mbedtls_rsa_rsassa_pss_verify(ctx, md_alg,
 2762|      0|                                                 hashlen, hash, sig);
 2763|      0|#endif
 2764|       |
 2765|      0|        default:
  ------------------
  |  Branch (2765:9): [True: 0, False: 4.19k]
  ------------------
 2766|      0|            return MBEDTLS_ERR_RSA_INVALID_PADDING;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_RSA_INVALID_PADDING                   -0x4100
  ------------------
 2767|  4.19k|    }
 2768|  4.19k|}
mbedtls_rsa_copy:
 2774|  2.61k|{
 2775|  2.61k|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|  2.61k|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 2776|       |
 2777|  2.61k|    dst->len = src->len;
 2778|       |
 2779|  2.61k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->N, &src->N));
  ------------------
  |  |   41|  2.61k|    do                           \
  |  |   42|  2.61k|    {                            \
  |  |   43|  2.61k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.61k]
  |  |  ------------------
  |  |   44|  2.61k|        goto cleanup;        \
  |  |   45|  2.61k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2780|  2.61k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->E, &src->E));
  ------------------
  |  |   41|  2.61k|    do                           \
  |  |   42|  2.61k|    {                            \
  |  |   43|  2.61k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.61k]
  |  |  ------------------
  |  |   44|  2.61k|        goto cleanup;        \
  |  |   45|  2.61k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2781|       |
 2782|  2.61k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->D, &src->D));
  ------------------
  |  |   41|  2.61k|    do                           \
  |  |   42|  2.61k|    {                            \
  |  |   43|  2.61k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.61k]
  |  |  ------------------
  |  |   44|  2.61k|        goto cleanup;        \
  |  |   45|  2.61k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2783|  2.61k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->P, &src->P));
  ------------------
  |  |   41|  2.61k|    do                           \
  |  |   42|  2.61k|    {                            \
  |  |   43|  2.61k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.61k]
  |  |  ------------------
  |  |   44|  2.61k|        goto cleanup;        \
  |  |   45|  2.61k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2784|  2.61k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->Q, &src->Q));
  ------------------
  |  |   41|  2.61k|    do                           \
  |  |   42|  2.61k|    {                            \
  |  |   43|  2.61k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.61k]
  |  |  ------------------
  |  |   44|  2.61k|        goto cleanup;        \
  |  |   45|  2.61k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2785|       |
 2786|  2.61k|#if !defined(MBEDTLS_RSA_NO_CRT)
 2787|  2.61k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->DP, &src->DP));
  ------------------
  |  |   41|  2.61k|    do                           \
  |  |   42|  2.61k|    {                            \
  |  |   43|  2.61k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.61k]
  |  |  ------------------
  |  |   44|  2.61k|        goto cleanup;        \
  |  |   45|  2.61k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2788|  2.61k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->DQ, &src->DQ));
  ------------------
  |  |   41|  2.61k|    do                           \
  |  |   42|  2.61k|    {                            \
  |  |   43|  2.61k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.61k]
  |  |  ------------------
  |  |   44|  2.61k|        goto cleanup;        \
  |  |   45|  2.61k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2789|  2.61k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->QP, &src->QP));
  ------------------
  |  |   41|  2.61k|    do                           \
  |  |   42|  2.61k|    {                            \
  |  |   43|  2.61k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.61k]
  |  |  ------------------
  |  |   44|  2.61k|        goto cleanup;        \
  |  |   45|  2.61k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2790|  2.61k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->RP, &src->RP));
  ------------------
  |  |   41|  2.61k|    do                           \
  |  |   42|  2.61k|    {                            \
  |  |   43|  2.61k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.61k]
  |  |  ------------------
  |  |   44|  2.61k|        goto cleanup;        \
  |  |   45|  2.61k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2791|  2.61k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->RQ, &src->RQ));
  ------------------
  |  |   41|  2.61k|    do                           \
  |  |   42|  2.61k|    {                            \
  |  |   43|  2.61k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.61k]
  |  |  ------------------
  |  |   44|  2.61k|        goto cleanup;        \
  |  |   45|  2.61k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2792|  2.61k|#endif
 2793|       |
 2794|  2.61k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->RN, &src->RN));
  ------------------
  |  |   41|  2.61k|    do                           \
  |  |   42|  2.61k|    {                            \
  |  |   43|  2.61k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.61k]
  |  |  ------------------
  |  |   44|  2.61k|        goto cleanup;        \
  |  |   45|  2.61k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2795|       |
 2796|  2.61k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->Vi, &src->Vi));
  ------------------
  |  |   41|  2.61k|    do                           \
  |  |   42|  2.61k|    {                            \
  |  |   43|  2.61k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.61k]
  |  |  ------------------
  |  |   44|  2.61k|        goto cleanup;        \
  |  |   45|  2.61k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2797|  2.61k|    MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->Vf, &src->Vf));
  ------------------
  |  |   41|  2.61k|    do                           \
  |  |   42|  2.61k|    {                            \
  |  |   43|  2.61k|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2.61k]
  |  |  ------------------
  |  |   44|  2.61k|        goto cleanup;        \
  |  |   45|  2.61k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2798|       |
 2799|  2.61k|    dst->padding = src->padding;
 2800|  2.61k|    dst->hash_id = src->hash_id;
 2801|       |
 2802|  2.61k|cleanup:
 2803|  2.61k|    if (ret != 0) {
  ------------------
  |  Branch (2803:9): [True: 0, False: 2.61k]
  ------------------
 2804|      0|        mbedtls_rsa_free(dst);
 2805|      0|    }
 2806|       |
 2807|  2.61k|    return ret;
 2808|  2.61k|}
mbedtls_rsa_free:
 2814|  36.6k|{
 2815|  36.6k|    if (ctx == NULL) {
  ------------------
  |  Branch (2815:9): [True: 0, False: 36.6k]
  ------------------
 2816|      0|        return;
 2817|      0|    }
 2818|       |
 2819|  36.6k|    mbedtls_mpi_free(&ctx->Vi);
 2820|  36.6k|    mbedtls_mpi_free(&ctx->Vf);
 2821|  36.6k|    mbedtls_mpi_free(&ctx->RN);
 2822|  36.6k|    mbedtls_mpi_free(&ctx->D);
 2823|  36.6k|    mbedtls_mpi_free(&ctx->Q);
 2824|  36.6k|    mbedtls_mpi_free(&ctx->P);
 2825|  36.6k|    mbedtls_mpi_free(&ctx->E);
 2826|  36.6k|    mbedtls_mpi_free(&ctx->N);
 2827|       |
 2828|  36.6k|#if !defined(MBEDTLS_RSA_NO_CRT)
 2829|  36.6k|    mbedtls_mpi_free(&ctx->RQ);
 2830|  36.6k|    mbedtls_mpi_free(&ctx->RP);
 2831|  36.6k|    mbedtls_mpi_free(&ctx->QP);
 2832|  36.6k|    mbedtls_mpi_free(&ctx->DQ);
 2833|  36.6k|    mbedtls_mpi_free(&ctx->DP);
 2834|  36.6k|#endif /* MBEDTLS_RSA_NO_CRT */
 2835|       |
 2836|       |#if defined(MBEDTLS_THREADING_C)
 2837|       |    /* Free the mutex, but only if it hasn't been freed already. */
 2838|       |    if (ctx->ver != 0) {
 2839|       |        mbedtls_mutex_free(&ctx->mutex);
 2840|       |        ctx->ver = 0;
 2841|       |    }
 2842|       |#endif
 2843|  36.6k|}
rsa.c:rsa_check_context:
  640|  72.3k|{
  641|  72.3k|#if !defined(MBEDTLS_RSA_NO_CRT)
  642|       |    /* blinding_needed is only used for NO_CRT to decide whether
  643|       |     * P,Q need to be present or not. */
  644|  72.3k|    ((void) blinding_needed);
  645|  72.3k|#endif
  646|       |
  647|  72.3k|    if (ctx->len != mbedtls_mpi_size(&ctx->N) ||
  ------------------
  |  Branch (647:9): [True: 0, False: 72.3k]
  ------------------
  648|  72.3k|        ctx->len > MBEDTLS_MPI_MAX_SIZE) {
  ------------------
  |  |   73|  72.3k|#define MBEDTLS_MPI_MAX_SIZE                              1024     /**< Maximum number of bytes for usable MPIs. */
  ------------------
  |  Branch (648:9): [True: 0, False: 72.3k]
  ------------------
  649|      0|        return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
  ------------------
  |  |   33|      0|#define MBEDTLS_ERR_RSA_BAD_INPUT_DATA                    -0x4080
  ------------------
  650|      0|    }
  651|       |
  652|       |    /*
  653|       |     * 1. Modular exponentiation needs positive, odd moduli.
  654|       |     */
  655|       |
  656|       |    /* Modular exponentiation wrt. N is always used for
  657|       |     * RSA public key operations. */
  658|  72.3k|    if (mbedtls_mpi_cmp_int(&ctx->N, 0) <= 0 ||
  ------------------
  |  Branch (658:9): [True: 0, False: 72.3k]
  ------------------
  659|  72.3k|        mbedtls_mpi_get_bit(&ctx->N, 0) == 0) {
  ------------------
  |  Branch (659:9): [True: 0, False: 72.3k]
  ------------------
  660|      0|        return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
  ------------------
  |  |   33|      0|#define MBEDTLS_ERR_RSA_BAD_INPUT_DATA                    -0x4080
  ------------------
  661|      0|    }
  662|       |
  663|  72.3k|#if !defined(MBEDTLS_RSA_NO_CRT)
  664|       |    /* Modular exponentiation for P and Q is only
  665|       |     * used for private key operations and if CRT
  666|       |     * is used. */
  667|  72.3k|    if (is_priv &&
  ------------------
  |  Branch (667:9): [True: 0, False: 72.3k]
  ------------------
  668|  72.3k|        (mbedtls_mpi_cmp_int(&ctx->P, 0) <= 0 ||
  ------------------
  |  Branch (668:10): [True: 0, False: 0]
  ------------------
  669|      0|         mbedtls_mpi_get_bit(&ctx->P, 0) == 0 ||
  ------------------
  |  Branch (669:10): [True: 0, False: 0]
  ------------------
  670|      0|         mbedtls_mpi_cmp_int(&ctx->Q, 0) <= 0 ||
  ------------------
  |  Branch (670:10): [True: 0, False: 0]
  ------------------
  671|      0|         mbedtls_mpi_get_bit(&ctx->Q, 0) == 0)) {
  ------------------
  |  Branch (671:10): [True: 0, False: 0]
  ------------------
  672|      0|        return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
  ------------------
  |  |   33|      0|#define MBEDTLS_ERR_RSA_BAD_INPUT_DATA                    -0x4080
  ------------------
  673|      0|    }
  674|  72.3k|#endif /* !MBEDTLS_RSA_NO_CRT */
  675|       |
  676|       |    /*
  677|       |     * 2. Exponents must be positive
  678|       |     */
  679|       |
  680|       |    /* Always need E for public key operations */
  681|  72.3k|    if (mbedtls_mpi_cmp_int(&ctx->E, 0) <= 0) {
  ------------------
  |  Branch (681:9): [True: 0, False: 72.3k]
  ------------------
  682|      0|        return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
  ------------------
  |  |   33|      0|#define MBEDTLS_ERR_RSA_BAD_INPUT_DATA                    -0x4080
  ------------------
  683|      0|    }
  684|       |
  685|       |#if defined(MBEDTLS_RSA_NO_CRT)
  686|       |    /* For private key operations, use D or DP & DQ
  687|       |     * as (unblinded) exponents. */
  688|       |    if (is_priv && mbedtls_mpi_cmp_int(&ctx->D, 0) <= 0) {
  689|       |        return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
  690|       |    }
  691|       |#else
  692|  72.3k|    if (is_priv &&
  ------------------
  |  Branch (692:9): [True: 0, False: 72.3k]
  ------------------
  693|  72.3k|        (mbedtls_mpi_cmp_int(&ctx->DP, 0) <= 0 ||
  ------------------
  |  Branch (693:10): [True: 0, False: 0]
  ------------------
  694|      0|         mbedtls_mpi_cmp_int(&ctx->DQ, 0) <= 0)) {
  ------------------
  |  Branch (694:10): [True: 0, False: 0]
  ------------------
  695|      0|        return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
  ------------------
  |  |   33|      0|#define MBEDTLS_ERR_RSA_BAD_INPUT_DATA                    -0x4080
  ------------------
  696|      0|    }
  697|  72.3k|#endif /* MBEDTLS_RSA_NO_CRT */
  698|       |
  699|       |    /* Blinding shouldn't make exponents negative either,
  700|       |     * so check that P, Q >= 1 if that hasn't yet been
  701|       |     * done as part of 1. */
  702|       |#if defined(MBEDTLS_RSA_NO_CRT)
  703|       |    if (is_priv && blinding_needed &&
  704|       |        (mbedtls_mpi_cmp_int(&ctx->P, 0) <= 0 ||
  705|       |         mbedtls_mpi_cmp_int(&ctx->Q, 0) <= 0)) {
  706|       |        return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
  707|       |    }
  708|       |#endif
  709|       |
  710|       |    /* It wouldn't lead to an error if it wasn't satisfied,
  711|       |     * but check for QP >= 1 nonetheless. */
  712|  72.3k|#if !defined(MBEDTLS_RSA_NO_CRT)
  713|  72.3k|    if (is_priv &&
  ------------------
  |  Branch (713:9): [True: 0, False: 72.3k]
  ------------------
  714|  72.3k|        mbedtls_mpi_cmp_int(&ctx->QP, 0) <= 0) {
  ------------------
  |  Branch (714:9): [True: 0, False: 0]
  ------------------
  715|      0|        return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
  ------------------
  |  |   33|      0|#define MBEDTLS_ERR_RSA_BAD_INPUT_DATA                    -0x4080
  ------------------
  716|      0|    }
  717|  72.3k|#endif
  718|       |
  719|  72.3k|    return 0;
  720|  72.3k|}
rsa.c:rsa_rsassa_pkcs1_v15_encode:
 2314|  4.19k|{
 2315|  4.19k|    size_t oid_size  = 0;
 2316|  4.19k|    size_t nb_pad    = dst_len;
 2317|  4.19k|    unsigned char *p = dst;
 2318|  4.19k|    const char *oid  = NULL;
 2319|       |
 2320|       |    /* Are we signing hashed or raw data? */
 2321|  4.19k|    if (md_alg != MBEDTLS_MD_NONE) {
  ------------------
  |  Branch (2321:9): [True: 4.19k, False: 0]
  ------------------
 2322|  4.19k|        unsigned char md_size = mbedtls_md_get_size_from_type(md_alg);
 2323|  4.19k|        if (md_size == 0) {
  ------------------
  |  Branch (2323:13): [True: 0, False: 4.19k]
  ------------------
 2324|      0|            return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
  ------------------
  |  |   33|      0|#define MBEDTLS_ERR_RSA_BAD_INPUT_DATA                    -0x4080
  ------------------
 2325|      0|        }
 2326|       |
 2327|  4.19k|        if (mbedtls_oid_get_oid_by_md(md_alg, &oid, &oid_size) != 0) {
  ------------------
  |  Branch (2327:13): [True: 0, False: 4.19k]
  ------------------
 2328|      0|            return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
  ------------------
  |  |   33|      0|#define MBEDTLS_ERR_RSA_BAD_INPUT_DATA                    -0x4080
  ------------------
 2329|      0|        }
 2330|       |
 2331|  4.19k|        if (hashlen != md_size) {
  ------------------
  |  Branch (2331:13): [True: 0, False: 4.19k]
  ------------------
 2332|      0|            return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
  ------------------
  |  |   33|      0|#define MBEDTLS_ERR_RSA_BAD_INPUT_DATA                    -0x4080
  ------------------
 2333|      0|        }
 2334|       |
 2335|       |        /* Double-check that 8 + hashlen + oid_size can be used as a
 2336|       |         * 1-byte ASN.1 length encoding and that there's no overflow. */
 2337|  4.19k|        if (8 + hashlen + oid_size  >= 0x80         ||
  ------------------
  |  Branch (2337:13): [True: 0, False: 4.19k]
  ------------------
 2338|  4.19k|            10 + hashlen            <  hashlen      ||
  ------------------
  |  Branch (2338:13): [True: 0, False: 4.19k]
  ------------------
 2339|  4.19k|            10 + hashlen + oid_size <  10 + hashlen) {
  ------------------
  |  Branch (2339:13): [True: 0, False: 4.19k]
  ------------------
 2340|      0|            return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
  ------------------
  |  |   33|      0|#define MBEDTLS_ERR_RSA_BAD_INPUT_DATA                    -0x4080
  ------------------
 2341|      0|        }
 2342|       |
 2343|       |        /*
 2344|       |         * Static bounds check:
 2345|       |         * - Need 10 bytes for five tag-length pairs.
 2346|       |         *   (Insist on 1-byte length encodings to protect against variants of
 2347|       |         *    Bleichenbacher's forgery attack against lax PKCS#1v1.5 verification)
 2348|       |         * - Need hashlen bytes for hash
 2349|       |         * - Need oid_size bytes for hash alg OID.
 2350|       |         */
 2351|  4.19k|        if (nb_pad < 10 + hashlen + oid_size) {
  ------------------
  |  Branch (2351:13): [True: 0, False: 4.19k]
  ------------------
 2352|      0|            return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
  ------------------
  |  |   33|      0|#define MBEDTLS_ERR_RSA_BAD_INPUT_DATA                    -0x4080
  ------------------
 2353|      0|        }
 2354|  4.19k|        nb_pad -= 10 + hashlen + oid_size;
 2355|  4.19k|    } else {
 2356|      0|        if (nb_pad < hashlen) {
  ------------------
  |  Branch (2356:13): [True: 0, False: 0]
  ------------------
 2357|      0|            return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
  ------------------
  |  |   33|      0|#define MBEDTLS_ERR_RSA_BAD_INPUT_DATA                    -0x4080
  ------------------
 2358|      0|        }
 2359|       |
 2360|      0|        nb_pad -= hashlen;
 2361|      0|    }
 2362|       |
 2363|       |    /* Need space for signature header and padding delimiter (3 bytes),
 2364|       |     * and 8 bytes for the minimal padding */
 2365|  4.19k|    if (nb_pad < 3 + 8) {
  ------------------
  |  Branch (2365:9): [True: 0, False: 4.19k]
  ------------------
 2366|      0|        return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
  ------------------
  |  |   33|      0|#define MBEDTLS_ERR_RSA_BAD_INPUT_DATA                    -0x4080
  ------------------
 2367|      0|    }
 2368|  4.19k|    nb_pad -= 3;
 2369|       |
 2370|       |    /* Now nb_pad is the amount of memory to be filled
 2371|       |     * with padding, and at least 8 bytes long. */
 2372|       |
 2373|       |    /* Write signature header and padding */
 2374|  4.19k|    *p++ = 0;
 2375|  4.19k|    *p++ = MBEDTLS_RSA_SIGN;
  ------------------
  |  |   58|  4.19k|#define MBEDTLS_RSA_SIGN        1 /**< Identifier for RSA signature operations. */
  ------------------
 2376|  4.19k|    memset(p, 0xFF, nb_pad);
 2377|  4.19k|    p += nb_pad;
 2378|  4.19k|    *p++ = 0;
 2379|       |
 2380|       |    /* Are we signing raw data? */
 2381|  4.19k|    if (md_alg == MBEDTLS_MD_NONE) {
  ------------------
  |  Branch (2381:9): [True: 0, False: 4.19k]
  ------------------
 2382|      0|        memcpy(p, hash, hashlen);
 2383|      0|        return 0;
 2384|      0|    }
 2385|       |
 2386|       |    /* Signing hashed data, add corresponding ASN.1 structure
 2387|       |     *
 2388|       |     * DigestInfo ::= SEQUENCE {
 2389|       |     *   digestAlgorithm DigestAlgorithmIdentifier,
 2390|       |     *   digest Digest }
 2391|       |     * DigestAlgorithmIdentifier ::= AlgorithmIdentifier
 2392|       |     * Digest ::= OCTET STRING
 2393|       |     *
 2394|       |     * Schematic:
 2395|       |     * TAG-SEQ + LEN [ TAG-SEQ + LEN [ TAG-OID  + LEN [ OID  ]
 2396|       |     *                                 TAG-NULL + LEN [ NULL ] ]
 2397|       |     *                 TAG-OCTET + LEN [ HASH ] ]
 2398|       |     */
 2399|  4.19k|    *p++ = MBEDTLS_ASN1_SEQUENCE | MBEDTLS_ASN1_CONSTRUCTED;
  ------------------
  |  |   72|  4.19k|#define MBEDTLS_ASN1_SEQUENCE                0x10
  ------------------
                  *p++ = MBEDTLS_ASN1_SEQUENCE | MBEDTLS_ASN1_CONSTRUCTED;
  ------------------
  |  |   82|  4.19k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
 2400|  4.19k|    *p++ = (unsigned char) (0x08 + oid_size + hashlen);
 2401|  4.19k|    *p++ = MBEDTLS_ASN1_SEQUENCE | MBEDTLS_ASN1_CONSTRUCTED;
  ------------------
  |  |   72|  4.19k|#define MBEDTLS_ASN1_SEQUENCE                0x10
  ------------------
                  *p++ = MBEDTLS_ASN1_SEQUENCE | MBEDTLS_ASN1_CONSTRUCTED;
  ------------------
  |  |   82|  4.19k|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
 2402|  4.19k|    *p++ = (unsigned char) (0x04 + oid_size);
 2403|  4.19k|    *p++ = MBEDTLS_ASN1_OID;
  ------------------
  |  |   69|  4.19k|#define MBEDTLS_ASN1_OID                     0x06
  ------------------
 2404|  4.19k|    *p++ = (unsigned char) oid_size;
 2405|  4.19k|    memcpy(p, oid, oid_size);
 2406|  4.19k|    p += oid_size;
 2407|  4.19k|    *p++ = MBEDTLS_ASN1_NULL;
  ------------------
  |  |   68|  4.19k|#define MBEDTLS_ASN1_NULL                    0x05
  ------------------
 2408|  4.19k|    *p++ = 0x00;
 2409|  4.19k|    *p++ = MBEDTLS_ASN1_OCTET_STRING;
  ------------------
  |  |   67|  4.19k|#define MBEDTLS_ASN1_OCTET_STRING            0x04
  ------------------
 2410|  4.19k|    *p++ = (unsigned char) hashlen;
 2411|  4.19k|    memcpy(p, hash, hashlen);
 2412|  4.19k|    p += hashlen;
 2413|       |
 2414|       |    /* Just a sanity-check, should be automatic
 2415|       |     * after the initial bounds check. */
 2416|  4.19k|    if (p != dst + dst_len) {
  ------------------
  |  Branch (2416:9): [True: 0, False: 4.19k]
  ------------------
 2417|      0|        mbedtls_platform_zeroize(dst, dst_len);
 2418|      0|        return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
  ------------------
  |  |   33|      0|#define MBEDTLS_ERR_RSA_BAD_INPUT_DATA                    -0x4080
  ------------------
 2419|      0|    }
 2420|       |
 2421|  4.19k|    return 0;
 2422|  4.19k|}

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

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

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

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

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

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

libspdm_setup_test_context:
   59|    699|{
   60|    699|    m_libspdm_test_context = spdm_test_context;
   61|    699|}
libspdm_unit_test_group_setup:
   64|  2.79k|{
   65|  2.79k|    libspdm_test_context_t *spdm_test_context;
   66|  2.79k|    void *spdm_context;
   67|       |
   68|  2.79k|    spdm_test_context = m_libspdm_test_context;
   69|  2.79k|    spdm_test_context->spdm_context =
   70|  2.79k|        (void *)malloc(libspdm_get_context_size());
   71|  2.79k|    if (spdm_test_context->spdm_context == NULL) {
  ------------------
  |  Branch (71:9): [True: 0, False: 2.79k]
  ------------------
   72|      0|        return (size_t)-1;
   73|      0|    }
   74|  2.79k|    spdm_context = spdm_test_context->spdm_context;
   75|       |
   76|  2.79k|    libspdm_init_context(spdm_context);
   77|       |
   78|  2.79k|    libspdm_register_device_io_func(spdm_context,
   79|  2.79k|                                    spdm_test_context->send_message,
   80|  2.79k|                                    spdm_test_context->receive_message);
   81|  2.79k|    libspdm_register_transport_layer_func(spdm_context,
   82|  2.79k|                                          LIBSPDM_MAX_SPDM_MSG_SIZE,
  ------------------
  |  |  101|  2.79k|#define LIBSPDM_MAX_SPDM_MSG_SIZE 0x1200
  ------------------
   83|  2.79k|                                          LIBSPDM_TEST_TRANSPORT_HEADER_SIZE,
  ------------------
  |  |   27|  2.79k|#define LIBSPDM_TEST_TRANSPORT_HEADER_SIZE  (2 + 8 + \
  |  |   28|  2.79k|                                             LIBSPDM_TEST_SEQUENCE_NUMBER_COUNT)
  |  |  ------------------
  |  |  |  |   16|  2.79k|#define LIBSPDM_TEST_SEQUENCE_NUMBER_COUNT 2
  |  |  ------------------
  ------------------
   84|  2.79k|                                          LIBSPDM_TEST_TRANSPORT_TAIL_SIZE,
  ------------------
  |  |   30|  2.79k|#define LIBSPDM_TEST_TRANSPORT_TAIL_SIZE    (LIBSPDM_TEST_MAX_RANDOM_NUMBER_COUNT + \
  |  |  ------------------
  |  |  |  |   17|  2.79k|#define LIBSPDM_TEST_MAX_RANDOM_NUMBER_COUNT 32
  |  |  ------------------
  |  |   31|  2.79k|                                             LIBSPDM_MAX_AEAD_TAG_SIZE + \
  |  |  ------------------
  |  |  |  |   75|  2.79k|#define LIBSPDM_MAX_AEAD_TAG_SIZE 16
  |  |  ------------------
  |  |   32|  2.79k|                                             (LIBSPDM_TEST_ALIGNMENT - 1))
  |  |  ------------------
  |  |  |  |   15|  2.79k|#define LIBSPDM_TEST_ALIGNMENT 4
  |  |  ------------------
  ------------------
   85|  2.79k|                                          libspdm_transport_test_encode_message,
   86|  2.79k|                                          libspdm_transport_test_decode_message);
   87|  2.79k|    libspdm_register_device_buffer_func(spdm_context,
   88|  2.79k|                                        LIBSPDM_MAX_SENDER_RECEIVER_BUFFER_SIZE,
  ------------------
  |  |   93|  2.79k|#define LIBSPDM_MAX_SENDER_RECEIVER_BUFFER_SIZE LIBSPDM_RECEIVER_BUFFER_SIZE
  |  |  ------------------
  |  |  |  |   78|  2.79k|#define LIBSPDM_RECEIVER_BUFFER_SIZE (0x1200 + \
  |  |  |  |   79|  2.79k|                                      LIBSPDM_TRANSPORT_ADDITIONAL_SIZE)
  |  |  |  |  ------------------
  |  |  |  |  |  |   70|  2.79k|#define LIBSPDM_TRANSPORT_ADDITIONAL_SIZE    (LIBSPDM_TEST_TRANSPORT_HEADER_SIZE + \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   27|  2.79k|#define LIBSPDM_TEST_TRANSPORT_HEADER_SIZE  (2 + 8 + \
  |  |  |  |  |  |  |  |   28|  2.79k|                                             LIBSPDM_TEST_SEQUENCE_NUMBER_COUNT)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   16|  2.79k|#define LIBSPDM_TEST_SEQUENCE_NUMBER_COUNT 2
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |   71|  2.79k|                                              LIBSPDM_TEST_TRANSPORT_TAIL_SIZE)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   30|  2.79k|#define LIBSPDM_TEST_TRANSPORT_TAIL_SIZE    (LIBSPDM_TEST_MAX_RANDOM_NUMBER_COUNT + \
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   17|  2.79k|#define LIBSPDM_TEST_MAX_RANDOM_NUMBER_COUNT 32
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|  2.79k|                                             LIBSPDM_MAX_AEAD_TAG_SIZE + \
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   75|  2.79k|#define LIBSPDM_MAX_AEAD_TAG_SIZE 16
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   32|  2.79k|                                             (LIBSPDM_TEST_ALIGNMENT - 1))
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   15|  2.79k|#define LIBSPDM_TEST_ALIGNMENT 4
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   89|  2.79k|                                        LIBSPDM_MAX_SENDER_RECEIVER_BUFFER_SIZE,
  ------------------
  |  |   93|  2.79k|#define LIBSPDM_MAX_SENDER_RECEIVER_BUFFER_SIZE LIBSPDM_RECEIVER_BUFFER_SIZE
  |  |  ------------------
  |  |  |  |   78|  2.79k|#define LIBSPDM_RECEIVER_BUFFER_SIZE (0x1200 + \
  |  |  |  |   79|  2.79k|                                      LIBSPDM_TRANSPORT_ADDITIONAL_SIZE)
  |  |  |  |  ------------------
  |  |  |  |  |  |   70|  2.79k|#define LIBSPDM_TRANSPORT_ADDITIONAL_SIZE    (LIBSPDM_TEST_TRANSPORT_HEADER_SIZE + \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   27|  2.79k|#define LIBSPDM_TEST_TRANSPORT_HEADER_SIZE  (2 + 8 + \
  |  |  |  |  |  |  |  |   28|  2.79k|                                             LIBSPDM_TEST_SEQUENCE_NUMBER_COUNT)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   16|  2.79k|#define LIBSPDM_TEST_SEQUENCE_NUMBER_COUNT 2
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |   71|  2.79k|                                              LIBSPDM_TEST_TRANSPORT_TAIL_SIZE)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   30|  2.79k|#define LIBSPDM_TEST_TRANSPORT_TAIL_SIZE    (LIBSPDM_TEST_MAX_RANDOM_NUMBER_COUNT + \
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   17|  2.79k|#define LIBSPDM_TEST_MAX_RANDOM_NUMBER_COUNT 32
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|  2.79k|                                             LIBSPDM_MAX_AEAD_TAG_SIZE + \
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   75|  2.79k|#define LIBSPDM_MAX_AEAD_TAG_SIZE 16
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   32|  2.79k|                                             (LIBSPDM_TEST_ALIGNMENT - 1))
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   15|  2.79k|#define LIBSPDM_TEST_ALIGNMENT 4
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   90|  2.79k|                                        spdm_device_acquire_sender_buffer,
   91|  2.79k|                                        spdm_device_release_sender_buffer,
   92|  2.79k|                                        spdm_device_acquire_receiver_buffer,
   93|  2.79k|                                        spdm_device_release_receiver_buffer);
   94|       |
   95|  2.79k|    spdm_test_context->scratch_buffer_size =
   96|  2.79k|        libspdm_get_sizeof_required_scratch_buffer(spdm_context);
   97|  2.79k|    spdm_test_context->scratch_buffer = (void *)malloc(spdm_test_context->scratch_buffer_size);
   98|  2.79k|    libspdm_set_scratch_buffer (spdm_context,
   99|  2.79k|                                spdm_test_context->scratch_buffer,
  100|  2.79k|                                spdm_test_context->scratch_buffer_size);
  101|       |
  102|  2.79k|    *State = spdm_test_context;
  103|  2.79k|    return 0;
  104|  2.79k|}
libspdm_unit_test_group_teardown:
  107|  2.79k|{
  108|  2.79k|    libspdm_test_context_t *spdm_test_context;
  109|       |
  110|  2.79k|    spdm_test_context = *State;
  111|  2.79k|    free(spdm_test_context->spdm_context);
  112|  2.79k|    free(spdm_test_context->scratch_buffer);
  113|  2.79k|    spdm_test_context->spdm_context = NULL;
  114|  2.79k|    return 0;
  115|  2.79k|}
libspdm_read_input_file:
  119|  2.79k|{
  120|  2.79k|    FILE *fp_in;
  121|  2.79k|    size_t temp_result;
  122|       |
  123|  2.79k|    if ((fp_in = fopen(file_name, "rb")) == NULL) {
  ------------------
  |  Branch (123:9): [True: 0, False: 2.79k]
  ------------------
  124|      0|        printf("Unable to open file %s\n", file_name);
  125|      0|        *file_data = NULL;
  126|      0|        return false;
  127|      0|    }
  128|       |
  129|  2.79k|    fseek(fp_in, 0, SEEK_END);
  130|  2.79k|    *file_size = ftell(fp_in);
  131|       |
  132|  2.79k|    *file_data = (void *)malloc(*file_size);
  133|  2.79k|    if (NULL == *file_data) {
  ------------------
  |  Branch (133:9): [True: 0, False: 2.79k]
  ------------------
  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|  2.79k|    fseek(fp_in, 0, SEEK_SET);
  140|  2.79k|    temp_result = fread(*file_data, 1, *file_size, fp_in);
  141|  2.79k|    if (temp_result != *file_size) {
  ------------------
  |  Branch (141:9): [True: 0, False: 2.79k]
  ------------------
  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|  2.79k|    fclose(fp_in);
  149|       |
  150|  2.79k|    return true;
  151|  2.79k|}
libspdm_dump_data:
  184|  88.0k|{
  185|  88.0k|    size_t index;
  186|       |
  187|  2.84M|    for (index = 0; index < buffer_size; index++) {
  ------------------
  |  Branch (187:21): [True: 2.75M, False: 88.0k]
  ------------------
  188|  2.75M|        printf("%02x ", buffer[index]);
  189|  2.75M|    }
  190|  88.0k|}
libspdm_dump_hex:
  193|  2.09k|{
  194|  2.09k|    size_t index;
  195|  2.09k|    size_t count;
  196|  2.09k|    size_t left;
  197|       |
  198|  2.09k|#define COLUME_SIZE (16 * 2)
  199|       |
  200|  2.09k|    count = size / COLUME_SIZE;
  ------------------
  |  |  198|  2.09k|#define COLUME_SIZE (16 * 2)
  ------------------
  201|  2.09k|    left = size % COLUME_SIZE;
  ------------------
  |  |  198|  2.09k|#define COLUME_SIZE (16 * 2)
  ------------------
  202|  88.0k|    for (index = 0; index < count; index++) {
  ------------------
  |  Branch (202:21): [True: 85.9k, False: 2.09k]
  ------------------
  203|  85.9k|        printf("%04x: ", (uint32_t)(index * COLUME_SIZE));
  ------------------
  |  |  198|  85.9k|#define COLUME_SIZE (16 * 2)
  ------------------
  204|  85.9k|        libspdm_dump_data(data + index * COLUME_SIZE, COLUME_SIZE);
  ------------------
  |  |  198|  85.9k|#define COLUME_SIZE (16 * 2)
  ------------------
                      libspdm_dump_data(data + index * COLUME_SIZE, COLUME_SIZE);
  ------------------
  |  |  198|  85.9k|#define COLUME_SIZE (16 * 2)
  ------------------
  205|  85.9k|        printf("\n");
  206|  85.9k|    }
  207|       |
  208|  2.09k|    if (left != 0) {
  ------------------
  |  Branch (208:9): [True: 2.09k, False: 0]
  ------------------
  209|  2.09k|        printf("%04x: ", (uint32_t)(index * COLUME_SIZE));
  ------------------
  |  |  198|  2.09k|#define COLUME_SIZE (16 * 2)
  ------------------
  210|  2.09k|        libspdm_dump_data(data + index * COLUME_SIZE, left);
  ------------------
  |  |  198|  2.09k|#define COLUME_SIZE (16 * 2)
  ------------------
  211|  2.09k|        printf("\n");
  212|  2.09k|    }
  213|  2.09k|}

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

libspdm_test_verify_spdm_cert_chain:
   21|    568|{
   22|    568|    return true;
   23|    568|}
libspdm_get_max_buffer_size:
   26|  1.39k|{
   27|  1.39k|    return LIBSPDM_MAX_SPDM_MSG_SIZE;
  ------------------
  |  |  101|  1.39k|#define LIBSPDM_MAX_SPDM_MSG_SIZE 0x1200
  ------------------
   28|  1.39k|}
libspdm_test_responder_encap_get_certificate_case1:
   36|    699|{
   37|    699|    libspdm_test_context_t *spdm_test_context;
   38|    699|    spdm_certificate_response_t *spdm_response;
   39|    699|    size_t spdm_response_size;
   40|    699|    bool need_continue;
   41|       |
   42|    699|    libspdm_context_t *spdm_context;
   43|    699|    void *data;
   44|    699|    size_t data_size;
   45|       |
   46|    699|    void *hash;
   47|    699|    size_t hash_size;
   48|    699|    const uint8_t *root_cert;
   49|    699|    size_t root_cert_size;
   50|       |
   51|    699|    spdm_test_context = *State;
   52|    699|    spdm_context = spdm_test_context->spdm_context;
   53|    699|    spdm_response_size = spdm_test_context->test_buffer_size;
   54|    699|    spdm_response = (spdm_certificate_response_t *)spdm_test_context->test_buffer;
   55|       |
   56|    699|    spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
  ------------------
  |  |  111|    699|#define SPDM_MESSAGE_VERSION_11 0x11
  ------------------
   57|    699|                                            SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    699|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
   58|    699|    spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_DIGESTS;
   59|    699|    spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
  ------------------
  |  |  234|    699|#define SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP 0x00000002
  ------------------
   60|    699|    libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
   61|    699|                                                    m_libspdm_use_req_asym_algo, &data,
   62|    699|                                                    &data_size,
   63|    699|                                                    &hash, &hash_size);
   64|    699|    libspdm_x509_get_cert_from_cert_chain((uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size,
   65|    699|                                          data_size - sizeof(spdm_cert_chain_t) - hash_size, 0,
   66|    699|                                          &root_cert,
   67|    699|                                          &root_cert_size);
   68|    699|    libspdm_dump_hex(root_cert, root_cert_size);
   69|    699|    spdm_context->local_context.peer_root_cert_provision_size[0] = root_cert_size;
   70|    699|    spdm_context->local_context.peer_root_cert_provision[0] = root_cert;
   71|    699|    spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
   72|    699|    spdm_context->connection_info.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
   73|    699|    libspdm_reset_message_b(spdm_context);
   74|       |
   75|    699|    libspdm_register_cert_chain_buffer(spdm_context, m_cert_chain_buffer,
   76|    699|                                       sizeof(m_cert_chain_buffer));
   77|       |
   78|    699|    libspdm_copy_mem(m_cert_chain_buffer, sizeof(m_cert_chain_buffer), data, data_size);
   79|    699|    spdm_context->mut_auth_cert_chain_buffer_size = data_size;
   80|       |
   81|    699|    uint16_t cert_chain_total_len =
   82|    699|        (uint16_t)spdm_context->mut_auth_cert_chain_buffer_size +
   83|    699|        spdm_response->portion_length + spdm_response->remainder_length;
   84|    699|    spdm_context->encap_context.cert_chain_total_len = cert_chain_total_len;
   85|       |
   86|    699|    libspdm_process_encap_response_certificate(spdm_context, spdm_response_size, spdm_response,
   87|    699|                                               &need_continue);
   88|    699|    libspdm_reset_message_mut_b(spdm_context);
   89|    699|    free(data);
   90|       |    #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
   91|       |#else
   92|    699|    libspdm_asym_free(spdm_context->connection_info.algorithm.req_base_asym_alg,
   93|    699|                      spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
   94|    699|#endif
   95|    699|}
libspdm_test_responder_encap_get_certificate_case2:
   98|    699|{
   99|    699|    libspdm_test_context_t *spdm_test_context;
  100|    699|    spdm_certificate_response_t *spdm_response;
  101|    699|    size_t spdm_response_size;
  102|    699|    bool need_continue;
  103|       |
  104|    699|    libspdm_context_t *spdm_context;
  105|    699|    void *data;
  106|    699|    size_t data_size;
  107|       |
  108|    699|    void *hash;
  109|    699|    size_t hash_size;
  110|    699|    const uint8_t *root_cert;
  111|    699|    size_t root_cert_size;
  112|       |
  113|    699|    spdm_test_context = *State;
  114|    699|    spdm_context = spdm_test_context->spdm_context;
  115|    699|    spdm_response_size = spdm_test_context->test_buffer_size;
  116|    699|    spdm_response = (spdm_certificate_response_t *)spdm_test_context->test_buffer;
  117|    699|    spdm_response->remainder_length = 0;
  118|    699|    spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
  ------------------
  |  |  111|    699|#define SPDM_MESSAGE_VERSION_11 0x11
  ------------------
  119|    699|                                            SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    699|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
  120|    699|    spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_DIGESTS;
  121|    699|    spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
  ------------------
  |  |  234|    699|#define SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP 0x00000002
  ------------------
  122|       |
  123|       |
  124|    699|    libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
  125|    699|                                                    m_libspdm_use_req_asym_algo, &data,
  126|    699|                                                    &data_size,
  127|    699|                                                    &hash, &hash_size);
  128|    699|    libspdm_x509_get_cert_from_cert_chain((uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size,
  129|    699|                                          data_size - sizeof(spdm_cert_chain_t) - hash_size, 0,
  130|    699|                                          &root_cert,
  131|    699|                                          &root_cert_size);
  132|    699|    libspdm_dump_hex(root_cert, root_cert_size);
  133|    699|    spdm_context->local_context.peer_root_cert_provision_size[0] = root_cert_size;
  134|    699|    spdm_context->local_context.peer_root_cert_provision[0] = root_cert;
  135|    699|    spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
  136|    699|    spdm_context->connection_info.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
  137|       |
  138|       |#if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
  139|       |    if(data_size > LIBSPDM_MAX_CERT_CHAIN_SIZE ||
  140|       |       spdm_response->portion_length + data_size > LIBSPDM_MAX_CERT_CHAIN_SIZE) {
  141|       |        data_size = LIBSPDM_MAX_CERT_CHAIN_SIZE - spdm_response->portion_length;
  142|       |    }
  143|       |#endif
  144|    699|    libspdm_register_cert_chain_buffer(spdm_context, m_cert_chain_buffer,
  145|    699|                                       sizeof(m_cert_chain_buffer));
  146|       |
  147|    699|    libspdm_copy_mem(m_cert_chain_buffer, sizeof(m_cert_chain_buffer), data, data_size);
  148|    699|    spdm_context->mut_auth_cert_chain_buffer_size = data_size;
  149|       |
  150|    699|    uint16_t cert_chain_total_len =
  151|    699|        (uint16_t)spdm_context->mut_auth_cert_chain_buffer_size +
  152|    699|        spdm_response->portion_length + spdm_response->remainder_length;
  153|    699|    spdm_context->encap_context.cert_chain_total_len = cert_chain_total_len;
  154|       |
  155|    699|    libspdm_process_encap_response_certificate(spdm_context, spdm_response_size, spdm_response,
  156|    699|                                               &need_continue);
  157|       |
  158|    699|    libspdm_reset_message_mut_b(spdm_context);
  159|    699|    free(data);
  160|       |    #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
  161|       |#else
  162|    699|    libspdm_asym_free(spdm_context->connection_info.algorithm.req_base_asym_alg,
  163|    699|                      spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
  164|    699|#endif
  165|    699|}
libspdm_test_responder_encap_get_certificate_case3:
  168|    699|{
  169|    699|    libspdm_test_context_t *spdm_test_context;
  170|    699|    spdm_certificate_response_t *spdm_response;
  171|    699|    size_t spdm_response_size;
  172|    699|    bool need_continue;
  173|       |
  174|    699|    libspdm_context_t *spdm_context;
  175|    699|    void *data;
  176|    699|    size_t data_size;
  177|       |
  178|    699|    void *hash;
  179|    699|    size_t hash_size;
  180|    699|    const uint8_t *root_cert;
  181|    699|    size_t root_cert_size;
  182|       |
  183|    699|    spdm_test_context = *State;
  184|    699|    spdm_context = spdm_test_context->spdm_context;
  185|    699|    spdm_response_size = spdm_test_context->test_buffer_size;
  186|    699|    spdm_response = (spdm_certificate_response_t *)spdm_test_context->test_buffer;
  187|    699|    spdm_response->remainder_length = 0;
  188|    699|    spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
  ------------------
  |  |  111|    699|#define SPDM_MESSAGE_VERSION_11 0x11
  ------------------
  189|    699|                                            SPDM_VERSION_NUMBER_SHIFT_BIT;
  ------------------
  |  |  140|    699|#define SPDM_VERSION_NUMBER_SHIFT_BIT 8
  ------------------
  190|    699|    spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_DIGESTS;
  191|    699|    spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
  ------------------
  |  |  234|    699|#define SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP 0x00000002
  ------------------
  192|    699|    libspdm_register_verify_spdm_cert_chain_func (spdm_context,
  193|    699|                                                  libspdm_test_verify_spdm_cert_chain);
  194|       |
  195|    699|    libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
  196|    699|                                                    m_libspdm_use_req_asym_algo, &data,
  197|    699|                                                    &data_size,
  198|    699|                                                    &hash, &hash_size);
  199|    699|    libspdm_x509_get_cert_from_cert_chain((uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size,
  200|    699|                                          data_size - sizeof(spdm_cert_chain_t) - hash_size, 0,
  201|    699|                                          &root_cert,
  202|    699|                                          &root_cert_size);
  203|    699|    libspdm_dump_hex(root_cert, root_cert_size);
  204|    699|    spdm_context->local_context.peer_root_cert_provision_size[0] = root_cert_size;
  205|    699|    spdm_context->local_context.peer_root_cert_provision[0] = root_cert;
  206|    699|    spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
  207|    699|    spdm_context->connection_info.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
  208|       |#if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
  209|       |    if(data_size > LIBSPDM_MAX_CERT_CHAIN_SIZE ||
  210|       |       spdm_response->portion_length + data_size > LIBSPDM_MAX_CERT_CHAIN_SIZE) {
  211|       |        data_size = LIBSPDM_MAX_CERT_CHAIN_SIZE - spdm_response->portion_length;
  212|       |    }
  213|       |#endif
  214|    699|    libspdm_register_cert_chain_buffer(spdm_context, m_cert_chain_buffer,
  215|    699|                                       sizeof(m_cert_chain_buffer));
  216|       |
  217|    699|    libspdm_copy_mem(m_cert_chain_buffer, sizeof(m_cert_chain_buffer), data, data_size);
  218|    699|    spdm_context->mut_auth_cert_chain_buffer_size = data_size;
  219|       |
  220|    699|    uint16_t cert_chain_total_len =
  221|    699|        (uint16_t)spdm_context->mut_auth_cert_chain_buffer_size +
  222|    699|        spdm_response->portion_length + spdm_response->remainder_length;
  223|    699|    spdm_context->encap_context.cert_chain_total_len = cert_chain_total_len;
  224|       |
  225|    699|    libspdm_process_encap_response_certificate(spdm_context, spdm_response_size, spdm_response,
  226|    699|                                               &need_continue);
  227|       |
  228|    699|    libspdm_reset_message_mut_b(spdm_context);
  229|    699|    free(data);
  230|       |#if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
  231|       |#else
  232|    699|    libspdm_asym_free(spdm_context->connection_info.algorithm.req_base_asym_alg,
  233|    699|                      spdm_context->connection_info.peer_used_cert_chain[0].leaf_cert_public_key);
  234|    699|#endif
  235|    699|}
libspdm_test_get_encap_request_get_certificate_case2:
  238|    699|{
  239|    699|    libspdm_test_context_t *spdm_test_context;
  240|    699|    libspdm_context_t *spdm_context;
  241|    699|    size_t encap_request_size;
  242|    699|    void *data;
  243|    699|    size_t data_size;
  244|       |
  245|    699|    spdm_get_certificate_request_t *spdm_request;
  246|       |
  247|    699|    spdm_test_context = *State;
  248|    699|    spdm_context = spdm_test_context->spdm_context;
  249|    699|    encap_request_size = spdm_test_context->test_buffer_size;
  250|       |
  251|    699|    if (encap_request_size < sizeof(spdm_get_certificate_request_t)) {
  ------------------
  |  Branch (251:9): [True: 32, False: 667]
  ------------------
  252|     32|        encap_request_size = sizeof(spdm_get_certificate_request_t);
  253|     32|    }
  254|       |
  255|    699|    spdm_request = malloc(encap_request_size);
  256|       |
  257|    699|    spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
  258|    699|    spdm_context->connection_info.capability.flags = 0;
  259|    699|    spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP;
  ------------------
  |  |  185|    699|#define SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP 0x00000002
  ------------------
  260|    699|    libspdm_read_responder_public_certificate_chain(m_libspdm_use_hash_algo,
  261|    699|                                                    m_libspdm_use_asym_algo, &data,
  262|    699|                                                    &data_size,
  263|    699|                                                    NULL, NULL);
  264|    699|    spdm_context->local_context.local_cert_chain_provision_size[0] = data_size;
  265|    699|    spdm_context->local_context.local_cert_chain_provision[0] = data;
  266|    699|    spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
  267|    699|    spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
  268|    699|    libspdm_reset_message_b(spdm_context);
  269|       |
  270|    699|    libspdm_get_encap_request_get_certificate(spdm_context, &encap_request_size,
  271|    699|                                              spdm_request);
  272|    699|    libspdm_reset_message_mut_b(spdm_context);
  273|    699|    free(spdm_request);
  274|    699|    free(data);
  275|    699|}
libspdm_run_test_harness:
  278|    699|{
  279|    699|    void *State;
  280|       |
  281|    699|    libspdm_setup_test_context(&m_libspdm_responder_encap_get_certificate_test_context);
  282|       |
  283|    699|    m_libspdm_responder_encap_get_certificate_test_context.test_buffer = test_buffer;
  284|    699|    m_libspdm_responder_encap_get_certificate_test_context.test_buffer_size = test_buffer_size;
  285|       |
  286|       |    /* Success Case */
  287|    699|    libspdm_unit_test_group_setup(&State);
  288|    699|    libspdm_test_responder_encap_get_certificate_case1(&State);
  289|    699|    libspdm_unit_test_group_teardown(&State);
  290|       |
  291|       |    /* Force spdm_response->remainder_length to zero
  292|       |     * It is convenient for fuzzy testing and testing other branches*/
  293|    699|    libspdm_unit_test_group_setup(&State);
  294|    699|    libspdm_test_responder_encap_get_certificate_case2(&State);
  295|    699|    libspdm_unit_test_group_teardown(&State);
  296|       |
  297|       |    /* Use Peer Cert verify*/
  298|    699|    libspdm_unit_test_group_setup(&State);
  299|    699|    libspdm_test_responder_encap_get_certificate_case3(&State);
  300|    699|    libspdm_unit_test_group_teardown(&State);
  301|       |
  302|       |    /* Success Case */
  303|    699|    libspdm_unit_test_group_setup(&State);
  304|    699|    libspdm_test_get_encap_request_get_certificate_case2(&State);
  305|    699|    libspdm_unit_test_group_teardown(&State);
  306|    699|}

