fuzz_early_setup:
   23|      2|void fuzz_early_setup(void) {
   24|       |    /* Set stderr to point to normal stderr by default */
   25|      2|    fuzz.fake_stderr = stderr;
   26|      2|}
fuzz_common_setup:
   28|      1|void fuzz_common_setup(void) {
   29|      1|	disallow_core();
   30|      1|    fuzz.fuzzing = 1;
   31|      1|    fuzz.wrapfds = 1;
   32|      1|    fuzz.do_jmp = 1;
   33|      1|    fuzz.input = m_malloc(sizeof(buffer));
   34|      1|    _dropbear_log = fuzz_dropbear_log;
   35|      1|    crypto_init();
   36|      1|    fuzz_seed("start", 5);
   37|       |    /* let any messages get flushed */
   38|      1|    setlinebuf(stdout);
   39|       |#if DEBUG_TRACE
   40|       |    if (debug_trace)
   41|       |    {
   42|       |        fprintf(stderr, "Dropbear fuzzer: -v specified, not disabling stderr output\n");
   43|       |    }
   44|       |    else
   45|       |#endif
   46|      1|    if (getenv("DROPBEAR_KEEP_STDERR")) {
  ------------------
  |  Branch (46:9): [True: 0, False: 1]
  ------------------
   47|      0|        fprintf(stderr, "Dropbear fuzzer: DROPBEAR_KEEP_STDERR, not disabling stderr output\n");
   48|      0|    } 
   49|      1|    else 
   50|      1|    {
   51|      1|        fprintf(stderr, "Dropbear fuzzer: Disabling stderr output\n");
   52|      1|        fuzz.fake_stderr = fopen("/dev/null", "w");
   53|      1|        assert(fuzz.fake_stderr);
   54|      1|    }
   55|      1|}
fuzz_set_input:
   57|  2.34k|int fuzz_set_input(const uint8_t *Data, size_t Size) {
   58|       |
   59|  2.34k|    fuzz.input->data = (unsigned char*)Data;
   60|  2.34k|    fuzz.input->size = Size;
   61|  2.34k|    fuzz.input->len = Size;
   62|  2.34k|    fuzz.input->pos = 0;
   63|       |
   64|  2.34k|    memset(&ses, 0x0, sizeof(ses));
   65|  2.34k|    memset(&svr_ses, 0x0, sizeof(svr_ses));
   66|  2.34k|    memset(&cli_ses, 0x0, sizeof(cli_ses));
   67|  2.34k|    wrapfd_setup(fuzz.input);
   68|       |    // printhex("input", fuzz.input->data, fuzz.input->len);
   69|       |
   70|  2.34k|    fuzz_seed(fuzz.input->data, MIN(fuzz.input->len, 16));
   71|       |
   72|  2.34k|    return DROPBEAR_SUCCESS;
  ------------------
  |  |  102|  2.34k|#define DROPBEAR_SUCCESS 0
  ------------------
   73|  2.34k|}
fuzz-common.c:fuzz_dropbear_log:
   84|  3.13k|static void fuzz_dropbear_log(int UNUSED(priority), const char* UNUSED(format), va_list UNUSED(param)) {
   85|       |    /* No print */
   86|  3.13k|}

wrapfd_setup:
   32|  2.34k|void wrapfd_setup(buffer *buf) {
   33|  2.34k|	TRACE(("wrapfd_setup"))
   34|       |
   35|       |	// clean old ones
   36|  2.34k|	int i;
   37|  2.34k|	for (i = 0; i <= wrapfd_maxfd; i++) {
  ------------------
  |  Branch (37:14): [True: 0, False: 2.34k]
  ------------------
   38|      0|		if (wrap_fds[i].mode != UNUSED) {
  ------------------
  |  Branch (38:7): [True: 0, False: 0]
  ------------------
   39|      0|			wrapfd_remove(i);
   40|      0|		}
   41|      0|	}
   42|  2.34k|	wrapfd_maxfd = -1;
   43|       |
   44|  2.34k|	memset(rand_state, 0x0, sizeof(rand_state));
   45|  2.34k|	wrapfd_setseed(50);
   46|  2.34k|	input_buf = buf;
   47|  2.34k|}
wrapfd_setseed:
   49|  2.34k|void wrapfd_setseed(uint32_t seed) {
   50|  2.34k|	memcpy(rand_state, &seed, sizeof(seed));
   51|  2.34k|	nrand48(rand_state);
   52|  2.34k|}

LLVMFuzzerTestOneInput:
   10|  2.34k|int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
   11|  2.34k|	static int once = 0;
   12|  2.34k|	if (!once) {
  ------------------
  |  Branch (12:6): [True: 1, False: 2.34k]
  ------------------
   13|      1|		setup_fuzzer();
   14|      1|		once = 1;
   15|      1|	}
   16|       |
   17|  2.34k|	if (fuzz_set_input(Data, Size) == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|  2.34k|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (17:6): [True: 0, False: 2.34k]
  ------------------
   18|      0|		return 0;
   19|      0|	}
   20|       |
   21|  2.34k|	m_malloc_set_epoch(1);
   22|       |
   23|  2.34k|	if (setjmp(fuzz.jmp) == 0) {
  ------------------
  |  Branch (23:6): [True: 2.34k, False: 0]
  ------------------
   24|  2.34k|		buffer *line = buf_getstringbuf(fuzz.input);
   25|  2.34k|		buffer *keyblob = buf_getstringbuf(fuzz.input);
   26|       |
   27|  2.34k|		unsigned int algolen;
   28|  2.34k|		char* algoname = buf_getstring(keyblob, &algolen);
   29|       |
   30|  2.34k|		if (signature_type_from_name(algoname, algolen) == DROPBEAR_SIGNATURE_NONE) {
  ------------------
  |  Branch (30:7): [True: 203, False: 2.14k]
  ------------------
   31|    203|			dropbear_exit("fuzzer imagined a bogus algorithm");
   32|    203|		}
   33|       |
   34|  2.14k|		int ret = fuzz_checkpubkey_line(line, 5, "/home/me/authorized_keys",
   35|  2.14k|			algoname, algolen,
   36|  2.14k|			keyblob->data, keyblob->len);
   37|       |
   38|  2.14k|		if (ret == DROPBEAR_SUCCESS) {
  ------------------
  |  |  102|  2.14k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (38:7): [True: 147, False: 1.99k]
  ------------------
   39|       |			/* fuzz_checkpubkey_line() should have cleaned up for failure */
   40|    147|			svr_pubkey_options_cleanup();
   41|    147|		}
   42|       |
   43|  2.14k|		buf_free(line);
   44|  2.14k|		buf_free(keyblob);
   45|  2.14k|		m_free(algoname);
  ------------------
  |  |   24|  2.14k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
   46|  2.14k|		m_malloc_free_epoch(1, 0);
   47|  2.14k|	} else {
   48|      0|		m_malloc_free_epoch(1, 1);
   49|      0|		TRACE(("dropbear_exit longjmped"))
   50|       |		/* dropbear_exit jumped here */
   51|      0|	}
   52|       |
   53|  2.14k|	return 0;
   54|  2.34k|}
fuzzer-pubkey.c:setup_fuzzer:
    6|      1|static void setup_fuzzer(void) {
    7|      1|	fuzz_common_setup();
    8|      1|}

sha256_init:
  205|  2.34k|{
  206|  2.34k|    LTC_ARGCHK(md != NULL);
  ------------------
  |  |   32|  2.34k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 2.34k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  207|       |
  208|  2.34k|    md->sha256.curlen = 0;
  209|  2.34k|    md->sha256.length = 0;
  210|  2.34k|    md->sha256.state[0] = 0x6A09E667UL;
  211|  2.34k|    md->sha256.state[1] = 0xBB67AE85UL;
  212|  2.34k|    md->sha256.state[2] = 0x3C6EF372UL;
  213|  2.34k|    md->sha256.state[3] = 0xA54FF53AUL;
  214|  2.34k|    md->sha256.state[4] = 0x510E527FUL;
  215|  2.34k|    md->sha256.state[5] = 0x9B05688CUL;
  216|  2.34k|    md->sha256.state[6] = 0x1F83D9ABUL;
  217|  2.34k|    md->sha256.state[7] = 0x5BE0CD19UL;
  218|  2.34k|    return CRYPT_OK;
  219|  2.34k|}
sha256_done:
  237|  2.34k|{
  238|  2.34k|    int i;
  239|       |
  240|  2.34k|    LTC_ARGCHK(md  != NULL);
  ------------------
  |  |   32|  2.34k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 2.34k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  241|  2.34k|    LTC_ARGCHK(out != NULL);
  ------------------
  |  |   32|  2.34k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 2.34k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  242|       |
  243|  2.34k|    if (md->sha256.curlen >= sizeof(md->sha256.buf)) {
  ------------------
  |  Branch (243:9): [True: 0, False: 2.34k]
  ------------------
  244|      0|       return CRYPT_INVALID_ARG;
  245|      0|    }
  246|       |
  247|       |
  248|       |    /* increase the length of the message */
  249|  2.34k|    md->sha256.length += md->sha256.curlen * 8;
  250|       |
  251|       |    /* append the '1' bit */
  252|  2.34k|    md->sha256.buf[md->sha256.curlen++] = (unsigned char)0x80;
  253|       |
  254|       |    /* if the length is currently above 56 bytes we append zeros
  255|       |     * then compress.  Then we can fall back to padding zeros and length
  256|       |     * encoding like normal.
  257|       |     */
  258|  2.34k|    if (md->sha256.curlen > 56) {
  ------------------
  |  Branch (258:9): [True: 0, False: 2.34k]
  ------------------
  259|      0|        while (md->sha256.curlen < 64) {
  ------------------
  |  Branch (259:16): [True: 0, False: 0]
  ------------------
  260|      0|            md->sha256.buf[md->sha256.curlen++] = (unsigned char)0;
  261|      0|        }
  262|      0|        sha256_compress(md, md->sha256.buf);
  263|      0|        md->sha256.curlen = 0;
  264|      0|    }
  265|       |
  266|       |    /* pad upto 56 bytes of zeroes */
  267|  67.0k|    while (md->sha256.curlen < 56) {
  ------------------
  |  Branch (267:12): [True: 64.6k, False: 2.34k]
  ------------------
  268|  64.6k|        md->sha256.buf[md->sha256.curlen++] = (unsigned char)0;
  269|  64.6k|    }
  270|       |
  271|       |    /* store length */
  272|  2.34k|    STORE64H(md->sha256.length, md->sha256.buf+56);
  ------------------
  |  |  101|  2.34k|#define STORE64H(x, y)                          \
  |  |  102|  2.34k|do { ulong64 __t = __builtin_bswap64 ((x));     \
  |  |  103|  2.34k|      XMEMCPY ((y), &__t, 8); } while(0)
  |  |  ------------------
  |  |  |  |   39|  2.34k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (103:39): [Folded - Ignored]
  |  |  ------------------
  ------------------
  273|  2.34k|    sha256_compress(md, md->sha256.buf);
  274|       |
  275|       |    /* copy output */
  276|  21.1k|    for (i = 0; i < 8; i++) {
  ------------------
  |  Branch (276:17): [True: 18.7k, False: 2.34k]
  ------------------
  277|  18.7k|        STORE32H(md->sha256.state[i], out+(4*i));
  ------------------
  |  |   62|  18.7k|#define STORE32H(x, y)                          \
  |  |   63|  18.7k|do { ulong32 __t = __builtin_bswap32 ((x));     \
  |  |   64|  18.7k|      XMEMCPY ((y), &__t, 4); } while(0)
  |  |  ------------------
  |  |  |  |   39|  18.7k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (64:39): [Folded - Ignored]
  |  |  ------------------
  ------------------
  278|  18.7k|    }
  279|       |#ifdef LTC_CLEAN_STACK
  280|       |    zeromem(md, sizeof(hash_state));
  281|       |#endif
  282|  2.34k|    return CRYPT_OK;
  283|  2.34k|}
