psa_crypto.c:psa_driver_wrapper_free:
   97|     21|{
   98|     21|#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
   99|       |    /* Unregister all secure element drivers, so that we restart from
  100|       |     * a pristine state. */
  101|     21|    psa_unregister_all_se_drivers( );
  102|     21|#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
  103|       |
  104|       |#if defined(PSA_CRYPTO_DRIVER_TEST)
  105|       |    mbedtls_test_transparent_free( );
  106|       |    mbedtls_test_opaque_free( );
  107|       |#endif
  108|     21|}
psa_crypto.c:psa_driver_wrapper_init:
   73|     21|{
   74|     21|    psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  231|     21|#define PSA_ERROR_CORRUPTION_DETECTED    ((psa_status_t)-151)
  ------------------
   75|       |
   76|     21|#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
   77|     21|    status = psa_init_all_se_drivers( );
   78|     21|    if( status != PSA_SUCCESS )
  ------------------
  |  |   57|     21|#define PSA_SUCCESS ((psa_status_t)0)
  ------------------
  |  Branch (78:9): [True: 0, False: 21]
  ------------------
   79|      0|        return( status );
   80|     21|#endif
   81|       |
   82|       |#if defined(PSA_CRYPTO_DRIVER_TEST)
   83|       |    status = mbedtls_test_transparent_init( );
   84|       |    if( status != PSA_SUCCESS )
   85|       |        return( status );
   86|       |
   87|       |    status = mbedtls_test_opaque_init( );
   88|       |    if( status != PSA_SUCCESS )
   89|       |        return( status );
   90|       |#endif
   91|       |
   92|     21|    (void) status;
   93|     21|    return( PSA_SUCCESS );
  ------------------
  |  |   57|     21|#define PSA_SUCCESS ((psa_status_t)0)
  ------------------
   94|     21|}

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

pkparse.c:mbedtls_pk_rsa:
 1038|      2|{
 1039|      2|    switch (mbedtls_pk_get_type(&pk)) {
 1040|      2|        case MBEDTLS_PK_RSA:
  ------------------
  |  Branch (1040:9): [True: 2, False: 0]
  ------------------
 1041|      2|            return (mbedtls_rsa_context *) (pk).MBEDTLS_PRIVATE(pk_ctx);
  ------------------
  |  |   17|      2|#define MBEDTLS_PRIVATE(member) member
  ------------------
 1042|      0|        default:
  ------------------
  |  Branch (1042:9): [True: 0, False: 2]
  ------------------
 1043|      0|            return NULL;
 1044|      2|    }
 1045|      2|}

ssl_tls.c:mbedtls_svc_key_id_is_null:
 2475|     21|{
 2476|     21|    return key == 0;
 2477|     21|}

mbedtls_aes_init:
  493|     42|{
  494|     42|    memset(ctx, 0, sizeof(mbedtls_aes_context));
  495|     42|}
mbedtls_aes_free:
  498|     42|{
  499|     42|    if (ctx == NULL) {
  ------------------
  |  Branch (499:9): [True: 0, False: 42]
  ------------------
  500|      0|        return;
  501|      0|    }
  502|       |
  503|     42|    mbedtls_platform_zeroize(ctx, sizeof(mbedtls_aes_context));
  504|     42|}
mbedtls_aes_setkey_enc:
  578|     21|{
  579|     21|    uint32_t *RK;
  580|       |
  581|     21|    switch (keybits) {
  582|      0|        case 128: ctx->nr = 10; break;
  ------------------
  |  Branch (582:9): [True: 0, False: 21]
  ------------------
  583|      0|#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
  584|      0|        case 192: ctx->nr = 12; break;
  ------------------
  |  Branch (584:9): [True: 0, False: 21]
  ------------------
  585|     21|        case 256: ctx->nr = 14; break;
  ------------------
  |  Branch (585:9): [True: 21, False: 0]
  ------------------
  586|      0|#endif /* !MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
  587|      0|        default: return MBEDTLS_ERR_AES_INVALID_KEY_LENGTH;
  ------------------
  |  |   44|      0|#define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH                -0x0020
  ------------------
  |  Branch (587:9): [True: 0, False: 21]
  ------------------
  588|     21|    }
  589|       |
  590|       |#if !defined(MBEDTLS_AES_ROM_TABLES)
  591|       |    if (aes_init_done == 0) {
  592|       |        aes_gen_tables();
  593|       |        aes_init_done = 1;
  594|       |    }
  595|       |#endif
  596|       |
  597|     21|    ctx->rk_offset = mbedtls_aes_rk_offset(ctx->buf);
  598|     21|    RK = ctx->buf + ctx->rk_offset;
  599|       |
  600|     21|#if defined(MBEDTLS_AESNI_HAVE_CODE)
  601|     21|    if (mbedtls_aesni_has_support(MBEDTLS_AESNI_AES)) {
  ------------------
  |  |   20|     21|#define MBEDTLS_AESNI_AES      0x02000000u
  ------------------
  |  Branch (601:9): [True: 21, False: 0]
  ------------------
  602|     21|        return mbedtls_aesni_setkey_enc((unsigned char *) RK, key, keybits);
  603|     21|    }
  604|      0|#endif
  605|       |
  606|       |#if defined(MBEDTLS_AESCE_HAVE_CODE)
  607|       |    if (MBEDTLS_AESCE_HAS_SUPPORT()) {
  608|       |        return mbedtls_aesce_setkey_enc((unsigned char *) RK, key, keybits);
  609|       |    }
  610|       |#endif
  611|       |
  612|      0|#if !defined(MBEDTLS_AES_USE_HARDWARE_ONLY)
  613|      0|    for (unsigned int i = 0; i < (keybits >> 5); i++) {
  ------------------
  |  Branch (613:30): [True: 0, False: 0]
  ------------------
  614|      0|        RK[i] = MBEDTLS_GET_UINT32_LE(key, i << 2);
  ------------------
  |  |  449|      0|    ((MBEDTLS_IS_BIG_ENDIAN)                                               \
  |  |  ------------------
  |  |  |  |  398|      0|#define MBEDTLS_IS_BIG_ENDIAN 0
  |  |  ------------------
  |  |  |  Branch (449:6): [Folded - Ignored]
  |  |  ------------------
  |  |  450|      0|        ? MBEDTLS_BSWAP32(mbedtls_get_unaligned_uint32((data) + (offset))) \
  |  |  ------------------
  |  |  |  |  298|      0|#define MBEDTLS_BSWAP32 __builtin_bswap32
  |  |  ------------------
  |  |  451|      0|        : mbedtls_get_unaligned_uint32((data) + (offset))                  \
  |  |  452|      0|    )
  ------------------
  615|      0|    }
  616|       |
  617|      0|    switch (ctx->nr) {
  ------------------
  |  Branch (617:13): [True: 0, False: 0]
  ------------------
  618|      0|        case 10:
  ------------------
  |  Branch (618:9): [True: 0, False: 0]
  ------------------
  619|       |
  620|      0|            for (unsigned int i = 0; i < 10; i++, RK += 4) {
  ------------------
  |  Branch (620:38): [True: 0, False: 0]
  ------------------
  621|      0|                RK[4]  = RK[0] ^ round_constants[i] ^
  622|      0|                         ((uint32_t) FSb[MBEDTLS_BYTE_1(RK[3])]) ^
  ------------------
  |  |  269|      0|#define MBEDTLS_BYTE_1(x) ((uint8_t) (((x) >>  8) & 0xff))
  ------------------
  623|      0|                         ((uint32_t) FSb[MBEDTLS_BYTE_2(RK[3])] <<  8) ^
  ------------------
  |  |  270|      0|#define MBEDTLS_BYTE_2(x) ((uint8_t) (((x) >> 16) & 0xff))
  ------------------
  624|      0|                         ((uint32_t) FSb[MBEDTLS_BYTE_3(RK[3])] << 16) ^
  ------------------
  |  |  271|      0|#define MBEDTLS_BYTE_3(x) ((uint8_t) (((x) >> 24) & 0xff))
  ------------------
  625|      0|                         ((uint32_t) FSb[MBEDTLS_BYTE_0(RK[3])] << 24);
  ------------------
  |  |  268|      0|#define MBEDTLS_BYTE_0(x) ((uint8_t) ((x)         & 0xff))
  ------------------
  626|       |
  627|      0|                RK[5]  = RK[1] ^ RK[4];
  628|      0|                RK[6]  = RK[2] ^ RK[5];
  629|      0|                RK[7]  = RK[3] ^ RK[6];
  630|      0|            }
  631|      0|            break;
  632|       |
  633|      0|#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
  634|      0|        case 12:
  ------------------
  |  Branch (634:9): [True: 0, False: 0]
  ------------------
  635|       |
  636|      0|            for (unsigned int i = 0; i < 8; i++, RK += 6) {
  ------------------
  |  Branch (636:38): [True: 0, False: 0]
  ------------------
  637|      0|                RK[6]  = RK[0] ^ round_constants[i] ^
  638|      0|                         ((uint32_t) FSb[MBEDTLS_BYTE_1(RK[5])]) ^
  ------------------
  |  |  269|      0|#define MBEDTLS_BYTE_1(x) ((uint8_t) (((x) >>  8) & 0xff))
  ------------------
  639|      0|                         ((uint32_t) FSb[MBEDTLS_BYTE_2(RK[5])] <<  8) ^
  ------------------
  |  |  270|      0|#define MBEDTLS_BYTE_2(x) ((uint8_t) (((x) >> 16) & 0xff))
  ------------------
  640|      0|                         ((uint32_t) FSb[MBEDTLS_BYTE_3(RK[5])] << 16) ^
  ------------------
  |  |  271|      0|#define MBEDTLS_BYTE_3(x) ((uint8_t) (((x) >> 24) & 0xff))
  ------------------
  641|      0|                         ((uint32_t) FSb[MBEDTLS_BYTE_0(RK[5])] << 24);
  ------------------
  |  |  268|      0|#define MBEDTLS_BYTE_0(x) ((uint8_t) ((x)         & 0xff))
  ------------------
  642|       |
  643|      0|                RK[7]  = RK[1] ^ RK[6];
  644|      0|                RK[8]  = RK[2] ^ RK[7];
  645|      0|                RK[9]  = RK[3] ^ RK[8];
  646|      0|                RK[10] = RK[4] ^ RK[9];
  647|      0|                RK[11] = RK[5] ^ RK[10];
  648|      0|            }
  649|      0|            break;
  650|       |
  651|      0|        case 14:
  ------------------
  |  Branch (651:9): [True: 0, False: 0]
  ------------------
  652|       |
  653|      0|            for (unsigned int i = 0; i < 7; i++, RK += 8) {
  ------------------
  |  Branch (653:38): [True: 0, False: 0]
  ------------------
  654|      0|                RK[8]  = RK[0] ^ round_constants[i] ^
  655|      0|                         ((uint32_t) FSb[MBEDTLS_BYTE_1(RK[7])]) ^
  ------------------
  |  |  269|      0|#define MBEDTLS_BYTE_1(x) ((uint8_t) (((x) >>  8) & 0xff))
  ------------------
  656|      0|                         ((uint32_t) FSb[MBEDTLS_BYTE_2(RK[7])] <<  8) ^
  ------------------
  |  |  270|      0|#define MBEDTLS_BYTE_2(x) ((uint8_t) (((x) >> 16) & 0xff))
  ------------------
  657|      0|                         ((uint32_t) FSb[MBEDTLS_BYTE_3(RK[7])] << 16) ^
  ------------------
  |  |  271|      0|#define MBEDTLS_BYTE_3(x) ((uint8_t) (((x) >> 24) & 0xff))
  ------------------
  658|      0|                         ((uint32_t) FSb[MBEDTLS_BYTE_0(RK[7])] << 24);
  ------------------
  |  |  268|      0|#define MBEDTLS_BYTE_0(x) ((uint8_t) ((x)         & 0xff))
  ------------------
  659|       |
  660|      0|                RK[9]  = RK[1] ^ RK[8];
  661|      0|                RK[10] = RK[2] ^ RK[9];
  662|      0|                RK[11] = RK[3] ^ RK[10];
  663|       |
  664|      0|                RK[12] = RK[4] ^
  665|      0|                         ((uint32_t) FSb[MBEDTLS_BYTE_0(RK[11])]) ^
  ------------------
  |  |  268|      0|#define MBEDTLS_BYTE_0(x) ((uint8_t) ((x)         & 0xff))
  ------------------
  666|      0|                         ((uint32_t) FSb[MBEDTLS_BYTE_1(RK[11])] <<  8) ^
  ------------------
  |  |  269|      0|#define MBEDTLS_BYTE_1(x) ((uint8_t) (((x) >>  8) & 0xff))
  ------------------
  667|      0|                         ((uint32_t) FSb[MBEDTLS_BYTE_2(RK[11])] << 16) ^
  ------------------
  |  |  270|      0|#define MBEDTLS_BYTE_2(x) ((uint8_t) (((x) >> 16) & 0xff))
  ------------------
  668|      0|                         ((uint32_t) FSb[MBEDTLS_BYTE_3(RK[11])] << 24);
  ------------------
  |  |  271|      0|#define MBEDTLS_BYTE_3(x) ((uint8_t) (((x) >> 24) & 0xff))
  ------------------
  669|       |
  670|      0|                RK[13] = RK[5] ^ RK[12];
  671|      0|                RK[14] = RK[6] ^ RK[13];
  672|      0|                RK[15] = RK[7] ^ RK[14];
  673|      0|            }
  674|      0|            break;
  675|      0|#endif /* !MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
  676|      0|    }
  677|       |
  678|      0|    return 0;
  679|      0|#endif /* !MBEDTLS_AES_USE_HARDWARE_ONLY */
  680|      0|}
aes.c:mbedtls_aes_rk_offset:
  536|     21|{
  537|       |#if defined(MAY_NEED_TO_ALIGN)
  538|       |    int align_16_bytes = 0;
  539|       |
  540|       |#if defined(MBEDTLS_VIA_PADLOCK_HAVE_CODE)
  541|       |    if (aes_padlock_ace == -1) {
  542|       |        aes_padlock_ace = mbedtls_padlock_has_support(MBEDTLS_PADLOCK_ACE);
  543|       |    }
  544|       |    if (aes_padlock_ace) {
  545|       |        align_16_bytes = 1;
  546|       |    }
  547|       |#endif
  548|       |
  549|       |#if defined(MBEDTLS_AESNI_C) && MBEDTLS_AESNI_HAVE_CODE == 2
  550|       |    if (mbedtls_aesni_has_support(MBEDTLS_AESNI_AES)) {
  551|       |        align_16_bytes = 1;
  552|       |    }
  553|       |#endif
  554|       |
  555|       |    if (align_16_bytes) {
  556|       |        /* These implementations needs 16-byte alignment
  557|       |         * for the round key array. */
  558|       |        unsigned delta = ((uintptr_t) buf & 0x0000000fU) / 4;
  559|       |        if (delta == 0) {
  560|       |            return 0;
  561|       |        } else {
  562|       |            return 4 - delta; // 16 bytes = 4 uint32_t
  563|       |        }
  564|       |    }
  565|       |#else /* MAY_NEED_TO_ALIGN */
  566|     21|    (void) buf;
  567|     21|#endif /* MAY_NEED_TO_ALIGN */
  568|       |
  569|     21|    return 0;
  570|     21|}

mbedtls_aesni_has_support:
   50|     21|{
   51|     21|    static int done = 0;
   52|     21|    static unsigned int c = 0;
   53|       |
   54|     21|    if (!done) {
  ------------------
  |  Branch (54:9): [True: 1, False: 20]
  ------------------
   55|       |#if MBEDTLS_AESNI_HAVE_CODE == 2
   56|       |        static int info[4] = { 0, 0, 0, 0 };
   57|       |#if defined(_MSC_VER)
   58|       |        __cpuid(info, 1);
   59|       |#else
   60|       |        __cpuid(1, info[0], info[1], info[2], info[3]);
   61|       |#endif
   62|       |        c = info[2];
   63|       |#else /* AESNI using asm */
   64|      1|        asm ("movl  $1, %%eax   \n\t"
  ------------------
  |  |  321|      1|#define asm __asm__
  ------------------
   65|      1|             "cpuid             \n\t"
   66|      1|             : "=c" (c)
   67|      1|             :
   68|      1|             : "eax", "ebx", "edx");
   69|      1|#endif /* MBEDTLS_AESNI_HAVE_CODE */
   70|      1|        done = 1;
   71|      1|    }
   72|       |
   73|     21|    return (c & what) != 0;
   74|     21|}
mbedtls_aesni_setkey_enc:
  820|     21|{
  821|     21|    switch (bits) {
  822|      0|        case 128: aesni_setkey_enc_128(rk, key); break;
  ------------------
  |  Branch (822:9): [True: 0, False: 21]
  ------------------
  823|      0|#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
  824|      0|        case 192: aesni_setkey_enc_192(rk, key); break;
  ------------------
  |  Branch (824:9): [True: 0, False: 21]
  ------------------
  825|     21|        case 256: aesni_setkey_enc_256(rk, key); break;
  ------------------
  |  Branch (825:9): [True: 21, False: 0]
  ------------------
  826|      0|#endif /* !MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
  827|      0|        default: return MBEDTLS_ERR_AES_INVALID_KEY_LENGTH;
  ------------------
  |  |   44|      0|#define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH                -0x0020
  ------------------
  |  Branch (827:9): [True: 0, False: 21]
  ------------------
  828|     21|    }
  829|       |
  830|     21|    return 0;
  831|     21|}
aesni.c:aesni_setkey_enc_256:
  750|     21|{
  751|     21|    asm ("movdqu (%1), %%xmm0           \n\t"
  ------------------
  |  |  321|     21|#define asm __asm__
  ------------------
  752|     21|         "movdqu %%xmm0, (%0)           \n\t"
  753|     21|         "add $16, %0                   \n\t"
  754|     21|         "movdqu 16(%1), %%xmm1         \n\t"
  755|     21|         "movdqu %%xmm1, (%0)           \n\t"
  756|     21|         "jmp 2f                        \n\t" // skip auxiliary routine
  757|       |
  758|       |         /*
  759|       |          * Finish generating the next two round keys.
  760|       |          *
  761|       |          * On entry xmm0 is r3:r2:r1:r0, xmm1 is r7:r6:r5:r4 and
  762|       |          * xmm2 is X:stuff:stuff:stuff with X = rot( sub( r7 )) ^ RCON
  763|       |          *
  764|       |          * On exit, xmm0 is r11:r10:r9:r8 and xmm1 is r15:r14:r13:r12
  765|       |          * and those have been written to the output buffer.
  766|       |          */
  767|     21|         "1:                                \n\t"
  768|     21|         "pshufd $0xff, %%xmm2, %%xmm2      \n\t"
  769|     21|         "pxor %%xmm0, %%xmm2               \n\t"
  770|     21|         "pslldq $4, %%xmm0                 \n\t"
  771|     21|         "pxor %%xmm0, %%xmm2               \n\t"
  772|     21|         "pslldq $4, %%xmm0                 \n\t"
  773|     21|         "pxor %%xmm0, %%xmm2               \n\t"
  774|     21|         "pslldq $4, %%xmm0                 \n\t"
  775|     21|         "pxor %%xmm2, %%xmm0               \n\t"
  776|     21|         "add $16, %0                       \n\t"
  777|     21|         "movdqu %%xmm0, (%0)               \n\t"
  778|       |
  779|       |         /* Set xmm2 to stuff:Y:stuff:stuff with Y = subword( r11 )
  780|       |          * and proceed to generate next round key from there */
  781|     21|         AESKEYGENA(xmm0_xmm2, "0x00")
  782|     21|         "pshufd $0xaa, %%xmm2, %%xmm2      \n\t"
  783|     21|         "pxor %%xmm1, %%xmm2               \n\t"
  784|     21|         "pslldq $4, %%xmm1                 \n\t"
  785|     21|         "pxor %%xmm1, %%xmm2               \n\t"
  786|     21|         "pslldq $4, %%xmm1                 \n\t"
  787|     21|         "pxor %%xmm1, %%xmm2               \n\t"
  788|     21|         "pslldq $4, %%xmm1                 \n\t"
  789|     21|         "pxor %%xmm2, %%xmm1               \n\t"
  790|     21|         "add $16, %0                       \n\t"
  791|     21|         "movdqu %%xmm1, (%0)               \n\t"
  792|     21|         "ret                               \n\t"
  793|       |
  794|       |         /*
  795|       |          * Main "loop" - Generating one more key than necessary,
  796|       |          * see definition of mbedtls_aes_context.buf
  797|       |          */
  798|     21|         "2:                                \n\t"
  799|     21|         AESKEYGENA(xmm1_xmm2, "0x01")      "call 1b \n\t"
  800|     21|         AESKEYGENA(xmm1_xmm2, "0x02")      "call 1b \n\t"
  801|     21|         AESKEYGENA(xmm1_xmm2, "0x04")      "call 1b \n\t"
  802|     21|         AESKEYGENA(xmm1_xmm2, "0x08")      "call 1b \n\t"
  803|     21|         AESKEYGENA(xmm1_xmm2, "0x10")      "call 1b \n\t"
  804|     21|         AESKEYGENA(xmm1_xmm2, "0x20")      "call 1b \n\t"
  805|     21|         AESKEYGENA(xmm1_xmm2, "0x40")      "call 1b \n\t"
  806|     21|         :
  807|     21|         : "r" (rk), "r" (key)
  808|     21|         : "memory", "cc", "xmm0", "xmm1", "xmm2", "0");
  809|     21|}

sha512.c:mbedtls_get_unaligned_uint64:
  220|    672|{
  221|    672|    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|    672|    memcpy(&r, p, sizeof(r));
  230|    672|#endif
  231|    672|    return r;
  232|    672|}
sha512.c:mbedtls_put_unaligned_uint64:
  247|    210|{
  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|    210|    memcpy(p, &x, sizeof(x));
  256|    210|#endif
  257|    210|}

mbedtls_asn1_get_len:
   31|    193|{
   32|    193|    if ((end - *p) < 1) {
  ------------------
  |  Branch (32:9): [True: 0, False: 193]
  ------------------
   33|      0|        return MBEDTLS_ERR_ASN1_OUT_OF_DATA;
  ------------------
  |  |   37|      0|#define MBEDTLS_ERR_ASN1_OUT_OF_DATA                      -0x0060
  ------------------
   34|      0|    }
   35|       |
   36|    193|    if ((**p & 0x80) == 0) {
  ------------------
  |  Branch (36:9): [True: 177, False: 16]
  ------------------
   37|    177|        *len = *(*p)++;
   38|    177|    } else {
   39|     16|        int n = (**p) & 0x7F;
   40|     16|        if (n == 0 || n > 4) {
  ------------------
  |  Branch (40:13): [True: 0, False: 16]
  |  Branch (40:23): [True: 0, False: 16]
  ------------------
   41|      0|            return MBEDTLS_ERR_ASN1_INVALID_LENGTH;
  ------------------
  |  |   41|      0|#define MBEDTLS_ERR_ASN1_INVALID_LENGTH                   -0x0064
  ------------------
   42|      0|        }
   43|     16|        if ((end - *p) <= n) {
  ------------------
  |  Branch (43:13): [True: 0, False: 16]
  ------------------
   44|      0|            return MBEDTLS_ERR_ASN1_OUT_OF_DATA;
  ------------------
  |  |   37|      0|#define MBEDTLS_ERR_ASN1_OUT_OF_DATA                      -0x0060
  ------------------
   45|      0|        }
   46|     16|        *len = 0;
   47|     16|        (*p)++;
   48|     48|        while (n--) {
  ------------------
  |  Branch (48:16): [True: 32, False: 16]
  ------------------
   49|     32|            *len = (*len << 8) | **p;
   50|     32|            (*p)++;
   51|     32|        }
   52|     16|    }
   53|       |
   54|    193|    if (*len > (size_t) (end - *p)) {
  ------------------
  |  Branch (54:9): [True: 0, False: 193]
  ------------------
   55|      0|        return MBEDTLS_ERR_ASN1_OUT_OF_DATA;
  ------------------
  |  |   37|      0|#define MBEDTLS_ERR_ASN1_OUT_OF_DATA                      -0x0060
  ------------------
   56|      0|    }
   57|       |
   58|    193|    return 0;
   59|    193|}
mbedtls_asn1_get_tag:
   64|    171|{
   65|    171|    if ((end - *p) < 1) {
  ------------------
  |  Branch (65:9): [True: 0, False: 171]
  ------------------
   66|      0|        return MBEDTLS_ERR_ASN1_OUT_OF_DATA;
  ------------------
  |  |   37|      0|#define MBEDTLS_ERR_ASN1_OUT_OF_DATA                      -0x0060
  ------------------
   67|      0|    }
   68|       |
   69|    171|    if (**p != tag) {
  ------------------
  |  Branch (69:9): [True: 14, False: 157]
  ------------------
   70|     14|        return MBEDTLS_ERR_ASN1_UNEXPECTED_TAG;
  ------------------
  |  |   39|     14|#define MBEDTLS_ERR_ASN1_UNEXPECTED_TAG                   -0x0062
  ------------------
   71|     14|    }
   72|       |
   73|    157|    (*p)++;
   74|       |
   75|    157|    return mbedtls_asn1_get_len(p, end, len);
   76|    171|}
mbedtls_asn1_get_bool:
   83|     12|{
   84|     12|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|     12|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
   85|     12|    size_t len;
   86|       |
   87|     12|    if ((ret = mbedtls_asn1_get_tag(p, end, &len, MBEDTLS_ASN1_BOOLEAN)) != 0) {
  ------------------
  |  |   64|     12|#define MBEDTLS_ASN1_BOOLEAN                 0x01
  ------------------
  |  Branch (87:9): [True: 8, False: 4]
  ------------------
   88|      8|        return ret;
   89|      8|    }
   90|       |
   91|      4|    if (len != 1) {
  ------------------
  |  Branch (91:9): [True: 0, False: 4]
  ------------------
   92|      0|        return MBEDTLS_ERR_ASN1_INVALID_LENGTH;
  ------------------
  |  |   41|      0|#define MBEDTLS_ERR_ASN1_INVALID_LENGTH                   -0x0064
  ------------------
   93|      0|    }
   94|       |
   95|      4|    *val = (**p != 0) ? 1 : 0;
  ------------------
  |  Branch (95:12): [True: 4, False: 0]
  ------------------
   96|      4|    (*p)++;
   97|       |
   98|      4|    return 0;
   99|      4|}
mbedtls_asn1_get_int:
  151|      3|{
  152|      3|    return asn1_get_tagged_int(p, end, MBEDTLS_ASN1_INTEGER, val);
  ------------------
  |  |   65|      3|#define MBEDTLS_ASN1_INTEGER                 0x02
  ------------------
  153|      3|}
mbedtls_asn1_get_bitstring_null:
  273|      6|{
  274|      6|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|      6|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  275|       |
  276|      6|    if ((ret = mbedtls_asn1_get_tag(p, end, len, MBEDTLS_ASN1_BIT_STRING)) != 0) {
  ------------------
  |  |   66|      6|#define MBEDTLS_ASN1_BIT_STRING              0x03
  ------------------
  |  Branch (276:9): [True: 0, False: 6]
  ------------------
  277|      0|        return ret;
  278|      0|    }
  279|       |
  280|      6|    if (*len == 0) {
  ------------------
  |  Branch (280:9): [True: 0, False: 6]
  ------------------
  281|      0|        return MBEDTLS_ERR_ASN1_INVALID_DATA;
  ------------------
  |  |   45|      0|#define MBEDTLS_ERR_ASN1_INVALID_DATA                     -0x0068
  ------------------
  282|      0|    }
  283|      6|    --(*len);
  284|       |
  285|      6|    if (**p != 0) {
  ------------------
  |  Branch (285:9): [True: 0, False: 6]
  ------------------
  286|      0|        return MBEDTLS_ERR_ASN1_INVALID_DATA;
  ------------------
  |  |   45|      0|#define MBEDTLS_ERR_ASN1_INVALID_DATA                     -0x0068
  ------------------
  287|      0|    }
  288|      6|    ++(*p);
  289|       |
  290|      6|    return 0;
  291|      6|}
mbedtls_asn1_get_alg:
  354|      9|{
  355|      9|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|      9|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  356|      9|    size_t len;
  357|       |
  358|      9|    if ((ret = mbedtls_asn1_get_tag(p, end, &len,
  ------------------
  |  Branch (358:9): [True: 0, False: 9]
  ------------------
  359|      9|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|      9|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|      9|#define MBEDTLS_ASN1_SEQUENCE                0x10
  ------------------
  360|      0|        return ret;
  361|      0|    }
  362|       |
  363|      9|    if ((end - *p) < 1) {
  ------------------
  |  Branch (363:9): [True: 0, False: 9]
  ------------------
  364|      0|        return MBEDTLS_ERR_ASN1_OUT_OF_DATA;
  ------------------
  |  |   37|      0|#define MBEDTLS_ERR_ASN1_OUT_OF_DATA                      -0x0060
  ------------------
  365|      0|    }
  366|       |
  367|      9|    alg->tag = **p;
  368|      9|    end = *p + len;
  369|       |
  370|      9|    if ((ret = mbedtls_asn1_get_tag(p, end, &alg->len, MBEDTLS_ASN1_OID)) != 0) {
  ------------------
  |  |   69|      9|#define MBEDTLS_ASN1_OID                     0x06
  ------------------
  |  Branch (370:9): [True: 0, False: 9]
  ------------------
  371|      0|        return ret;
  372|      0|    }
  373|       |
  374|      9|    alg->p = *p;
  375|      9|    *p += alg->len;
  376|       |
  377|      9|    if (*p == end) {
  ------------------
  |  Branch (377:9): [True: 0, False: 9]
  ------------------
  378|      0|        mbedtls_platform_zeroize(params, sizeof(mbedtls_asn1_buf));
  379|      0|        return 0;
  380|      0|    }
  381|       |
  382|      9|    params->tag = **p;
  383|      9|    (*p)++;
  384|       |
  385|      9|    if ((ret = mbedtls_asn1_get_len(p, end, &params->len)) != 0) {
  ------------------
  |  Branch (385:9): [True: 0, False: 9]
  ------------------
  386|      0|        return ret;
  387|      0|    }
  388|       |
  389|      9|    params->p = *p;
  390|      9|    *p += params->len;
  391|       |
  392|      9|    if (*p != end) {
  ------------------
  |  Branch (392:9): [True: 0, False: 9]
  ------------------
  393|      0|        return MBEDTLS_ERR_ASN1_LENGTH_MISMATCH;
  ------------------
  |  |   43|      0|#define MBEDTLS_ERR_ASN1_LENGTH_MISMATCH                  -0x0066
  ------------------
  394|      0|    }
  395|       |
  396|      9|    return 0;
  397|      9|}
asn1parse.c:asn1_get_tagged_int:
  104|      3|{
  105|      3|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|      3|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  106|      3|    size_t len;
  107|       |
  108|      3|    if ((ret = mbedtls_asn1_get_tag(p, end, &len, tag)) != 0) {
  ------------------
  |  Branch (108:9): [True: 0, False: 3]
  ------------------
  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|      3|    if (len == 0) {
  ------------------
  |  Branch (116:9): [True: 0, False: 3]
  ------------------
  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|      3|    if ((**p & 0x80) != 0) {
  ------------------
  |  Branch (120:9): [True: 0, False: 3]
  ------------------
  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|      3|    while (len > 0 && **p == 0) {
  ------------------
  |  Branch (125:12): [True: 3, False: 0]
  |  Branch (125:23): [True: 0, False: 3]
  ------------------
  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|      3|    if (len > sizeof(int)) {
  ------------------
  |  Branch (132:9): [True: 0, False: 3]
  ------------------
  133|      0|        return MBEDTLS_ERR_ASN1_INVALID_LENGTH;
  ------------------
  |  |   41|      0|#define MBEDTLS_ERR_ASN1_INVALID_LENGTH                   -0x0064
  ------------------
  134|      0|    }
  135|      3|    if (len == sizeof(int) && (**p & 0x80) != 0) {
  ------------------
  |  Branch (135:9): [True: 0, False: 3]
  |  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|      3|    *val = 0;
  140|      6|    while (len-- > 0) {
  ------------------
  |  Branch (140:12): [True: 3, False: 3]
  ------------------
  141|      3|        *val = (*val << 8) | **p;
  142|      3|        (*p)++;
  143|      3|    }
  144|       |
  145|      3|    return 0;
  146|      3|}

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

mbedtls_mpi_init:
  182|     26|{
  183|     26|    X->s = 1;
  184|     26|    X->n = 0;
  185|     26|    X->p = NULL;
  186|     26|}
mbedtls_mpi_free:
  192|     63|{
  193|     63|    if (X == NULL) {
  ------------------
  |  Branch (193:9): [True: 0, False: 63]
  ------------------
  194|      0|        return;
  195|      0|    }
  196|       |
  197|     63|    if (X->p != NULL) {
  ------------------
  |  Branch (197:9): [True: 3, False: 60]
  ------------------
  198|      3|        mbedtls_mpi_zeroize_and_free(X->p, X->n);
  ------------------
  |  |  176|      3|#define mbedtls_mpi_zeroize_and_free(v, n) mbedtls_zeroize_and_free(v, ciL * (n))
  |  |  ------------------
  |  |  |  |   77|      3|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  199|      3|    }
  200|       |
  201|     63|    X->s = 1;
  202|     63|    X->n = 0;
  203|     63|    X->p = NULL;
  204|     63|}
mbedtls_mpi_grow:
  210|     23|{
  211|     23|    mbedtls_mpi_uint *p;
  212|       |
  213|     23|    if (nblimbs > MBEDTLS_MPI_MAX_LIMBS) {
  ------------------
  |  |   50|     23|#define MBEDTLS_MPI_MAX_LIMBS                             10000
  ------------------
  |  Branch (213:9): [True: 0, False: 23]
  ------------------
  214|      0|        return MBEDTLS_ERR_MPI_ALLOC_FAILED;
  ------------------
  |  |   38|      0|#define MBEDTLS_ERR_MPI_ALLOC_FAILED                      -0x0010
  ------------------
  215|      0|    }
  216|       |
  217|     23|    if (X->n < nblimbs) {
  ------------------
  |  Branch (217:9): [True: 12, False: 11]
  ------------------
  218|     12|        if ((p = (mbedtls_mpi_uint *) mbedtls_calloc(nblimbs, ciL)) == NULL) {
  ------------------
  |  |   77|     12|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  |  Branch (218:13): [True: 0, False: 12]
  ------------------
  219|      0|            return MBEDTLS_ERR_MPI_ALLOC_FAILED;
  ------------------
  |  |   38|      0|#define MBEDTLS_ERR_MPI_ALLOC_FAILED                      -0x0010
  ------------------
  220|      0|        }
  221|       |
  222|     12|        if (X->p != NULL) {
  ------------------
  |  Branch (222:13): [True: 2, False: 10]
  ------------------
  223|      2|            memcpy(p, X->p, X->n * ciL);
  ------------------
  |  |   77|      2|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  224|      2|            mbedtls_mpi_zeroize_and_free(X->p, X->n);
  ------------------
  |  |  176|      2|#define mbedtls_mpi_zeroize_and_free(v, n) mbedtls_zeroize_and_free(v, ciL * (n))
  |  |  ------------------
  |  |  |  |   77|      2|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  225|      2|        }
  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|     12|        X->n = (unsigned short) nblimbs;
  230|     12|        X->p = p;
  231|     12|    }
  232|       |
  233|     23|    return 0;
  234|     23|}
mbedtls_mpi_copy:
  308|      1|{
  309|      1|    int ret = 0;
  310|      1|    size_t i;
  311|       |
  312|      1|    if (X == Y) {
  ------------------
  |  Branch (312:9): [True: 0, False: 1]
  ------------------
  313|      0|        return 0;
  314|      0|    }
  315|       |
  316|      1|    if (Y->n == 0) {
  ------------------
  |  Branch (316:9): [True: 0, False: 1]
  ------------------
  317|      0|        if (X->n != 0) {
  ------------------
  |  Branch (317:13): [True: 0, False: 0]
  ------------------
  318|      0|            X->s = 1;
  319|      0|            memset(X->p, 0, X->n * ciL);
  ------------------
  |  |   77|      0|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  320|      0|        }
  321|      0|        return 0;
  322|      0|    }
  323|       |
  324|      8|    for (i = Y->n - 1; i > 0; i--) {
  ------------------
  |  Branch (324:24): [True: 8, False: 0]
  ------------------
  325|      8|        if (Y->p[i] != 0) {
  ------------------
  |  Branch (325:13): [True: 1, False: 7]
  ------------------
  326|      1|            break;
  327|      1|        }
  328|      8|    }
  329|      1|    i++;
  330|       |
  331|      1|    X->s = Y->s;
  332|       |
  333|      1|    if (X->n < i) {
  ------------------
  |  Branch (333:9): [True: 1, False: 0]
  ------------------
  334|      1|        MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, i));
  ------------------
  |  |   41|      1|    do                           \
  |  |   42|      1|    {                            \
  |  |   43|      1|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1]
  |  |  ------------------
  |  |   44|      1|        goto cleanup;        \
  |  |   45|      1|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  335|      1|    } else {
  336|      0|        memset(X->p + i, 0, (X->n - i) * ciL);
  ------------------
  |  |   77|      0|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  337|      0|    }
  338|       |
  339|      1|    memcpy(X->p, Y->p, i * ciL);
  ------------------
  |  |   77|      1|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  340|       |
  341|      1|cleanup:
  342|       |
  343|      1|    return ret;
  344|      1|}
mbedtls_mpi_lset:
  378|      4|{
  379|      4|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|      4|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  380|       |
  381|      4|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, 1));
  ------------------
  |  |   41|      4|    do                           \
  |  |   42|      4|    {                            \
  |  |   43|      4|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 4]
  |  |  ------------------
  |  |   44|      4|        goto cleanup;        \
  |  |   45|      4|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  382|      4|    memset(X->p, 0, X->n * ciL);
  ------------------
  |  |   77|      4|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  383|       |
  384|      4|    X->p[0] = mpi_sint_abs(z);
  385|      4|    X->s    = TO_SIGN(z);
  ------------------
  |  |  372|      4|#define TO_SIGN(x) ((mbedtls_mpi_sint) (((mbedtls_mpi_uint) x) >> (biL - 1)) * -2 + 1)
  |  |  ------------------
  |  |  |  |   78|      4|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  |  |  ------------------
  |  |  |  |  |  |   77|      4|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  386|       |
  387|      4|cleanup:
  388|       |
  389|      4|    return ret;
  390|      4|}
mbedtls_mpi_get_bit:
  396|      6|{
  397|      6|    if (X->n * biL <= pos) {
  ------------------
  |  |   78|      6|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   77|      6|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  |  Branch (397:9): [True: 0, False: 6]
  ------------------
  398|      0|        return 0;
  399|      0|    }
  400|       |
  401|      6|    return (X->p[pos / biL] >> (pos % biL)) & 0x01;
  ------------------
  |  |   78|      6|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   77|      6|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
                  return (X->p[pos / biL] >> (pos % biL)) & 0x01;
  ------------------
  |  |   78|      6|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   77|      6|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  402|      6|}
mbedtls_mpi_bitlen:
  474|     16|{
  475|     16|    return mbedtls_mpi_core_bitlen(X->p, X->n);
  476|     16|}
mbedtls_mpi_size:
  482|      7|{
  483|      7|    return (mbedtls_mpi_bitlen(X) + 7) >> 3;
  484|      7|}
mbedtls_mpi_read_binary:
  821|      6|{
  822|      6|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|      6|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  823|      6|    const size_t limbs = CHARS_TO_LIMBS(buflen);
  ------------------
  |  |   86|      6|#define CHARS_TO_LIMBS(i) ((i) / ciL + ((i) % ciL != 0))
  |  |  ------------------
  |  |  |  |   77|      6|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  |  |               #define CHARS_TO_LIMBS(i) ((i) / ciL + ((i) % ciL != 0))
  |  |  ------------------
  |  |  |  |   77|      6|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  824|       |
  825|       |    /* Ensure that target MPI has exactly the necessary number of limbs */
  826|      6|    MBEDTLS_MPI_CHK(mbedtls_mpi_resize_clear(X, limbs));
  ------------------
  |  |   41|      6|    do                           \
  |  |   42|      6|    {                            \
  |  |   43|      6|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 6]
  |  |  ------------------
  |  |   44|      6|        goto cleanup;        \
  |  |   45|      6|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  827|       |
  828|      6|    MBEDTLS_MPI_CHK(mbedtls_mpi_core_read_be(X->p, X->n, buf, buflen));
  ------------------
  |  |   41|      6|    do                           \
  |  |   42|      6|    {                            \
  |  |   43|      6|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 6]
  |  |  ------------------
  |  |   44|      6|        goto cleanup;        \
  |  |   45|      6|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  829|       |
  830|      6|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|      6|    return ret;
  838|      6|}
mbedtls_mpi_cmp_abs:
  895|      2|{
  896|      2|    size_t i, j;
  897|       |
  898|     16|    for (i = X->n; i > 0; i--) {
  ------------------
  |  Branch (898:20): [True: 16, False: 0]
  ------------------
  899|     16|        if (X->p[i - 1] != 0) {
  ------------------
  |  Branch (899:13): [True: 2, False: 14]
  ------------------
  900|      2|            break;
  901|      2|        }
  902|     16|    }
  903|       |
  904|      2|    for (j = Y->n; j > 0; j--) {
  ------------------
  |  Branch (904:20): [True: 2, False: 0]
  ------------------
  905|      2|        if (Y->p[j - 1] != 0) {
  ------------------
  |  Branch (905:13): [True: 2, False: 0]
  ------------------
  906|      2|            break;
  907|      2|        }
  908|      2|    }
  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|      2|    if (i > j) {
  ------------------
  |  Branch (913:9): [True: 1, False: 1]
  ------------------
  914|      1|        return 1;
  915|      1|    }
  916|      1|    if (j > i) {
  ------------------
  |  Branch (916:9): [True: 0, False: 1]
  ------------------
  917|      0|        return -1;
  918|      0|    }
  919|       |
  920|      1|    for (; i > 0; i--) {
  ------------------
  |  Branch (920:12): [True: 1, False: 0]
  ------------------
  921|      1|        if (X->p[i - 1] > Y->p[i - 1]) {
  ------------------
  |  Branch (921:13): [True: 0, False: 1]
  ------------------
  922|      0|            return 1;
  923|      0|        }
  924|      1|        if (X->p[i - 1] < Y->p[i - 1]) {
  ------------------
  |  Branch (924:13): [True: 1, False: 0]
  ------------------
  925|      1|            return -1;
  926|      1|        }
  927|      1|    }
  928|       |
  929|      0|    return 0;
  930|      1|}
mbedtls_mpi_cmp_mpi:
  936|     34|{
  937|     34|    size_t i, j;
  938|       |
  939|    100|    for (i = X->n; i > 0; i--) {
  ------------------
  |  Branch (939:20): [True: 94, False: 6]
  ------------------
  940|     94|        if (X->p[i - 1] != 0) {
  ------------------
  |  Branch (940:13): [True: 28, False: 66]
  ------------------
  941|     28|            break;
  942|     28|        }
  943|     94|    }
  944|       |
  945|     64|    for (j = Y->n; j > 0; j--) {
  ------------------
  |  Branch (945:20): [True: 43, False: 21]
  ------------------
  946|     43|        if (Y->p[j - 1] != 0) {
  ------------------
  |  Branch (946:13): [True: 13, False: 30]
  ------------------
  947|     13|            break;
  948|     13|        }
  949|     43|    }
  950|       |
  951|     34|    if (i == 0 && j == 0) {
  ------------------
  |  Branch (951:9): [True: 6, False: 28]
  |  Branch (951:19): [True: 6, False: 0]
  ------------------
  952|      6|        return 0;
  953|      6|    }
  954|       |
  955|     28|    if (i > j) {
  ------------------
  |  Branch (955:9): [True: 18, False: 10]
  ------------------
  956|     18|        return X->s;
  957|     18|    }
  958|     10|    if (j > i) {
  ------------------
  |  Branch (958:9): [True: 2, False: 8]
  ------------------
  959|      2|        return -Y->s;
  960|      2|    }
  961|       |
  962|      8|    if (X->s > 0 && Y->s < 0) {
  ------------------
  |  Branch (962:9): [True: 8, False: 0]
  |  Branch (962:21): [True: 0, False: 8]
  ------------------
  963|      0|        return 1;
  964|      0|    }
  965|      8|    if (Y->s > 0 && X->s < 0) {
  ------------------
  |  Branch (965:9): [True: 8, False: 0]
  |  Branch (965:21): [True: 0, False: 8]
  ------------------
  966|      0|        return -1;
  967|      0|    }
  968|       |
  969|     15|    for (; i > 0; i--) {
  ------------------
  |  Branch (969:12): [True: 13, False: 2]
  ------------------
  970|     13|        if (X->p[i - 1] > Y->p[i - 1]) {
  ------------------
  |  Branch (970:13): [True: 0, False: 13]
  ------------------
  971|      0|            return X->s;
  972|      0|        }
  973|     13|        if (X->p[i - 1] < Y->p[i - 1]) {
  ------------------
  |  Branch (973:13): [True: 6, False: 7]
  ------------------
  974|      6|            return -X->s;
  975|      6|        }
  976|     13|    }
  977|       |
  978|      2|    return 0;
  979|      8|}
mbedtls_mpi_cmp_int:
  985|     22|{
  986|     22|    mbedtls_mpi Y;
  987|     22|    mbedtls_mpi_uint p[1];
  988|       |
  989|     22|    *p  = mpi_sint_abs(z);
  990|     22|    Y.s = TO_SIGN(z);
  ------------------
  |  |  372|     22|#define TO_SIGN(x) ((mbedtls_mpi_sint) (((mbedtls_mpi_uint) x) >> (biL - 1)) * -2 + 1)
  |  |  ------------------
  |  |  |  |   78|     22|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  |  |  ------------------
  |  |  |  |  |  |   77|     22|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  991|     22|    Y.n = 1;
  992|     22|    Y.p = p;
  993|       |
  994|     22|    return mbedtls_mpi_cmp_mpi(X, &Y);
  995|     22|}
mbedtls_mpi_add_abs:
 1001|      1|{
 1002|      1|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|      1|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1003|      1|    size_t j;
 1004|      1|    mbedtls_mpi_uint *p;
 1005|      1|    mbedtls_mpi_uint c;
 1006|       |
 1007|      1|    if (X == B) {
  ------------------
  |  Branch (1007:9): [True: 0, False: 1]
  ------------------
 1008|      0|        const mbedtls_mpi *T = A; A = X; B = T;
 1009|      0|    }
 1010|       |
 1011|      1|    if (X != A) {
  ------------------
  |  Branch (1011:9): [True: 0, False: 1]
  ------------------
 1012|      0|        MBEDTLS_MPI_CHK(mbedtls_mpi_copy(X, 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]
  |  |  ------------------
  ------------------
 1013|      0|    }
 1014|       |
 1015|       |    /*
 1016|       |     * X must always be positive as a result of unsigned additions.
 1017|       |     */
 1018|      1|    X->s = 1;
 1019|       |
 1020|      1|    for (j = B->n; j > 0; j--) {
  ------------------
  |  Branch (1020:20): [True: 1, False: 0]
  ------------------
 1021|      1|        if (B->p[j - 1] != 0) {
  ------------------
  |  Branch (1021:13): [True: 1, False: 0]
  ------------------
 1022|      1|            break;
 1023|      1|        }
 1024|      1|    }
 1025|       |
 1026|       |    /* Exit early to avoid undefined behavior on NULL+0 when X->n == 0
 1027|       |     * and B is 0 (of any size). */
 1028|      1|    if (j == 0) {
  ------------------
  |  Branch (1028:9): [True: 0, False: 1]
  ------------------
 1029|      0|        return 0;
 1030|      0|    }
 1031|       |
 1032|      1|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, j));
  ------------------
  |  |   41|      1|    do                           \
  |  |   42|      1|    {                            \
  |  |   43|      1|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1]
  |  |  ------------------
  |  |   44|      1|        goto cleanup;        \
  |  |   45|      1|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1033|       |
 1034|       |    /* j is the number of non-zero limbs of B. Add those to X. */
 1035|       |
 1036|      1|    p = X->p;
 1037|       |
 1038|      1|    c = mbedtls_mpi_core_add(p, p, B->p, j);
 1039|       |
 1040|      1|    p += j;
 1041|       |
 1042|       |    /* Now propagate any carry */
 1043|       |
 1044|      2|    while (c != 0) {
  ------------------
  |  Branch (1044:12): [True: 1, False: 1]
  ------------------
 1045|      1|        if (j >= X->n) {
  ------------------
  |  Branch (1045:13): [True: 0, False: 1]
  ------------------
 1046|      0|            MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, j + 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]
  |  |  ------------------
  ------------------
 1047|      0|            p = X->p + j;
 1048|      0|        }
 1049|       |
 1050|      1|        *p += c; c = (*p < c); j++; p++;
 1051|      1|    }
 1052|       |
 1053|      1|cleanup:
 1054|       |
 1055|      1|    return ret;
 1056|      1|}
mbedtls_mpi_sub_abs:
 1062|      5|{
 1063|      5|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|      5|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1064|      5|    size_t n;
 1065|      5|    mbedtls_mpi_uint carry;
 1066|       |
 1067|     12|    for (n = B->n; n > 0; n--) {
  ------------------
  |  Branch (1067:20): [True: 12, False: 0]
  ------------------
 1068|     12|        if (B->p[n - 1] != 0) {
  ------------------
  |  Branch (1068:13): [True: 5, False: 7]
  ------------------
 1069|      5|            break;
 1070|      5|        }
 1071|     12|    }
 1072|      5|    if (n > A->n) {
  ------------------
  |  Branch (1072:9): [True: 0, False: 5]
  ------------------
 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|      5|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, A->n));
  ------------------
  |  |   41|      5|    do                           \
  |  |   42|      5|    {                            \
  |  |   43|      5|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 5]
  |  |  ------------------
  |  |   44|      5|        goto cleanup;        \
  |  |   45|      5|    } 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|      5|    if (A->n > n && A != X) {
  ------------------
  |  Branch (1083:9): [True: 4, False: 1]
  |  Branch (1083:21): [True: 0, False: 4]
  ------------------
 1084|      0|        memcpy(X->p + n, A->p + n, (A->n - n) * ciL);
  ------------------
  |  |   77|      0|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
 1085|      0|    }
 1086|      5|    if (X->n > A->n) {
  ------------------
  |  Branch (1086:9): [True: 1, False: 4]
  ------------------
 1087|      1|        memset(X->p + A->n, 0, (X->n - A->n) * ciL);
  ------------------
  |  |   77|      1|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
 1088|      1|    }
 1089|       |
 1090|      5|    carry = mbedtls_mpi_core_sub(X->p, A->p, B->p, n);
 1091|      5|    if (carry != 0) {
  ------------------
  |  Branch (1091:9): [True: 3, False: 2]
  ------------------
 1092|       |        /* Propagate the carry through the rest of X. */
 1093|      3|        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|        if (carry != 0) {
  ------------------
  |  Branch (1096:13): [True: 0, False: 3]
  ------------------
 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|    }
 1101|       |
 1102|       |    /* X should always be positive as a result of unsigned subtractions. */
 1103|      5|    X->s = 1;
 1104|       |
 1105|      5|cleanup:
 1106|      5|    return ret;
 1107|      5|}
mbedtls_mpi_add_mpi:
 1146|      2|{
 1147|      2|    return add_sub_mpi(X, A, B, 1);
 1148|      2|}
mbedtls_mpi_sub_mpi:
 1154|      1|{
 1155|      1|    return add_sub_mpi(X, A, B, -1);
 1156|      1|}
mbedtls_mpi_sub_int:
 1178|      1|{
 1179|      1|    mbedtls_mpi B;
 1180|      1|    mbedtls_mpi_uint p[1];
 1181|       |
 1182|      1|    p[0] = mpi_sint_abs(b);
 1183|      1|    B.s = TO_SIGN(b);
  ------------------
  |  |  372|      1|#define TO_SIGN(x) ((mbedtls_mpi_sint) (((mbedtls_mpi_uint) x) >> (biL - 1)) * -2 + 1)
  |  |  ------------------
  |  |  |  |   78|      1|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  |  |  ------------------
  |  |  |  |  |  |   77|      1|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1184|      1|    B.n = 1;
 1185|      1|    B.p = p;
 1186|       |
 1187|      1|    return mbedtls_mpi_sub_mpi(X, A, &B);
 1188|      1|}
mbedtls_mpi_mul_mpi:
 1194|      3|{
 1195|      3|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|      3|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1196|      3|    size_t i, j;
 1197|      3|    mbedtls_mpi TA, TB;
 1198|      3|    int result_is_zero = 0;
 1199|       |
 1200|      3|    mbedtls_mpi_init(&TA);
 1201|      3|    mbedtls_mpi_init(&TB);
 1202|       |
 1203|      3|    if (X == A) {
  ------------------
  |  Branch (1203:9): [True: 1, False: 2]
  ------------------
 1204|      1|        MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TA, A)); A = &TA;
  ------------------
  |  |   41|      1|    do                           \
  |  |   42|      1|    {                            \
  |  |   43|      1|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1]
  |  |  ------------------
  |  |   44|      1|        goto cleanup;        \
  |  |   45|      1|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1205|      1|    }
 1206|      3|    if (X == B) {
  ------------------
  |  Branch (1206:9): [True: 0, False: 3]
  ------------------
 1207|      0|        MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TB, B)); B = &TB;
  ------------------
  |  |   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]
  |  |  ------------------
  ------------------
 1208|      0|    }
 1209|       |
 1210|      3|    for (i = A->n; i > 0; i--) {
  ------------------
  |  Branch (1210:20): [True: 3, False: 0]
  ------------------
 1211|      3|        if (A->p[i - 1] != 0) {
  ------------------
  |  Branch (1211:13): [True: 3, False: 0]
  ------------------
 1212|      3|            break;
 1213|      3|        }
 1214|      3|    }
 1215|      3|    if (i == 0) {
  ------------------
  |  Branch (1215:9): [True: 0, False: 3]
  ------------------
 1216|      0|        result_is_zero = 1;
 1217|      0|    }
 1218|       |
 1219|      3|    for (j = B->n; j > 0; j--) {
  ------------------
  |  Branch (1219:20): [True: 3, False: 0]
  ------------------
 1220|      3|        if (B->p[j - 1] != 0) {
  ------------------
  |  Branch (1220:13): [True: 3, False: 0]
  ------------------
 1221|      3|            break;
 1222|      3|        }
 1223|      3|    }
 1224|      3|    if (j == 0) {
  ------------------
  |  Branch (1224:9): [True: 0, False: 3]
  ------------------
 1225|      0|        result_is_zero = 1;
 1226|      0|    }
 1227|       |
 1228|      3|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, i + j));
  ------------------
  |  |   41|      3|    do                           \
  |  |   42|      3|    {                            \
  |  |   43|      3|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3]
  |  |  ------------------
  |  |   44|      3|        goto cleanup;        \
  |  |   45|      3|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1229|      3|    MBEDTLS_MPI_CHK(mbedtls_mpi_lset(X, 0));
  ------------------
  |  |   41|      3|    do                           \
  |  |   42|      3|    {                            \
  |  |   43|      3|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3]
  |  |  ------------------
  |  |   44|      3|        goto cleanup;        \
  |  |   45|      3|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1230|       |
 1231|      3|    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|      3|    if (result_is_zero) {
  ------------------
  |  Branch (1237:9): [True: 0, False: 3]
  ------------------
 1238|      0|        X->s = 1;
 1239|      3|    } else {
 1240|      3|        X->s = A->s * B->s;
 1241|      3|    }
 1242|       |
 1243|      3|cleanup:
 1244|       |
 1245|      3|    mbedtls_mpi_free(&TB); mbedtls_mpi_free(&TA);
 1246|       |
 1247|      3|    return ret;
 1248|      3|}
bignum.c:mpi_sint_abs:
  359|     27|{
  360|     27|    if (z >= 0) {
  ------------------
  |  Branch (360:9): [True: 27, False: 0]
  ------------------
  361|     27|        return z;
  362|     27|    }
  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|      0|    return (mbedtls_mpi_uint) 0 - (mbedtls_mpi_uint) z;
  368|     27|}
bignum.c:mbedtls_mpi_resize_clear:
  285|      6|{
  286|      6|    if (limbs == 0) {
  ------------------
  |  Branch (286:9): [True: 0, False: 6]
  ------------------
  287|      0|        mbedtls_mpi_free(X);
  288|      0|        return 0;
  289|      6|    } else if (X->n == limbs) {
  ------------------
  |  Branch (289:16): [True: 0, False: 6]
  ------------------
  290|      0|        memset(X->p, 0, limbs * ciL);
  ------------------
  |  |   77|      0|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  291|      0|        X->s = 1;
  292|      0|        return 0;
  293|      6|    } else {
  294|      6|        mbedtls_mpi_free(X);
  295|      6|        return mbedtls_mpi_grow(X, limbs);
  296|      6|    }
  297|      6|}
bignum.c:add_sub_mpi:
 1115|      3|{
 1116|      3|    int ret, s;
 1117|       |
 1118|      3|    s = A->s;
 1119|      3|    if (A->s * B->s * flip_B < 0) {
  ------------------
  |  Branch (1119:9): [True: 2, False: 1]
  ------------------
 1120|      2|        int cmp = mbedtls_mpi_cmp_abs(A, B);
 1121|      2|        if (cmp >= 0) {
  ------------------
  |  Branch (1121:13): [True: 1, False: 1]
  ------------------
 1122|      1|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs(X, A, B));
  ------------------
  |  |   41|      1|    do                           \
  |  |   42|      1|    {                            \
  |  |   43|      1|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1]
  |  |  ------------------
  |  |   44|      1|        goto cleanup;        \
  |  |   45|      1|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1123|       |            /* If |A| = |B|, the result is 0 and we must set the sign bit
 1124|       |             * to +1 regardless of which of A or B was negative. Otherwise,
 1125|       |             * since |A| > |B|, the sign is the sign of A. */
 1126|      1|            X->s = cmp == 0 ? 1 : s;
  ------------------
  |  Branch (1126:20): [True: 0, False: 1]
  ------------------
 1127|      1|        } else {
 1128|      1|            MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs(X, B, A));
  ------------------
  |  |   41|      1|    do                           \
  |  |   42|      1|    {                            \
  |  |   43|      1|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1]
  |  |  ------------------
  |  |   44|      1|        goto cleanup;        \
  |  |   45|      1|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1129|       |            /* Since |A| < |B|, the sign is the opposite of A. */
 1130|      1|            X->s = -s;
 1131|      1|        }
 1132|      2|    } else {
 1133|      1|        MBEDTLS_MPI_CHK(mbedtls_mpi_add_abs(X, A, B));
  ------------------
  |  |   41|      1|    do                           \
  |  |   42|      1|    {                            \
  |  |   43|      1|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1]
  |  |  ------------------
  |  |   44|      1|        goto cleanup;        \
  |  |   45|      1|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1134|      1|        X->s = s;
 1135|      1|    }
 1136|       |
 1137|      3|cleanup:
 1138|       |
 1139|      3|    return ret;
 1140|      3|}

mbedtls_mpi_core_clz:
   25|     16|{
   26|     16|#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|     16|#endif
   35|     16|#if defined(core_clz)
   36|     16|    return (size_t) core_clz(a);
  ------------------
  |  |   30|     16|    #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|     16|}
mbedtls_mpi_core_bitlen:
   54|     16|{
   55|     16|    int i;
   56|     16|    size_t j;
   57|       |
   58|     25|    for (i = ((int) A_limbs) - 1; i >= 0; i--) {
  ------------------
  |  Branch (58:35): [True: 25, False: 0]
  ------------------
   59|     25|        if (A[i] != 0) {
  ------------------
  |  Branch (59:13): [True: 16, False: 9]
  ------------------
   60|     16|            j = biL - mbedtls_mpi_core_clz(A[i]);
  ------------------
  |  |   78|     16|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   77|     16|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
   61|     16|            return (i * biL) + j;
  ------------------
  |  |   78|     16|#define biL    (ciL << 3)                     /** bits  in limb  */
  |  |  ------------------
  |  |  |  |   77|     16|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
   62|     16|        }
   63|     25|    }
   64|       |
   65|      0|    return 0;
   66|     16|}
mbedtls_mpi_core_bigendian_to_host:
   84|      6|{
   85|      6|    mbedtls_mpi_uint *cur_limb_left;
   86|      6|    mbedtls_mpi_uint *cur_limb_right;
   87|      6|    if (A_limbs == 0) {
  ------------------
  |  Branch (87:9): [True: 0, False: 6]
  ------------------
   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|      6|    for (cur_limb_left = A, cur_limb_right = A + (A_limbs - 1);
  101|     48|         cur_limb_left <= cur_limb_right;
  ------------------
  |  Branch (101:10): [True: 42, False: 6]
  ------------------
  102|     42|         cur_limb_left++, cur_limb_right--) {
  103|     42|        mbedtls_mpi_uint tmp;
  104|       |        /* Note that if cur_limb_left == cur_limb_right,
  105|       |         * this code effectively swaps the bytes only once. */
  106|     42|        tmp             = mpi_bigendian_to_host(*cur_limb_left);
  107|     42|        *cur_limb_left  = mpi_bigendian_to_host(*cur_limb_right);
  108|     42|        *cur_limb_right = tmp;
  109|     42|    }
  110|      6|}
mbedtls_mpi_core_read_be:
  230|      6|{
  231|      6|    const size_t limbs = CHARS_TO_LIMBS(input_length);
  ------------------
  |  |   86|      6|#define CHARS_TO_LIMBS(i) ((i) / ciL + ((i) % ciL != 0))
  |  |  ------------------
  |  |  |  |   77|      6|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  |  |               #define CHARS_TO_LIMBS(i) ((i) / ciL + ((i) % ciL != 0))
  |  |  ------------------
  |  |  |  |   77|      6|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  232|       |
  233|      6|    if (X_limbs < limbs) {
  ------------------
  |  Branch (233:9): [True: 0, False: 6]
  ------------------
  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|      6|    if (X_limbs == 0) {
  ------------------
  |  Branch (239:9): [True: 0, False: 6]
  ------------------
  240|      0|        return 0;
  241|      0|    }
  242|       |
  243|      6|    memset(X, 0, X_limbs * ciL);
  ------------------
  |  |   77|      6|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  244|       |
  245|       |    /* memcpy() with (NULL, 0) is undefined behaviour */
  246|      6|    if (input_length != 0) {
  ------------------
  |  Branch (246:9): [True: 6, False: 0]
  ------------------
  247|      6|        size_t overhead = (X_limbs * ciL) - input_length;
  ------------------
  |  |   77|      6|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  248|      6|        unsigned char *Xp = (unsigned char *) X;
  249|      6|        memcpy(Xp + overhead, input, input_length);
  250|      6|    }
  251|       |
  252|      6|    mbedtls_mpi_core_bigendian_to_host(X, X_limbs);
  253|       |
  254|      6|    return 0;
  255|      6|}
mbedtls_mpi_core_add:
  409|      1|{
  410|      1|    mbedtls_mpi_uint c = 0;
  411|       |
  412|      7|    for (size_t i = 0; i < limbs; i++) {
  ------------------
  |  Branch (412:24): [True: 6, False: 1]
  ------------------
  413|      6|        mbedtls_mpi_uint t = c + A[i];
  414|      6|        c = (t < A[i]);
  415|      6|        t += B[i];
  416|      6|        c += (t < B[i]);
  417|      6|        X[i] = t;
  418|      6|    }
  419|       |
  420|      1|    return c;
  421|      1|}
mbedtls_mpi_core_sub:
  448|      5|{
  449|      5|    mbedtls_mpi_uint c = 0;
  450|       |
  451|     30|    for (size_t i = 0; i < limbs; i++) {
  ------------------
  |  Branch (451:24): [True: 25, False: 5]
  ------------------
  452|     25|        mbedtls_mpi_uint z = (A[i] < c);
  453|     25|        mbedtls_mpi_uint t = A[i] - c;
  454|     25|        c = (t < B[i]) + z;
  455|     25|        X[i] = t - B[i];
  456|     25|    }
  457|       |
  458|      5|    return c;
  459|      5|}
mbedtls_mpi_core_mla:
  464|     18|{
  465|     18|    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|     18|    if (d_len < s_len) {
  ------------------
  |  Branch (471:9): [True: 0, False: 18]
  ------------------
  472|      0|        s_len = d_len;
  473|      0|    }
  474|     18|    size_t excess_len = d_len - s_len;
  475|     18|    size_t steps_x8 = s_len / 8;
  476|     18|    size_t steps_x1 = s_len & 7;
  477|       |
  478|     18|    while (steps_x8--) {
  ------------------
  |  Branch (478:12): [True: 0, False: 18]
  ------------------
  479|      0|        MULADDC_X8_INIT
  ------------------
  |  | 1088|      0|#define MULADDC_X8_INIT MULADDC_X4_INIT
  |  |  ------------------
  |  |  |  | 1082|      0|#define MULADDC_X4_INIT MULADDC_X2_INIT
  |  |  |  |  ------------------
  |  |  |  |  |  | 1076|      0|#define MULADDC_X2_INIT MULADDC_X1_INIT
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  216|      0|    asm(                                    \
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  321|      0|#define asm __asm__
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  217|      0|        "xorq   %%r8, %%r8\n"
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  480|      0|        MULADDC_X8_CORE
  481|      0|            MULADDC_X8_STOP
  ------------------
  |  | 1089|      0|#define MULADDC_X8_STOP MULADDC_X4_STOP
  |  |  ------------------
  |  |  |  | 1083|      0|#define MULADDC_X4_STOP MULADDC_X2_STOP
  |  |  |  |  ------------------
  |  |  |  |  |  | 1077|      0|#define MULADDC_X2_STOP MULADDC_X1_STOP
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  232|      0|        : "+c" (c), "+D" (d), "+S" (s), "+m" (*(uint64_t (*)[16]) d) \
  |  |  |  |  |  |  |  |  233|      0|        : "b" (b), "m" (*(const uint64_t (*)[16]) s)                 \
  |  |  |  |  |  |  |  |  234|      0|        : "rax", "rdx", "r8"                                         \
  |  |  |  |  |  |  |  |  235|      0|    );
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  482|      0|    }
  483|       |
  484|    126|    while (steps_x1--) {
  ------------------
  |  Branch (484:12): [True: 108, False: 18]
  ------------------
  485|    108|        MULADDC_X1_INIT
  ------------------
  |  |  216|    108|    asm(                                    \
  |  |  ------------------
  |  |  |  |  321|    108|#define asm __asm__
  |  |  ------------------
  |  |  217|    108|        "xorq   %%r8, %%r8\n"
  ------------------
  486|    108|        MULADDC_X1_CORE
  487|    108|            MULADDC_X1_STOP
  ------------------
  |  |  232|    108|        : "+c" (c), "+D" (d), "+S" (s), "+m" (*(uint64_t (*)[16]) d) \
  |  |  233|    108|        : "b" (b), "m" (*(const uint64_t (*)[16]) s)                 \
  |  |  234|    108|        : "rax", "rdx", "r8"                                         \
  |  |  235|    108|    );
  ------------------
  488|    108|    }
  489|       |
  490|     36|    while (excess_len--) {
  ------------------
  |  Branch (490:12): [True: 18, False: 18]
  ------------------
  491|     18|        *d += c;
  492|     18|        c = (*d < c);
  493|     18|        d++;
  494|     18|    }
  495|       |
  496|     18|    return c;
  497|     18|}
mbedtls_mpi_core_mul:
  502|      3|{
  503|      3|    memset(X, 0, (A_limbs + B_limbs) * ciL);
  ------------------
  |  |   77|      3|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  ------------------
  504|       |
  505|     21|    for (size_t i = 0; i < B_limbs; i++) {
  ------------------
  |  Branch (505:24): [True: 18, False: 3]
  ------------------
  506|     18|        (void) mbedtls_mpi_core_mla(X + i, A_limbs + 1, A, A_limbs, B[i]);
  507|     18|    }
  508|      3|}
mbedtls_mpi_core_sub_int:
  975|      3|{
  976|     24|    for (size_t i = 0; i < limbs; i++) {
  ------------------
  |  Branch (976:24): [True: 21, False: 3]
  ------------------
  977|     21|        mbedtls_mpi_uint s = A[i];
  978|     21|        mbedtls_mpi_uint t = s - c;
  979|     21|        c = (t > s);
  980|     21|        X[i] = t;
  981|     21|    }
  982|       |
  983|      3|    return c;
  984|      3|}
bignum_core.c:mpi_bigendian_to_host:
   69|     84|{
   70|     84|    if (MBEDTLS_IS_BIG_ENDIAN) {
  ------------------
  |  |  398|     84|#define MBEDTLS_IS_BIG_ENDIAN 0
  |  |  ------------------
  |  |  |  Branch (398:31): [Folded - Ignored]
  |  |  ------------------
  ------------------
   71|       |        /* Nothing to do on bigendian systems. */
   72|      0|        return a;
   73|     84|    } else {
   74|       |#if defined(MBEDTLS_HAVE_INT32)
   75|       |        return (mbedtls_mpi_uint) MBEDTLS_BSWAP32(a);
   76|       |#elif defined(MBEDTLS_HAVE_INT64)
   77|     84|        return (mbedtls_mpi_uint) MBEDTLS_BSWAP64(a);
  ------------------
  |  |  301|     84|#define MBEDTLS_BSWAP64 __builtin_bswap64
  ------------------
   78|     84|#endif
   79|     84|    }
   80|     84|}

base64.c:mbedtls_ct_uchar_in_range_if:
  395|  43.9k|{
  396|  43.9k|    const unsigned char co = (unsigned char) mbedtls_ct_compiler_opaque(c);
  397|  43.9k|    const unsigned char to = (unsigned char) mbedtls_ct_compiler_opaque(t);
  398|       |
  399|       |    /* low_mask is: 0 if low <= c, 0x...ff if low > c */
  400|  43.9k|    unsigned low_mask = ((unsigned) co - low) >> 8;
  401|       |    /* high_mask is: 0 if c <= high, 0x...ff if c > high */
  402|  43.9k|    unsigned high_mask = ((unsigned) high - co) >> 8;
  403|       |
  404|  43.9k|    return (unsigned char) (~(low_mask | high_mask)) & to;
  405|  43.9k|}
base64.c:mbedtls_ct_compiler_opaque:
   86|  87.9k|{
   87|  87.9k|#if defined(MBEDTLS_CT_ASM)
   88|  87.9k|    asm volatile ("" : [x] "+r" (x) :);
  ------------------
  |  |  321|  87.9k|#define asm __asm__
  ------------------
   89|  87.9k|    return x;
   90|       |#else
   91|       |    return x ^ mbedtls_ct_zero;
   92|       |#endif
   93|  87.9k|}

mbedtls_ctr_drbg_init:
   74|     42|{
   75|     42|    memset(ctx, 0, sizeof(mbedtls_ctr_drbg_context));
   76|       |#if defined(MBEDTLS_CTR_DRBG_USE_PSA_CRYPTO)
   77|       |    ctx->psa_ctx.key_id = MBEDTLS_SVC_KEY_ID_INIT;
   78|       |    ctx->psa_ctx.operation = psa_cipher_operation_init();
   79|       |#else
   80|     42|    mbedtls_aes_init(&ctx->aes_ctx);
   81|     42|#endif
   82|       |    /* Indicate that the entropy nonce length is not set explicitly.
   83|       |     * See mbedtls_ctr_drbg_set_nonce_len(). */
   84|     42|    ctx->reseed_counter = -1;
   85|       |
   86|     42|    ctx->reseed_interval = MBEDTLS_CTR_DRBG_RESEED_INTERVAL;
  ------------------
  |  |  127|     42|#define MBEDTLS_CTR_DRBG_RESEED_INTERVAL    10000
  ------------------
   87|     42|}
mbedtls_ctr_drbg_free:
   94|     42|{
   95|     42|    if (ctx == NULL) {
  ------------------
  |  Branch (95:9): [True: 0, False: 42]
  ------------------
   96|      0|        return;
   97|      0|    }
   98|       |
   99|     42|#if defined(MBEDTLS_THREADING_C)
  100|       |    /* The mutex is initialized iff f_entropy is set. */
  101|     42|    if (ctx->f_entropy != NULL) {
  ------------------
  |  Branch (101:9): [True: 21, False: 21]
  ------------------
  102|     21|        mbedtls_mutex_free(&ctx->mutex);
  103|     21|    }
  104|     42|#endif
  105|       |#if defined(MBEDTLS_CTR_DRBG_USE_PSA_CRYPTO)
  106|       |    ctr_drbg_destroy_psa_contex(&ctx->psa_ctx);
  107|       |#else
  108|     42|    mbedtls_aes_free(&ctx->aes_ctx);
  109|     42|#endif
  110|     42|    mbedtls_platform_zeroize(ctx, sizeof(mbedtls_ctr_drbg_context));
  111|     42|    ctx->reseed_interval = MBEDTLS_CTR_DRBG_RESEED_INTERVAL;
  ------------------
  |  |  127|     42|#define MBEDTLS_CTR_DRBG_RESEED_INTERVAL    10000
  ------------------
  112|     42|    ctx->reseed_counter = -1;
  113|     42|}
mbedtls_ctr_drbg_seed:
  540|     21|{
  541|     21|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|     21|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  542|     21|    unsigned char key[MBEDTLS_CTR_DRBG_KEYSIZE];
  543|     21|    size_t nonce_len;
  544|       |
  545|     21|    memset(key, 0, MBEDTLS_CTR_DRBG_KEYSIZE);
  ------------------
  |  |   83|     21|#define MBEDTLS_CTR_DRBG_KEYSIZE            32
  ------------------
  546|       |
  547|       |    /* The mutex is initialized iff f_entropy is set. */
  548|     21|#if defined(MBEDTLS_THREADING_C)
  549|     21|    mbedtls_mutex_init(&ctx->mutex);
  550|     21|#endif
  551|       |
  552|     21|    ctx->f_entropy = f_entropy;
  553|     21|    ctx->p_entropy = p_entropy;
  554|       |
  555|     21|    if (ctx->entropy_len == 0) {
  ------------------
  |  Branch (555:9): [True: 21, False: 0]
  ------------------
  556|     21|        ctx->entropy_len = MBEDTLS_CTR_DRBG_ENTROPY_LEN;
  ------------------
  |  |  111|     21|#define MBEDTLS_CTR_DRBG_ENTROPY_LEN        48
  ------------------
  557|     21|    }
  558|       |    /* ctx->reseed_counter contains the desired amount of entropy to
  559|       |     * grab for a nonce (see mbedtls_ctr_drbg_set_nonce_len()).
  560|       |     * If it's -1, indicating that the entropy nonce length was not set
  561|       |     * explicitly, use a sufficiently large nonce for security. */
  562|     21|    nonce_len = (ctx->reseed_counter >= 0 ?
  ------------------
  |  Branch (562:18): [True: 0, False: 21]
  ------------------
  563|      0|                 (size_t) ctx->reseed_counter :
  564|     21|                 good_nonce_len(ctx->entropy_len));
  565|       |
  566|       |    /* Initialize with an empty key. */
  567|       |#if defined(MBEDTLS_CTR_DRBG_USE_PSA_CRYPTO)
  568|       |    psa_status_t status;
  569|       |
  570|       |    status = ctr_drbg_setup_psa_context(&ctx->psa_ctx, key, MBEDTLS_CTR_DRBG_KEYSIZE);
  571|       |    if (status != PSA_SUCCESS) {
  572|       |        ret = psa_generic_status_to_mbedtls(status);
  573|       |        return status;
  574|       |    }
  575|       |#else
  576|     21|    if ((ret = mbedtls_aes_setkey_enc(&ctx->aes_ctx, key,
  ------------------
  |  Branch (576:9): [True: 0, False: 21]
  ------------------
  577|     21|                                      MBEDTLS_CTR_DRBG_KEYBITS)) != 0) {
  ------------------
  |  |   91|     21|#define MBEDTLS_CTR_DRBG_KEYBITS            (MBEDTLS_CTR_DRBG_KEYSIZE * 8)   /**< The key size for the DRBG operation, in bits. */
  |  |  ------------------
  |  |  |  |   83|     21|#define MBEDTLS_CTR_DRBG_KEYSIZE            32
  |  |  ------------------
  ------------------
  578|      0|        return ret;
  579|      0|    }
  580|     21|#endif
  581|       |
  582|       |    /* Do the initial seeding. */
  583|     21|    if ((ret = mbedtls_ctr_drbg_reseed_internal(ctx, custom, len,
  ------------------
  |  Branch (583:9): [True: 21, False: 0]
  ------------------
  584|     21|                                                nonce_len)) != 0) {
  585|     21|        return ret;
  586|     21|    }
  587|      0|    return 0;
  588|     21|}
ctr_drbg.c:mbedtls_ctr_drbg_reseed_internal:
  451|     21|{
  452|     21|    unsigned char seed[MBEDTLS_CTR_DRBG_MAX_SEED_INPUT];
  453|     21|    size_t seedlen = 0;
  454|     21|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|     21|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  455|       |
  456|     21|    if (ctx->entropy_len > MBEDTLS_CTR_DRBG_MAX_SEED_INPUT) {
  ------------------
  |  |  142|     21|#define MBEDTLS_CTR_DRBG_MAX_SEED_INPUT     384
  ------------------
  |  Branch (456:9): [True: 0, False: 21]
  ------------------
  457|      0|        return MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG;
  ------------------
  |  |   69|      0|#define MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG                -0x0038
  ------------------
  458|      0|    }
  459|     21|    if (nonce_len > MBEDTLS_CTR_DRBG_MAX_SEED_INPUT - ctx->entropy_len) {
  ------------------
  |  |  142|     21|#define MBEDTLS_CTR_DRBG_MAX_SEED_INPUT     384
  ------------------
  |  Branch (459:9): [True: 0, False: 21]
  ------------------
  460|      0|        return MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG;
  ------------------
  |  |   69|      0|#define MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG                -0x0038
  ------------------
  461|      0|    }
  462|     21|    if (len > MBEDTLS_CTR_DRBG_MAX_SEED_INPUT - ctx->entropy_len - nonce_len) {
  ------------------
  |  |  142|     21|#define MBEDTLS_CTR_DRBG_MAX_SEED_INPUT     384
  ------------------
  |  Branch (462:9): [True: 0, False: 21]
  ------------------
  463|      0|        return MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG;
  ------------------
  |  |   69|      0|#define MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG                -0x0038
  ------------------
  464|      0|    }
  465|       |
  466|     21|    memset(seed, 0, MBEDTLS_CTR_DRBG_MAX_SEED_INPUT);
  ------------------
  |  |  142|     21|#define MBEDTLS_CTR_DRBG_MAX_SEED_INPUT     384
  ------------------
  467|       |
  468|       |    /* Gather entropy_len bytes of entropy to seed state. */
  469|     21|    if (0 != ctx->f_entropy(ctx->p_entropy, seed, ctx->entropy_len)) {
  ------------------
  |  Branch (469:9): [True: 21, False: 0]
  ------------------
  470|     21|        return MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED;
  ------------------
  |  |   65|     21|#define MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED        -0x0034
  ------------------
  471|     21|    }
  472|      0|    seedlen += ctx->entropy_len;
  473|       |
  474|       |    /* Gather entropy for a nonce if requested. */
  475|      0|    if (nonce_len != 0) {
  ------------------
  |  Branch (475:9): [True: 0, False: 0]
  ------------------
  476|      0|        if (0 != ctx->f_entropy(ctx->p_entropy, seed + seedlen, nonce_len)) {
  ------------------
  |  Branch (476:13): [True: 0, False: 0]
  ------------------
  477|      0|            return MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED;
  ------------------
  |  |   65|      0|#define MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED        -0x0034
  ------------------
  478|      0|        }
  479|      0|        seedlen += nonce_len;
  480|      0|    }
  481|       |
  482|       |    /* Add additional data if provided. */
  483|      0|    if (additional != NULL && len != 0) {
  ------------------
  |  Branch (483:9): [True: 0, False: 0]
  |  Branch (483:31): [True: 0, False: 0]
  ------------------
  484|      0|        memcpy(seed + seedlen, additional, len);
  485|      0|        seedlen += len;
  486|      0|    }
  487|       |
  488|       |    /* Reduce to 384 bits. */
  489|      0|    if ((ret = block_cipher_df(seed, seed, seedlen)) != 0) {
  ------------------
  |  Branch (489:9): [True: 0, False: 0]
  ------------------
  490|      0|        goto exit;
  491|      0|    }
  492|       |
  493|       |    /* Update state. */
  494|      0|    if ((ret = ctr_drbg_update_internal(ctx, seed)) != 0) {
  ------------------
  |  Branch (494:9): [True: 0, False: 0]
  ------------------
  495|      0|        goto exit;
  496|      0|    }
  497|      0|    ctx->reseed_counter = 1;
  498|       |
  499|      0|exit:
  500|      0|    mbedtls_platform_zeroize(seed, sizeof(seed));
  501|      0|    return ret;
  502|      0|}
ctr_drbg.c:good_nonce_len:
  516|     21|{
  517|     21|    if (entropy_len >= MBEDTLS_CTR_DRBG_KEYSIZE * 3 / 2) {
  ------------------
  |  |   83|     21|#define MBEDTLS_CTR_DRBG_KEYSIZE            32
  ------------------
  |  Branch (517:9): [True: 21, False: 0]
  ------------------
  518|     21|        return 0;
  519|     21|    } else {
  520|      0|        return (entropy_len + 1) / 2;
  521|      0|    }
  522|     21|}

mbedtls_debug_print_msg:
   56|     42|{
   57|     42|    va_list argp;
   58|     42|    char str[DEBUG_BUF_SIZE];
   59|     42|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|     42|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
   60|       |
   61|     42|    MBEDTLS_STATIC_ASSERT(DEBUG_BUF_SIZE >= 2, "DEBUG_BUF_SIZE too small");
  ------------------
  |  |  367|     42|    struct ISO_C_does_not_allow_extra_semicolon_outside_of_a_function
  ------------------
   62|       |
   63|     42|    if (NULL == ssl              ||
  ------------------
  |  Branch (63:9): [True: 0, False: 42]
  ------------------
   64|     42|        NULL == ssl->conf        ||
  ------------------
  |  Branch (64:9): [True: 42, False: 0]
  ------------------
   65|     42|        NULL == ssl->conf->f_dbg ||
  ------------------
  |  Branch (65:9): [True: 0, False: 0]
  ------------------
   66|     42|        level > debug_threshold) {
  ------------------
  |  Branch (66:9): [True: 0, False: 0]
  ------------------
   67|     42|        return;
   68|     42|    }
   69|       |
   70|      0|    va_start(argp, format);
   71|      0|    ret = mbedtls_vsnprintf(str, DEBUG_BUF_SIZE, format, argp);
  ------------------
  |  |   22|      0|#define DEBUG_BUF_SIZE      512
  ------------------
   72|      0|    va_end(argp);
   73|       |
   74|      0|    if (ret < 0) {
  ------------------
  |  Branch (74:9): [True: 0, False: 0]
  ------------------
   75|      0|        ret = 0;
   76|      0|    } else {
   77|      0|        if (ret >= DEBUG_BUF_SIZE - 1) {
  ------------------
  |  |   22|      0|#define DEBUG_BUF_SIZE      512
  ------------------
  |  Branch (77:13): [True: 0, False: 0]
  ------------------
   78|      0|            ret = DEBUG_BUF_SIZE - 2;
  ------------------
  |  |   22|      0|#define DEBUG_BUF_SIZE      512
  ------------------
   79|      0|        }
   80|      0|    }
   81|      0|    str[ret]     = '\n';
   82|      0|    str[ret + 1] = '\0';
   83|       |
   84|      0|    debug_send_line(ssl, level, file, line, str);
   85|      0|}

mbedtls_ecp_get_type:
  487|      4|{
  488|      4|    if (grp->G.X.p == NULL) {
  ------------------
  |  Branch (488:9): [True: 0, False: 4]
  ------------------
  489|      0|        return MBEDTLS_ECP_TYPE_NONE;
  490|      0|    }
  491|       |
  492|      4|    if (grp->G.Y.p == NULL) {
  ------------------
  |  Branch (492:9): [True: 0, False: 4]
  ------------------
  493|      0|        return MBEDTLS_ECP_TYPE_MONTGOMERY;
  494|      4|    } else {
  495|      4|        return MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS;
  496|      4|    }
  497|      4|}
mbedtls_ecp_point_init:
  503|      3|{
  504|      3|    mbedtls_mpi_init(&pt->X);
  505|      3|    mbedtls_mpi_init(&pt->Y);
  506|      3|    mbedtls_mpi_init(&pt->Z);
  507|      3|}
mbedtls_ecp_group_init:
  513|      2|{
  514|      2|    grp->id = MBEDTLS_ECP_DP_NONE;
  515|      2|    mbedtls_mpi_init(&grp->P);
  516|      2|    mbedtls_mpi_init(&grp->A);
  517|      2|    mbedtls_mpi_init(&grp->B);
  518|      2|    mbedtls_ecp_point_init(&grp->G);
  519|      2|    mbedtls_mpi_init(&grp->N);
  520|      2|    grp->pbits = 0;
  521|      2|    grp->nbits = 0;
  522|      2|    grp->h = 0;
  523|      2|    grp->modp = NULL;
  524|      2|    grp->t_pre = NULL;
  525|      2|    grp->t_post = NULL;
  526|      2|    grp->t_data = NULL;
  527|      2|    grp->T = NULL;
  528|      2|    grp->T_size = 0;
  529|      2|}
mbedtls_ecp_keypair_init:
  535|      1|{
  536|      1|    mbedtls_ecp_group_init(&key->grp);
  537|      1|    mbedtls_mpi_init(&key->d);
  538|      1|    mbedtls_ecp_point_init(&key->Q);
  539|      1|}
mbedtls_ecp_point_free:
  545|      1|{
  546|      1|    if (pt == NULL) {
  ------------------
  |  Branch (546:9): [True: 0, False: 1]
  ------------------
  547|      0|        return;
  548|      0|    }
  549|       |
  550|      1|    mbedtls_mpi_free(&(pt->X));
  551|      1|    mbedtls_mpi_free(&(pt->Y));
  552|      1|    mbedtls_mpi_free(&(pt->Z));
  553|      1|}
mbedtls_ecp_group_free:
  572|      1|{
  573|      1|    size_t i;
  574|       |
  575|      1|    if (grp == NULL) {
  ------------------
  |  Branch (575:9): [True: 0, False: 1]
  ------------------
  576|      0|        return;
  577|      0|    }
  578|       |
  579|      1|    if (grp->h != 1) {
  ------------------
  |  Branch (579:9): [True: 1, False: 0]
  ------------------
  580|      1|        mbedtls_mpi_free(&grp->A);
  581|      1|        mbedtls_mpi_free(&grp->B);
  582|      1|        mbedtls_ecp_point_free(&grp->G);
  583|       |
  584|      1|#if !defined(MBEDTLS_ECP_WITH_MPI_UINT)
  585|      1|        mbedtls_mpi_free(&grp->N);
  586|      1|        mbedtls_mpi_free(&grp->P);
  587|      1|#endif
  588|      1|    }
  589|       |
  590|      1|    if (!ecp_group_is_static_comb_table(grp) && grp->T != NULL) {
  ------------------
  |  Branch (590:9): [True: 1, False: 0]
  |  Branch (590:49): [True: 0, False: 1]
  ------------------
  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);
  595|      0|    }
  596|       |
  597|      1|    mbedtls_platform_zeroize(grp, sizeof(mbedtls_ecp_group));
  598|      1|}
mbedtls_ecp_point_read_binary:
  772|      1|{
  773|      1|    int ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
  ------------------
  |  |   39|      1|#define MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE               -0x4E80
  ------------------
  774|      1|    size_t plen;
  775|      1|    if (ilen < 1) {
  ------------------
  |  Branch (775:9): [True: 0, False: 1]
  ------------------
  776|      0|        return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
  777|      0|    }
  778|       |
  779|      1|    plen = mbedtls_mpi_size(&grp->P);
  780|       |
  781|      1|#if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED)
  782|      1|    if (mbedtls_ecp_get_type(grp) == MBEDTLS_ECP_TYPE_MONTGOMERY) {
  ------------------
  |  Branch (782:9): [True: 0, False: 1]
  ------------------
  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|      1|#endif
  798|      1|#if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
  799|      1|    if (mbedtls_ecp_get_type(grp) == MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS) {
  ------------------
  |  Branch (799:9): [True: 1, False: 0]
  ------------------
  800|      1|        if (buf[0] == 0x00) {
  ------------------
  |  Branch (800:13): [True: 0, False: 1]
  ------------------
  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|      1|        if (ilen < 1 + plen) {
  ------------------
  |  Branch (808:13): [True: 0, False: 1]
  ------------------
  809|      0|            return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
  810|      0|        }
  811|       |
  812|      1|        MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&pt->X, buf + 1, plen));
  ------------------
  |  |   41|      1|    do                           \
  |  |   42|      1|    {                            \
  |  |   43|      1|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1]
  |  |  ------------------
  |  |   44|      1|        goto cleanup;        \
  |  |   45|      1|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  813|      1|        MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&pt->Z, 1));
  ------------------
  |  |   41|      1|    do                           \
  |  |   42|      1|    {                            \
  |  |   43|      1|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1]
  |  |  ------------------
  |  |   44|      1|        goto cleanup;        \
  |  |   45|      1|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  814|       |
  815|      1|        if (buf[0] == 0x04) {
  ------------------
  |  Branch (815:13): [True: 1, False: 0]
  ------------------
  816|       |            /* format == MBEDTLS_ECP_PF_UNCOMPRESSED */
  817|      1|            if (ilen != 1 + plen * 2) {
  ------------------
  |  Branch (817:17): [True: 0, False: 1]
  ------------------
  818|      0|                return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
  819|      0|            }
  820|      1|            return mbedtls_mpi_read_binary(&pt->Y, buf + 1 + plen, plen);
  821|      1|        } 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|      1|    }
  832|      0|#endif
  833|       |
  834|      0|cleanup:
  835|      0|    return ret;
  836|      1|}
mbedtls_ecp_check_pubkey:
 3029|      1|{
 3030|       |    /* Must use affine coordinates */
 3031|      1|    if (mbedtls_mpi_cmp_int(&pt->Z, 1) != 0) {
  ------------------
  |  Branch (3031:9): [True: 0, False: 1]
  ------------------
 3032|      0|        return MBEDTLS_ERR_ECP_INVALID_KEY;
  ------------------
  |  |   47|      0|#define MBEDTLS_ERR_ECP_INVALID_KEY                       -0x4C80
  ------------------
 3033|      0|    }
 3034|       |
 3035|      1|#if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED)
 3036|      1|    if (mbedtls_ecp_get_type(grp) == MBEDTLS_ECP_TYPE_MONTGOMERY) {
  ------------------
  |  Branch (3036:9): [True: 0, False: 1]
  ------------------
 3037|      0|        return ecp_check_pubkey_mx(grp, pt);
 3038|      0|    }
 3039|      1|#endif
 3040|      1|#if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
 3041|      1|    if (mbedtls_ecp_get_type(grp) == MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS) {
  ------------------
  |  Branch (3041:9): [True: 1, False: 0]
  ------------------
 3042|      1|        return ecp_check_pubkey_sw(grp, pt);
 3043|      1|    }
 3044|      0|#endif
 3045|      0|    return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
 3046|      1|}
ecp.c:ecp_group_is_static_comb_table:
  559|      1|{
  560|      1|#if MBEDTLS_ECP_FIXED_POINT_OPTIM == 1
  561|      1|    return grp->T != NULL && grp->T_size == 0;
  ------------------
  |  Branch (561:12): [True: 0, False: 1]
  |  Branch (561:30): [True: 0, False: 0]
  ------------------
  562|       |#else
  563|       |    (void) grp;
  564|       |    return 0;
  565|       |#endif
  566|      1|}
ecp.c:ecp_sw_rhs:
 1228|      1|{
 1229|      1|    int ret;
 1230|       |
 1231|       |    /* Compute X^3 + A X + B as X (X^2 + A) + B */
 1232|      1|    MPI_ECP_SQR(rhs, X);
  ------------------
  |  | 1170|      1|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, A))
  |  |  ------------------
  |  |  |  |   41|      1|    do                           \
  |  |  |  |   42|      1|    {                            \
  |  |  |  |   43|      1|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 1]
  |  |  |  |  ------------------
  |  |  |  |   44|      1|        goto cleanup;        \
  |  |  |  |   45|      1|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1233|       |
 1234|       |    /* Special case for A = -3 */
 1235|      1|    if (mbedtls_ecp_group_a_is_minus_3(grp)) {
  ------------------
  |  Branch (1235:9): [True: 1, False: 0]
  ------------------
 1236|      1|        MPI_ECP_SUB_INT(rhs, rhs, 3);
  ------------------
  |  | 1140|      1|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int_mod(grp, X, A, c))
  |  |  ------------------
  |  |  |  |   41|      1|    do                           \
  |  |  |  |   42|      1|    {                            \
  |  |  |  |   43|      1|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 1]
  |  |  |  |  ------------------
  |  |  |  |   44|      1|        goto cleanup;        \
  |  |  |  |   45|      1|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1237|      1|    } 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|      1|    MPI_ECP_MUL(rhs, rhs, X);
  ------------------
  |  | 1167|      1|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|      1|    do                           \
  |  |  |  |   42|      1|    {                            \
  |  |  |  |   43|      1|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 1]
  |  |  |  |  ------------------
  |  |  |  |   44|      1|        goto cleanup;        \
  |  |  |  |   45|      1|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1242|      1|    MPI_ECP_ADD(rhs, rhs, &grp->B);
  ------------------
  |  | 1161|      1|    MBEDTLS_MPI_CHK(mbedtls_mpi_add_mod(grp, X, A, B))
  |  |  ------------------
  |  |  |  |   41|      1|    do                           \
  |  |  |  |   42|      1|    {                            \
  |  |  |  |   43|      1|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 1]
  |  |  |  |  ------------------
  |  |  |  |   44|      1|        goto cleanup;        \
  |  |  |  |   45|      1|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1243|       |
 1244|      1|cleanup:
 1245|      1|    return ret;
 1246|      1|}
ecp.c:mbedtls_mpi_mul_mod:
 1059|      3|{
 1060|      3|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|      3|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1061|      3|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(X, A, B));
  ------------------
  |  |   41|      3|    do                           \
  |  |   42|      3|    {                            \
  |  |   43|      3|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3]
  |  |  ------------------
  |  |   44|      3|        goto cleanup;        \
  |  |   45|      3|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1062|      3|    MOD_MUL(*X);
  ------------------
  |  | 1049|      3|    do                                                                  \
  |  | 1050|      3|    {                                                                   \
  |  | 1051|      3|        MBEDTLS_MPI_CHK(ecp_modp(&(N), grp));                       \
  |  |  ------------------
  |  |  |  |   41|      3|    do                           \
  |  |  |  |   42|      3|    {                            \
  |  |  |  |   43|      3|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 3]
  |  |  |  |  ------------------
  |  |  |  |   44|      3|        goto cleanup;        \
  |  |  |  |   45|      3|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 1052|      3|        INC_MUL_COUNT                                                   \
  |  |  ------------------
  |  |  |  | 1043|      3|#define INC_MUL_COUNT   mul_count++;
  |  |  ------------------
  |  | 1053|      3|    } while (0)
  |  |  ------------------
  |  |  |  Branch (1053:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1063|      3|cleanup:
 1064|      3|    return ret;
 1065|      3|}
ecp.c:ecp_modp:
 1000|      3|{
 1001|      3|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|      3|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1002|       |
 1003|      3|    if (grp->modp == NULL) {
  ------------------
  |  Branch (1003:9): [True: 0, False: 3]
  ------------------
 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|      3|    if ((N->s < 0 && mbedtls_mpi_cmp_int(N, 0) != 0) ||
  ------------------
  |  Branch (1008:10): [True: 0, False: 3]
  |  Branch (1008:22): [True: 0, False: 0]
  ------------------
 1009|      3|        mbedtls_mpi_bitlen(N) > 2 * grp->pbits) {
  ------------------
  |  Branch (1009:9): [True: 0, False: 3]
  ------------------
 1010|      0|        return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
 1011|      0|    }
 1012|       |
 1013|      3|    MBEDTLS_MPI_CHK(grp->modp(N));
  ------------------
  |  |   41|      3|    do                           \
  |  |   42|      3|    {                            \
  |  |   43|      3|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 3]
  |  |  ------------------
  |  |   44|      3|        goto cleanup;        \
  |  |   45|      3|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1014|       |
 1015|       |    /* N->s < 0 is a much faster test, which fails only if N is 0 */
 1016|      4|    while (N->s < 0 && mbedtls_mpi_cmp_int(N, 0) != 0) {
  ------------------
  |  Branch (1016:12): [True: 1, False: 3]
  |  Branch (1016:24): [True: 1, False: 0]
  ------------------
 1017|      1|        MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(N, N, &grp->P));
  ------------------
  |  |   41|      1|    do                           \
  |  |   42|      1|    {                            \
  |  |   43|      1|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1]
  |  |  ------------------
  |  |   44|      1|        goto cleanup;        \
  |  |   45|      1|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1018|      1|    }
 1019|       |
 1020|      5|    while (mbedtls_mpi_cmp_mpi(N, &grp->P) >= 0) {
  ------------------
  |  Branch (1020:12): [True: 2, False: 3]
  ------------------
 1021|       |        /* we known P, N and the result are positive */
 1022|      2|        MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs(N, N, &grp->P));
  ------------------
  |  |   41|      2|    do                           \
  |  |   42|      2|    {                            \
  |  |   43|      2|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2]
  |  |  ------------------
  |  |   44|      2|        goto cleanup;        \
  |  |   45|      2|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1023|      2|    }
 1024|       |
 1025|      3|cleanup:
 1026|      3|    return ret;
 1027|      3|}
ecp.c:mbedtls_mpi_sub_int_mod:
 1130|      1|{
 1131|      1|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|      1|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1132|       |
 1133|      1|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(X, A, c));
  ------------------
  |  |   41|      1|    do                           \
  |  |   42|      1|    {                            \
  |  |   43|      1|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1]
  |  |  ------------------
  |  |   44|      1|        goto cleanup;        \
  |  |   45|      1|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1134|      1|    MOD_SUB(X);
  ------------------
  |  | 1072|      1|    do {                                                                      \
  |  | 1073|      1|        while ((N)->s < 0 && mbedtls_mpi_cmp_int((N), 0) != 0)             \
  |  |  ------------------
  |  |  |  Branch (1073:16): [True: 0, False: 1]
  |  |  |  Branch (1073:30): [True: 0, False: 0]
  |  |  ------------------
  |  | 1074|      1|        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|      1|    } while (0)
  |  |  ------------------
  |  |  |  Branch (1075:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1135|      1|cleanup:
 1136|      1|    return ret;
 1137|      1|}
ecp.c:mbedtls_mpi_add_mod:
 1103|      1|{
 1104|      1|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|      1|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1105|      1|    MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(X, A, B));
  ------------------
  |  |   41|      1|    do                           \
  |  |   42|      1|    {                            \
  |  |   43|      1|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1]
  |  |  ------------------
  |  |   44|      1|        goto cleanup;        \
  |  |   45|      1|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1106|      1|    MOD_ADD(X);
  ------------------
  |  | 1096|      2|    while (mbedtls_mpi_cmp_mpi((N), &grp->P) >= 0)                  \
  |  |  ------------------
  |  |  |  Branch (1096:12): [True: 1, False: 1]
  |  |  ------------------
  |  | 1097|      1|    MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs((N), (N), &grp->P))
  |  |  ------------------
  |  |  |  |   41|      2|    do                           \
  |  |  |  |   42|      2|    {                            \
  |  |  |  |   43|      1|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 1]
  |  |  |  |  ------------------
  |  |  |  |   44|      1|        goto cleanup;        \
  |  |  |  |   45|      1|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1107|      1|cleanup:
 1108|      1|    return ret;
 1109|      1|}
ecp.c:ecp_check_pubkey_sw:
 2726|      1|{
 2727|      1|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|      1|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 2728|      1|    mbedtls_mpi YY, RHS;
 2729|       |
 2730|       |    /* pt coordinates must be normalized for our checks */
 2731|      1|    if (mbedtls_mpi_cmp_int(&pt->X, 0) < 0 ||
  ------------------
  |  Branch (2731:9): [True: 0, False: 1]
  ------------------
 2732|      1|        mbedtls_mpi_cmp_int(&pt->Y, 0) < 0 ||
  ------------------
  |  Branch (2732:9): [True: 0, False: 1]
  ------------------
 2733|      1|        mbedtls_mpi_cmp_mpi(&pt->X, &grp->P) >= 0 ||
  ------------------
  |  Branch (2733:9): [True: 0, False: 1]
  ------------------
 2734|      1|        mbedtls_mpi_cmp_mpi(&pt->Y, &grp->P) >= 0) {
  ------------------
  |  Branch (2734:9): [True: 0, False: 1]
  ------------------
 2735|      0|        return MBEDTLS_ERR_ECP_INVALID_KEY;
  ------------------
  |  |   47|      0|#define MBEDTLS_ERR_ECP_INVALID_KEY                       -0x4C80
  ------------------
 2736|      0|    }
 2737|       |
 2738|      1|    mbedtls_mpi_init(&YY); mbedtls_mpi_init(&RHS);
 2739|       |
 2740|       |    /*
 2741|       |     * YY = Y^2
 2742|       |     * RHS = X^3 + A X + B
 2743|       |     */
 2744|      1|    MPI_ECP_SQR(&YY,  &pt->Y);
  ------------------
  |  | 1170|      1|    MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mod(grp, X, A, A))
  |  |  ------------------
  |  |  |  |   41|      1|    do                           \
  |  |  |  |   42|      1|    {                            \
  |  |  |  |   43|      1|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 1]
  |  |  |  |  ------------------
  |  |  |  |   44|      1|        goto cleanup;        \
  |  |  |  |   45|      1|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2745|      1|    MBEDTLS_MPI_CHK(ecp_sw_rhs(grp, &RHS, &pt->X));
  ------------------
  |  |   41|      1|    do                           \
  |  |   42|      1|    {                            \
  |  |   43|      1|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 1]
  |  |  ------------------
  |  |   44|      1|        goto cleanup;        \
  |  |   45|      1|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 2746|       |
 2747|      1|    if (MPI_ECP_CMP(&YY, &RHS) != 0) {
  ------------------
  |  | 1191|      1|    mbedtls_mpi_cmp_mpi(X, Y)
  ------------------
  |  Branch (2747:9): [True: 0, False: 1]
  ------------------
 2748|      0|        ret = MBEDTLS_ERR_ECP_INVALID_KEY;
  ------------------
  |  |   47|      0|#define MBEDTLS_ERR_ECP_INVALID_KEY                       -0x4C80
  ------------------
 2749|      0|    }
 2750|       |
 2751|      1|cleanup:
 2752|       |
 2753|      1|    mbedtls_mpi_free(&YY); mbedtls_mpi_free(&RHS);
 2754|       |
 2755|      1|    return ret;
 2756|      1|}

mbedtls_ecp_group_load:
 4718|      1|{
 4719|      1|    mbedtls_ecp_group_free(grp);
 4720|       |
 4721|      1|    mbedtls_ecp_group_init(grp);
 4722|       |
 4723|      1|    grp->id = id;
 4724|       |
 4725|      1|    switch (id) {
 4726|      0|#if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
 4727|      0|        case MBEDTLS_ECP_DP_SECP192R1:
  ------------------
  |  Branch (4727:9): [True: 0, False: 1]
  ------------------
 4728|      0|            NIST_MODP(p192);
  ------------------
  |  | 4567|      0|#define NIST_MODP(P)      grp->modp = ecp_mod_ ## P;
  ------------------
 4729|      0|            return LOAD_GROUP(secp192r1);
  ------------------
  |  | 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|                                         )
  ------------------
 4730|      0|#endif /* MBEDTLS_ECP_DP_SECP192R1_ENABLED */
 4731|       |
 4732|      0|#if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED)
 4733|      0|        case MBEDTLS_ECP_DP_SECP224R1:
  ------------------
  |  Branch (4733:9): [True: 0, False: 1]
  ------------------
 4734|      0|            NIST_MODP(p224);
  ------------------
  |  | 4567|      0|#define NIST_MODP(P)      grp->modp = ecp_mod_ ## P;
  ------------------
 4735|      0|            return LOAD_GROUP(secp224r1);
  ------------------
  |  | 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|                                         )
  ------------------
 4736|      0|#endif /* MBEDTLS_ECP_DP_SECP224R1_ENABLED */
 4737|       |
 4738|      0|#if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED)
 4739|      0|        case MBEDTLS_ECP_DP_SECP256R1:
  ------------------
  |  Branch (4739:9): [True: 0, False: 1]
  ------------------
 4740|      0|            NIST_MODP(p256);
  ------------------
  |  | 4567|      0|#define NIST_MODP(P)      grp->modp = ecp_mod_ ## P;
  ------------------
 4741|      0|            return LOAD_GROUP(secp256r1);
  ------------------
  |  | 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|                                         )
  ------------------
 4742|      0|#endif /* MBEDTLS_ECP_DP_SECP256R1_ENABLED */
 4743|       |
 4744|      0|#if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
 4745|      1|        case MBEDTLS_ECP_DP_SECP384R1:
  ------------------
  |  Branch (4745:9): [True: 1, False: 0]
  ------------------
 4746|      1|            NIST_MODP(p384);
  ------------------
  |  | 4567|      1|#define NIST_MODP(P)      grp->modp = ecp_mod_ ## P;
  ------------------
 4747|      1|            return LOAD_GROUP(secp384r1);
  ------------------
  |  | 4600|      1|#define LOAD_GROUP(G)     ecp_group_load(grp,            \
  |  | 4601|      1|                                         G ## _p,  sizeof(G ## _p),   \
  |  | 4602|      1|                                         NULL,     0,                    \
  |  | 4603|      1|                                         G ## _b,  sizeof(G ## _b),   \
  |  | 4604|      1|                                         G ## _gx, sizeof(G ## _gx),   \
  |  | 4605|      1|                                         G ## _gy, sizeof(G ## _gy),   \
  |  | 4606|      1|                                         G ## _n,  sizeof(G ## _n),   \
  |  | 4607|      1|                                         G ## _T                         \
  |  | 4608|      1|                                         )
  ------------------
 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: 1]
  ------------------
 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|      0|#if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED)
 4757|      0|        case MBEDTLS_ECP_DP_SECP192K1:
  ------------------
  |  Branch (4757:9): [True: 0, False: 1]
  ------------------
 4758|      0|            grp->modp = ecp_mod_p192k1;
 4759|      0|            return LOAD_GROUP_A(secp192k1);
  ------------------
  |  | 4590|      0|#define LOAD_GROUP_A(G)   ecp_group_load(grp,            \
  |  | 4591|      0|                                         G ## _p,  sizeof(G ## _p),   \
  |  | 4592|      0|                                         G ## _a,  sizeof(G ## _a),   \
  |  | 4593|      0|                                         G ## _b,  sizeof(G ## _b),   \
  |  | 4594|      0|                                         G ## _gx, sizeof(G ## _gx),   \
  |  | 4595|      0|                                         G ## _gy, sizeof(G ## _gy),   \
  |  | 4596|      0|                                         G ## _n,  sizeof(G ## _n),   \
  |  | 4597|      0|                                         G ## _T                         \
  |  | 4598|      0|                                         )
  ------------------
 4760|      0|#endif /* MBEDTLS_ECP_DP_SECP192K1_ENABLED */
 4761|       |
 4762|      0|#if defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED)
 4763|      0|        case MBEDTLS_ECP_DP_SECP224K1:
  ------------------
  |  Branch (4763:9): [True: 0, False: 1]
  ------------------
 4764|      0|            grp->modp = ecp_mod_p224k1;
 4765|      0|            return LOAD_GROUP_A(secp224k1);
  ------------------
  |  | 4590|      0|#define LOAD_GROUP_A(G)   ecp_group_load(grp,            \
  |  | 4591|      0|                                         G ## _p,  sizeof(G ## _p),   \
  |  | 4592|      0|                                         G ## _a,  sizeof(G ## _a),   \
  |  | 4593|      0|                                         G ## _b,  sizeof(G ## _b),   \
  |  | 4594|      0|                                         G ## _gx, sizeof(G ## _gx),   \
  |  | 4595|      0|                                         G ## _gy, sizeof(G ## _gy),   \
  |  | 4596|      0|                                         G ## _n,  sizeof(G ## _n),   \
  |  | 4597|      0|                                         G ## _T                         \
  |  | 4598|      0|                                         )
  ------------------
 4766|      0|#endif /* MBEDTLS_ECP_DP_SECP224K1_ENABLED */
 4767|       |
 4768|      0|#if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
 4769|      0|        case MBEDTLS_ECP_DP_SECP256K1:
  ------------------
  |  Branch (4769:9): [True: 0, False: 1]
  ------------------
 4770|      0|            grp->modp = ecp_mod_p256k1;
 4771|      0|            return LOAD_GROUP_A(secp256k1);
  ------------------
  |  | 4590|      0|#define LOAD_GROUP_A(G)   ecp_group_load(grp,            \
  |  | 4591|      0|                                         G ## _p,  sizeof(G ## _p),   \
  |  | 4592|      0|                                         G ## _a,  sizeof(G ## _a),   \
  |  | 4593|      0|                                         G ## _b,  sizeof(G ## _b),   \
  |  | 4594|      0|                                         G ## _gx, sizeof(G ## _gx),   \
  |  | 4595|      0|                                         G ## _gy, sizeof(G ## _gy),   \
  |  | 4596|      0|                                         G ## _n,  sizeof(G ## _n),   \
  |  | 4597|      0|                                         G ## _T                         \
  |  | 4598|      0|                                         )
  ------------------
 4772|      0|#endif /* MBEDTLS_ECP_DP_SECP256K1_ENABLED */
 4773|       |
 4774|      0|#if defined(MBEDTLS_ECP_DP_BP256R1_ENABLED)
 4775|      0|        case MBEDTLS_ECP_DP_BP256R1:
  ------------------
  |  Branch (4775:9): [True: 0, False: 1]
  ------------------
 4776|      0|            return LOAD_GROUP_A(brainpoolP256r1);
  ------------------
  |  | 4590|      0|#define LOAD_GROUP_A(G)   ecp_group_load(grp,            \
  |  | 4591|      0|                                         G ## _p,  sizeof(G ## _p),   \
  |  | 4592|      0|                                         G ## _a,  sizeof(G ## _a),   \
  |  | 4593|      0|                                         G ## _b,  sizeof(G ## _b),   \
  |  | 4594|      0|                                         G ## _gx, sizeof(G ## _gx),   \
  |  | 4595|      0|                                         G ## _gy, sizeof(G ## _gy),   \
  |  | 4596|      0|                                         G ## _n,  sizeof(G ## _n),   \
  |  | 4597|      0|                                         G ## _T                         \
  |  | 4598|      0|                                         )
  ------------------
 4777|      0|#endif /* MBEDTLS_ECP_DP_BP256R1_ENABLED */
 4778|       |
 4779|      0|#if defined(MBEDTLS_ECP_DP_BP384R1_ENABLED)
 4780|      0|        case MBEDTLS_ECP_DP_BP384R1:
  ------------------
  |  Branch (4780:9): [True: 0, False: 1]
  ------------------
 4781|      0|            return LOAD_GROUP_A(brainpoolP384r1);
  ------------------
  |  | 4590|      0|#define LOAD_GROUP_A(G)   ecp_group_load(grp,            \
  |  | 4591|      0|                                         G ## _p,  sizeof(G ## _p),   \
  |  | 4592|      0|                                         G ## _a,  sizeof(G ## _a),   \
  |  | 4593|      0|                                         G ## _b,  sizeof(G ## _b),   \
  |  | 4594|      0|                                         G ## _gx, sizeof(G ## _gx),   \
  |  | 4595|      0|                                         G ## _gy, sizeof(G ## _gy),   \
  |  | 4596|      0|                                         G ## _n,  sizeof(G ## _n),   \
  |  | 4597|      0|                                         G ## _T                         \
  |  | 4598|      0|                                         )
  ------------------
 4782|      0|#endif /* MBEDTLS_ECP_DP_BP384R1_ENABLED */
 4783|       |
 4784|      0|#if defined(MBEDTLS_ECP_DP_BP512R1_ENABLED)
 4785|      0|        case MBEDTLS_ECP_DP_BP512R1:
  ------------------
  |  Branch (4785:9): [True: 0, False: 1]
  ------------------
 4786|      0|            return LOAD_GROUP_A(brainpoolP512r1);
  ------------------
  |  | 4590|      0|#define LOAD_GROUP_A(G)   ecp_group_load(grp,            \
  |  | 4591|      0|                                         G ## _p,  sizeof(G ## _p),   \
  |  | 4592|      0|                                         G ## _a,  sizeof(G ## _a),   \
  |  | 4593|      0|                                         G ## _b,  sizeof(G ## _b),   \
  |  | 4594|      0|                                         G ## _gx, sizeof(G ## _gx),   \
  |  | 4595|      0|                                         G ## _gy, sizeof(G ## _gy),   \
  |  | 4596|      0|                                         G ## _n,  sizeof(G ## _n),   \
  |  | 4597|      0|                                         G ## _T                         \
  |  | 4598|      0|                                         )
  ------------------
 4787|      0|#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: 1]
  ------------------
 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: 1]
  ------------------
 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: 1]
  ------------------
 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|      1|    }
 4805|      1|}
ecp_curves.c:ecp_group_load:
 4522|      1|{
 4523|      1|    ecp_mpi_load(&grp->P, p, plen);
 4524|      1|    if (a != NULL) {
  ------------------
  |  Branch (4524:9): [True: 0, False: 1]
  ------------------
 4525|      0|        ecp_mpi_load(&grp->A, a, alen);
 4526|      0|    }
 4527|      1|    ecp_mpi_load(&grp->B, b, blen);
 4528|      1|    ecp_mpi_load(&grp->N, n, nlen);
 4529|       |
 4530|      1|    ecp_mpi_load(&grp->G.X, gx, gxlen);
 4531|      1|    ecp_mpi_load(&grp->G.Y, gy, gylen);
 4532|      1|    ecp_mpi_set1(&grp->G.Z);
 4533|       |
 4534|      1|    grp->pbits = mbedtls_mpi_bitlen(&grp->P);
 4535|      1|    grp->nbits = mbedtls_mpi_bitlen(&grp->N);
 4536|       |
 4537|      1|    grp->h = 1;
 4538|       |
 4539|      1|    grp->T = (mbedtls_ecp_point *) T;
 4540|       |    /*
 4541|       |     * Set T_size to 0 to prevent T free by mbedtls_ecp_group_free.
 4542|       |     */
 4543|      1|    grp->T_size = 0;
 4544|       |
 4545|      1|    return 0;
 4546|      1|}
ecp_curves.c:ecp_mpi_load:
 4495|      5|{
 4496|      5|    X->s = 1;
 4497|      5|    X->n = (unsigned short) (len / sizeof(mbedtls_mpi_uint));
 4498|      5|    X->p = (mbedtls_mpi_uint *) p;
 4499|      5|}
ecp_curves.c:ecp_mpi_set1:
 4505|      1|{
 4506|      1|    X->s = 1;
 4507|      1|    X->n = 1;
 4508|      1|    X->p = (mbedtls_mpi_uint *) mpi_one; /* X->p will not be modified so the cast is safe */
 4509|      1|}
ecp_curves.c:sub32:
 4942|     55|{
 4943|     55|    *carry -= (*dst < src);
 4944|     55|    *dst -= src;
 4945|     55|}
ecp_curves.c:add32:
 4936|    176|{
 4937|    176|    *dst += src;
 4938|    176|    *carry += (*dst < src);
 4939|    176|}
ecp_curves.c:mbedtls_ecp_fix_negative:
 4982|      1|{
 4983|      1|    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|      8|    for (i = 0; i <= bits / 8 / sizeof(mbedtls_mpi_uint); i++) {
  ------------------
  |  Branch (4988:17): [True: 7, False: 1]
  ------------------
 4989|      7|        N->p[i] = ~(mbedtls_mpi_uint) 0 - N->p[i];
 4990|      7|    }
 4991|       |    /* Add 1, taking care of the carry. */
 4992|      1|    i = 0;
 4993|      1|    do {
 4994|      1|        ++N->p[i];
 4995|      1|    } while (N->p[i++] == 0 && i <= bits / 8 / sizeof(mbedtls_mpi_uint));
  ------------------
  |  Branch (4995:14): [True: 0, False: 1]
  |  Branch (4995:32): [True: 0, False: 0]
  ------------------
 4996|       |    /* Invert the sign.
 4997|       |     * Now N = N0 - 2^bits where N0 is the initial value of N. */
 4998|      1|    N->s = -1;
 4999|       |
 5000|       |    /* Add |c| * 2^bits to the absolute value. Since c and N are
 5001|       |     * negative, this adds c * 2^bits. */
 5002|      1|    mbedtls_mpi_uint msw = (mbedtls_mpi_uint) -c;
 5003|      1|#if defined(MBEDTLS_HAVE_INT64)
 5004|      1|    if (bits == 224) {
  ------------------
  |  Branch (5004:9): [True: 0, False: 1]
  ------------------
 5005|      0|        msw <<= 32;
 5006|      0|    }
 5007|      1|#endif
 5008|      1|    N->p[bits / 8 / sizeof(mbedtls_mpi_uint)] += msw;
 5009|      1|}
ecp_curves.c:ecp_mod_p384:
 5074|      3|{
 5075|      3|    INIT(384);
  ------------------
  |  | 4954|      3|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;                    \
  |  |  ------------------
  |  |  |  |  100|      3|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  |  |  ------------------
  |  | 4955|      3|    signed char c = 0, cc;                                              \
  |  | 4956|      3|    uint32_t cur;                                                       \
  |  | 4957|      3|    size_t i = 0, bits = (b);                                           \
  |  | 4958|      3|    /* N is the size of the product of two b-bit numbers, plus one */   \
  |  | 4959|      3|    /* limb for fix_negative */                                         \
  |  | 4960|      3|    MBEDTLS_MPI_CHK(mbedtls_mpi_grow(N, (b) * 2 / biL + 1));      \
  |  |  ------------------
  |  |  |  |   41|      3|    do                           \
  |  |  |  |   42|      3|    {                            \
  |  |  |  |   43|      3|        if ((ret = (f)) != 0) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:13): [True: 0, False: 3]
  |  |  |  |  ------------------
  |  |  |  |   44|      3|        goto cleanup;        \
  |  |  |  |   45|      3|    } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 4961|      3|    LOAD32;
  |  |  ------------------
  |  |  |  | 4908|      3|#define LOAD32      cur = A(i);
  |  |  |  |  ------------------
  |  |  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (4919:14): [True: 0, False: 3]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5076|       |
 5077|      3|    ADD(12); ADD(21); ADD(20);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(12); ADD(21); ADD(20);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(12); ADD(21); ADD(20);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
 5078|      3|    SUB(23);                                              NEXT;   // A0
  ------------------
  |  | 4948|      3|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(23);                                              NEXT;   // A0
  ------------------
  |  | 4964|      3|    STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4922|      3|    if (i % 2) {                                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4922:9): [True: 0, False: 3]
  |  |  |  |  ------------------
  |  |  |  | 4923|      0|        N->p[i/2] &= 0x00000000FFFFFFFF;          \
  |  |  |  | 4924|      0|        N->p[i/2] |= ((mbedtls_mpi_uint) cur) << 32;        \
  |  |  |  | 4925|      3|    } else {                                      \
  |  |  |  | 4926|      3|        N->p[i/2] &= 0xFFFFFFFF00000000;          \
  |  |  |  | 4927|      3|        N->p[i/2] |= (mbedtls_mpi_uint) cur;                \
  |  |  |  | 4928|      3|    }
  |  |  ------------------
  |  |                   STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4908|      3|#define LOAD32      cur = A(i);
  |  |  |  |  ------------------
  |  |  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (4919:14): [True: 3, False: 0]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 4965|      3|    cc = c; c = 0;              \
  |  | 4966|      3|    if (cc < 0)                \
  |  |  ------------------
  |  |  |  Branch (4966:9): [True: 0, False: 3]
  |  |  ------------------
  |  | 4967|      3|    sub32(&cur, -cc, &c); \
  |  | 4968|      3|    else                        \
  |  | 4969|      3|    add32(&cur, cc, &c);  \
  ------------------
 5079|       |
 5080|      3|    ADD(13); ADD(22); ADD(23);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(13); ADD(22); ADD(23);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(13); ADD(22); ADD(23);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
 5081|      3|    SUB(12); SUB(20);                                   NEXT;     // A2
  ------------------
  |  | 4948|      3|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(12); SUB(20);                                   NEXT;     // A2
  ------------------
  |  | 4948|      3|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(12); SUB(20);                                   NEXT;     // A2
  ------------------
  |  | 4964|      3|    STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4922|      3|    if (i % 2) {                                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4922:9): [True: 3, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 4923|      3|        N->p[i/2] &= 0x00000000FFFFFFFF;          \
  |  |  |  | 4924|      3|        N->p[i/2] |= ((mbedtls_mpi_uint) cur) << 32;        \
  |  |  |  | 4925|      3|    } else {                                      \
  |  |  |  | 4926|      0|        N->p[i/2] &= 0xFFFFFFFF00000000;          \
  |  |  |  | 4927|      0|        N->p[i/2] |= (mbedtls_mpi_uint) cur;                \
  |  |  |  | 4928|      0|    }
  |  |  ------------------
  |  |                   STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4908|      3|#define LOAD32      cur = A(i);
  |  |  |  |  ------------------
  |  |  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (4919:14): [True: 0, False: 3]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 4965|      3|    cc = c; c = 0;              \
  |  | 4966|      3|    if (cc < 0)                \
  |  |  ------------------
  |  |  |  Branch (4966:9): [True: 0, False: 3]
  |  |  ------------------
  |  | 4967|      3|    sub32(&cur, -cc, &c); \
  |  | 4968|      3|    else                        \
  |  | 4969|      3|    add32(&cur, cc, &c);  \
  ------------------
 5082|       |
 5083|      3|    ADD(14); ADD(23);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(14); ADD(23);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
 5084|      3|    SUB(13); SUB(21);                                   NEXT;     // A2
  ------------------
  |  | 4948|      3|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(13); SUB(21);                                   NEXT;     // A2
  ------------------
  |  | 4948|      3|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(13); SUB(21);                                   NEXT;     // A2
  ------------------
  |  | 4964|      3|    STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4922|      3|    if (i % 2) {                                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4922:9): [True: 0, False: 3]
  |  |  |  |  ------------------
  |  |  |  | 4923|      0|        N->p[i/2] &= 0x00000000FFFFFFFF;          \
  |  |  |  | 4924|      0|        N->p[i/2] |= ((mbedtls_mpi_uint) cur) << 32;        \
  |  |  |  | 4925|      3|    } else {                                      \
  |  |  |  | 4926|      3|        N->p[i/2] &= 0xFFFFFFFF00000000;          \
  |  |  |  | 4927|      3|        N->p[i/2] |= (mbedtls_mpi_uint) cur;                \
  |  |  |  | 4928|      3|    }
  |  |  ------------------
  |  |                   STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4908|      3|#define LOAD32      cur = A(i);
  |  |  |  |  ------------------
  |  |  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (4919:14): [True: 3, False: 0]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 4965|      3|    cc = c; c = 0;              \
  |  | 4966|      3|    if (cc < 0)                \
  |  |  ------------------
  |  |  |  Branch (4966:9): [True: 1, False: 2]
  |  |  ------------------
  |  | 4967|      3|    sub32(&cur, -cc, &c); \
  |  | 4968|      3|    else                        \
  |  | 4969|      3|    add32(&cur, cc, &c);  \
  ------------------
 5085|       |
 5086|      3|    ADD(15); ADD(12); ADD(20); ADD(21);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(15); ADD(12); ADD(20); ADD(21);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(15); ADD(12); ADD(20); ADD(21);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(15); ADD(12); ADD(20); ADD(21);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
 5087|      3|    SUB(14); SUB(22); SUB(23);                        NEXT;       // A3
  ------------------
  |  | 4948|      3|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(14); SUB(22); SUB(23);                        NEXT;       // A3
  ------------------
  |  | 4948|      3|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(14); SUB(22); SUB(23);                        NEXT;       // A3
  ------------------
  |  | 4948|      3|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(14); SUB(22); SUB(23);                        NEXT;       // A3
  ------------------
  |  | 4964|      3|    STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4922|      3|    if (i % 2) {                                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4922:9): [True: 3, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 4923|      3|        N->p[i/2] &= 0x00000000FFFFFFFF;          \
  |  |  |  | 4924|      3|        N->p[i/2] |= ((mbedtls_mpi_uint) cur) << 32;        \
  |  |  |  | 4925|      3|    } else {                                      \
  |  |  |  | 4926|      0|        N->p[i/2] &= 0xFFFFFFFF00000000;          \
  |  |  |  | 4927|      0|        N->p[i/2] |= (mbedtls_mpi_uint) cur;                \
  |  |  |  | 4928|      0|    }
  |  |  ------------------
  |  |                   STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4908|      3|#define LOAD32      cur = A(i);
  |  |  |  |  ------------------
  |  |  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (4919:14): [True: 0, False: 3]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 4965|      3|    cc = c; c = 0;              \
  |  | 4966|      3|    if (cc < 0)                \
  |  |  ------------------
  |  |  |  Branch (4966:9): [True: 0, False: 3]
  |  |  ------------------
  |  | 4967|      3|    sub32(&cur, -cc, &c); \
  |  | 4968|      3|    else                        \
  |  | 4969|      3|    add32(&cur, cc, &c);  \
  ------------------
 5088|       |
 5089|      3|    ADD(21); ADD(21); ADD(16); ADD(13); ADD(12); ADD(20); ADD(22);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(21); ADD(21); ADD(16); ADD(13); ADD(12); ADD(20); ADD(22);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(21); ADD(21); ADD(16); ADD(13); ADD(12); ADD(20); ADD(22);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(21); ADD(21); ADD(16); ADD(13); ADD(12); ADD(20); ADD(22);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(21); ADD(21); ADD(16); ADD(13); ADD(12); ADD(20); ADD(22);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(21); ADD(21); ADD(16); ADD(13); ADD(12); ADD(20); ADD(22);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(21); ADD(21); ADD(16); ADD(13); ADD(12); ADD(20); ADD(22);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
 5090|      3|    SUB(15); SUB(23); SUB(23);                        NEXT;       // A4
  ------------------
  |  | 4948|      3|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(15); SUB(23); SUB(23);                        NEXT;       // A4
  ------------------
  |  | 4948|      3|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(15); SUB(23); SUB(23);                        NEXT;       // A4
  ------------------
  |  | 4948|      3|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(15); SUB(23); SUB(23);                        NEXT;       // A4
  ------------------
  |  | 4964|      3|    STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4922|      3|    if (i % 2) {                                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4922:9): [True: 0, False: 3]
  |  |  |  |  ------------------
  |  |  |  | 4923|      0|        N->p[i/2] &= 0x00000000FFFFFFFF;          \
  |  |  |  | 4924|      0|        N->p[i/2] |= ((mbedtls_mpi_uint) cur) << 32;        \
  |  |  |  | 4925|      3|    } else {                                      \
  |  |  |  | 4926|      3|        N->p[i/2] &= 0xFFFFFFFF00000000;          \
  |  |  |  | 4927|      3|        N->p[i/2] |= (mbedtls_mpi_uint) cur;                \
  |  |  |  | 4928|      3|    }
  |  |  ------------------
  |  |                   STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4908|      3|#define LOAD32      cur = A(i);
  |  |  |  |  ------------------
  |  |  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (4919:14): [True: 3, False: 0]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 4965|      3|    cc = c; c = 0;              \
  |  | 4966|      3|    if (cc < 0)                \
  |  |  ------------------
  |  |  |  Branch (4966:9): [True: 0, False: 3]
  |  |  ------------------
  |  | 4967|      3|    sub32(&cur, -cc, &c); \
  |  | 4968|      3|    else                        \
  |  | 4969|      3|    add32(&cur, cc, &c);  \
  ------------------
 5091|       |
 5092|      3|    ADD(22); ADD(22); ADD(17); ADD(14); ADD(13); ADD(21); ADD(23);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(22); ADD(22); ADD(17); ADD(14); ADD(13); ADD(21); ADD(23);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(22); ADD(22); ADD(17); ADD(14); ADD(13); ADD(21); ADD(23);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(22); ADD(22); ADD(17); ADD(14); ADD(13); ADD(21); ADD(23);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(22); ADD(22); ADD(17); ADD(14); ADD(13); ADD(21); ADD(23);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(22); ADD(22); ADD(17); ADD(14); ADD(13); ADD(21); ADD(23);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(22); ADD(22); ADD(17); ADD(14); ADD(13); ADD(21); ADD(23);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
 5093|      3|    SUB(16);                                              NEXT;   // A5
  ------------------
  |  | 4948|      3|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(16);                                              NEXT;   // A5
  ------------------
  |  | 4964|      3|    STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4922|      3|    if (i % 2) {                                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4922:9): [True: 3, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 4923|      3|        N->p[i/2] &= 0x00000000FFFFFFFF;          \
  |  |  |  | 4924|      3|        N->p[i/2] |= ((mbedtls_mpi_uint) cur) << 32;        \
  |  |  |  | 4925|      3|    } else {                                      \
  |  |  |  | 4926|      0|        N->p[i/2] &= 0xFFFFFFFF00000000;          \
  |  |  |  | 4927|      0|        N->p[i/2] |= (mbedtls_mpi_uint) cur;                \
  |  |  |  | 4928|      0|    }
  |  |  ------------------
  |  |                   STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4908|      3|#define LOAD32      cur = A(i);
  |  |  |  |  ------------------
  |  |  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (4919:14): [True: 0, False: 3]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 4965|      3|    cc = c; c = 0;              \
  |  | 4966|      3|    if (cc < 0)                \
  |  |  ------------------
  |  |  |  Branch (4966:9): [True: 0, False: 3]
  |  |  ------------------
  |  | 4967|      3|    sub32(&cur, -cc, &c); \
  |  | 4968|      3|    else                        \
  |  | 4969|      3|    add32(&cur, cc, &c);  \
  ------------------
 5094|       |
 5095|      3|    ADD(23); ADD(23); ADD(18); ADD(15); ADD(14); ADD(22);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(23); ADD(23); ADD(18); ADD(15); ADD(14); ADD(22);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(23); ADD(23); ADD(18); ADD(15); ADD(14); ADD(22);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(23); ADD(23); ADD(18); ADD(15); ADD(14); ADD(22);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(23); ADD(23); ADD(18); ADD(15); ADD(14); ADD(22);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(23); ADD(23); ADD(18); ADD(15); ADD(14); ADD(22);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
 5096|      3|    SUB(17);                                              NEXT;   // A6
  ------------------
  |  | 4948|      3|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(17);                                              NEXT;   // A6
  ------------------
  |  | 4964|      3|    STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4922|      3|    if (i % 2) {                                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4922:9): [True: 0, False: 3]
  |  |  |  |  ------------------
  |  |  |  | 4923|      0|        N->p[i/2] &= 0x00000000FFFFFFFF;          \
  |  |  |  | 4924|      0|        N->p[i/2] |= ((mbedtls_mpi_uint) cur) << 32;        \
  |  |  |  | 4925|      3|    } else {                                      \
  |  |  |  | 4926|      3|        N->p[i/2] &= 0xFFFFFFFF00000000;          \
  |  |  |  | 4927|      3|        N->p[i/2] |= (mbedtls_mpi_uint) cur;                \
  |  |  |  | 4928|      3|    }
  |  |  ------------------
  |  |                   STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4908|      3|#define LOAD32      cur = A(i);
  |  |  |  |  ------------------
  |  |  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (4919:14): [True: 3, False: 0]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 4965|      3|    cc = c; c = 0;              \
  |  | 4966|      3|    if (cc < 0)                \
  |  |  ------------------
  |  |  |  Branch (4966:9): [True: 0, False: 3]
  |  |  ------------------
  |  | 4967|      3|    sub32(&cur, -cc, &c); \
  |  | 4968|      3|    else                        \
  |  | 4969|      3|    add32(&cur, cc, &c);  \
  ------------------
 5097|       |
 5098|      3|    ADD(19); ADD(16); ADD(15); ADD(23);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(19); ADD(16); ADD(15); ADD(23);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(19); ADD(16); ADD(15); ADD(23);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(19); ADD(16); ADD(15); ADD(23);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
 5099|      3|    SUB(18);                                              NEXT;   // A7
  ------------------
  |  | 4948|      3|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(18);                                              NEXT;   // A7
  ------------------
  |  | 4964|      3|    STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4922|      3|    if (i % 2) {                                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4922:9): [True: 3, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 4923|      3|        N->p[i/2] &= 0x00000000FFFFFFFF;          \
  |  |  |  | 4924|      3|        N->p[i/2] |= ((mbedtls_mpi_uint) cur) << 32;        \
  |  |  |  | 4925|      3|    } else {                                      \
  |  |  |  | 4926|      0|        N->p[i/2] &= 0xFFFFFFFF00000000;          \
  |  |  |  | 4927|      0|        N->p[i/2] |= (mbedtls_mpi_uint) cur;                \
  |  |  |  | 4928|      0|    }
  |  |  ------------------
  |  |                   STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4908|      3|#define LOAD32      cur = A(i);
  |  |  |  |  ------------------
  |  |  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (4919:14): [True: 0, False: 3]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 4965|      3|    cc = c; c = 0;              \
  |  | 4966|      3|    if (cc < 0)                \
  |  |  ------------------
  |  |  |  Branch (4966:9): [True: 0, False: 3]
  |  |  ------------------
  |  | 4967|      3|    sub32(&cur, -cc, &c); \
  |  | 4968|      3|    else                        \
  |  | 4969|      3|    add32(&cur, cc, &c);  \
  ------------------
 5100|       |
 5101|      3|    ADD(20); ADD(17); ADD(16);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(20); ADD(17); ADD(16);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(20); ADD(17); ADD(16);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
 5102|      3|    SUB(19);                                              NEXT;   // A8
  ------------------
  |  | 4948|      3|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(19);                                              NEXT;   // A8
  ------------------
  |  | 4964|      3|    STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4922|      3|    if (i % 2) {                                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4922:9): [True: 0, False: 3]
  |  |  |  |  ------------------
  |  |  |  | 4923|      0|        N->p[i/2] &= 0x00000000FFFFFFFF;          \
  |  |  |  | 4924|      0|        N->p[i/2] |= ((mbedtls_mpi_uint) cur) << 32;        \
  |  |  |  | 4925|      3|    } else {                                      \
  |  |  |  | 4926|      3|        N->p[i/2] &= 0xFFFFFFFF00000000;          \
  |  |  |  | 4927|      3|        N->p[i/2] |= (mbedtls_mpi_uint) cur;                \
  |  |  |  | 4928|      3|    }
  |  |  ------------------
  |  |                   STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4908|      3|#define LOAD32      cur = A(i);
  |  |  |  |  ------------------
  |  |  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (4919:14): [True: 3, False: 0]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 4965|      3|    cc = c; c = 0;              \
  |  | 4966|      3|    if (cc < 0)                \
  |  |  ------------------
  |  |  |  Branch (4966:9): [True: 0, False: 3]
  |  |  ------------------
  |  | 4967|      3|    sub32(&cur, -cc, &c); \
  |  | 4968|      3|    else                        \
  |  | 4969|      3|    add32(&cur, cc, &c);  \
  ------------------
 5103|       |
 5104|      3|    ADD(21); ADD(18); ADD(17);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(21); ADD(18); ADD(17);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(21); ADD(18); ADD(17);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
 5105|      3|    SUB(20);                                              NEXT;   // A9
  ------------------
  |  | 4948|      3|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(20);                                              NEXT;   // A9
  ------------------
  |  | 4964|      3|    STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4922|      3|    if (i % 2) {                                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4922:9): [True: 3, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 4923|      3|        N->p[i/2] &= 0x00000000FFFFFFFF;          \
  |  |  |  | 4924|      3|        N->p[i/2] |= ((mbedtls_mpi_uint) cur) << 32;        \
  |  |  |  | 4925|      3|    } else {                                      \
  |  |  |  | 4926|      0|        N->p[i/2] &= 0xFFFFFFFF00000000;          \
  |  |  |  | 4927|      0|        N->p[i/2] |= (mbedtls_mpi_uint) cur;                \
  |  |  |  | 4928|      0|    }
  |  |  ------------------
  |  |                   STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4908|      3|#define LOAD32      cur = A(i);
  |  |  |  |  ------------------
  |  |  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (4919:14): [True: 0, False: 3]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 4965|      3|    cc = c; c = 0;              \
  |  | 4966|      3|    if (cc < 0)                \
  |  |  ------------------
  |  |  |  Branch (4966:9): [True: 0, False: 3]
  |  |  ------------------
  |  | 4967|      3|    sub32(&cur, -cc, &c); \
  |  | 4968|      3|    else                        \
  |  | 4969|      3|    add32(&cur, cc, &c);  \
  ------------------
 5106|       |
 5107|      3|    ADD(22); ADD(19); ADD(18);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(22); ADD(19); ADD(18);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(22); ADD(19); ADD(18);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
 5108|      3|    SUB(21);                                              NEXT;   // A10
  ------------------
  |  | 4948|      3|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(21);                                              NEXT;   // A10
  ------------------
  |  | 4964|      3|    STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4922|      3|    if (i % 2) {                                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4922:9): [True: 0, False: 3]
  |  |  |  |  ------------------
  |  |  |  | 4923|      0|        N->p[i/2] &= 0x00000000FFFFFFFF;          \
  |  |  |  | 4924|      0|        N->p[i/2] |= ((mbedtls_mpi_uint) cur) << 32;        \
  |  |  |  | 4925|      3|    } else {                                      \
  |  |  |  | 4926|      3|        N->p[i/2] &= 0xFFFFFFFF00000000;          \
  |  |  |  | 4927|      3|        N->p[i/2] |= (mbedtls_mpi_uint) cur;                \
  |  |  |  | 4928|      3|    }
  |  |  ------------------
  |  |                   STORE32; i++; LOAD32;       \
  |  |  ------------------
  |  |  |  | 4908|      3|#define LOAD32      cur = A(i);
  |  |  |  |  ------------------
  |  |  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (4919:14): [True: 3, False: 0]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 4965|      3|    cc = c; c = 0;              \
  |  | 4966|      3|    if (cc < 0)                \
  |  |  ------------------
  |  |  |  Branch (4966:9): [True: 0, False: 3]
  |  |  ------------------
  |  | 4967|      3|    sub32(&cur, -cc, &c); \
  |  | 4968|      3|    else                        \
  |  | 4969|      3|    add32(&cur, cc, &c);  \
  ------------------
 5109|       |
 5110|      3|    ADD(23); ADD(20); ADD(19);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(23); ADD(20); ADD(19);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  ADD(23); ADD(20); ADD(19);
  ------------------
  |  | 4947|      3|#define ADD(j)    add32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
 5111|      3|    SUB(22);                                              LAST;   // A11
  ------------------
  |  | 4948|      3|#define SUB(j)    sub32(&cur, A(j), &c);
  |  |  ------------------
  |  |  |  | 4919|      3|#define A(j) (j) % 2 ? (uint32_t) (N->p[(j)/2] >> 32) : \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4919:14): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  |  | 4920|      3|    (uint32_t) (N->p[(j)/2])
  |  |  ------------------
  ------------------
                  SUB(22);                                              LAST;   // A11
  ------------------
  |  | 4972|      3|    STORE32; i++;                               \
  |  |  ------------------
  |  |  |  | 4922|      3|    if (i % 2) {                                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4922:9): [True: 3, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 4923|      3|        N->p[i/2] &= 0x00000000FFFFFFFF;          \
  |  |  |  | 4924|      3|        N->p[i/2] |= ((mbedtls_mpi_uint) cur) << 32;        \
  |  |  |  | 4925|      3|    } else {                                      \
  |  |  |  | 4926|      0|        N->p[i/2] &= 0xFFFFFFFF00000000;          \
  |  |  |  | 4927|      0|        N->p[i/2] |= (mbedtls_mpi_uint) cur;                \
  |  |  |  | 4928|      0|    }
  |  |  ------------------
  |  | 4973|      3|    cur = c > 0 ? c : 0; STORE32;               \
  |  |  ------------------
  |  |  |  | 4922|      3|    if (i % 2) {                                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4922:9): [True: 0, False: 3]
  |  |  |  |  ------------------
  |  |  |  | 4923|      0|        N->p[i/2] &= 0x00000000FFFFFFFF;          \
  |  |  |  | 4924|      0|        N->p[i/2] |= ((mbedtls_mpi_uint) cur) << 32;        \
  |  |  |  | 4925|      3|    } else {                                      \
  |  |  |  | 4926|      3|        N->p[i/2] &= 0xFFFFFFFF00000000;          \
  |  |  |  | 4927|      3|        N->p[i/2] |= (mbedtls_mpi_uint) cur;                \
  |  |  |  | 4928|      3|    }
  |  |  ------------------
  |  |  |  Branch (4973:11): [True: 1, False: 2]
  |  |  ------------------
  |  | 4974|     42|    cur = 0; while (++i < MAX32) { STORE32; }  \
  |  |  ------------------
  |  |  |  | 4918|     42|#define MAX32       N->n * 2
  |  |  ------------------
  |  |                   cur = 0; while (++i < MAX32) { STORE32; }  \
  |  |  ------------------
  |  |  |  | 4922|     39|    if (i % 2) {                                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (4922:9): [True: 21, False: 18]
  |  |  |  |  ------------------
  |  |  |  | 4923|     21|        N->p[i/2] &= 0x00000000FFFFFFFF;          \
  |  |  |  | 4924|     21|        N->p[i/2] |= ((mbedtls_mpi_uint) cur) << 32;        \
  |  |  |  | 4925|     21|    } else {                                      \
  |  |  |  | 4926|     18|        N->p[i/2] &= 0xFFFFFFFF00000000;          \
  |  |  |  | 4927|     18|        N->p[i/2] |= (mbedtls_mpi_uint) cur;                \
  |  |  |  | 4928|     18|    }
  |  |  ------------------
  |  |  |  Branch (4974:21): [True: 39, False: 3]
  |  |  ------------------
  |  | 4975|      3|    if (c < 0) mbedtls_ecp_fix_negative(N, c, bits);
  |  |  ------------------
  |  |  |  Branch (4975:9): [True: 1, False: 2]
  |  |  ------------------
  ------------------
 5112|       |
 5113|      3|cleanup:
 5114|      3|    return ret;
 5115|      3|}

mbedtls_entropy_init:
   28|     42|{
   29|     42|    ctx->source_count = 0;
   30|     42|    memset(ctx->source, 0, sizeof(ctx->source));
   31|       |
   32|     42|#if defined(MBEDTLS_THREADING_C)
   33|     42|    mbedtls_mutex_init(&ctx->mutex);
   34|     42|#endif
   35|       |
   36|     42|    ctx->accumulator_started = 0;
   37|     42|    mbedtls_md_init(&ctx->accumulator);
   38|       |
   39|       |    /* Reminder: Update ENTROPY_HAVE_STRONG in the test files
   40|       |     *           when adding more strong entropy sources here. */
   41|       |
   42|     42|#if !defined(MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES)
   43|     42|#if !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
   44|     42|    mbedtls_entropy_add_source(ctx, mbedtls_platform_entropy_poll, NULL,
   45|     42|                               MBEDTLS_ENTROPY_MIN_PLATFORM,
  ------------------
  |  |   24|     42|#define MBEDTLS_ENTROPY_MIN_PLATFORM     32     /**< Minimum for platform source    */
  ------------------
   46|     42|                               MBEDTLS_ENTROPY_SOURCE_STRONG);
  ------------------
  |  |   70|     42|#define MBEDTLS_ENTROPY_SOURCE_STRONG   1       /**< Entropy source is strong   */
  ------------------
   47|     42|#endif
   48|       |#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
   49|       |    mbedtls_entropy_add_source(ctx, mbedtls_hardware_poll, NULL,
   50|       |                               MBEDTLS_ENTROPY_MIN_HARDWARE,
   51|       |                               MBEDTLS_ENTROPY_SOURCE_STRONG);
   52|       |#endif
   53|     42|#if defined(MBEDTLS_ENTROPY_NV_SEED)
   54|     42|    mbedtls_entropy_add_source(ctx, mbedtls_nv_seed_poll, NULL,
   55|     42|                               MBEDTLS_ENTROPY_BLOCK_SIZE,
  ------------------
  |  |   24|     42|#define MBEDTLS_ENTROPY_BLOCK_SIZE      64      /**< Block size of entropy accumulator (SHA-512) */
  ------------------
   56|     42|                               MBEDTLS_ENTROPY_SOURCE_STRONG);
  ------------------
  |  |   70|     42|#define MBEDTLS_ENTROPY_SOURCE_STRONG   1       /**< Entropy source is strong   */
  ------------------
   57|     42|    ctx->initial_entropy_run = 0;
   58|     42|#endif
   59|     42|#endif /* MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES */
   60|     42|}
mbedtls_entropy_free:
   63|     42|{
   64|     42|    if (ctx == NULL) {
  ------------------
  |  Branch (64:9): [True: 0, False: 42]
  ------------------
   65|      0|        return;
   66|      0|    }
   67|       |
   68|       |    /* If the context was already free, don't call free() again.
   69|       |     * This is important for mutexes which don't allow double-free. */
   70|     42|    if (ctx->accumulator_started == -1) {
  ------------------
  |  Branch (70:9): [True: 0, False: 42]
  ------------------
   71|      0|        return;
   72|      0|    }
   73|       |
   74|     42|#if defined(MBEDTLS_THREADING_C)
   75|     42|    mbedtls_mutex_free(&ctx->mutex);
   76|     42|#endif
   77|     42|    mbedtls_md_free(&ctx->accumulator);
   78|     42|#if defined(MBEDTLS_ENTROPY_NV_SEED)
   79|     42|    ctx->initial_entropy_run = 0;
   80|     42|#endif
   81|     42|    ctx->source_count = 0;
   82|     42|    mbedtls_platform_zeroize(ctx->source, sizeof(ctx->source));
   83|     42|    ctx->accumulator_started = -1;
   84|     42|}
mbedtls_entropy_add_source:
   89|     84|{
   90|     84|    int idx, ret = 0;
   91|       |
   92|     84|#if defined(MBEDTLS_THREADING_C)
   93|     84|    if ((ret = mbedtls_mutex_lock(&ctx->mutex)) != 0) {
  ------------------
  |  Branch (93:9): [True: 0, False: 84]
  ------------------
   94|      0|        return ret;
   95|      0|    }
   96|     84|#endif
   97|       |
   98|     84|    idx = ctx->source_count;
   99|     84|    if (idx >= MBEDTLS_ENTROPY_MAX_SOURCES) {
  ------------------
  |  |   58|     84|#define MBEDTLS_ENTROPY_MAX_SOURCES     20      /**< Maximum number of sources supported */
  ------------------
  |  Branch (99:9): [True: 0, False: 84]
  ------------------
  100|      0|        ret = MBEDTLS_ERR_ENTROPY_MAX_SOURCES;
  ------------------
  |  |   41|      0|#define MBEDTLS_ERR_ENTROPY_MAX_SOURCES                   -0x003E
  ------------------
  101|      0|        goto exit;
  102|      0|    }
  103|       |
  104|     84|    ctx->source[idx].f_source  = f_source;
  105|     84|    ctx->source[idx].p_source  = p_source;
  106|     84|    ctx->source[idx].threshold = threshold;
  107|     84|    ctx->source[idx].strong    = strong;
  108|       |
  109|     84|    ctx->source_count++;
  110|       |
  111|     84|exit:
  112|     84|#if defined(MBEDTLS_THREADING_C)
  113|     84|    if (mbedtls_mutex_unlock(&ctx->mutex) != 0) {
  ------------------
  |  Branch (113:9): [True: 0, False: 84]
  ------------------
  114|      0|        return MBEDTLS_ERR_THREADING_MUTEX_ERROR;
  ------------------
  |  |   25|      0|#define MBEDTLS_ERR_THREADING_MUTEX_ERROR                 -0x001E
  ------------------
  115|      0|    }
  116|     84|#endif
  117|       |
  118|     84|    return ret;
  119|     84|}
mbedtls_entropy_func:
  271|     42|{
  272|     42|    int ret, count = 0, i, thresholds_reached;
  273|     42|    size_t strong_size;
  274|     42|    mbedtls_entropy_context *ctx = (mbedtls_entropy_context *) data;
  275|     42|    unsigned char buf[MBEDTLS_ENTROPY_BLOCK_SIZE];
  276|       |
  277|     42|    if (len > MBEDTLS_ENTROPY_BLOCK_SIZE) {
  ------------------
  |  |   24|     42|#define MBEDTLS_ENTROPY_BLOCK_SIZE      64      /**< Block size of entropy accumulator (SHA-512) */
  ------------------
  |  Branch (277:9): [True: 0, False: 42]
  ------------------
  278|      0|        return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
  ------------------
  |  |   39|      0|#define MBEDTLS_ERR_ENTROPY_SOURCE_FAILED                 -0x003C
  ------------------
  279|      0|    }
  280|       |
  281|     42|#if defined(MBEDTLS_ENTROPY_NV_SEED)
  282|       |    /* Update the NV entropy seed before generating any entropy for outside
  283|       |     * use.
  284|       |     */
  285|     42|    if (ctx->initial_entropy_run == 0) {
  ------------------
  |  Branch (285:9): [True: 21, False: 21]
  ------------------
  286|     21|        ctx->initial_entropy_run = 1;
  287|     21|        if ((ret = mbedtls_entropy_update_nv_seed(ctx)) != 0) {
  ------------------
  |  Branch (287:13): [True: 21, False: 0]
  ------------------
  288|     21|            return ret;
  289|     21|        }
  290|     21|    }
  291|     21|#endif
  292|       |
  293|     21|#if defined(MBEDTLS_THREADING_C)
  294|     21|    if ((ret = mbedtls_mutex_lock(&ctx->mutex)) != 0) {
  ------------------
  |  Branch (294:9): [True: 0, False: 21]
  ------------------
  295|      0|        return ret;
  296|      0|    }
  297|     21|#endif
  298|       |
  299|       |    /*
  300|       |     * Always gather extra entropy before a call
  301|       |     */
  302|     21|    do {
  303|     21|        if (count++ > ENTROPY_MAX_LOOP) {
  ------------------
  |  |   25|     21|#define ENTROPY_MAX_LOOP    256     /**< Maximum amount to loop before error */
  ------------------
  |  Branch (303:13): [True: 0, False: 21]
  ------------------
  304|      0|            ret = MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
  ------------------
  |  |   39|      0|#define MBEDTLS_ERR_ENTROPY_SOURCE_FAILED                 -0x003C
  ------------------
  305|      0|            goto exit;
  306|      0|        }
  307|       |
  308|     21|        if ((ret = entropy_gather_internal(ctx)) != 0) {
  ------------------
  |  Branch (308:13): [True: 21, False: 0]
  ------------------
  309|     21|            goto exit;
  310|     21|        }
  311|       |
  312|      0|        thresholds_reached = 1;
  313|      0|        strong_size = 0;
  314|      0|        for (i = 0; i < ctx->source_count; i++) {
  ------------------
  |  Branch (314:21): [True: 0, False: 0]
  ------------------
  315|      0|            if (ctx->source[i].size < ctx->source[i].threshold) {
  ------------------
  |  Branch (315:17): [True: 0, False: 0]
  ------------------
  316|      0|                thresholds_reached = 0;
  317|      0|            }
  318|      0|            if (ctx->source[i].strong == MBEDTLS_ENTROPY_SOURCE_STRONG) {
  ------------------
  |  |   70|      0|#define MBEDTLS_ENTROPY_SOURCE_STRONG   1       /**< Entropy source is strong   */
  ------------------
  |  Branch (318:17): [True: 0, False: 0]
  ------------------
  319|      0|                strong_size += ctx->source[i].size;
  320|      0|            }
  321|      0|        }
  322|      0|    } while (!thresholds_reached || strong_size < MBEDTLS_ENTROPY_BLOCK_SIZE);
  ------------------
  |  |   24|      0|#define MBEDTLS_ENTROPY_BLOCK_SIZE      64      /**< Block size of entropy accumulator (SHA-512) */
  ------------------
  |  Branch (322:14): [True: 0, False: 0]
  |  Branch (322:37): [True: 0, False: 0]
  ------------------
  323|       |
  324|      0|    memset(buf, 0, MBEDTLS_ENTROPY_BLOCK_SIZE);
  ------------------
  |  |   24|      0|#define MBEDTLS_ENTROPY_BLOCK_SIZE      64      /**< Block size of entropy accumulator (SHA-512) */
  ------------------
  325|       |
  326|       |    /*
  327|       |     * Note that at this stage it is assumed that the accumulator was started
  328|       |     * in a previous call to entropy_update(). If this is not guaranteed, the
  329|       |     * code below will fail.
  330|       |     */
  331|      0|    if ((ret = mbedtls_md_finish(&ctx->accumulator, buf)) != 0) {
  ------------------
  |  Branch (331:9): [True: 0, False: 0]
  ------------------
  332|      0|        goto exit;
  333|      0|    }
  334|       |
  335|       |    /*
  336|       |     * Reset accumulator and counters and recycle existing entropy
  337|       |     */
  338|      0|    mbedtls_md_free(&ctx->accumulator);
  339|      0|    mbedtls_md_init(&ctx->accumulator);
  340|      0|    ret = mbedtls_md_setup(&ctx->accumulator,
  341|      0|                           mbedtls_md_info_from_type(MBEDTLS_ENTROPY_MD), 0);
  ------------------
  |  |   23|      0|#define MBEDTLS_ENTROPY_MD  MBEDTLS_MD_SHA512
  ------------------
  342|      0|    if (ret != 0) {
  ------------------
  |  Branch (342:9): [True: 0, False: 0]
  ------------------
  343|      0|        goto exit;
  344|      0|    }
  345|      0|    ret = mbedtls_md_starts(&ctx->accumulator);
  346|      0|    if (ret != 0) {
  ------------------
  |  Branch (346:9): [True: 0, False: 0]
  ------------------
  347|      0|        goto exit;
  348|      0|    }
  349|      0|    if ((ret = mbedtls_md_update(&ctx->accumulator, buf,
  ------------------
  |  Branch (349:9): [True: 0, False: 0]
  ------------------
  350|      0|                                 MBEDTLS_ENTROPY_BLOCK_SIZE)) != 0) {
  ------------------
  |  |   24|      0|#define MBEDTLS_ENTROPY_BLOCK_SIZE      64      /**< Block size of entropy accumulator (SHA-512) */
  ------------------
  351|      0|        goto exit;
  352|      0|    }
  353|       |
  354|       |    /*
  355|       |     * Perform second hashing on entropy
  356|       |     */
  357|      0|    if ((ret = mbedtls_md(mbedtls_md_info_from_type(MBEDTLS_ENTROPY_MD),
  ------------------
  |  |   23|      0|#define MBEDTLS_ENTROPY_MD  MBEDTLS_MD_SHA512
  ------------------
  |  Branch (357:9): [True: 0, False: 0]
  ------------------
  358|      0|                          buf, MBEDTLS_ENTROPY_BLOCK_SIZE, buf)) != 0) {
  ------------------
  |  |   24|      0|#define MBEDTLS_ENTROPY_BLOCK_SIZE      64      /**< Block size of entropy accumulator (SHA-512) */
  ------------------
  359|      0|        goto exit;
  360|      0|    }
  361|       |
  362|      0|    for (i = 0; i < ctx->source_count; i++) {
  ------------------
  |  Branch (362:17): [True: 0, False: 0]
  ------------------
  363|      0|        ctx->source[i].size = 0;
  364|      0|    }
  365|       |
  366|      0|    memcpy(output, buf, len);
  367|       |
  368|      0|    ret = 0;
  369|       |
  370|     21|exit:
  371|     21|    mbedtls_platform_zeroize(buf, sizeof(buf));
  372|       |
  373|     21|#if defined(MBEDTLS_THREADING_C)
  374|     21|    if (mbedtls_mutex_unlock(&ctx->mutex) != 0) {
  ------------------
  |  Branch (374:9): [True: 0, False: 21]
  ------------------
  375|      0|        return MBEDTLS_ERR_THREADING_MUTEX_ERROR;
  ------------------
  |  |   25|      0|#define MBEDTLS_ERR_THREADING_MUTEX_ERROR                 -0x001E
  ------------------
  376|      0|    }
  377|     21|#endif
  378|       |
  379|     21|    return ret;
  380|     21|}
mbedtls_entropy_update_nv_seed:
  384|     21|{
  385|     21|    int ret = MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR;
  ------------------
  |  |   47|     21|#define MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR                 -0x003F
  ------------------
  386|     21|    unsigned char buf[MBEDTLS_ENTROPY_BLOCK_SIZE];
  387|       |
  388|       |    /* Read new seed  and write it to NV */
  389|     21|    if ((ret = mbedtls_entropy_func(ctx, buf, MBEDTLS_ENTROPY_BLOCK_SIZE)) != 0) {
  ------------------
  |  |   24|     21|#define MBEDTLS_ENTROPY_BLOCK_SIZE      64      /**< Block size of entropy accumulator (SHA-512) */
  ------------------
  |  Branch (389:9): [True: 21, False: 0]
  ------------------
  390|     21|        return ret;
  391|     21|    }
  392|       |
  393|      0|    if (mbedtls_nv_seed_write(buf, MBEDTLS_ENTROPY_BLOCK_SIZE) < 0) {
  ------------------
  |  |   24|      0|#define MBEDTLS_ENTROPY_BLOCK_SIZE      64      /**< Block size of entropy accumulator (SHA-512) */
  ------------------
  |  Branch (393:9): [True: 0, False: 0]
  ------------------
  394|      0|        return MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR;
  ------------------
  |  |   47|      0|#define MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR                 -0x003F
  ------------------
  395|      0|    }
  396|       |
  397|       |    /* Manually update the remaining stream with a separator value to diverge */
  398|      0|    memset(buf, 0, MBEDTLS_ENTROPY_BLOCK_SIZE);
  ------------------
  |  |   24|      0|#define MBEDTLS_ENTROPY_BLOCK_SIZE      64      /**< Block size of entropy accumulator (SHA-512) */
  ------------------
  399|      0|    ret = mbedtls_entropy_update_manual(ctx, buf, MBEDTLS_ENTROPY_BLOCK_SIZE);
  ------------------
  |  |   24|      0|#define MBEDTLS_ENTROPY_BLOCK_SIZE      64      /**< Block size of entropy accumulator (SHA-512) */
  ------------------
  400|       |
  401|      0|    return ret;
  402|      0|}
entropy.c:entropy_update:
  126|     21|{
  127|     21|    unsigned char header[2];
  128|     21|    unsigned char tmp[MBEDTLS_ENTROPY_BLOCK_SIZE];
  129|     21|    size_t use_len = len;
  130|     21|    const unsigned char *p = data;
  131|     21|    int ret = 0;
  132|       |
  133|     21|    if (use_len > MBEDTLS_ENTROPY_BLOCK_SIZE) {
  ------------------
  |  |   24|     21|#define MBEDTLS_ENTROPY_BLOCK_SIZE      64      /**< Block size of entropy accumulator (SHA-512) */
  ------------------
  |  Branch (133:9): [True: 21, False: 0]
  ------------------
  134|     21|        if ((ret = mbedtls_md(mbedtls_md_info_from_type(MBEDTLS_ENTROPY_MD),
  ------------------
  |  |   23|     21|#define MBEDTLS_ENTROPY_MD  MBEDTLS_MD_SHA512
  ------------------
  |  Branch (134:13): [True: 0, False: 21]
  ------------------
  135|     21|                              data, len, tmp)) != 0) {
  136|      0|            goto cleanup;
  137|      0|        }
  138|     21|        p = tmp;
  139|     21|        use_len = MBEDTLS_ENTROPY_BLOCK_SIZE;
  ------------------
  |  |   24|     21|#define MBEDTLS_ENTROPY_BLOCK_SIZE      64      /**< Block size of entropy accumulator (SHA-512) */
  ------------------
  140|     21|    }
  141|       |
  142|     21|    header[0] = source_id;
  143|     21|    header[1] = use_len & 0xFF;
  144|       |
  145|       |    /*
  146|       |     * Start the accumulator if this has not already happened. Note that
  147|       |     * it is sufficient to start the accumulator here only because all calls to
  148|       |     * gather entropy eventually execute this code.
  149|       |     */
  150|     21|    if (ctx->accumulator_started == 0) {
  ------------------
  |  Branch (150:9): [True: 21, False: 0]
  ------------------
  151|     21|        ret = mbedtls_md_setup(&ctx->accumulator,
  152|     21|                               mbedtls_md_info_from_type(MBEDTLS_ENTROPY_MD), 0);
  ------------------
  |  |   23|     21|#define MBEDTLS_ENTROPY_MD  MBEDTLS_MD_SHA512
  ------------------
  153|     21|        if (ret != 0) {
  ------------------
  |  Branch (153:13): [True: 0, False: 21]
  ------------------
  154|      0|            goto cleanup;
  155|      0|        }
  156|     21|        ret = mbedtls_md_starts(&ctx->accumulator);
  157|     21|        if (ret != 0) {
  ------------------
  |  Branch (157:13): [True: 0, False: 21]
  ------------------
  158|      0|            goto cleanup;
  159|      0|        }
  160|     21|        ctx->accumulator_started = 1;
  161|     21|    }
  162|     21|    if ((ret = mbedtls_md_update(&ctx->accumulator, header, 2)) != 0) {
  ------------------
  |  Branch (162:9): [True: 0, False: 21]
  ------------------
  163|      0|        goto cleanup;
  164|      0|    }
  165|     21|    ret = mbedtls_md_update(&ctx->accumulator, p, use_len);
  166|       |
  167|     21|cleanup:
  168|     21|    mbedtls_platform_zeroize(tmp, sizeof(tmp));
  169|       |
  170|     21|    return ret;
  171|     21|}
entropy.c:entropy_gather_internal:
  199|     21|{
  200|     21|    int ret = MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
  ------------------
  |  |   39|     21|#define MBEDTLS_ERR_ENTROPY_SOURCE_FAILED                 -0x003C
  ------------------
  201|     21|    int i;
  202|     21|    int have_one_strong = 0;
  203|     21|    unsigned char buf[MBEDTLS_ENTROPY_MAX_GATHER];
  204|     21|    size_t olen;
  205|       |
  206|     21|    if (ctx->source_count == 0) {
  ------------------
  |  Branch (206:9): [True: 0, False: 21]
  ------------------
  207|      0|        return MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED;
  ------------------
  |  |   43|      0|#define MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED            -0x0040
  ------------------
  208|      0|    }
  209|       |
  210|       |    /*
  211|       |     * Run through our entropy sources
  212|       |     */
  213|     42|    for (i = 0; i < ctx->source_count; i++) {
  ------------------
  |  Branch (213:17): [True: 42, False: 0]
  ------------------
  214|     42|        if (ctx->source[i].strong == MBEDTLS_ENTROPY_SOURCE_STRONG) {
  ------------------
  |  |   70|     42|#define MBEDTLS_ENTROPY_SOURCE_STRONG   1       /**< Entropy source is strong   */
  ------------------
  |  Branch (214:13): [True: 42, False: 0]
  ------------------
  215|     42|            have_one_strong = 1;
  216|     42|        }
  217|       |
  218|     42|        olen = 0;
  219|     42|        if ((ret = ctx->source[i].f_source(ctx->source[i].p_source,
  ------------------
  |  Branch (219:13): [True: 21, False: 21]
  ------------------
  220|     42|                                           buf, MBEDTLS_ENTROPY_MAX_GATHER, &olen)) != 0) {
  ------------------
  |  |   62|     42|#define MBEDTLS_ENTROPY_MAX_GATHER      128     /**< Maximum amount requested from entropy sources */
  ------------------
  221|     21|            goto cleanup;
  222|     21|        }
  223|       |
  224|       |        /*
  225|       |         * Add if we actually gathered something
  226|       |         */
  227|     21|        if (olen > 0) {
  ------------------
  |  Branch (227:13): [True: 21, False: 0]
  ------------------
  228|     21|            if ((ret = entropy_update(ctx, (unsigned char) i,
  ------------------
  |  Branch (228:17): [True: 0, False: 21]
  ------------------
  229|     21|                                      buf, olen)) != 0) {
  230|      0|                return ret;
  231|      0|            }
  232|     21|            ctx->source[i].size += olen;
  233|     21|        }
  234|     21|    }
  235|       |
  236|      0|    if (have_one_strong == 0) {
  ------------------
  |  Branch (236:9): [True: 0, False: 0]
  ------------------
  237|      0|        ret = MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE;
  ------------------
  |  |   45|      0|#define MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE              -0x003D
  ------------------
  238|      0|    }
  239|       |
  240|     21|cleanup:
  241|     21|    mbedtls_platform_zeroize(buf, sizeof(buf));
  242|       |
  243|     21|    return ret;
  244|      0|}

mbedtls_platform_entropy_poll:
  152|     21|{
  153|     21|    FILE *file;
  154|     21|    size_t read_len;
  155|     21|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|     21|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  156|     21|    ((void) data);
  157|       |
  158|     21|#if defined(HAVE_GETRANDOM)
  159|     21|    ret = getrandom_wrapper(output, len, 0);
  160|     21|    if (ret >= 0) {
  ------------------
  |  Branch (160:9): [True: 21, False: 0]
  ------------------
  161|     21|        *olen = (size_t) ret;
  162|     21|        return 0;
  163|     21|    } else if (errno != ENOSYS) {
  ------------------
  |  Branch (163:16): [True: 0, False: 0]
  ------------------
  164|      0|        return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
  ------------------
  |  |   39|      0|#define MBEDTLS_ERR_ENTROPY_SOURCE_FAILED                 -0x003C
  ------------------
  165|      0|    }
  166|       |    /* Fall through if the system call isn't known. */
  167|       |#else
  168|       |    ((void) ret);
  169|       |#endif /* HAVE_GETRANDOM */
  170|       |
  171|       |#if defined(HAVE_SYSCTL_ARND)
  172|       |    ((void) file);
  173|       |    ((void) read_len);
  174|       |    if (sysctl_arnd_wrapper(output, len) == -1) {
  175|       |        return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
  176|       |    }
  177|       |    *olen = len;
  178|       |    return 0;
  179|       |#else
  180|       |
  181|      0|    *olen = 0;
  182|       |
  183|      0|    file = fopen("/dev/urandom", "rb");
  184|      0|    if (file == NULL) {
  ------------------
  |  Branch (184:9): [True: 0, False: 0]
  ------------------
  185|      0|        return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
  ------------------
  |  |   39|      0|#define MBEDTLS_ERR_ENTROPY_SOURCE_FAILED                 -0x003C
  ------------------
  186|      0|    }
  187|       |
  188|       |    /* Ensure no stdio buffering of secrets, as such buffers cannot be wiped. */
  189|      0|    mbedtls_setbuf(file, NULL);
  190|       |
  191|      0|    read_len = fread(output, 1, len, file);
  192|      0|    if (read_len != len) {
  ------------------
  |  Branch (192:9): [True: 0, False: 0]
  ------------------
  193|      0|        fclose(file);
  194|      0|        return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
  ------------------
  |  |   39|      0|#define MBEDTLS_ERR_ENTROPY_SOURCE_FAILED                 -0x003C
  ------------------
  195|      0|    }
  196|       |
  197|      0|    fclose(file);
  198|      0|    *olen = len;
  199|       |
  200|      0|    return 0;
  201|      0|#endif /* HAVE_SYSCTL_ARND */
  202|      0|}
mbedtls_nv_seed_poll:
  209|     21|{
  210|     21|    unsigned char buf[MBEDTLS_ENTROPY_BLOCK_SIZE];
  211|     21|    size_t use_len = MBEDTLS_ENTROPY_BLOCK_SIZE;
  ------------------
  |  |   24|     21|#define MBEDTLS_ENTROPY_BLOCK_SIZE      64      /**< Block size of entropy accumulator (SHA-512) */
  ------------------
  212|     21|    ((void) data);
  213|       |
  214|     21|    memset(buf, 0, MBEDTLS_ENTROPY_BLOCK_SIZE);
  ------------------
  |  |   24|     21|#define MBEDTLS_ENTROPY_BLOCK_SIZE      64      /**< Block size of entropy accumulator (SHA-512) */
  ------------------
  215|       |
  216|     21|    if (mbedtls_nv_seed_read(buf, MBEDTLS_ENTROPY_BLOCK_SIZE) < 0) {
  ------------------
  |  |   24|     21|#define MBEDTLS_ENTROPY_BLOCK_SIZE      64      /**< Block size of entropy accumulator (SHA-512) */
  ------------------
  |  Branch (216:9): [True: 21, False: 0]
  ------------------
  217|     21|        return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
  ------------------
  |  |   39|     21|#define MBEDTLS_ERR_ENTROPY_SOURCE_FAILED                 -0x003C
  ------------------
  218|     21|    }
  219|       |
  220|      0|    if (len < use_len) {
  ------------------
  |  Branch (220:9): [True: 0, False: 0]
  ------------------
  221|      0|        use_len = len;
  222|      0|    }
  223|       |
  224|      0|    memcpy(output, buf, use_len);
  225|      0|    *olen = use_len;
  226|       |
  227|      0|    return 0;
  228|     21|}
entropy_poll.c:getrandom_wrapper:
   86|     21|{
   87|       |    /* MemSan cannot understand that the syscall writes to the buffer */
   88|     21|#if defined(__has_feature)
   89|       |#if __has_feature(memory_sanitizer)
   90|       |    memset(buf, 0, buflen);
   91|       |#endif
   92|     21|#endif
   93|     21|    return (int) syscall(SYS_getrandom, buf, buflen, flags);
   94|     21|}

mbedtls_md_info_from_type:
  140|     42|{
  141|     42|    switch (md_type) {
  142|      0|#if defined(MBEDTLS_MD_CAN_MD5)
  143|      0|        case MBEDTLS_MD_MD5:
  ------------------
  |  Branch (143:9): [True: 0, False: 42]
  ------------------
  144|      0|            return &mbedtls_md5_info;
  145|      0|#endif
  146|      0|#if defined(MBEDTLS_MD_CAN_RIPEMD160)
  147|      0|        case MBEDTLS_MD_RIPEMD160:
  ------------------
  |  Branch (147:9): [True: 0, False: 42]
  ------------------
  148|      0|            return &mbedtls_ripemd160_info;
  149|      0|#endif
  150|      0|#if defined(MBEDTLS_MD_CAN_SHA1)
  151|      0|        case MBEDTLS_MD_SHA1:
  ------------------
  |  Branch (151:9): [True: 0, False: 42]
  ------------------
  152|      0|            return &mbedtls_sha1_info;
  153|      0|#endif
  154|      0|#if defined(MBEDTLS_MD_CAN_SHA224)
  155|      0|        case MBEDTLS_MD_SHA224:
  ------------------
  |  Branch (155:9): [True: 0, False: 42]
  ------------------
  156|      0|            return &mbedtls_sha224_info;
  157|      0|#endif
  158|      0|#if defined(MBEDTLS_MD_CAN_SHA256)
  159|      0|        case MBEDTLS_MD_SHA256:
  ------------------
  |  Branch (159:9): [True: 0, False: 42]
  ------------------
  160|      0|            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: 42]
  ------------------
  164|      0|            return &mbedtls_sha384_info;
  165|      0|#endif
  166|      0|#if defined(MBEDTLS_MD_CAN_SHA512)
  167|     42|        case MBEDTLS_MD_SHA512:
  ------------------
  |  Branch (167:9): [True: 42, False: 0]
  ------------------
  168|     42|            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: 42]
  ------------------
  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: 42]
  ------------------
  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: 42]
  ------------------
  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: 42]
  ------------------
  184|      0|            return &mbedtls_sha3_512_info;
  185|      0|#endif
  186|      0|        default:
  ------------------
  |  Branch (186:9): [True: 0, False: 42]
  ------------------
  187|      0|            return NULL;
  188|     42|    }
  189|     42|}
mbedtls_md_init:
  256|     42|{
  257|       |    /* Note: this sets engine (if present) to MBEDTLS_MD_ENGINE_LEGACY */
  258|     42|    memset(ctx, 0, sizeof(mbedtls_md_context_t));
  259|     42|}
mbedtls_md_free:
  262|     42|{
  263|     42|    if (ctx == NULL || ctx->md_info == NULL) {
  ------------------
  |  Branch (263:9): [True: 0, False: 42]
  |  Branch (263:24): [True: 21, False: 21]
  ------------------
  264|     21|        return;
  265|     21|    }
  266|       |
  267|     21|    if (ctx->md_ctx != NULL) {
  ------------------
  |  Branch (267:9): [True: 21, False: 0]
  ------------------
  268|       |#if defined(MBEDTLS_MD_SOME_PSA)
  269|       |        if (ctx->engine == MBEDTLS_MD_ENGINE_PSA) {
  270|       |            psa_hash_abort(ctx->md_ctx);
  271|       |        } else
  272|       |#endif
  273|     21|        switch (ctx->md_info->type) {
  274|      0|#if defined(MBEDTLS_MD5_C)
  275|      0|            case MBEDTLS_MD_MD5:
  ------------------
  |  Branch (275:13): [True: 0, False: 21]
  ------------------
  276|      0|                mbedtls_md5_free(ctx->md_ctx);
  277|      0|                break;
  278|      0|#endif
  279|      0|#if defined(MBEDTLS_RIPEMD160_C)
  280|      0|            case MBEDTLS_MD_RIPEMD160:
  ------------------
  |  Branch (280:13): [True: 0, False: 21]
  ------------------
  281|      0|                mbedtls_ripemd160_free(ctx->md_ctx);
  282|      0|                break;
  283|      0|#endif
  284|      0|#if defined(MBEDTLS_SHA1_C)
  285|      0|            case MBEDTLS_MD_SHA1:
  ------------------
  |  Branch (285:13): [True: 0, False: 21]
  ------------------
  286|      0|                mbedtls_sha1_free(ctx->md_ctx);
  287|      0|                break;
  288|      0|#endif
  289|      0|#if defined(MBEDTLS_SHA224_C)
  290|      0|            case MBEDTLS_MD_SHA224:
  ------------------
  |  Branch (290:13): [True: 0, False: 21]
  ------------------
  291|      0|                mbedtls_sha256_free(ctx->md_ctx);
  292|      0|                break;
  293|      0|#endif
  294|      0|#if defined(MBEDTLS_SHA256_C)
  295|      0|            case MBEDTLS_MD_SHA256:
  ------------------
  |  Branch (295:13): [True: 0, False: 21]
  ------------------
  296|      0|                mbedtls_sha256_free(ctx->md_ctx);
  297|      0|                break;
  298|      0|#endif
  299|      0|#if defined(MBEDTLS_SHA384_C)
  300|      0|            case MBEDTLS_MD_SHA384:
  ------------------
  |  Branch (300:13): [True: 0, False: 21]
  ------------------
  301|      0|                mbedtls_sha512_free(ctx->md_ctx);
  302|      0|                break;
  303|      0|#endif
  304|      0|#if defined(MBEDTLS_SHA512_C)
  305|     21|            case MBEDTLS_MD_SHA512:
  ------------------
  |  Branch (305:13): [True: 21, False: 0]
  ------------------
  306|     21|                mbedtls_sha512_free(ctx->md_ctx);
  307|     21|                break;
  308|      0|#endif
  309|      0|#if defined(MBEDTLS_SHA3_C)
  310|      0|            case MBEDTLS_MD_SHA3_224:
  ------------------
  |  Branch (310:13): [True: 0, False: 21]
  ------------------
  311|      0|            case MBEDTLS_MD_SHA3_256:
  ------------------
  |  Branch (311:13): [True: 0, False: 21]
  ------------------
  312|      0|            case MBEDTLS_MD_SHA3_384:
  ------------------
  |  Branch (312:13): [True: 0, False: 21]
  ------------------
  313|      0|            case MBEDTLS_MD_SHA3_512:
  ------------------
  |  Branch (313:13): [True: 0, False: 21]
  ------------------
  314|      0|                mbedtls_sha3_free(ctx->md_ctx);
  315|      0|                break;
  316|      0|#endif
  317|      0|            default:
  ------------------
  |  Branch (317:13): [True: 0, False: 21]
  ------------------
  318|       |                /* Shouldn't happen */
  319|      0|                break;
  320|     21|        }
  321|     21|        mbedtls_free(ctx->md_ctx);
  322|     21|    }
  323|       |
  324|     21|#if defined(MBEDTLS_MD_C)
  325|     21|    if (ctx->hmac_ctx != NULL) {
  ------------------
  |  Branch (325:9): [True: 0, False: 21]
  ------------------
  326|      0|        mbedtls_zeroize_and_free(ctx->hmac_ctx,
  327|      0|                                 2 * ctx->md_info->block_size);
  328|      0|    }
  329|     21|#endif
  330|       |
  331|     21|    mbedtls_platform_zeroize(ctx, sizeof(mbedtls_md_context_t));
  332|     21|}
mbedtls_md_setup:
  419|     21|{
  420|     21|#if defined(MBEDTLS_MD_C)
  421|     21|    if (ctx == NULL) {
  ------------------
  |  Branch (421:9): [True: 0, False: 21]
  ------------------
  422|      0|        return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MD_BAD_INPUT_DATA                     -0x5100
  ------------------
  423|      0|    }
  424|     21|#endif
  425|     21|    if (md_info == NULL) {
  ------------------
  |  Branch (425:9): [True: 0, False: 21]
  ------------------
  426|      0|        return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MD_BAD_INPUT_DATA                     -0x5100
  ------------------
  427|      0|    }
  428|       |
  429|     21|    ctx->md_info = md_info;
  430|     21|    ctx->md_ctx = NULL;
  431|     21|#if defined(MBEDTLS_MD_C)
  432|     21|    ctx->hmac_ctx = NULL;
  433|       |#else
  434|       |    if (hmac != 0) {
  435|       |        return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
  436|       |    }
  437|       |#endif
  438|       |
  439|       |#if defined(MBEDTLS_MD_SOME_PSA)
  440|       |    if (md_can_use_psa(ctx->md_info)) {
  441|       |        ctx->md_ctx = mbedtls_calloc(1, sizeof(psa_hash_operation_t));
  442|       |        if (ctx->md_ctx == NULL) {
  443|       |            return MBEDTLS_ERR_MD_ALLOC_FAILED;
  444|       |        }
  445|       |        ctx->engine = MBEDTLS_MD_ENGINE_PSA;
  446|       |    } else
  447|       |#endif
  448|     21|    switch (md_info->type) {
  449|      0|#if defined(MBEDTLS_MD5_C)
  450|      0|        case MBEDTLS_MD_MD5:
  ------------------
  |  Branch (450:9): [True: 0, False: 21]
  ------------------
  451|      0|            ALLOC(md5);
  ------------------
  |  |  410|      0|    do {                                                                \
  |  |  411|      0|        ctx->md_ctx = mbedtls_calloc(1, sizeof(mbedtls_##type##_context)); \
  |  |  412|      0|        if (ctx->md_ctx == NULL)                                       \
  |  |  ------------------
  |  |  |  Branch (412:13): [True: 0, False: 0]
  |  |  ------------------
  |  |  413|      0|        return MBEDTLS_ERR_MD_ALLOC_FAILED;                      \
  |  |  ------------------
  |  |  |  |   28|      0|#define MBEDTLS_ERR_MD_ALLOC_FAILED                       -0x5180
  |  |  ------------------
  |  |  414|      0|        mbedtls_##type##_init(ctx->md_ctx);                           \
  |  |  415|      0|    }                                                                   \
  |  |  416|      0|    while (0)
  |  |  ------------------
  |  |  |  Branch (416:12): [Folded - Ignored]
  |  |  ------------------
  ------------------
  452|      0|            break;
  453|      0|#endif
  454|      0|#if defined(MBEDTLS_RIPEMD160_C)
  455|      0|        case MBEDTLS_MD_RIPEMD160:
  ------------------
  |  Branch (455:9): [True: 0, False: 21]
  ------------------
  456|      0|            ALLOC(ripemd160);
  ------------------
  |  |  410|      0|    do {                                                                \
  |  |  411|      0|        ctx->md_ctx = mbedtls_calloc(1, sizeof(mbedtls_##type##_context)); \
  |  |  412|      0|        if (ctx->md_ctx == NULL)                                       \
  |  |  ------------------
  |  |  |  Branch (412:13): [True: 0, False: 0]
  |  |  ------------------
  |  |  413|      0|        return MBEDTLS_ERR_MD_ALLOC_FAILED;                      \
  |  |  ------------------
  |  |  |  |   28|      0|#define MBEDTLS_ERR_MD_ALLOC_FAILED                       -0x5180
  |  |  ------------------
  |  |  414|      0|        mbedtls_##type##_init(ctx->md_ctx);                           \
  |  |  415|      0|    }                                                                   \
  |  |  416|      0|    while (0)
  |  |  ------------------
  |  |  |  Branch (416:12): [Folded - Ignored]
  |  |  ------------------
  ------------------
  457|      0|            break;
  458|      0|#endif
  459|      0|#if defined(MBEDTLS_SHA1_C)
  460|      0|        case MBEDTLS_MD_SHA1:
  ------------------
  |  Branch (460:9): [True: 0, False: 21]
  ------------------
  461|      0|            ALLOC(sha1);
  ------------------
  |  |  410|      0|    do {                                                                \
  |  |  411|      0|        ctx->md_ctx = mbedtls_calloc(1, sizeof(mbedtls_##type##_context)); \
  |  |  412|      0|        if (ctx->md_ctx == NULL)                                       \
  |  |  ------------------
  |  |  |  Branch (412:13): [True: 0, False: 0]
  |  |  ------------------
  |  |  413|      0|        return MBEDTLS_ERR_MD_ALLOC_FAILED;                      \
  |  |  ------------------
  |  |  |  |   28|      0|#define MBEDTLS_ERR_MD_ALLOC_FAILED                       -0x5180
  |  |  ------------------
  |  |  414|      0|        mbedtls_##type##_init(ctx->md_ctx);                           \
  |  |  415|      0|    }                                                                   \
  |  |  416|      0|    while (0)
  |  |  ------------------
  |  |  |  Branch (416:12): [Folded - Ignored]
  |  |  ------------------
  ------------------
  462|      0|            break;
  463|      0|#endif
  464|      0|#if defined(MBEDTLS_SHA224_C)
  465|      0|        case MBEDTLS_MD_SHA224:
  ------------------
  |  Branch (465:9): [True: 0, False: 21]
  ------------------
  466|      0|            ALLOC(sha256);
  ------------------
  |  |  410|      0|    do {                                                                \
  |  |  411|      0|        ctx->md_ctx = mbedtls_calloc(1, sizeof(mbedtls_##type##_context)); \
  |  |  412|      0|        if (ctx->md_ctx == NULL)                                       \
  |  |  ------------------
  |  |  |  Branch (412:13): [True: 0, False: 0]
  |  |  ------------------
  |  |  413|      0|        return MBEDTLS_ERR_MD_ALLOC_FAILED;                      \
  |  |  ------------------
  |  |  |  |   28|      0|#define MBEDTLS_ERR_MD_ALLOC_FAILED                       -0x5180
  |  |  ------------------
  |  |  414|      0|        mbedtls_##type##_init(ctx->md_ctx);                           \
  |  |  415|      0|    }                                                                   \
  |  |  416|      0|    while (0)
  |  |  ------------------
  |  |  |  Branch (416:12): [Folded - Ignored]
  |  |  ------------------
  ------------------
  467|      0|            break;
  468|      0|#endif
  469|      0|#if defined(MBEDTLS_SHA256_C)
  470|      0|        case MBEDTLS_MD_SHA256:
  ------------------
  |  Branch (470:9): [True: 0, False: 21]
  ------------------
  471|      0|            ALLOC(sha256);
  ------------------
  |  |  410|      0|    do {                                                                \
  |  |  411|      0|        ctx->md_ctx = mbedtls_calloc(1, sizeof(mbedtls_##type##_context)); \
  |  |  412|      0|        if (ctx->md_ctx == NULL)                                       \
  |  |  ------------------
  |  |  |  Branch (412:13): [True: 0, False: 0]
  |  |  ------------------
  |  |  413|      0|        return MBEDTLS_ERR_MD_ALLOC_FAILED;                      \
  |  |  ------------------
  |  |  |  |   28|      0|#define MBEDTLS_ERR_MD_ALLOC_FAILED                       -0x5180
  |  |  ------------------
  |  |  414|      0|        mbedtls_##type##_init(ctx->md_ctx);                           \
  |  |  415|      0|    }                                                                   \
  |  |  416|      0|    while (0)
  |  |  ------------------
  |  |  |  Branch (416:12): [Folded - Ignored]
  |  |  ------------------
  ------------------
  472|      0|            break;
  473|      0|#endif
  474|      0|#if defined(MBEDTLS_SHA384_C)
  475|      0|        case MBEDTLS_MD_SHA384:
  ------------------
  |  Branch (475:9): [True: 0, False: 21]
  ------------------
  476|      0|            ALLOC(sha512);
  ------------------
  |  |  410|      0|    do {                                                                \
  |  |  411|      0|        ctx->md_ctx = mbedtls_calloc(1, sizeof(mbedtls_##type##_context)); \
  |  |  412|      0|        if (ctx->md_ctx == NULL)                                       \
  |  |  ------------------
  |  |  |  Branch (412:13): [True: 0, False: 0]
  |  |  ------------------
  |  |  413|      0|        return MBEDTLS_ERR_MD_ALLOC_FAILED;                      \
  |  |  ------------------
  |  |  |  |   28|      0|#define MBEDTLS_ERR_MD_ALLOC_FAILED                       -0x5180
  |  |  ------------------
  |  |  414|      0|        mbedtls_##type##_init(ctx->md_ctx);                           \
  |  |  415|      0|    }                                                                   \
  |  |  416|      0|    while (0)
  |  |  ------------------
  |  |  |  Branch (416:12): [Folded - Ignored]
  |  |  ------------------
  ------------------
  477|      0|            break;
  478|      0|#endif
  479|      0|#if defined(MBEDTLS_SHA512_C)
  480|     21|        case MBEDTLS_MD_SHA512:
  ------------------
  |  Branch (480:9): [True: 21, False: 0]
  ------------------
  481|     21|            ALLOC(sha512);
  ------------------
  |  |  410|     21|    do {                                                                \
  |  |  411|     21|        ctx->md_ctx = mbedtls_calloc(1, sizeof(mbedtls_##type##_context)); \
  |  |  412|     21|        if (ctx->md_ctx == NULL)                                       \
  |  |  ------------------
  |  |  |  Branch (412:13): [True: 0, False: 21]
  |  |  ------------------
  |  |  413|     21|        return MBEDTLS_ERR_MD_ALLOC_FAILED;                      \
  |  |  ------------------
  |  |  |  |   28|      0|#define MBEDTLS_ERR_MD_ALLOC_FAILED                       -0x5180
  |  |  ------------------
  |  |  414|     21|        mbedtls_##type##_init(ctx->md_ctx);                           \
  |  |  415|     21|    }                                                                   \
  |  |  416|     21|    while (0)
  |  |  ------------------
  |  |  |  Branch (416:12): [Folded - Ignored]
  |  |  ------------------
  ------------------
  482|     21|            break;
  483|     21|#endif
  484|     21|#if defined(MBEDTLS_SHA3_C)
  485|     21|        case MBEDTLS_MD_SHA3_224:
  ------------------
  |  Branch (485:9): [True: 0, False: 21]
  ------------------
  486|      0|        case MBEDTLS_MD_SHA3_256:
  ------------------
  |  Branch (486:9): [True: 0, False: 21]
  ------------------
  487|      0|        case MBEDTLS_MD_SHA3_384:
  ------------------
  |  Branch (487:9): [True: 0, False: 21]
  ------------------
  488|      0|        case MBEDTLS_MD_SHA3_512:
  ------------------
  |  Branch (488:9): [True: 0, False: 21]
  ------------------
  489|      0|            ALLOC(sha3);
  ------------------
  |  |  410|      0|    do {                                                                \
  |  |  411|      0|        ctx->md_ctx = mbedtls_calloc(1, sizeof(mbedtls_##type##_context)); \
  |  |  412|      0|        if (ctx->md_ctx == NULL)                                       \
  |  |  ------------------
  |  |  |  Branch (412:13): [True: 0, False: 0]
  |  |  ------------------
  |  |  413|      0|        return MBEDTLS_ERR_MD_ALLOC_FAILED;                      \
  |  |  ------------------
  |  |  |  |   28|      0|#define MBEDTLS_ERR_MD_ALLOC_FAILED                       -0x5180
  |  |  ------------------
  |  |  414|      0|        mbedtls_##type##_init(ctx->md_ctx);                           \
  |  |  415|      0|    }                                                                   \
  |  |  416|      0|    while (0)
  |  |  ------------------
  |  |  |  Branch (416:12): [Folded - Ignored]
  |  |  ------------------
  ------------------
  490|      0|            break;
  491|      0|#endif
  492|      0|        default:
  ------------------
  |  Branch (492:9): [True: 0, False: 21]
  ------------------
  493|      0|            return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MD_BAD_INPUT_DATA                     -0x5100
  ------------------
  494|     21|    }
  495|       |
  496|     21|#if defined(MBEDTLS_MD_C)
  497|     21|    if (hmac != 0) {
  ------------------
  |  Branch (497:9): [True: 0, False: 21]
  ------------------
  498|      0|        ctx->hmac_ctx = mbedtls_calloc(2, md_info->block_size);
  499|      0|        if (ctx->hmac_ctx == NULL) {
  ------------------
  |  Branch (499:13): [True: 0, False: 0]
  ------------------
  500|      0|            mbedtls_md_free(ctx);
  501|      0|            return MBEDTLS_ERR_MD_ALLOC_FAILED;
  ------------------
  |  |   28|      0|#define MBEDTLS_ERR_MD_ALLOC_FAILED                       -0x5180
  ------------------
  502|      0|        }
  503|      0|    }
  504|     21|#endif
  505|       |
  506|     21|    return 0;
  507|     21|}
mbedtls_md_starts:
  511|     21|{
  512|     21|#if defined(MBEDTLS_MD_C)
  513|     21|    if (ctx == NULL || ctx->md_info == NULL) {
  ------------------
  |  Branch (513:9): [True: 0, False: 21]
  |  Branch (513:24): [True: 0, False: 21]
  ------------------
  514|      0|        return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MD_BAD_INPUT_DATA                     -0x5100
  ------------------
  515|      0|    }
  516|     21|#endif
  517|       |
  518|       |#if defined(MBEDTLS_MD_SOME_PSA)
  519|       |    if (ctx->engine == MBEDTLS_MD_ENGINE_PSA) {
  520|       |        psa_algorithm_t alg = psa_alg_of_md(ctx->md_info);
  521|       |        psa_hash_abort(ctx->md_ctx);
  522|       |        psa_status_t status = psa_hash_setup(ctx->md_ctx, alg);
  523|       |        return mbedtls_md_error_from_psa(status);
  524|       |    }
  525|       |#endif
  526|       |
  527|     21|    switch (ctx->md_info->type) {
  528|      0|#if defined(MBEDTLS_MD5_C)
  529|      0|        case MBEDTLS_MD_MD5:
  ------------------
  |  Branch (529:9): [True: 0, False: 21]
  ------------------
  530|      0|            return mbedtls_md5_starts(ctx->md_ctx);
  531|      0|#endif
  532|      0|#if defined(MBEDTLS_RIPEMD160_C)
  533|      0|        case MBEDTLS_MD_RIPEMD160:
  ------------------
  |  Branch (533:9): [True: 0, False: 21]
  ------------------
  534|      0|            return mbedtls_ripemd160_starts(ctx->md_ctx);
  535|      0|#endif
  536|      0|#if defined(MBEDTLS_SHA1_C)
  537|      0|        case MBEDTLS_MD_SHA1:
  ------------------
  |  Branch (537:9): [True: 0, False: 21]
  ------------------
  538|      0|            return mbedtls_sha1_starts(ctx->md_ctx);
  539|      0|#endif
  540|      0|#if defined(MBEDTLS_SHA224_C)
  541|      0|        case MBEDTLS_MD_SHA224:
  ------------------
  |  Branch (541:9): [True: 0, False: 21]
  ------------------
  542|      0|            return mbedtls_sha256_starts(ctx->md_ctx, 1);
  543|      0|#endif
  544|      0|#if defined(MBEDTLS_SHA256_C)
  545|      0|        case MBEDTLS_MD_SHA256:
  ------------------
  |  Branch (545:9): [True: 0, False: 21]
  ------------------
  546|      0|            return mbedtls_sha256_starts(ctx->md_ctx, 0);
  547|      0|#endif
  548|      0|#if defined(MBEDTLS_SHA384_C)
  549|      0|        case MBEDTLS_MD_SHA384:
  ------------------
  |  Branch (549:9): [True: 0, False: 21]
  ------------------
  550|      0|            return mbedtls_sha512_starts(ctx->md_ctx, 1);
  551|      0|#endif
  552|      0|#if defined(MBEDTLS_SHA512_C)
  553|     21|        case MBEDTLS_MD_SHA512:
  ------------------
  |  Branch (553:9): [True: 21, False: 0]
  ------------------
  554|     21|            return mbedtls_sha512_starts(ctx->md_ctx, 0);
  555|      0|#endif
  556|      0|#if defined(MBEDTLS_SHA3_C)
  557|      0|        case MBEDTLS_MD_SHA3_224:
  ------------------
  |  Branch (557:9): [True: 0, False: 21]
  ------------------
  558|      0|            return mbedtls_sha3_starts(ctx->md_ctx, MBEDTLS_SHA3_224);
  559|      0|        case MBEDTLS_MD_SHA3_256:
  ------------------
  |  Branch (559:9): [True: 0, False: 21]
  ------------------
  560|      0|            return mbedtls_sha3_starts(ctx->md_ctx, MBEDTLS_SHA3_256);
  561|      0|        case MBEDTLS_MD_SHA3_384:
  ------------------
  |  Branch (561:9): [True: 0, False: 21]
  ------------------
  562|      0|            return mbedtls_sha3_starts(ctx->md_ctx, MBEDTLS_SHA3_384);
  563|      0|        case MBEDTLS_MD_SHA3_512:
  ------------------
  |  Branch (563:9): [True: 0, False: 21]
  ------------------
  564|      0|            return mbedtls_sha3_starts(ctx->md_ctx, MBEDTLS_SHA3_512);
  565|      0|#endif
  566|      0|        default:
  ------------------
  |  Branch (566:9): [True: 0, False: 21]
  ------------------
  567|      0|            return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MD_BAD_INPUT_DATA                     -0x5100
  ------------------
  568|     21|    }
  569|     21|}
mbedtls_md_update:
  572|     42|{
  573|     42|#if defined(MBEDTLS_MD_C)
  574|     42|    if (ctx == NULL || ctx->md_info == NULL) {
  ------------------
  |  Branch (574:9): [True: 0, False: 42]
  |  Branch (574:24): [True: 0, False: 42]
  ------------------
  575|      0|        return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MD_BAD_INPUT_DATA                     -0x5100
  ------------------
  576|      0|    }
  577|     42|#endif
  578|       |
  579|       |#if defined(MBEDTLS_MD_SOME_PSA)
  580|       |    if (ctx->engine == MBEDTLS_MD_ENGINE_PSA) {
  581|       |        psa_status_t status = psa_hash_update(ctx->md_ctx, input, ilen);
  582|       |        return mbedtls_md_error_from_psa(status);
  583|       |    }
  584|       |#endif
  585|       |
  586|     42|    switch (ctx->md_info->type) {
  587|      0|#if defined(MBEDTLS_MD5_C)
  588|      0|        case MBEDTLS_MD_MD5:
  ------------------
  |  Branch (588:9): [True: 0, False: 42]
  ------------------
  589|      0|            return mbedtls_md5_update(ctx->md_ctx, input, ilen);
  590|      0|#endif
  591|      0|#if defined(MBEDTLS_RIPEMD160_C)
  592|      0|        case MBEDTLS_MD_RIPEMD160:
  ------------------
  |  Branch (592:9): [True: 0, False: 42]
  ------------------
  593|      0|            return mbedtls_ripemd160_update(ctx->md_ctx, input, ilen);
  594|      0|#endif
  595|      0|#if defined(MBEDTLS_SHA1_C)
  596|      0|        case MBEDTLS_MD_SHA1:
  ------------------
  |  Branch (596:9): [True: 0, False: 42]
  ------------------
  597|      0|            return mbedtls_sha1_update(ctx->md_ctx, input, ilen);
  598|      0|#endif
  599|      0|#if defined(MBEDTLS_SHA224_C)
  600|      0|        case MBEDTLS_MD_SHA224:
  ------------------
  |  Branch (600:9): [True: 0, False: 42]
  ------------------
  601|      0|            return mbedtls_sha256_update(ctx->md_ctx, input, ilen);
  602|      0|#endif
  603|      0|#if defined(MBEDTLS_SHA256_C)
  604|      0|        case MBEDTLS_MD_SHA256:
  ------------------
  |  Branch (604:9): [True: 0, False: 42]
  ------------------
  605|      0|            return mbedtls_sha256_update(ctx->md_ctx, input, ilen);
  606|      0|#endif
  607|      0|#if defined(MBEDTLS_SHA384_C)
  608|      0|        case MBEDTLS_MD_SHA384:
  ------------------
  |  Branch (608:9): [True: 0, False: 42]
  ------------------
  609|      0|            return mbedtls_sha512_update(ctx->md_ctx, input, ilen);
  610|      0|#endif
  611|      0|#if defined(MBEDTLS_SHA512_C)
  612|     42|        case MBEDTLS_MD_SHA512:
  ------------------
  |  Branch (612:9): [True: 42, False: 0]
  ------------------
  613|     42|            return mbedtls_sha512_update(ctx->md_ctx, input, ilen);
  614|      0|#endif
  615|      0|#if defined(MBEDTLS_SHA3_C)
  616|      0|        case MBEDTLS_MD_SHA3_224:
  ------------------
  |  Branch (616:9): [True: 0, False: 42]
  ------------------
  617|      0|        case MBEDTLS_MD_SHA3_256:
  ------------------
  |  Branch (617:9): [True: 0, False: 42]
  ------------------
  618|      0|        case MBEDTLS_MD_SHA3_384:
  ------------------
  |  Branch (618:9): [True: 0, False: 42]
  ------------------
  619|      0|        case MBEDTLS_MD_SHA3_512:
  ------------------
  |  Branch (619:9): [True: 0, False: 42]
  ------------------
  620|      0|            return mbedtls_sha3_update(ctx->md_ctx, input, ilen);
  621|      0|#endif
  622|      0|        default:
  ------------------
  |  Branch (622:9): [True: 0, False: 42]
  ------------------
  623|      0|            return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MD_BAD_INPUT_DATA                     -0x5100
  ------------------
  624|     42|    }
  625|     42|}
mbedtls_md:
  687|     21|{
  688|     21|    if (md_info == NULL) {
  ------------------
  |  Branch (688:9): [True: 0, False: 21]
  ------------------
  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|     21|    switch (md_info->type) {
  703|      0|#if defined(MBEDTLS_MD5_C)
  704|      0|        case MBEDTLS_MD_MD5:
  ------------------
  |  Branch (704:9): [True: 0, False: 21]
  ------------------
  705|      0|            return mbedtls_md5(input, ilen, output);
  706|      0|#endif
  707|      0|#if defined(MBEDTLS_RIPEMD160_C)
  708|      0|        case MBEDTLS_MD_RIPEMD160:
  ------------------
  |  Branch (708:9): [True: 0, False: 21]
  ------------------
  709|      0|            return mbedtls_ripemd160(input, ilen, output);
  710|      0|#endif
  711|      0|#if defined(MBEDTLS_SHA1_C)
  712|      0|        case MBEDTLS_MD_SHA1:
  ------------------
  |  Branch (712:9): [True: 0, False: 21]
  ------------------
  713|      0|            return mbedtls_sha1(input, ilen, output);
  714|      0|#endif
  715|      0|#if defined(MBEDTLS_SHA224_C)
  716|      0|        case MBEDTLS_MD_SHA224:
  ------------------
  |  Branch (716:9): [True: 0, False: 21]
  ------------------
  717|      0|            return mbedtls_sha256(input, ilen, output, 1);
  718|      0|#endif
  719|      0|#if defined(MBEDTLS_SHA256_C)
  720|      0|        case MBEDTLS_MD_SHA256:
  ------------------
  |  Branch (720:9): [True: 0, False: 21]
  ------------------
  721|      0|            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: 21]
  ------------------
  725|      0|            return mbedtls_sha512(input, ilen, output, 1);
  726|      0|#endif
  727|      0|#if defined(MBEDTLS_SHA512_C)
  728|     21|        case MBEDTLS_MD_SHA512:
  ------------------
  |  Branch (728:9): [True: 21, False: 0]
  ------------------
  729|     21|            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: 21]
  ------------------
  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: 21]
  ------------------
  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: 21]
  ------------------
  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: 21]
  ------------------
  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: 21]
  ------------------
  742|      0|            return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MD_BAD_INPUT_DATA                     -0x5100
  ------------------
  743|     21|    }
  744|     21|}

mbedtls_oid_get_x509_ext_type:
   84|      9|    {                                                                       \
   85|      9|        const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1(oid);        \
   86|      9|        if (data == NULL) return MBEDTLS_ERR_OID_NOT_FOUND;            \
  ------------------
  |  |   28|      0|#define MBEDTLS_ERR_OID_NOT_FOUND                         -0x002E
  ------------------
  |  Branch (86:13): [True: 0, False: 9]
  ------------------
   87|      9|        *ATTR1 = data->ATTR1;                                               \
   88|      9|        return 0;                                                        \
   89|      9|    }
mbedtls_oid_get_sig_alg:
   99|      3|    {                                                                           \
  100|      3|        const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1(oid);            \
  101|      3|        if (data == NULL) return MBEDTLS_ERR_OID_NOT_FOUND;                 \
  ------------------
  |  |   28|      0|#define MBEDTLS_ERR_OID_NOT_FOUND                         -0x002E
  ------------------
  |  Branch (101:13): [True: 0, False: 3]
  ------------------
  102|      3|        *(ATTR1) = data->ATTR1;                                                 \
  103|      3|        *(ATTR2) = data->ATTR2;                                                 \
  104|      3|        return 0;                                                            \
  105|      3|    }
mbedtls_oid_get_pk_alg:
   84|      3|    {                                                                       \
   85|      3|        const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1(oid);        \
   86|      3|        if (data == NULL) return MBEDTLS_ERR_OID_NOT_FOUND;            \
  ------------------
  |  |   28|      0|#define MBEDTLS_ERR_OID_NOT_FOUND                         -0x002E
  ------------------
  |  Branch (86:13): [True: 0, False: 3]
  ------------------
   87|      3|        *ATTR1 = data->ATTR1;                                               \
   88|      3|        return 0;                                                        \
   89|      3|    }
mbedtls_oid_get_ec_grp:
   84|      1|    {                                                                       \
   85|      1|        const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1(oid);        \
   86|      1|        if (data == NULL) return MBEDTLS_ERR_OID_NOT_FOUND;            \
  ------------------
  |  |   28|      0|#define MBEDTLS_ERR_OID_NOT_FOUND                         -0x002E
  ------------------
  |  Branch (86:13): [True: 0, False: 1]
  ------------------
   87|      1|        *ATTR1 = data->ATTR1;                                               \
   88|      1|        return 0;                                                        \
   89|      1|    }
oid.c:oid_x509_ext_from_asn1:
   47|      9|    {                                                                   \
   48|      9|        const TYPE_T *p = (LIST);                                       \
   49|      9|        const mbedtls_oid_descriptor_t *cur =                           \
   50|      9|            (const mbedtls_oid_descriptor_t *) p;                       \
   51|      9|        if (p == NULL || oid == NULL) return NULL;                  \
  ------------------
  |  Branch (51:13): [True: 0, False: 9]
  |  Branch (51:26): [True: 0, False: 9]
  ------------------
   52|     48|        while (cur->asn1 != NULL) {                                    \
  ------------------
  |  Branch (52:16): [True: 48, False: 0]
  ------------------
   53|     48|            if (cur->asn1_len == oid->len &&                            \
  ------------------
  |  Branch (53:17): [True: 42, False: 6]
  ------------------
   54|     48|                memcmp(cur->asn1, oid->p, oid->len) == 0) {          \
  ------------------
  |  Branch (54:17): [True: 9, False: 33]
  ------------------
   55|      9|                return p;                                            \
   56|      9|            }                                                           \
   57|     48|            p++;                                                        \
   58|     39|            cur = (const mbedtls_oid_descriptor_t *) p;                 \
   59|     39|        }                                                               \
   60|      9|        return NULL;                                                 \
   61|      9|    }
oid.c:oid_sig_alg_from_asn1:
   47|      3|    {                                                                   \
   48|      3|        const TYPE_T *p = (LIST);                                       \
   49|      3|        const mbedtls_oid_descriptor_t *cur =                           \
   50|      3|            (const mbedtls_oid_descriptor_t *) p;                       \
   51|      3|        if (p == NULL || oid == NULL) return NULL;                  \
  ------------------
  |  Branch (51:13): [True: 0, False: 3]
  |  Branch (51:26): [True: 0, False: 3]
  ------------------
   52|     16|        while (cur->asn1 != NULL) {                                    \
  ------------------
  |  Branch (52:16): [True: 16, False: 0]
  ------------------
   53|     16|            if (cur->asn1_len == oid->len &&                            \
  ------------------
  |  Branch (53:17): [True: 8, False: 8]
  ------------------
   54|     16|                memcmp(cur->asn1, oid->p, oid->len) == 0) {          \
  ------------------
  |  Branch (54:17): [True: 3, False: 5]
  ------------------
   55|      3|                return p;                                            \
   56|      3|            }                                                           \
   57|     16|            p++;                                                        \
   58|     13|            cur = (const mbedtls_oid_descriptor_t *) p;                 \
   59|     13|        }                                                               \
   60|      3|        return NULL;                                                 \
   61|      3|    }
oid.c:oid_pk_alg_from_asn1:
   47|      3|    {                                                                   \
   48|      3|        const TYPE_T *p = (LIST);                                       \
   49|      3|        const mbedtls_oid_descriptor_t *cur =                           \
   50|      3|            (const mbedtls_oid_descriptor_t *) p;                       \
   51|      3|        if (p == NULL || oid == NULL) return NULL;                  \
  ------------------
  |  Branch (51:13): [True: 0, False: 3]
  |  Branch (51:26): [True: 0, False: 3]
  ------------------
   52|      4|        while (cur->asn1 != NULL) {                                    \
  ------------------
  |  Branch (52:16): [True: 4, False: 0]
  ------------------
   53|      4|            if (cur->asn1_len == oid->len &&                            \
  ------------------
  |  Branch (53:17): [True: 3, False: 1]
  ------------------
   54|      4|                memcmp(cur->asn1, oid->p, oid->len) == 0) {          \
  ------------------
  |  Branch (54:17): [True: 3, False: 0]
  ------------------
   55|      3|                return p;                                            \
   56|      3|            }                                                           \
   57|      4|            p++;                                                        \
   58|      1|            cur = (const mbedtls_oid_descriptor_t *) p;                 \
   59|      1|        }                                                               \
   60|      3|        return NULL;                                                 \
   61|      3|    }
oid.c:oid_grp_id_from_asn1:
   47|      1|    {                                                                   \
   48|      1|        const TYPE_T *p = (LIST);                                       \
   49|      1|        const mbedtls_oid_descriptor_t *cur =                           \
   50|      1|            (const mbedtls_oid_descriptor_t *) p;                       \
   51|      1|        if (p == NULL || oid == NULL) return NULL;                  \
  ------------------
  |  Branch (51:13): [True: 0, False: 1]
  |  Branch (51:26): [True: 0, False: 1]
  ------------------
   52|      4|        while (cur->asn1 != NULL) {                                    \
  ------------------
  |  Branch (52:16): [True: 4, False: 0]
  ------------------
   53|      4|            if (cur->asn1_len == oid->len &&                            \
  ------------------
  |  Branch (53:17): [True: 2, False: 2]
  ------------------
   54|      4|                memcmp(cur->asn1, oid->p, oid->len) == 0) {          \
  ------------------
  |  Branch (54:17): [True: 1, False: 1]
  ------------------
   55|      1|                return p;                                            \
   56|      1|            }                                                           \
   57|      4|            p++;                                                        \
   58|      3|            cur = (const mbedtls_oid_descriptor_t *) p;                 \
   59|      3|        }                                                               \
   60|      1|        return NULL;                                                 \
   61|      1|    }

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

mbedtls_pk_info_from_type:
  111|      3|{
  112|      3|    switch (pk_type) {
  113|      0|#if defined(MBEDTLS_RSA_C)
  114|      2|        case MBEDTLS_PK_RSA:
  ------------------
  |  Branch (114:9): [True: 2, False: 1]
  ------------------
  115|      2|            return &mbedtls_rsa_info;
  116|      0|#endif /* MBEDTLS_RSA_C */
  117|      0|#if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
  118|      1|        case MBEDTLS_PK_ECKEY:
  ------------------
  |  Branch (118:9): [True: 1, False: 2]
  ------------------
  119|      1|            return &mbedtls_eckey_info;
  120|      0|        case MBEDTLS_PK_ECKEY_DH:
  ------------------
  |  Branch (120:9): [True: 0, False: 3]
  ------------------
  121|      0|            return &mbedtls_eckeydh_info;
  122|      0|#endif /* MBEDTLS_PK_HAVE_ECC_KEYS */
  123|      0|#if defined(MBEDTLS_PK_CAN_ECDSA_SOME)
  124|      0|        case MBEDTLS_PK_ECDSA:
  ------------------
  |  Branch (124:9): [True: 0, False: 3]
  ------------------
  125|      0|            return &mbedtls_ecdsa_info;
  126|      0|#endif /* MBEDTLS_PK_CAN_ECDSA_SOME */
  127|       |        /* MBEDTLS_PK_RSA_ALT omitted on purpose */
  128|      0|        default:
  ------------------
  |  Branch (128:9): [True: 0, False: 3]
  ------------------
  129|      0|            return NULL;
  130|      3|    }
  131|      3|}
mbedtls_pk_setup:
  137|      3|{
  138|      3|    if (info == NULL || ctx->pk_info != NULL) {
  ------------------
  |  Branch (138:9): [True: 0, False: 3]
  |  Branch (138:25): [True: 0, False: 3]
  ------------------
  139|      0|        return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
  ------------------
  |  |   40|      0|#define MBEDTLS_ERR_PK_BAD_INPUT_DATA      -0x3E80
  ------------------
  140|      0|    }
  141|       |
  142|      3|    if ((info->ctx_alloc_func != NULL) &&
  ------------------
  |  Branch (142:9): [True: 3, False: 0]
  ------------------
  143|      3|        ((ctx->pk_ctx = info->ctx_alloc_func()) == NULL)) {
  ------------------
  |  Branch (143:9): [True: 0, False: 3]
  ------------------
  144|      0|        return MBEDTLS_ERR_PK_ALLOC_FAILED;
  ------------------
  |  |   36|      0|#define MBEDTLS_ERR_PK_ALLOC_FAILED        -0x3F80
  ------------------
  145|      0|    }
  146|       |
  147|      3|    ctx->pk_info = info;
  148|       |
  149|      3|    return 0;
  150|      3|}
mbedtls_pk_get_type:
 1495|      4|{
 1496|      4|    if (ctx == NULL || ctx->pk_info == NULL) {
  ------------------
  |  Branch (1496:9): [True: 0, False: 4]
  |  Branch (1496:24): [True: 0, False: 4]
  ------------------
 1497|      0|        return MBEDTLS_PK_NONE;
 1498|      0|    }
 1499|       |
 1500|      4|    return ctx->pk_info->type;
 1501|      4|}

mbedtls_pk_ecc_set_group:
   18|      1|{
   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|      1|    mbedtls_ecp_keypair *ecp = mbedtls_pk_ec_rw(*pk);
   36|       |
   37|       |    /* grp may already be initialized; if so, make sure IDs match */
   38|      1|    if (mbedtls_pk_ec_ro(*pk)->grp.id != MBEDTLS_ECP_DP_NONE &&
  ------------------
  |  Branch (38:9): [True: 0, False: 1]
  ------------------
   39|      1|        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|      1|    return mbedtls_ecp_group_load(&(ecp->grp), grp_id);
   45|      1|#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
   46|      1|}
mbedtls_pk_ecc_set_pubkey:
  205|      1|{
  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|      1|    int ret;
  245|      1|    mbedtls_ecp_keypair *ec_key = (mbedtls_ecp_keypair *) pk->pk_ctx;
  246|      1|    ret = mbedtls_ecp_point_read_binary(&ec_key->grp, &ec_key->Q, pub, pub_len);
  247|      1|    if (ret != 0) {
  ------------------
  |  Branch (247:9): [True: 0, False: 1]
  ------------------
  248|      0|        return ret;
  249|      0|    }
  250|      1|    return mbedtls_ecp_check_pubkey(&ec_key->grp, &ec_key->Q);
  251|       |
  252|      1|#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
  253|      1|}

pk_ecc.c:mbedtls_pk_ec_rw:
   73|      1|{
   74|      1|    switch (mbedtls_pk_get_type(&pk)) {
   75|      1|        case MBEDTLS_PK_ECKEY:
  ------------------
  |  Branch (75:9): [True: 1, False: 0]
  ------------------
   76|      1|        case MBEDTLS_PK_ECKEY_DH:
  ------------------
  |  Branch (76:9): [True: 0, False: 1]
  ------------------
   77|      1|        case MBEDTLS_PK_ECDSA:
  ------------------
  |  Branch (77:9): [True: 0, False: 1]
  ------------------
   78|      1|            return (mbedtls_ecp_keypair *) (pk).MBEDTLS_PRIVATE(pk_ctx);
  ------------------
  |  |   17|      1|#define MBEDTLS_PRIVATE(member) member
  ------------------
   79|      0|        default:
  ------------------
  |  Branch (79:9): [True: 0, False: 1]
  ------------------
   80|      0|            return NULL;
   81|      1|    }
   82|      1|}
pk_ecc.c:mbedtls_pk_ec_ro:
   61|      1|{
   62|      1|    switch (mbedtls_pk_get_type(&pk)) {
   63|      1|        case MBEDTLS_PK_ECKEY:
  ------------------
  |  Branch (63:9): [True: 1, False: 0]
  ------------------
   64|      1|        case MBEDTLS_PK_ECKEY_DH:
  ------------------
  |  Branch (64:9): [True: 0, False: 1]
  ------------------
   65|      1|        case MBEDTLS_PK_ECDSA:
  ------------------
  |  Branch (65:9): [True: 0, False: 1]
  ------------------
   66|      1|            return (const mbedtls_ecp_keypair *) (pk).MBEDTLS_PRIVATE(pk_ctx);
  ------------------
  |  |   17|      1|#define MBEDTLS_PRIVATE(member) member
  ------------------
   67|      0|        default:
  ------------------
  |  Branch (67:9): [True: 0, False: 1]
  ------------------
   68|      0|            return NULL;
   69|      1|    }
   70|      1|}

pk_wrap.c:rsa_alloc_wrap:
  455|      2|{
  456|      2|    void *ctx = mbedtls_calloc(1, sizeof(mbedtls_rsa_context));
  457|       |
  458|      2|    if (ctx != NULL) {
  ------------------
  |  Branch (458:9): [True: 2, False: 0]
  ------------------
  459|      2|        mbedtls_rsa_init((mbedtls_rsa_context *) ctx);
  460|      2|    }
  461|       |
  462|      2|    return ctx;
  463|      2|}
pk_wrap.c:eckey_alloc_wrap:
 1082|      1|{
 1083|      1|    void *ctx = mbedtls_calloc(1, sizeof(mbedtls_ecp_keypair));
 1084|       |
 1085|      1|    if (ctx != NULL) {
  ------------------
  |  Branch (1085:9): [True: 1, False: 0]
  ------------------
 1086|      1|        mbedtls_ecp_keypair_init(ctx);
 1087|      1|    }
 1088|       |
 1089|      1|    return ctx;
 1090|      1|}

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

mbedtls_calloc:
   48|     77|{
   49|     77|    return (*mbedtls_calloc_func)(nmemb, size);
   50|     77|}
mbedtls_free:
   53|     95|{
   54|     95|    (*mbedtls_free_func)(ptr);
   55|     95|}
mbedtls_platform_set_time:
  280|      1|{
  281|      1|    mbedtls_time = time_func;
  282|      1|    return 0;
  283|      1|}
mbedtls_platform_std_nv_seed_read:
  294|     21|{
  295|     21|    FILE *file;
  296|     21|    size_t n;
  297|       |
  298|     21|    if ((file = fopen(MBEDTLS_PLATFORM_STD_NV_SEED_FILE, "rb")) == NULL) {
  ------------------
  |  |  112|     21|#define MBEDTLS_PLATFORM_STD_NV_SEED_FILE   "seedfile"
  ------------------
  |  Branch (298:9): [True: 21, False: 0]
  ------------------
  299|     21|        return -1;
  300|     21|    }
  301|       |
  302|       |    /* Ensure no stdio buffering of secrets, as such buffers cannot be wiped. */
  303|      0|    mbedtls_setbuf(file, NULL);
  304|       |
  305|      0|    if ((n = fread(buf, 1, buf_len, file)) != buf_len) {
  ------------------
  |  Branch (305:9): [True: 0, False: 0]
  ------------------
  306|      0|        fclose(file);
  307|      0|        mbedtls_platform_zeroize(buf, buf_len);
  308|      0|        return -1;
  309|      0|    }
  310|       |
  311|      0|    fclose(file);
  312|      0|    return (int) n;
  313|      0|}

mbedtls_platform_zeroize:
   95|    411|{
   96|    411|    if (len > 0) {
  ------------------
  |  Branch (96:9): [True: 411, False: 0]
  ------------------
   97|    411|#if defined(MBEDTLS_PLATFORM_HAS_EXPLICIT_BZERO)
   98|    411|        explicit_bzero(buf, len);
   99|       |#if defined(HAVE_MEMORY_SANITIZER)
  100|       |        /* You'd think that Msan would recognize explicit_bzero() as
  101|       |         * equivalent to bzero(), but it actually doesn't on several
  102|       |         * platforms, including Linux (Ubuntu 20.04).
  103|       |         * https://github.com/google/sanitizers/issues/1507
  104|       |         * https://github.com/openssh/openssh-portable/commit/74433a19bb6f4cef607680fa4d1d7d81ca3826aa
  105|       |         */
  106|       |        __msan_unpoison(buf, len);
  107|       |#endif
  108|       |#elif defined(__STDC_LIB_EXT1__) && !defined(__IAR_SYSTEMS_ICC__)
  109|       |        memset_s(buf, len, 0, len);
  110|       |#elif defined(_WIN32)
  111|       |        SecureZeroMemory(buf, len);
  112|       |#else
  113|       |        memset_func(buf, 0, len);
  114|       |#endif
  115|       |
  116|    411|#if defined(__GNUC__)
  117|       |        /* For clang and recent gcc, pretend that we have some assembly that reads the
  118|       |         * zero'd memory as an additional protection against being optimised away. */
  119|    411|#if defined(__clang__) || (__GNUC__ >= 10)
  120|    411|#if defined(__clang__)
  121|    411|#pragma clang diagnostic push
  122|    411|#pragma clang diagnostic ignored "-Wvla"
  123|       |#elif defined(MBEDTLS_COMPILER_IS_GCC)
  124|       |#pragma GCC diagnostic push
  125|       |#pragma GCC diagnostic ignored "-Wvla"
  126|       |#endif
  127|    411|        asm volatile ("" : : "m" (*(char (*)[len]) buf) :);
  ------------------
  |  |  321|    411|#define asm __asm__
  ------------------
  128|    411|#if defined(__clang__)
  129|    411|#pragma clang diagnostic pop
  130|       |#elif defined(MBEDTLS_COMPILER_IS_GCC)
  131|       |#pragma GCC diagnostic pop
  132|       |#endif
  133|    411|#endif
  134|    411|#endif
  135|    411|    }
  136|    411|}
mbedtls_zeroize_and_free:
  140|      8|{
  141|      8|    if (buf != NULL) {
  ------------------
  |  Branch (141:9): [True: 8, False: 0]
  ------------------
  142|      8|        mbedtls_platform_zeroize(buf, len);
  143|      8|    }
  144|       |
  145|      8|    mbedtls_free(buf);
  146|      8|}

mbedtls_to_psa_error:
  333|     21|{
  334|       |    /* Mbed TLS error codes can combine a high-level error code and a
  335|       |     * low-level error code. The low-level error usually reflects the
  336|       |     * root cause better, so dispatch on that preferably. */
  337|     21|    int low_level_ret = -(-ret & 0x007f);
  338|     21|    switch (low_level_ret != 0 ? low_level_ret : ret) {
  ------------------
  |  Branch (338:13): [True: 21, False: 0]
  ------------------
  339|      0|        case 0:
  ------------------
  |  Branch (339:9): [True: 0, False: 21]
  ------------------
  340|      0|            return PSA_SUCCESS;
  ------------------
  |  |   57|      0|#define PSA_SUCCESS ((psa_status_t)0)
  ------------------
  341|       |
  342|      0|#if defined(MBEDTLS_AES_C)
  343|      0|        case MBEDTLS_ERR_AES_INVALID_KEY_LENGTH:
  ------------------
  |  |   44|      0|#define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH                -0x0020
  ------------------
  |  Branch (343:9): [True: 0, False: 21]
  ------------------
  344|      0|        case MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH:
  ------------------
  |  |   46|      0|#define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH              -0x0022
  ------------------
  |  Branch (344:9): [True: 0, False: 21]
  ------------------
  345|      0|            return PSA_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   73|      0|#define PSA_ERROR_NOT_SUPPORTED         ((psa_status_t)-134)
  ------------------
  346|      0|        case MBEDTLS_ERR_AES_BAD_INPUT_DATA:
  ------------------
  |  |   50|      0|#define MBEDTLS_ERR_AES_BAD_INPUT_DATA                    -0x0021
  ------------------
  |  Branch (346:9): [True: 0, False: 21]
  ------------------
  347|      0|            return PSA_ERROR_INVALID_ARGUMENT;
  ------------------
  |  |  137|      0|#define PSA_ERROR_INVALID_ARGUMENT      ((psa_status_t)-135)
  ------------------
  348|      0|#endif
  349|       |
  350|      0|#if defined(MBEDTLS_ASN1_PARSE_C) || defined(MBEDTLS_ASN1_WRITE_C)
  351|      0|        case MBEDTLS_ERR_ASN1_OUT_OF_DATA:
  ------------------
  |  |   37|      0|#define MBEDTLS_ERR_ASN1_OUT_OF_DATA                      -0x0060
  ------------------
  |  Branch (351:9): [True: 0, False: 21]
  ------------------
  352|      0|        case MBEDTLS_ERR_ASN1_UNEXPECTED_TAG:
  ------------------
  |  |   39|      0|#define MBEDTLS_ERR_ASN1_UNEXPECTED_TAG                   -0x0062
  ------------------
  |  Branch (352:9): [True: 0, False: 21]
  ------------------
  353|      0|        case MBEDTLS_ERR_ASN1_INVALID_LENGTH:
  ------------------
  |  |   41|      0|#define MBEDTLS_ERR_ASN1_INVALID_LENGTH                   -0x0064
  ------------------
  |  Branch (353:9): [True: 0, False: 21]
  ------------------
  354|      0|        case MBEDTLS_ERR_ASN1_LENGTH_MISMATCH:
  ------------------
  |  |   43|      0|#define MBEDTLS_ERR_ASN1_LENGTH_MISMATCH                  -0x0066
  ------------------
  |  Branch (354:9): [True: 0, False: 21]
  ------------------
  355|      0|        case MBEDTLS_ERR_ASN1_INVALID_DATA:
  ------------------
  |  |   45|      0|#define MBEDTLS_ERR_ASN1_INVALID_DATA                     -0x0068
  ------------------
  |  Branch (355:9): [True: 0, False: 21]
  ------------------
  356|      0|            return PSA_ERROR_INVALID_ARGUMENT;
  ------------------
  |  |  137|      0|#define PSA_ERROR_INVALID_ARGUMENT      ((psa_status_t)-135)
  ------------------
  357|      0|        case MBEDTLS_ERR_ASN1_ALLOC_FAILED:
  ------------------
  |  |   47|      0|#define MBEDTLS_ERR_ASN1_ALLOC_FAILED                     -0x006A
  ------------------
  |  Branch (357:9): [True: 0, False: 21]
  ------------------
  358|      0|            return PSA_ERROR_INSUFFICIENT_MEMORY;
  ------------------
  |  |  143|      0|#define PSA_ERROR_INSUFFICIENT_MEMORY   ((psa_status_t)-141)
  ------------------
  359|      0|        case MBEDTLS_ERR_ASN1_BUF_TOO_SMALL:
  ------------------
  |  |   49|      0|#define MBEDTLS_ERR_ASN1_BUF_TOO_SMALL                    -0x006C
  ------------------
  |  Branch (359:9): [True: 0, False: 21]
  ------------------
  360|      0|            return PSA_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   98|      0|#define PSA_ERROR_BUFFER_TOO_SMALL      ((psa_status_t)-138)
  ------------------
  361|      0|#endif
  362|       |
  363|      0|#if defined(MBEDTLS_CAMELLIA_C)
  364|      0|        case MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA:
  ------------------
  |  |   25|      0|#define MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA -0x0024
  ------------------
  |  Branch (364:9): [True: 0, False: 21]
  ------------------
  365|      0|        case MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH:
  ------------------
  |  |   28|      0|#define MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH -0x0026
  ------------------
  |  Branch (365:9): [True: 0, False: 21]
  ------------------
  366|      0|            return PSA_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   73|      0|#define PSA_ERROR_NOT_SUPPORTED         ((psa_status_t)-134)
  ------------------
  367|      0|#endif
  368|       |
  369|      0|#if defined(MBEDTLS_CCM_C)
  370|      0|        case MBEDTLS_ERR_CCM_BAD_INPUT:
  ------------------
  |  |   53|      0|#define MBEDTLS_ERR_CCM_BAD_INPUT       -0x000D
  ------------------
  |  Branch (370:9): [True: 0, False: 21]
  ------------------
  371|      0|            return PSA_ERROR_INVALID_ARGUMENT;
  ------------------
  |  |  137|      0|#define PSA_ERROR_INVALID_ARGUMENT      ((psa_status_t)-135)
  ------------------
  372|      0|        case MBEDTLS_ERR_CCM_AUTH_FAILED:
  ------------------
  |  |   55|      0|#define MBEDTLS_ERR_CCM_AUTH_FAILED     -0x000F
  ------------------
  |  Branch (372:9): [True: 0, False: 21]
  ------------------
  373|      0|            return PSA_ERROR_INVALID_SIGNATURE;
  ------------------
  |  |  260|      0|#define PSA_ERROR_INVALID_SIGNATURE     ((psa_status_t)-149)
  ------------------
  374|      0|#endif
  375|       |
  376|      0|#if defined(MBEDTLS_CHACHA20_C)
  377|      0|        case MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA:
  ------------------
  |  |   30|      0|#define MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA         -0x0051
  ------------------
  |  Branch (377:9): [True: 0, False: 21]
  ------------------
  378|      0|            return PSA_ERROR_INVALID_ARGUMENT;
  ------------------
  |  |  137|      0|#define PSA_ERROR_INVALID_ARGUMENT      ((psa_status_t)-135)
  ------------------
  379|      0|#endif
  380|       |
  381|      0|#if defined(MBEDTLS_CHACHAPOLY_C)
  382|      0|        case MBEDTLS_ERR_CHACHAPOLY_BAD_STATE:
  ------------------
  |  |   30|      0|#define MBEDTLS_ERR_CHACHAPOLY_BAD_STATE            -0x0054
  ------------------
  |  Branch (382:9): [True: 0, False: 21]
  ------------------
  383|      0|            return PSA_ERROR_BAD_STATE;
  ------------------
  |  |  126|      0|#define PSA_ERROR_BAD_STATE             ((psa_status_t)-137)
  ------------------
  384|      0|        case MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED:
  ------------------
  |  |   32|      0|#define MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED          -0x0056
  ------------------
  |  Branch (384:9): [True: 0, False: 21]
  ------------------
  385|      0|            return PSA_ERROR_INVALID_SIGNATURE;
  ------------------
  |  |  260|      0|#define PSA_ERROR_INVALID_SIGNATURE     ((psa_status_t)-149)
  ------------------
  386|      0|#endif
  387|       |
  388|      0|#if defined(MBEDTLS_CIPHER_C)
  389|      0|        case MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE:
  ------------------
  |  |   38|      0|#define MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE  -0x6080
  ------------------
  |  Branch (389:9): [True: 0, False: 21]
  ------------------
  390|      0|            return PSA_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   73|      0|#define PSA_ERROR_NOT_SUPPORTED         ((psa_status_t)-134)
  ------------------
  391|      0|        case MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA:
  ------------------
  |  |   40|      0|#define MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA       -0x6100
  ------------------
  |  Branch (391:9): [True: 0, False: 21]
  ------------------
  392|      0|            return PSA_ERROR_INVALID_ARGUMENT;
  ------------------
  |  |  137|      0|#define PSA_ERROR_INVALID_ARGUMENT      ((psa_status_t)-135)
  ------------------
  393|      0|        case MBEDTLS_ERR_CIPHER_ALLOC_FAILED:
  ------------------
  |  |   42|      0|#define MBEDTLS_ERR_CIPHER_ALLOC_FAILED         -0x6180
  ------------------
  |  Branch (393:9): [True: 0, False: 21]
  ------------------
  394|      0|            return PSA_ERROR_INSUFFICIENT_MEMORY;
  ------------------
  |  |  143|      0|#define PSA_ERROR_INSUFFICIENT_MEMORY   ((psa_status_t)-141)
  ------------------
  395|      0|        case MBEDTLS_ERR_CIPHER_INVALID_PADDING:
  ------------------
  |  |   44|      0|#define MBEDTLS_ERR_CIPHER_INVALID_PADDING      -0x6200
  ------------------
  |  Branch (395:9): [True: 0, False: 21]
  ------------------
  396|      0|            return PSA_ERROR_INVALID_PADDING;
  ------------------
  |  |  276|      0|#define PSA_ERROR_INVALID_PADDING       ((psa_status_t)-150)
  ------------------
  397|      0|        case MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED:
  ------------------
  |  |   46|      0|#define MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED  -0x6280
  ------------------
  |  Branch (397:9): [True: 0, False: 21]
  ------------------
  398|      0|            return PSA_ERROR_INVALID_ARGUMENT;
  ------------------
  |  |  137|      0|#define PSA_ERROR_INVALID_ARGUMENT      ((psa_status_t)-135)
  ------------------
  399|      0|        case MBEDTLS_ERR_CIPHER_AUTH_FAILED:
  ------------------
  |  |   48|      0|#define MBEDTLS_ERR_CIPHER_AUTH_FAILED          -0x6300
  ------------------
  |  Branch (399:9): [True: 0, False: 21]
  ------------------
  400|      0|            return PSA_ERROR_INVALID_SIGNATURE;
  ------------------
  |  |  260|      0|#define PSA_ERROR_INVALID_SIGNATURE     ((psa_status_t)-149)
  ------------------
  401|      0|        case MBEDTLS_ERR_CIPHER_INVALID_CONTEXT:
  ------------------
  |  |   50|      0|#define MBEDTLS_ERR_CIPHER_INVALID_CONTEXT      -0x6380
  ------------------
  |  Branch (401:9): [True: 0, False: 21]
  ------------------
  402|      0|            return PSA_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  231|      0|#define PSA_ERROR_CORRUPTION_DETECTED    ((psa_status_t)-151)
  ------------------
  403|      0|#endif
  404|       |
  405|      0|#if !(defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) ||      \
  406|      0|            defined(MBEDTLS_PSA_HMAC_DRBG_MD_TYPE))
  407|       |        /* Only check CTR_DRBG error codes if underlying mbedtls_xxx
  408|       |         * functions are passed a CTR_DRBG instance. */
  409|     21|        case MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED:
  ------------------
  |  |   65|     21|#define MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED        -0x0034
  ------------------
  |  Branch (409:9): [True: 21, False: 0]
  ------------------
  410|     21|            return PSA_ERROR_INSUFFICIENT_ENTROPY;
  ------------------
  |  |  250|     21|#define PSA_ERROR_INSUFFICIENT_ENTROPY  ((psa_status_t)-148)
  ------------------
  411|      0|        case MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG:
  ------------------
  |  |   67|      0|#define MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG              -0x0036
  ------------------
  |  Branch (411:9): [True: 0, False: 21]
  ------------------
  412|      0|        case MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG:
  ------------------
  |  |   69|      0|#define MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG                -0x0038
  ------------------
  |  Branch (412:9): [True: 0, False: 21]
  ------------------
  413|      0|            return PSA_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   73|      0|#define PSA_ERROR_NOT_SUPPORTED         ((psa_status_t)-134)
  ------------------
  414|      0|        case MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR:
  ------------------
  |  |   71|      0|#define MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR                -0x003A
  ------------------
  |  Branch (414:9): [True: 0, False: 21]
  ------------------
  415|      0|            return PSA_ERROR_INSUFFICIENT_ENTROPY;
  ------------------
  |  |  250|      0|#define PSA_ERROR_INSUFFICIENT_ENTROPY  ((psa_status_t)-148)
  ------------------
  416|      0|#endif
  417|       |
  418|      0|#if defined(MBEDTLS_DES_C)
  419|      0|        case MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH:
  ------------------
  |  |   29|      0|#define MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH              -0x0032
  ------------------
  |  Branch (419:9): [True: 0, False: 21]
  ------------------
  420|      0|            return PSA_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   73|      0|#define PSA_ERROR_NOT_SUPPORTED         ((psa_status_t)-134)
  ------------------
  421|      0|#endif
  422|       |
  423|      0|        case MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED:
  ------------------
  |  |   43|      0|#define MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED            -0x0040
  ------------------
  |  Branch (423:9): [True: 0, False: 21]
  ------------------
  424|      0|        case MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE:
  ------------------
  |  |   45|      0|#define MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE              -0x003D
  ------------------
  |  Branch (424:9): [True: 0, False: 21]
  ------------------
  425|      0|        case MBEDTLS_ERR_ENTROPY_SOURCE_FAILED:
  ------------------
  |  |   39|      0|#define MBEDTLS_ERR_ENTROPY_SOURCE_FAILED                 -0x003C
  ------------------
  |  Branch (425:9): [True: 0, False: 21]
  ------------------
  426|      0|            return PSA_ERROR_INSUFFICIENT_ENTROPY;
  ------------------
  |  |  250|      0|#define PSA_ERROR_INSUFFICIENT_ENTROPY  ((psa_status_t)-148)
  ------------------
  427|       |
  428|      0|#if defined(MBEDTLS_GCM_C)
  429|      0|        case MBEDTLS_ERR_GCM_AUTH_FAILED:
  ------------------
  |  |   37|      0|#define MBEDTLS_ERR_GCM_AUTH_FAILED                       -0x0012
  ------------------
  |  Branch (429:9): [True: 0, False: 21]
  ------------------
  430|      0|            return PSA_ERROR_INVALID_SIGNATURE;
  ------------------
  |  |  260|      0|#define PSA_ERROR_INVALID_SIGNATURE     ((psa_status_t)-149)
  ------------------
  431|      0|        case MBEDTLS_ERR_GCM_BUFFER_TOO_SMALL:
  ------------------
  |  |   41|      0|#define MBEDTLS_ERR_GCM_BUFFER_TOO_SMALL                  -0x0016
  ------------------
  |  Branch (431:9): [True: 0, False: 21]
  ------------------
  432|      0|            return PSA_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   98|      0|#define PSA_ERROR_BUFFER_TOO_SMALL      ((psa_status_t)-138)
  ------------------
  433|      0|        case MBEDTLS_ERR_GCM_BAD_INPUT:
  ------------------
  |  |   39|      0|#define MBEDTLS_ERR_GCM_BAD_INPUT                         -0x0014
  ------------------
  |  Branch (433:9): [True: 0, False: 21]
  ------------------
  434|      0|            return PSA_ERROR_INVALID_ARGUMENT;
  ------------------
  |  |  137|      0|#define PSA_ERROR_INVALID_ARGUMENT      ((psa_status_t)-135)
  ------------------
  435|      0|#endif
  436|       |
  437|       |#if !defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) &&        \
  438|       |            defined(MBEDTLS_PSA_HMAC_DRBG_MD_TYPE)
  439|       |        /* Only check HMAC_DRBG error codes if underlying mbedtls_xxx
  440|       |         * functions are passed a HMAC_DRBG instance. */
  441|       |        case MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED:
  442|       |            return PSA_ERROR_INSUFFICIENT_ENTROPY;
  443|       |        case MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG:
  444|       |        case MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG:
  445|       |            return PSA_ERROR_NOT_SUPPORTED;
  446|       |        case MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR:
  447|       |            return PSA_ERROR_INSUFFICIENT_ENTROPY;
  448|       |#endif
  449|       |
  450|      0|#if defined(MBEDTLS_MD_LIGHT)
  451|      0|        case MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE:
  ------------------
  |  |   24|      0|#define MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE                -0x5080
  ------------------
  |  Branch (451:9): [True: 0, False: 21]
  ------------------
  452|      0|            return PSA_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   73|      0|#define PSA_ERROR_NOT_SUPPORTED         ((psa_status_t)-134)
  ------------------
  453|      0|        case MBEDTLS_ERR_MD_BAD_INPUT_DATA:
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MD_BAD_INPUT_DATA                     -0x5100
  ------------------
  |  Branch (453:9): [True: 0, False: 21]
  ------------------
  454|      0|            return PSA_ERROR_INVALID_ARGUMENT;
  ------------------
  |  |  137|      0|#define PSA_ERROR_INVALID_ARGUMENT      ((psa_status_t)-135)
  ------------------
  455|      0|        case MBEDTLS_ERR_MD_ALLOC_FAILED:
  ------------------
  |  |   28|      0|#define MBEDTLS_ERR_MD_ALLOC_FAILED                       -0x5180
  ------------------
  |  Branch (455:9): [True: 0, False: 21]
  ------------------
  456|      0|            return PSA_ERROR_INSUFFICIENT_MEMORY;
  ------------------
  |  |  143|      0|#define PSA_ERROR_INSUFFICIENT_MEMORY   ((psa_status_t)-141)
  ------------------
  457|      0|#if defined(MBEDTLS_FS_IO)
  458|      0|        case MBEDTLS_ERR_MD_FILE_IO_ERROR:
  ------------------
  |  |   30|      0|#define MBEDTLS_ERR_MD_FILE_IO_ERROR                      -0x5200
  ------------------
  |  Branch (458:9): [True: 0, False: 21]
  ------------------
  459|      0|            return PSA_ERROR_STORAGE_FAILURE;
  ------------------
  |  |  194|      0|#define PSA_ERROR_STORAGE_FAILURE       ((psa_status_t)-146)
  ------------------
  460|      0|#endif
  461|      0|#endif
  462|       |
  463|      0|#if defined(MBEDTLS_BIGNUM_C)
  464|      0|#if defined(MBEDTLS_FS_IO)
  465|      0|        case MBEDTLS_ERR_MPI_FILE_IO_ERROR:
  ------------------
  |  |   24|      0|#define MBEDTLS_ERR_MPI_FILE_IO_ERROR                     -0x0002
  ------------------
  |  Branch (465:9): [True: 0, False: 21]
  ------------------
  466|      0|            return PSA_ERROR_STORAGE_FAILURE;
  ------------------
  |  |  194|      0|#define PSA_ERROR_STORAGE_FAILURE       ((psa_status_t)-146)
  ------------------
  467|      0|#endif
  468|      0|        case MBEDTLS_ERR_MPI_BAD_INPUT_DATA:
  ------------------
  |  |   26|      0|#define MBEDTLS_ERR_MPI_BAD_INPUT_DATA                    -0x0004
  ------------------
  |  Branch (468:9): [True: 0, False: 21]
  ------------------
  469|      0|            return PSA_ERROR_INVALID_ARGUMENT;
  ------------------
  |  |  137|      0|#define PSA_ERROR_INVALID_ARGUMENT      ((psa_status_t)-135)
  ------------------
  470|      0|        case MBEDTLS_ERR_MPI_INVALID_CHARACTER:
  ------------------
  |  |   28|      0|#define MBEDTLS_ERR_MPI_INVALID_CHARACTER                 -0x0006
  ------------------
  |  Branch (470:9): [True: 0, False: 21]
  ------------------
  471|      0|            return PSA_ERROR_INVALID_ARGUMENT;
  ------------------
  |  |  137|      0|#define PSA_ERROR_INVALID_ARGUMENT      ((psa_status_t)-135)
  ------------------
  472|      0|        case MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL:
  ------------------
  |  |   30|      0|#define MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL                  -0x0008
  ------------------
  |  Branch (472:9): [True: 0, False: 21]
  ------------------
  473|      0|            return PSA_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   98|      0|#define PSA_ERROR_BUFFER_TOO_SMALL      ((psa_status_t)-138)
  ------------------
  474|      0|        case MBEDTLS_ERR_MPI_NEGATIVE_VALUE:
  ------------------
  |  |   32|      0|#define MBEDTLS_ERR_MPI_NEGATIVE_VALUE                    -0x000A
  ------------------
  |  Branch (474:9): [True: 0, False: 21]
  ------------------
  475|      0|            return PSA_ERROR_INVALID_ARGUMENT;
  ------------------
  |  |  137|      0|#define PSA_ERROR_INVALID_ARGUMENT      ((psa_status_t)-135)
  ------------------
  476|      0|        case MBEDTLS_ERR_MPI_DIVISION_BY_ZERO:
  ------------------
  |  |   34|      0|#define MBEDTLS_ERR_MPI_DIVISION_BY_ZERO                  -0x000C
  ------------------
  |  Branch (476:9): [True: 0, False: 21]
  ------------------
  477|      0|            return PSA_ERROR_INVALID_ARGUMENT;
  ------------------
  |  |  137|      0|#define PSA_ERROR_INVALID_ARGUMENT      ((psa_status_t)-135)
  ------------------
  478|      0|        case MBEDTLS_ERR_MPI_NOT_ACCEPTABLE:
  ------------------
  |  |   36|      0|#define MBEDTLS_ERR_MPI_NOT_ACCEPTABLE                    -0x000E
  ------------------
  |  Branch (478:9): [True: 0, False: 21]
  ------------------
  479|      0|            return PSA_ERROR_INVALID_ARGUMENT;
  ------------------
  |  |  137|      0|#define PSA_ERROR_INVALID_ARGUMENT      ((psa_status_t)-135)
  ------------------
  480|      0|        case MBEDTLS_ERR_MPI_ALLOC_FAILED:
  ------------------
  |  |   38|      0|#define MBEDTLS_ERR_MPI_ALLOC_FAILED                      -0x0010
  ------------------
  |  Branch (480:9): [True: 0, False: 21]
  ------------------
  481|      0|            return PSA_ERROR_INSUFFICIENT_MEMORY;
  ------------------
  |  |  143|      0|#define PSA_ERROR_INSUFFICIENT_MEMORY   ((psa_status_t)-141)
  ------------------
  482|      0|#endif
  483|       |
  484|      0|#if defined(MBEDTLS_PK_C)
  485|      0|        case MBEDTLS_ERR_PK_ALLOC_FAILED:
  ------------------
  |  |   36|      0|#define MBEDTLS_ERR_PK_ALLOC_FAILED        -0x3F80
  ------------------
  |  Branch (485:9): [True: 0, False: 21]
  ------------------
  486|      0|            return PSA_ERROR_INSUFFICIENT_MEMORY;
  ------------------
  |  |  143|      0|#define PSA_ERROR_INSUFFICIENT_MEMORY   ((psa_status_t)-141)
  ------------------
  487|      0|        case MBEDTLS_ERR_PK_TYPE_MISMATCH:
  ------------------
  |  |   38|      0|#define MBEDTLS_ERR_PK_TYPE_MISMATCH       -0x3F00
  ------------------
  |  Branch (487:9): [True: 0, False: 21]
  ------------------
  488|      0|        case MBEDTLS_ERR_PK_BAD_INPUT_DATA:
  ------------------
  |  |   40|      0|#define MBEDTLS_ERR_PK_BAD_INPUT_DATA      -0x3E80
  ------------------
  |  Branch (488:9): [True: 0, False: 21]
  ------------------
  489|      0|            return PSA_ERROR_INVALID_ARGUMENT;
  ------------------
  |  |  137|      0|#define PSA_ERROR_INVALID_ARGUMENT      ((psa_status_t)-135)
  ------------------
  490|      0|#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) || defined(MBEDTLS_FS_IO) || \
  491|      0|            defined(MBEDTLS_PSA_ITS_FILE_C)
  492|      0|        case MBEDTLS_ERR_PK_FILE_IO_ERROR:
  ------------------
  |  |   42|      0|#define MBEDTLS_ERR_PK_FILE_IO_ERROR       -0x3E00
  ------------------
  |  Branch (492:9): [True: 0, False: 21]
  ------------------
  493|      0|            return PSA_ERROR_STORAGE_FAILURE;
  ------------------
  |  |  194|      0|#define PSA_ERROR_STORAGE_FAILURE       ((psa_status_t)-146)
  ------------------
  494|      0|#endif
  495|      0|        case MBEDTLS_ERR_PK_KEY_INVALID_VERSION:
  ------------------
  |  |   44|      0|#define MBEDTLS_ERR_PK_KEY_INVALID_VERSION -0x3D80
  ------------------
  |  Branch (495:9): [True: 0, False: 21]
  ------------------
  496|      0|        case MBEDTLS_ERR_PK_KEY_INVALID_FORMAT:
  ------------------
  |  |   46|      0|#define MBEDTLS_ERR_PK_KEY_INVALID_FORMAT  -0x3D00
  ------------------
  |  Branch (496:9): [True: 0, False: 21]
  ------------------
  497|      0|            return PSA_ERROR_INVALID_ARGUMENT;
  ------------------
  |  |  137|      0|#define PSA_ERROR_INVALID_ARGUMENT      ((psa_status_t)-135)
  ------------------
  498|      0|        case MBEDTLS_ERR_PK_UNKNOWN_PK_ALG:
  ------------------
  |  |   48|      0|#define MBEDTLS_ERR_PK_UNKNOWN_PK_ALG      -0x3C80
  ------------------
  |  Branch (498:9): [True: 0, False: 21]
  ------------------
  499|      0|            return PSA_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   73|      0|#define PSA_ERROR_NOT_SUPPORTED         ((psa_status_t)-134)
  ------------------
  500|      0|        case MBEDTLS_ERR_PK_PASSWORD_REQUIRED:
  ------------------
  |  |   50|      0|#define MBEDTLS_ERR_PK_PASSWORD_REQUIRED   -0x3C00
  ------------------
  |  Branch (500:9): [True: 0, False: 21]
  ------------------
  501|      0|        case MBEDTLS_ERR_PK_PASSWORD_MISMATCH:
  ------------------
  |  |   52|      0|#define MBEDTLS_ERR_PK_PASSWORD_MISMATCH   -0x3B80
  ------------------
  |  Branch (501:9): [True: 0, False: 21]
  ------------------
  502|      0|            return PSA_ERROR_NOT_PERMITTED;
  ------------------
  |  |   86|      0|#define PSA_ERROR_NOT_PERMITTED         ((psa_status_t)-133)
  ------------------
  503|      0|        case MBEDTLS_ERR_PK_INVALID_PUBKEY:
  ------------------
  |  |   54|      0|#define MBEDTLS_ERR_PK_INVALID_PUBKEY      -0x3B00
  ------------------
  |  Branch (503:9): [True: 0, False: 21]
  ------------------
  504|      0|            return PSA_ERROR_INVALID_ARGUMENT;
  ------------------
  |  |  137|      0|#define PSA_ERROR_INVALID_ARGUMENT      ((psa_status_t)-135)
  ------------------
  505|      0|        case MBEDTLS_ERR_PK_INVALID_ALG:
  ------------------
  |  |   56|      0|#define MBEDTLS_ERR_PK_INVALID_ALG         -0x3A80
  ------------------
  |  Branch (505:9): [True: 0, False: 21]
  ------------------
  506|      0|        case MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE:
  ------------------
  |  |   58|      0|#define MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE -0x3A00
  ------------------
  |  Branch (506:9): [True: 0, False: 21]
  ------------------
  507|      0|        case MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE:
  ------------------
  |  |   60|      0|#define MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE -0x3980
  ------------------
  |  Branch (507:9): [True: 0, False: 21]
  ------------------
  508|      0|            return PSA_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   73|      0|#define PSA_ERROR_NOT_SUPPORTED         ((psa_status_t)-134)
  ------------------
  509|      0|        case MBEDTLS_ERR_PK_SIG_LEN_MISMATCH:
  ------------------
  |  |   62|      0|#define MBEDTLS_ERR_PK_SIG_LEN_MISMATCH    -0x3900
  ------------------
  |  Branch (509:9): [True: 0, False: 21]
  ------------------
  510|      0|            return PSA_ERROR_INVALID_SIGNATURE;
  ------------------
  |  |  260|      0|#define PSA_ERROR_INVALID_SIGNATURE     ((psa_status_t)-149)
  ------------------
  511|      0|        case MBEDTLS_ERR_PK_BUFFER_TOO_SMALL:
  ------------------
  |  |   64|      0|#define MBEDTLS_ERR_PK_BUFFER_TOO_SMALL    -0x3880
  ------------------
  |  Branch (511:9): [True: 0, False: 21]
  ------------------
  512|      0|            return PSA_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   98|      0|#define PSA_ERROR_BUFFER_TOO_SMALL      ((psa_status_t)-138)
  ------------------
  513|      0|#endif
  514|       |
  515|      0|        case MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED:
  ------------------
  |  |  103|      0|#define MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED     -0x0070
  ------------------
  |  Branch (515:9): [True: 0, False: 21]
  ------------------
  516|      0|            return PSA_ERROR_HARDWARE_FAILURE;
  ------------------
  |  |  200|      0|#define PSA_ERROR_HARDWARE_FAILURE      ((psa_status_t)-147)
  ------------------
  517|      0|        case MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED:
  ------------------
  |  |  105|      0|#define MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED -0x0072
  ------------------
  |  Branch (517:9): [True: 0, False: 21]
  ------------------
  518|      0|            return PSA_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   73|      0|#define PSA_ERROR_NOT_SUPPORTED         ((psa_status_t)-134)
  ------------------
  519|       |
  520|      0|#if defined(MBEDTLS_RSA_C)
  521|      0|        case MBEDTLS_ERR_RSA_BAD_INPUT_DATA:
  ------------------
  |  |   33|      0|#define MBEDTLS_ERR_RSA_BAD_INPUT_DATA                    -0x4080
  ------------------
  |  Branch (521:9): [True: 0, False: 21]
  ------------------
  522|      0|            return PSA_ERROR_INVALID_ARGUMENT;
  ------------------
  |  |  137|      0|#define PSA_ERROR_INVALID_ARGUMENT      ((psa_status_t)-135)
  ------------------
  523|      0|        case MBEDTLS_ERR_RSA_INVALID_PADDING:
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_RSA_INVALID_PADDING                   -0x4100
  ------------------
  |  Branch (523:9): [True: 0, False: 21]
  ------------------
  524|      0|            return PSA_ERROR_INVALID_PADDING;
  ------------------
  |  |  276|      0|#define PSA_ERROR_INVALID_PADDING       ((psa_status_t)-150)
  ------------------
  525|      0|        case MBEDTLS_ERR_RSA_KEY_GEN_FAILED:
  ------------------
  |  |   37|      0|#define MBEDTLS_ERR_RSA_KEY_GEN_FAILED                    -0x4180
  ------------------
  |  Branch (525:9): [True: 0, False: 21]
  ------------------
  526|      0|            return PSA_ERROR_HARDWARE_FAILURE;
  ------------------
  |  |  200|      0|#define PSA_ERROR_HARDWARE_FAILURE      ((psa_status_t)-147)
  ------------------
  527|      0|        case MBEDTLS_ERR_RSA_KEY_CHECK_FAILED:
  ------------------
  |  |   39|      0|#define MBEDTLS_ERR_RSA_KEY_CHECK_FAILED                  -0x4200
  ------------------
  |  Branch (527:9): [True: 0, False: 21]
  ------------------
  528|      0|            return PSA_ERROR_INVALID_ARGUMENT;
  ------------------
  |  |  137|      0|#define PSA_ERROR_INVALID_ARGUMENT      ((psa_status_t)-135)
  ------------------
  529|      0|        case MBEDTLS_ERR_RSA_PUBLIC_FAILED:
  ------------------
  |  |   41|      0|#define MBEDTLS_ERR_RSA_PUBLIC_FAILED                     -0x4280
  ------------------
  |  Branch (529:9): [True: 0, False: 21]
  ------------------
  530|      0|        case MBEDTLS_ERR_RSA_PRIVATE_FAILED:
  ------------------
  |  |   43|      0|#define MBEDTLS_ERR_RSA_PRIVATE_FAILED                    -0x4300
  ------------------
  |  Branch (530:9): [True: 0, False: 21]
  ------------------
  531|      0|            return PSA_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  231|      0|#define PSA_ERROR_CORRUPTION_DETECTED    ((psa_status_t)-151)
  ------------------
  532|      0|        case MBEDTLS_ERR_RSA_VERIFY_FAILED:
  ------------------
  |  |   45|      0|#define MBEDTLS_ERR_RSA_VERIFY_FAILED                     -0x4380
  ------------------
  |  Branch (532:9): [True: 0, False: 21]
  ------------------
  533|      0|            return PSA_ERROR_INVALID_SIGNATURE;
  ------------------
  |  |  260|      0|#define PSA_ERROR_INVALID_SIGNATURE     ((psa_status_t)-149)
  ------------------
  534|      0|        case MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE:
  ------------------
  |  |   47|      0|#define MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE                  -0x4400
  ------------------
  |  Branch (534:9): [True: 0, False: 21]
  ------------------
  535|      0|            return PSA_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   98|      0|#define PSA_ERROR_BUFFER_TOO_SMALL      ((psa_status_t)-138)
  ------------------
  536|      0|        case MBEDTLS_ERR_RSA_RNG_FAILED:
  ------------------
  |  |   49|      0|#define MBEDTLS_ERR_RSA_RNG_FAILED                        -0x4480
  ------------------
  |  Branch (536:9): [True: 0, False: 21]
  ------------------
  537|      0|            return PSA_ERROR_INSUFFICIENT_ENTROPY;
  ------------------
  |  |  250|      0|#define PSA_ERROR_INSUFFICIENT_ENTROPY  ((psa_status_t)-148)
  ------------------
  538|      0|#endif
  539|       |
  540|      0|#if defined(MBEDTLS_ECP_LIGHT)
  541|      0|        case MBEDTLS_ERR_ECP_BAD_INPUT_DATA:
  ------------------
  |  |   35|      0|#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA                    -0x4F80
  ------------------
  |  Branch (541:9): [True: 0, False: 21]
  ------------------
  542|      0|        case MBEDTLS_ERR_ECP_INVALID_KEY:
  ------------------
  |  |   47|      0|#define MBEDTLS_ERR_ECP_INVALID_KEY                       -0x4C80
  ------------------
  |  Branch (542:9): [True: 0, False: 21]
  ------------------
  543|      0|            return PSA_ERROR_INVALID_ARGUMENT;
  ------------------
  |  |  137|      0|#define PSA_ERROR_INVALID_ARGUMENT      ((psa_status_t)-135)
  ------------------
  544|      0|        case MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL:
  ------------------
  |  |   37|      0|#define MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL                  -0x4F00
  ------------------
  |  Branch (544:9): [True: 0, False: 21]
  ------------------
  545|      0|            return PSA_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   98|      0|#define PSA_ERROR_BUFFER_TOO_SMALL      ((psa_status_t)-138)
  ------------------
  546|      0|        case MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE:
  ------------------
  |  |   39|      0|#define MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE               -0x4E80
  ------------------
  |  Branch (546:9): [True: 0, False: 21]
  ------------------
  547|      0|            return PSA_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   73|      0|#define PSA_ERROR_NOT_SUPPORTED         ((psa_status_t)-134)
  ------------------
  548|      0|        case MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH:
  ------------------
  |  |   49|      0|#define MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH                  -0x4C00
  ------------------
  |  Branch (548:9): [True: 0, False: 21]
  ------------------
  549|      0|        case MBEDTLS_ERR_ECP_VERIFY_FAILED:
  ------------------
  |  |   41|      0|#define MBEDTLS_ERR_ECP_VERIFY_FAILED                     -0x4E00
  ------------------
  |  Branch (549:9): [True: 0, False: 21]
  ------------------
  550|      0|            return PSA_ERROR_INVALID_SIGNATURE;
  ------------------
  |  |  260|      0|#define PSA_ERROR_INVALID_SIGNATURE     ((psa_status_t)-149)
  ------------------
  551|      0|        case MBEDTLS_ERR_ECP_ALLOC_FAILED:
  ------------------
  |  |   43|      0|#define MBEDTLS_ERR_ECP_ALLOC_FAILED                      -0x4D80
  ------------------
  |  Branch (551:9): [True: 0, False: 21]
  ------------------
  552|      0|            return PSA_ERROR_INSUFFICIENT_MEMORY;
  ------------------
  |  |  143|      0|#define PSA_ERROR_INSUFFICIENT_MEMORY   ((psa_status_t)-141)
  ------------------
  553|      0|        case MBEDTLS_ERR_ECP_RANDOM_FAILED:
  ------------------
  |  |   45|      0|#define MBEDTLS_ERR_ECP_RANDOM_FAILED                     -0x4D00
  ------------------
  |  Branch (553:9): [True: 0, False: 21]
  ------------------
  554|      0|            return PSA_ERROR_INSUFFICIENT_ENTROPY;
  ------------------
  |  |  250|      0|#define PSA_ERROR_INSUFFICIENT_ENTROPY  ((psa_status_t)-148)
  ------------------
  555|       |
  556|      0|#if defined(MBEDTLS_ECP_RESTARTABLE)
  557|      0|        case MBEDTLS_ERR_ECP_IN_PROGRESS:
  ------------------
  |  |   51|      0|#define MBEDTLS_ERR_ECP_IN_PROGRESS                       -0x4B00
  ------------------
  |  Branch (557:9): [True: 0, False: 21]
  ------------------
  558|      0|            return PSA_OPERATION_INCOMPLETE;
  ------------------
  |  |  336|      0|#define PSA_OPERATION_INCOMPLETE           ((psa_status_t)-248)
  ------------------
  559|      0|#endif
  560|      0|#endif
  561|       |
  562|      0|        case MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED:
  ------------------
  |  |  100|      0|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  |  Branch (562:9): [True: 0, False: 21]
  ------------------
  563|      0|            return PSA_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  231|      0|#define PSA_ERROR_CORRUPTION_DETECTED    ((psa_status_t)-151)
  ------------------
  564|       |
  565|      0|        default:
  ------------------
  |  Branch (565:9): [True: 0, False: 21]
  ------------------
  566|      0|            return PSA_ERROR_GENERIC_ERROR;
  ------------------
  |  |   64|      0|#define PSA_ERROR_GENERIC_ERROR         ((psa_status_t)-132)
  ------------------
  567|     21|    }
  568|     21|}
mbedtls_psa_crypto_free:
 8244|     42|{
 8245|       |
 8246|     42|#if defined(MBEDTLS_THREADING_C)
 8247|     42|    mbedtls_mutex_lock(&mbedtls_threading_psa_globaldata_mutex);
 8248|     42|#endif /* defined(MBEDTLS_THREADING_C) */
 8249|       |
 8250|       |    /* Nothing to do to free transaction. */
 8251|     42|    if (global_data.initialized & PSA_CRYPTO_SUBSYSTEM_TRANSACTION_INITIALIZED) {
  ------------------
  |  |  108|     42|#define PSA_CRYPTO_SUBSYSTEM_TRANSACTION_INITIALIZED        0x04
  ------------------
  |  Branch (8251:9): [True: 0, False: 42]
  ------------------
 8252|      0|        global_data.initialized &= ~PSA_CRYPTO_SUBSYSTEM_TRANSACTION_INITIALIZED;
  ------------------
  |  |  108|      0|#define PSA_CRYPTO_SUBSYSTEM_TRANSACTION_INITIALIZED        0x04
  ------------------
 8253|      0|    }
 8254|       |
 8255|     42|    if (global_data.initialized & PSA_CRYPTO_SUBSYSTEM_KEY_SLOTS_INITIALIZED) {
  ------------------
  |  |  107|     42|#define PSA_CRYPTO_SUBSYSTEM_KEY_SLOTS_INITIALIZED          0x02
  ------------------
  |  Branch (8255:9): [True: 21, False: 21]
  ------------------
 8256|     21|        psa_wipe_all_key_slots();
 8257|     21|        global_data.initialized &= ~PSA_CRYPTO_SUBSYSTEM_KEY_SLOTS_INITIALIZED;
  ------------------
  |  |  107|     21|#define PSA_CRYPTO_SUBSYSTEM_KEY_SLOTS_INITIALIZED          0x02
  ------------------
 8258|     21|    }
 8259|       |
 8260|     42|#if defined(MBEDTLS_THREADING_C)
 8261|     42|    mbedtls_mutex_unlock(&mbedtls_threading_psa_globaldata_mutex);
 8262|     42|#endif /* defined(MBEDTLS_THREADING_C) */
 8263|       |
 8264|     42|#if defined(MBEDTLS_THREADING_C)
 8265|     42|    mbedtls_mutex_lock(&mbedtls_threading_psa_rngdata_mutex);
 8266|     42|#endif /* defined(MBEDTLS_THREADING_C) */
 8267|       |
 8268|     42|    if (global_data.rng_state != RNG_NOT_INITIALIZED) {
  ------------------
  |  |   92|     42|#define RNG_NOT_INITIALIZED 0
  ------------------
  |  Branch (8268:9): [True: 21, False: 21]
  ------------------
 8269|     21|        mbedtls_psa_random_free(&global_data.rng);
 8270|     21|    }
 8271|     42|    global_data.rng_state = RNG_NOT_INITIALIZED;
  ------------------
  |  |   92|     42|#define RNG_NOT_INITIALIZED 0
  ------------------
 8272|     42|    mbedtls_platform_zeroize(&global_data.rng, sizeof(global_data.rng));
 8273|       |
 8274|     42|#if defined(MBEDTLS_THREADING_C)
 8275|     42|    mbedtls_mutex_unlock(&mbedtls_threading_psa_rngdata_mutex);
 8276|     42|#endif /* defined(MBEDTLS_THREADING_C) */
 8277|       |
 8278|     42|#if defined(MBEDTLS_THREADING_C)
 8279|     42|    mbedtls_mutex_lock(&mbedtls_threading_psa_globaldata_mutex);
 8280|     42|#endif /* defined(MBEDTLS_THREADING_C) */
 8281|       |
 8282|       |    /* Terminate drivers */
 8283|     42|    if (global_data.initialized & PSA_CRYPTO_SUBSYSTEM_DRIVER_WRAPPERS_INITIALIZED) {
  ------------------
  |  |  106|     42|#define PSA_CRYPTO_SUBSYSTEM_DRIVER_WRAPPERS_INITIALIZED    0x01
  ------------------
  |  Branch (8283:9): [True: 21, False: 21]
  ------------------
 8284|     21|        psa_driver_wrapper_free();
 8285|     21|        global_data.initialized &= ~PSA_CRYPTO_SUBSYSTEM_DRIVER_WRAPPERS_INITIALIZED;
  ------------------
  |  |  106|     21|#define PSA_CRYPTO_SUBSYSTEM_DRIVER_WRAPPERS_INITIALIZED    0x01
  ------------------
 8286|     21|    }
 8287|       |
 8288|     42|#if defined(MBEDTLS_THREADING_C)
 8289|     42|    mbedtls_mutex_unlock(&mbedtls_threading_psa_globaldata_mutex);
 8290|     42|#endif /* defined(MBEDTLS_THREADING_C) */
 8291|       |
 8292|     42|}
psa_crypto_init:
 8452|     21|{
 8453|     21|    psa_status_t status;
 8454|       |
 8455|       |    /* Double initialization is explicitly allowed. Early out if everything is
 8456|       |     * done. */
 8457|     21|    if (psa_get_initialized()) {
  ------------------
  |  Branch (8457:9): [True: 0, False: 21]
  ------------------
 8458|      0|        return PSA_SUCCESS;
  ------------------
  |  |   57|      0|#define PSA_SUCCESS ((psa_status_t)0)
  ------------------
 8459|      0|    }
 8460|       |
 8461|     21|    status = mbedtls_psa_crypto_init_subsystem(PSA_CRYPTO_SUBSYSTEM_DRIVER_WRAPPERS);
 8462|     21|    if (status != PSA_SUCCESS) {
  ------------------
  |  |   57|     21|#define PSA_SUCCESS ((psa_status_t)0)
  ------------------
  |  Branch (8462:9): [True: 0, False: 21]
  ------------------
 8463|      0|        goto exit;
 8464|      0|    }
 8465|       |
 8466|     21|    status = mbedtls_psa_crypto_init_subsystem(PSA_CRYPTO_SUBSYSTEM_KEY_SLOTS);
 8467|     21|    if (status != PSA_SUCCESS) {
  ------------------
  |  |   57|     21|#define PSA_SUCCESS ((psa_status_t)0)
  ------------------
  |  Branch (8467:9): [True: 0, False: 21]
  ------------------
 8468|      0|        goto exit;
 8469|      0|    }
 8470|       |
 8471|     21|    status = mbedtls_psa_crypto_init_subsystem(PSA_CRYPTO_SUBSYSTEM_RNG);
 8472|     21|    if (status != PSA_SUCCESS) {
  ------------------
  |  |   57|     21|#define PSA_SUCCESS ((psa_status_t)0)
  ------------------
  |  Branch (8472:9): [True: 21, False: 0]
  ------------------
 8473|     21|        goto exit;
 8474|     21|    }
 8475|       |
 8476|      0|    status = mbedtls_psa_crypto_init_subsystem(PSA_CRYPTO_SUBSYSTEM_TRANSACTION);
 8477|       |
 8478|     21|exit:
 8479|       |
 8480|     21|    if (status != PSA_SUCCESS) {
  ------------------
  |  |   57|     21|#define PSA_SUCCESS ((psa_status_t)0)
  ------------------
  |  Branch (8480:9): [True: 21, False: 0]
  ------------------
 8481|     21|        mbedtls_psa_crypto_free();
 8482|     21|    }
 8483|       |
 8484|     21|    return status;
 8485|      0|}
psa_crypto.c:mbedtls_psa_random_free:
 7915|     21|{
 7916|       |#if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
 7917|       |    memset(rng, 0, sizeof(*rng));
 7918|       |#else /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
 7919|     21|    mbedtls_psa_drbg_free(&rng->drbg);
 7920|     21|    rng->entropy_free(&rng->entropy);
 7921|     21|#endif /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
 7922|     21|}
psa_crypto.c:psa_get_initialized:
  124|     21|{
  125|     21|    uint8_t initialized;
  126|       |
  127|     21|#if defined(MBEDTLS_THREADING_C)
  128|     21|    mbedtls_mutex_lock(&mbedtls_threading_psa_rngdata_mutex);
  129|     21|#endif /* defined(MBEDTLS_THREADING_C) */
  130|       |
  131|     21|    initialized = global_data.rng_state == RNG_SEEDED;
  ------------------
  |  |   94|     21|#define RNG_SEEDED 2
  ------------------
  132|       |
  133|     21|#if defined(MBEDTLS_THREADING_C)
  134|     21|    mbedtls_mutex_unlock(&mbedtls_threading_psa_rngdata_mutex);
  135|     21|#endif /* defined(MBEDTLS_THREADING_C) */
  136|       |
  137|     21|#if defined(MBEDTLS_THREADING_C)
  138|     21|    mbedtls_mutex_lock(&mbedtls_threading_psa_globaldata_mutex);
  139|     21|#endif /* defined(MBEDTLS_THREADING_C) */
  140|       |
  141|     21|    initialized =
  142|     21|        (initialized && (global_data.initialized == PSA_CRYPTO_SUBSYSTEM_ALL_INITIALISED));
  ------------------
  |  |  110|      0|#define PSA_CRYPTO_SUBSYSTEM_ALL_INITIALISED                ( \
  |  |  111|      0|        PSA_CRYPTO_SUBSYSTEM_DRIVER_WRAPPERS_INITIALIZED | \
  |  |  ------------------
  |  |  |  |  106|      0|#define PSA_CRYPTO_SUBSYSTEM_DRIVER_WRAPPERS_INITIALIZED    0x01
  |  |  ------------------
  |  |  112|      0|        PSA_CRYPTO_SUBSYSTEM_KEY_SLOTS_INITIALIZED | \
  |  |  ------------------
  |  |  |  |  107|      0|#define PSA_CRYPTO_SUBSYSTEM_KEY_SLOTS_INITIALIZED          0x02
  |  |  ------------------
  |  |  113|      0|        PSA_CRYPTO_SUBSYSTEM_TRANSACTION_INITIALIZED)
  |  |  ------------------
  |  |  |  |  108|      0|#define PSA_CRYPTO_SUBSYSTEM_TRANSACTION_INITIALIZED        0x04
  |  |  ------------------
  ------------------
  |  Branch (142:10): [True: 0, False: 21]
  |  Branch (142:25): [True: 0, False: 0]
  ------------------
  143|       |
  144|     21|#if defined(MBEDTLS_THREADING_C)
  145|     21|    mbedtls_mutex_unlock(&mbedtls_threading_psa_globaldata_mutex);
  146|     21|#endif /* defined(MBEDTLS_THREADING_C) */
  147|       |
  148|     21|    return initialized;
  149|     21|}
psa_crypto.c:mbedtls_psa_crypto_init_subsystem:
 8320|     63|{
 8321|     63|    psa_status_t status = PSA_SUCCESS;
  ------------------
  |  |   57|     63|#define PSA_SUCCESS ((psa_status_t)0)
  ------------------
 8322|     63|    uint8_t driver_wrappers_initialized = 0;
 8323|       |
 8324|     63|    switch (subsystem) {
 8325|     21|        case PSA_CRYPTO_SUBSYSTEM_DRIVER_WRAPPERS:
  ------------------
  |  Branch (8325:9): [True: 21, False: 42]
  ------------------
 8326|       |
 8327|     21|#if defined(MBEDTLS_THREADING_C)
 8328|     21|            PSA_THREADING_CHK_GOTO_EXIT(mbedtls_mutex_lock(&mbedtls_threading_psa_globaldata_mutex));
  ------------------
  |  |  199|     21|    do                                                 \
  |  |  200|     21|    {                                                  \
  |  |  201|     21|        if ((f) != 0) {                                \
  |  |  ------------------
  |  |  |  Branch (201:13): [True: 0, False: 21]
  |  |  ------------------
  |  |  202|      0|            if (status == PSA_SUCCESS) {               \
  |  |  ------------------
  |  |  |  |   57|      0|#define PSA_SUCCESS ((psa_status_t)0)
  |  |  ------------------
  |  |  |  Branch (202:17): [True: 0, False: 0]
  |  |  ------------------
  |  |  203|      0|                status = PSA_ERROR_SERVICE_FAILURE;    \
  |  |  ------------------
  |  |  |  |  285|      0|#define PSA_ERROR_SERVICE_FAILURE       ((psa_status_t)-144)
  |  |  ------------------
  |  |  204|      0|            }                                          \
  |  |  205|      0|            goto exit;                                 \
  |  |  206|      0|        }                                              \
  |  |  207|     21|    } while (0);
  |  |  ------------------
  |  |  |  Branch (207:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 8329|     21|#endif /* defined(MBEDTLS_THREADING_C) */
 8330|       |
 8331|     21|            if (!(global_data.initialized & PSA_CRYPTO_SUBSYSTEM_DRIVER_WRAPPERS_INITIALIZED)) {
  ------------------
  |  |  106|     21|#define PSA_CRYPTO_SUBSYSTEM_DRIVER_WRAPPERS_INITIALIZED    0x01
  ------------------
  |  Branch (8331:17): [True: 21, False: 0]
  ------------------
 8332|       |                /* Init drivers */
 8333|     21|                status = psa_driver_wrapper_init();
 8334|       |
 8335|       |                /* Drivers need shutdown regardless of startup errors. */
 8336|     21|                global_data.initialized |= PSA_CRYPTO_SUBSYSTEM_DRIVER_WRAPPERS_INITIALIZED;
  ------------------
  |  |  106|     21|#define PSA_CRYPTO_SUBSYSTEM_DRIVER_WRAPPERS_INITIALIZED    0x01
  ------------------
 8337|       |
 8338|       |
 8339|     21|            }
 8340|     21|#if defined(MBEDTLS_THREADING_C)
 8341|     21|            PSA_THREADING_CHK_GOTO_EXIT(mbedtls_mutex_unlock(
  ------------------
  |  |  199|     21|    do                                                 \
  |  |  200|     21|    {                                                  \
  |  |  201|     21|        if ((f) != 0) {                                \
  |  |  ------------------
  |  |  |  Branch (201:13): [True: 0, False: 21]
  |  |  ------------------
  |  |  202|      0|            if (status == PSA_SUCCESS) {               \
  |  |  ------------------
  |  |  |  |   57|      0|#define PSA_SUCCESS ((psa_status_t)0)
  |  |  ------------------
  |  |  |  Branch (202:17): [True: 0, False: 0]
  |  |  ------------------
  |  |  203|      0|                status = PSA_ERROR_SERVICE_FAILURE;    \
  |  |  ------------------
  |  |  |  |  285|      0|#define PSA_ERROR_SERVICE_FAILURE       ((psa_status_t)-144)
  |  |  ------------------
  |  |  204|      0|            }                                          \
  |  |  205|      0|            goto exit;                                 \
  |  |  206|      0|        }                                              \
  |  |  207|     21|    } while (0);
  |  |  ------------------
  |  |  |  Branch (207:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 8342|     21|                                            &mbedtls_threading_psa_globaldata_mutex));
 8343|     21|#endif /* defined(MBEDTLS_THREADING_C) */
 8344|       |
 8345|     21|            break;
 8346|       |
 8347|     21|        case PSA_CRYPTO_SUBSYSTEM_KEY_SLOTS:
  ------------------
  |  Branch (8347:9): [True: 21, False: 42]
  ------------------
 8348|       |
 8349|     21|#if defined(MBEDTLS_THREADING_C)
 8350|     21|            PSA_THREADING_CHK_GOTO_EXIT(mbedtls_mutex_lock(&mbedtls_threading_psa_globaldata_mutex));
  ------------------
  |  |  199|     21|    do                                                 \
  |  |  200|     21|    {                                                  \
  |  |  201|     21|        if ((f) != 0) {                                \
  |  |  ------------------
  |  |  |  Branch (201:13): [True: 0, False: 21]
  |  |  ------------------
  |  |  202|      0|            if (status == PSA_SUCCESS) {               \
  |  |  ------------------
  |  |  |  |   57|      0|#define PSA_SUCCESS ((psa_status_t)0)
  |  |  ------------------
  |  |  |  Branch (202:17): [True: 0, False: 0]
  |  |  ------------------
  |  |  203|      0|                status = PSA_ERROR_SERVICE_FAILURE;    \
  |  |  ------------------
  |  |  |  |  285|      0|#define PSA_ERROR_SERVICE_FAILURE       ((psa_status_t)-144)
  |  |  ------------------
  |  |  204|      0|            }                                          \
  |  |  205|      0|            goto exit;                                 \
  |  |  206|      0|        }                                              \
  |  |  207|     21|    } while (0);
  |  |  ------------------
  |  |  |  Branch (207:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 8351|     21|#endif /* defined(MBEDTLS_THREADING_C) */
 8352|       |
 8353|     21|            if (!(global_data.initialized & PSA_CRYPTO_SUBSYSTEM_KEY_SLOTS_INITIALIZED)) {
  ------------------
  |  |  107|     21|#define PSA_CRYPTO_SUBSYSTEM_KEY_SLOTS_INITIALIZED          0x02
  ------------------
  |  Branch (8353:17): [True: 21, False: 0]
  ------------------
 8354|     21|                status = psa_initialize_key_slots();
 8355|       |
 8356|       |                /* Need to wipe keys even if initialization fails. */
 8357|     21|                global_data.initialized |= PSA_CRYPTO_SUBSYSTEM_KEY_SLOTS_INITIALIZED;
  ------------------
  |  |  107|     21|#define PSA_CRYPTO_SUBSYSTEM_KEY_SLOTS_INITIALIZED          0x02
  ------------------
 8358|       |
 8359|     21|            }
 8360|     21|#if defined(MBEDTLS_THREADING_C)
 8361|     21|            PSA_THREADING_CHK_GOTO_EXIT(mbedtls_mutex_unlock(
  ------------------
  |  |  199|     21|    do                                                 \
  |  |  200|     21|    {                                                  \
  |  |  201|     21|        if ((f) != 0) {                                \
  |  |  ------------------
  |  |  |  Branch (201:13): [True: 0, False: 21]
  |  |  ------------------
  |  |  202|      0|            if (status == PSA_SUCCESS) {               \
  |  |  ------------------
  |  |  |  |   57|      0|#define PSA_SUCCESS ((psa_status_t)0)
  |  |  ------------------
  |  |  |  Branch (202:17): [True: 0, False: 0]
  |  |  ------------------
  |  |  203|      0|                status = PSA_ERROR_SERVICE_FAILURE;    \
  |  |  ------------------
  |  |  |  |  285|      0|#define PSA_ERROR_SERVICE_FAILURE       ((psa_status_t)-144)
  |  |  ------------------
  |  |  204|      0|            }                                          \
  |  |  205|      0|            goto exit;                                 \
  |  |  206|      0|        }                                              \
  |  |  207|     21|    } while (0);
  |  |  ------------------
  |  |  |  Branch (207:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 8362|     21|                                            &mbedtls_threading_psa_globaldata_mutex));
 8363|     21|#endif /* defined(MBEDTLS_THREADING_C) */
 8364|       |
 8365|     21|            break;
 8366|       |
 8367|     21|        case PSA_CRYPTO_SUBSYSTEM_RNG:
  ------------------
  |  Branch (8367:9): [True: 21, False: 42]
  ------------------
 8368|       |
 8369|     21|#if defined(MBEDTLS_THREADING_C)
 8370|     21|            PSA_THREADING_CHK_GOTO_EXIT(mbedtls_mutex_lock(&mbedtls_threading_psa_globaldata_mutex));
  ------------------
  |  |  199|     21|    do                                                 \
  |  |  200|     21|    {                                                  \
  |  |  201|     21|        if ((f) != 0) {                                \
  |  |  ------------------
  |  |  |  Branch (201:13): [True: 0, False: 21]
  |  |  ------------------
  |  |  202|      0|            if (status == PSA_SUCCESS) {               \
  |  |  ------------------
  |  |  |  |   57|      0|#define PSA_SUCCESS ((psa_status_t)0)
  |  |  ------------------
  |  |  |  Branch (202:17): [True: 0, False: 0]
  |  |  ------------------
  |  |  203|      0|                status = PSA_ERROR_SERVICE_FAILURE;    \
  |  |  ------------------
  |  |  |  |  285|      0|#define PSA_ERROR_SERVICE_FAILURE       ((psa_status_t)-144)
  |  |  ------------------
  |  |  204|      0|            }                                          \
  |  |  205|      0|            goto exit;                                 \
  |  |  206|      0|        }                                              \
  |  |  207|     21|    } while (0);
  |  |  ------------------
  |  |  |  Branch (207:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 8371|     21|#endif /* defined(MBEDTLS_THREADING_C) */
 8372|       |
 8373|     21|            driver_wrappers_initialized =
 8374|     21|                (global_data.initialized & PSA_CRYPTO_SUBSYSTEM_DRIVER_WRAPPERS_INITIALIZED);
  ------------------
  |  |  106|     21|#define PSA_CRYPTO_SUBSYSTEM_DRIVER_WRAPPERS_INITIALIZED    0x01
  ------------------
 8375|       |
 8376|     21|#if defined(MBEDTLS_THREADING_C)
 8377|     21|            PSA_THREADING_CHK_GOTO_EXIT(mbedtls_mutex_unlock(
  ------------------
  |  |  199|     21|    do                                                 \
  |  |  200|     21|    {                                                  \
  |  |  201|     21|        if ((f) != 0) {                                \
  |  |  ------------------
  |  |  |  Branch (201:13): [True: 0, False: 21]
  |  |  ------------------
  |  |  202|      0|            if (status == PSA_SUCCESS) {               \
  |  |  ------------------
  |  |  |  |   57|      0|#define PSA_SUCCESS ((psa_status_t)0)
  |  |  ------------------
  |  |  |  Branch (202:17): [True: 0, False: 0]
  |  |  ------------------
  |  |  203|      0|                status = PSA_ERROR_SERVICE_FAILURE;    \
  |  |  ------------------
  |  |  |  |  285|      0|#define PSA_ERROR_SERVICE_FAILURE       ((psa_status_t)-144)
  |  |  ------------------
  |  |  204|      0|            }                                          \
  |  |  205|      0|            goto exit;                                 \
  |  |  206|      0|        }                                              \
  |  |  207|     21|    } while (0);
  |  |  ------------------
  |  |  |  Branch (207:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 8378|     21|                                            &mbedtls_threading_psa_globaldata_mutex));
 8379|     21|#endif /* defined(MBEDTLS_THREADING_C) */
 8380|       |
 8381|       |            /* Need to use separate mutex here, as initialisation can require
 8382|       |             * testing of init flags, which requires locking the global data
 8383|       |             * mutex. */
 8384|     21|#if defined(MBEDTLS_THREADING_C)
 8385|     21|            PSA_THREADING_CHK_GOTO_EXIT(mbedtls_mutex_lock(&mbedtls_threading_psa_rngdata_mutex));
  ------------------
  |  |  199|     21|    do                                                 \
  |  |  200|     21|    {                                                  \
  |  |  201|     21|        if ((f) != 0) {                                \
  |  |  ------------------
  |  |  |  Branch (201:13): [True: 0, False: 21]
  |  |  ------------------
  |  |  202|      0|            if (status == PSA_SUCCESS) {               \
  |  |  ------------------
  |  |  |  |   57|      0|#define PSA_SUCCESS ((psa_status_t)0)
  |  |  ------------------
  |  |  |  Branch (202:17): [True: 0, False: 0]
  |  |  ------------------
  |  |  203|      0|                status = PSA_ERROR_SERVICE_FAILURE;    \
  |  |  ------------------
  |  |  |  |  285|      0|#define PSA_ERROR_SERVICE_FAILURE       ((psa_status_t)-144)
  |  |  ------------------
  |  |  204|      0|            }                                          \
  |  |  205|      0|            goto exit;                                 \
  |  |  206|      0|        }                                              \
  |  |  207|     21|    } while (0);
  |  |  ------------------
  |  |  |  Branch (207:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 8386|     21|#endif /* defined(MBEDTLS_THREADING_C) */
 8387|       |
 8388|       |            /* Initialize and seed the random generator. */
 8389|     21|            if (global_data.rng_state == RNG_NOT_INITIALIZED && driver_wrappers_initialized) {
  ------------------
  |  |   92|     42|#define RNG_NOT_INITIALIZED 0
  ------------------
  |  Branch (8389:17): [True: 21, False: 0]
  |  Branch (8389:65): [True: 21, False: 0]
  ------------------
 8390|     21|                mbedtls_psa_random_init(&global_data.rng);
 8391|     21|                global_data.rng_state = RNG_INITIALIZED;
  ------------------
  |  |   93|     21|#define RNG_INITIALIZED 1
  ------------------
 8392|       |
 8393|     21|                status = mbedtls_psa_random_seed(&global_data.rng);
 8394|     21|                if (status == PSA_SUCCESS) {
  ------------------
  |  |   57|     21|#define PSA_SUCCESS ((psa_status_t)0)
  ------------------
  |  Branch (8394:21): [True: 0, False: 21]
  ------------------
 8395|      0|                    global_data.rng_state = RNG_SEEDED;
  ------------------
  |  |   94|      0|#define RNG_SEEDED 2
  ------------------
 8396|      0|                }
 8397|     21|            }
 8398|       |
 8399|     21|#if defined(MBEDTLS_THREADING_C)
 8400|     21|            PSA_THREADING_CHK_GOTO_EXIT(mbedtls_mutex_unlock(
  ------------------
  |  |  199|     21|    do                                                 \
  |  |  200|     21|    {                                                  \
  |  |  201|     21|        if ((f) != 0) {                                \
  |  |  ------------------
  |  |  |  Branch (201:13): [True: 0, False: 21]
  |  |  ------------------
  |  |  202|      0|            if (status == PSA_SUCCESS) {               \
  |  |  ------------------
  |  |  |  |   57|      0|#define PSA_SUCCESS ((psa_status_t)0)
  |  |  ------------------
  |  |  |  Branch (202:17): [True: 0, False: 0]
  |  |  ------------------
  |  |  203|      0|                status = PSA_ERROR_SERVICE_FAILURE;    \
  |  |  ------------------
  |  |  |  |  285|      0|#define PSA_ERROR_SERVICE_FAILURE       ((psa_status_t)-144)
  |  |  ------------------
  |  |  204|      0|            }                                          \
  |  |  205|      0|            goto exit;                                 \
  |  |  206|      0|        }                                              \
  |  |  207|     21|    } while (0);
  |  |  ------------------
  |  |  |  Branch (207:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 8401|     21|                                            &mbedtls_threading_psa_rngdata_mutex));
 8402|     21|#endif /* defined(MBEDTLS_THREADING_C) */
 8403|       |
 8404|     21|            break;
 8405|       |
 8406|      0|        case PSA_CRYPTO_SUBSYSTEM_TRANSACTION:
  ------------------
  |  Branch (8406:9): [True: 0, False: 63]
  ------------------
 8407|       |
 8408|      0|#if defined(MBEDTLS_THREADING_C)
 8409|      0|            PSA_THREADING_CHK_GOTO_EXIT(mbedtls_mutex_lock(&mbedtls_threading_psa_globaldata_mutex));
  ------------------
  |  |  199|      0|    do                                                 \
  |  |  200|      0|    {                                                  \
  |  |  201|      0|        if ((f) != 0) {                                \
  |  |  ------------------
  |  |  |  Branch (201:13): [True: 0, False: 0]
  |  |  ------------------
  |  |  202|      0|            if (status == PSA_SUCCESS) {               \
  |  |  ------------------
  |  |  |  |   57|      0|#define PSA_SUCCESS ((psa_status_t)0)
  |  |  ------------------
  |  |  |  Branch (202:17): [True: 0, False: 0]
  |  |  ------------------
  |  |  203|      0|                status = PSA_ERROR_SERVICE_FAILURE;    \
  |  |  ------------------
  |  |  |  |  285|      0|#define PSA_ERROR_SERVICE_FAILURE       ((psa_status_t)-144)
  |  |  ------------------
  |  |  204|      0|            }                                          \
  |  |  205|      0|            goto exit;                                 \
  |  |  206|      0|        }                                              \
  |  |  207|      0|    } while (0);
  |  |  ------------------
  |  |  |  Branch (207:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 8410|      0|#endif /* defined(MBEDTLS_THREADING_C) */
 8411|       |
 8412|      0|            if (!(global_data.initialized & PSA_CRYPTO_SUBSYSTEM_TRANSACTION_INITIALIZED)) {
  ------------------
  |  |  108|      0|#define PSA_CRYPTO_SUBSYSTEM_TRANSACTION_INITIALIZED        0x04
  ------------------
  |  Branch (8412:17): [True: 0, False: 0]
  ------------------
 8413|      0|#if defined(PSA_CRYPTO_STORAGE_HAS_TRANSACTIONS)
 8414|      0|                status = psa_crypto_load_transaction();
 8415|      0|                if (status == PSA_SUCCESS) {
  ------------------
  |  |   57|      0|#define PSA_SUCCESS ((psa_status_t)0)
  ------------------
  |  Branch (8415:21): [True: 0, False: 0]
  ------------------
 8416|      0|                    status = psa_crypto_recover_transaction(&psa_crypto_transaction);
 8417|      0|                    if (status == PSA_SUCCESS) {
  ------------------
  |  |   57|      0|#define PSA_SUCCESS ((psa_status_t)0)
  ------------------
  |  Branch (8417:25): [True: 0, False: 0]
  ------------------
 8418|      0|                        global_data.initialized |= PSA_CRYPTO_SUBSYSTEM_TRANSACTION_INITIALIZED;
  ------------------
  |  |  108|      0|#define PSA_CRYPTO_SUBSYSTEM_TRANSACTION_INITIALIZED        0x04
  ------------------
 8419|      0|                    }
 8420|      0|                    status = psa_crypto_stop_transaction();
 8421|      0|                } else if (status == PSA_ERROR_DOES_NOT_EXIST) {
  ------------------
  |  |  110|      0|#define PSA_ERROR_DOES_NOT_EXIST        ((psa_status_t)-140)
  ------------------
  |  Branch (8421:28): [True: 0, False: 0]
  ------------------
 8422|       |                    /* There's no transaction to complete. It's all good. */
 8423|      0|                    global_data.initialized |= PSA_CRYPTO_SUBSYSTEM_TRANSACTION_INITIALIZED;
  ------------------
  |  |  108|      0|#define PSA_CRYPTO_SUBSYSTEM_TRANSACTION_INITIALIZED        0x04
  ------------------
 8424|      0|                    status = PSA_SUCCESS;
  ------------------
  |  |   57|      0|#define PSA_SUCCESS ((psa_status_t)0)
  ------------------
 8425|      0|                }
 8426|       |#else /* defined(PSA_CRYPTO_STORAGE_HAS_TRANSACTIONS) */
 8427|       |                global_data.initialized |= PSA_CRYPTO_SUBSYSTEM_TRANSACTION_INITIALIZED;
 8428|       |                status = PSA_SUCCESS;
 8429|       |#endif /* defined(PSA_CRYPTO_STORAGE_HAS_TRANSACTIONS) */
 8430|      0|            }
 8431|       |
 8432|      0|#if defined(MBEDTLS_THREADING_C)
 8433|      0|            PSA_THREADING_CHK_GOTO_EXIT(mbedtls_mutex_unlock(
  ------------------
  |  |  199|      0|    do                                                 \
  |  |  200|      0|    {                                                  \
  |  |  201|      0|        if ((f) != 0) {                                \
  |  |  ------------------
  |  |  |  Branch (201:13): [True: 0, False: 0]
  |  |  ------------------
  |  |  202|      0|            if (status == PSA_SUCCESS) {               \
  |  |  ------------------
  |  |  |  |   57|      0|#define PSA_SUCCESS ((psa_status_t)0)
  |  |  ------------------
  |  |  |  Branch (202:17): [True: 0, False: 0]
  |  |  ------------------
  |  |  203|      0|                status = PSA_ERROR_SERVICE_FAILURE;    \
  |  |  ------------------
  |  |  |  |  285|      0|#define PSA_ERROR_SERVICE_FAILURE       ((psa_status_t)-144)
  |  |  ------------------
  |  |  204|      0|            }                                          \
  |  |  205|      0|            goto exit;                                 \
  |  |  206|      0|        }                                              \
  |  |  207|      0|    } while (0);
  |  |  ------------------
  |  |  |  Branch (207:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 8434|      0|                                            &mbedtls_threading_psa_globaldata_mutex));
 8435|      0|#endif /* defined(MBEDTLS_THREADING_C) */
 8436|       |
 8437|      0|            break;
 8438|       |
 8439|      0|        default:
  ------------------
  |  Branch (8439:9): [True: 0, False: 63]
  ------------------
 8440|      0|            status = PSA_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  231|      0|#define PSA_ERROR_CORRUPTION_DETECTED    ((psa_status_t)-151)
  ------------------
 8441|     63|    }
 8442|       |
 8443|       |    /* Exit label only required when using threading macros. */
 8444|     63|#if defined(MBEDTLS_THREADING_C)
 8445|     63|exit:
 8446|     63|#endif /* defined(MBEDTLS_THREADING_C) */
 8447|       |
 8448|     63|    return status;
 8449|     63|}
psa_crypto.c:mbedtls_psa_random_init:
 7880|     21|{
 7881|       |#if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
 7882|       |    memset(rng, 0, sizeof(*rng));
 7883|       |#else /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
 7884|       |
 7885|       |    /* Set default configuration if
 7886|       |     * mbedtls_psa_crypto_configure_entropy_sources() hasn't been called. */
 7887|     21|    if (rng->entropy_init == NULL) {
  ------------------
  |  Branch (7887:9): [True: 21, False: 0]
  ------------------
 7888|     21|        rng->entropy_init = mbedtls_entropy_init;
 7889|     21|    }
 7890|     21|    if (rng->entropy_free == NULL) {
  ------------------
  |  Branch (7890:9): [True: 21, False: 0]
  ------------------
 7891|     21|        rng->entropy_free = mbedtls_entropy_free;
 7892|     21|    }
 7893|       |
 7894|     21|    rng->entropy_init(&rng->entropy);
 7895|       |#if defined(MBEDTLS_PSA_INJECT_ENTROPY) && \
 7896|       |    defined(MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES)
 7897|       |    /* The PSA entropy injection feature depends on using NV seed as an entropy
 7898|       |     * source. Add NV seed as an entropy source for PSA entropy injection. */
 7899|       |    mbedtls_entropy_add_source(&rng->entropy,
 7900|       |                               mbedtls_nv_seed_poll, NULL,
 7901|       |                               MBEDTLS_ENTROPY_BLOCK_SIZE,
 7902|       |                               MBEDTLS_ENTROPY_SOURCE_STRONG);
 7903|       |#endif
 7904|       |
 7905|     21|    mbedtls_psa_drbg_init(&rng->drbg);
 7906|     21|#endif /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
 7907|     21|}
psa_crypto.c:mbedtls_psa_random_seed:
 7927|     21|{
 7928|       |#if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
 7929|       |    /* Do nothing: the external RNG seeds itself. */
 7930|       |    (void) rng;
 7931|       |    return PSA_SUCCESS;
 7932|       |#else /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
 7933|     21|    const unsigned char drbg_seed[] = "PSA";
 7934|     21|    int ret = mbedtls_psa_drbg_seed(&rng->drbg, &rng->entropy,
 7935|     21|                                    drbg_seed, sizeof(drbg_seed) - 1);
 7936|     21|    return mbedtls_to_psa_error(ret);
 7937|     21|#endif /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
 7938|     21|}

psa_crypto.c:mbedtls_psa_drbg_free:
   93|     21|{
   94|     21|#if defined(MBEDTLS_CTR_DRBG_C)
   95|     21|    mbedtls_ctr_drbg_free(p_rng);
   96|       |#elif defined(MBEDTLS_HMAC_DRBG_C)
   97|       |    mbedtls_hmac_drbg_free(p_rng);
   98|       |#endif
   99|     21|}
psa_crypto.c:mbedtls_psa_drbg_init:
   80|     21|{
   81|     21|#if defined(MBEDTLS_CTR_DRBG_C)
   82|     21|    mbedtls_ctr_drbg_init(p_rng);
   83|       |#elif defined(MBEDTLS_HMAC_DRBG_C)
   84|       |    mbedtls_hmac_drbg_init(p_rng);
   85|       |#endif
   86|     21|}
psa_crypto.c:mbedtls_psa_drbg_seed:
  115|     21|{
  116|     21|#if defined(MBEDTLS_CTR_DRBG_C)
  117|     21|    return mbedtls_ctr_drbg_seed(drbg_ctx, mbedtls_entropy_func, entropy, custom, len);
  118|       |#elif defined(MBEDTLS_HMAC_DRBG_C)
  119|       |    const mbedtls_md_info_t *md_info = mbedtls_md_info_from_type(MBEDTLS_PSA_HMAC_DRBG_MD_TYPE);
  120|       |    return mbedtls_hmac_drbg_seed(drbg_ctx, md_info, mbedtls_entropy_func, entropy, custom, len);
  121|       |#endif
  122|     21|}

psa_init_all_se_drivers:
  260|     21|{
  261|     21|    size_t i;
  262|    105|    for (i = 0; i < PSA_MAX_SE_DRIVERS; i++) {
  ------------------
  |  |   48|    105|#define PSA_MAX_SE_DRIVERS 4
  ------------------
  |  Branch (262:17): [True: 84, False: 21]
  ------------------
  263|     84|        psa_se_drv_table_entry_t *driver = &driver_table[i];
  264|     84|        if (driver->location == 0) {
  ------------------
  |  Branch (264:13): [True: 84, False: 0]
  ------------------
  265|     84|            continue; /* skipping unused entry */
  266|     84|        }
  267|      0|        const psa_drv_se_t *methods = psa_get_se_driver_methods(driver);
  268|      0|        if (methods->p_init != NULL) {
  ------------------
  |  Branch (268:13): [True: 0, False: 0]
  ------------------
  269|      0|            psa_status_t status = methods->p_init(
  270|      0|                &driver->u.context,
  271|      0|                driver->u.internal.persistent_data,
  272|      0|                driver->location);
  273|      0|            if (status != PSA_SUCCESS) {
  ------------------
  |  |   57|      0|#define PSA_SUCCESS ((psa_status_t)0)
  ------------------
  |  Branch (273:17): [True: 0, False: 0]
  ------------------
  274|      0|                return status;
  275|      0|            }
  276|      0|            status = psa_save_se_persistent_data(driver);
  277|      0|            if (status != PSA_SUCCESS) {
  ------------------
  |  |   57|      0|#define PSA_SUCCESS ((psa_status_t)0)
  ------------------
  |  Branch (277:17): [True: 0, False: 0]
  ------------------
  278|      0|                return status;
  279|      0|            }
  280|      0|        }
  281|      0|    }
  282|     21|    return PSA_SUCCESS;
  ------------------
  |  |   57|     21|#define PSA_SUCCESS ((psa_status_t)0)
  ------------------
  283|     21|}
psa_unregister_all_se_drivers:
  357|     21|{
  358|     21|    size_t i;
  359|    105|    for (i = 0; i < PSA_MAX_SE_DRIVERS; i++) {
  ------------------
  |  |   48|    105|#define PSA_MAX_SE_DRIVERS 4
  ------------------
  |  Branch (359:17): [True: 84, False: 21]
  ------------------
  360|     84|        if (driver_table[i].u.internal.persistent_data != NULL) {
  ------------------
  |  Branch (360:13): [True: 0, False: 84]
  ------------------
  361|      0|            mbedtls_free(driver_table[i].u.internal.persistent_data);
  362|      0|        }
  363|     84|    }
  364|     21|    memset(driver_table, 0, sizeof(driver_table));
  365|     21|}

psa_initialize_key_slots:
  431|     21|{
  432|     21|#if defined(MBEDTLS_PSA_KEY_STORE_DYNAMIC)
  433|     21|    global_data.key_slices[KEY_SLOT_CACHE_SLICE_INDEX] =
  ------------------
  |  |   97|     21|#define KEY_SLOT_CACHE_SLICE_INDEX KEY_SLOT_VOLATILE_SLICE_COUNT
  |  |  ------------------
  |  |  |  |   95|     21|#define KEY_SLOT_VOLATILE_SLICE_COUNT 22u
  |  |  ------------------
  ------------------
  434|     21|        mbedtls_calloc(PERSISTENT_KEY_CACHE_COUNT,
  ------------------
  |  |   81|     21|#define PERSISTENT_KEY_CACHE_COUNT MBEDTLS_PSA_KEY_SLOT_COUNT
  |  |  ------------------
  |  |  |  |   32|     21|#define MBEDTLS_PSA_KEY_SLOT_COUNT 32
  |  |  ------------------
  ------------------
  435|     21|                       sizeof(*global_data.key_slices[KEY_SLOT_CACHE_SLICE_INDEX]));
  ------------------
  |  |   97|     21|#define KEY_SLOT_CACHE_SLICE_INDEX KEY_SLOT_VOLATILE_SLICE_COUNT
  |  |  ------------------
  |  |  |  |   95|     21|#define KEY_SLOT_VOLATILE_SLICE_COUNT 22u
  |  |  ------------------
  ------------------
  436|     21|    if (global_data.key_slices[KEY_SLOT_CACHE_SLICE_INDEX] == NULL) {
  ------------------
  |  |   97|     21|#define KEY_SLOT_CACHE_SLICE_INDEX KEY_SLOT_VOLATILE_SLICE_COUNT
  |  |  ------------------
  |  |  |  |   95|     21|#define KEY_SLOT_VOLATILE_SLICE_COUNT 22u
  |  |  ------------------
  ------------------
  |  Branch (436:9): [True: 0, False: 21]
  ------------------
  437|      0|        return PSA_ERROR_INSUFFICIENT_MEMORY;
  ------------------
  |  |  143|      0|#define PSA_ERROR_INSUFFICIENT_MEMORY   ((psa_status_t)-141)
  ------------------
  438|      0|    }
  439|       |#else /* MBEDTLS_PSA_KEY_STORE_DYNAMIC */
  440|       |    /* Nothing to do: program startup and psa_wipe_all_key_slots() both
  441|       |     * guarantee that the key slots are initialized to all-zero, which
  442|       |     * means that all the key slots are in a valid, empty state. The global
  443|       |     * data mutex is already held when calling this function, so no need to
  444|       |     * lock it here, to set the flag. */
  445|       |#endif /* MBEDTLS_PSA_KEY_STORE_DYNAMIC */
  446|       |
  447|     21|    global_data.key_slots_initialized = 1;
  448|     21|    return PSA_SUCCESS;
  ------------------
  |  |   57|     21|#define PSA_SUCCESS ((psa_status_t)0)
  ------------------
  449|     21|}
psa_wipe_all_key_slots:
  452|     21|{
  453|    504|    for (size_t slice_idx = 0; slice_idx < KEY_SLICE_COUNT; slice_idx++) {
  ------------------
  |  |   96|    504|#define KEY_SLICE_COUNT (KEY_SLOT_VOLATILE_SLICE_COUNT + 1u)
  |  |  ------------------
  |  |  |  |   95|    504|#define KEY_SLOT_VOLATILE_SLICE_COUNT 22u
  |  |  ------------------
  ------------------
  |  Branch (453:32): [True: 483, False: 21]
  ------------------
  454|    483|#if defined(MBEDTLS_PSA_KEY_STORE_DYNAMIC)
  455|    483|        if (global_data.key_slices[slice_idx] == NULL) {
  ------------------
  |  Branch (455:13): [True: 462, False: 21]
  ------------------
  456|    462|            continue;
  457|    462|        }
  458|     21|#endif  /* MBEDTLS_PSA_KEY_STORE_DYNAMIC */
  459|    693|        for (size_t slot_idx = 0; slot_idx < key_slice_length(slice_idx); slot_idx++) {
  ------------------
  |  Branch (459:35): [True: 672, False: 21]
  ------------------
  460|    672|            psa_key_slot_t *slot = get_key_slot(slice_idx, slot_idx);
  461|    672|#if defined(MBEDTLS_PSA_KEY_STORE_DYNAMIC)
  462|       |            /* When MBEDTLS_PSA_KEY_STORE_DYNAMIC is disabled, calling
  463|       |             * psa_wipe_key_slot() on an unused slot is useless, but it
  464|       |             * happens to work (because we flip the state to PENDING_DELETION).
  465|       |             *
  466|       |             * When MBEDTLS_PSA_KEY_STORE_DYNAMIC is enabled,
  467|       |             * psa_wipe_key_slot() needs to have a valid slice_index
  468|       |             * field, but that value might not be correct in a
  469|       |             * free slot, so we must not call it.
  470|       |             *
  471|       |             * Bypass the call to psa_wipe_key_slot() if the slot is empty,
  472|       |             * but only if MBEDTLS_PSA_KEY_STORE_DYNAMIC is enabled, to save
  473|       |             * a few bytes of code size otherwise.
  474|       |             */
  475|    672|            if (slot->state == PSA_SLOT_EMPTY) {
  ------------------
  |  Branch (475:17): [True: 672, False: 0]
  ------------------
  476|    672|                continue;
  477|    672|            }
  478|      0|#endif
  479|      0|            slot->var.occupied.registered_readers = 1;
  480|      0|            slot->state = PSA_SLOT_PENDING_DELETION;
  481|      0|            (void) psa_wipe_key_slot(slot);
  482|      0|        }
  483|     21|#if defined(MBEDTLS_PSA_KEY_STORE_DYNAMIC)
  484|     21|        mbedtls_free(global_data.key_slices[slice_idx]);
  485|     21|        global_data.key_slices[slice_idx] = NULL;
  486|     21|#endif  /* MBEDTLS_PSA_KEY_STORE_DYNAMIC */
  487|     21|    }
  488|       |
  489|     21|#if defined(MBEDTLS_PSA_KEY_STORE_DYNAMIC)
  490|    483|    for (size_t slice_idx = 0; slice_idx < KEY_SLOT_VOLATILE_SLICE_COUNT; slice_idx++) {
  ------------------
  |  |   95|    483|#define KEY_SLOT_VOLATILE_SLICE_COUNT 22u
  ------------------
  |  Branch (490:32): [True: 462, False: 21]
  ------------------
  491|    462|        global_data.first_free_slot_index[slice_idx] = 0;
  492|    462|    }
  493|     21|#endif  /* MBEDTLS_PSA_KEY_STORE_DYNAMIC */
  494|       |
  495|       |    /* The global data mutex is already held when calling this function. */
  496|     21|    global_data.key_slots_initialized = 0;
  497|     21|}
psa_crypto_slot_management.c:key_slice_length:
  260|    693|{
  261|    693|    if (slice_idx == KEY_SLOT_CACHE_SLICE_INDEX) {
  ------------------
  |  |   97|    693|#define KEY_SLOT_CACHE_SLICE_INDEX KEY_SLOT_VOLATILE_SLICE_COUNT
  |  |  ------------------
  |  |  |  |   95|    693|#define KEY_SLOT_VOLATILE_SLICE_COUNT 22u
  |  |  ------------------
  ------------------
  |  Branch (261:9): [True: 693, False: 0]
  ------------------
  262|    693|        return PERSISTENT_KEY_CACHE_COUNT;
  ------------------
  |  |   81|    693|#define PERSISTENT_KEY_CACHE_COUNT MBEDTLS_PSA_KEY_SLOT_COUNT
  |  |  ------------------
  |  |  |  |   32|    693|#define MBEDTLS_PSA_KEY_SLOT_COUNT 32
  |  |  ------------------
  ------------------
  263|    693|    } else {
  264|      0|#if defined(MBEDTLS_TEST_HOOKS)
  265|      0|        if (mbedtls_test_hook_psa_volatile_key_slice_length != NULL) {
  ------------------
  |  Branch (265:13): [True: 0, False: 0]
  ------------------
  266|      0|            return mbedtls_test_hook_psa_volatile_key_slice_length(slice_idx);
  267|      0|        }
  268|      0|#endif
  269|      0|        return KEY_SLOT_VOLATILE_SLICE_BASE_LENGTH << slice_idx;
  ------------------
  |  |   94|      0|#define KEY_SLOT_VOLATILE_SLICE_BASE_LENGTH 16u
  ------------------
  270|      0|    }
  271|    693|}
psa_crypto_slot_management.c:get_key_slot:
  296|    672|{
  297|    672|    return &global_data.key_slices[slice_idx][slot_idx];
  298|    672|}

mbedtls_rsa_parse_pubkey:
  228|      2|{
  229|      2|    unsigned char *p = (unsigned char *) key;
  230|      2|    unsigned char *end = (unsigned char *) (key + keylen);
  231|      2|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|      2|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  232|      2|    size_t len;
  233|       |
  234|       |    /*
  235|       |     *  RSAPublicKey ::= SEQUENCE {
  236|       |     *      modulus           INTEGER,  -- n
  237|       |     *      publicExponent    INTEGER   -- e
  238|       |     *  }
  239|       |     */
  240|       |
  241|      2|    if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
  ------------------
  |  Branch (241:9): [True: 0, False: 2]
  ------------------
  242|      2|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|      2|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|      2|#define MBEDTLS_ASN1_SEQUENCE                0x10
  ------------------
  243|      0|        return ret;
  244|      0|    }
  245|       |
  246|      2|    if (end != p + len) {
  ------------------
  |  Branch (246:9): [True: 0, False: 2]
  ------------------
  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|      2|    if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_INTEGER)) != 0) {
  ------------------
  |  |   65|      2|#define MBEDTLS_ASN1_INTEGER                 0x02
  ------------------
  |  Branch (251:9): [True: 0, False: 2]
  ------------------
  252|      0|        return ret;
  253|      0|    }
  254|       |
  255|      2|    if ((ret = mbedtls_rsa_import_raw(rsa, p, len, NULL, 0, NULL, 0,
  ------------------
  |  Branch (255:9): [True: 0, False: 2]
  ------------------
  256|      2|                                      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|      2|    p += len;
  261|       |
  262|       |    /* Import E */
  263|      2|    if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_INTEGER)) != 0) {
  ------------------
  |  |   65|      2|#define MBEDTLS_ASN1_INTEGER                 0x02
  ------------------
  |  Branch (263:9): [True: 0, False: 2]
  ------------------
  264|      0|        return ret;
  265|      0|    }
  266|       |
  267|      2|    if ((ret = mbedtls_rsa_import_raw(rsa, NULL, 0, NULL, 0, NULL, 0,
  ------------------
  |  Branch (267:9): [True: 0, False: 2]
  ------------------
  268|      2|                                      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|      2|    p += len;
  273|       |
  274|      2|    if (mbedtls_rsa_complete(rsa) != 0 ||
  ------------------
  |  Branch (274:9): [True: 0, False: 2]
  ------------------
  275|      2|        mbedtls_rsa_check_pubkey(rsa) != 0) {
  ------------------
  |  Branch (275:9): [True: 0, False: 2]
  ------------------
  276|      0|        return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
  ------------------
  |  |   33|      0|#define MBEDTLS_ERR_RSA_BAD_INPUT_DATA                    -0x4080
  ------------------
  277|      0|    }
  278|       |
  279|      2|    if (p != end) {
  ------------------
  |  Branch (279:9): [True: 0, False: 2]
  ------------------
  280|      0|        return MBEDTLS_ERR_ASN1_LENGTH_MISMATCH;
  ------------------
  |  |   43|      0|#define MBEDTLS_ERR_ASN1_LENGTH_MISMATCH                  -0x0066
  ------------------
  281|      0|    }
  282|       |
  283|      2|    return 0;
  284|      2|}
mbedtls_rsa_import_raw:
  600|      4|{
  601|      4|    int ret = 0;
  602|       |
  603|      4|    if (N != NULL) {
  ------------------
  |  Branch (603:9): [True: 2, False: 2]
  ------------------
  604|      2|        MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&ctx->N, N, N_len));
  ------------------
  |  |   41|      2|    do                           \
  |  |   42|      2|    {                            \
  |  |   43|      2|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2]
  |  |  ------------------
  |  |   44|      2|        goto cleanup;        \
  |  |   45|      2|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  605|      2|        ctx->len = mbedtls_mpi_size(&ctx->N);
  606|      2|    }
  607|       |
  608|      4|    if (P != NULL) {
  ------------------
  |  Branch (608:9): [True: 0, False: 4]
  ------------------
  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|      4|    if (Q != NULL) {
  ------------------
  |  Branch (612:9): [True: 0, False: 4]
  ------------------
  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|      4|    if (D != NULL) {
  ------------------
  |  Branch (616:9): [True: 0, False: 4]
  ------------------
  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|      4|    if (E != NULL) {
  ------------------
  |  Branch (620:9): [True: 2, False: 2]
  ------------------
  621|      2|        MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&ctx->E, E, E_len));
  ------------------
  |  |   41|      2|    do                           \
  |  |   42|      2|    {                            \
  |  |   43|      2|        if ((ret = (f)) != 0) \
  |  |  ------------------
  |  |  |  Branch (43:13): [True: 0, False: 2]
  |  |  ------------------
  |  |   44|      2|        goto cleanup;        \
  |  |   45|      2|    } while (0)
  |  |  ------------------
  |  |  |  Branch (45:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  622|      2|    }
  623|       |
  624|      4|cleanup:
  625|       |
  626|      4|    if (ret != 0) {
  ------------------
  |  Branch (626:9): [True: 0, False: 4]
  ------------------
  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|      4|    return 0;
  631|      4|}
mbedtls_rsa_complete:
  723|      2|{
  724|      2|    int ret = 0;
  725|      2|    int have_N, have_P, have_Q, have_D, have_E;
  726|       |#if !defined(MBEDTLS_RSA_NO_CRT)
  727|       |    int have_DP, have_DQ, have_QP;
  728|       |#endif
  729|      2|    int n_missing, pq_missing, d_missing, is_pub, is_priv;
  730|       |
  731|      2|    have_N = (mbedtls_mpi_cmp_int(&ctx->N, 0) != 0);
  732|      2|    have_P = (mbedtls_mpi_cmp_int(&ctx->P, 0) != 0);
  733|      2|    have_Q = (mbedtls_mpi_cmp_int(&ctx->Q, 0) != 0);
  734|      2|    have_D = (mbedtls_mpi_cmp_int(&ctx->D, 0) != 0);
  735|      2|    have_E = (mbedtls_mpi_cmp_int(&ctx->E, 0) != 0);
  736|       |
  737|       |#if !defined(MBEDTLS_RSA_NO_CRT)
  738|       |    have_DP = (mbedtls_mpi_cmp_int(&ctx->DP, 0) != 0);
  739|       |    have_DQ = (mbedtls_mpi_cmp_int(&ctx->DQ, 0) != 0);
  740|       |    have_QP = (mbedtls_mpi_cmp_int(&ctx->QP, 0) != 0);
  741|       |#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|      2|    n_missing  =              have_P &&  have_Q &&  have_D && have_E;
  ------------------
  |  Branch (753:31): [True: 0, False: 2]
  |  Branch (753:42): [True: 0, False: 0]
  |  Branch (753:53): [True: 0, False: 0]
  |  Branch (753:63): [True: 0, False: 0]
  ------------------
  754|      2|    pq_missing =   have_N && !have_P && !have_Q &&  have_D && have_E;
  ------------------
  |  Branch (754:20): [True: 2, False: 0]
  |  Branch (754:30): [True: 2, False: 0]
  |  Branch (754:41): [True: 2, False: 0]
  |  Branch (754:53): [True: 0, False: 2]
  |  Branch (754:63): [True: 0, False: 0]
  ------------------
  755|      2|    d_missing  =              have_P &&  have_Q && !have_D && have_E;
  ------------------
  |  Branch (755:31): [True: 0, False: 2]
  |  Branch (755:42): [True: 0, False: 0]
  |  Branch (755:52): [True: 0, False: 0]
  |  Branch (755:63): [True: 0, False: 0]
  ------------------
  756|      2|    is_pub     =   have_N && !have_P && !have_Q && !have_D && have_E;
  ------------------
  |  Branch (756:20): [True: 2, False: 0]
  |  Branch (756:30): [True: 2, False: 0]
  |  Branch (756:41): [True: 2, False: 0]
  |  Branch (756:52): [True: 2, False: 0]
  |  Branch (756:63): [True: 2, False: 0]
  ------------------
  757|       |
  758|       |    /* These three alternatives are mutually exclusive */
  759|      2|    is_priv = n_missing || pq_missing || d_missing;
  ------------------
  |  Branch (759:15): [True: 0, False: 2]
  |  Branch (759:28): [True: 0, False: 2]
  |  Branch (759:42): [True: 0, False: 2]
  ------------------
  760|       |
  761|      2|    if (!is_priv && !is_pub) {
  ------------------
  |  Branch (761:9): [True: 2, False: 0]
  |  Branch (761:21): [True: 0, False: 2]
  ------------------
  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|      2|    if (!have_N && have_P && have_Q) {
  ------------------
  |  Branch (769:9): [True: 0, False: 2]
  |  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|      2|    if (pq_missing) {
  ------------------
  |  Branch (782:9): [True: 0, False: 2]
  ------------------
  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|      2|    } else if (d_missing) {
  ------------------
  |  Branch (789:16): [True: 0, False: 2]
  ------------------
  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|       |#if !defined(MBEDTLS_RSA_NO_CRT)
  804|       |    if (is_priv && !(have_DP && have_DQ && have_QP)) {
  805|       |        ret = mbedtls_rsa_deduce_crt(&ctx->P,  &ctx->Q,  &ctx->D,
  806|       |                                     &ctx->DP, &ctx->DQ, &ctx->QP);
  807|       |        if (ret != 0) {
  808|       |            return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret);
  809|       |        }
  810|       |    }
  811|       |#endif /* MBEDTLS_RSA_NO_CRT */
  812|       |
  813|       |    /*
  814|       |     * Step 3: Basic sanity checks
  815|       |     */
  816|       |
  817|      2|    return rsa_check_context(ctx, is_priv, 1);
  818|      2|}
mbedtls_rsa_init:
  954|      2|{
  955|      2|    memset(ctx, 0, sizeof(mbedtls_rsa_context));
  956|       |
  957|      2|    ctx->padding = MBEDTLS_RSA_PKCS_V15;
  ------------------
  |  |   55|      2|#define MBEDTLS_RSA_PKCS_V15    0 /**< Use PKCS#1 v1.5 encoding. */
  ------------------
  958|      2|    ctx->hash_id = MBEDTLS_MD_NONE;
  959|       |
  960|      2|#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|      2|    ctx->ver = 1;
  964|      2|    mbedtls_mutex_init(&ctx->mutex);
  965|      2|#endif
  966|      2|}
mbedtls_rsa_check_pubkey:
 1170|      2|{
 1171|      2|    if (rsa_check_context(ctx, 0 /* public */, 0 /* no blinding */) != 0) {
  ------------------
  |  Branch (1171:9): [True: 0, False: 2]
  ------------------
 1172|      0|        return MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
  ------------------
  |  |   39|      0|#define MBEDTLS_ERR_RSA_KEY_CHECK_FAILED                  -0x4200
  ------------------
 1173|      0|    }
 1174|       |
 1175|      2|    if (mbedtls_mpi_bitlen(&ctx->N) < 128) {
  ------------------
  |  Branch (1175:9): [True: 0, False: 2]
  ------------------
 1176|      0|        return MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
  ------------------
  |  |   39|      0|#define MBEDTLS_ERR_RSA_KEY_CHECK_FAILED                  -0x4200
  ------------------
 1177|      0|    }
 1178|       |
 1179|      2|    if (mbedtls_mpi_get_bit(&ctx->E, 0) == 0 ||
  ------------------
  |  Branch (1179:9): [True: 0, False: 2]
  ------------------
 1180|      2|        mbedtls_mpi_bitlen(&ctx->E)     < 2  ||
  ------------------
  |  Branch (1180:9): [True: 0, False: 2]
  ------------------
 1181|      2|        mbedtls_mpi_cmp_mpi(&ctx->E, &ctx->N) >= 0) {
  ------------------
  |  Branch (1181:9): [True: 0, False: 2]
  ------------------
 1182|      0|        return MBEDTLS_ERR_RSA_KEY_CHECK_FAILED;
  ------------------
  |  |   39|      0|#define MBEDTLS_ERR_RSA_KEY_CHECK_FAILED                  -0x4200
  ------------------
 1183|      0|    }
 1184|       |
 1185|      2|    return 0;
 1186|      2|}
rsa.c:rsa_check_context:
  640|      4|{
  641|       |#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|       |    ((void) blinding_needed);
  645|       |#endif
  646|       |
  647|      4|    if (ctx->len != mbedtls_mpi_size(&ctx->N) ||
  ------------------
  |  Branch (647:9): [True: 0, False: 4]
  ------------------
  648|      4|        ctx->len > MBEDTLS_MPI_MAX_SIZE) {
  ------------------
  |  |   73|      4|#define MBEDTLS_MPI_MAX_SIZE                              1024     /**< Maximum number of bytes for usable MPIs. */
  ------------------
  |  Branch (648:9): [True: 0, False: 4]
  ------------------
  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|      4|    if (mbedtls_mpi_cmp_int(&ctx->N, 0) <= 0 ||
  ------------------
  |  Branch (658:9): [True: 0, False: 4]
  ------------------
  659|      4|        mbedtls_mpi_get_bit(&ctx->N, 0) == 0) {
  ------------------
  |  Branch (659:9): [True: 0, False: 4]
  ------------------
  660|      0|        return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
  ------------------
  |  |   33|      0|#define MBEDTLS_ERR_RSA_BAD_INPUT_DATA                    -0x4080
  ------------------
  661|      0|    }
  662|       |
  663|       |#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|       |    if (is_priv &&
  668|       |        (mbedtls_mpi_cmp_int(&ctx->P, 0) <= 0 ||
  669|       |         mbedtls_mpi_get_bit(&ctx->P, 0) == 0 ||
  670|       |         mbedtls_mpi_cmp_int(&ctx->Q, 0) <= 0 ||
  671|       |         mbedtls_mpi_get_bit(&ctx->Q, 0) == 0)) {
  672|       |        return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
  673|       |    }
  674|       |#endif /* !MBEDTLS_RSA_NO_CRT */
  675|       |
  676|       |    /*
  677|       |     * 2. Exponents must be positive
  678|       |     */
  679|       |
  680|       |    /* Always need E for public key operations */
  681|      4|    if (mbedtls_mpi_cmp_int(&ctx->E, 0) <= 0) {
  ------------------
  |  Branch (681:9): [True: 0, False: 4]
  ------------------
  682|      0|        return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
  ------------------
  |  |   33|      0|#define MBEDTLS_ERR_RSA_BAD_INPUT_DATA                    -0x4080
  ------------------
  683|      0|    }
  684|       |
  685|      4|#if defined(MBEDTLS_RSA_NO_CRT)
  686|       |    /* For private key operations, use D or DP & DQ
  687|       |     * as (unblinded) exponents. */
  688|      4|    if (is_priv && mbedtls_mpi_cmp_int(&ctx->D, 0) <= 0) {
  ------------------
  |  Branch (688:9): [True: 0, False: 4]
  |  Branch (688:20): [True: 0, False: 0]
  ------------------
  689|      0|        return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
  ------------------
  |  |   33|      0|#define MBEDTLS_ERR_RSA_BAD_INPUT_DATA                    -0x4080
  ------------------
  690|      0|    }
  691|       |#else
  692|       |    if (is_priv &&
  693|       |        (mbedtls_mpi_cmp_int(&ctx->DP, 0) <= 0 ||
  694|       |         mbedtls_mpi_cmp_int(&ctx->DQ, 0) <= 0)) {
  695|       |        return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
  696|       |    }
  697|       |#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|      4|#if defined(MBEDTLS_RSA_NO_CRT)
  703|      4|    if (is_priv && blinding_needed &&
  ------------------
  |  Branch (703:9): [True: 0, False: 4]
  |  Branch (703:20): [True: 0, False: 0]
  ------------------
  704|      4|        (mbedtls_mpi_cmp_int(&ctx->P, 0) <= 0 ||
  ------------------
  |  Branch (704:10): [True: 0, False: 0]
  ------------------
  705|      0|         mbedtls_mpi_cmp_int(&ctx->Q, 0) <= 0)) {
  ------------------
  |  Branch (705:10): [True: 0, False: 0]
  ------------------
  706|      0|        return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
  ------------------
  |  |   33|      0|#define MBEDTLS_ERR_RSA_BAD_INPUT_DATA                    -0x4080
  ------------------
  707|      0|    }
  708|      4|#endif
  709|       |
  710|       |    /* It wouldn't lead to an error if it wasn't satisfied,
  711|       |     * but check for QP >= 1 nonetheless. */
  712|       |#if !defined(MBEDTLS_RSA_NO_CRT)
  713|       |    if (is_priv &&
  714|       |        mbedtls_mpi_cmp_int(&ctx->QP, 0) <= 0) {
  715|       |        return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
  716|       |    }
  717|       |#endif
  718|       |
  719|      4|    return 0;
  720|      4|}

mbedtls_sha512_init:
  222|     42|{
  223|     42|    memset(ctx, 0, sizeof(mbedtls_sha512_context));
  224|     42|}
mbedtls_sha512_free:
  227|     63|{
  228|     63|    if (ctx == NULL) {
  ------------------
  |  Branch (228:9): [True: 0, False: 63]
  ------------------
  229|      0|        return;
  230|      0|    }
  231|       |
  232|     63|    mbedtls_platform_zeroize(ctx, sizeof(mbedtls_sha512_context));
  233|     63|}
mbedtls_sha512_starts:
  245|     42|{
  246|     42|#if defined(MBEDTLS_SHA384_C) && defined(MBEDTLS_SHA512_C)
  247|     42|    if (is384 != 0 && is384 != 1) {
  ------------------
  |  Branch (247:9): [True: 0, False: 42]
  |  Branch (247:23): [True: 0, False: 0]
  ------------------
  248|      0|        return MBEDTLS_ERR_SHA512_BAD_INPUT_DATA;
  ------------------
  |  |   22|      0|#define MBEDTLS_ERR_SHA512_BAD_INPUT_DATA                 -0x0075
  ------------------
  249|      0|    }
  250|       |#elif defined(MBEDTLS_SHA512_C)
  251|       |    if (is384 != 0) {
  252|       |        return MBEDTLS_ERR_SHA512_BAD_INPUT_DATA;
  253|       |    }
  254|       |#else /* defined MBEDTLS_SHA384_C only */
  255|       |    if (is384 == 0) {
  256|       |        return MBEDTLS_ERR_SHA512_BAD_INPUT_DATA;
  257|       |    }
  258|       |#endif
  259|       |
  260|     42|    ctx->total[0] = 0;
  261|     42|    ctx->total[1] = 0;
  262|       |
  263|     42|    if (is384 == 0) {
  ------------------
  |  Branch (263:9): [True: 42, False: 0]
  ------------------
  264|     42|#if defined(MBEDTLS_SHA512_C)
  265|     42|        ctx->state[0] = UL64(0x6A09E667F3BCC908);
  ------------------
  |  |   40|     42|  #define UL64(x) x##ULL
  ------------------
  266|     42|        ctx->state[1] = UL64(0xBB67AE8584CAA73B);
  ------------------
  |  |   40|     42|  #define UL64(x) x##ULL
  ------------------
  267|     42|        ctx->state[2] = UL64(0x3C6EF372FE94F82B);
  ------------------
  |  |   40|     42|  #define UL64(x) x##ULL
  ------------------
  268|     42|        ctx->state[3] = UL64(0xA54FF53A5F1D36F1);
  ------------------
  |  |   40|     42|  #define UL64(x) x##ULL
  ------------------
  269|     42|        ctx->state[4] = UL64(0x510E527FADE682D1);
  ------------------
  |  |   40|     42|  #define UL64(x) x##ULL
  ------------------
  270|     42|        ctx->state[5] = UL64(0x9B05688C2B3E6C1F);
  ------------------
  |  |   40|     42|  #define UL64(x) x##ULL
  ------------------
  271|     42|        ctx->state[6] = UL64(0x1F83D9ABFB41BD6B);
  ------------------
  |  |   40|     42|  #define UL64(x) x##ULL
  ------------------
  272|     42|        ctx->state[7] = UL64(0x5BE0CD19137E2179);
  ------------------
  |  |   40|     42|  #define UL64(x) x##ULL
  ------------------
  273|     42|#endif /* MBEDTLS_SHA512_C */
  274|     42|    } else {
  275|      0|#if defined(MBEDTLS_SHA384_C)
  276|      0|        ctx->state[0] = UL64(0xCBBB9D5DC1059ED8);
  ------------------
  |  |   40|      0|  #define UL64(x) x##ULL
  ------------------
  277|      0|        ctx->state[1] = UL64(0x629A292A367CD507);
  ------------------
  |  |   40|      0|  #define UL64(x) x##ULL
  ------------------
  278|      0|        ctx->state[2] = UL64(0x9159015A3070DD17);
  ------------------
  |  |   40|      0|  #define UL64(x) x##ULL
  ------------------
  279|      0|        ctx->state[3] = UL64(0x152FECD8F70E5939);
  ------------------
  |  |   40|      0|  #define UL64(x) x##ULL
  ------------------
  280|      0|        ctx->state[4] = UL64(0x67332667FFC00B31);
  ------------------
  |  |   40|      0|  #define UL64(x) x##ULL
  ------------------
  281|      0|        ctx->state[5] = UL64(0x8EB44A8768581511);
  ------------------
  |  |   40|      0|  #define UL64(x) x##ULL
  ------------------
  282|      0|        ctx->state[6] = UL64(0xDB0C2E0D64F98FA7);
  ------------------
  |  |   40|      0|  #define UL64(x) x##ULL
  ------------------
  283|      0|        ctx->state[7] = UL64(0x47B5481DBEFA4FA4);
  ------------------
  |  |   40|      0|  #define UL64(x) x##ULL
  ------------------
  284|      0|#endif /* MBEDTLS_SHA384_C */
  285|      0|    }
  286|       |
  287|     42|#if defined(MBEDTLS_SHA384_C)
  288|     42|    ctx->is384 = is384;
  289|     42|#endif
  290|       |
  291|     42|    return 0;
  292|     42|}
mbedtls_internal_sha512_process:
  603|     42|{
  604|     42|    int i;
  605|     42|    struct {
  606|     42|        uint64_t temp1, temp2, W[80];
  607|     42|        uint64_t A[8];
  608|     42|    } local;
  609|       |
  610|     42|#define  SHR(x, n) ((x) >> (n))
  611|     42|#define ROTR(x, n) (SHR((x), (n)) | ((x) << (64 - (n))))
  612|       |
  613|     42|#define S0(x) (ROTR(x, 1) ^ ROTR(x, 8) ^  SHR(x, 7))
  614|     42|#define S1(x) (ROTR(x, 19) ^ ROTR(x, 61) ^  SHR(x, 6))
  615|       |
  616|     42|#define S2(x) (ROTR(x, 28) ^ ROTR(x, 34) ^ ROTR(x, 39))
  617|     42|#define S3(x) (ROTR(x, 14) ^ ROTR(x, 18) ^ ROTR(x, 41))
  618|       |
  619|     42|#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
  620|     42|#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
  621|       |
  622|     42|#define P(a, b, c, d, e, f, g, h, x, K)                                      \
  623|     42|    do                                                              \
  624|     42|    {                                                               \
  625|     42|        local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  626|     42|        local.temp2 = S2(a) + F0((a), (b), (c));                      \
  627|     42|        (d) += local.temp1; (h) = local.temp1 + local.temp2;        \
  628|     42|    } while (0)
  629|       |
  630|    378|    for (i = 0; i < 8; i++) {
  ------------------
  |  Branch (630:17): [True: 336, False: 42]
  ------------------
  631|    336|        local.A[i] = ctx->state[i];
  632|    336|    }
  633|       |
  634|     42|#if defined(MBEDTLS_SHA512_SMALLER)
  635|  3.40k|    for (i = 0; i < 80; i++) {
  ------------------
  |  Branch (635:17): [True: 3.36k, False: 42]
  ------------------
  636|  3.36k|        if (i < 16) {
  ------------------
  |  Branch (636:13): [True: 672, False: 2.68k]
  ------------------
  637|    672|            local.W[i] = MBEDTLS_GET_UINT64_BE(data, i << 3);
  ------------------
  |  |  622|    672|    ((MBEDTLS_IS_BIG_ENDIAN)                                               \
  |  |  ------------------
  |  |  |  |  398|    672|#define MBEDTLS_IS_BIG_ENDIAN 0
  |  |  ------------------
  |  |  |  Branch (622:6): [Folded - Ignored]
  |  |  ------------------
  |  |  623|    672|        ? mbedtls_get_unaligned_uint64((data) + (offset))                  \
  |  |  624|    672|        : MBEDTLS_BSWAP64(mbedtls_get_unaligned_uint64((data) + (offset))) \
  |  |  ------------------
  |  |  |  |  301|    672|#define MBEDTLS_BSWAP64 __builtin_bswap64
  |  |  ------------------
  |  |  625|    672|    )
  ------------------
  638|  2.68k|        } else {
  639|  2.68k|            local.W[i] = S1(local.W[i -  2]) + local.W[i -  7] +
  ------------------
  |  |  614|  2.68k|#define S1(x) (ROTR(x, 19) ^ ROTR(x, 61) ^  SHR(x, 6))
  |  |  ------------------
  |  |  |  |  611|  2.68k|#define ROTR(x, n) (SHR((x), (n)) | ((x) << (64 - (n))))
  |  |  |  |  ------------------
  |  |  |  |  |  |  610|  2.68k|#define  SHR(x, n) ((x) >> (n))
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define S1(x) (ROTR(x, 19) ^ ROTR(x, 61) ^  SHR(x, 6))
  |  |  ------------------
  |  |  |  |  611|  2.68k|#define ROTR(x, n) (SHR((x), (n)) | ((x) << (64 - (n))))
  |  |  |  |  ------------------
  |  |  |  |  |  |  610|  2.68k|#define  SHR(x, n) ((x) >> (n))
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define S1(x) (ROTR(x, 19) ^ ROTR(x, 61) ^  SHR(x, 6))
  |  |  ------------------
  |  |  |  |  610|  2.68k|#define  SHR(x, n) ((x) >> (n))
  |  |  ------------------
  ------------------
  640|  2.68k|                         S0(local.W[i - 15]) + local.W[i - 16];
  ------------------
  |  |  613|  2.68k|#define S0(x) (ROTR(x, 1) ^ ROTR(x, 8) ^  SHR(x, 7))
  |  |  ------------------
  |  |  |  |  611|  2.68k|#define ROTR(x, n) (SHR((x), (n)) | ((x) << (64 - (n))))
  |  |  |  |  ------------------
  |  |  |  |  |  |  610|  2.68k|#define  SHR(x, n) ((x) >> (n))
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define S0(x) (ROTR(x, 1) ^ ROTR(x, 8) ^  SHR(x, 7))
  |  |  ------------------
  |  |  |  |  611|  2.68k|#define ROTR(x, n) (SHR((x), (n)) | ((x) << (64 - (n))))
  |  |  |  |  ------------------
  |  |  |  |  |  |  610|  2.68k|#define  SHR(x, n) ((x) >> (n))
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define S0(x) (ROTR(x, 1) ^ ROTR(x, 8) ^  SHR(x, 7))
  |  |  ------------------
  |  |  |  |  610|  2.68k|#define  SHR(x, n) ((x) >> (n))
  |  |  ------------------
  ------------------
  641|  2.68k|        }
  642|       |
  643|  3.36k|        P(local.A[0], local.A[1], local.A[2], local.A[3], local.A[4],
  ------------------
  |  |  623|  3.36k|    do                                                              \
  |  |  624|  3.36k|    {                                                               \
  |  |  625|  3.36k|        local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  617|  3.36k|#define S3(x) (ROTR(x, 14) ^ ROTR(x, 18) ^ ROTR(x, 41))
  |  |  |  |  ------------------
  |  |  |  |  |  |  611|  3.36k|#define ROTR(x, n) (SHR((x), (n)) | ((x) << (64 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  610|  3.36k|#define  SHR(x, n) ((x) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 14) ^ ROTR(x, 18) ^ ROTR(x, 41))
  |  |  |  |  ------------------
  |  |  |  |  |  |  611|  3.36k|#define ROTR(x, n) (SHR((x), (n)) | ((x) << (64 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  610|  3.36k|#define  SHR(x, n) ((x) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S3(x) (ROTR(x, 14) ^ ROTR(x, 18) ^ ROTR(x, 41))
  |  |  |  |  ------------------
  |  |  |  |  |  |  611|  3.36k|#define ROTR(x, n) (SHR((x), (n)) | ((x) << (64 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  610|  3.36k|#define  SHR(x, n) ((x) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x);    \
  |  |  ------------------
  |  |  |  |  620|  3.36k|#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
  |  |  ------------------
  |  |  626|  3.36k|        local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  616|  3.36k|#define S2(x) (ROTR(x, 28) ^ ROTR(x, 34) ^ ROTR(x, 39))
  |  |  |  |  ------------------
  |  |  |  |  |  |  611|  3.36k|#define ROTR(x, n) (SHR((x), (n)) | ((x) << (64 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  610|  3.36k|#define  SHR(x, n) ((x) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 28) ^ ROTR(x, 34) ^ ROTR(x, 39))
  |  |  |  |  ------------------
  |  |  |  |  |  |  611|  3.36k|#define ROTR(x, n) (SHR((x), (n)) | ((x) << (64 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  610|  3.36k|#define  SHR(x, n) ((x) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define S2(x) (ROTR(x, 28) ^ ROTR(x, 34) ^ ROTR(x, 39))
  |  |  |  |  ------------------
  |  |  |  |  |  |  611|  3.36k|#define ROTR(x, n) (SHR((x), (n)) | ((x) << (64 - (n))))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  610|  3.36k|#define  SHR(x, n) ((x) >> (n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                       local.temp2 = S2(a) + F0((a), (b), (c));                      \
  |  |  ------------------
  |  |  |  |  619|  3.36k|#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
  |  |  ------------------
  |  |  627|  3.36k|        (d) += local.temp1; (h) = local.temp1 + local.temp2;        \
  |  |  628|  3.36k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (628:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
  644|  3.36k|          local.A[5], local.A[6], local.A[7], local.W[i], K[i]);
  645|       |
  646|  3.36k|        local.temp1 = local.A[7]; local.A[7] = local.A[6];
  647|  3.36k|        local.A[6] = local.A[5]; local.A[5] = local.A[4];
  648|  3.36k|        local.A[4] = local.A[3]; local.A[3] = local.A[2];
  649|  3.36k|        local.A[2] = local.A[1]; local.A[1] = local.A[0];
  650|  3.36k|        local.A[0] = local.temp1;
  651|  3.36k|    }
  652|       |#else /* MBEDTLS_SHA512_SMALLER */
  653|       |    for (i = 0; i < 16; i++) {
  654|       |        local.W[i] = MBEDTLS_GET_UINT64_BE(data, i << 3);
  655|       |    }
  656|       |
  657|       |    for (; i < 80; i++) {
  658|       |        local.W[i] = S1(local.W[i -  2]) + local.W[i -  7] +
  659|       |                     S0(local.W[i - 15]) + local.W[i - 16];
  660|       |    }
  661|       |
  662|       |    i = 0;
  663|       |    do {
  664|       |        P(local.A[0], local.A[1], local.A[2], local.A[3], local.A[4],
  665|       |          local.A[5], local.A[6], local.A[7], local.W[i], K[i]); i++;
  666|       |        P(local.A[7], local.A[0], local.A[1], local.A[2], local.A[3],
  667|       |          local.A[4], local.A[5], local.A[6], local.W[i], K[i]); i++;
  668|       |        P(local.A[6], local.A[7], local.A[0], local.A[1], local.A[2],
  669|       |          local.A[3], local.A[4], local.A[5], local.W[i], K[i]); i++;
  670|       |        P(local.A[5], local.A[6], local.A[7], local.A[0], local.A[1],
  671|       |          local.A[2], local.A[3], local.A[4], local.W[i], K[i]); i++;
  672|       |        P(local.A[4], local.A[5], local.A[6], local.A[7], local.A[0],
  673|       |          local.A[1], local.A[2], local.A[3], local.W[i], K[i]); i++;
  674|       |        P(local.A[3], local.A[4], local.A[5], local.A[6], local.A[7],
  675|       |          local.A[0], local.A[1], local.A[2], local.W[i], K[i]); i++;
  676|       |        P(local.A[2], local.A[3], local.A[4], local.A[5], local.A[6],
  677|       |          local.A[7], local.A[0], local.A[1], local.W[i], K[i]); i++;
  678|       |        P(local.A[1], local.A[2], local.A[3], local.A[4], local.A[5],
  679|       |          local.A[6], local.A[7], local.A[0], local.W[i], K[i]); i++;
  680|       |    } while (i < 80);
  681|       |#endif /* MBEDTLS_SHA512_SMALLER */
  682|       |
  683|    378|    for (i = 0; i < 8; i++) {
  ------------------
  |  Branch (683:17): [True: 336, False: 42]
  ------------------
  684|    336|        ctx->state[i] += local.A[i];
  685|    336|    }
  686|       |
  687|       |    /* Zeroise buffers and variables to clear sensitive data from memory. */
  688|     42|    mbedtls_platform_zeroize(&local, sizeof(local));
  689|       |
  690|     42|    return 0;
  691|     42|}
mbedtls_sha512_update:
  763|     63|{
  764|     63|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|     63|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  765|     63|    size_t fill;
  766|     63|    unsigned int left;
  767|       |
  768|     63|    if (ilen == 0) {
  ------------------
  |  Branch (768:9): [True: 0, False: 63]
  ------------------
  769|      0|        return 0;
  770|      0|    }
  771|       |
  772|     63|    left = (unsigned int) (ctx->total[0] & 0x7F);
  773|     63|    fill = SHA512_BLOCK_SIZE - left;
  ------------------
  |  |  210|     63|#define SHA512_BLOCK_SIZE 128
  ------------------
  774|       |
  775|     63|    ctx->total[0] += (uint64_t) ilen;
  776|       |
  777|     63|    if (ctx->total[0] < (uint64_t) ilen) {
  ------------------
  |  Branch (777:9): [True: 0, False: 63]
  ------------------
  778|      0|        ctx->total[1]++;
  779|      0|    }
  780|       |
  781|     63|    if (left && ilen >= fill) {
  ------------------
  |  Branch (781:9): [True: 21, False: 42]
  |  Branch (781:17): [True: 0, False: 21]
  ------------------
  782|      0|        memcpy((void *) (ctx->buffer + left), input, fill);
  783|       |
  784|      0|        if ((ret = mbedtls_internal_sha512_process(ctx, ctx->buffer)) != 0) {
  ------------------
  |  Branch (784:13): [True: 0, False: 0]
  ------------------
  785|      0|            return ret;
  786|      0|        }
  787|       |
  788|      0|        input += fill;
  789|      0|        ilen  -= fill;
  790|      0|        left = 0;
  791|      0|    }
  792|       |
  793|     84|    while (ilen >= SHA512_BLOCK_SIZE) {
  ------------------
  |  |  210|     84|#define SHA512_BLOCK_SIZE 128
  ------------------
  |  Branch (793:12): [True: 21, False: 63]
  ------------------
  794|     21|        size_t processed =
  795|     21|            mbedtls_internal_sha512_process_many(ctx, input, ilen);
  796|     21|        if (processed < SHA512_BLOCK_SIZE) {
  ------------------
  |  |  210|     21|#define SHA512_BLOCK_SIZE 128
  ------------------
  |  Branch (796:13): [True: 0, False: 21]
  ------------------
  797|      0|            return MBEDTLS_ERR_ERROR_GENERIC_ERROR;
  ------------------
  |  |   98|      0|#define MBEDTLS_ERR_ERROR_GENERIC_ERROR       -0x0001
  ------------------
  798|      0|        }
  799|       |
  800|     21|        input += processed;
  801|     21|        ilen  -= processed;
  802|     21|    }
  803|       |
  804|     63|    if (ilen > 0) {
  ------------------
  |  Branch (804:9): [True: 42, False: 21]
  ------------------
  805|     42|        memcpy((void *) (ctx->buffer + left), input, ilen);
  806|     42|    }
  807|       |
  808|     63|    return 0;
  809|     63|}
mbedtls_sha512_finish:
  816|     21|{
  817|     21|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|     21|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  818|     21|    unsigned used;
  819|     21|    uint64_t high, low;
  820|     21|    int truncated = 0;
  821|       |
  822|       |    /*
  823|       |     * Add padding: 0x80 then 0x00 until 16 bytes remain for the length
  824|       |     */
  825|     21|    used = ctx->total[0] & 0x7F;
  826|       |
  827|     21|    ctx->buffer[used++] = 0x80;
  828|       |
  829|     21|    if (used <= 112) {
  ------------------
  |  Branch (829:9): [True: 21, False: 0]
  ------------------
  830|       |        /* Enough room for padding + length in current block */
  831|     21|        memset(ctx->buffer + used, 0, 112 - used);
  832|     21|    } else {
  833|       |        /* We'll need an extra block */
  834|      0|        memset(ctx->buffer + used, 0, SHA512_BLOCK_SIZE - used);
  ------------------
  |  |  210|      0|#define SHA512_BLOCK_SIZE 128
  ------------------
  835|       |
  836|      0|        if ((ret = mbedtls_internal_sha512_process(ctx, ctx->buffer)) != 0) {
  ------------------
  |  Branch (836:13): [True: 0, False: 0]
  ------------------
  837|      0|            goto exit;
  838|      0|        }
  839|       |
  840|      0|        memset(ctx->buffer, 0, 112);
  841|      0|    }
  842|       |
  843|       |    /*
  844|       |     * Add message length
  845|       |     */
  846|     21|    high = (ctx->total[0] >> 61)
  847|     21|           | (ctx->total[1] <<  3);
  848|     21|    low  = (ctx->total[0] <<  3);
  849|       |
  850|     21|    sha512_put_uint64_be(high, ctx->buffer, 112);
  851|     21|    sha512_put_uint64_be(low,  ctx->buffer, 120);
  852|       |
  853|     21|    if ((ret = mbedtls_internal_sha512_process(ctx, ctx->buffer)) != 0) {
  ------------------
  |  Branch (853:9): [True: 0, False: 21]
  ------------------
  854|      0|        goto exit;
  855|      0|    }
  856|       |
  857|       |    /*
  858|       |     * Output final state
  859|       |     */
  860|     21|    sha512_put_uint64_be(ctx->state[0], output,  0);
  861|     21|    sha512_put_uint64_be(ctx->state[1], output,  8);
  862|     21|    sha512_put_uint64_be(ctx->state[2], output, 16);
  863|     21|    sha512_put_uint64_be(ctx->state[3], output, 24);
  864|     21|    sha512_put_uint64_be(ctx->state[4], output, 32);
  865|     21|    sha512_put_uint64_be(ctx->state[5], output, 40);
  866|       |
  867|     21|#if defined(MBEDTLS_SHA384_C)
  868|     21|    truncated = ctx->is384;
  869|     21|#endif
  870|     21|    if (!truncated) {
  ------------------
  |  Branch (870:9): [True: 21, False: 0]
  ------------------
  871|     21|        sha512_put_uint64_be(ctx->state[6], output, 48);
  872|     21|        sha512_put_uint64_be(ctx->state[7], output, 56);
  873|     21|    }
  874|       |
  875|     21|    ret = 0;
  876|       |
  877|     21|exit:
  878|     21|    mbedtls_sha512_free(ctx);
  879|     21|    return ret;
  880|     21|}
mbedtls_sha512:
  891|     21|{
  892|     21|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|     21|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  893|     21|    mbedtls_sha512_context ctx;
  894|       |
  895|     21|#if defined(MBEDTLS_SHA384_C) && defined(MBEDTLS_SHA512_C)
  896|     21|    if (is384 != 0 && is384 != 1) {
  ------------------
  |  Branch (896:9): [True: 0, False: 21]
  |  Branch (896:23): [True: 0, False: 0]
  ------------------
  897|      0|        return MBEDTLS_ERR_SHA512_BAD_INPUT_DATA;
  ------------------
  |  |   22|      0|#define MBEDTLS_ERR_SHA512_BAD_INPUT_DATA                 -0x0075
  ------------------
  898|      0|    }
  899|       |#elif defined(MBEDTLS_SHA512_C)
  900|       |    if (is384 != 0) {
  901|       |        return MBEDTLS_ERR_SHA512_BAD_INPUT_DATA;
  902|       |    }
  903|       |#else /* defined MBEDTLS_SHA384_C only */
  904|       |    if (is384 == 0) {
  905|       |        return MBEDTLS_ERR_SHA512_BAD_INPUT_DATA;
  906|       |    }
  907|       |#endif
  908|       |
  909|     21|    mbedtls_sha512_init(&ctx);
  910|       |
  911|     21|    if ((ret = mbedtls_sha512_starts(&ctx, is384)) != 0) {
  ------------------
  |  Branch (911:9): [True: 0, False: 21]
  ------------------
  912|      0|        goto exit;
  913|      0|    }
  914|       |
  915|     21|    if ((ret = mbedtls_sha512_update(&ctx, input, ilen)) != 0) {
  ------------------
  |  Branch (915:9): [True: 0, False: 21]
  ------------------
  916|      0|        goto exit;
  917|      0|    }
  918|       |
  919|     21|    if ((ret = mbedtls_sha512_finish(&ctx, output)) != 0) {
  ------------------
  |  Branch (919:9): [True: 0, False: 21]
  ------------------
  920|      0|        goto exit;
  921|      0|    }
  922|       |
  923|     21|exit:
  924|     21|    mbedtls_sha512_free(&ctx);
  925|       |
  926|     21|    return ret;
  927|     21|}
sha512.c:mbedtls_internal_sha512_process_many:
  700|     21|{
  701|     21|    size_t processed = 0;
  702|       |
  703|     42|    while (len >= SHA512_BLOCK_SIZE) {
  ------------------
  |  |  210|     42|#define SHA512_BLOCK_SIZE 128
  ------------------
  |  Branch (703:12): [True: 21, False: 21]
  ------------------
  704|     21|        if (mbedtls_internal_sha512_process_c(ctx, data) != 0) {
  ------------------
  |  |  588|     21|#define mbedtls_internal_sha512_process_c      mbedtls_internal_sha512_process
  ------------------
  |  Branch (704:13): [True: 0, False: 21]
  ------------------
  705|      0|            return 0;
  706|      0|        }
  707|       |
  708|     21|        data += SHA512_BLOCK_SIZE;
  ------------------
  |  |  210|     21|#define SHA512_BLOCK_SIZE 128
  ------------------
  709|     21|        len  -= SHA512_BLOCK_SIZE;
  ------------------
  |  |  210|     21|#define SHA512_BLOCK_SIZE 128
  ------------------
  710|       |
  711|     21|        processed += SHA512_BLOCK_SIZE;
  ------------------
  |  |  210|     21|#define SHA512_BLOCK_SIZE 128
  ------------------
  712|     21|    }
  713|       |
  714|     21|    return processed;
  715|     21|}
sha512.c:sha512_put_uint64_be:
  214|    210|{
  215|    210|    MBEDTLS_PUT_UINT64_BE(n, b, i);
  ------------------
  |  |  637|    210|    {                                                                            \
  |  |  638|    210|        if (MBEDTLS_IS_BIG_ENDIAN)                                               \
  |  |  ------------------
  |  |  |  |  398|    210|#define MBEDTLS_IS_BIG_ENDIAN 0
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (398:31): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  639|    210|        {                                                                        \
  |  |  640|      0|            mbedtls_put_unaligned_uint64((data) + (offset), (uint64_t) (n));     \
  |  |  641|      0|        }                                                                        \
  |  |  642|    210|        else                                                                     \
  |  |  643|    210|        {                                                                        \
  |  |  644|    210|            mbedtls_put_unaligned_uint64((data) + (offset), MBEDTLS_BSWAP64((uint64_t) (n))); \
  |  |  ------------------
  |  |  |  |  301|    210|#define MBEDTLS_BSWAP64 __builtin_bswap64
  |  |  ------------------
  |  |  645|    210|        }                                                                        \
  |  |  646|    210|    }
  ------------------
  216|    210|}

mbedtls_ssl_transform_free:
 6207|     21|{
 6208|     21|    if (transform == NULL) {
  ------------------
  |  Branch (6208:9): [True: 21, False: 0]
  ------------------
 6209|     21|        return;
 6210|     21|    }
 6211|       |
 6212|      0|#if defined(MBEDTLS_USE_PSA_CRYPTO)
 6213|      0|    psa_destroy_key(transform->psa_key_enc);
 6214|      0|    psa_destroy_key(transform->psa_key_dec);
 6215|       |#else
 6216|       |    mbedtls_cipher_free(&transform->cipher_ctx_enc);
 6217|       |    mbedtls_cipher_free(&transform->cipher_ctx_dec);
 6218|       |#endif /* MBEDTLS_USE_PSA_CRYPTO */
 6219|       |
 6220|      0|#if defined(MBEDTLS_SSL_SOME_SUITES_USE_MAC)
 6221|      0|#if defined(MBEDTLS_USE_PSA_CRYPTO)
 6222|      0|    psa_destroy_key(transform->psa_mac_enc);
 6223|      0|    psa_destroy_key(transform->psa_mac_dec);
 6224|       |#else
 6225|       |    mbedtls_md_free(&transform->md_ctx_enc);
 6226|       |    mbedtls_md_free(&transform->md_ctx_dec);
 6227|       |#endif /* MBEDTLS_USE_PSA_CRYPTO */
 6228|      0|#endif
 6229|       |
 6230|      0|    mbedtls_platform_zeroize(transform, sizeof(mbedtls_ssl_transform));
 6231|      0|}

mbedtls_ssl_init:
 1304|     21|{
 1305|     21|    memset(ssl, 0, sizeof(mbedtls_ssl_context));
 1306|     21|}
mbedtls_ssl_free:
 5516|     21|{
 5517|     21|    if (ssl == NULL) {
  ------------------
  |  Branch (5517:9): [True: 0, False: 21]
  ------------------
 5518|      0|        return;
 5519|      0|    }
 5520|       |
 5521|     21|    MBEDTLS_SSL_DEBUG_MSG(2, ("=> free"));
  ------------------
  |  |   26|     21|    mbedtls_debug_print_msg(ssl, level, __FILE__, __LINE__,    \
  |  |   27|     21|                            MBEDTLS_DEBUG_STRIP_PARENS args)
  |  |  ------------------
  |  |  |  |   23|     21|#define MBEDTLS_DEBUG_STRIP_PARENS(...)   __VA_ARGS__
  |  |  ------------------
  ------------------
 5522|       |
 5523|     21|    if (ssl->out_buf != NULL) {
  ------------------
  |  Branch (5523:9): [True: 0, False: 21]
  ------------------
 5524|      0|#if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH)
 5525|      0|        size_t out_buf_len = ssl->out_buf_len;
 5526|       |#else
 5527|       |        size_t out_buf_len = MBEDTLS_SSL_OUT_BUFFER_LEN;
 5528|       |#endif
 5529|       |
 5530|      0|        mbedtls_zeroize_and_free(ssl->out_buf, out_buf_len);
 5531|      0|        ssl->out_buf = NULL;
 5532|      0|    }
 5533|       |
 5534|     21|    if (ssl->in_buf != NULL) {
  ------------------
  |  Branch (5534:9): [True: 0, False: 21]
  ------------------
 5535|      0|#if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH)
 5536|      0|        size_t in_buf_len = ssl->in_buf_len;
 5537|       |#else
 5538|       |        size_t in_buf_len = MBEDTLS_SSL_IN_BUFFER_LEN;
 5539|       |#endif
 5540|       |
 5541|      0|        mbedtls_zeroize_and_free(ssl->in_buf, in_buf_len);
 5542|      0|        ssl->in_buf = NULL;
 5543|      0|    }
 5544|       |
 5545|     21|    if (ssl->transform) {
  ------------------
  |  Branch (5545:9): [True: 0, False: 21]
  ------------------
 5546|      0|        mbedtls_ssl_transform_free(ssl->transform);
 5547|      0|        mbedtls_free(ssl->transform);
 5548|      0|    }
 5549|       |
 5550|     21|    if (ssl->handshake) {
  ------------------
  |  Branch (5550:9): [True: 0, False: 21]
  ------------------
 5551|      0|        mbedtls_ssl_handshake_free(ssl);
 5552|      0|        mbedtls_free(ssl->handshake);
 5553|       |
 5554|      0|#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
 5555|      0|        mbedtls_ssl_transform_free(ssl->transform_negotiate);
 5556|      0|        mbedtls_free(ssl->transform_negotiate);
 5557|      0|#endif
 5558|       |
 5559|      0|        mbedtls_ssl_session_free(ssl->session_negotiate);
 5560|      0|        mbedtls_free(ssl->session_negotiate);
 5561|      0|    }
 5562|       |
 5563|     21|#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
 5564|     21|    mbedtls_ssl_transform_free(ssl->transform_application);
 5565|     21|    mbedtls_free(ssl->transform_application);
 5566|     21|#endif /* MBEDTLS_SSL_PROTO_TLS1_3 */
 5567|       |
 5568|     21|    if (ssl->session) {
  ------------------
  |  Branch (5568:9): [True: 0, False: 21]
  ------------------
 5569|      0|        mbedtls_ssl_session_free(ssl->session);
 5570|      0|        mbedtls_free(ssl->session);
 5571|      0|    }
 5572|       |
 5573|     21|#if defined(MBEDTLS_X509_CRT_PARSE_C)
 5574|     21|    if (ssl->hostname != NULL) {
  ------------------
  |  Branch (5574:9): [True: 0, False: 21]
  ------------------
 5575|      0|        mbedtls_zeroize_and_free(ssl->hostname, strlen(ssl->hostname));
 5576|      0|    }
 5577|     21|#endif
 5578|       |
 5579|     21|#if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
 5580|     21|    mbedtls_free(ssl->cli_id);
 5581|     21|#endif
 5582|       |
 5583|     21|    MBEDTLS_SSL_DEBUG_MSG(2, ("<= free"));
  ------------------
  |  |   26|     21|    mbedtls_debug_print_msg(ssl, level, __FILE__, __LINE__,    \
  |  |   27|     21|                            MBEDTLS_DEBUG_STRIP_PARENS args)
  |  |  ------------------
  |  |  |  |   23|     21|#define MBEDTLS_DEBUG_STRIP_PARENS(...)   __VA_ARGS__
  |  |  ------------------
  ------------------
 5584|       |
 5585|       |    /* Actually clear after last debug message */
 5586|     21|    mbedtls_platform_zeroize(ssl, sizeof(mbedtls_ssl_context));
 5587|     21|}
mbedtls_ssl_config_init:
 5593|     21|{
 5594|     21|    memset(conf, 0, sizeof(mbedtls_ssl_config));
 5595|     21|}
mbedtls_ssl_config_free:
 6058|     21|{
 6059|     21|    if (conf == NULL) {
  ------------------
  |  Branch (6059:9): [True: 0, False: 21]
  ------------------
 6060|      0|        return;
 6061|      0|    }
 6062|       |
 6063|     21|#if defined(MBEDTLS_DHM_C)
 6064|     21|    mbedtls_mpi_free(&conf->dhm_P);
 6065|     21|    mbedtls_mpi_free(&conf->dhm_G);
 6066|     21|#endif
 6067|       |
 6068|     21|#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED)
 6069|     21|#if defined(MBEDTLS_USE_PSA_CRYPTO)
 6070|     21|    if (!mbedtls_svc_key_id_is_null(conf->psk_opaque)) {
  ------------------
  |  Branch (6070:9): [True: 0, False: 21]
  ------------------
 6071|      0|        conf->psk_opaque = MBEDTLS_SVC_KEY_ID_INIT;
  ------------------
  |  | 2438|      0|#define MBEDTLS_SVC_KEY_ID_INIT ((psa_key_id_t) 0)
  ------------------
 6072|      0|    }
 6073|     21|#endif /* MBEDTLS_USE_PSA_CRYPTO */
 6074|     21|    if (conf->psk != NULL) {
  ------------------
  |  Branch (6074:9): [True: 0, False: 21]
  ------------------
 6075|      0|        mbedtls_zeroize_and_free(conf->psk, conf->psk_len);
 6076|      0|        conf->psk = NULL;
 6077|      0|        conf->psk_len = 0;
 6078|      0|    }
 6079|       |
 6080|     21|    if (conf->psk_identity != NULL) {
  ------------------
  |  Branch (6080:9): [True: 0, False: 21]
  ------------------
 6081|      0|        mbedtls_zeroize_and_free(conf->psk_identity, conf->psk_identity_len);
 6082|      0|        conf->psk_identity = NULL;
 6083|      0|        conf->psk_identity_len = 0;
 6084|      0|    }
 6085|     21|#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED */
 6086|       |
 6087|     21|#if defined(MBEDTLS_X509_CRT_PARSE_C)
 6088|     21|    ssl_key_cert_free(conf->key_cert);
 6089|     21|#endif
 6090|       |
 6091|     21|    mbedtls_platform_zeroize(conf, sizeof(mbedtls_ssl_config));
 6092|     21|}
ssl_tls.c:ssl_key_cert_free:
 1812|     21|{
 1813|     21|    mbedtls_ssl_key_cert *cur = key_cert, *next;
 1814|       |
 1815|     21|    while (cur != NULL) {
  ------------------
  |  Branch (1815:12): [True: 0, False: 21]
  ------------------
 1816|      0|        next = cur->next;
 1817|      0|        mbedtls_free(cur);
 1818|      0|        cur = next;
 1819|      0|    }
 1820|     21|}

threading.c:threading_mutex_init_pthread:
   54|     65|{
   55|     65|    if (mutex == NULL) {
  ------------------
  |  Branch (55:9): [True: 0, False: 65]
  ------------------
   56|      0|        return;
   57|      0|    }
   58|       |
   59|       |    /* One problem here is that calling lock on a pthread mutex without first
   60|       |     * having initialised it is undefined behaviour. Obviously we cannot check
   61|       |     * this here in a thread safe manner without a significant performance
   62|       |     * hit, so state transitions are checked in tests only via the state
   63|       |     * variable. Please make sure any new mutex that gets added is exercised in
   64|       |     * tests; see framework/tests/src/threading_helpers.c for more details. */
   65|     65|    (void) pthread_mutex_init(&mutex->mutex, NULL);
   66|     65|}
threading.c:threading_mutex_free_pthread:
   69|     63|{
   70|     63|    if (mutex == NULL) {
  ------------------
  |  Branch (70:9): [True: 0, False: 63]
  ------------------
   71|      0|        return;
   72|      0|    }
   73|       |
   74|     63|    (void) pthread_mutex_destroy(&mutex->mutex);
   75|     63|}
threading.c:threading_mutex_lock_pthread:
   78|    357|{
   79|    357|    if (mutex == NULL) {
  ------------------
  |  Branch (79:9): [True: 0, False: 357]
  ------------------
   80|      0|        return MBEDTLS_ERR_THREADING_BAD_INPUT_DATA;
  ------------------
  |  |   23|      0|#define MBEDTLS_ERR_THREADING_BAD_INPUT_DATA              -0x001C
  ------------------
   81|      0|    }
   82|       |
   83|    357|    if (pthread_mutex_lock(&mutex->mutex) != 0) {
  ------------------
  |  Branch (83:9): [True: 0, False: 357]
  ------------------
   84|      0|        return MBEDTLS_ERR_THREADING_MUTEX_ERROR;
  ------------------
  |  |   25|      0|#define MBEDTLS_ERR_THREADING_MUTEX_ERROR                 -0x001E
  ------------------
   85|      0|    }
   86|       |
   87|    357|    return 0;
   88|    357|}
threading.c:threading_mutex_unlock_pthread:
   91|    357|{
   92|    357|    if (mutex == NULL) {
  ------------------
  |  Branch (92:9): [True: 0, False: 357]
  ------------------
   93|      0|        return MBEDTLS_ERR_THREADING_BAD_INPUT_DATA;
  ------------------
  |  |   23|      0|#define MBEDTLS_ERR_THREADING_BAD_INPUT_DATA              -0x001C
  ------------------
   94|      0|    }
   95|       |
   96|    357|    if (pthread_mutex_unlock(&mutex->mutex) != 0) {
  ------------------
  |  Branch (96:9): [True: 0, False: 357]
  ------------------
   97|      0|        return MBEDTLS_ERR_THREADING_MUTEX_ERROR;
  ------------------
  |  |   25|      0|#define MBEDTLS_ERR_THREADING_MUTEX_ERROR                 -0x001E
  ------------------
   98|      0|    }
   99|       |
  100|    357|    return 0;
  101|    357|}

mbedtls_x509_get_serial:
   65|      3|{
   66|      3|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|      3|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
   67|       |
   68|      3|    if ((end - *p) < 1) {
  ------------------
  |  Branch (68:9): [True: 0, False: 3]
  ------------------
   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|      3|    if (**p != (MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_PRIMITIVE | 2) &&
  ------------------
  |  |   83|      3|#define MBEDTLS_ASN1_CONTEXT_SPECIFIC        0x80
  ------------------
                  if (**p != (MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_PRIMITIVE | 2) &&
  ------------------
  |  |   81|      3|#define MBEDTLS_ASN1_PRIMITIVE               0x00
  ------------------
  |  Branch (73:9): [True: 3, False: 0]
  ------------------
   74|      3|        **p !=   MBEDTLS_ASN1_INTEGER) {
  ------------------
  |  |   65|      3|#define MBEDTLS_ASN1_INTEGER                 0x02
  ------------------
  |  Branch (74:9): [True: 0, False: 3]
  ------------------
   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|      3|    serial->tag = *(*p)++;
   80|       |
   81|      3|    if ((ret = mbedtls_asn1_get_len(p, end, &serial->len)) != 0) {
  ------------------
  |  Branch (81:9): [True: 0, False: 3]
  ------------------
   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|      3|    serial->p = *p;
   86|      3|    *p += serial->len;
   87|       |
   88|      3|    return 0;
   89|      3|}
mbedtls_x509_get_alg:
  114|      6|{
  115|      6|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|      6|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  116|       |
  117|      6|    if ((ret = mbedtls_asn1_get_alg(p, end, alg, params)) != 0) {
  ------------------
  |  Branch (117:9): [True: 0, False: 6]
  ------------------
  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|      6|    return 0;
  122|      6|}
mbedtls_x509_get_name:
  500|      6|{
  501|      6|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|      6|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  502|      6|    size_t set_len;
  503|      6|    const unsigned char *end_set;
  504|      6|    mbedtls_x509_name *head = cur;
  505|       |
  506|       |    /* don't use recursion, we'd risk stack overflow if not optimized */
  507|     18|    while (1) {
  ------------------
  |  Branch (507:12): [Folded - Ignored]
  ------------------
  508|       |        /*
  509|       |         * parse SET
  510|       |         */
  511|     18|        if ((ret = mbedtls_asn1_get_tag(p, end, &set_len,
  ------------------
  |  Branch (511:13): [True: 0, False: 18]
  ------------------
  512|     18|                                        MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SET)) != 0) {
  ------------------
  |  |   82|     18|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                      MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SET)) != 0) {
  ------------------
  |  |   73|     18|#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|     18|        end_set  = *p + set_len;
  518|       |
  519|     18|        while (1) {
  ------------------
  |  Branch (519:16): [Folded - Ignored]
  ------------------
  520|     18|            if ((ret = x509_get_attr_type_value(p, end_set, cur)) != 0) {
  ------------------
  |  Branch (520:17): [True: 0, False: 18]
  ------------------
  521|      0|                goto error;
  522|      0|            }
  523|       |
  524|     18|            if (*p == end_set) {
  ------------------
  |  Branch (524:17): [True: 18, False: 0]
  ------------------
  525|     18|                break;
  526|     18|            }
  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));
  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|     18|        if (*p == end) {
  ------------------
  |  Branch (544:13): [True: 6, False: 12]
  ------------------
  545|      6|            return 0;
  546|      6|        }
  547|       |
  548|     12|        cur->next = mbedtls_calloc(1, sizeof(mbedtls_x509_name));
  549|       |
  550|     12|        if (cur->next == NULL) {
  ------------------
  |  Branch (550:13): [True: 0, False: 12]
  ------------------
  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|     12|        cur = cur->next;
  556|     12|    }
  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|      6|}
mbedtls_x509_get_time:
  651|      6|{
  652|      6|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|      6|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  653|      6|    size_t len, year_len;
  654|      6|    unsigned char tag;
  655|       |
  656|      6|    if ((end - *p) < 1) {
  ------------------
  |  Branch (656:9): [True: 0, False: 6]
  ------------------
  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|      6|    tag = **p;
  662|       |
  663|      6|    if (tag == MBEDTLS_ASN1_UTC_TIME) {
  ------------------
  |  |   77|      6|#define MBEDTLS_ASN1_UTC_TIME                0x17
  ------------------
  |  Branch (663:9): [True: 6, False: 0]
  ------------------
  664|      6|        year_len = 2;
  665|      6|    } 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|      6|    (*p)++;
  673|      6|    ret = mbedtls_asn1_get_len(p, end, &len);
  674|       |
  675|      6|    if (ret != 0) {
  ------------------
  |  Branch (675:9): [True: 0, False: 6]
  ------------------
  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|      6|    if (len != year_len + 10 &&
  ------------------
  |  Branch (680:9): [True: 6, False: 0]
  ------------------
  681|      6|        !(len == year_len + 11 && (*p)[(len - 1)] == 'Z')) {
  ------------------
  |  Branch (681:11): [True: 6, False: 0]
  |  Branch (681:35): [True: 6, False: 0]
  ------------------
  682|      0|        return MBEDTLS_ERR_X509_INVALID_DATE;
  ------------------
  |  |   59|      0|#define MBEDTLS_ERR_X509_INVALID_DATE                     -0x2400
  ------------------
  683|      0|    }
  684|       |
  685|      6|    (*p) += len;
  686|      6|    return x509_parse_time(*p - len, tm, year_len);
  687|      6|}
mbedtls_x509_get_sig:
  690|      3|{
  691|      3|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|      3|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  692|      3|    size_t len;
  693|      3|    int tag_type;
  694|       |
  695|      3|    if ((end - *p) < 1) {
  ------------------
  |  Branch (695:9): [True: 0, False: 3]
  ------------------
  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|      3|    tag_type = **p;
  701|       |
  702|      3|    if ((ret = mbedtls_asn1_get_bitstring_null(p, end, &len)) != 0) {
  ------------------
  |  Branch (702:9): [True: 0, False: 3]
  ------------------
  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|      3|    sig->tag = tag_type;
  707|      3|    sig->len = len;
  708|      3|    sig->p = *p;
  709|       |
  710|      3|    *p += len;
  711|       |
  712|      3|    return 0;
  713|      3|}
mbedtls_x509_get_sig_alg:
  721|      3|{
  722|      3|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|      3|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  723|       |
  724|      3|    if (*sig_opts != NULL) {
  ------------------
  |  Branch (724:9): [True: 0, False: 3]
  ------------------
  725|      0|        return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
  ------------------
  |  |   75|      0|#define MBEDTLS_ERR_X509_BAD_INPUT_DATA                   -0x2800
  ------------------
  726|      0|    }
  727|       |
  728|      3|    if ((ret = mbedtls_oid_get_sig_alg(sig_oid, md_alg, pk_alg)) != 0) {
  ------------------
  |  Branch (728:9): [True: 0, False: 3]
  ------------------
  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|      3|#if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
  733|      3|    if (*pk_alg == MBEDTLS_PK_RSASSA_PSS) {
  ------------------
  |  Branch (733:9): [True: 0, False: 3]
  ------------------
  734|      0|        mbedtls_pk_rsassa_pss_options *pss_opts;
  735|       |
  736|      0|        pss_opts = mbedtls_calloc(1, sizeof(mbedtls_pk_rsassa_pss_options));
  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);
  747|      0|            return ret;
  748|      0|        }
  749|       |
  750|      0|        *sig_opts = (void *) pss_opts;
  751|      0|    } else
  752|      3|#endif /* MBEDTLS_X509_RSASSA_PSS_SUPPORT */
  753|      3|    {
  754|       |        /* Make sure parameters are absent or NULL */
  755|      3|        if ((sig_params->tag != MBEDTLS_ASN1_NULL && sig_params->tag != 0) ||
  ------------------
  |  |   68|      6|#define MBEDTLS_ASN1_NULL                    0x05
  ------------------
  |  Branch (755:14): [True: 0, False: 3]
  |  Branch (755:54): [True: 0, False: 0]
  ------------------
  756|      3|            sig_params->len != 0) {
  ------------------
  |  Branch (756:13): [True: 0, False: 3]
  ------------------
  757|      0|            return MBEDTLS_ERR_X509_INVALID_ALG;
  ------------------
  |  |   55|      0|#define MBEDTLS_ERR_X509_INVALID_ALG                      -0x2300
  ------------------
  758|      0|        }
  759|      3|    }
  760|       |
  761|      3|    return 0;
  762|      3|}
mbedtls_x509_get_ext:
  770|      3|{
  771|      3|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|      3|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  772|      3|    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|      3|    ret = mbedtls_asn1_get_tag(p, end, &ext->len,
  778|      3|                               MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | tag);
  ------------------
  |  |   83|      3|#define MBEDTLS_ASN1_CONTEXT_SPECIFIC        0x80
  ------------------
                                             MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | tag);
  ------------------
  |  |   82|      3|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
  779|      3|    if (ret != 0) {
  ------------------
  |  Branch (779:9): [True: 0, False: 3]
  ------------------
  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|      3|    ext->tag = MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | tag;
  ------------------
  |  |   83|      3|#define MBEDTLS_ASN1_CONTEXT_SPECIFIC        0x80
  ------------------
                  ext->tag = MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | tag;
  ------------------
  |  |   82|      3|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
  784|      3|    ext->p   = *p;
  785|      3|    end      = *p + ext->len;
  786|       |
  787|       |    /*
  788|       |     * Extensions  ::=  SEQUENCE SIZE (1..MAX) OF Extension
  789|       |     */
  790|      3|    if ((ret = mbedtls_asn1_get_tag(p, end, &len,
  ------------------
  |  Branch (790:9): [True: 0, False: 3]
  ------------------
  791|      3|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|      3|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|      3|#define MBEDTLS_ASN1_SEQUENCE                0x10
  ------------------
  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|      3|    if (end != *p + len) {
  ------------------
  |  Branch (795:9): [True: 0, False: 3]
  ------------------
  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|      3|    return 0;
  801|      3|}
x509.c:x509_get_attr_type_value:
  409|     18|{
  410|     18|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|     18|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  411|     18|    size_t len;
  412|     18|    mbedtls_x509_buf *oid;
  413|     18|    mbedtls_x509_buf *val;
  414|       |
  415|     18|    if ((ret = mbedtls_asn1_get_tag(p, end, &len,
  ------------------
  |  Branch (415:9): [True: 0, False: 18]
  ------------------
  416|     18|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|     18|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|     18|#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|     18|    end = *p + len;
  421|       |
  422|     18|    if ((end - *p) < 1) {
  ------------------
  |  Branch (422:9): [True: 0, False: 18]
  ------------------
  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|     18|    oid = &cur->oid;
  428|     18|    oid->tag = **p;
  429|       |
  430|     18|    if ((ret = mbedtls_asn1_get_tag(p, end, &oid->len, MBEDTLS_ASN1_OID)) != 0) {
  ------------------
  |  |   69|     18|#define MBEDTLS_ASN1_OID                     0x06
  ------------------
  |  Branch (430:9): [True: 0, False: 18]
  ------------------
  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|     18|    oid->p = *p;
  435|     18|    *p += oid->len;
  436|       |
  437|     18|    if ((end - *p) < 1) {
  ------------------
  |  Branch (437:9): [True: 0, False: 18]
  ------------------
  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|     18|    if (**p != MBEDTLS_ASN1_BMP_STRING && **p != MBEDTLS_ASN1_UTF8_STRING      &&
  ------------------
  |  |   80|     36|#define MBEDTLS_ASN1_BMP_STRING              0x1E
  ------------------
                  if (**p != MBEDTLS_ASN1_BMP_STRING && **p != MBEDTLS_ASN1_UTF8_STRING      &&
  ------------------
  |  |   71|     36|#define MBEDTLS_ASN1_UTF8_STRING             0x0C
  ------------------
  |  Branch (442:9): [True: 18, False: 0]
  |  Branch (442:43): [True: 6, False: 12]
  ------------------
  443|     18|        **p != MBEDTLS_ASN1_T61_STRING && **p != MBEDTLS_ASN1_PRINTABLE_STRING &&
  ------------------
  |  |   75|     24|#define MBEDTLS_ASN1_T61_STRING              0x14
  ------------------
                      **p != MBEDTLS_ASN1_T61_STRING && **p != MBEDTLS_ASN1_PRINTABLE_STRING &&
  ------------------
  |  |   74|     24|#define MBEDTLS_ASN1_PRINTABLE_STRING        0x13
  ------------------
  |  Branch (443:9): [True: 6, False: 0]
  |  Branch (443:43): [True: 0, False: 6]
  ------------------
  444|     18|        **p != MBEDTLS_ASN1_IA5_STRING && **p != MBEDTLS_ASN1_UNIVERSAL_STRING &&
  ------------------
  |  |   76|     18|#define MBEDTLS_ASN1_IA5_STRING              0x16
  ------------------
                      **p != MBEDTLS_ASN1_IA5_STRING && **p != MBEDTLS_ASN1_UNIVERSAL_STRING &&
  ------------------
  |  |   79|     18|#define MBEDTLS_ASN1_UNIVERSAL_STRING        0x1C
  ------------------
  |  Branch (444:9): [True: 0, False: 0]
  |  Branch (444:43): [True: 0, False: 0]
  ------------------
  445|     18|        **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|     18|    val = &cur->val;
  451|     18|    val->tag = *(*p)++;
  452|       |
  453|     18|    if ((ret = mbedtls_asn1_get_len(p, end, &val->len)) != 0) {
  ------------------
  |  Branch (453:9): [True: 0, False: 18]
  ------------------
  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|     18|    val->p = *p;
  458|     18|    *p += val->len;
  459|       |
  460|     18|    if (*p != end) {
  ------------------
  |  Branch (460:9): [True: 0, False: 18]
  ------------------
  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|     18|    cur->next = NULL;
  466|       |
  467|     18|    return 0;
  468|     18|}
x509.c:x509_parse_time:
  612|      6|{
  613|      6|    int x;
  614|       |
  615|       |    /*
  616|       |     * Parse year, month, day, hour, minute, second
  617|       |     */
  618|      6|    tm->year = x509_parse2_int(p);
  619|      6|    if (tm->year < 0) {
  ------------------
  |  Branch (619:9): [True: 0, False: 6]
  ------------------
  620|      0|        return MBEDTLS_ERR_X509_INVALID_DATE;
  ------------------
  |  |   59|      0|#define MBEDTLS_ERR_X509_INVALID_DATE                     -0x2400
  ------------------
  621|      0|    }
  622|       |
  623|      6|    if (4 == yearlen) {
  ------------------
  |  Branch (623:9): [True: 0, False: 6]
  ------------------
  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|      6|    } else {
  631|      6|        x = (tm->year < 50) ? 2000 : 1900;
  ------------------
  |  Branch (631:13): [True: 6, False: 0]
  ------------------
  632|      6|    }
  633|      6|    tm->year += x;
  634|       |
  635|      6|    tm->mon  = x509_parse2_int(p + 2);
  636|      6|    tm->day  = x509_parse2_int(p + 4);
  637|      6|    tm->hour = x509_parse2_int(p + 6);
  638|      6|    tm->min  = x509_parse2_int(p + 8);
  639|      6|    tm->sec  = x509_parse2_int(p + 10);
  640|       |
  641|      6|    return x509_date_is_valid(tm);
  642|      6|}
x509.c:x509_parse2_int:
  600|     36|{
  601|     36|    uint32_t d1 = p[0] - '0';
  602|     36|    uint32_t d2 = p[1] - '0';
  603|     36|    return (d1 < 10 && d2 < 10) ? (int) (d1 * 10 + d2) : -1;
  ------------------
  |  Branch (603:13): [True: 36, False: 0]
  |  Branch (603:24): [True: 36, False: 0]
  ------------------
  604|     36|}
x509.c:x509_date_is_valid:
  567|      6|{
  568|      6|    unsigned int month_days;
  569|      6|    unsigned int year;
  570|      6|    switch (t->mon) {
  571|      0|        case 1: case 3: case 5: case 7: case 8: case 10: case 12:
  ------------------
  |  Branch (571:9): [True: 0, False: 6]
  |  Branch (571:17): [True: 0, False: 6]
  |  Branch (571:25): [True: 0, False: 6]
  |  Branch (571:33): [True: 0, False: 6]
  |  Branch (571:41): [True: 0, False: 6]
  |  Branch (571:49): [True: 0, False: 6]
  |  Branch (571:58): [True: 0, False: 6]
  ------------------
  572|      0|            month_days = 31;
  573|      0|            break;
  574|      0|        case 4: case 6: case 9: case 11:
  ------------------
  |  Branch (574:9): [True: 0, False: 6]
  |  Branch (574:17): [True: 0, False: 6]
  |  Branch (574:25): [True: 0, False: 6]
  |  Branch (574:33): [True: 0, False: 6]
  ------------------
  575|      0|            month_days = 30;
  576|      0|            break;
  577|      6|        case 2:
  ------------------
  |  Branch (577:9): [True: 6, False: 0]
  ------------------
  578|      6|            year = (unsigned int) t->year;
  579|      6|            month_days = ((year & 3) || (!(year % 100)
  ------------------
  |  Branch (579:27): [True: 6, False: 0]
  |  Branch (579:42): [True: 0, False: 0]
  ------------------
  580|      0|                                         && (year % 400)))
  ------------------
  |  Branch (580:45): [True: 0, False: 0]
  ------------------
  581|      6|                          ? 28 : 29;
  582|      6|            break;
  583|      0|        default:
  ------------------
  |  Branch (583:9): [True: 0, False: 6]
  ------------------
  584|      0|            return MBEDTLS_ERR_X509_INVALID_DATE;
  ------------------
  |  |   59|      0|#define MBEDTLS_ERR_X509_INVALID_DATE                     -0x2400
  ------------------
  585|      6|    }
  586|       |
  587|      6|    if ((unsigned int) (t->day - 1) >= month_days ||      /* (1 - days in month) */
  ------------------
  |  Branch (587:9): [True: 0, False: 6]
  ------------------
  588|       |        /* (unsigned int) (t->mon - 1) >= 12 || */  /* (1 - 12) checked above */
  589|      6|        (unsigned int) t->year > 9999 ||         /* (0 - 9999) */
  ------------------
  |  Branch (589:9): [True: 0, False: 6]
  ------------------
  590|      6|        (unsigned int) t->hour > 23 ||           /* (0 - 23) */
  ------------------
  |  Branch (590:9): [True: 0, False: 6]
  ------------------
  591|      6|        (unsigned int) t->min  > 59 ||           /* (0 - 59) */
  ------------------
  |  Branch (591:9): [True: 0, False: 6]
  ------------------
  592|      6|        (unsigned int) t->sec  > 59) {           /* (0 - 59) */
  ------------------
  |  Branch (592:9): [True: 0, False: 6]
  ------------------
  593|      0|        return MBEDTLS_ERR_X509_INVALID_DATE;
  ------------------
  |  |   59|      0|#define MBEDTLS_ERR_X509_INVALID_DATE                     -0x2400
  ------------------
  594|      0|    }
  595|       |
  596|      6|    return 0;
  597|      6|}

mbedtls_x509_crt_parse_der:
 1386|      3|{
 1387|      3|    return mbedtls_x509_crt_parse_der_internal(chain, buf, buflen, 1, NULL, NULL);
 1388|      3|}
mbedtls_x509_crt_parse:
 1397|      1|{
 1398|      1|#if defined(MBEDTLS_PEM_PARSE_C)
 1399|      1|    int success = 0, first_error = 0, total_failed = 0;
 1400|      1|    int buf_format = MBEDTLS_X509_FORMAT_DER;
  ------------------
  |  |  195|      1|#define MBEDTLS_X509_FORMAT_DER                 1
  ------------------
 1401|      1|#endif
 1402|       |
 1403|       |    /*
 1404|       |     * Check for valid input
 1405|       |     */
 1406|      1|    if (chain == NULL || buf == NULL) {
  ------------------
  |  Branch (1406:9): [True: 0, False: 1]
  |  Branch (1406:26): [True: 0, False: 1]
  ------------------
 1407|      0|        return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
  ------------------
  |  |   75|      0|#define MBEDTLS_ERR_X509_BAD_INPUT_DATA                   -0x2800
  ------------------
 1408|      0|    }
 1409|       |
 1410|       |    /*
 1411|       |     * Determine buffer content. Buffer contains either one DER certificate or
 1412|       |     * one or more PEM certificates.
 1413|       |     */
 1414|      1|#if defined(MBEDTLS_PEM_PARSE_C)
 1415|      1|    if (buflen != 0 && buf[buflen - 1] == '\0' &&
  ------------------
  |  Branch (1415:9): [True: 1, False: 0]
  |  Branch (1415:24): [True: 1, False: 0]
  ------------------
 1416|      1|        strstr((const char *) buf, "-----BEGIN CERTIFICATE-----") != NULL) {
  ------------------
  |  Branch (1416:9): [True: 1, False: 0]
  ------------------
 1417|      1|        buf_format = MBEDTLS_X509_FORMAT_PEM;
  ------------------
  |  |  196|      1|#define MBEDTLS_X509_FORMAT_PEM                 2
  ------------------
 1418|      1|    }
 1419|       |
 1420|      1|    if (buf_format == MBEDTLS_X509_FORMAT_DER) {
  ------------------
  |  |  195|      1|#define MBEDTLS_X509_FORMAT_DER                 1
  ------------------
  |  Branch (1420:9): [True: 0, False: 1]
  ------------------
 1421|      0|        return mbedtls_x509_crt_parse_der(chain, buf, buflen);
 1422|      0|    }
 1423|       |#else
 1424|       |    return mbedtls_x509_crt_parse_der(chain, buf, buflen);
 1425|       |#endif
 1426|       |
 1427|      1|#if defined(MBEDTLS_PEM_PARSE_C)
 1428|      1|    if (buf_format == MBEDTLS_X509_FORMAT_PEM) {
  ------------------
  |  |  196|      1|#define MBEDTLS_X509_FORMAT_PEM                 2
  ------------------
  |  Branch (1428:9): [True: 1, False: 0]
  ------------------
 1429|      1|        int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|      1|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1430|      1|        mbedtls_pem_context pem;
 1431|       |
 1432|       |        /* 1 rather than 0 since the terminating NULL byte is counted in */
 1433|      4|        while (buflen > 1) {
  ------------------
  |  Branch (1433:16): [True: 3, False: 1]
  ------------------
 1434|      3|            size_t use_len;
 1435|      3|            mbedtls_pem_init(&pem);
 1436|       |
 1437|       |            /* If we get there, we know the string is null-terminated */
 1438|      3|            ret = mbedtls_pem_read_buffer(&pem,
 1439|      3|                                          "-----BEGIN CERTIFICATE-----",
 1440|      3|                                          "-----END CERTIFICATE-----",
 1441|      3|                                          buf, NULL, 0, &use_len);
 1442|       |
 1443|      3|            if (ret == 0) {
  ------------------
  |  Branch (1443:17): [True: 3, False: 0]
  ------------------
 1444|       |                /*
 1445|       |                 * Was PEM encoded
 1446|       |                 */
 1447|      3|                buflen -= use_len;
 1448|      3|                buf += use_len;
 1449|      3|            } else if (ret == MBEDTLS_ERR_PEM_BAD_INPUT_DATA) {
  ------------------
  |  |   41|      0|#define MBEDTLS_ERR_PEM_BAD_INPUT_DATA                    -0x1480
  ------------------
  |  Branch (1449:24): [True: 0, False: 0]
  ------------------
 1450|      0|                return ret;
 1451|      0|            } else if (ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) {
  ------------------
  |  |   25|      0|#define MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT          -0x1080
  ------------------
  |  Branch (1451:24): [True: 0, False: 0]
  ------------------
 1452|      0|                mbedtls_pem_free(&pem);
 1453|       |
 1454|       |                /*
 1455|       |                 * PEM header and footer were found
 1456|       |                 */
 1457|      0|                buflen -= use_len;
 1458|      0|                buf += use_len;
 1459|       |
 1460|      0|                if (first_error == 0) {
  ------------------
  |  Branch (1460:21): [True: 0, False: 0]
  ------------------
 1461|      0|                    first_error = ret;
 1462|      0|                }
 1463|       |
 1464|      0|                total_failed++;
 1465|      0|                continue;
 1466|      0|            } else {
 1467|      0|                break;
 1468|      0|            }
 1469|       |
 1470|      3|            ret = mbedtls_x509_crt_parse_der(chain, pem.buf, pem.buflen);
 1471|       |
 1472|      3|            mbedtls_pem_free(&pem);
 1473|       |
 1474|      3|            if (ret != 0) {
  ------------------
  |  Branch (1474:17): [True: 0, False: 3]
  ------------------
 1475|       |                /*
 1476|       |                 * Quit parsing on a memory error
 1477|       |                 */
 1478|      0|                if (ret == MBEDTLS_ERR_X509_ALLOC_FAILED) {
  ------------------
  |  |   77|      0|#define MBEDTLS_ERR_X509_ALLOC_FAILED                     -0x2880
  ------------------
  |  Branch (1478:21): [True: 0, False: 0]
  ------------------
 1479|      0|                    return ret;
 1480|      0|                }
 1481|       |
 1482|      0|                if (first_error == 0) {
  ------------------
  |  Branch (1482:21): [True: 0, False: 0]
  ------------------
 1483|      0|                    first_error = ret;
 1484|      0|                }
 1485|       |
 1486|      0|                total_failed++;
 1487|      0|                continue;
 1488|      0|            }
 1489|       |
 1490|      3|            success = 1;
 1491|      3|        }
 1492|      1|    }
 1493|       |
 1494|      1|    if (success) {
  ------------------
  |  Branch (1494:9): [True: 1, False: 0]
  ------------------
 1495|      1|        return total_failed;
 1496|      1|    } else if (first_error) {
  ------------------
  |  Branch (1496:16): [True: 0, False: 0]
  ------------------
 1497|      0|        return first_error;
 1498|      0|    } else {
 1499|      0|        return MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT;
  ------------------
  |  |   73|      0|#define MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT              -0x2780
  ------------------
 1500|      0|    }
 1501|      1|#endif /* MBEDTLS_PEM_PARSE_C */
 1502|      1|}
mbedtls_x509_crt_init:
 3222|      3|{
 3223|      3|    memset(crt, 0, sizeof(mbedtls_x509_crt));
 3224|      3|}
x509_crt.c:mbedtls_x509_crt_parse_der_internal:
 1319|      3|{
 1320|      3|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|      3|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1321|      3|    mbedtls_x509_crt *crt = chain, *prev = NULL;
 1322|       |
 1323|       |    /*
 1324|       |     * Check for valid input
 1325|       |     */
 1326|      3|    if (crt == NULL || buf == NULL) {
  ------------------
  |  Branch (1326:9): [True: 0, False: 3]
  |  Branch (1326:24): [True: 0, False: 3]
  ------------------
 1327|      0|        return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
  ------------------
  |  |   75|      0|#define MBEDTLS_ERR_X509_BAD_INPUT_DATA                   -0x2800
  ------------------
 1328|      0|    }
 1329|       |
 1330|      4|    while (crt->version != 0 && crt->next != NULL) {
  ------------------
  |  Branch (1330:12): [True: 3, False: 1]
  |  Branch (1330:33): [True: 1, False: 2]
  ------------------
 1331|      1|        prev = crt;
 1332|      1|        crt = crt->next;
 1333|      1|    }
 1334|       |
 1335|       |    /*
 1336|       |     * Add new certificate on the end of the chain if needed.
 1337|       |     */
 1338|      3|    if (crt->version != 0 && crt->next == NULL) {
  ------------------
  |  Branch (1338:9): [True: 2, False: 1]
  |  Branch (1338:30): [True: 2, False: 0]
  ------------------
 1339|      2|        crt->next = mbedtls_calloc(1, sizeof(mbedtls_x509_crt));
 1340|       |
 1341|      2|        if (crt->next == NULL) {
  ------------------
  |  Branch (1341:13): [True: 0, False: 2]
  ------------------
 1342|      0|            return MBEDTLS_ERR_X509_ALLOC_FAILED;
  ------------------
  |  |   77|      0|#define MBEDTLS_ERR_X509_ALLOC_FAILED                     -0x2880
  ------------------
 1343|      0|        }
 1344|       |
 1345|      2|        prev = crt;
 1346|      2|        mbedtls_x509_crt_init(crt->next);
 1347|      2|        crt = crt->next;
 1348|      2|    }
 1349|       |
 1350|      3|    ret = x509_crt_parse_der_core(crt, buf, buflen, make_copy, cb, p_ctx);
 1351|      3|    if (ret != 0) {
  ------------------
  |  Branch (1351:9): [True: 0, False: 3]
  ------------------
 1352|      0|        if (prev) {
  ------------------
  |  Branch (1352:13): [True: 0, False: 0]
  ------------------
 1353|      0|            prev->next = NULL;
 1354|      0|        }
 1355|       |
 1356|      0|        if (crt != chain) {
  ------------------
  |  Branch (1356:13): [True: 0, False: 0]
  ------------------
 1357|      0|            mbedtls_free(crt);
 1358|      0|        }
 1359|       |
 1360|      0|        return ret;
 1361|      0|    }
 1362|       |
 1363|      3|    return 0;
 1364|      3|}
x509_crt.c:x509_crt_parse_der_core:
 1079|      3|{
 1080|      3|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|      3|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
 1081|      3|    size_t len;
 1082|      3|    unsigned char *p, *end, *crt_end;
 1083|      3|    mbedtls_x509_buf sig_params1, sig_params2, sig_oid2;
 1084|       |
 1085|      3|    memset(&sig_params1, 0, sizeof(mbedtls_x509_buf));
 1086|      3|    memset(&sig_params2, 0, sizeof(mbedtls_x509_buf));
 1087|      3|    memset(&sig_oid2, 0, sizeof(mbedtls_x509_buf));
 1088|       |
 1089|       |    /*
 1090|       |     * Check for valid input
 1091|       |     */
 1092|      3|    if (crt == NULL || buf == NULL) {
  ------------------
  |  Branch (1092:9): [True: 0, False: 3]
  |  Branch (1092:24): [True: 0, False: 3]
  ------------------
 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|      3|    p = (unsigned char *) buf;
 1098|      3|    len = buflen;
 1099|      3|    end = p + len;
 1100|       |
 1101|       |    /*
 1102|       |     * Certificate  ::=  SEQUENCE  {
 1103|       |     *      tbsCertificate       TBSCertificate,
 1104|       |     *      signatureAlgorithm   AlgorithmIdentifier,
 1105|       |     *      signatureValue       BIT STRING  }
 1106|       |     */
 1107|      3|    if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
  ------------------
  |  Branch (1107:9): [True: 0, False: 3]
  ------------------
 1108|      3|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|      3|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|      3|#define MBEDTLS_ASN1_SEQUENCE                0x10
  ------------------
 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|      3|    end = crt_end = p + len;
 1114|      3|    crt->raw.len = (size_t) (crt_end - buf);
 1115|      3|    if (make_copy != 0) {
  ------------------
  |  Branch (1115:9): [True: 3, False: 0]
  ------------------
 1116|       |        /* Create and populate a new buffer for the raw field. */
 1117|      3|        crt->raw.p = p = mbedtls_calloc(1, crt->raw.len);
 1118|      3|        if (crt->raw.p == NULL) {
  ------------------
  |  Branch (1118:13): [True: 0, False: 3]
  ------------------
 1119|      0|            return MBEDTLS_ERR_X509_ALLOC_FAILED;
  ------------------
  |  |   77|      0|#define MBEDTLS_ERR_X509_ALLOC_FAILED                     -0x2880
  ------------------
 1120|      0|        }
 1121|       |
 1122|      3|        memcpy(crt->raw.p, buf, crt->raw.len);
 1123|      3|        crt->own_buffer = 1;
 1124|       |
 1125|      3|        p += crt->raw.len - len;
 1126|      3|        end = crt_end = p + len;
 1127|      3|    } else {
 1128|      0|        crt->raw.p = (unsigned char *) buf;
 1129|      0|        crt->own_buffer = 0;
 1130|      0|    }
 1131|       |
 1132|       |    /*
 1133|       |     * TBSCertificate  ::=  SEQUENCE  {
 1134|       |     */
 1135|      3|    crt->tbs.p = p;
 1136|       |
 1137|      3|    if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
  ------------------
  |  Branch (1137:9): [True: 0, False: 3]
  ------------------
 1138|      3|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|      3|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|      3|#define MBEDTLS_ASN1_SEQUENCE                0x10
  ------------------
 1139|      0|        mbedtls_x509_crt_free(crt);
 1140|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_FORMAT, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
 1141|      0|    }
 1142|       |
 1143|      3|    end = p + len;
 1144|      3|    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|      3|    if ((ret = x509_get_version(&p, end, &crt->version)) != 0 ||
  ------------------
  |  Branch (1153:9): [True: 0, False: 3]
  ------------------
 1154|      3|        (ret = mbedtls_x509_get_serial(&p, end, &crt->serial)) != 0 ||
  ------------------
  |  Branch (1154:9): [True: 0, False: 3]
  ------------------
 1155|      3|        (ret = mbedtls_x509_get_alg(&p, end, &crt->sig_oid,
  ------------------
  |  Branch (1155:9): [True: 0, False: 3]
  ------------------
 1156|      3|                                    &sig_params1)) != 0) {
 1157|      0|        mbedtls_x509_crt_free(crt);
 1158|      0|        return ret;
 1159|      0|    }
 1160|       |
 1161|      3|    if (crt->version < 0 || crt->version > 2) {
  ------------------
  |  Branch (1161:9): [True: 0, False: 3]
  |  Branch (1161:29): [True: 0, False: 3]
  ------------------
 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|      3|    crt->version++;
 1167|       |
 1168|      3|    if ((ret = mbedtls_x509_get_sig_alg(&crt->sig_oid, &sig_params1,
  ------------------
  |  Branch (1168:9): [True: 0, False: 3]
  ------------------
 1169|      3|                                        &crt->sig_md, &crt->sig_pk,
 1170|      3|                                        &crt->sig_opts)) != 0) {
 1171|      0|        mbedtls_x509_crt_free(crt);
 1172|      0|        return ret;
 1173|      0|    }
 1174|       |
 1175|       |    /*
 1176|       |     * issuer               Name
 1177|       |     */
 1178|      3|    crt->issuer_raw.p = p;
 1179|       |
 1180|      3|    if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
  ------------------
  |  Branch (1180:9): [True: 0, False: 3]
  ------------------
 1181|      3|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|      3|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|      3|#define MBEDTLS_ASN1_SEQUENCE                0x10
  ------------------
 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|      3|    if ((ret = mbedtls_x509_get_name(&p, p + len, &crt->issuer)) != 0) {
  ------------------
  |  Branch (1186:9): [True: 0, False: 3]
  ------------------
 1187|      0|        mbedtls_x509_crt_free(crt);
 1188|      0|        return ret;
 1189|      0|    }
 1190|       |
 1191|      3|    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|      3|    if ((ret = x509_get_dates(&p, end, &crt->valid_from,
  ------------------
  |  Branch (1199:9): [True: 0, False: 3]
  ------------------
 1200|      3|                              &crt->valid_to)) != 0) {
 1201|      0|        mbedtls_x509_crt_free(crt);
 1202|      0|        return ret;
 1203|      0|    }
 1204|       |
 1205|       |    /*
 1206|       |     * subject              Name
 1207|       |     */
 1208|      3|    crt->subject_raw.p = p;
 1209|       |
 1210|      3|    if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
  ------------------
  |  Branch (1210:9): [True: 0, False: 3]
  ------------------
 1211|      3|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|      3|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|      3|#define MBEDTLS_ASN1_SEQUENCE                0x10
  ------------------
 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|      3|    if (len && (ret = mbedtls_x509_get_name(&p, p + len, &crt->subject)) != 0) {
  ------------------
  |  Branch (1216:9): [True: 3, False: 0]
  |  Branch (1216:16): [True: 0, False: 3]
  ------------------
 1217|      0|        mbedtls_x509_crt_free(crt);
 1218|      0|        return ret;
 1219|      0|    }
 1220|       |
 1221|      3|    crt->subject_raw.len = (size_t) (p - crt->subject_raw.p);
 1222|       |
 1223|       |    /*
 1224|       |     * SubjectPublicKeyInfo
 1225|       |     */
 1226|      3|    crt->pk_raw.p = p;
 1227|      3|    if ((ret = mbedtls_pk_parse_subpubkey(&p, end, &crt->pk)) != 0) {
  ------------------
  |  Branch (1227:9): [True: 0, False: 3]
  ------------------
 1228|      0|        mbedtls_x509_crt_free(crt);
 1229|      0|        return ret;
 1230|      0|    }
 1231|      3|    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|      3|    if (crt->version == 2 || crt->version == 3) {
  ------------------
  |  Branch (1241:9): [True: 0, False: 3]
  |  Branch (1241:30): [True: 3, False: 0]
  ------------------
 1242|      3|        ret = x509_get_uid(&p, end, &crt->issuer_id,  1);
 1243|      3|        if (ret != 0) {
  ------------------
  |  Branch (1243:13): [True: 0, False: 3]
  ------------------
 1244|      0|            mbedtls_x509_crt_free(crt);
 1245|      0|            return ret;
 1246|      0|        }
 1247|      3|    }
 1248|       |
 1249|      3|    if (crt->version == 2 || crt->version == 3) {
  ------------------
  |  Branch (1249:9): [True: 0, False: 3]
  |  Branch (1249:30): [True: 3, False: 0]
  ------------------
 1250|      3|        ret = x509_get_uid(&p, end, &crt->subject_id,  2);
 1251|      3|        if (ret != 0) {
  ------------------
  |  Branch (1251:13): [True: 0, False: 3]
  ------------------
 1252|      0|            mbedtls_x509_crt_free(crt);
 1253|      0|            return ret;
 1254|      0|        }
 1255|      3|    }
 1256|       |
 1257|      3|    if (crt->version == 3) {
  ------------------
  |  Branch (1257:9): [True: 3, False: 0]
  ------------------
 1258|      3|        ret = x509_get_crt_ext(&p, end, crt, cb, p_ctx);
 1259|      3|        if (ret != 0) {
  ------------------
  |  Branch (1259:13): [True: 0, False: 3]
  ------------------
 1260|      0|            mbedtls_x509_crt_free(crt);
 1261|      0|            return ret;
 1262|      0|        }
 1263|      3|    }
 1264|       |
 1265|      3|    if (p != end) {
  ------------------
  |  Branch (1265:9): [True: 0, False: 3]
  ------------------
 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|      3|    end = crt_end;
 1272|       |
 1273|       |    /*
 1274|       |     *  }
 1275|       |     *  -- end of TBSCertificate
 1276|       |     *
 1277|       |     *  signatureAlgorithm   AlgorithmIdentifier,
 1278|       |     *  signatureValue       BIT STRING
 1279|       |     */
 1280|      3|    if ((ret = mbedtls_x509_get_alg(&p, end, &sig_oid2, &sig_params2)) != 0) {
  ------------------
  |  Branch (1280:9): [True: 0, False: 3]
  ------------------
 1281|      0|        mbedtls_x509_crt_free(crt);
 1282|      0|        return ret;
 1283|      0|    }
 1284|       |
 1285|      3|    if (crt->sig_oid.len != sig_oid2.len ||
  ------------------
  |  Branch (1285:9): [True: 0, False: 3]
  ------------------
 1286|      3|        memcmp(crt->sig_oid.p, sig_oid2.p, crt->sig_oid.len) != 0 ||
  ------------------
  |  Branch (1286:9): [True: 0, False: 3]
  ------------------
 1287|      3|        sig_params1.tag != sig_params2.tag ||
  ------------------
  |  Branch (1287:9): [True: 0, False: 3]
  ------------------
 1288|      3|        sig_params1.len != sig_params2.len ||
  ------------------
  |  Branch (1288:9): [True: 0, False: 3]
  ------------------
 1289|      3|        (sig_params1.len != 0 &&
  ------------------
  |  Branch (1289:10): [True: 0, False: 3]
  ------------------
 1290|      3|         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|      3|    if ((ret = mbedtls_x509_get_sig(&p, end, &crt->sig)) != 0) {
  ------------------
  |  Branch (1295:9): [True: 0, False: 3]
  ------------------
 1296|      0|        mbedtls_x509_crt_free(crt);
 1297|      0|        return ret;
 1298|      0|    }
 1299|       |
 1300|      3|    if (p != end) {
  ------------------
  |  Branch (1300:9): [True: 0, False: 3]
  ------------------
 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|      3|    return 0;
 1307|      3|}
x509_crt.c:x509_get_version:
  398|      3|{
  399|      3|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|      3|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  400|      3|    size_t len;
  401|       |
  402|      3|    if ((ret = mbedtls_asn1_get_tag(p, end, &len,
  ------------------
  |  Branch (402:9): [True: 0, False: 3]
  ------------------
  403|      3|                                    MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED |
  ------------------
  |  |   83|      3|#define MBEDTLS_ASN1_CONTEXT_SPECIFIC        0x80
  ------------------
                                                  MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED |
  ------------------
  |  |   82|      3|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
  404|      3|                                    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|      3|    end = *p + len;
  414|       |
  415|      3|    if ((ret = mbedtls_asn1_get_int(p, end, ver)) != 0) {
  ------------------
  |  Branch (415:9): [True: 0, False: 3]
  ------------------
  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|      3|    if (*p != end) {
  ------------------
  |  Branch (419:9): [True: 0, False: 3]
  ------------------
  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|      3|    return 0;
  425|      3|}
x509_crt.c:x509_get_dates:
  436|      3|{
  437|      3|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|      3|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  438|      3|    size_t len;
  439|       |
  440|      3|    if ((ret = mbedtls_asn1_get_tag(p, end, &len,
  ------------------
  |  Branch (440:9): [True: 0, False: 3]
  ------------------
  441|      3|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|      3|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|      3|#define MBEDTLS_ASN1_SEQUENCE                0x10
  ------------------
  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|      3|    end = *p + len;
  446|       |
  447|      3|    if ((ret = mbedtls_x509_get_time(p, end, from)) != 0) {
  ------------------
  |  Branch (447:9): [True: 0, False: 3]
  ------------------
  448|      0|        return ret;
  449|      0|    }
  450|       |
  451|      3|    if ((ret = mbedtls_x509_get_time(p, end, to)) != 0) {
  ------------------
  |  Branch (451:9): [True: 0, False: 3]
  ------------------
  452|      0|        return ret;
  453|      0|    }
  454|       |
  455|      3|    if (*p != end) {
  ------------------
  |  Branch (455:9): [True: 0, False: 3]
  ------------------
  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|      3|    return 0;
  461|      3|}
x509_crt.c:x509_get_uid:
  469|      6|{
  470|      6|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|      6|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  471|       |
  472|      6|    if (*p == end) {
  ------------------
  |  Branch (472:9): [True: 0, False: 6]
  ------------------
  473|      0|        return 0;
  474|      0|    }
  475|       |
  476|      6|    uid->tag = **p;
  477|       |
  478|      6|    if ((ret = mbedtls_asn1_get_tag(p, end, &uid->len,
  ------------------
  |  Branch (478:9): [True: 6, False: 0]
  ------------------
  479|      6|                                    MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED |
  ------------------
  |  |   83|      6|#define MBEDTLS_ASN1_CONTEXT_SPECIFIC        0x80
  ------------------
                                                  MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED |
  ------------------
  |  |   82|      6|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
  480|      6|                                    n)) != 0) {
  481|      6|        if (ret == MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) {
  ------------------
  |  |   39|      6|#define MBEDTLS_ERR_ASN1_UNEXPECTED_TAG                   -0x0062
  ------------------
  |  Branch (481:13): [True: 6, False: 0]
  ------------------
  482|      6|            return 0;
  483|      6|        }
  484|       |
  485|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_FORMAT, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  486|      6|    }
  487|       |
  488|      0|    uid->p = *p;
  489|      0|    *p += uid->len;
  490|       |
  491|      0|    return 0;
  492|      6|}
x509_crt.c:x509_get_crt_ext:
  867|      3|{
  868|      3|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|      3|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  869|      3|    size_t len;
  870|      3|    unsigned char *end_ext_data, *start_ext_octet, *end_ext_octet;
  871|       |
  872|      3|    if (*p == end) {
  ------------------
  |  Branch (872:9): [True: 0, False: 3]
  ------------------
  873|      0|        return 0;
  874|      0|    }
  875|       |
  876|      3|    if ((ret = mbedtls_x509_get_ext(p, end, &crt->v3_ext, 3)) != 0) {
  ------------------
  |  Branch (876:9): [True: 0, False: 3]
  ------------------
  877|      0|        return ret;
  878|      0|    }
  879|       |
  880|      3|    end = crt->v3_ext.p + crt->v3_ext.len;
  881|     12|    while (*p < end) {
  ------------------
  |  Branch (881:12): [True: 9, False: 3]
  ------------------
  882|       |        /*
  883|       |         * Extension  ::=  SEQUENCE  {
  884|       |         *      extnID      OBJECT IDENTIFIER,
  885|       |         *      critical    BOOLEAN DEFAULT FALSE,
  886|       |         *      extnValue   OCTET STRING  }
  887|       |         */
  888|      9|        mbedtls_x509_buf extn_oid = { 0, 0, NULL };
  889|      9|        int is_critical = 0; /* DEFAULT FALSE */
  890|      9|        int ext_type = 0;
  891|       |
  892|      9|        if ((ret = mbedtls_asn1_get_tag(p, end, &len,
  ------------------
  |  Branch (892:13): [True: 0, False: 9]
  ------------------
  893|      9|                                        MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|      9|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                      MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|      9|#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|      9|        end_ext_data = *p + len;
  898|       |
  899|       |        /* Get extension ID */
  900|      9|        if ((ret = mbedtls_asn1_get_tag(p, end_ext_data, &extn_oid.len,
  ------------------
  |  Branch (900:13): [True: 0, False: 9]
  ------------------
  901|      9|                                        MBEDTLS_ASN1_OID)) != 0) {
  ------------------
  |  |   69|      9|#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|      9|        extn_oid.tag = MBEDTLS_ASN1_OID;
  ------------------
  |  |   69|      9|#define MBEDTLS_ASN1_OID                     0x06
  ------------------
  906|      9|        extn_oid.p = *p;
  907|      9|        *p += extn_oid.len;
  908|       |
  909|       |        /* Get optional critical */
  910|      9|        if ((ret = mbedtls_asn1_get_bool(p, end_ext_data, &is_critical)) != 0 &&
  ------------------
  |  Branch (910:13): [True: 8, False: 1]
  ------------------
  911|      9|            (ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG)) {
  ------------------
  |  |   39|      8|#define MBEDTLS_ERR_ASN1_UNEXPECTED_TAG                   -0x0062
  ------------------
  |  Branch (911:13): [True: 0, False: 8]
  ------------------
  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|      9|        if ((ret = mbedtls_asn1_get_tag(p, end_ext_data, &len,
  ------------------
  |  Branch (916:13): [True: 0, False: 9]
  ------------------
  917|      9|                                        MBEDTLS_ASN1_OCTET_STRING)) != 0) {
  ------------------
  |  |   67|      9|#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|      9|        start_ext_octet = *p;
  922|      9|        end_ext_octet = *p + len;
  923|       |
  924|      9|        if (end_ext_octet != end_ext_data) {
  ------------------
  |  Branch (924:13): [True: 0, False: 9]
  ------------------
  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|      9|        ret = mbedtls_oid_get_x509_ext_type(&extn_oid, &ext_type);
  933|       |
  934|      9|        if (ret != 0) {
  ------------------
  |  Branch (934:13): [True: 0, False: 9]
  ------------------
  935|       |            /* Give the callback (if any) a chance to handle the extension */
  936|      0|            if (cb != NULL) {
  ------------------
  |  Branch (936:17): [True: 0, False: 0]
  ------------------
  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|      0|            *p = end_ext_octet;
  947|       |
  948|      0|            if (is_critical) {
  ------------------
  |  Branch (948:17): [True: 0, False: 0]
  ------------------
  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|      0|            continue;
  954|      0|        }
  955|       |
  956|       |        /* Forbid repeated extensions */
  957|      9|        if ((crt->ext_types & ext_type) != 0) {
  ------------------
  |  Branch (957:13): [True: 0, False: 9]
  ------------------
  958|      0|            return MBEDTLS_ERR_X509_INVALID_EXTENSIONS;
  ------------------
  |  |   63|      0|#define MBEDTLS_ERR_X509_INVALID_EXTENSIONS               -0x2500
  ------------------
  959|      0|        }
  960|       |
  961|      9|        crt->ext_types |= ext_type;
  962|       |
  963|      9|        switch (ext_type) {
  964|      3|            case MBEDTLS_X509_EXT_BASIC_CONSTRAINTS:
  ------------------
  |  |  182|      3|#define MBEDTLS_X509_EXT_BASIC_CONSTRAINTS        MBEDTLS_OID_X509_EXT_BASIC_CONSTRAINTS        /* Supported */
  |  |  ------------------
  |  |  |  |   45|      3|#define MBEDTLS_OID_X509_EXT_BASIC_CONSTRAINTS           (1 << 8)
  |  |  ------------------
  ------------------
  |  Branch (964:13): [True: 3, False: 6]
  ------------------
  965|       |                /* Parse basic constraints */
  966|      3|                if ((ret = x509_get_basic_constraints(p, end_ext_octet,
  ------------------
  |  Branch (966:21): [True: 0, False: 3]
  ------------------
  967|      3|                                                      &crt->ca_istrue, &crt->max_pathlen)) != 0) {
  968|      0|                    return ret;
  969|      0|                }
  970|      3|                break;
  971|       |
  972|      3|            case MBEDTLS_X509_EXT_KEY_USAGE:
  ------------------
  |  |  176|      0|#define MBEDTLS_X509_EXT_KEY_USAGE                MBEDTLS_OID_X509_EXT_KEY_USAGE
  |  |  ------------------
  |  |  |  |   39|      0|#define MBEDTLS_OID_X509_EXT_KEY_USAGE                   (1 << 2)
  |  |  ------------------
  ------------------
  |  Branch (972:13): [True: 0, False: 9]
  ------------------
  973|       |                /* Parse key usage */
  974|      0|                if ((ret = mbedtls_x509_get_key_usage(p, end_ext_octet,
  ------------------
  |  Branch (974:21): [True: 0, False: 0]
  ------------------
  975|      0|                                                      &crt->key_usage)) != 0) {
  976|      0|                    return ret;
  977|      0|                }
  978|      0|                break;
  979|       |
  980|      0|            case MBEDTLS_X509_EXT_EXTENDED_KEY_USAGE:
  ------------------
  |  |  185|      0|#define MBEDTLS_X509_EXT_EXTENDED_KEY_USAGE       MBEDTLS_OID_X509_EXT_EXTENDED_KEY_USAGE
  |  |  ------------------
  |  |  |  |   48|      0|#define MBEDTLS_OID_X509_EXT_EXTENDED_KEY_USAGE          (1 << 11)
  |  |  ------------------
  ------------------
  |  Branch (980:13): [True: 0, False: 9]
  ------------------
  981|       |                /* Parse extended key usage */
  982|      0|                if ((ret = x509_get_ext_key_usage(p, end_ext_octet,
  ------------------
  |  Branch (982:21): [True: 0, False: 0]
  ------------------
  983|      0|                                                  &crt->ext_key_usage)) != 0) {
  984|      0|                    return ret;
  985|      0|                }
  986|      0|                break;
  987|       |
  988|      3|            case MBEDTLS_X509_EXT_SUBJECT_KEY_IDENTIFIER:
  ------------------
  |  |  175|      3|#define MBEDTLS_X509_EXT_SUBJECT_KEY_IDENTIFIER   MBEDTLS_OID_X509_EXT_SUBJECT_KEY_IDENTIFIER
  |  |  ------------------
  |  |  |  |   38|      3|#define MBEDTLS_OID_X509_EXT_SUBJECT_KEY_IDENTIFIER      (1 << 1)
  |  |  ------------------
  ------------------
  |  Branch (988:13): [True: 3, False: 6]
  ------------------
  989|       |                /* Parse subject key identifier */
  990|      3|                if ((ret = x509_get_subject_key_id(p, end_ext_data,
  ------------------
  |  Branch (990:21): [True: 0, False: 3]
  ------------------
  991|      3|                                                   &crt->subject_key_id)) != 0) {
  992|      0|                    return ret;
  993|      0|                }
  994|      3|                break;
  995|       |
  996|      3|            case MBEDTLS_X509_EXT_AUTHORITY_KEY_IDENTIFIER:
  ------------------
  |  |  174|      3|#define MBEDTLS_X509_EXT_AUTHORITY_KEY_IDENTIFIER MBEDTLS_OID_X509_EXT_AUTHORITY_KEY_IDENTIFIER
  |  |  ------------------
  |  |  |  |   37|      3|#define MBEDTLS_OID_X509_EXT_AUTHORITY_KEY_IDENTIFIER    (1 << 0)
  |  |  ------------------
  ------------------
  |  Branch (996:13): [True: 3, False: 6]
  ------------------
  997|       |                /* Parse authority key identifier */
  998|      3|                if ((ret = x509_get_authority_key_id(p, end_ext_octet,
  ------------------
  |  Branch (998:21): [True: 0, False: 3]
  ------------------
  999|      3|                                                     &crt->authority_key_id)) != 0) {
 1000|      0|                    return ret;
 1001|      0|                }
 1002|      3|                break;
 1003|      3|            case MBEDTLS_X509_EXT_SUBJECT_ALT_NAME:
  ------------------
  |  |  179|      0|#define MBEDTLS_X509_EXT_SUBJECT_ALT_NAME         MBEDTLS_OID_X509_EXT_SUBJECT_ALT_NAME         /* Supported (DNS) */
  |  |  ------------------
  |  |  |  |   42|      0|#define MBEDTLS_OID_X509_EXT_SUBJECT_ALT_NAME            (1 << 5)
  |  |  ------------------
  ------------------
  |  Branch (1003:13): [True: 0, False: 9]
  ------------------
 1004|       |                /* Parse subject alt name
 1005|       |                 * SubjectAltName ::= GeneralNames
 1006|       |                 */
 1007|      0|                if ((ret = mbedtls_x509_get_subject_alt_name(p, end_ext_octet,
  ------------------
  |  Branch (1007:21): [True: 0, False: 0]
  ------------------
 1008|      0|                                                             &crt->subject_alt_names)) != 0) {
 1009|      0|                    return ret;
 1010|      0|                }
 1011|      0|                break;
 1012|       |
 1013|      0|            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: 9]
  ------------------
 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: 9]
  ------------------
 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: 9]
  ------------------
 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|      9|        }
 1060|      9|    }
 1061|       |
 1062|      3|    if (*p != end) {
  ------------------
  |  Branch (1062:9): [True: 0, False: 3]
  ------------------
 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|      3|    return 0;
 1068|      3|}
x509_crt.c:x509_get_basic_constraints:
  498|      3|{
  499|      3|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|      3|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  500|      3|    size_t len;
  501|       |
  502|       |    /*
  503|       |     * BasicConstraints ::= SEQUENCE {
  504|       |     *      cA                      BOOLEAN DEFAULT FALSE,
  505|       |     *      pathLenConstraint       INTEGER (0..MAX) OPTIONAL }
  506|       |     */
  507|      3|    *ca_istrue = 0; /* DEFAULT FALSE */
  508|      3|    *max_pathlen = 0; /* endless */
  509|       |
  510|      3|    if ((ret = mbedtls_asn1_get_tag(p, end, &len,
  ------------------
  |  Branch (510:9): [True: 0, False: 3]
  ------------------
  511|      3|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|      3|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|      3|#define MBEDTLS_ASN1_SEQUENCE                0x10
  ------------------
  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|      3|    if (*p == end) {
  ------------------
  |  Branch (515:9): [True: 0, False: 3]
  ------------------
  516|      0|        return 0;
  517|      0|    }
  518|       |
  519|      3|    if ((ret = mbedtls_asn1_get_bool(p, end, ca_istrue)) != 0) {
  ------------------
  |  Branch (519:9): [True: 0, False: 3]
  ------------------
  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|      3|    if (*p == end) {
  ------------------
  |  Branch (533:9): [True: 3, False: 0]
  ------------------
  534|      3|        return 0;
  535|      3|    }
  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_subject_key_id:
  590|      3|{
  591|      3|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|      3|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  592|      3|    size_t len = 0u;
  593|       |
  594|      3|    if ((ret = mbedtls_asn1_get_tag(p, end, &len,
  ------------------
  |  Branch (594:9): [True: 0, False: 3]
  ------------------
  595|      3|                                    MBEDTLS_ASN1_OCTET_STRING)) != 0) {
  ------------------
  |  |   67|      3|#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|      3|    subject_key_id->len = len;
  600|      3|    subject_key_id->tag = MBEDTLS_ASN1_OCTET_STRING;
  ------------------
  |  |   67|      3|#define MBEDTLS_ASN1_OCTET_STRING            0x04
  ------------------
  601|      3|    subject_key_id->p = *p;
  602|      3|    *p += len;
  603|       |
  604|      3|    if (*p != end) {
  ------------------
  |  Branch (604:9): [True: 0, False: 3]
  ------------------
  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|      3|    return 0;
  610|      3|}
x509_crt.c:x509_get_authority_key_id:
  623|      3|{
  624|      3|    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
  ------------------
  |  |  100|      3|#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
  ------------------
  625|      3|    size_t len = 0u;
  626|       |
  627|      3|    if ((ret = mbedtls_asn1_get_tag(p, end, &len,
  ------------------
  |  Branch (627:9): [True: 0, False: 3]
  ------------------
  628|      3|                                    MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   82|      3|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
                                                  MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
  ------------------
  |  |   72|      3|#define MBEDTLS_ASN1_SEQUENCE                0x10
  ------------------
  629|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  630|      0|    }
  631|       |
  632|      3|    if (*p + len != end) {
  ------------------
  |  Branch (632:9): [True: 0, False: 3]
  ------------------
  633|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  634|      0|                                 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
  635|      0|    }
  636|       |
  637|      3|    ret = mbedtls_asn1_get_tag(p, end, &len,
  638|      3|                               MBEDTLS_ASN1_CONTEXT_SPECIFIC);
  ------------------
  |  |   83|      3|#define MBEDTLS_ASN1_CONTEXT_SPECIFIC        0x80
  ------------------
  639|       |
  640|       |    /* KeyIdentifier is an OPTIONAL field */
  641|      3|    if (ret == 0) {
  ------------------
  |  Branch (641:9): [True: 3, False: 0]
  ------------------
  642|      3|        authority_key_id->keyIdentifier.len = len;
  643|      3|        authority_key_id->keyIdentifier.p = *p;
  644|       |        /* Setting tag of the keyIdentfier intentionally to 0x04.
  645|       |         * Although the .keyIdentfier field is CONTEXT_SPECIFIC ([0] OPTIONAL),
  646|       |         * its tag with the content is the payload of on OCTET STRING primitive */
  647|      3|        authority_key_id->keyIdentifier.tag = MBEDTLS_ASN1_OCTET_STRING;
  ------------------
  |  |   67|      3|#define MBEDTLS_ASN1_OCTET_STRING            0x04
  ------------------
  648|       |
  649|      3|        *p += len;
  650|      3|    } else if (ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) {
  ------------------
  |  |   39|      0|#define MBEDTLS_ERR_ASN1_UNEXPECTED_TAG                   -0x0062
  ------------------
  |  Branch (650:16): [True: 0, False: 0]
  ------------------
  651|      0|        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  652|      0|    }
  653|       |
  654|      3|    if (*p < end) {
  ------------------
  |  Branch (654:9): [True: 0, False: 3]
  ------------------
  655|       |        /* Getting authorityCertIssuer using the required specific class tag [1] */
  656|      0|        if ((ret = mbedtls_asn1_get_tag(p, end, &len,
  ------------------
  |  Branch (656:13): [True: 0, False: 0]
  ------------------
  657|      0|                                        MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED |
  ------------------
  |  |   83|      0|#define MBEDTLS_ASN1_CONTEXT_SPECIFIC        0x80
  ------------------
                                                      MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED |
  ------------------
  |  |   82|      0|#define MBEDTLS_ASN1_CONSTRUCTED             0x20
  ------------------
  658|      0|                                        1)) != 0) {
  659|       |            /* authorityCertIssuer and authorityCertSerialNumber MUST both
  660|       |               be present or both be absent. At this point we expect to have both. */
  661|      0|            return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  662|      0|        }
  663|       |        /* "end" also includes the CertSerialNumber field so "len" shall be used */
  664|      0|        ret = mbedtls_x509_get_subject_alt_name_ext(p,
  665|      0|                                                    (*p+len),
  666|      0|                                                    &authority_key_id->authorityCertIssuer);
  667|      0|        if (ret != 0) {
  ------------------
  |  Branch (667:13): [True: 0, False: 0]
  ------------------
  668|      0|            return ret;
  669|      0|        }
  670|       |
  671|       |        /* Getting authorityCertSerialNumber using the required specific class tag [2] */
  672|      0|        if ((ret = mbedtls_asn1_get_tag(p, end, &len,
  ------------------
  |  Branch (672:13): [True: 0, False: 0]
  ------------------
  673|      0|                                        MBEDTLS_ASN1_CONTEXT_SPECIFIC | 2)) != 0) {
  ------------------
  |  |   83|      0|#define MBEDTLS_ASN1_CONTEXT_SPECIFIC        0x80
  ------------------
  674|      0|            return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret);
  ------------------
  |  |  114|      0|    mbedtls_error_add(high, low, __FILE__, __LINE__)
  ------------------
  675|      0|        }
  676|      0|        authority_key_id->authorityCertSerialNumber.len = len;
  677|      0|        authority_key_id->authorityCertSerialNumber.p = *p;
  678|      0|        authority_key_id->authorityCertSerialNumber.tag = MBEDTLS_ASN1_INTEGER;
  ------------------
  |  |   65|      0|#define MBEDTLS_ASN1_INTEGER                 0x02
  ------------------
  679|      0|        *p += len;
  680|      0|    }
  681|       |
  682|      3|    if (*p != end) {
  ------------------
  |  Branch (682:9): [True: 0, False: 3]
  ------------------
  683|      0|        return MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
  ------------------
  |  |   63|      0|#define MBEDTLS_ERR_X509_INVALID_EXTENSIONS               -0x2500
  ------------------
  684|      0|               MBEDTLS_ERR_ASN1_LENGTH_MISMATCH;
  ------------------
  |  |   43|      0|#define MBEDTLS_ERR_ASN1_LENGTH_MISMATCH                  -0x0066
  ------------------
  685|      0|    }
  686|       |
  687|      3|    return 0;
  688|      3|}

dummy_init:
   17|      1|{
   18|      1|#if defined(MBEDTLS_PLATFORM_TIME_ALT)
   19|      1|    mbedtls_platform_set_time(dummy_constant_time);
   20|       |#else
   21|       |    fprintf(stderr, "Warning: fuzzing without constant time\n");
   22|       |#endif
   23|      1|}

LLVMFuzzerTestOneInput:
   34|     23|{
   35|     23|#if defined(MBEDTLS_SSL_CLI_C) && \
   36|     23|    defined(MBEDTLS_ENTROPY_C) && \
   37|     23|    defined(MBEDTLS_CTR_DRBG_C)
   38|     23|    int ret;
   39|     23|    size_t len;
   40|     23|    mbedtls_ssl_context ssl;
   41|     23|    mbedtls_ssl_config conf;
   42|     23|    mbedtls_ctr_drbg_context ctr_drbg;
   43|     23|    mbedtls_entropy_context entropy;
   44|     23|    unsigned char buf[4096];
   45|     23|    fuzzBufferOffset_t biomemfuzz;
   46|     23|    uint16_t options;
   47|       |
   48|     23|    if (initialized == 0) {
  ------------------
  |  Branch (48:9): [True: 1, False: 22]
  ------------------
   49|      1|#if defined(MBEDTLS_X509_CRT_PARSE_C) && defined(MBEDTLS_PEM_PARSE_C)
   50|      1|        mbedtls_x509_crt_init(&cacert);
   51|      1|        if (mbedtls_x509_crt_parse(&cacert, (const unsigned char *) mbedtls_test_cas_pem,
  ------------------
  |  Branch (51:13): [True: 0, False: 1]
  ------------------
   52|      1|                                   mbedtls_test_cas_pem_len) != 0) {
   53|      0|            return 1;
   54|      0|        }
   55|      1|#endif
   56|       |
   57|      1|        alpn_list[0] = "HTTP";
   58|      1|        alpn_list[1] = "fuzzalpn";
   59|      1|        alpn_list[2] = NULL;
   60|       |
   61|      1|        dummy_init();
   62|       |
   63|      1|        initialized = 1;
   64|      1|    }
   65|       |
   66|       |    //we take 1 byte as options input
   67|     23|    if (Size < 2) {
  ------------------
  |  Branch (67:9): [True: 2, False: 21]
  ------------------
   68|      2|        return 0;
   69|      2|    }
   70|     21|    options = (Data[Size - 2] << 8) | Data[Size - 1];
   71|       |    //Avoid warnings if compile options imply no options
   72|     21|    (void) options;
   73|       |
   74|     21|    mbedtls_ssl_init(&ssl);
   75|     21|    mbedtls_ssl_config_init(&conf);
   76|     21|    mbedtls_ctr_drbg_init(&ctr_drbg);
   77|     21|    mbedtls_entropy_init(&entropy);
   78|       |
   79|     21|#if defined(MBEDTLS_USE_PSA_CRYPTO)
   80|     21|    psa_status_t status = psa_crypto_init();
   81|     21|    if (status != PSA_SUCCESS) {
  ------------------
  |  |   57|     21|#define PSA_SUCCESS ((psa_status_t)0)
  ------------------
  |  Branch (81:9): [True: 21, False: 0]
  ------------------
   82|     21|        goto exit;
   83|     21|    }
   84|      0|#endif /* MBEDTLS_USE_PSA_CRYPTO */
   85|       |
   86|      0|    if (mbedtls_ctr_drbg_seed(&ctr_drbg, dummy_entropy, &entropy,
  ------------------
  |  Branch (86:9): [True: 0, False: 0]
  ------------------
   87|      0|                              (const unsigned char *) pers, strlen(pers)) != 0) {
   88|      0|        goto exit;
   89|      0|    }
   90|       |
   91|      0|    if (mbedtls_ssl_config_defaults(&conf,
  ------------------
  |  Branch (91:9): [True: 0, False: 0]
  ------------------
   92|      0|                                    MBEDTLS_SSL_IS_CLIENT,
  ------------------
  |  |  282|      0|#define MBEDTLS_SSL_IS_CLIENT                   0
  ------------------
   93|      0|                                    MBEDTLS_SSL_TRANSPORT_STREAM,
  ------------------
  |  |  265|      0|#define MBEDTLS_SSL_TRANSPORT_STREAM            0   /*!< TLS      */
  ------------------
   94|      0|                                    MBEDTLS_SSL_PRESET_DEFAULT) != 0) {
  ------------------
  |  |  327|      0|#define MBEDTLS_SSL_PRESET_DEFAULT              0
  ------------------
   95|      0|        goto exit;
   96|      0|    }
   97|       |
   98|      0|#if defined(MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED)
   99|      0|    if (options & 2) {
  ------------------
  |  Branch (99:9): [True: 0, False: 0]
  ------------------
  100|      0|        mbedtls_ssl_conf_psk(&conf, psk, sizeof(psk),
  101|      0|                             (const unsigned char *) psk_id, sizeof(psk_id) - 1);
  102|      0|    }
  103|      0|#endif
  104|       |
  105|      0|#if defined(MBEDTLS_X509_CRT_PARSE_C) && defined(MBEDTLS_PEM_PARSE_C)
  106|      0|    if (options & 4) {
  ------------------
  |  Branch (106:9): [True: 0, False: 0]
  ------------------
  107|      0|        mbedtls_ssl_conf_ca_chain(&conf, &cacert, NULL);
  108|      0|        mbedtls_ssl_conf_authmode(&conf, MBEDTLS_SSL_VERIFY_REQUIRED);
  ------------------
  |  |  298|      0|#define MBEDTLS_SSL_VERIFY_REQUIRED             2
  ------------------
  109|      0|    } else
  110|      0|#endif
  111|      0|    {
  112|      0|        mbedtls_ssl_conf_authmode(&conf, MBEDTLS_SSL_VERIFY_NONE);
  ------------------
  |  |  296|      0|#define MBEDTLS_SSL_VERIFY_NONE                 0
  ------------------
  113|      0|    }
  114|      0|#if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
  115|      0|    mbedtls_ssl_conf_extended_master_secret(&conf,
  116|      0|                                            (options &
  ------------------
  |  Branch (116:45): [True: 0, False: 0]
  ------------------
  117|      0|                                             0x10) ? MBEDTLS_SSL_EXTENDED_MS_DISABLED : MBEDTLS_SSL_EXTENDED_MS_ENABLED);
  ------------------
  |  |  285|      0|#define MBEDTLS_SSL_EXTENDED_MS_DISABLED        0
  ------------------
                                                           0x10) ? MBEDTLS_SSL_EXTENDED_MS_DISABLED : MBEDTLS_SSL_EXTENDED_MS_ENABLED);
  ------------------
  |  |  286|      0|#define MBEDTLS_SSL_EXTENDED_MS_ENABLED         1
  ------------------
  118|      0|#endif
  119|      0|#if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
  120|      0|    mbedtls_ssl_conf_encrypt_then_mac(&conf,
  121|      0|                                      (options &
  ------------------
  |  Branch (121:39): [True: 0, False: 0]
  ------------------
  122|      0|                                       0x20) ? MBEDTLS_SSL_ETM_DISABLED : MBEDTLS_SSL_ETM_ENABLED);
  ------------------
  |  |  291|      0|#define MBEDTLS_SSL_ETM_DISABLED                0
  ------------------
                                                     0x20) ? MBEDTLS_SSL_ETM_DISABLED : MBEDTLS_SSL_ETM_ENABLED);
  ------------------
  |  |  292|      0|#define MBEDTLS_SSL_ETM_ENABLED                 1
  ------------------
  123|      0|#endif
  124|      0|#if defined(MBEDTLS_SSL_RENEGOTIATION)
  125|      0|    mbedtls_ssl_conf_renegotiation(&conf,
  126|      0|                                   (options &
  ------------------
  |  Branch (126:36): [True: 0, False: 0]
  ------------------
  127|      0|                                    0x80) ? MBEDTLS_SSL_RENEGOTIATION_ENABLED : MBEDTLS_SSL_RENEGOTIATION_DISABLED);
  ------------------
  |  |  305|      0|#define MBEDTLS_SSL_RENEGOTIATION_ENABLED       1
  ------------------
                                                  0x80) ? MBEDTLS_SSL_RENEGOTIATION_ENABLED : MBEDTLS_SSL_RENEGOTIATION_DISABLED);
  ------------------
  |  |  304|      0|#define MBEDTLS_SSL_RENEGOTIATION_DISABLED      0
  ------------------
  128|      0|#endif
  129|      0|#if defined(MBEDTLS_SSL_SESSION_TICKETS)
  130|      0|    mbedtls_ssl_conf_session_tickets(&conf,
  131|      0|                                     (options &
  ------------------
  |  Branch (131:38): [True: 0, False: 0]
  ------------------
  132|      0|                                      0x100) ? MBEDTLS_SSL_SESSION_TICKETS_DISABLED : MBEDTLS_SSL_SESSION_TICKETS_ENABLED);
  ------------------
  |  |  321|      0|#define MBEDTLS_SSL_SESSION_TICKETS_DISABLED     0
  ------------------
                                                    0x100) ? MBEDTLS_SSL_SESSION_TICKETS_DISABLED : MBEDTLS_SSL_SESSION_TICKETS_ENABLED);
  ------------------
  |  |  322|      0|#define MBEDTLS_SSL_SESSION_TICKETS_ENABLED      1
  ------------------
  133|      0|#endif
  134|      0|#if defined(MBEDTLS_SSL_ALPN)
  135|      0|    if (options & 0x200) {
  ------------------
  |  Branch (135:9): [True: 0, False: 0]
  ------------------
  136|      0|        mbedtls_ssl_conf_alpn_protocols(&conf, alpn_list);
  137|      0|    }
  138|      0|#endif
  139|       |    //There may be other options to add :
  140|       |    // mbedtls_ssl_conf_cert_profile, mbedtls_ssl_conf_sig_hashes
  141|       |
  142|      0|    srand(1);
  143|      0|    mbedtls_ssl_conf_rng(&conf, dummy_random, &ctr_drbg);
  144|       |
  145|      0|    if (mbedtls_ssl_setup(&ssl, &conf) != 0) {
  ------------------
  |  Branch (145:9): [True: 0, False: 0]
  ------------------
  146|      0|        goto exit;
  147|      0|    }
  148|       |
  149|      0|#if defined(MBEDTLS_X509_CRT_PARSE_C) && defined(MBEDTLS_PEM_PARSE_C)
  150|      0|    if ((options & 1) == 0) {
  ------------------
  |  Branch (150:9): [True: 0, False: 0]
  ------------------
  151|      0|        if (mbedtls_ssl_set_hostname(&ssl, "localhost") != 0) {
  ------------------
  |  Branch (151:13): [True: 0, False: 0]
  ------------------
  152|      0|            goto exit;
  153|      0|        }
  154|      0|    }
  155|      0|#endif
  156|       |
  157|      0|    biomemfuzz.Data = Data;
  158|      0|    biomemfuzz.Size = Size-2;
  159|      0|    biomemfuzz.Offset = 0;
  160|      0|    mbedtls_ssl_set_bio(&ssl, &biomemfuzz, dummy_send, fuzz_recv, NULL);
  161|       |
  162|      0|    ret = mbedtls_ssl_handshake(&ssl);
  163|      0|    if (ret == 0) {
  ------------------
  |  Branch (163:9): [True: 0, False: 0]
  ------------------
  164|       |        //keep reading data from server until the end
  165|      0|        do {
  166|      0|            len = sizeof(buf) - 1;
  167|      0|            ret = mbedtls_ssl_read(&ssl, buf, len);
  168|       |
  169|      0|            if (ret == MBEDTLS_ERR_SSL_WANT_READ) {
  ------------------
  |  |  136|      0|#define MBEDTLS_ERR_SSL_WANT_READ                         -0x6900
  ------------------
  |  Branch (169:17): [True: 0, False: 0]
  ------------------
  170|      0|                continue;
  171|      0|            } else if (ret <= 0) {
  ------------------
  |  Branch (171:24): [True: 0, False: 0]
  ------------------
  172|       |                //EOF or error
  173|      0|                break;
  174|      0|            }
  175|      0|        } while (1);
  ------------------
  |  Branch (175:18): [Folded - Ignored]
  ------------------
  176|      0|    }
  177|       |
  178|     21|exit:
  179|     21|    mbedtls_entropy_free(&entropy);
  180|     21|    mbedtls_ctr_drbg_free(&ctr_drbg);
  181|     21|    mbedtls_ssl_config_free(&conf);
  182|     21|    mbedtls_ssl_free(&ssl);
  183|     21|#if defined(MBEDTLS_USE_PSA_CRYPTO)
  184|     21|    mbedtls_psa_crypto_free();
  185|     21|#endif /* MBEDTLS_USE_PSA_CRYPTO */
  186|       |
  187|       |#else
  188|       |    (void) Data;
  189|       |    (void) Size;
  190|       |#endif /* MBEDTLS_SSL_CLI_C && MBEDTLS_ENTROPY_C && MBEDTLS_CTR_DRBG_C */
  191|       |
  192|     21|    return 0;
  193|      0|}

