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|}

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

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_sequence_free:
  294|     84|{
  295|     84|    while (seq != NULL) {
  ------------------
  |  Branch (295:12): [True: 0, False: 84]
  ------------------
  296|      0|        mbedtls_asn1_sequence *next = seq->next;
  297|      0|        mbedtls_free(seq);
  298|      0|        seq = next;
  299|      0|    }
  300|     84|}
mbedtls_asn1_free_named_data_list_shallow:
  446|     42|{
  447|     42|    for (mbedtls_asn1_named_data *next; name != NULL; name = next) {
  ------------------
  |  Branch (447:41): [True: 0, False: 42]
  ------------------
  448|      0|        next = name->next;
  449|      0|        mbedtls_free(name);
  450|      0|    }
  451|     42|}

mbedtls_mpi_free:
  192|     42|{
  193|     42|    if (X == NULL) {
  ------------------
  |  Branch (193:9): [True: 0, False: 42]
  ------------------
  194|      0|        return;
  195|      0|    }
  196|       |
  197|     42|    if (X->p != NULL) {
  ------------------
  |  Branch (197:9): [True: 0, False: 42]
  ------------------
  198|      0|        mbedtls_mpi_zeroize_and_free(X->p, X->n);
  ------------------
  |  |  176|      0|#define mbedtls_mpi_zeroize_and_free(v, n) mbedtls_zeroize_and_free(v, ciL * (n))
  |  |  ------------------
  |  |  |  |   77|      0|#define ciL    (sizeof(mbedtls_mpi_uint))     /** chars in limb  */
  |  |  ------------------
  ------------------
  199|      0|    }
  200|       |
  201|     42|    X->s = 1;
  202|     42|    X->n = 0;
  203|     42|    X->p = NULL;
  204|     42|}

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_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_pk_init:
   42|     21|{
   43|     21|    ctx->pk_info = NULL;
   44|     21|    ctx->pk_ctx = NULL;
   45|     21|#if defined(MBEDTLS_USE_PSA_CRYPTO)
   46|     21|    ctx->priv_id = MBEDTLS_SVC_KEY_ID_INIT;
  ------------------
  |  | 2438|     21|#define MBEDTLS_SVC_KEY_ID_INIT ((psa_key_id_t) 0)
  ------------------
   47|     21|#endif /* MBEDTLS_USE_PSA_CRYPTO */
   48|       |#if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
   49|       |    memset(ctx->pub_raw, 0, sizeof(ctx->pub_raw));
   50|       |    ctx->pub_raw_len = 0;
   51|       |    ctx->ec_family = 0;
   52|       |    ctx->ec_bits = 0;
   53|       |#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
   54|     21|}
mbedtls_pk_free:
   60|     42|{
   61|     42|    if (ctx == NULL) {
  ------------------
  |  Branch (61:9): [True: 0, False: 42]
  ------------------
   62|      0|        return;
   63|      0|    }
   64|       |
   65|     42|    if ((ctx->pk_info != NULL) && (ctx->pk_info->ctx_free_func != NULL)) {
  ------------------
  |  Branch (65:9): [True: 0, False: 42]
  |  Branch (65:35): [True: 0, False: 0]
  ------------------
   66|      0|        ctx->pk_info->ctx_free_func(ctx->pk_ctx);
   67|      0|    }
   68|       |
   69|       |#if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
   70|       |    /* The ownership of the priv_id key for opaque keys is external of the PK
   71|       |     * module. It's the user responsibility to clear it after use. */
   72|       |    if ((ctx->pk_info != NULL) && (ctx->pk_info->type != MBEDTLS_PK_OPAQUE)) {
   73|       |        psa_destroy_key(ctx->priv_id);
   74|       |    }
   75|       |#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
   76|       |
   77|     42|    mbedtls_platform_zeroize(ctx, sizeof(mbedtls_pk_context));
   78|     42|}

mbedtls_calloc:
   48|     42|{
   49|     42|    return (*mbedtls_calloc_func)(nmemb, size);
   50|     42|}