sha256.c:sha256_compress:
   71|  2.34k|{
   72|  2.34k|    ulong32 S[8], W[64], t0, t1;
   73|  2.34k|#ifdef LTC_SMALL_CODE
   74|  2.34k|    ulong32 t;
   75|  2.34k|#endif
   76|  2.34k|    int i;
   77|       |
   78|       |    /* copy state into S */
   79|  21.1k|    for (i = 0; i < 8; i++) {
  ------------------
  |  Branch (79:17): [True: 18.7k, False: 2.34k]
  ------------------
   80|  18.7k|        S[i] = md->sha256.state[i];
   81|  18.7k|    }
   82|       |
   83|       |    /* copy the state into 512-bits into W[0..15] */
   84|  39.8k|    for (i = 0; i < 16; i++) {
  ------------------
  |  Branch (84:17): [True: 37.5k, False: 2.34k]
  ------------------
   85|  37.5k|        LOAD32H(W[i], buf + (4*i));
  ------------------
  |  |   66|  37.5k|#define LOAD32H(x, y)                           \
  |  |   67|  37.5k|do { XMEMCPY (&(x), (y), 4);                    \
  |  |  ------------------
  |  |  |  |   39|  37.5k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |   68|  37.5k|      (x) = __builtin_bswap32 ((x)); } while(0)
  |  |  ------------------
  |  |  |  Branch (68:46): [Folded - Ignored]
  |  |  ------------------
  ------------------
   86|  37.5k|    }
   87|       |
   88|       |    /* fill W[16..63] */
   89|   115k|    for (i = 16; i < 64; i++) {
  ------------------
  |  Branch (89:18): [True: 112k, False: 2.34k]
  ------------------
   90|   112k|        W[i] = Gamma1(W[i - 2]) + W[i - 7] + Gamma0(W[i - 15]) + W[i - 16];
  ------------------
  |  |   63|   112k|#define Gamma1(x)       (S(x, 17) ^ S(x, 19) ^ R(x, 10))
  |  |  ------------------
  |  |  |  |   58|   112k|#define S(x, n)         RORc((x),(n))
  |  |  |  |  ------------------
  |  |  |  |  |  |  283|   112k|#define RORc(word,i) ({ \
  |  |  |  |  |  |  284|   112k|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  |  |  285|   112k|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  |  |  286|   112k|            "=r" (__RORc_tmp) : \
  |  |  |  |  |  |  287|   112k|            "0" (__RORc_tmp), \
  |  |  |  |  |  |  288|   112k|            "I" (i)); \
  |  |  |  |  |  |  289|   112k|            __RORc_tmp; \
  |  |  |  |  |  |  290|   112k|   })
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define Gamma1(x)       (S(x, 17) ^ S(x, 19) ^ R(x, 10))
  |  |  ------------------
  |  |  |  |   58|   112k|#define S(x, n)         RORc((x),(n))
  |  |  |  |  ------------------
  |  |  |  |  |  |  283|   112k|#define RORc(word,i) ({ \
  |  |  |  |  |  |  284|   112k|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  |  |  285|   112k|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  |  |  286|   112k|            "=r" (__RORc_tmp) : \
  |  |  |  |  |  |  287|   112k|            "0" (__RORc_tmp), \
  |  |  |  |  |  |  288|   112k|            "I" (i)); \
  |  |  |  |  |  |  289|   112k|            __RORc_tmp; \
  |  |  |  |  |  |  290|   112k|   })
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define Gamma1(x)       (S(x, 17) ^ S(x, 19) ^ R(x, 10))
  |  |  ------------------
  |  |  |  |   59|   112k|#define R(x, n)         (((x)&0xFFFFFFFFUL)>>(n))
  |  |  ------------------
  ------------------
                      W[i] = Gamma1(W[i - 2]) + W[i - 7] + Gamma0(W[i - 15]) + W[i - 16];
  ------------------
  |  |   62|   112k|#define Gamma0(x)       (S(x, 7) ^ S(x, 18) ^ R(x, 3))
  |  |  ------------------
  |  |  |  |   58|   112k|#define S(x, n)         RORc((x),(n))
  |  |  |  |  ------------------
  |  |  |  |  |  |  283|   112k|#define RORc(word,i) ({ \
  |  |  |  |  |  |  284|   112k|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  |  |  285|   112k|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  |  |  286|   112k|            "=r" (__RORc_tmp) : \
  |  |  |  |  |  |  287|   112k|            "0" (__RORc_tmp), \
  |  |  |  |  |  |  288|   112k|            "I" (i)); \
  |  |  |  |  |  |  289|   112k|            __RORc_tmp; \
  |  |  |  |  |  |  290|   112k|   })
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define Gamma0(x)       (S(x, 7) ^ S(x, 18) ^ R(x, 3))
  |  |  ------------------
  |  |  |  |   58|   112k|#define S(x, n)         RORc((x),(n))
  |  |  |  |  ------------------
  |  |  |  |  |  |  283|   112k|#define RORc(word,i) ({ \
  |  |  |  |  |  |  284|   112k|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  |  |  285|   112k|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  |  |  286|   112k|            "=r" (__RORc_tmp) : \
  |  |  |  |  |  |  287|   112k|            "0" (__RORc_tmp), \
  |  |  |  |  |  |  288|   112k|            "I" (i)); \
  |  |  |  |  |  |  289|   112k|            __RORc_tmp; \
  |  |  |  |  |  |  290|   112k|   })
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define Gamma0(x)       (S(x, 7) ^ S(x, 18) ^ R(x, 3))
  |  |  ------------------
  |  |  |  |   59|   112k|#define R(x, n)         (((x)&0xFFFFFFFFUL)>>(n))
  |  |  ------------------
  ------------------
   91|   112k|    }
   92|       |
   93|       |    /* Compress */
   94|  2.34k|#ifdef LTC_SMALL_CODE
   95|  2.34k|#define RND(a,b,c,d,e,f,g,h,i)                         \
   96|  2.34k|     t0 = h + Sigma1(e) + Ch(e, f, g) + K[i] + W[i];   \
   97|  2.34k|     t1 = Sigma0(a) + Maj(a, b, c);                    \
   98|  2.34k|     d += t0;                                          \
   99|  2.34k|     h  = t0 + t1;
  100|       |
  101|   152k|     for (i = 0; i < 64; ++i) {
  ------------------
  |  Branch (101:18): [True: 150k, False: 2.34k]
  ------------------
  102|   150k|         RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],i);
  ------------------
  |  |   96|   150k|     t0 = h + Sigma1(e) + Ch(e, f, g) + K[i] + W[i];   \
  |  |  ------------------
  |  |  |  |   61|   150k|#define Sigma1(x)       (S(x, 6) ^ S(x, 11) ^ S(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |   58|   150k|#define S(x, n)         RORc((x),(n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  283|   150k|#define RORc(word,i) ({ \
  |  |  |  |  |  |  |  |  284|   150k|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  |  |  |  |  285|   150k|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  |  |  |  |  286|   150k|            "=r" (__RORc_tmp) : \
  |  |  |  |  |  |  |  |  287|   150k|            "0" (__RORc_tmp), \
  |  |  |  |  |  |  |  |  288|   150k|            "I" (i)); \
  |  |  |  |  |  |  |  |  289|   150k|            __RORc_tmp; \
  |  |  |  |  |  |  |  |  290|   150k|   })
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define Sigma1(x)       (S(x, 6) ^ S(x, 11) ^ S(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |   58|   150k|#define S(x, n)         RORc((x),(n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  283|   150k|#define RORc(word,i) ({ \
  |  |  |  |  |  |  |  |  284|   150k|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  |  |  |  |  285|   150k|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  |  |  |  |  286|   150k|            "=r" (__RORc_tmp) : \
  |  |  |  |  |  |  |  |  287|   150k|            "0" (__RORc_tmp), \
  |  |  |  |  |  |  |  |  288|   150k|            "I" (i)); \
  |  |  |  |  |  |  |  |  289|   150k|            __RORc_tmp; \
  |  |  |  |  |  |  |  |  290|   150k|   })
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define Sigma1(x)       (S(x, 6) ^ S(x, 11) ^ S(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |   58|   150k|#define S(x, n)         RORc((x),(n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  283|   150k|#define RORc(word,i) ({ \
  |  |  |  |  |  |  |  |  284|   150k|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  |  |  |  |  285|   150k|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  |  |  |  |  286|   150k|            "=r" (__RORc_tmp) : \
  |  |  |  |  |  |  |  |  287|   150k|            "0" (__RORc_tmp), \
  |  |  |  |  |  |  |  |  288|   150k|            "I" (i)); \
  |  |  |  |  |  |  |  |  289|   150k|            __RORc_tmp; \
  |  |  |  |  |  |  |  |  290|   150k|   })
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                    t0 = h + Sigma1(e) + Ch(e, f, g) + K[i] + W[i];   \
  |  |  ------------------
  |  |  |  |   56|   150k|#define Ch(x,y,z)       (z ^ (x & (y ^ z)))
  |  |  ------------------
  |  |   97|   150k|     t1 = Sigma0(a) + Maj(a, b, c);                    \
  |  |  ------------------
  |  |  |  |   60|   150k|#define Sigma0(x)       (S(x, 2) ^ S(x, 13) ^ S(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |   58|   150k|#define S(x, n)         RORc((x),(n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  283|   150k|#define RORc(word,i) ({ \
  |  |  |  |  |  |  |  |  284|   150k|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  |  |  |  |  285|   150k|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  |  |  |  |  286|   150k|            "=r" (__RORc_tmp) : \
  |  |  |  |  |  |  |  |  287|   150k|            "0" (__RORc_tmp), \
  |  |  |  |  |  |  |  |  288|   150k|            "I" (i)); \
  |  |  |  |  |  |  |  |  289|   150k|            __RORc_tmp; \
  |  |  |  |  |  |  |  |  290|   150k|   })
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define Sigma0(x)       (S(x, 2) ^ S(x, 13) ^ S(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |   58|   150k|#define S(x, n)         RORc((x),(n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  283|   150k|#define RORc(word,i) ({ \
  |  |  |  |  |  |  |  |  284|   150k|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  |  |  |  |  285|   150k|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  |  |  |  |  286|   150k|            "=r" (__RORc_tmp) : \
  |  |  |  |  |  |  |  |  287|   150k|            "0" (__RORc_tmp), \
  |  |  |  |  |  |  |  |  288|   150k|            "I" (i)); \
  |  |  |  |  |  |  |  |  289|   150k|            __RORc_tmp; \
  |  |  |  |  |  |  |  |  290|   150k|   })
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define Sigma0(x)       (S(x, 2) ^ S(x, 13) ^ S(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |   58|   150k|#define S(x, n)         RORc((x),(n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  283|   150k|#define RORc(word,i) ({ \
  |  |  |  |  |  |  |  |  284|   150k|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  |  |  |  |  285|   150k|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  |  |  |  |  286|   150k|            "=r" (__RORc_tmp) : \
  |  |  |  |  |  |  |  |  287|   150k|            "0" (__RORc_tmp), \
  |  |  |  |  |  |  |  |  288|   150k|            "I" (i)); \
  |  |  |  |  |  |  |  |  289|   150k|            __RORc_tmp; \
  |  |  |  |  |  |  |  |  290|   150k|   })
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                    t1 = Sigma0(a) + Maj(a, b, c);                    \
  |  |  ------------------
  |  |  |  |   57|   150k|#define Maj(x,y,z)      (((x | y) & z) | (x & y))
  |  |  ------------------
  |  |   98|   150k|     d += t0;                                          \
  |  |   99|   150k|     h  = t0 + t1;
  ------------------
  103|   150k|         t = S[7]; S[7] = S[6]; S[6] = S[5]; S[5] = S[4];
  104|   150k|         S[4] = S[3]; S[3] = S[2]; S[2] = S[1]; S[1] = S[0]; S[0] = t;
  105|   150k|     }
  106|       |#else
  107|       |#define RND(a,b,c,d,e,f,g,h,i,ki)                    \
  108|       |     t0 = h + Sigma1(e) + Ch(e, f, g) + ki + W[i];   \
  109|       |     t1 = Sigma0(a) + Maj(a, b, c);                  \
  110|       |     d += t0;                                        \
  111|       |     h  = t0 + t1;
  112|       |
  113|       |    RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],0,0x428a2f98);
  114|       |    RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],1,0x71374491);
  115|       |    RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],2,0xb5c0fbcf);
  116|       |    RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],3,0xe9b5dba5);
  117|       |    RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],4,0x3956c25b);
  118|       |    RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],5,0x59f111f1);
  119|       |    RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],6,0x923f82a4);
  120|       |    RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],7,0xab1c5ed5);
  121|       |    RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],8,0xd807aa98);
  122|       |    RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],9,0x12835b01);
  123|       |    RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],10,0x243185be);
  124|       |    RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],11,0x550c7dc3);
  125|       |    RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],12,0x72be5d74);
  126|       |    RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],13,0x80deb1fe);
  127|       |    RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],14,0x9bdc06a7);
  128|       |    RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],15,0xc19bf174);
  129|       |    RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],16,0xe49b69c1);
  130|       |    RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],17,0xefbe4786);
  131|       |    RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],18,0x0fc19dc6);
  132|       |    RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],19,0x240ca1cc);
  133|       |    RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],20,0x2de92c6f);
  134|       |    RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],21,0x4a7484aa);
  135|       |    RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],22,0x5cb0a9dc);
  136|       |    RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],23,0x76f988da);
  137|       |    RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],24,0x983e5152);
  138|       |    RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],25,0xa831c66d);
  139|       |    RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],26,0xb00327c8);
  140|       |    RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],27,0xbf597fc7);
  141|       |    RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],28,0xc6e00bf3);
  142|       |    RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],29,0xd5a79147);
  143|       |    RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],30,0x06ca6351);
  144|       |    RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],31,0x14292967);
  145|       |    RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],32,0x27b70a85);
  146|       |    RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],33,0x2e1b2138);
  147|       |    RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],34,0x4d2c6dfc);
  148|       |    RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],35,0x53380d13);
  149|       |    RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],36,0x650a7354);
  150|       |    RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],37,0x766a0abb);
  151|       |    RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],38,0x81c2c92e);
  152|       |    RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],39,0x92722c85);
  153|       |    RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],40,0xa2bfe8a1);
  154|       |    RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],41,0xa81a664b);
  155|       |    RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],42,0xc24b8b70);
  156|       |    RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],43,0xc76c51a3);
  157|       |    RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],44,0xd192e819);
  158|       |    RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],45,0xd6990624);
  159|       |    RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],46,0xf40e3585);
  160|       |    RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],47,0x106aa070);
  161|       |    RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],48,0x19a4c116);
  162|       |    RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],49,0x1e376c08);
  163|       |    RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],50,0x2748774c);
  164|       |    RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],51,0x34b0bcb5);
  165|       |    RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],52,0x391c0cb3);
  166|       |    RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],53,0x4ed8aa4a);
  167|       |    RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],54,0x5b9cca4f);
  168|       |    RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],55,0x682e6ff3);
  169|       |    RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],56,0x748f82ee);
  170|       |    RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],57,0x78a5636f);
  171|       |    RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],58,0x84c87814);
  172|       |    RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],59,0x8cc70208);
  173|       |    RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],60,0x90befffa);
  174|       |    RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],61,0xa4506ceb);
  175|       |    RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],62,0xbef9a3f7);
  176|       |    RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],63,0xc67178f2);
  177|       |
  178|       |#undef RND
  179|       |
  180|       |#endif
  181|       |
  182|       |    /* feedback */
  183|  21.1k|    for (i = 0; i < 8; i++) {
  ------------------
  |  Branch (183:17): [True: 18.7k, False: 2.34k]
  ------------------
  184|  18.7k|        md->sha256.state[i] = md->sha256.state[i] + S[i];
  185|  18.7k|    }
  186|  2.34k|    return CRYPT_OK;
  187|  2.34k|}

sha256_process:
  491|  4.69k|int func_name (hash_state * md, const unsigned char *in, unsigned long inlen)               \
  492|  4.69k|{                                                                                           \
  493|  4.69k|    unsigned long n;                                                                        \
  494|  4.69k|    int           err;                                                                      \
  495|  4.69k|    LTC_ARGCHK(md != NULL);                                                                 \
  ------------------
  |  |   32|  4.69k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 4.69k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  496|  4.69k|    LTC_ARGCHK(in != NULL);                                                                 \
  ------------------
  |  |   32|  4.69k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 4.69k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  497|  4.69k|    if (md-> state_var .curlen > sizeof(md-> state_var .buf)) {                             \
  ------------------
  |  Branch (497:9): [True: 0, False: 4.69k]
  ------------------
  498|      0|       return CRYPT_INVALID_ARG;                                                            \
  499|      0|    }                                                                                       \
  500|  4.69k|    if ((md-> state_var .length + inlen) < md-> state_var .length) {                        \
  ------------------
  |  Branch (500:9): [True: 0, False: 4.69k]
  ------------------
  501|      0|      return CRYPT_HASH_OVERFLOW;                                                           \
  502|      0|    }                                                                                       \
  503|  9.38k|    while (inlen > 0) {                                                                     \
  ------------------
  |  Branch (503:12): [True: 4.69k, False: 4.69k]
  ------------------
  504|  4.69k|        if (md-> state_var .curlen == 0 && inlen >= block_size) {                           \
  ------------------
  |  Branch (504:13): [True: 2.34k, False: 2.34k]
  |  Branch (504:44): [True: 0, False: 2.34k]
  ------------------
  505|      0|           if ((err = compress_name (md, (unsigned char *)in)) != CRYPT_OK) {               \
  ------------------
  |  Branch (505:16): [True: 0, False: 0]
  ------------------
  506|      0|              return err;                                                                   \
  507|      0|           }                                                                                \
  508|      0|           md-> state_var .length += block_size * 8;                                        \
  509|      0|           in             += block_size;                                                    \
  510|      0|           inlen          -= block_size;                                                    \
  511|  4.69k|        } else {                                                                            \
  512|  4.69k|           n = MIN(inlen, (block_size - md-> state_var .curlen));                           \
  ------------------
  |  |  425|  4.69k|   #define MIN(x, y) ( ((x)<(y))?(x):(y) )
  |  |  ------------------
  |  |  |  Branch (425:24): [True: 4.69k, False: 0]
  |  |  ------------------
  ------------------
  513|  4.69k|           XMEMCPY(md-> state_var .buf + md-> state_var.curlen, in, (size_t)n);             \
  ------------------
  |  |   39|  4.69k|#define XMEMCPY  memcpy
  ------------------
  514|  4.69k|           md-> state_var .curlen += n;                                                     \
  515|  4.69k|           in             += n;                                                             \
  516|  4.69k|           inlen          -= n;                                                             \
  517|  4.69k|           if (md-> state_var .curlen == block_size) {                                      \
  ------------------
  |  Branch (517:16): [True: 0, False: 4.69k]
  ------------------
  518|      0|              if ((err = compress_name (md, md-> state_var .buf)) != CRYPT_OK) {            \
  ------------------
  |  Branch (518:19): [True: 0, False: 0]
  ------------------
  519|      0|                 return err;                                                                \
  520|      0|              }                                                                             \
  521|      0|              md-> state_var .length += 8*block_size;                                       \
  522|      0|              md-> state_var .curlen = 0;                                                   \
  523|      0|           }                                                                                \
  524|  4.69k|       }                                                                                    \
  525|  4.69k|    }                                                                                       \
  526|  4.69k|    return CRYPT_OK;                                                                        \
  527|  4.69k|}

base64_decode:
  148|  1.51k|{
  149|  1.51k|    return _base64_decode_internal(in, inlen, out, outlen, map_base64, relaxed);
  150|  1.51k|}
base64_decode.c:_base64_decode_internal:
   81|  1.51k|{
   82|  1.51k|   unsigned long t, x, y, z;
   83|  1.51k|   unsigned char c;
   84|  1.51k|   int           g;
   85|       |
   86|  1.51k|   LTC_ARGCHK(in     != NULL);
  ------------------
  |  |   32|  1.51k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 1.51k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   87|  1.51k|   LTC_ARGCHK(out    != NULL);
  ------------------
  |  |   32|  1.51k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 1.51k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   88|  1.51k|   LTC_ARGCHK(outlen != NULL);
  ------------------
  |  |   32|  1.51k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 1.51k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   89|       |
   90|  1.51k|   g = 0; /* '=' counter */
   91|  99.8k|   for (x = y = z = t = 0; x < inlen; x++) {
  ------------------
  |  Branch (91:28): [True: 98.3k, False: 1.51k]
  ------------------
   92|  98.3k|       c = map[in[x]&0xFF];
   93|  98.3k|       if (c == 254) {
  ------------------
  |  Branch (93:12): [True: 4.81k, False: 93.5k]
  ------------------
   94|  4.81k|          g++;
   95|  4.81k|          continue;
   96|  4.81k|       }
   97|  93.5k|       else if (is_strict && g > 0) {
  ------------------
  |  Branch (97:17): [True: 0, False: 93.5k]
  |  Branch (97:30): [True: 0, False: 0]
  ------------------
   98|       |          /* we only allow '=' to be at the end */
   99|      0|          return CRYPT_INVALID_PACKET;
  100|      0|       }
  101|  93.5k|       if (c == 255) {
  ------------------
  |  Branch (101:12): [True: 16.4k, False: 77.1k]
  ------------------
  102|  16.4k|          if (is_strict)
  ------------------
  |  Branch (102:15): [True: 0, False: 16.4k]
  ------------------
  103|      0|             return CRYPT_INVALID_PACKET;
  104|  16.4k|          else
  105|  16.4k|             continue;
  106|  16.4k|       }
  107|       |
  108|  77.1k|       t = (t<<6)|c;
  109|       |
  110|  77.1k|       if (++y == 4) {
  ------------------
  |  Branch (110:12): [True: 18.2k, False: 58.8k]
  ------------------
  111|  18.2k|          if (z + 3 > *outlen) return CRYPT_BUFFER_OVERFLOW;
  ------------------
  |  Branch (111:15): [True: 0, False: 18.2k]
  ------------------
  112|  18.2k|          out[z++] = (unsigned char)((t>>16)&255);
  113|  18.2k|          out[z++] = (unsigned char)((t>>8)&255);
  114|  18.2k|          out[z++] = (unsigned char)(t&255);
  115|  18.2k|          y = t = 0;
  116|  18.2k|       }
  117|  77.1k|   }
  118|       |
  119|  1.51k|   if (y != 0) {
  ------------------
  |  Branch (119:8): [True: 1.44k, False: 70]
  ------------------
  120|  1.44k|      int allow_b64url = 0;
  121|       |#ifdef LTC_BASE64_URL
  122|       |      if (map == map_base64url) {
  123|       |        allow_b64url = 1;
  124|       |      }
  125|       |#endif
  126|  1.44k|      if (y == 1) return CRYPT_INVALID_PACKET;
  ------------------
  |  Branch (126:11): [True: 23, False: 1.42k]
  ------------------
  127|  1.42k|      if ((y + g) != 4 && is_strict && !allow_b64url) return CRYPT_INVALID_PACKET;
  ------------------
  |  Branch (127:11): [True: 1.41k, False: 6]
  |  Branch (127:27): [True: 0, False: 1.41k]
  |  Branch (127:40): [True: 0, False: 0]
  ------------------
  128|  1.42k|      t = t << (6 * (4 - y));
  129|  1.42k|      if (z + y - 1 > *outlen) return CRYPT_BUFFER_OVERFLOW;
  ------------------
  |  Branch (129:11): [True: 0, False: 1.42k]
  ------------------
  130|  1.42k|      if (y >= 2) out[z++] = (unsigned char) ((t >> 16) & 255);
  ------------------
  |  Branch (130:11): [True: 1.42k, False: 0]
  ------------------
  131|  1.42k|      if (y == 3) out[z++] = (unsigned char) ((t >> 8) & 255);
  ------------------
  |  Branch (131:11): [True: 1.37k, False: 45]
  ------------------
  132|  1.42k|   }
  133|  1.49k|   *outlen = z;
  134|  1.49k|   return CRYPT_OK;
  135|  1.51k|}

register_cipher:
   22|      1|{
   23|      1|   int x;
   24|       |
   25|      1|   LTC_ARGCHK(cipher != NULL);
  ------------------
  |  |   32|      1|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 1]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   26|       |
   27|       |   /* is it already registered? */
   28|      1|   LTC_MUTEX_LOCK(&ltc_cipher_mutex);
   29|      6|   for (x = 0; x < TAB_SIZE; x++) {
  ------------------
  |  |   14|      6|#define TAB_SIZE      5
  ------------------
  |  Branch (29:16): [True: 5, False: 1]
  ------------------
   30|      5|       if (cipher_descriptor[x].name != NULL && cipher_descriptor[x].ID == cipher->ID) {
  ------------------
  |  Branch (30:12): [True: 0, False: 5]
  |  Branch (30:49): [True: 0, False: 0]
  ------------------
   31|      0|          LTC_MUTEX_UNLOCK(&ltc_cipher_mutex);
   32|      0|          return x;
   33|      0|       }
   34|      5|   }
   35|       |
   36|       |   /* find a blank spot */
   37|      1|   for (x = 0; x < TAB_SIZE; x++) {
  ------------------
  |  |   14|      1|#define TAB_SIZE      5
  ------------------
  |  Branch (37:16): [True: 1, False: 0]
  ------------------
   38|      1|       if (cipher_descriptor[x].name == NULL) {
  ------------------
  |  Branch (38:12): [True: 1, False: 0]
  ------------------
   39|      1|          XMEMCPY(&cipher_descriptor[x], cipher, sizeof(struct ltc_cipher_descriptor));
  ------------------
  |  |   39|      1|#define XMEMCPY  memcpy
  ------------------
   40|      1|          LTC_MUTEX_UNLOCK(&ltc_cipher_mutex);
   41|      1|          return x;
   42|      1|       }
   43|      1|   }
   44|       |
   45|       |   /* no spot */
   46|      0|   LTC_MUTEX_UNLOCK(&ltc_cipher_mutex);
   47|      0|   return -1;
   48|      1|}

register_hash:
   22|      4|{
   23|      4|   int x;
   24|       |
   25|      4|   LTC_ARGCHK(hash != NULL);
  ------------------
  |  |   32|      4|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 4]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   26|       |
   27|       |   /* is it already registered? */
   28|      4|   LTC_MUTEX_LOCK(&ltc_hash_mutex);
   29|     24|   for (x = 0; x < TAB_SIZE; x++) {
  ------------------
  |  |   14|     24|#define TAB_SIZE      5
  ------------------
  |  Branch (29:16): [True: 20, False: 4]
  ------------------
   30|     20|       if (XMEMCMP(&hash_descriptor[x], hash, sizeof(struct ltc_hash_descriptor)) == 0) {
  ------------------
  |  |   45|     20|#define XMEMCMP  memcmp
  ------------------
  |  Branch (30:12): [True: 0, False: 20]
  ------------------
   31|      0|          LTC_MUTEX_UNLOCK(&ltc_hash_mutex);
   32|      0|          return x;
   33|      0|       }
   34|     20|   }
   35|       |
   36|       |   /* find a blank spot */
   37|     10|   for (x = 0; x < TAB_SIZE; x++) {
  ------------------
  |  |   14|     10|#define TAB_SIZE      5
  ------------------
  |  Branch (37:16): [True: 10, False: 0]
  ------------------
   38|     10|       if (hash_descriptor[x].name == NULL) {
  ------------------
  |  Branch (38:12): [True: 4, False: 6]
  ------------------
   39|      4|          XMEMCPY(&hash_descriptor[x], hash, sizeof(struct ltc_hash_descriptor));
  ------------------
  |  |   39|      4|#define XMEMCPY  memcpy
  ------------------
   40|      4|          LTC_MUTEX_UNLOCK(&ltc_hash_mutex);
   41|      4|          return x;
   42|      4|       }
   43|     10|   }
   44|       |
   45|       |   /* no spot */
   46|      0|   LTC_MUTEX_UNLOCK(&ltc_hash_mutex);
   47|      0|   return -1;
   48|      4|}