mbedtls_free:
   53|    105|{
   54|    105|    (*mbedtls_free_func)(ptr);
   55|    105|}
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|    483|{
   96|    483|    if (len > 0) {
  ------------------
  |  Branch (96:9): [True: 483, False: 0]
  ------------------
   97|    483|#if defined(MBEDTLS_PLATFORM_HAS_EXPLICIT_BZERO)
   98|    483|        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|    483|#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|    483|#if defined(__clang__) || (__GNUC__ >= 10)
  120|    483|#if defined(__clang__)
  121|    483|#pragma clang diagnostic push
  122|    483|#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|    483|        asm volatile ("" : : "m" (*(char (*)[len]) buf) :);
  ------------------
  |  |  321|    483|#define asm __asm__
  ------------------
  128|    483|#if defined(__clang__)
  129|    483|#pragma clang diagnostic pop
  130|       |#elif defined(MBEDTLS_COMPILER_IS_GCC)
  131|       |#pragma GCC diagnostic pop
  132|       |#endif
  133|    483|#endif
  134|    483|#endif
  135|    483|    }
  136|    483|}

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|}
psa_destroy_key:
 1278|     42|{
 1279|     42|    psa_key_slot_t *slot;
 1280|     42|    psa_status_t status; /* status of the last operation */
 1281|     42|    psa_status_t overall_status = PSA_SUCCESS;
  ------------------
  |  |   57|     42|#define PSA_SUCCESS ((psa_status_t)0)
  ------------------
 1282|     42|#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
 1283|     42|    psa_se_drv_table_entry_t *driver;
 1284|     42|#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
 1285|       |
 1286|     42|    if (mbedtls_svc_key_id_is_null(key)) {
  ------------------
  |  Branch (1286:9): [True: 42, False: 0]
  ------------------
 1287|     42|        return PSA_SUCCESS;
  ------------------
  |  |   57|     42|#define PSA_SUCCESS ((psa_status_t)0)
  ------------------
 1288|     42|    }
 1289|       |
 1290|       |    /*
 1291|       |     * Get the description of the key in a key slot, and register to read it.
 1292|       |     * In the case of a persistent key, this will load the key description
 1293|       |     * from persistent memory if not done yet.
 1294|       |     * We cannot avoid this loading as without it we don't know if
 1295|       |     * the key is operated by an SE or not and this information is needed by
 1296|       |     * the current implementation. */
 1297|      0|    status = psa_get_and_lock_key_slot(key, &slot);
 1298|      0|    if (status != PSA_SUCCESS) {
  ------------------
  |  |   57|      0|#define PSA_SUCCESS ((psa_status_t)0)
  ------------------
  |  Branch (1298:9): [True: 0, False: 0]
  ------------------
 1299|      0|        return status;
 1300|      0|    }
 1301|       |
 1302|      0|#if defined(MBEDTLS_THREADING_C)
 1303|       |    /* We cannot unlock between setting the state to PENDING_DELETION
 1304|       |     * and destroying the key in storage, as otherwise another thread
 1305|       |     * could load the key into a new slot and the key will not be
 1306|       |     * fully destroyed. */
 1307|      0|    PSA_THREADING_CHK_GOTO_EXIT(mbedtls_mutex_lock(
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1308|      0|                                    &mbedtls_threading_key_slot_mutex));
 1309|       |
 1310|      0|    if (slot->state == PSA_SLOT_PENDING_DELETION) {
  ------------------
  |  Branch (1310:9): [True: 0, False: 0]
  ------------------
 1311|       |        /* Another thread has destroyed the key between us locking the slot
 1312|       |         * and us gaining the mutex. Unregister from the slot,
 1313|       |         * and report that the key does not exist. */
 1314|      0|        status = psa_unregister_read(slot);
 1315|       |
 1316|      0|        PSA_THREADING_CHK_RET(mbedtls_mutex_unlock(
  ------------------
  |  |  179|      0|    do                                                 \
  |  |  180|      0|    {                                                  \
  |  |  181|      0|        if ((f) != 0) {                                \
  |  |  ------------------
  |  |  |  Branch (181:13): [True: 0, False: 0]
  |  |  ------------------
  |  |  182|      0|            if (status == PSA_SUCCESS) {               \
  |  |  ------------------
  |  |  |  |   57|      0|#define PSA_SUCCESS ((psa_status_t)0)
  |  |  ------------------
  |  |  |  Branch (182:17): [True: 0, False: 0]
  |  |  ------------------
  |  |  183|      0|                return PSA_ERROR_SERVICE_FAILURE;      \
  |  |  ------------------
  |  |  |  |  285|      0|#define PSA_ERROR_SERVICE_FAILURE       ((psa_status_t)-144)
  |  |  ------------------
  |  |  184|      0|            }                                          \
  |  |  185|      0|            return status;                             \
  |  |  186|      0|        }                                              \
  |  |  187|      0|    } while (0);
  |  |  ------------------
  |  |  |  Branch (187:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1317|      0|                                  &mbedtls_threading_key_slot_mutex));
 1318|      0|        return (status == PSA_SUCCESS) ? PSA_ERROR_INVALID_HANDLE : status;
  ------------------
  |  |   57|      0|#define PSA_SUCCESS ((psa_status_t)0)
  ------------------
                      return (status == PSA_SUCCESS) ? PSA_ERROR_INVALID_HANDLE : status;
  ------------------
  |  |  289|      0|#define PSA_ERROR_INVALID_HANDLE        ((psa_status_t)-136)
  ------------------
  |  Branch (1318:16): [True: 0, False: 0]
  ------------------
 1319|      0|    }
 1320|      0|#endif
 1321|       |    /* Set the key slot containing the key description's state to
 1322|       |     * PENDING_DELETION. This stops new operations from registering
 1323|       |     * to read the slot. Current readers can safely continue to access
 1324|       |     * the key within the slot; the last registered reader will
 1325|       |     * automatically wipe the slot when they call psa_unregister_read().
 1326|       |     * If the key is persistent, we can now delete the copy of the key
 1327|       |     * from memory. If the key is opaque, we require the driver to
 1328|       |     * deal with the deletion. */
 1329|      0|    overall_status = psa_key_slot_state_transition(slot, PSA_SLOT_FULL,
 1330|      0|                                                   PSA_SLOT_PENDING_DELETION);
 1331|       |
 1332|      0|    if (overall_status != PSA_SUCCESS) {
  ------------------
  |  |   57|      0|#define PSA_SUCCESS ((psa_status_t)0)
  ------------------
  |  Branch (1332:9): [True: 0, False: 0]
  ------------------
 1333|      0|        goto exit;
 1334|      0|    }
 1335|       |
 1336|      0|    if (PSA_KEY_LIFETIME_IS_READ_ONLY(slot->attr.lifetime)) {
  ------------------
  |  | 2386|      0|    (PSA_KEY_LIFETIME_GET_PERSISTENCE(lifetime) == \
  |  |  ------------------
  |  |  |  | 2343|      0|    ((psa_key_persistence_t) ((lifetime) & 0x000000ff))
  |  |  ------------------
  |  |  |  Branch (2386:5): [True: 0, False: 0]
  |  |  ------------------
  |  | 2387|      0|     PSA_KEY_PERSISTENCE_READ_ONLY)
  |  |  ------------------
  |  |  |  | 2340|      0|#define PSA_KEY_PERSISTENCE_READ_ONLY           ((psa_key_persistence_t) 0xff)
  |  |  ------------------
  ------------------
 1337|       |        /* Refuse the destruction of a read-only key (which may or may not work
 1338|       |         * if we attempt it, depending on whether the key is merely read-only
 1339|       |         * by policy or actually physically read-only).
 1340|       |         * Just do the best we can, which is to wipe the copy in memory
 1341|       |         * (done in this function's cleanup code). */
 1342|      0|        overall_status = PSA_ERROR_NOT_PERMITTED;
  ------------------
  |  |   86|      0|#define PSA_ERROR_NOT_PERMITTED         ((psa_status_t)-133)
  ------------------
 1343|      0|        goto exit;
 1344|      0|    }
 1345|       |
 1346|      0|#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
 1347|      0|    driver = psa_get_se_driver_entry(slot->attr.lifetime);
 1348|      0|    if (driver != NULL) {
  ------------------
  |  Branch (1348:9): [True: 0, False: 0]
  ------------------
 1349|       |        /* For a key in a secure element, we need to do three things:
 1350|       |         * remove the key file in internal storage, destroy the
 1351|       |         * key inside the secure element, and update the driver's
 1352|       |         * persistent data. Start a transaction that will encompass these
 1353|       |         * three actions. */
 1354|      0|        psa_crypto_prepare_transaction(PSA_CRYPTO_TRANSACTION_DESTROY_KEY);
  ------------------
  |  |  234|      0|#define PSA_CRYPTO_TRANSACTION_DESTROY_KEY      ((psa_crypto_transaction_type_t) 0x0002)
  ------------------
 1355|      0|        psa_crypto_transaction.key.lifetime = slot->attr.lifetime;
 1356|      0|        psa_crypto_transaction.key.slot = psa_key_slot_get_slot_number(slot);
 1357|      0|        psa_crypto_transaction.key.id = slot->attr.id;
 1358|      0|        status = psa_crypto_save_transaction();
 1359|      0|        if (status != PSA_SUCCESS) {
  ------------------
  |  |   57|      0|#define PSA_SUCCESS ((psa_status_t)0)
  ------------------
  |  Branch (1359:13): [True: 0, False: 0]
  ------------------
 1360|      0|            (void) psa_crypto_stop_transaction();
 1361|       |            /* We should still try to destroy the key in the secure
 1362|       |             * element and the key metadata in storage. This is especially
 1363|       |             * important if the error is that the storage is full.
 1364|       |             * But how to do it exactly without risking an inconsistent
 1365|       |             * state after a reset?
 1366|       |             * https://github.com/ARMmbed/mbed-crypto/issues/215
 1367|       |             */
 1368|      0|            overall_status = status;
 1369|      0|            goto exit;
 1370|      0|        }
 1371|       |
 1372|      0|        status = psa_destroy_se_key(driver,
 1373|      0|                                    psa_key_slot_get_slot_number(slot));
 1374|      0|        if (overall_status == PSA_SUCCESS) {
  ------------------
  |  |   57|      0|#define PSA_SUCCESS ((psa_status_t)0)
  ------------------
  |  Branch (1374:13): [True: 0, False: 0]
  ------------------
 1375|      0|            overall_status = status;
 1376|      0|        }
 1377|      0|    }
 1378|      0|#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
 1379|       |
 1380|      0|#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C)
 1381|      0|    if (!PSA_KEY_LIFETIME_IS_VOLATILE(slot->attr.lifetime)) {
  ------------------
  |  | 2365|      0|    (PSA_KEY_LIFETIME_GET_PERSISTENCE(lifetime) == \
  |  |  ------------------
  |  |  |  | 2343|      0|    ((psa_key_persistence_t) ((lifetime) & 0x000000ff))
  |  |  ------------------
  |  | 2366|      0|     PSA_KEY_PERSISTENCE_VOLATILE)
  |  |  ------------------
  |  |  |  | 2328|      0|#define PSA_KEY_PERSISTENCE_VOLATILE            ((psa_key_persistence_t) 0x00)
  |  |  ------------------
  ------------------
  |  Branch (1381:9): [True: 0, False: 0]
  ------------------
 1382|       |        /* Destroy the copy of the persistent key from storage.
 1383|       |         * The slot will still hold a copy of the key until the last reader
 1384|       |         * unregisters. */
 1385|      0|        status = psa_destroy_persistent_key(slot->attr.id);
 1386|      0|        if (overall_status == PSA_SUCCESS) {
  ------------------
  |  |   57|      0|#define PSA_SUCCESS ((psa_status_t)0)
  ------------------
  |  Branch (1386:13): [True: 0, False: 0]
  ------------------
 1387|      0|            overall_status = status;
 1388|      0|        }
 1389|      0|    }
 1390|      0|#endif /* defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) */
 1391|       |
 1392|      0|#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
 1393|      0|    if (driver != NULL) {
  ------------------
  |  Branch (1393:9): [True: 0, False: 0]
  ------------------
 1394|      0|        status = psa_save_se_persistent_data(driver);
 1395|      0|        if (overall_status == PSA_SUCCESS) {
  ------------------
  |  |   57|      0|#define PSA_SUCCESS ((psa_status_t)0)
  ------------------
  |  Branch (1395:13): [True: 0, False: 0]
  ------------------
 1396|      0|            overall_status = status;
 1397|      0|        }
 1398|      0|        status = psa_crypto_stop_transaction();
 1399|      0|        if (overall_status == PSA_SUCCESS) {
  ------------------
  |  |   57|      0|#define PSA_SUCCESS ((psa_status_t)0)
  ------------------
  |  Branch (1399:13): [True: 0, False: 0]
  ------------------
 1400|      0|            overall_status = status;
 1401|      0|        }
 1402|      0|    }
 1403|      0|#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
 1404|       |
 1405|      0|exit:
 1406|       |    /* Unregister from reading the slot. If we are the last active reader
 1407|       |     * then this will wipe the slot. */
 1408|      0|    status = psa_unregister_read(slot);
 1409|       |    /* Prioritize CORRUPTION_DETECTED from unregistering over
 1410|       |     * a storage error. */
 1411|      0|    if (status != PSA_SUCCESS) {
  ------------------
  |  |   57|      0|#define PSA_SUCCESS ((psa_status_t)0)
  ------------------
  |  Branch (1411:9): [True: 0, False: 0]
  ------------------
 1412|      0|        overall_status = status;
 1413|      0|    }
 1414|       |
 1415|      0|#if defined(MBEDTLS_THREADING_C)
 1416|       |    /* Don't overwrite existing errors if the unlock fails. */
 1417|      0|    status = overall_status;
 1418|      0|    PSA_THREADING_CHK_RET(mbedtls_mutex_unlock(
  ------------------
  |  |  179|      0|    do                                                 \
  |  |  180|      0|    {                                                  \
  |  |  181|      0|        if ((f) != 0) {                                \
  |  |  ------------------
  |  |  |  Branch (181:13): [True: 0, False: 0]
  |  |  ------------------
  |  |  182|      0|            if (status == PSA_SUCCESS) {               \
  |  |  ------------------
  |  |  |  |   57|      0|#define PSA_SUCCESS ((psa_status_t)0)
  |  |  ------------------
  |  |  |  Branch (182:17): [True: 0, False: 0]
  |  |  ------------------
  |  |  183|      0|                return PSA_ERROR_SERVICE_FAILURE;      \
  |  |  ------------------
  |  |  |  |  285|      0|#define PSA_ERROR_SERVICE_FAILURE       ((psa_status_t)-144)
  |  |  ------------------
  |  |  184|      0|            }                                          \
  |  |  185|      0|            return status;                             \
  |  |  186|      0|        }                                              \
  |  |  187|      0|    } while (0);
  |  |  ------------------
  |  |  |  Branch (187:14): [Folded - Ignored]
  |  |  ------------------
  ------------------
 1419|      0|                              &mbedtls_threading_key_slot_mutex));
 1420|      0|#endif
 1421|       |
 1422|      0|    return overall_status;
 1423|      0|}
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_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_ticket_init:
   37|     21|{
   38|     21|    memset(ctx, 0, sizeof(mbedtls_ssl_ticket_context));
   39|       |
   40|     21|#if defined(MBEDTLS_THREADING_C)
   41|     21|    mbedtls_mutex_init(&ctx->mutex);
   42|     21|#endif
   43|     21|}
mbedtls_ssl_ticket_free:
  536|     21|{
  537|     21|    if (ctx == NULL) {
  ------------------
  |  Branch (537:9): [True: 0, False: 21]
  ------------------
  538|      0|        return;
  539|      0|    }
  540|       |
  541|     21|#if defined(MBEDTLS_USE_PSA_CRYPTO)
  542|     21|    psa_destroy_key(ctx->keys[0].key);
  543|     21|    psa_destroy_key(ctx->keys[1].key);
  544|       |#else
  545|       |    mbedtls_cipher_free(&ctx->keys[0].ctx);
  546|       |    mbedtls_cipher_free(&ctx->keys[1].ctx);
  547|       |#endif /* MBEDTLS_USE_PSA_CRYPTO */
  548|       |
  549|     21|#if defined(MBEDTLS_THREADING_C)
  550|     21|    mbedtls_mutex_free(&ctx->mutex);
  551|     21|#endif
  552|       |
  553|     21|    mbedtls_platform_zeroize(ctx, sizeof(mbedtls_ssl_ticket_context));
  554|     21|}

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|     84|{
   55|     84|    if (mutex == NULL) {
  ------------------
  |  Branch (55:9): [True: 0, False: 84]
  ------------------
   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|     84|    (void) pthread_mutex_init(&mutex->mutex, NULL);
   66|     84|}
threading.c:threading_mutex_free_pthread:
   69|     84|{
   70|     84|    if (mutex == NULL) {
  ------------------
  |  Branch (70:9): [True: 0, False: 84]
  ------------------
   71|      0|        return;
   72|      0|    }
   73|       |
   74|     84|    (void) pthread_mutex_destroy(&mutex->mutex);
   75|     84|}
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_crt_init:
 3222|     21|{
 3223|     21|    memset(crt, 0, sizeof(mbedtls_x509_crt));
 3224|     21|}
mbedtls_x509_crt_free:
 3230|     21|{
 3231|     21|    mbedtls_x509_crt *cert_cur = crt;
 3232|     21|    mbedtls_x509_crt *cert_prv;
 3233|       |
 3234|     42|    while (cert_cur != NULL) {
  ------------------
  |  Branch (3234:12): [True: 21, False: 21]
  ------------------
 3235|     21|        mbedtls_pk_free(&cert_cur->pk);
 3236|       |
 3237|     21|#if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
 3238|     21|        mbedtls_free(cert_cur->sig_opts);
 3239|     21|#endif
 3240|       |
 3241|     21|        mbedtls_asn1_free_named_data_list_shallow(cert_cur->issuer.next);
 3242|     21|        mbedtls_asn1_free_named_data_list_shallow(cert_cur->subject.next);
 3243|     21|        mbedtls_asn1_sequence_free(cert_cur->ext_key_usage.next);
 3244|     21|        mbedtls_asn1_sequence_free(cert_cur->subject_alt_names.next);
 3245|     21|        mbedtls_asn1_sequence_free(cert_cur->certificate_policies.next);
 3246|     21|        mbedtls_asn1_sequence_free(cert_cur->authority_key_id.authorityCertIssuer.next);
 3247|       |
 3248|     21|        if (cert_cur->raw.p != NULL && cert_cur->own_buffer) {
  ------------------
  |  Branch (3248:13): [True: 0, False: 21]
  |  Branch (3248:40): [True: 0, False: 0]
  ------------------
 3249|      0|            mbedtls_zeroize_and_free(cert_cur->raw.p, cert_cur->raw.len);
 3250|      0|        }
 3251|       |
 3252|     21|        cert_prv = cert_cur;
 3253|     21|        cert_cur = cert_cur->next;
 3254|       |
 3255|     21|        mbedtls_platform_zeroize(cert_prv, sizeof(mbedtls_x509_crt));
 3256|     21|        if (cert_prv != crt) {
  ------------------
  |  Branch (3256:13): [True: 0, False: 21]
  ------------------
 3257|      0|            mbedtls_free(cert_prv);
 3258|      0|        }
 3259|     21|    }
 3260|     21|}

LLVMFuzzerTestOneInput:
   34|     21|{
   35|     21|#if defined(MBEDTLS_SSL_SRV_C) && \
   36|     21|    defined(MBEDTLS_ENTROPY_C) && \
   37|     21|    defined(MBEDTLS_CTR_DRBG_C)
   38|     21|    int ret;
   39|     21|    size_t len;
   40|     21|    mbedtls_ssl_context ssl;
   41|     21|    mbedtls_ssl_config conf;
   42|     21|    mbedtls_ctr_drbg_context ctr_drbg;
   43|     21|    mbedtls_entropy_context entropy;
   44|     21|#if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_TICKET_C)
   45|     21|    mbedtls_ssl_ticket_context ticket_ctx;
   46|     21|#endif
   47|     21|    unsigned char buf[4096];
   48|     21|    fuzzBufferOffset_t biomemfuzz;
   49|     21|    uint8_t options;
   50|       |
   51|       |    //we take 1 byte as options input
   52|     21|    if (Size < 1) {
  ------------------
  |  Branch (52:9): [True: 0, False: 21]
  ------------------
   53|      0|        return 0;
   54|      0|    }
   55|     21|    options = Data[Size - 1];
   56|       |
   57|     21|    mbedtls_ctr_drbg_init(&ctr_drbg);
   58|     21|    mbedtls_entropy_init(&entropy);
   59|     21|#if defined(MBEDTLS_X509_CRT_PARSE_C) && defined(MBEDTLS_PEM_PARSE_C)
   60|     21|    mbedtls_x509_crt_init(&srvcert);
   61|     21|    mbedtls_pk_init(&pkey);
   62|     21|#endif
   63|     21|    mbedtls_ssl_init(&ssl);
   64|     21|    mbedtls_ssl_config_init(&conf);
   65|     21|#if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_TICKET_C)
   66|     21|    mbedtls_ssl_ticket_init(&ticket_ctx);
   67|     21|#endif
   68|     21|#if defined(MBEDTLS_USE_PSA_CRYPTO)
   69|     21|    psa_status_t status = psa_crypto_init();
   70|     21|    if (status != PSA_SUCCESS) {
  ------------------
  |  |   57|     21|#define PSA_SUCCESS ((psa_status_t)0)
  ------------------
  |  Branch (70:9): [True: 21, False: 0]
  ------------------
   71|     21|        goto exit;
   72|     21|    }
   73|      0|#endif /* MBEDTLS_USE_PSA_CRYPTO */
   74|       |
   75|      0|    if (mbedtls_ctr_drbg_seed(&ctr_drbg, dummy_entropy, &entropy,
  ------------------
  |  Branch (75:9): [True: 0, False: 0]
  ------------------
   76|      0|                              (const unsigned char *) pers, strlen(pers)) != 0) {
   77|      0|        return 1;
   78|      0|    }
   79|       |
   80|      0|    if (initialized == 0) {
  ------------------
  |  Branch (80:9): [True: 0, False: 0]
  ------------------
   81|       |
   82|      0|#if defined(MBEDTLS_X509_CRT_PARSE_C) && defined(MBEDTLS_PEM_PARSE_C)
   83|      0|        if (mbedtls_x509_crt_parse(&srvcert, (const unsigned char *) mbedtls_test_srv_crt,
  ------------------
  |  Branch (83:13): [True: 0, False: 0]
  ------------------
   84|      0|                                   mbedtls_test_srv_crt_len) != 0) {
   85|      0|            return 1;
   86|      0|        }
   87|      0|        if (mbedtls_x509_crt_parse(&srvcert, (const unsigned char *) mbedtls_test_cas_pem,
  ------------------
  |  Branch (87:13): [True: 0, False: 0]
  ------------------
   88|      0|                                   mbedtls_test_cas_pem_len) != 0) {
   89|      0|            return 1;
   90|      0|        }
   91|      0|        if (mbedtls_pk_parse_key(&pkey, (const unsigned char *) mbedtls_test_srv_key,
  ------------------
  |  Branch (91:13): [True: 0, False: 0]
  ------------------
   92|      0|                                 mbedtls_test_srv_key_len, NULL, 0,
   93|      0|                                 dummy_random, &ctr_drbg) != 0) {
   94|      0|            return 1;
   95|      0|        }
   96|      0|#endif
   97|       |
   98|      0|        alpn_list[0] = "HTTP";
   99|      0|        alpn_list[1] = "fuzzalpn";
  100|      0|        alpn_list[2] = NULL;
  101|       |
  102|      0|        dummy_init();
  103|       |
  104|      0|        initialized = 1;
  105|      0|    }
  106|       |
  107|      0|    if (mbedtls_ssl_config_defaults(&conf,
  ------------------
  |  Branch (107:9): [True: 0, False: 0]
  ------------------
  108|      0|                                    MBEDTLS_SSL_IS_SERVER,
  ------------------
  |  |  283|      0|#define MBEDTLS_SSL_IS_SERVER                   1
  ------------------
  109|      0|                                    MBEDTLS_SSL_TRANSPORT_STREAM,
  ------------------
  |  |  265|      0|#define MBEDTLS_SSL_TRANSPORT_STREAM            0   /*!< TLS      */
  ------------------
  110|      0|                                    MBEDTLS_SSL_PRESET_DEFAULT) != 0) {
  ------------------
  |  |  327|      0|#define MBEDTLS_SSL_PRESET_DEFAULT              0
  ------------------
  111|      0|        goto exit;
  112|      0|    }
  113|       |
  114|      0|    srand(1);
  115|      0|    mbedtls_ssl_conf_rng(&conf, dummy_random, &ctr_drbg);
  116|       |
  117|      0|#if defined(MBEDTLS_X509_CRT_PARSE_C) && defined(MBEDTLS_PEM_PARSE_C)
  118|      0|    mbedtls_ssl_conf_ca_chain(&conf, srvcert.next, NULL);
  119|      0|    if (mbedtls_ssl_conf_own_cert(&conf, &srvcert, &pkey) != 0) {
  ------------------
  |  Branch (119:9): [True: 0, False: 0]
  ------------------
  120|      0|        goto exit;
  121|      0|    }
  122|      0|#endif
  123|       |
  124|      0|    mbedtls_ssl_conf_cert_req_ca_list(&conf,
  125|      0|                                      (options &
  ------------------
  |  Branch (125:39): [True: 0, False: 0]
  ------------------
  126|      0|                                       0x1) ? MBEDTLS_SSL_CERT_REQ_CA_LIST_ENABLED : MBEDTLS_SSL_CERT_REQ_CA_LIST_DISABLED);
  ------------------
  |  |  330|      0|#define MBEDTLS_SSL_CERT_REQ_CA_LIST_ENABLED       1
  ------------------
                                                     0x1) ? MBEDTLS_SSL_CERT_REQ_CA_LIST_ENABLED : MBEDTLS_SSL_CERT_REQ_CA_LIST_DISABLED);
  ------------------
  |  |  331|      0|#define MBEDTLS_SSL_CERT_REQ_CA_LIST_DISABLED      0
  ------------------
  127|      0|#if defined(MBEDTLS_SSL_ALPN)
  128|      0|    if (options & 0x2) {
  ------------------
  |  Branch (128:9): [True: 0, False: 0]
  ------------------
  129|      0|        mbedtls_ssl_conf_alpn_protocols(&conf, alpn_list);
  130|      0|    }
  131|      0|#endif
  132|      0|#if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_TICKET_C)
  133|      0|    if (options & 0x4) {
  ------------------
  |  Branch (133:9): [True: 0, False: 0]
  ------------------
  134|      0|        if (mbedtls_ssl_ticket_setup(&ticket_ctx,
  ------------------
  |  Branch (134:13): [True: 0, False: 0]
  ------------------
  135|      0|                                     dummy_random, &ctr_drbg,
  136|      0|                                     MBEDTLS_CIPHER_AES_256_GCM,
  137|      0|                                     86400) != 0) {
  138|      0|            goto exit;
  139|      0|        }
  140|       |
  141|      0|        mbedtls_ssl_conf_session_tickets_cb(&conf,
  142|      0|                                            mbedtls_ssl_ticket_write,
  143|      0|                                            mbedtls_ssl_ticket_parse,
  144|      0|                                            &ticket_ctx);
  145|      0|    }
  146|      0|#endif
  147|      0|#if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
  148|      0|    mbedtls_ssl_conf_extended_master_secret(&conf,
  149|      0|                                            (options &
  ------------------
  |  Branch (149:45): [True: 0, False: 0]
  ------------------
  150|      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
  ------------------
  151|      0|#endif
  152|      0|#if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
  153|      0|    mbedtls_ssl_conf_encrypt_then_mac(&conf,
  154|      0|                                      (options &
  ------------------
  |  Branch (154:39): [True: 0, False: 0]
  ------------------
  155|      0|                                       0x20) ? MBEDTLS_SSL_ETM_ENABLED : MBEDTLS_SSL_ETM_DISABLED);
  ------------------
  |  |  292|      0|#define MBEDTLS_SSL_ETM_ENABLED                 1
  ------------------
                                                     0x20) ? MBEDTLS_SSL_ETM_ENABLED : MBEDTLS_SSL_ETM_DISABLED);
  ------------------
  |  |  291|      0|#define MBEDTLS_SSL_ETM_DISABLED                0
  ------------------
  156|      0|#endif
  157|      0|#if defined(MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED)
  158|      0|    if (options & 0x40) {
  ------------------
  |  Branch (158:9): [True: 0, False: 0]
  ------------------
  159|      0|        mbedtls_ssl_conf_psk(&conf, psk, sizeof(psk),
  160|      0|                             (const unsigned char *) psk_id, sizeof(psk_id) - 1);
  161|      0|    }
  162|      0|#endif
  163|      0|#if defined(MBEDTLS_SSL_RENEGOTIATION)
  164|      0|    mbedtls_ssl_conf_renegotiation(&conf,
  165|      0|                                   (options &
  ------------------
  |  Branch (165:36): [True: 0, False: 0]
  ------------------
  166|      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
  ------------------
  167|      0|#endif
  168|       |
  169|      0|    if (mbedtls_ssl_setup(&ssl, &conf) != 0) {
  ------------------
  |  Branch (169:9): [True: 0, False: 0]
  ------------------
  170|      0|        goto exit;
  171|      0|    }
  172|       |
  173|      0|    biomemfuzz.Data = Data;
  174|      0|    biomemfuzz.Size = Size-1;
  175|      0|    biomemfuzz.Offset = 0;
  176|      0|    mbedtls_ssl_set_bio(&ssl, &biomemfuzz, dummy_send, fuzz_recv, NULL);
  177|       |
  178|      0|    mbedtls_ssl_session_reset(&ssl);
  179|      0|    ret = mbedtls_ssl_handshake(&ssl);
  180|      0|    if (ret == 0) {
  ------------------
  |  Branch (180:9): [True: 0, False: 0]
  ------------------
  181|       |        //keep reading data from server until the end
  182|      0|        do {
  183|      0|            len = sizeof(buf) - 1;
  184|      0|            ret = mbedtls_ssl_read(&ssl, buf, len);
  185|       |
  186|      0|            if (ret == MBEDTLS_ERR_SSL_WANT_READ) {
  ------------------
  |  |  136|      0|#define MBEDTLS_ERR_SSL_WANT_READ                         -0x6900
  ------------------
  |  Branch (186:17): [True: 0, False: 0]
  ------------------
  187|      0|                continue;
  188|      0|            } else if (ret <= 0) {
  ------------------
  |  Branch (188:24): [True: 0, False: 0]
  ------------------
  189|       |                //EOF or error
  190|      0|                break;
  191|      0|            }
  192|      0|        } while (1);
  ------------------
  |  Branch (192:18): [Folded - Ignored]
  ------------------
  193|      0|    }
  194|       |
  195|     21|exit:
  196|     21|#if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_TICKET_C)
  197|     21|    mbedtls_ssl_ticket_free(&ticket_ctx);
  198|     21|#endif
  199|     21|    mbedtls_entropy_free(&entropy);
  200|     21|    mbedtls_ctr_drbg_free(&ctr_drbg);
  201|     21|    mbedtls_ssl_config_free(&conf);
  202|     21|#if defined(MBEDTLS_X509_CRT_PARSE_C) && defined(MBEDTLS_PEM_PARSE_C)
  203|     21|    mbedtls_x509_crt_free(&srvcert);
  204|     21|    mbedtls_pk_free(&pkey);
  205|     21|#endif
  206|     21|    mbedtls_ssl_free(&ssl);
  207|     21|#if defined(MBEDTLS_USE_PSA_CRYPTO)
  208|     21|    mbedtls_psa_crypto_free();
  209|     21|#endif
  210|       |#else
  211|       |    (void) Data;
  212|       |    (void) Size;
  213|       |#endif /* MBEDTLS_SSL_SRV_C && MBEDTLS_ENTROPY_C && MBEDTLS_CTR_DRBG_C */
  214|       |
  215|     21|    return 0;
  216|      0|}