register_prng:
   22|      1|{
   23|      1|   int x;
   24|       |
   25|      1|   LTC_ARGCHK(prng != NULL);
  ------------------
  |  |   32|      1|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 1]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   26|       |
   27|       |   /* is it already registered? */
   28|      1|   LTC_MUTEX_LOCK(&ltc_prng_mutex);
   29|      6|   for (x = 0; x < TAB_SIZE; x++) {
  ------------------
  |  |   14|      6|#define TAB_SIZE      5
  ------------------
  |  Branch (29:16): [True: 5, False: 1]
  ------------------
   30|      5|       if (XMEMCMP(&prng_descriptor[x], prng, sizeof(struct ltc_prng_descriptor)) == 0) {
  ------------------
  |  |   45|      5|#define XMEMCMP  memcmp
  ------------------
  |  Branch (30:12): [True: 0, False: 5]
  ------------------
   31|      0|          LTC_MUTEX_UNLOCK(&ltc_prng_mutex);
   32|      0|          return x;
   33|      0|       }
   34|      5|   }
   35|       |
   36|       |   /* find a blank spot */
   37|      1|   for (x = 0; x < TAB_SIZE; x++) {
  ------------------
  |  |   14|      1|#define TAB_SIZE      5
  ------------------
  |  Branch (37:16): [True: 1, False: 0]
  ------------------
   38|      1|       if (prng_descriptor[x].name == NULL) {
  ------------------
  |  Branch (38:12): [True: 1, False: 0]
  ------------------
   39|      1|          XMEMCPY(&prng_descriptor[x], prng, sizeof(struct ltc_prng_descriptor));
  ------------------
  |  |   39|      1|#define XMEMCPY  memcpy
  ------------------
   40|      1|          LTC_MUTEX_UNLOCK(&ltc_prng_mutex);
   41|      1|          return x;
   42|      1|       }
   43|      1|   }
   44|       |
   45|       |   /* no spot */
   46|      0|   LTC_MUTEX_UNLOCK(&ltc_prng_mutex);
   47|      0|   return -1;
   48|      1|}

mp_rand_source:
   10|      1|{
   11|       |   /* Dropbear, don't reset to platform if source==NULL */
   12|      1|   s_mp_rand_source = source;
   13|      1|}

buf_new:
   41|  7.81k|buffer* buf_new(unsigned int size) {
   42|  7.81k|	buffer* buf;
   43|  7.81k|	if (size > BUF_MAX_SIZE) {
  ------------------
  |  |   35|  7.81k|#define BUF_MAX_SIZE 1000000000
  ------------------
  |  Branch (43:6): [True: 0, False: 7.81k]
  ------------------
   44|      0|		dropbear_exit("buf->size too big");
   45|      0|	}
   46|       |
   47|  7.81k|	buf = (buffer*)m_malloc(sizeof(buffer)+size);
   48|  7.81k|	buf->data = (unsigned char*)buf + sizeof(buffer);
   49|  7.81k|	buf->size = size;
   50|  7.81k|	return buf;
   51|  7.81k|}
buf_free:
   54|  7.14k|void buf_free(buffer* buf) {
   55|  7.14k|	m_free(buf);
  ------------------
  |  |   24|  7.14k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
   56|  7.14k|}
buf_setlen:
   95|  1.55k|void buf_setlen(buffer* buf, unsigned int len) {
   96|  1.55k|	if (len > buf->size) {
  ------------------
  |  Branch (96:6): [True: 0, False: 1.55k]
  ------------------
   97|      0|		dropbear_exit("Bad buf_setlen");
   98|      0|	}
   99|  1.55k|	buf->len = len;
  100|  1.55k|	buf->pos = MIN(buf->pos, buf->len);
  101|  1.55k|}
buf_incrlen:
  104|  5.99k|void buf_incrlen(buffer* buf, unsigned int incr) {
  105|  5.99k|	if (incr > BUF_MAX_INCR || buf->len + incr > buf->size) {
  ------------------
  |  |   34|  11.9k|#define BUF_MAX_INCR 1000000000
  ------------------
  |  Branch (105:6): [True: 0, False: 5.99k]
  |  Branch (105:29): [True: 0, False: 5.99k]
  ------------------
  106|      0|		dropbear_exit("Bad buf_incrlen");
  107|      0|	}
  108|  5.99k|	buf->len += incr;
  109|  5.99k|}
buf_setpos:
  111|  7.43k|void buf_setpos(buffer* buf, unsigned int pos) {
  112|       |
  113|  7.43k|	if (pos > buf->len) {
  ------------------
  |  Branch (113:6): [True: 0, False: 7.43k]
  ------------------
  114|      0|		dropbear_exit("Bad buf_setpos");
  115|      0|	}
  116|  7.43k|	buf->pos = pos;
  117|  7.43k|}
buf_incrwritepos:
  120|  1.74k|void buf_incrwritepos(buffer* buf, unsigned int incr) {
  121|  1.74k|	if (incr > BUF_MAX_INCR || buf->pos + incr > buf->size) {
  ------------------
  |  |   34|  3.49k|#define BUF_MAX_INCR 1000000000
  ------------------
  |  Branch (121:6): [True: 0, False: 1.74k]
  |  Branch (121:29): [True: 0, False: 1.74k]
  ------------------
  122|      0|		dropbear_exit("Bad buf_incrwritepos");
  123|      0|	}
  124|  1.74k|	buf->pos += incr;
  125|  1.74k|	if (buf->pos > buf->len) {
  ------------------
  |  Branch (125:6): [True: 1.74k, False: 0]
  ------------------
  126|  1.74k|		buf->len = buf->pos;
  127|  1.74k|	}
  128|  1.74k|}
buf_incrpos:
  131|  19.8k|void buf_incrpos(buffer* buf, unsigned int incr) {
  132|  19.8k|	if (incr > BUF_MAX_INCR 
  ------------------
  |  |   34|  39.7k|#define BUF_MAX_INCR 1000000000
  ------------------
  |  Branch (132:6): [True: 0, False: 19.8k]
  ------------------
  133|  19.8k|		|| (buf->pos + incr) > buf->len) {
  ------------------
  |  Branch (133:6): [True: 0, False: 19.8k]
  ------------------
  134|      0|		dropbear_exit("Bad buf_incrpos");
  135|      0|	}
  136|  19.8k|	buf->pos += incr;
  137|  19.8k|}
buf_decrpos:
  140|  1.74k|void buf_decrpos(buffer* buf, unsigned int decr) {
  141|  1.74k|	if (decr > buf->pos) {
  ------------------
  |  Branch (141:6): [True: 0, False: 1.74k]
  ------------------
  142|      0|		dropbear_exit("Bad buf_decrpos");
  143|      0|	}
  144|  1.74k|	buf->pos -= decr;
  145|  1.74k|}
buf_getbyte:
  148|   415k|unsigned char buf_getbyte(buffer* buf) {
  149|       |
  150|       |	/* This check is really just ==, but the >= allows us to check for the
  151|       |	 * bad case of pos > len, which should _never_ happen. */
  152|   415k|	if (buf->pos >= buf->len) {
  ------------------
  |  Branch (152:6): [True: 0, False: 415k]
  ------------------
  153|      0|		dropbear_exit("Bad buf_getbyte");
  154|      0|	}
  155|   415k|	return buf->data[buf->pos++];
  156|   415k|}
buf_getptr:
  180|  90.7k|unsigned char* buf_getptr(const buffer* buf, unsigned int len) {
  181|       |
  182|  90.7k|	if (len > BUF_MAX_INCR || buf->pos + len > buf->len) {
  ------------------
  |  |   34|   181k|#define BUF_MAX_INCR 1000000000
  ------------------
  |  Branch (182:6): [True: 0, False: 90.7k]
  |  Branch (182:28): [True: 131, False: 90.5k]
  ------------------
  183|    131|		dropbear_exit("Bad buf_getptr");
  184|    131|	}
  185|  90.5k|	return &buf->data[buf->pos];
  186|  90.7k|}
buf_getwriteptr:
  190|  7.81k|unsigned char* buf_getwriteptr(const buffer* buf, unsigned int len) {
  191|       |
  192|  7.81k|	if (len > BUF_MAX_INCR || buf->pos + len > buf->size) {
  ------------------
  |  |   34|  15.6k|#define BUF_MAX_INCR 1000000000
  ------------------
  |  Branch (192:6): [True: 0, False: 7.81k]
  |  Branch (192:28): [True: 0, False: 7.81k]
  ------------------
  193|      0|		dropbear_exit("Bad buf_getwriteptr");
  194|      0|	}
  195|  7.81k|	return &buf->data[buf->pos];
  196|  7.81k|}
buf_getstring:
  201|  2.23k|char* buf_getstring(buffer* buf, unsigned int *retlen) {
  202|       |
  203|  2.23k|	unsigned int len;
  204|  2.23k|	char* ret;
  205|  2.23k|	void* src = NULL;
  206|  2.23k|	len = buf_getint(buf);
  207|  2.23k|	if (len > MAX_STRING_LEN) {
  ------------------
  |  |  228|  2.23k|#define MAX_STRING_LEN (MAX(MAX_CMD_LEN, 2400)) /* Sun SSH needs 2400 for algos,
  ------------------
  |  Branch (207:6): [True: 32, False: 2.20k]
  ------------------
  208|     32|		dropbear_exit("String too long");
  209|     32|	}
  210|       |
  211|  2.20k|	if (retlen != NULL) {
  ------------------
  |  Branch (211:6): [True: 2.20k, False: 4]
  ------------------
  212|  2.20k|		*retlen = len;
  213|  2.20k|	}
  214|  2.20k|	src = buf_getptr(buf, len);
  215|  2.20k|	ret = m_malloc(len+1);
  216|  2.20k|	memcpy(ret, src, len);
  217|  2.20k|	buf_incrpos(buf, len);
  218|  2.20k|	ret[len] = '\0';
  219|       |
  220|  2.20k|	return ret;
  221|  2.23k|}
buf_getstringbuf:
  246|  4.60k|buffer * buf_getstringbuf(buffer *buf) {
  247|  4.60k|	return buf_getstringbuf_int(buf, 0);
  248|  4.60k|}
buf_getint:
  263|  8.16k|unsigned int buf_getint(buffer* buf) {
  264|  8.16k|	unsigned int ret;
  265|       |
  266|  8.16k|	LOAD32H(ret, buf_getptr(buf, 4));
  ------------------
  |  |   66|  8.16k|#define LOAD32H(x, y)                           \
  |  |   67|  8.16k|do { XMEMCPY (&(x), (y), 4);                    \
  |  |  ------------------
  |  |  |  |   39|  8.16k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |   68|  8.16k|      (x) = __builtin_bswap32 ((x)); } while(0)
  |  |  ------------------
  |  |  |  Branch (68:46): [Folded - Ignored]
  |  |  ------------------
  ------------------
  267|  8.16k|	buf_incrpos(buf, 4);
  268|  8.16k|	return ret;
  269|  8.16k|}
buf_putbytes:
  294|  1.74k|void buf_putbytes(buffer *buf, const unsigned char *bytes, unsigned int len) {
  295|  1.74k|	memcpy(buf_getwriteptr(buf, len), bytes, len);
  296|  1.74k|	buf_incrwritepos(buf, len);
  297|  1.74k|}
buffer.c:buf_getstringbuf_int:
  224|  4.60k|static buffer * buf_getstringbuf_int(buffer *buf, int incllen) {
  225|  4.60k|	buffer *ret = NULL;
  226|  4.60k|	unsigned int len = buf_getint(buf);
  227|  4.60k|	int extra = 0;
  228|  4.60k|	if (len > MAX_STRING_LEN) {
  ------------------
  |  |  228|  4.60k|#define MAX_STRING_LEN (MAX(MAX_CMD_LEN, 2400)) /* Sun SSH needs 2400 for algos,
  ------------------
  |  Branch (228:6): [True: 38, False: 4.56k]
  ------------------
  229|     38|		dropbear_exit("String too long");
  230|     38|	}
  231|  4.56k|	if (incllen) {
  ------------------
  |  Branch (231:6): [True: 0, False: 4.56k]
  ------------------
  232|      0|		extra = 4;
  233|      0|	}
  234|  4.56k|	ret = buf_new(len+extra);
  235|  4.56k|	if (incllen) {
  ------------------
  |  Branch (235:6): [True: 0, False: 4.56k]
  ------------------
  236|      0|		buf_putint(ret, len);
  237|      0|	}
  238|  4.56k|	memcpy(buf_getwriteptr(ret, len), buf_getptr(buf, len), len);
  239|  4.56k|	buf_incrpos(buf, len);
  240|  4.56k|	buf_incrlen(ret, len);
  241|  4.56k|	buf_setpos(ret, 0);
  242|  4.56k|	return ret;
  243|  4.60k|}

split_address_port:
  128|  1.85k|int split_address_port(const char* spec, char **first, char ** second) {
  129|  1.85k|	char *spec_copy = NULL, *addr = NULL, *colon = NULL;
  130|  1.85k|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  103|  1.85k|#define DROPBEAR_FAILURE -1
  ------------------
  131|       |
  132|  1.85k|	*first = NULL;
  133|  1.85k|	*second = NULL;
  134|  1.85k|	spec_copy = m_strdup(spec);
  135|  1.85k|	addr = spec_copy;
  136|       |
  137|  1.85k|	if (*addr == '[') {
  ------------------
  |  Branch (137:6): [True: 504, False: 1.35k]
  ------------------
  138|    504|		addr++;
  139|    504|		colon = strchr(addr, ']');
  140|    504|		if (!colon) {
  ------------------
  |  Branch (140:7): [True: 3, False: 501]
  ------------------
  141|      3|			dropbear_log(LOG_WARNING, "Bad address '%s'", spec);
  142|      3|			goto out;
  143|      3|		}
  144|    501|		*colon = '\0';
  145|    501|		colon++;
  146|    501|		if (*colon == '\0') {
  ------------------
  |  Branch (146:7): [True: 1, False: 500]
  ------------------
  147|       |			/* No port part */
  148|      1|			colon = NULL;
  149|    500|		} else if (*colon != ':') {
  ------------------
  |  Branch (149:14): [True: 14, False: 486]
  ------------------
  150|     14|			dropbear_log(LOG_WARNING, "Bad address '%s'", spec);
  151|     14|			goto out;
  152|     14|		}
  153|  1.35k|	} else {
  154|       |		/* search for ':', that separates address and port */
  155|  1.35k|		colon = strrchr(addr, ':');
  156|  1.35k|	}
  157|       |
  158|       |	/* colon points to ':' now, or is NULL */
  159|  1.83k|	if (colon) {
  ------------------
  |  Branch (159:6): [True: 1.80k, False: 30]
  ------------------
  160|       |		/* Split the address/port */
  161|  1.80k|		*colon = '\0';
  162|  1.80k|		colon++;
  163|  1.80k|		*second = m_strdup(colon);
  164|  1.80k|	}
  165|  1.83k|	if (strlen(addr)) {
  ------------------
  |  Branch (165:6): [True: 1.83k, False: 6]
  ------------------
  166|  1.83k|		*first = m_strdup(addr);
  167|  1.83k|	}
  168|  1.83k|	ret = DROPBEAR_SUCCESS;
  ------------------
  |  |  102|  1.83k|#define DROPBEAR_SUCCESS 0
  ------------------
  169|       |
  170|  1.85k|out:
  171|  1.85k|	m_free(spec_copy);
  ------------------
  |  |   24|  1.85k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  172|  1.85k|	return ret;
  173|  1.83k|}

crypto_init:
   21|      1|void crypto_init() {
   22|       |
   23|      1|	const struct ltc_cipher_descriptor *regciphers[] = {
   24|      1|#if DROPBEAR_AES
   25|      1|		&aes_desc,
   26|      1|#endif
   27|       |#if DROPBEAR_3DES
   28|       |		&des3_desc,
   29|       |#endif
   30|      1|		NULL
   31|      1|	};
   32|       |
   33|      1|	const struct ltc_hash_descriptor *reghashes[] = {
   34|      1|#if DROPBEAR_SHA1_HMAC
   35|      1|		&sha1_desc,
   36|      1|#endif
   37|      1|#if DROPBEAR_SHA256
   38|      1|		&sha256_desc,
   39|      1|#endif
   40|      1|#if DROPBEAR_SHA384
   41|      1|		&sha384_desc,
   42|      1|#endif
   43|      1|#if DROPBEAR_SHA512
   44|      1|		&sha512_desc,
   45|      1|#endif
   46|      1|		NULL
   47|      1|	};
   48|      1|	int i;
   49|       |
   50|      2|	for (i = 0; regciphers[i] != NULL; i++) {
  ------------------
  |  Branch (50:14): [True: 1, False: 1]
  ------------------
   51|      1|		if (register_cipher(regciphers[i]) == -1) {
  ------------------
  |  Branch (51:7): [True: 0, False: 1]
  ------------------
   52|      0|			dropbear_exit("Error registering crypto");
   53|      0|		}
   54|      1|	}
   55|       |
   56|      5|	for (i = 0; reghashes[i] != NULL; i++) {
  ------------------
  |  Branch (56:14): [True: 4, False: 1]
  ------------------
   57|      4|		if (register_hash(reghashes[i]) == -1) {
  ------------------
  |  Branch (57:7): [True: 0, False: 4]
  ------------------
   58|      0|			dropbear_exit("Error registering crypto");
   59|      0|		}
   60|      4|	}
   61|       |
   62|      1|#if DROPBEAR_LTC_PRNG
   63|      1|	dropbear_ltc_prng = register_prng(&dropbear_prng_desc);
   64|      1|	if (dropbear_ltc_prng == -1) {
  ------------------
  |  Branch (64:6): [True: 0, False: 1]
  ------------------
   65|      0|		dropbear_exit("Error registering crypto");
   66|      0|	}
   67|      1|#endif
   68|       |
   69|      1|	mp_rand_source(dropbear_rand_source);
   70|       |
   71|      1|#if DROPBEAR_ECC
   72|      1|	ltc_mp = ltm_desc;
   73|      1|	dropbear_ecc_fill_dp();
   74|      1|#endif
   75|      1|}

m_strdup:
   12|  5.49k|void * m_strdup(const char * str) {
   13|  5.49k|    char* ret;
   14|  5.49k|    unsigned int len;
   15|  5.49k|    len = strlen(str);
   16|       |
   17|  5.49k|    ret = m_malloc(len+1);
   18|  5.49k|    if (ret == NULL) {
  ------------------
  |  Branch (18:9): [True: 0, False: 5.49k]
  ------------------
   19|      0|        dropbear_exit("m_strdup failed");
   20|      0|    }
   21|  5.49k|    memcpy(ret, str, len+1);
   22|  5.49k|    return ret;
   23|  5.49k|}
m_malloc_set_epoch:
   76|  2.34k|void m_malloc_set_epoch(unsigned int epoch) {
   77|  2.34k|    current_epoch = epoch;
   78|  2.34k|}
m_malloc_free_epoch:
   80|  2.34k|void m_malloc_free_epoch(unsigned int epoch, int dofree) {
   81|  2.34k|    struct dbmalloc_header* header;
   82|  2.34k|    struct dbmalloc_header* nextheader = NULL;
   83|  2.34k|    struct dbmalloc_header* oldstaple = staple;
   84|  2.34k|    staple = NULL;
   85|       |    /* free allocations from this epoch, create a new staple-anchored list from
   86|       |    the remainder */
   87|  5.57k|    for (header = oldstaple; header; header = nextheader)
  ------------------
  |  Branch (87:30): [True: 3.23k, False: 2.34k]
  ------------------
   88|  3.23k|    {
   89|  3.23k|        nextheader = header->next;
   90|  3.23k|        if (header->epoch == epoch) {
  ------------------
  |  Branch (90:13): [True: 887, False: 2.34k]
  ------------------
   91|    887|            if (dofree) {
  ------------------
  |  Branch (91:17): [True: 887, False: 0]
  ------------------
   92|    887|                free(header);
   93|    887|            }
   94|  2.34k|        } else {
   95|  2.34k|            header->prev = NULL;
   96|  2.34k|            header->next = NULL;
   97|  2.34k|            put_alloc(header);
   98|  2.34k|        }
   99|  3.23k|    }
  100|  2.34k|}
m_malloc:
  131|  22.7k|void * m_malloc(size_t size) {
  132|  22.7k|    char* mem = NULL;
  133|  22.7k|    struct dbmalloc_header* header = NULL;
  134|       |
  135|  22.7k|    if (size == 0 || size > 1e9) {
  ------------------
  |  Branch (135:9): [True: 0, False: 22.7k]
  |  Branch (135:22): [True: 0, False: 22.7k]
  ------------------
  136|      0|        dropbear_exit("m_malloc failed");
  137|      0|    }
  138|       |
  139|  22.7k|    size = size + sizeof(struct dbmalloc_header);
  140|       |
  141|  22.7k|    mem = calloc(1, size);
  142|  22.7k|    if (mem == NULL) {
  ------------------
  |  Branch (142:9): [True: 0, False: 22.7k]
  ------------------
  143|      0|        dropbear_exit("m_malloc failed");
  144|      0|    }
  145|  22.7k|    header = (struct dbmalloc_header*)mem;
  146|  22.7k|    put_alloc(header);
  147|  22.7k|    header->epoch = current_epoch;
  148|  22.7k|    return &mem[sizeof(struct dbmalloc_header)];
  149|  22.7k|}
m_free_direct:
  172|  21.8k|void m_free_direct(void* ptr) {
  173|  21.8k|    struct dbmalloc_header* header = NULL;
  174|  21.8k|    if (!ptr) {
  ------------------
  |  Branch (174:9): [True: 70, False: 21.8k]
  ------------------
  175|     70|        return;
  176|     70|    }
  177|  21.8k|    header = get_header(ptr);
  178|  21.8k|    remove_alloc(header);
  179|  21.8k|    free(header);
  180|  21.8k|}
dbmalloc.c:put_alloc:
  102|  25.0k|static void put_alloc(struct dbmalloc_header *header) {
  103|  25.0k|    assert(header->next == NULL);
  104|  25.0k|    assert(header->prev == NULL);
  105|  25.0k|    if (staple) {
  ------------------
  |  Branch (105:9): [True: 22.7k, False: 2.34k]
  ------------------
  106|  22.7k|        staple->prev = header;
  107|  22.7k|    }
  108|  25.0k|    header->next = staple;
  109|  25.0k|    staple = header;
  110|  25.0k|}
dbmalloc.c:get_header:
  126|  21.8k|static struct dbmalloc_header* get_header(void* ptr) {
  127|  21.8k|    char* bptr = ptr;
  128|  21.8k|    return (struct dbmalloc_header*)&bptr[-sizeof(struct dbmalloc_header)];
  129|  21.8k|}
dbmalloc.c:remove_alloc:
  112|  21.8k|static void remove_alloc(struct dbmalloc_header *header) {
  113|  21.8k|    if (header->prev) {
  ------------------
  |  Branch (113:9): [True: 14.6k, False: 7.21k]
  ------------------
  114|  14.6k|        header->prev->next = header->next;
  115|  14.6k|    }
  116|  21.8k|    if (header->next) {
  ------------------
  |  Branch (116:9): [True: 21.8k, False: 0]
  ------------------
  117|  21.8k|        header->next->prev = header->prev;
  118|  21.8k|    }
  119|  21.8k|    if (staple == header) {
  ------------------
  |  Branch (119:9): [True: 7.21k, False: 14.6k]
  ------------------
  120|  7.21k|        staple = header->next;
  121|  7.21k|    }
  122|  21.8k|    header->prev = NULL;
  123|  21.8k|    header->next = NULL;
  124|  21.8k|}

fuzz_seed:
  153|  2.34k|void fuzz_seed(const unsigned char* dat, unsigned int len) {
  154|  2.34k|	hash_state hs;
  155|  2.34k|	sha256_init(&hs);
  156|  2.34k|	sha256_process(&hs, "fuzzfuzzfuzz", strlen("fuzzfuzzfuzz"));
  157|  2.34k|	sha256_process(&hs, dat, len);
  158|  2.34k|	sha256_done(&hs, hashpool);
  159|  2.34k|	counter = 0;
  160|  2.34k|	donerandinit = 1;
  161|  2.34k|}

dropbear_exit:
  105|    404|void dropbear_exit(const char* format, ...) {
  106|       |
  107|    404|	va_list param;
  108|       |
  109|    404|	va_start(param, format);
  110|    404|	_dropbear_exit(EXIT_FAILURE, format, param);
  111|      0|	va_end(param);
  112|      0|}
dropbear_log:
  148|  2.72k|void dropbear_log(int priority, const char* format, ...) {
  149|       |
  150|  2.72k|	va_list param;
  151|       |
  152|  2.72k|	va_start(param, format);
  153|  2.72k|	_dropbear_log(priority, format, param);
  154|  2.72k|	va_end(param);
  155|  2.72k|}
disallow_core:
  601|      1|void disallow_core() {
  602|      1|	struct rlimit lim = {0};
  603|      1|	if (getrlimit(RLIMIT_CORE, &lim) < 0) {
  ------------------
  |  Branch (603:6): [True: 0, False: 1]
  ------------------
  604|      0|		TRACE(("getrlimit(RLIMIT_CORE) failed"));
  605|      0|	}
  606|      1|	lim.rlim_cur = 0;
  607|      1|	if (setrlimit(RLIMIT_CORE, &lim) < 0) {
  ------------------
  |  Branch (607:6): [True: 0, False: 1]
  ------------------
  608|      0|		TRACE(("setrlimit(RLIMIT_CORE) failed"));
  609|      0|	}
  610|      1|}
m_str_to_uint:
  613|  1.19k|int m_str_to_uint(const char* str, unsigned int *val) {
  614|  1.19k|	unsigned long l;
  615|  1.19k|	char *endp;
  616|       |
  617|  1.19k|	l = strtoul(str, &endp, 10);
  618|       |
  619|  1.19k|	if (endp == str || *endp != '\0') {
  ------------------
  |  Branch (619:6): [True: 8, False: 1.18k]
  |  Branch (619:21): [True: 9, False: 1.17k]
  ------------------
  620|       |		/* parse error */
  621|     17|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|     17|#define DROPBEAR_FAILURE -1
  ------------------
  622|     17|	}
  623|       |
  624|       |	/* The c99 spec doesn't actually seem to define EINVAL, but most platforms
  625|       |	 * I've looked at mention it in their manpage */
  626|  1.17k|	if ((l == 0 && errno == EINVAL)
  ------------------
  |  Branch (626:7): [True: 488, False: 686]
  |  Branch (626:17): [True: 0, False: 488]
  ------------------
  627|  1.17k|		|| (l == ULONG_MAX && errno == ERANGE)
  ------------------
  |  Branch (627:7): [True: 2, False: 1.17k]
  |  Branch (627:25): [True: 1, False: 1]
  ------------------
  628|  1.17k|		|| (l > UINT_MAX)) {
  ------------------
  |  Branch (628:6): [True: 84, False: 1.08k]
  ------------------
  629|     85|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|     85|#define DROPBEAR_FAILURE -1
  ------------------
  630|  1.08k|	} else {
  631|  1.08k|		*val = l;
  632|  1.08k|		return DROPBEAR_SUCCESS;
  ------------------
  |  |  102|  1.08k|#define DROPBEAR_SUCCESS 0
  ------------------
  633|  1.08k|	}
  634|  1.17k|}
dbutil.c:generic_dropbear_exit:
  115|    404|		va_list param) {
  116|       |
  117|    404|	char fmtbuf[300];
  118|       |
  119|    404|	snprintf(fmtbuf, sizeof(fmtbuf), "Exited: %s", format);
  120|       |
  121|    404|	_dropbear_log(LOG_INFO, fmtbuf, param);
  122|       |
  123|    404|#if DROPBEAR_FUZZ
  124|    404|    if (fuzz.do_jmp) {
  ------------------
  |  Branch (124:9): [True: 404, False: 0]
  ------------------
  125|    404|        longjmp(fuzz.jmp, 1);
  126|    404|    }
  127|      0|#endif
  128|       |
  129|      0|	exit(exitcode);
  130|    404|}

dropbear_ecc_fill_dp:
   47|      1|void dropbear_ecc_fill_dp() {
   48|      1|	struct dropbear_ecc_curve **curve;
   49|       |	/* libtomcrypt guarantees they're ordered by size */
   50|      1|	const ltc_ecc_set_type *dp = ltc_ecc_sets;
   51|      4|	for (curve = dropbear_ecc_curves; *curve; curve++) {
  ------------------
  |  Branch (51:36): [True: 3, False: 1]
  ------------------
   52|     10|		for (;dp->size > 0; dp++) {
  ------------------
  |  Branch (52:9): [True: 10, False: 0]
  ------------------
   53|     10|			if (dp->size == (*curve)->ltc_size) {
  ------------------
  |  Branch (53:8): [True: 3, False: 7]
  ------------------
   54|      3|				(*curve)->dp = dp;
   55|      3|				break;
   56|      3|			}
   57|     10|		}
   58|      3|		if (!(*curve)->dp) {
  ------------------
  |  Branch (58:7): [True: 0, False: 3]
  ------------------
   59|      0|			dropbear_exit("Missing ECC params %s", (*curve)->name);
   60|      0|		}
   61|      3|	}
   62|      1|}

list_append:
    5|  1.85k|void list_append(m_list *list, void *item) {
    6|  1.85k|	m_list_elem *elem;
    7|       |	
    8|  1.85k|	elem = m_malloc(sizeof(*elem));
    9|  1.85k|	elem->item = item;
   10|  1.85k|	elem->list = list;
   11|  1.85k|	elem->next = NULL;
   12|  1.85k|	if (!list->first) {
  ------------------
  |  Branch (12:6): [True: 241, False: 1.61k]
  ------------------
   13|    241|		list->first = elem;
   14|    241|		elem->prev = NULL;
   15|  1.61k|	} else {
   16|  1.61k|		elem->prev = list->last;
   17|  1.61k|		list->last->next = elem;
   18|  1.61k|	}
   19|  1.85k|	list->last = elem;
   20|  1.85k|}
list_new:
   22|    242|m_list * list_new() {
   23|    242|	m_list *ret = m_malloc(sizeof(m_list));
   24|    242|	ret->first = ret->last = NULL;
   25|    242|	return ret;
   26|    242|}
list_remove:
   28|  1.85k|void * list_remove(m_list_elem *elem) {
   29|  1.85k|	void *item = elem->item;
   30|  1.85k|	m_list *list = elem->list;
   31|  1.85k|	if (list->first == elem)
  ------------------
  |  Branch (31:6): [True: 1.85k, False: 0]
  ------------------
   32|  1.85k|	{
   33|  1.85k|		list->first = elem->next;
   34|  1.85k|	}
   35|  1.85k|	if (list->last == elem)
  ------------------
  |  Branch (35:6): [True: 241, False: 1.61k]
  ------------------
   36|    241|	{
   37|    241|		list->last = elem->prev;
   38|    241|	}
   39|  1.85k|	if (elem->prev)
  ------------------
  |  Branch (39:6): [True: 0, False: 1.85k]
  ------------------
   40|      0|	{
   41|      0|		elem->prev->next = elem->next;
   42|      0|	}
   43|  1.85k|	if (elem->next)
  ------------------
  |  Branch (43:6): [True: 1.61k, False: 241]
  ------------------
   44|  1.61k|	{
   45|  1.61k|		elem->next->prev = elem->prev;
   46|  1.61k|	}
   47|  1.85k|	m_free(elem);
  ------------------
  |  |   24|  1.85k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
   48|  1.85k|	return item;
   49|  1.85k|}

signkey_type_from_name:
   86|  2.14k|enum signkey_type signkey_type_from_name(const char* name, unsigned int namelen) {
   87|  2.14k|	int i;
   88|  6.19k|	for (i = 0; i < DROPBEAR_SIGNKEY_NUM_NAMED; i++) {
  ------------------
  |  Branch (88:14): [True: 5.99k, False: 203]
  ------------------
   89|  5.99k|		const char *fixed_name = signkey_names[i];
   90|  5.99k|		if (namelen == strlen(fixed_name)
  ------------------
  |  Branch (90:7): [True: 4.05k, False: 1.93k]
  ------------------
   91|  5.99k|			&& memcmp(fixed_name, name, namelen) == 0) {
  ------------------
  |  Branch (91:7): [True: 1.93k, False: 2.12k]
  ------------------
   92|       |
   93|  1.93k|#if DROPBEAR_ECDSA
   94|       |			/* Some of the ECDSA key sizes are defined even if they're not compiled in */
   95|  1.93k|			if (0
  ------------------
  |  Branch (95:8): [Folded - Ignored]
  ------------------
   96|       |#if !DROPBEAR_ECC_256
   97|       |				|| i == DROPBEAR_SIGNKEY_ECDSA_NISTP256
   98|       |#endif
   99|       |#if !DROPBEAR_ECC_384
  100|       |				|| i == DROPBEAR_SIGNKEY_ECDSA_NISTP384
  101|       |#endif
  102|       |#if !DROPBEAR_ECC_521
  103|       |				|| i == DROPBEAR_SIGNKEY_ECDSA_NISTP521
  104|       |#endif
  105|  1.93k|				) {
  106|      0|				TRACE(("attempt to use ecdsa type %d not compiled in", i))
  107|      0|				return DROPBEAR_SIGNKEY_NONE;
  108|      0|			}
  109|  1.93k|#endif
  110|       |
  111|  1.93k|			return (enum signkey_type)i;
  112|  1.93k|		}
  113|  5.99k|	}
  114|       |
  115|    203|	TRACE(("signkey_type_from_name unexpected key type."))
  116|       |
  117|    203|	return DROPBEAR_SIGNKEY_NONE;
  118|  2.14k|}
signature_type_from_name:
  145|  2.16k|enum signature_type signature_type_from_name(const char* name, unsigned int namelen) {
  146|  2.16k|#if DROPBEAR_RSA
  147|  2.16k|#if DROPBEAR_RSA_SHA256
  148|  2.16k|	if (namelen == strlen(SSH_SIGNATURE_RSA_SHA256) 
  ------------------
  |  |  117|  2.16k|#define SSH_SIGNATURE_RSA_SHA256 "rsa-sha2-256"
  ------------------
  |  Branch (148:6): [True: 41, False: 2.12k]
  ------------------
  149|  2.16k|		&& memcmp(name, SSH_SIGNATURE_RSA_SHA256, namelen) == 0) {
  ------------------
  |  |  117|     41|#define SSH_SIGNATURE_RSA_SHA256 "rsa-sha2-256"
  ------------------
  |  Branch (149:6): [True: 18, False: 23]
  ------------------
  150|     18|		return DROPBEAR_SIGNATURE_RSA_SHA256;
  151|     18|	}
  152|  2.14k|#endif
  153|  2.14k|#if DROPBEAR_RSA_SHA1
  154|  2.14k|	if (namelen == strlen(SSH_SIGNKEY_RSA) 
  ------------------
  |  |  112|  2.14k|#define SSH_SIGNKEY_RSA "ssh-rsa"
  ------------------
  |  Branch (154:6): [True: 1.85k, False: 290]
  ------------------
  155|  2.14k|		&& memcmp(name, SSH_SIGNKEY_RSA, namelen) == 0) {
  ------------------
  |  |  112|  1.85k|#define SSH_SIGNKEY_RSA "ssh-rsa"
  ------------------
  |  Branch (155:6): [True: 8, False: 1.85k]
  ------------------
  156|      8|		return DROPBEAR_SIGNATURE_RSA_SHA1;
  157|      8|	}
  158|  2.14k|#endif
  159|  2.14k|#endif /* DROPBEAR_RSA */
  160|  2.14k|	return (enum signature_type)signkey_type_from_name(name, namelen);
  161|  2.14k|}
cmp_base64_key:
  724|  1.55k|					const buffer * line, char ** fingerprint) {
  725|       |
  726|  1.55k|	buffer * decodekey = NULL;
  727|  1.55k|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  103|  1.55k|#define DROPBEAR_FAILURE -1
  ------------------
  728|  1.55k|	unsigned int len, filealgolen;
  729|  1.55k|	unsigned long decodekeylen;
  730|  1.55k|	unsigned char* filealgo = NULL;
  731|       |
  732|       |	/* now we have the actual data */
  733|  1.55k|	len = line->len - line->pos;
  734|  1.55k|	if (len == 0) {
  ------------------
  |  Branch (734:6): [True: 41, False: 1.51k]
  ------------------
  735|       |		/* base64_decode doesn't like NULL argument */
  736|     41|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|     41|#define DROPBEAR_FAILURE -1
  ------------------
  737|     41|	}
  738|  1.51k|	decodekeylen = len * 2; /* big to be safe */
  739|  1.51k|	decodekey = buf_new(decodekeylen);
  740|       |
  741|  1.51k|	if (base64_decode(buf_getptr(line, len), len,
  ------------------
  |  Branch (741:6): [True: 23, False: 1.49k]
  ------------------
  742|  1.51k|				buf_getwriteptr(decodekey, decodekey->size),
  743|  1.51k|				&decodekeylen) != CRYPT_OK) {
  744|     23|		TRACE(("checkpubkey: base64 decode failed"))
  745|     23|		goto out;
  746|     23|	}
  747|  1.49k|	TRACE(("checkpubkey: base64_decode success"))
  748|  1.49k|	buf_incrlen(decodekey, decodekeylen);
  749|       |	
  750|  1.49k|	if (fingerprint) {
  ------------------
  |  Branch (750:6): [True: 0, False: 1.49k]
  ------------------
  751|      0|		*fingerprint = sign_key_fingerprint(buf_getptr(decodekey, decodekeylen),
  752|      0|											decodekeylen);
  753|      0|	}
  754|       |	
  755|       |	/* compare the keys */
  756|  1.49k|	if ( ( decodekeylen != keybloblen )
  ------------------
  |  Branch (756:7): [True: 147, False: 1.34k]
  ------------------
  757|  1.49k|			|| memcmp( buf_getptr(decodekey, decodekey->len),
  ------------------
  |  Branch (757:7): [True: 20, False: 1.32k]
  ------------------
  758|  1.34k|						keyblob, decodekey->len) != 0) {
  759|    167|		TRACE(("checkpubkey: compare failed"))
  760|    167|		goto out;
  761|    167|	}
  762|       |
  763|       |	/* ... and also check that the algo specified and the algo in the key
  764|       |	 * itself match */
  765|  1.32k|	filealgolen = buf_getint(decodekey);
  766|  1.32k|	filealgo = buf_getptr(decodekey, filealgolen);
  767|  1.32k|	if (filealgolen != algolen || memcmp(filealgo, algoname, algolen) != 0) {
  ------------------
  |  Branch (767:6): [True: 0, False: 1.32k]
  |  Branch (767:32): [True: 0, False: 1.32k]
  ------------------
  768|      0|		TRACE(("checkpubkey: algo match failed")) 
  769|      0|		goto out;
  770|      0|	}
  771|       |
  772|       |	/* All checks passed */
  773|  1.32k|	ret = DROPBEAR_SUCCESS;
  ------------------
  |  |  102|  1.32k|#define DROPBEAR_SUCCESS 0
  ------------------
  774|       |
  775|  1.51k|out:
  776|  1.51k|	buf_free(decodekey);
  777|  1.51k|	decodekey = NULL;
  778|  1.51k|	return ret;
  779|  1.32k|}

fuzz_checkpubkey_line:
  619|  1.96k|		const unsigned char* keyblob, unsigned int keybloblen) {
  620|  1.96k|	return checkpubkey_line(line, line_num, filename, algo, algolen, keyblob, keybloblen, NULL);
  621|  1.96k|}
svr-authpubkey.c:checkpubkey_line:
  289|  1.96k|		char ** ret_info) {
  290|  1.96k|	buffer *options_buf = NULL;
  291|  1.96k|	char *info_str = NULL;
  292|  1.96k|	unsigned int pos, len, infopos, infolen;
  293|  1.96k|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  103|  1.96k|#define DROPBEAR_FAILURE -1
  ------------------
  294|       |
  295|  1.96k|	if (line->len < MIN_AUTHKEYS_LINE || line->len > MAX_AUTHKEYS_LINE) {
  ------------------
  |  |   71|  3.92k|#define MIN_AUTHKEYS_LINE 10 /* "ssh-rsa AB" - short but doesn't matter */
  ------------------
              	if (line->len < MIN_AUTHKEYS_LINE || line->len > MAX_AUTHKEYS_LINE) {
  ------------------
  |  |   72|  1.95k|#define MAX_AUTHKEYS_LINE 4200 /* max length of a line in authkeys */
  ------------------
  |  Branch (295:6): [True: 12, False: 1.95k]
  |  Branch (295:39): [True: 2, False: 1.94k]
  ------------------
  296|     14|		TRACE(("checkpubkey_line: bad line length %d", line->len))
  297|     14|		goto out;
  298|     14|	}
  299|       |
  300|  1.94k|	if (memchr(line->data, 0x0, line->len) != NULL) {
  ------------------
  |  Branch (300:6): [True: 7, False: 1.94k]
  ------------------
  301|      7|		TRACE(("checkpubkey_line: bad line has null char"))
  302|      7|		goto out;
  303|      7|	}
  304|       |
  305|       |	/* compare the algorithm. +3 so we have enough bytes to read a space and some base64 characters too. */
  306|  1.94k|	if (line->pos + algolen+3 > line->len) {
  ------------------
  |  Branch (306:6): [True: 3, False: 1.93k]
  ------------------
  307|      3|		goto out;
  308|      3|	}
  309|       |	/* check the key type */
  310|  1.93k|	if (strncmp((const char *) buf_getptr(line, algolen), algo, algolen) != 0) {
  ------------------
  |  Branch (310:6): [True: 1.77k, False: 169]
  ------------------
  311|  1.77k|		int is_comment = 0;
  312|  1.77k|		unsigned char *options_start = NULL;
  313|  1.77k|		int options_len = 0;
  314|  1.77k|		int escape, quoted;
  315|       |
  316|       |		/* skip over any comments or leading whitespace */
  317|  27.6k|		while (line->pos < line->len) {
  ------------------
  |  Branch (317:10): [True: 27.5k, False: 21]
  ------------------
  318|  27.5k|			const char c = buf_getbyte(line);
  319|  27.5k|			if (c == ' ' || c == '\t') {
  ------------------
  |  Branch (319:8): [True: 3.75k, False: 23.8k]
  |  Branch (319:20): [True: 22.0k, False: 1.74k]
  ------------------
  320|  25.8k|				continue;
  321|  25.8k|			} else if (c == '#') {
  ------------------
  |  Branch (321:15): [True: 2, False: 1.74k]
  ------------------
  322|      2|				is_comment = 1;
  323|      2|				break;
  324|      2|			}
  325|  1.74k|			buf_decrpos(line, 1);
  326|  1.74k|			break;
  327|  27.5k|		}
  328|  1.77k|		if (is_comment) {
  ------------------
  |  Branch (328:7): [True: 2, False: 1.76k]
  ------------------
  329|       |			/* next line */
  330|      2|			goto out;
  331|      2|		}
  332|       |
  333|       |		/* remember start of options */
  334|  1.76k|		options_start = buf_getptr(line, 1);
  335|  1.76k|		quoted = 0;
  336|  1.76k|		escape = 0;
  337|  1.76k|		options_len = 0;
  338|       |
  339|       |		/* figure out where the options are */
  340|   240k|		while (line->pos < line->len) {
  ------------------
  |  Branch (340:10): [True: 240k, False: 178]
  ------------------
  341|   240k|			const char c = buf_getbyte(line);
  342|   240k|			if (!quoted && (c == ' ' || c == '\t')) {
  ------------------
  |  Branch (342:8): [True: 143k, False: 97.0k]
  |  Branch (342:20): [True: 81, False: 143k]
  |  Branch (342:32): [True: 1.50k, False: 141k]
  ------------------
  343|  1.59k|				break;
  344|  1.59k|			}
  345|   238k|			escape = (!escape && c == '\\');
  ------------------
  |  Branch (345:14): [True: 236k, False: 2.23k]
  |  Branch (345:25): [True: 2.24k, False: 234k]
  ------------------
  346|   238k|			if (!escape && c == '"') {
  ------------------
  |  Branch (346:8): [True: 236k, False: 2.24k]
  |  Branch (346:19): [True: 9.02k, False: 227k]
  ------------------
  347|  9.02k|				quoted = !quoted;
  348|  9.02k|			}
  349|   238k|			options_len++;
  350|   238k|		}
  351|  1.76k|		options_buf = buf_new(options_len);
  352|  1.76k|		buf_putbytes(options_buf, options_start, options_len);
  353|       |
  354|       |		/* compare the algorithm. +3 so we have enough bytes to read a space and some base64 characters too. */
  355|  1.76k|		if (line->pos + algolen+3 > line->len) {
  ------------------
  |  Branch (355:7): [True: 212, False: 1.55k]
  ------------------
  356|    212|			goto out;
  357|    212|		}
  358|  1.55k|		if (strncmp((const char *) buf_getptr(line, algolen), algo, algolen) != 0) {
  ------------------
  |  Branch (358:7): [True: 130, False: 1.42k]
  ------------------
  359|    130|			goto out;
  360|    130|		}
  361|  1.55k|	}
  362|  1.59k|	buf_incrpos(line, algolen);
  363|       |
  364|       |	/* check for space (' ') character */
  365|  1.59k|	if (buf_getbyte(line) != ' ') {
  ------------------
  |  Branch (365:6): [True: 16, False: 1.57k]
  ------------------
  366|     16|		TRACE(("checkpubkey_line: space character expected, isn't there"))
  367|     16|		goto out;
  368|     16|	}
  369|       |
  370|       |	/* find the length of base64 data */
  371|  1.57k|	pos = line->pos;
  372|  99.9k|	for (len = 0; line->pos < line->len; len++) {
  ------------------
  |  Branch (372:16): [True: 98.4k, False: 1.47k]
  ------------------
  373|  98.4k|		if (buf_getbyte(line) == ' ') {
  ------------------
  |  Branch (373:7): [True: 105, False: 98.3k]
  ------------------
  374|    105|			break;
  375|    105|		}
  376|  98.4k|	}
  377|       |
  378|       |	/* find out the length of the public key info, stop at the first space */
  379|  1.57k|	infopos = line->pos;
  380|  6.61k|	for (infolen = 0; line->pos < line->len; infolen++) {
  ------------------
  |  Branch (380:20): [True: 5.07k, False: 1.54k]
  ------------------
  381|  5.07k|		const char c = buf_getbyte(line);
  382|  5.07k|		if (c == ' ') {
  ------------------
  |  Branch (382:7): [True: 11, False: 5.06k]
  ------------------
  383|     11|			break;
  384|     11|		}
  385|       |		/* We have an allowlist - authorized_keys lines can't be fully trusted,
  386|       |		some shell scripts may do unsafe things with env var values */
  387|  5.06k|		if (!(isalnum(c) || strchr(".,_-+@", c))) {
  ------------------
  |  Branch (387:23): [True: 1.09k, False: 28]
  ------------------
  388|     28|			TRACE(("Not setting SSH_PUBKEYINFO, special characters"))
  389|     28|			infolen = 0;
  390|     28|			break;
  391|     28|		}
  392|  5.06k|	}
  393|  1.57k|	if (infolen > 0) {
  ------------------
  |  Branch (393:6): [True: 58, False: 1.52k]
  ------------------
  394|     58|		info_str = m_malloc(infolen + 1);
  395|     58|		buf_setpos(line, infopos);
  396|     58|        strncpy(info_str, buf_getptr(line, infolen), infolen);
  397|     58|	}
  398|       |
  399|       |	/* truncate to base64 data length */
  400|  1.57k|	buf_setpos(line, pos);
  401|  1.57k|	buf_setlen(line, line->pos + len);
  402|       |
  403|  1.57k|	TRACE(("checkpubkey_line: line pos = %d len = %d", line->pos, line->len))
  404|       |
  405|  1.57k|	ret = cmp_base64_key(keyblob, keybloblen, (const unsigned char *) algo, algolen, line, NULL);
  406|       |
  407|       |	/* free pubkey_info if it is filled */
  408|  1.57k|	if (ret_info && *ret_info) {
  ------------------
  |  Branch (408:6): [True: 0, False: 1.57k]
  |  Branch (408:18): [True: 0, False: 0]
  ------------------
  409|      0|		m_free(*ret_info);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  410|      0|		*ret_info = NULL;
  411|      0|	}
  412|       |
  413|  1.57k|	if (ret == DROPBEAR_SUCCESS) {
  ------------------
  |  |  102|  1.57k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (413:6): [True: 1.32k, False: 252]
  ------------------
  414|  1.32k|		if (options_buf) {
  ------------------
  |  Branch (414:7): [True: 1.32k, False: 2]
  ------------------
  415|  1.32k|			ret = svr_add_pubkey_options(options_buf, line_num, filename);
  416|  1.32k|		}
  417|  1.32k|		if (ret_info) {
  ------------------
  |  Branch (417:7): [True: 0, False: 1.32k]
  ------------------
  418|       |			/* take the (optional) public key information */
  419|      0|			*ret_info = info_str;
  420|      0|			info_str = NULL;
  421|      0|		}
  422|  1.32k|	}
  423|       |
  424|  1.94k|out:
  425|  1.94k|	if (options_buf) {
  ------------------
  |  Branch (425:6): [True: 1.74k, False: 195]
  ------------------
  426|  1.74k|		buf_free(options_buf);
  427|  1.74k|	}
  428|  1.94k|	if (info_str) {
  ------------------
  |  Branch (428:6): [True: 58, False: 1.88k]
  ------------------
  429|     58|		m_free(info_str);
  ------------------
  |  |   24|     58|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  430|     58|	}
  431|  1.94k|	return ret;
  432|  1.57k|}

svr_pubkey_options_cleanup:
  135|  1.32k|void svr_pubkey_options_cleanup() {
  136|  1.32k|	if (ses.authstate.pubkey_options) {
  ------------------
  |  Branch (136:6): [True: 1.32k, False: 2]
  ------------------
  137|  1.32k|		if (ses.authstate.pubkey_options->forced_command) {
  ------------------
  |  Branch (137:7): [True: 39, False: 1.28k]
  ------------------
  138|     39|			m_free(ses.authstate.pubkey_options->forced_command);
  ------------------
  |  |   24|     39|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  139|     39|		}
  140|  1.32k|		if (ses.authstate.pubkey_options->permit_open_destinations) {
  ------------------
  |  Branch (140:7): [True: 242, False: 1.08k]
  ------------------
  141|    242|			m_list_elem *iter = ses.authstate.pubkey_options->permit_open_destinations->first;
  142|  2.09k|			while (iter) {
  ------------------
  |  Branch (142:11): [True: 1.85k, False: 242]
  ------------------
  143|  1.85k|				struct PermitTCPFwdEntry *entry = (struct PermitTCPFwdEntry*)list_remove(iter);
  144|  1.85k|				m_free(entry->host);
  ------------------
  |  |   24|  1.85k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  145|  1.85k|				m_free(entry);
  ------------------
  |  |   24|  1.85k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  146|  1.85k|				iter = ses.authstate.pubkey_options->permit_open_destinations->first;
  147|  1.85k|			}
  148|    242|			m_free(ses.authstate.pubkey_options->permit_open_destinations);
  ------------------
  |  |   24|    242|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  149|    242|		}
  150|  1.32k|		m_free(ses.authstate.pubkey_options);
  ------------------
  |  |   24|  1.32k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  151|  1.32k|	}
  152|  1.32k|	if (ses.authstate.pubkey_info) {
  ------------------
  |  Branch (152:6): [True: 0, False: 1.32k]
  ------------------
  153|      0|		m_free(ses.authstate.pubkey_info);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  154|      0|	}
  155|  1.32k|}
svr_add_pubkey_options:
  173|  1.32k|int svr_add_pubkey_options(buffer *options_buf, int line_num, const char* filename) {
  174|  1.32k|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  103|  1.32k|#define DROPBEAR_FAILURE -1
  ------------------
  175|       |
  176|  1.32k|	TRACE(("enter addpubkeyoptions"))
  177|       |
  178|  1.32k|	ses.authstate.pubkey_options = (struct PubKeyOptions*)m_malloc(sizeof( struct PubKeyOptions ));
  179|       |
  180|  1.32k|	buf_setpos(options_buf, 0);
  181|  9.20k|	while (options_buf->pos < options_buf->len) {
  ------------------
  |  Branch (181:9): [True: 9.05k, False: 145]
  ------------------
  182|  9.05k|		if (match_option(options_buf, "no-port-forwarding") == DROPBEAR_SUCCESS) {
  ------------------
  |  |  102|  9.05k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (182:7): [True: 251, False: 8.80k]
  ------------------
  183|    251|			dropbear_log(LOG_WARNING, "Port forwarding disabled.");
  184|    251|			ses.authstate.pubkey_options->no_port_forwarding_flag = 1;
  185|    251|			goto next_option;
  186|    251|		}
  187|  8.80k|		if (match_option(options_buf, "no-agent-forwarding") == DROPBEAR_SUCCESS) {
  ------------------
  |  |  102|  8.80k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (187:7): [True: 263, False: 8.54k]
  ------------------
  188|    263|#if DROPBEAR_SVR_AGENTFWD
  189|    263|			dropbear_log(LOG_WARNING, "Agent forwarding disabled.");
  190|    263|			ses.authstate.pubkey_options->no_agent_forwarding_flag = 1;
  191|    263|#endif
  192|    263|			goto next_option;
  193|    263|		}
  194|  8.54k|		if (match_option(options_buf, "no-X11-forwarding") == DROPBEAR_SUCCESS) {
  ------------------
  |  |  102|  8.54k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (194:7): [True: 212, False: 8.33k]
  ------------------
  195|       |#if DROPBEAR_X11FWD
  196|       |			dropbear_log(LOG_WARNING, "X11 forwarding disabled.");
  197|       |			ses.authstate.pubkey_options->no_x11_forwarding_flag = 1;
  198|       |#endif
  199|    212|			goto next_option;
  200|    212|		}
  201|  8.33k|		if (match_option(options_buf, "no-pty") == DROPBEAR_SUCCESS) {
  ------------------
  |  |  102|  8.33k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (201:7): [True: 281, False: 8.05k]
  ------------------
  202|    281|			dropbear_log(LOG_WARNING, "Pty allocation disabled.");
  203|    281|			ses.authstate.pubkey_options->no_pty_flag = 1;
  204|    281|			goto next_option;
  205|    281|		}
  206|  8.05k|		if (match_option(options_buf, "restrict") == DROPBEAR_SUCCESS) {
  ------------------
  |  |  102|  8.05k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (206:7): [True: 384, False: 7.66k]
  ------------------
  207|    384|			dropbear_log(LOG_WARNING, "Restrict option set");
  208|    384|			ses.authstate.pubkey_options->no_port_forwarding_flag = 1;
  209|    384|#if DROPBEAR_SVR_AGENTFWD
  210|    384|			ses.authstate.pubkey_options->no_agent_forwarding_flag = 1;
  211|    384|#endif
  212|       |#if DROPBEAR_X11FWD
  213|       |			ses.authstate.pubkey_options->no_x11_forwarding_flag = 1;
  214|       |#endif
  215|    384|			ses.authstate.pubkey_options->no_pty_flag = 1;
  216|    384|			goto next_option;
  217|    384|		}
  218|  7.66k|		if (match_option(options_buf, "command=\"") == DROPBEAR_SUCCESS) {
  ------------------
  |  |  102|  7.66k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (218:7): [True: 61, False: 7.60k]
  ------------------
  219|     61|			int escaped = 0;
  220|     61|			const unsigned char* command_start = buf_getptr(options_buf, 0);
  221|       |
  222|     61|			if (ses.authstate.pubkey_options->forced_command) {
  ------------------
  |  Branch (222:8): [True: 1, False: 60]
  ------------------
  223|       |				/* multiple command= options */
  224|      1|				goto bad_option;
  225|      1|			}
  226|       |
  227|  17.7k|			while (options_buf->pos < options_buf->len) {
  ------------------
  |  Branch (227:11): [True: 17.6k, False: 21]
  ------------------
  228|  17.6k|				const char c = buf_getbyte(options_buf);
  229|  17.6k|				if (!escaped && c == '"') {
  ------------------
  |  Branch (229:9): [True: 16.7k, False: 926]
  |  Branch (229:21): [True: 39, False: 16.7k]
  ------------------
  230|     39|					const int command_len = buf_getptr(options_buf, 0) - command_start;
  231|     39|					ses.authstate.pubkey_options->forced_command = m_malloc(command_len);
  232|     39|					memcpy(ses.authstate.pubkey_options->forced_command,
  233|     39|							command_start, command_len-1);
  234|     39|					ses.authstate.pubkey_options->forced_command[command_len-1] = '\0';
  235|     39|					goto next_option;
  236|     39|				}
  237|  17.6k|				escaped = (!escaped && c == '\\');
  ------------------
  |  Branch (237:16): [True: 16.7k, False: 926]
  |  Branch (237:28): [True: 926, False: 15.7k]
  ------------------
  238|  17.6k|			}
  239|     21|			dropbear_log(LOG_WARNING, "Badly formatted command= authorized_keys option");
  240|     21|			goto bad_option;
  241|     60|		}
  242|       |
  243|  7.60k|		if (match_option(options_buf, "permitopen=\"") == DROPBEAR_SUCCESS) {
  ------------------
  |  |  102|  7.60k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (243:7): [True: 1.85k, False: 5.75k]
  ------------------
  244|  1.85k|			int valid_option = 0;
  245|  1.85k|			const unsigned char* permitopen_start = buf_getptr(options_buf, 0);
  246|       |
  247|  1.85k|			if (!ses.authstate.pubkey_options->permit_open_destinations) {
  ------------------
  |  Branch (247:8): [True: 242, False: 1.61k]
  ------------------
  248|    242|				ses.authstate.pubkey_options->permit_open_destinations = list_new();
  249|    242|			}
  250|       |
  251|  16.0k|			while (options_buf->pos < options_buf->len) {
  ------------------
  |  Branch (251:11): [True: 16.0k, False: 1]
  ------------------
  252|  16.0k|				const char c = buf_getbyte(options_buf);
  253|  16.0k|				if (c == '"') {
  ------------------
  |  Branch (253:9): [True: 1.85k, False: 14.2k]
  ------------------
  254|  1.85k|					char *spec = NULL;
  255|  1.85k|					char *portstring = NULL;
  256|  1.85k|					const int permitopen_len = buf_getptr(options_buf, 0) - permitopen_start;
  257|  1.85k|					struct PermitTCPFwdEntry *entry =
  258|  1.85k|							(struct PermitTCPFwdEntry*)m_malloc(sizeof(struct PermitTCPFwdEntry));
  259|       |
  260|  1.85k|					list_append(ses.authstate.pubkey_options->permit_open_destinations, entry);
  261|  1.85k|					spec = m_malloc(permitopen_len);
  262|  1.85k|					memcpy(spec, permitopen_start, permitopen_len - 1);
  263|  1.85k|					spec[permitopen_len - 1] = '\0';
  264|  1.85k|					if ((split_address_port(spec, &entry->host, &portstring) == DROPBEAR_SUCCESS)
  ------------------
  |  |  102|  1.85k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (264:10): [True: 1.83k, False: 17]
  ------------------
  265|  1.85k|						&& entry->host && portstring) {
  ------------------
  |  Branch (265:10): [True: 1.83k, False: 6]
  |  Branch (265:25): [True: 1.80k, False: 27]
  ------------------
  266|  1.80k|						if (strcmp(portstring, "*") == 0) {
  ------------------
  |  Branch (266:11): [True: 614, False: 1.19k]
  ------------------
  267|    614|							valid_option = 1;
  268|    614|							entry->port = PUBKEY_OPTIONS_ANY_PORT;
  ------------------
  |  |  101|    614|#define PUBKEY_OPTIONS_ANY_PORT UINT_MAX
  ------------------
  269|    614|							TRACE(("local port forwarding allowed to host '%s'", entry->host));
  270|  1.19k|						} else if (m_str_to_uint(portstring, &entry->port) == DROPBEAR_SUCCESS) {
  ------------------
  |  |  102|  1.19k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (270:18): [True: 1.08k, False: 102]
  ------------------
  271|  1.08k|							valid_option = 1;
  272|  1.08k|							TRACE(("local port forwarding allowed to host '%s' and port '%u'",
  273|  1.08k|									entry->host, entry->port));
  274|  1.08k|						}
  275|  1.80k|					}
  276|       |
  277|  1.85k|					m_free(spec);
  ------------------
  |  |   24|  1.85k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  278|  1.85k|					m_free(portstring);
  ------------------
  |  |   24|  1.85k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  279|  1.85k|					break;
  280|  1.85k|				}
  281|  16.0k|			}
  282|       |
  283|  1.85k|			if (valid_option) {
  ------------------
  |  Branch (283:8): [True: 1.70k, False: 153]
  ------------------
  284|  1.70k|				goto next_option;
  285|  1.70k|			} else {
  286|    153|				dropbear_log(LOG_WARNING, "Badly formatted permitopen= authorized_keys option");
  287|    153|				goto bad_option;
  288|    153|			}
  289|  1.85k|		}
  290|       |
  291|  5.75k|		if (match_option(options_buf, "no-touch-required") == DROPBEAR_SUCCESS) {
  ------------------
  |  |  102|  5.75k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (291:7): [True: 98, False: 5.65k]
  ------------------
  292|     98|#if DROPBEAR_SK_ECDSA || DROPBEAR_SK_ED25519
  293|     98|			dropbear_log(LOG_WARNING, "No user presence check required for U2F/FIDO key.");
  294|     98|			ses.authstate.pubkey_options->no_touch_required_flag = 1;
  295|     98|#endif
  296|     98|			goto next_option;
  297|     98|		}
  298|  5.65k|		if (match_option(options_buf, "verify-required") == DROPBEAR_SUCCESS) {
  ------------------
  |  |  102|  5.65k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (298:7): [True: 79, False: 5.57k]
  ------------------
  299|     79|#if DROPBEAR_SK_ECDSA || DROPBEAR_SK_ED25519
  300|     79|			dropbear_log(LOG_WARNING, "User verification required for U2F/FIDO key.");
  301|     79|			ses.authstate.pubkey_options->verify_required_flag = 1;
  302|     79|#endif
  303|     79|			goto next_option;
  304|     79|		}
  305|       |
  306|  8.88k|next_option:
  307|       |		/*
  308|       |		 * Skip the comma, and move to the next option
  309|       |		 * (or break out if there are no more).
  310|       |		 */
  311|  8.88k|		if (options_buf->pos < options_buf->len 
  ------------------
  |  Branch (311:7): [True: 8.76k, False: 123]
  ------------------
  312|  8.88k|				&& buf_getbyte(options_buf) != ',') {
  ------------------
  |  Branch (312:8): [True: 1.00k, False: 7.75k]
  ------------------
  313|  1.00k|			goto bad_option;
  314|  1.00k|		}
  315|       |		/* Process the next option. */
  316|  8.88k|	}
  317|       |	/* parsed all options with no problem */
  318|    145|	ret = DROPBEAR_SUCCESS;
  ------------------
  |  |  102|    145|#define DROPBEAR_SUCCESS 0
  ------------------
  319|    145|	goto end;
  320|       |
  321|  1.18k|bad_option:
  322|  1.18k|	ret = DROPBEAR_FAILURE;
  ------------------
  |  |  103|  1.18k|#define DROPBEAR_FAILURE -1
  ------------------
  323|  1.18k|	svr_pubkey_options_cleanup();
  324|  1.18k|	dropbear_log(LOG_WARNING, "Bad public key options at %s:%d", filename, line_num);
  325|       |
  326|  1.32k|end:
  327|  1.32k|	TRACE(("leave addpubkeyoptions"))
  328|  1.32k|	return ret;
  329|  1.18k|}
svr-authpubkeyoptions.c:match_option:
  159|  69.4k|static int match_option(buffer *options_buf, const char *opt_name) {
  160|  69.4k|	const unsigned int len = strlen(opt_name);
  161|  69.4k|	if (options_buf->len - options_buf->pos < len) {
  ------------------
  |  Branch (161:6): [True: 6.98k, False: 62.4k]
  ------------------
  162|  6.98k|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|  6.98k|#define DROPBEAR_FAILURE -1
  ------------------
  163|  6.98k|	}
  164|  62.4k|	if (strncasecmp((const char *) buf_getptr(options_buf, len), opt_name, len) == 0) {
  ------------------
  |  Branch (164:6): [True: 3.48k, False: 59.0k]
  ------------------
  165|  3.48k|		buf_incrpos(options_buf, len);
  166|  3.48k|		return DROPBEAR_SUCCESS;
  ------------------
  |  |  102|  3.48k|#define DROPBEAR_SUCCESS 0
  ------------------
  167|  3.48k|	}
  168|  59.0k|	return DROPBEAR_FAILURE;
  ------------------
  |  |  103|  59.0k|#define DROPBEAR_FAILURE -1
  ------------------
  169|  62.4k|}

