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|  1.49k|int fuzz_set_input(const uint8_t *Data, size_t Size) {
   58|       |
   59|  1.49k|    fuzz.input->data = (unsigned char*)Data;
   60|  1.49k|    fuzz.input->size = Size;
   61|  1.49k|    fuzz.input->len = Size;
   62|  1.49k|    fuzz.input->pos = 0;
   63|       |
   64|  1.49k|    memset(&ses, 0x0, sizeof(ses));
   65|  1.49k|    memset(&svr_ses, 0x0, sizeof(svr_ses));
   66|  1.49k|    memset(&cli_ses, 0x0, sizeof(cli_ses));
   67|  1.49k|    wrapfd_setup(fuzz.input);
   68|       |    // printhex("input", fuzz.input->data, fuzz.input->len);
   69|       |
   70|  1.49k|    fuzz_seed(fuzz.input->data, MIN(fuzz.input->len, 16));
   71|       |
   72|  1.49k|    return DROPBEAR_SUCCESS;
  ------------------
  |  |  102|  1.49k|#define DROPBEAR_SUCCESS 0
  ------------------
   73|  1.49k|}
fuzz_svr_setup:
   89|      1|void fuzz_svr_setup(void) {
   90|      1|    fuzz_common_setup();
   91|       |    
   92|      1|    _dropbear_exit = svr_dropbear_exit;
   93|       |
   94|      1|    char *argv[] = { 
   95|      1|		"dropbear",
   96|      1|        "-E", 
   97|      1|    };
   98|       |
   99|      1|    int argc = sizeof(argv) / sizeof(*argv);
  100|      1|    svr_getopts(argc, argv);
  101|       |
  102|      1|    load_fixed_hostkeys();
  103|      1|}
fuzz_svr_hook_preloop:
  105|  1.49k|void fuzz_svr_hook_preloop() {
  106|  1.49k|    if (fuzz.svr_postauth) {
  ------------------
  |  Branch (106:9): [True: 1.49k, False: 0]
  ------------------
  107|  1.49k|        ses.authstate.authdone = 1;
  108|  1.49k|        fill_passwd("root");
  109|  1.49k|    }
  110|  1.49k|}
fuzz_kex_fakealgos:
  197|  9.44k|void fuzz_kex_fakealgos(void) {
  198|  9.44k|    ses.newkeys->recv.crypt_mode = &dropbear_mode_none;
  199|  9.44k|    ses.newkeys->recv.algo_mac = &dropbear_nohash;
  200|  9.44k|}
fuzz_get_socket_address:
  203|  5.57k|                        char **remote_host, char **remote_port, int UNUSED(host_lookup)) {
  204|  5.57k|    if (local_host) {
  ------------------
  |  Branch (204:9): [True: 2.58k, False: 2.99k]
  ------------------
  205|  2.58k|        *local_host = m_strdup("fuzzlocalhost");
  206|  2.58k|    }
  207|  5.57k|    if (local_port) {
  ------------------
  |  Branch (207:9): [True: 2.58k, False: 2.99k]
  ------------------
  208|  2.58k|        *local_port = m_strdup("1234");
  209|  2.58k|    }
  210|  5.57k|    if (remote_host) {
  ------------------
  |  Branch (210:9): [True: 5.57k, False: 0]
  ------------------
  211|  5.57k|        *remote_host = m_strdup("fuzzremotehost");
  212|  5.57k|    }
  213|  5.57k|    if (remote_port) {
  ------------------
  |  Branch (213:9): [True: 4.08k, False: 1.49k]
  ------------------
  214|  4.08k|        *remote_port = m_strdup("9876");
  215|  4.08k|    }
  216|  5.57k|}
fuzz_fake_send_kexdh_reply:
  219|  9.27k|void fuzz_fake_send_kexdh_reply(void) {
  220|  9.27k|    assert(!ses.dh_K);
  221|  9.27k|    m_mp_alloc_init_multi(&ses.dh_K, NULL);
  222|  9.27k|    mp_set_ul(ses.dh_K, 12345678uL);
  223|  9.27k|    finish_kexhashbuf();
  224|  9.27k|}
fuzz_spawn_command:
  227|  1.55k|int fuzz_spawn_command(int *ret_writefd, int *ret_readfd, int *ret_errfd, pid_t *ret_pid) {
  228|  1.55k|    *ret_writefd = wrapfd_new_dummy();
  229|  1.55k|    *ret_readfd = wrapfd_new_dummy();
  230|  1.55k|    if (ret_errfd) {
  ------------------
  |  Branch (230:9): [True: 1.55k, False: 0]
  ------------------
  231|  1.55k|        *ret_errfd = wrapfd_new_dummy();
  232|  1.55k|    }
  233|  1.55k|    if (*ret_writefd == -1 || *ret_readfd == -1 || (ret_errfd && *ret_errfd == -1)) {
  ------------------
  |  Branch (233:9): [True: 0, False: 1.55k]
  |  Branch (233:31): [True: 0, False: 1.55k]
  |  Branch (233:53): [True: 1.55k, False: 0]
  |  Branch (233:66): [True: 0, False: 1.55k]
  ------------------
  234|      0|        m_close(*ret_writefd);
  235|      0|        m_close(*ret_readfd);
  236|      0|        if (ret_errfd) {
  ------------------
  |  Branch (236:13): [True: 0, False: 0]
  ------------------
  237|      0|            m_close(*ret_errfd);
  238|      0|        }
  239|      0|        return DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
  240|  1.55k|    } else {
  241|  1.55k|        *ret_pid = 999;
  242|  1.55k|        return DROPBEAR_SUCCESS;
  ------------------
  |  |  102|  1.55k|#define DROPBEAR_SUCCESS 0
  ------------------
  243|       |
  244|  1.55k|    }
  245|  1.55k|}
fuzz_dropbear_listen:
  257|  1.22k|        int *UNUSED(socks), unsigned int UNUSED(sockcount), char **errstring, int *UNUSED(maxfd)) {
  258|  1.22k|    if (errstring) {
  ------------------
  |  Branch (258:9): [True: 1.22k, False: 0]
  ------------------
  259|  1.22k|        *errstring = m_strdup("fuzzing can't listen (yet)");
  260|  1.22k|    }
  261|  1.22k|    return -1;
  262|  1.22k|}
fuzz_run_server:
  264|  1.49k|int fuzz_run_server(const uint8_t *Data, size_t Size, int skip_kexmaths, int postauth) {
  265|  1.49k|    static int once = 0;
  266|  1.49k|    if (!once) {
  ------------------
  |  Branch (266:9): [True: 1, False: 1.49k]
  ------------------
  267|      1|        fuzz_svr_setup();
  268|      1|        fuzz.skip_kexmaths = skip_kexmaths;
  269|      1|        once = 1;
  270|      1|    }
  271|       |
  272|  1.49k|    fuzz.svr_postauth = postauth;
  273|       |
  274|  1.49k|    if (fuzz_set_input(Data, Size) == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|  1.49k|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (274:9): [True: 0, False: 1.49k]
  ------------------
  275|      0|        return 0;
  276|      0|    }
  277|       |
  278|  1.49k|    uint32_t wrapseed;
  279|  1.49k|    genrandom((void*)&wrapseed, sizeof(wrapseed));
  280|  1.49k|    wrapfd_setseed(wrapseed);
  281|       |
  282|  1.49k|    int fakesock = wrapfd_new_fuzzinput();
  283|       |
  284|  1.49k|    m_malloc_set_epoch(1);
  285|  1.49k|    fuzz.do_jmp = 1;
  286|  1.49k|    if (setjmp(fuzz.jmp) == 0) {
  ------------------
  |  Branch (286:9): [True: 1.49k, False: 0]
  ------------------
  287|  1.49k|        svr_session(fakesock, fakesock);
  288|      0|        m_malloc_free_epoch(1, 0);
  289|      0|    } else {
  290|      0|        fuzz.do_jmp = 0;
  291|      0|        m_malloc_free_epoch(1, 1);
  292|      0|        TRACE(("dropbear_exit longjmped"))
  293|       |        /* dropbear_exit jumped here */
  294|      0|    }
  295|       |
  296|      0|    return 0;
  297|  1.49k|}
fuzz_dump:
  345|  96.2k|void fuzz_dump(const unsigned char* data, size_t len) {
  346|  96.2k|    if (fuzz.dumping) {
  ------------------
  |  Branch (346:9): [True: 0, False: 96.2k]
  ------------------
  347|      0|        TRACE(("dump %zu", len))
  348|      0|        assert(atomicio(vwrite, fuzz.recv_dumpfd, (void*)data, len) == len);
  349|      0|    }
  350|  96.2k|}
fuzz_getpwnam:
  373|  1.50k|struct passwd* fuzz_getpwnam(const char *login) {
  374|  1.50k|    if (!fuzz.fuzzing) {
  ------------------
  |  Branch (374:9): [True: 0, False: 1.50k]
  ------------------
  375|      0|        return getpwnam(login);
  376|      0|    }
  377|  1.50k|    if (strcmp(login, pwd_other.pw_name) == 0) {
  ------------------
  |  Branch (377:9): [True: 0, False: 1.50k]
  ------------------
  378|      0|        return &pwd_other;
  379|      0|    }
  380|  1.50k|    if (strcmp(login, pwd_root.pw_name) == 0) {
  ------------------
  |  Branch (380:9): [True: 1.50k, False: 0]
  ------------------
  381|  1.50k|        return &pwd_root;
  382|  1.50k|    }
  383|      0|    return NULL;
  384|  1.50k|}
fuzz-common.c:fuzz_dropbear_log:
   84|  3.75k|static void fuzz_dropbear_log(int UNUSED(priority), const char* UNUSED(format), va_list UNUSED(param)) {
   85|       |    /* No print */
   86|  3.75k|}
fuzz-common.c:load_fixed_hostkeys:
  153|      1|static void load_fixed_hostkeys(void) {
  154|       |
  155|      1|    buffer *b = buf_new(3000);
  156|      1|    enum signkey_type type;
  157|       |
  158|      1|    TRACE(("load fixed hostkeys"))
  159|       |
  160|      1|    svr_opts.hostkey = new_sign_key();
  161|       |
  162|      1|    buf_setlen(b, 0);
  163|      1|    buf_putbytes(b, keyr, keyr_len);
  164|      1|    buf_setpos(b, 0);
  165|      1|    type = DROPBEAR_SIGNKEY_RSA;
  166|      1|    if (buf_get_priv_key(b, svr_opts.hostkey, &type) == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (166:9): [True: 0, False: 1]
  ------------------
  167|      0|        dropbear_exit("failed fixed rsa hostkey");
  168|      0|    }
  169|       |
  170|      1|    buf_setlen(b, 0);
  171|      1|    buf_putbytes(b, keyd, keyd_len);
  172|      1|    buf_setpos(b, 0);
  173|      1|    type = DROPBEAR_SIGNKEY_DSS;
  174|      1|    if (buf_get_priv_key(b, svr_opts.hostkey, &type) == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (174:9): [True: 0, False: 1]
  ------------------
  175|      0|        dropbear_exit("failed fixed dss hostkey");
  176|      0|    }
  177|       |
  178|      1|    buf_setlen(b, 0);
  179|      1|    buf_putbytes(b, keye, keye_len);
  180|      1|    buf_setpos(b, 0);
  181|      1|    type = DROPBEAR_SIGNKEY_ECDSA_NISTP256;
  182|      1|    if (buf_get_priv_key(b, svr_opts.hostkey, &type) == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (182:9): [True: 0, False: 1]
  ------------------
  183|      0|        dropbear_exit("failed fixed ecdsa hostkey");
  184|      0|    }
  185|       |
  186|      1|    buf_setlen(b, 0);
  187|      1|    buf_putbytes(b, keyed25519, keyed25519_len);
  188|      1|    buf_setpos(b, 0);
  189|      1|    type = DROPBEAR_SIGNKEY_ED25519;
  190|      1|    if (buf_get_priv_key(b, svr_opts.hostkey, &type) == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (190:9): [True: 0, False: 1]
  ------------------
  191|      0|        dropbear_exit("failed fixed ed25519 hostkey");
  192|      0|    }
  193|       |
  194|      1|    buf_free(b);
  195|      1|}

fuzz-sshpacketmutator.c:alloc_static_buffers:
  126|      2|static void alloc_static_buffers() {
  127|       |
  128|      2|    int i;
  129|      2|    oup = buf_new(MAX_OUT_SIZE);
  130|      2|    alloc_packetA = buf_new(RECV_MAX_PACKET_LEN);
  ------------------
  |  |  215|      2|#define RECV_MAX_PACKET_LEN (MAX(35000, ((RECV_MAX_PAYLOAD_LEN)+100)))
  ------------------
  131|      2|    alloc_packetB = buf_new(RECV_MAX_PACKET_LEN);
  ------------------
  |  |  215|      2|#define RECV_MAX_PACKET_LEN (MAX(35000, ((RECV_MAX_PAYLOAD_LEN)+100)))
  ------------------
  132|       |
  133|  1.00k|    for (i = 0; i < MAX_FUZZ_PACKETS; i++) {
  ------------------
  |  |   20|  1.00k|#define MAX_FUZZ_PACKETS 500
  ------------------
  |  Branch (133:17): [True: 1.00k, False: 2]
  ------------------
  134|  1.00k|        packets1[i] = buf_new(RECV_MAX_PACKET_LEN);
  ------------------
  |  |  215|  1.00k|#define RECV_MAX_PACKET_LEN (MAX(35000, ((RECV_MAX_PAYLOAD_LEN)+100)))
  ------------------
  135|  1.00k|    }
  136|  1.00k|    for (i = 0; i < MAX_FUZZ_PACKETS; i++) {
  ------------------
  |  |   20|  1.00k|#define MAX_FUZZ_PACKETS 500
  ------------------
  |  Branch (136:17): [True: 1.00k, False: 2]
  ------------------
  137|  1.00k|        packets2[i] = buf_new(RECV_MAX_PACKET_LEN);
  ------------------
  |  |  215|  1.00k|#define RECV_MAX_PACKET_LEN (MAX(35000, ((RECV_MAX_PAYLOAD_LEN)+100)))
  ------------------
  138|  1.00k|    }
  139|      2|}

wrapfd_setup:
   32|  1.49k|void wrapfd_setup(buffer *buf) {
   33|  1.49k|	TRACE(("wrapfd_setup"))
   34|       |
   35|       |	// clean old ones
   36|  1.49k|	int i;
   37|  18.6k|	for (i = 0; i <= wrapfd_maxfd; i++) {
  ------------------
  |  Branch (37:14): [True: 17.1k, False: 1.49k]
  ------------------
   38|  17.1k|		if (wrap_fds[i].mode != UNUSED) {
  ------------------
  |  Branch (38:7): [True: 460, False: 16.6k]
  ------------------
   39|    460|			wrapfd_remove(i);
   40|    460|		}
   41|  17.1k|	}
   42|  1.49k|	wrapfd_maxfd = -1;
   43|       |
   44|  1.49k|	memset(rand_state, 0x0, sizeof(rand_state));
   45|  1.49k|	wrapfd_setseed(50);
   46|  1.49k|	input_buf = buf;
   47|  1.49k|}
wrapfd_setseed:
   49|  2.99k|void wrapfd_setseed(uint32_t seed) {
   50|  2.99k|	memcpy(rand_state, &seed, sizeof(seed));
   51|  2.99k|	nrand48(rand_state);
   52|  2.99k|}
wrapfd_new_fuzzinput:
   54|  1.49k|int wrapfd_new_fuzzinput() {
   55|  1.49k|	if (devnull_fd == -1) {
  ------------------
  |  Branch (55:6): [True: 1, False: 1.49k]
  ------------------
   56|      1|		devnull_fd = open("/dev/null", O_RDONLY);
   57|      1|		assert(devnull_fd != -1);
   58|      1|	}
   59|       |
   60|  1.49k|	int fd = dup(devnull_fd);
   61|  1.49k|	assert(fd != -1);
   62|  1.49k|	assert(wrap_fds[fd].mode == UNUSED);
   63|  1.49k|	wrap_fds[fd].mode = COMMONBUF;
   64|  1.49k|	wrap_fds[fd].closein = 0;
   65|  1.49k|	wrap_fds[fd].closeout = 0;
   66|  1.49k|	wrapfd_maxfd = MAX(fd, wrapfd_maxfd);
   67|       |
   68|  1.49k|	return fd;
   69|  1.49k|}
wrapfd_new_dummy:
   71|  4.67k|int wrapfd_new_dummy() {
   72|  4.67k|	if (devnull_fd == -1) {
  ------------------
  |  Branch (72:6): [True: 0, False: 4.67k]
  ------------------
   73|      0|		devnull_fd = open("/dev/null", O_RDONLY);
   74|      0|		assert(devnull_fd != -1);
   75|      0|	}
   76|       |
   77|  4.67k|	int fd = dup(devnull_fd);
   78|  4.67k|	if (fd == -1) {
  ------------------
  |  Branch (78:6): [True: 0, False: 4.67k]
  ------------------
   79|      0|		return -1;
   80|      0|	}
   81|  4.67k|	if (fd > IOWRAP_MAXFD) {
  ------------------
  |  |    9|  4.67k|#define IOWRAP_MAXFD (FD_SETSIZE-1)
  ------------------
  |  Branch (81:6): [True: 0, False: 4.67k]
  ------------------
   82|      0|		close(fd);
   83|      0|		errno = EMFILE;
   84|      0|		return -1;
   85|      0|	}
   86|  4.67k|	assert(wrap_fds[fd].mode == UNUSED);
   87|  4.67k|	wrap_fds[fd].mode = DUMMY;
   88|  4.67k|	wrap_fds[fd].closein = 0;
   89|  4.67k|	wrap_fds[fd].closeout = 0;
   90|  4.67k|	wrapfd_maxfd = MAX(fd, wrapfd_maxfd);
   91|       |
   92|  4.67k|	return fd;
   93|  4.67k|}
wrapfd_close:
  105|  5.70k|int wrapfd_close(int fd) {
  106|  5.70k|	if (fd >= 0 && fd <= IOWRAP_MAXFD && wrap_fds[fd].mode != UNUSED) {
  ------------------
  |  |    9|  11.4k|#define IOWRAP_MAXFD (FD_SETSIZE-1)
  ------------------
  |  Branch (106:6): [True: 5.70k, False: 0]
  |  Branch (106:17): [True: 5.70k, False: 0]
  |  Branch (106:39): [True: 5.70k, False: 0]
  ------------------
  107|  5.70k|		wrapfd_remove(fd);
  108|  5.70k|		return 0;
  109|  5.70k|	} else {
  110|      0|		return close(fd);
  111|      0|	}
  112|  5.70k|}
wrapfd_read:
  114|   567k|int wrapfd_read(int fd, void *out, size_t count) {
  115|   567k|	size_t maxread;
  116|       |
  117|   567k|	if (!fuzz.wrapfds) {
  ------------------
  |  Branch (117:6): [True: 0, False: 567k]
  ------------------
  118|      0|		return read(fd, out, count);
  119|      0|	}
  120|       |
  121|   567k|	if (fd < 0 || fd > IOWRAP_MAXFD || wrap_fds[fd].mode == UNUSED) {
  ------------------
  |  |    9|  1.13M|#define IOWRAP_MAXFD (FD_SETSIZE-1)
  ------------------
  |  Branch (121:6): [True: 0, False: 567k]
  |  Branch (121:16): [True: 0, False: 567k]
  |  Branch (121:37): [True: 0, False: 567k]
  ------------------
  122|       |		/* XXX - assertion failure? */
  123|      0|		TRACE(("Bad read descriptor %d\n", fd))
  124|      0|		errno = EBADF;
  125|      0|		return -1;
  126|      0|	}
  127|       |
  128|   567k|	assert(count != 0);
  129|       |
  130|   567k|	if (wrap_fds[fd].closein || erand48(rand_state) < CHANCE_CLOSE) {
  ------------------
  |  Branch (130:6): [True: 0, False: 567k]
  |  Branch (130:30): [True: 305, False: 566k]
  ------------------
  131|    305|		wrap_fds[fd].closein = 1;
  132|    305|		errno = ECONNRESET;
  133|    305|		return -1;
  134|    305|	}
  135|       |
  136|   566k|	if (erand48(rand_state) < CHANCE_INTR) {
  ------------------
  |  Branch (136:6): [True: 697, False: 566k]
  ------------------
  137|    697|		errno = EINTR;
  138|    697|		return -1;
  139|    697|	}
  140|       |
  141|   566k|	if (input_buf && wrap_fds[fd].mode == COMMONBUF) {
  ------------------
  |  Branch (141:6): [True: 566k, False: 0]
  |  Branch (141:19): [True: 361k, False: 204k]
  ------------------
  142|   361k|		maxread = MIN(input_buf->len - input_buf->pos, count);
  143|       |		/* returns 0 if buf is EOF, as intended */
  144|   361k|		if (maxread > 0) {
  ------------------
  |  Branch (144:7): [True: 360k, False: 1.03k]
  ------------------
  145|   360k|			maxread = nrand48(rand_state) % maxread + 1;
  146|   360k|		}
  147|   361k|		memcpy(out, buf_getptr(input_buf, maxread), maxread);
  148|   361k|		buf_incrpos(input_buf, maxread);
  149|   361k|		return maxread;
  150|   361k|	}
  151|       |
  152|       |	// return fixed output, of random length
  153|   204k|	maxread = MIN(MAX_RANDOM_IN, count);
  154|   204k|	maxread = nrand48(rand_state) % maxread + 1;
  155|   204k|	memset(out, 0xef, maxread);
  156|   204k|	return maxread;
  157|   566k|}
wrapfd_select:
  196|   502k|	fd_set *exceptfds, struct timeval *timeout) {
  197|   502k|	int i, nset, sel;
  198|   502k|	int ret = 0;
  199|   502k|	int fdlist[IOWRAP_MAXFD+1];
  200|       |
  201|   502k|	if (!fuzz.wrapfds) {
  ------------------
  |  Branch (201:6): [True: 0, False: 502k]
  ------------------
  202|      0|		return select(nfds, readfds, writefds, exceptfds, timeout);
  203|      0|	}
  204|       |
  205|   502k|	assert(nfds <= IOWRAP_MAXFD+1);
  206|       |
  207|   502k|	if (erand48(rand_state) < CHANCE_INTR) {
  ------------------
  |  Branch (207:6): [True: 657, False: 501k]
  ------------------
  208|    657|		errno = EINTR;
  209|    657|		return -1;
  210|    657|	}
  211|       |
  212|       |	/* read */
  213|   501k|	if (readfds != NULL && erand48(rand_state) < CHANCE_READ1) {
  ------------------
  |  Branch (213:6): [True: 501k, False: 0]
  |  Branch (213:25): [True: 477k, False: 24.2k]
  ------------------
  214|  9.47M|		for (i = 0, nset = 0; i < nfds; i++) {
  ------------------
  |  Branch (214:25): [True: 8.99M, False: 477k]
  ------------------
  215|  8.99M|			if (FD_ISSET(i, readfds)) {
  216|  1.37M|				assert(wrap_fds[i].mode != UNUSED);
  217|  1.37M|				fdlist[nset] = i;
  218|  1.37M|				nset++;
  219|  1.37M|			}
  220|  8.99M|		}
  221|   477k|		DROPBEAR_FD_ZERO(readfds);
  ------------------
  |  |  104|   477k|#define DROPBEAR_FD_ZERO(fds) FD_ZERO(fds)
  ------------------
  222|       |
  223|   477k|		if (nset > 0) {
  ------------------
  |  Branch (223:7): [True: 420k, False: 56.7k]
  ------------------
  224|       |			/* set one */
  225|   420k|			sel = fdlist[nrand48(rand_state) % nset];
  226|   420k|			FD_SET(sel, readfds);
  227|   420k|			ret++;
  228|       |
  229|   420k|			if (erand48(rand_state) < CHANCE_READ2) {
  ------------------
  |  Branch (229:8): [True: 208k, False: 212k]
  ------------------
  230|   208k|				sel = fdlist[nrand48(rand_state) % nset];
  231|   208k|				if (!FD_ISSET(sel, readfds)) {
  ------------------
  |  Branch (231:9): [True: 59.6k, False: 149k]
  ------------------
  232|  59.6k|					FD_SET(sel, readfds);
  233|  59.6k|					ret++;
  234|  59.6k|				}
  235|   208k|			}
  236|   420k|		}
  237|   477k|	}
  238|       |
  239|       |	/* write */
  240|   501k|	if (writefds != NULL && erand48(rand_state) < CHANCE_WRITE1) {
  ------------------
  |  Branch (240:6): [True: 457k, False: 44.2k]
  |  Branch (240:26): [True: 437k, False: 19.5k]
  ------------------
  241|  9.15M|		for (i = 0, nset = 0; i < nfds; i++) {
  ------------------
  |  Branch (241:25): [True: 8.71M, False: 437k]
  ------------------
  242|  8.71M|			if (FD_ISSET(i, writefds)) {
  243|   184k|				assert(wrap_fds[i].mode != UNUSED);
  244|   184k|				fdlist[nset] = i;
  245|   184k|				nset++;
  246|   184k|			}
  247|  8.71M|		}
  248|   437k|		DROPBEAR_FD_ZERO(writefds);
  ------------------
  |  |  104|   437k|#define DROPBEAR_FD_ZERO(fds) FD_ZERO(fds)
  ------------------
  249|       |
  250|       |		/* set one */
  251|   437k|		if (nset > 0) {
  ------------------
  |  Branch (251:7): [True: 184k, False: 253k]
  ------------------
  252|   184k|			sel = fdlist[nrand48(rand_state) % nset];
  253|   184k|			FD_SET(sel, writefds);
  254|   184k|			ret++;
  255|       |
  256|   184k|			if (erand48(rand_state) < CHANCE_WRITE2) {
  ------------------
  |  Branch (256:8): [True: 90.8k, False: 93.5k]
  ------------------
  257|  90.8k|				sel = fdlist[nrand48(rand_state) % nset];
  258|  90.8k|				if (!FD_ISSET(sel, writefds)) {
  ------------------
  |  Branch (258:9): [True: 0, False: 90.8k]
  ------------------
  259|      0|					FD_SET(sel, writefds);
  260|      0|					ret++;
  261|      0|				}
  262|  90.8k|			}
  263|   184k|		}
  264|   437k|	}
  265|   501k|	return ret;
  266|   501k|}
fuzz_kill:
  268|    185|int fuzz_kill(pid_t pid, int sig) {
  269|    185|	if (fuzz.fuzzing) {
  ------------------
  |  Branch (269:6): [True: 185, False: 0]
  ------------------
  270|    185|		TRACE(("fuzz_kill ignoring pid %d signal %d", (pid), sig))
  271|    185|		if (sig >= 0) {
  ------------------
  |  Branch (271:7): [True: 185, False: 0]
  ------------------
  272|    185|			return 0;
  273|    185|		} else {
  274|      0|			errno = EINVAL;
  275|      0|			return -1;
  276|      0|		}
  277|    185|	}
  278|      0|	return kill(pid, sig);
  279|    185|}
fuzz-wrapfd.c:wrapfd_remove:
   96|  6.16k|static void wrapfd_remove(int fd) {
   97|  6.16k|	TRACE(("wrapfd_remove %d", fd))
   98|  6.16k|	assert(fd >= 0);
   99|  6.16k|	assert(fd <= IOWRAP_MAXFD);
  100|  6.16k|	assert(wrap_fds[fd].mode != UNUSED);
  101|  6.16k|	wrap_fds[fd].mode = UNUSED;
  102|  6.16k|	close(fd);
  103|  6.16k|}

LLVMFuzzerTestOneInput:
    3|  1.49k|int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
    4|  1.49k|	return fuzz_run_server(Data, Size, 1, 1);
    5|  1.49k|}

rijndael_setup:
  123|  3.55k|{
  124|  3.55k|    int i;
  125|  3.55k|    ulong32 temp, *rk;
  126|  3.55k|#ifndef ENCRYPT_ONLY
  127|  3.55k|    ulong32 *rrk;
  128|  3.55k|#endif
  129|  3.55k|    LTC_ARGCHK(key  != NULL);
  ------------------
  |  |   32|  3.55k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 3.55k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  130|  3.55k|    LTC_ARGCHK(skey != NULL);
  ------------------
  |  |   32|  3.55k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 3.55k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  131|       |
  132|  3.55k|    if (keylen != 16 && keylen != 24 && keylen != 32) {
  ------------------
  |  Branch (132:9): [True: 1.24k, False: 2.31k]
  |  Branch (132:25): [True: 1.24k, False: 0]
  |  Branch (132:41): [True: 0, False: 1.24k]
  ------------------
  133|      0|       return CRYPT_INVALID_KEYSIZE;
  134|      0|    }
  135|       |
  136|  3.55k|    if (num_rounds != 0 && num_rounds != (10 + ((keylen/8)-2)*2)) {
  ------------------
  |  Branch (136:9): [True: 0, False: 3.55k]
  |  Branch (136:28): [True: 0, False: 0]
  ------------------
  137|      0|       return CRYPT_INVALID_ROUNDS;
  138|      0|    }
  139|       |
  140|  3.55k|    skey->rijndael.Nr = 10 + ((keylen/8)-2)*2;
  141|       |
  142|       |    /* setup the forward key */
  143|  3.55k|    i                 = 0;
  144|  3.55k|    rk                = skey->rijndael.eK;
  145|  3.55k|    LOAD32H(rk[0], key     );
  ------------------
  |  |   66|  3.55k|#define LOAD32H(x, y)                           \
  |  |   67|  3.55k|do { XMEMCPY (&(x), (y), 4);                    \
  |  |  ------------------
  |  |  |  |   39|  3.55k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |   68|  3.55k|      (x) = __builtin_bswap32 ((x)); } while(0)
  |  |  ------------------
  |  |  |  Branch (68:46): [Folded - Ignored]
  |  |  ------------------
  ------------------
  146|  3.55k|    LOAD32H(rk[1], key +  4);
  ------------------
  |  |   66|  3.55k|#define LOAD32H(x, y)                           \
  |  |   67|  3.55k|do { XMEMCPY (&(x), (y), 4);                    \
  |  |  ------------------
  |  |  |  |   39|  3.55k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |   68|  3.55k|      (x) = __builtin_bswap32 ((x)); } while(0)
  |  |  ------------------
  |  |  |  Branch (68:46): [Folded - Ignored]
  |  |  ------------------
  ------------------
  147|  3.55k|    LOAD32H(rk[2], key +  8);
  ------------------
  |  |   66|  3.55k|#define LOAD32H(x, y)                           \
  |  |   67|  3.55k|do { XMEMCPY (&(x), (y), 4);                    \
  |  |  ------------------
  |  |  |  |   39|  3.55k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |   68|  3.55k|      (x) = __builtin_bswap32 ((x)); } while(0)
  |  |  ------------------
  |  |  |  Branch (68:46): [Folded - Ignored]
  |  |  ------------------
  ------------------
  148|  3.55k|    LOAD32H(rk[3], key + 12);
  ------------------
  |  |   66|  3.55k|#define LOAD32H(x, y)                           \
  |  |   67|  3.55k|do { XMEMCPY (&(x), (y), 4);                    \
  |  |  ------------------
  |  |  |  |   39|  3.55k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |   68|  3.55k|      (x) = __builtin_bswap32 ((x)); } while(0)
  |  |  ------------------
  |  |  |  Branch (68:46): [Folded - Ignored]
  |  |  ------------------
  ------------------
  149|  3.55k|    if (keylen == 16) {
  ------------------
  |  Branch (149:9): [True: 2.31k, False: 1.24k]
  ------------------
  150|  23.1k|        for (;;) {
  151|  23.1k|            temp  = rk[3];
  152|  23.1k|            rk[4] = rk[0] ^ setup_mix(temp) ^ rcon[i];
  153|  23.1k|            rk[5] = rk[1] ^ rk[4];
  154|  23.1k|            rk[6] = rk[2] ^ rk[5];
  155|  23.1k|            rk[7] = rk[3] ^ rk[6];
  156|  23.1k|            if (++i == 10) {
  ------------------
  |  Branch (156:17): [True: 2.31k, False: 20.8k]
  ------------------
  157|  2.31k|               break;
  158|  2.31k|            }
  159|  20.8k|            rk += 4;
  160|  20.8k|        }
  161|  2.31k|    } else if (keylen == 24) {
  ------------------
  |  Branch (161:16): [True: 0, False: 1.24k]
  ------------------
  162|      0|        LOAD32H(rk[4], key + 16);
  ------------------
  |  |   66|      0|#define LOAD32H(x, y)                           \
  |  |   67|      0|do { XMEMCPY (&(x), (y), 4);                    \
  |  |  ------------------
  |  |  |  |   39|      0|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |   68|      0|      (x) = __builtin_bswap32 ((x)); } while(0)
  |  |  ------------------
  |  |  |  Branch (68:46): [Folded - Ignored]
  |  |  ------------------
  ------------------
  163|      0|        LOAD32H(rk[5], key + 20);
  ------------------
  |  |   66|      0|#define LOAD32H(x, y)                           \
  |  |   67|      0|do { XMEMCPY (&(x), (y), 4);                    \
  |  |  ------------------
  |  |  |  |   39|      0|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |   68|      0|      (x) = __builtin_bswap32 ((x)); } while(0)
  |  |  ------------------
  |  |  |  Branch (68:46): [Folded - Ignored]
  |  |  ------------------
  ------------------
  164|      0|        for (;;) {
  165|       |        #ifdef _MSC_VER
  166|       |            temp = skey->rijndael.eK[rk - skey->rijndael.eK + 5];
  167|       |        #else
  168|      0|            temp = rk[5];
  169|      0|        #endif
  170|      0|            rk[ 6] = rk[ 0] ^ setup_mix(temp) ^ rcon[i];
  171|      0|            rk[ 7] = rk[ 1] ^ rk[ 6];
  172|      0|            rk[ 8] = rk[ 2] ^ rk[ 7];
  173|      0|            rk[ 9] = rk[ 3] ^ rk[ 8];
  174|      0|            if (++i == 8) {
  ------------------
  |  Branch (174:17): [True: 0, False: 0]
  ------------------
  175|      0|                break;
  176|      0|            }
  177|      0|            rk[10] = rk[ 4] ^ rk[ 9];
  178|      0|            rk[11] = rk[ 5] ^ rk[10];
  179|      0|            rk += 6;
  180|      0|        }
  181|  1.24k|    } else if (keylen == 32) {
  ------------------
  |  Branch (181:16): [True: 1.24k, False: 0]
  ------------------
  182|  1.24k|        LOAD32H(rk[4], key + 16);
  ------------------
  |  |   66|  1.24k|#define LOAD32H(x, y)                           \
  |  |   67|  1.24k|do { XMEMCPY (&(x), (y), 4);                    \
  |  |  ------------------
  |  |  |  |   39|  1.24k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |   68|  1.24k|      (x) = __builtin_bswap32 ((x)); } while(0)
  |  |  ------------------
  |  |  |  Branch (68:46): [Folded - Ignored]
  |  |  ------------------
  ------------------
  183|  1.24k|        LOAD32H(rk[5], key + 20);
  ------------------
  |  |   66|  1.24k|#define LOAD32H(x, y)                           \
  |  |   67|  1.24k|do { XMEMCPY (&(x), (y), 4);                    \
  |  |  ------------------
  |  |  |  |   39|  1.24k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |   68|  1.24k|      (x) = __builtin_bswap32 ((x)); } while(0)
  |  |  ------------------
  |  |  |  Branch (68:46): [Folded - Ignored]
  |  |  ------------------
  ------------------
  184|  1.24k|        LOAD32H(rk[6], key + 24);
  ------------------
  |  |   66|  1.24k|#define LOAD32H(x, y)                           \
  |  |   67|  1.24k|do { XMEMCPY (&(x), (y), 4);                    \
  |  |  ------------------
  |  |  |  |   39|  1.24k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |   68|  1.24k|      (x) = __builtin_bswap32 ((x)); } while(0)
  |  |  ------------------
  |  |  |  Branch (68:46): [Folded - Ignored]
  |  |  ------------------
  ------------------
  185|  1.24k|        LOAD32H(rk[7], key + 28);
  ------------------
  |  |   66|  1.24k|#define LOAD32H(x, y)                           \
  |  |   67|  1.24k|do { XMEMCPY (&(x), (y), 4);                    \
  |  |  ------------------
  |  |  |  |   39|  1.24k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |   68|  1.24k|      (x) = __builtin_bswap32 ((x)); } while(0)
  |  |  ------------------
  |  |  |  Branch (68:46): [Folded - Ignored]
  |  |  ------------------
  ------------------
  186|  8.68k|        for (;;) {
  187|       |        #ifdef _MSC_VER
  188|       |            temp = skey->rijndael.eK[rk - skey->rijndael.eK + 7];
  189|       |        #else
  190|  8.68k|            temp = rk[7];
  191|  8.68k|        #endif
  192|  8.68k|            rk[ 8] = rk[ 0] ^ setup_mix(temp) ^ rcon[i];
  193|  8.68k|            rk[ 9] = rk[ 1] ^ rk[ 8];
  194|  8.68k|            rk[10] = rk[ 2] ^ rk[ 9];
  195|  8.68k|            rk[11] = rk[ 3] ^ rk[10];
  196|  8.68k|            if (++i == 7) {
  ------------------
  |  Branch (196:17): [True: 1.24k, False: 7.44k]
  ------------------
  197|  1.24k|                break;
  198|  1.24k|            }
  199|  7.44k|            temp = rk[11];
  200|  7.44k|            rk[12] = rk[ 4] ^ setup_mix(RORc(temp, 8));
  ------------------
  |  |  283|  7.44k|#define RORc(word,i) ({ \
  |  |  284|  7.44k|   ulong32 __RORc_tmp = (word); \
  |  |  285|  7.44k|   __asm__ ("rorl %2, %0" : \
  |  |  286|  7.44k|            "=r" (__RORc_tmp) : \
  |  |  287|  7.44k|            "0" (__RORc_tmp), \
  |  |  288|  7.44k|            "I" (i)); \
  |  |  289|  7.44k|            __RORc_tmp; \
  |  |  290|  7.44k|   })
  ------------------
  201|  7.44k|            rk[13] = rk[ 5] ^ rk[12];
  202|  7.44k|            rk[14] = rk[ 6] ^ rk[13];
  203|  7.44k|            rk[15] = rk[ 7] ^ rk[14];
  204|  7.44k|            rk += 8;
  205|  7.44k|        }
  206|  1.24k|    } else {
  207|       |       /* this can't happen */
  208|       |       /* coverity[dead_error_line] */
  209|      0|       return CRYPT_ERROR;
  210|      0|    }
  211|       |
  212|  3.55k|#ifndef ENCRYPT_ONLY
  213|       |    /* setup the inverse key now */
  214|  3.55k|    rk   = skey->rijndael.dK;
  215|  3.55k|    rrk  = skey->rijndael.eK + (28 + keylen) - 4;
  216|       |
  217|       |    /* apply the inverse MixColumn transform to all round keys but the first and the last: */
  218|       |    /* copy first */
  219|  3.55k|    *rk++ = *rrk++;
  220|  3.55k|    *rk++ = *rrk++;
  221|  3.55k|    *rk++ = *rrk++;
  222|  3.55k|    *rk   = *rrk;
  223|  3.55k|    rk -= 3; rrk -= 3;
  224|       |
  225|  40.5k|    for (i = 1; i < skey->rijndael.Nr; i++) {
  ------------------
  |  Branch (225:17): [True: 36.9k, False: 3.55k]
  ------------------
  226|  36.9k|        rrk -= 4;
  227|  36.9k|        rk  += 4;
  228|  36.9k|    #ifdef LTC_SMALL_CODE
  229|  36.9k|        temp = rrk[0];
  230|  36.9k|        rk[0] = setup_mix2(temp);
  231|  36.9k|        temp = rrk[1];
  232|  36.9k|        rk[1] = setup_mix2(temp);
  233|  36.9k|        temp = rrk[2];
  234|  36.9k|        rk[2] = setup_mix2(temp);
  235|  36.9k|        temp = rrk[3];
  236|  36.9k|        rk[3] = setup_mix2(temp);
  237|       |     #else
  238|       |        temp = rrk[0];
  239|       |        rk[0] =
  240|       |            Tks0[byte(temp, 3)] ^
  241|       |            Tks1[byte(temp, 2)] ^
  242|       |            Tks2[byte(temp, 1)] ^
  243|       |            Tks3[byte(temp, 0)];
  244|       |        temp = rrk[1];
  245|       |        rk[1] =
  246|       |            Tks0[byte(temp, 3)] ^
  247|       |            Tks1[byte(temp, 2)] ^
  248|       |            Tks2[byte(temp, 1)] ^
  249|       |            Tks3[byte(temp, 0)];
  250|       |        temp = rrk[2];
  251|       |        rk[2] =
  252|       |            Tks0[byte(temp, 3)] ^
  253|       |            Tks1[byte(temp, 2)] ^
  254|       |            Tks2[byte(temp, 1)] ^
  255|       |            Tks3[byte(temp, 0)];
  256|       |        temp = rrk[3];
  257|       |        rk[3] =
  258|       |            Tks0[byte(temp, 3)] ^
  259|       |            Tks1[byte(temp, 2)] ^
  260|       |            Tks2[byte(temp, 1)] ^
  261|       |            Tks3[byte(temp, 0)];
  262|       |      #endif
  263|       |
  264|  36.9k|    }
  265|       |
  266|       |    /* copy last */
  267|  3.55k|    rrk -= 4;
  268|  3.55k|    rk  += 4;
  269|  3.55k|    *rk++ = *rrk++;
  270|  3.55k|    *rk++ = *rrk++;
  271|  3.55k|    *rk++ = *rrk++;
  272|  3.55k|    *rk   = *rrk;
  273|  3.55k|#endif /* ENCRYPT_ONLY */
  274|       |
  275|  3.55k|    return CRYPT_OK;
  276|  3.55k|}
rijndael_ecb_encrypt:
  290|  5.85M|{
  291|  5.85M|    ulong32 s0, s1, s2, s3, t0, t1, t2, t3, *rk;
  292|  5.85M|    int Nr, r;
  293|       |
  294|  5.85M|    LTC_ARGCHK(pt != NULL);
  ------------------
  |  |   32|  5.85M|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 5.85M]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  295|  5.85M|    LTC_ARGCHK(ct != NULL);
  ------------------
  |  |   32|  5.85M|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 5.85M]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  296|  5.85M|    LTC_ARGCHK(skey != NULL);
  ------------------
  |  |   32|  5.85M|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 5.85M]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  297|       |
  298|  5.85M|    Nr = skey->rijndael.Nr;
  299|  5.85M|    rk = skey->rijndael.eK;
  300|       |
  301|       |    /*
  302|       |     * map byte array block to cipher state
  303|       |     * and add initial round key:
  304|       |     */
  305|  5.85M|    LOAD32H(s0, pt      ); s0 ^= rk[0];
  ------------------
  |  |   66|  5.85M|#define LOAD32H(x, y)                           \
  |  |   67|  5.85M|do { XMEMCPY (&(x), (y), 4);                    \
  |  |  ------------------
  |  |  |  |   39|  5.85M|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |   68|  5.85M|      (x) = __builtin_bswap32 ((x)); } while(0)
  |  |  ------------------
  |  |  |  Branch (68:46): [Folded - Ignored]
  |  |  ------------------
  ------------------
  306|  5.85M|    LOAD32H(s1, pt  +  4); s1 ^= rk[1];
  ------------------
  |  |   66|  5.85M|#define LOAD32H(x, y)                           \
  |  |   67|  5.85M|do { XMEMCPY (&(x), (y), 4);                    \
  |  |  ------------------
  |  |  |  |   39|  5.85M|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |   68|  5.85M|      (x) = __builtin_bswap32 ((x)); } while(0)
  |  |  ------------------
  |  |  |  Branch (68:46): [Folded - Ignored]
  |  |  ------------------
  ------------------
  307|  5.85M|    LOAD32H(s2, pt  +  8); s2 ^= rk[2];
  ------------------
  |  |   66|  5.85M|#define LOAD32H(x, y)                           \
  |  |   67|  5.85M|do { XMEMCPY (&(x), (y), 4);                    \
  |  |  ------------------
  |  |  |  |   39|  5.85M|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |   68|  5.85M|      (x) = __builtin_bswap32 ((x)); } while(0)
  |  |  ------------------
  |  |  |  Branch (68:46): [Folded - Ignored]
  |  |  ------------------
  ------------------
  308|  5.85M|    LOAD32H(s3, pt  + 12); s3 ^= rk[3];
  ------------------
  |  |   66|  5.85M|#define LOAD32H(x, y)                           \
  |  |   67|  5.85M|do { XMEMCPY (&(x), (y), 4);                    \
  |  |  ------------------
  |  |  |  |   39|  5.85M|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |   68|  5.85M|      (x) = __builtin_bswap32 ((x)); } while(0)
  |  |  ------------------
  |  |  |  Branch (68:46): [Folded - Ignored]
  |  |  ------------------
  ------------------
  309|       |
  310|  5.85M|#ifdef LTC_SMALL_CODE
  311|       |
  312|  57.5M|    for (r = 0; ; r++) {
  313|  57.5M|        rk += 4;
  314|  57.5M|        t0 =
  315|  57.5M|            Te0(byte(s0, 3)) ^
  ------------------
  |  |  306|  57.5M|#define Te0(x) TE0[x]
  ------------------
  316|  57.5M|            Te1(byte(s1, 2)) ^
  ------------------
  |  |  307|  57.5M|#define Te1(x) RORc(TE0[x], 8)
  |  |  ------------------
  |  |  |  |  283|  57.5M|#define RORc(word,i) ({ \
  |  |  |  |  284|  57.5M|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  285|  57.5M|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  286|  57.5M|            "=r" (__RORc_tmp) : \
  |  |  |  |  287|  57.5M|            "0" (__RORc_tmp), \
  |  |  |  |  288|  57.5M|            "I" (i)); \
  |  |  |  |  289|  57.5M|            __RORc_tmp; \
  |  |  |  |  290|  57.5M|   })
  |  |  ------------------
  ------------------
  317|  57.5M|            Te2(byte(s2, 1)) ^
  ------------------
  |  |  308|  57.5M|#define Te2(x) RORc(TE0[x], 16)
  |  |  ------------------
  |  |  |  |  283|  57.5M|#define RORc(word,i) ({ \
  |  |  |  |  284|  57.5M|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  285|  57.5M|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  286|  57.5M|            "=r" (__RORc_tmp) : \
  |  |  |  |  287|  57.5M|            "0" (__RORc_tmp), \
  |  |  |  |  288|  57.5M|            "I" (i)); \
  |  |  |  |  289|  57.5M|            __RORc_tmp; \
  |  |  |  |  290|  57.5M|   })
  |  |  ------------------
  ------------------
  318|  57.5M|            Te3(byte(s3, 0)) ^
  ------------------
  |  |  309|  57.5M|#define Te3(x) RORc(TE0[x], 24)
  |  |  ------------------
  |  |  |  |  283|  57.5M|#define RORc(word,i) ({ \
  |  |  |  |  284|  57.5M|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  285|  57.5M|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  286|  57.5M|            "=r" (__RORc_tmp) : \
  |  |  |  |  287|  57.5M|            "0" (__RORc_tmp), \
  |  |  |  |  288|  57.5M|            "I" (i)); \
  |  |  |  |  289|  57.5M|            __RORc_tmp; \
  |  |  |  |  290|  57.5M|   })
  |  |  ------------------
  ------------------
  319|  57.5M|            rk[0];
  320|  57.5M|        t1 =
  321|  57.5M|            Te0(byte(s1, 3)) ^
  ------------------
  |  |  306|  57.5M|#define Te0(x) TE0[x]
  ------------------
  322|  57.5M|            Te1(byte(s2, 2)) ^
  ------------------
  |  |  307|  57.5M|#define Te1(x) RORc(TE0[x], 8)
  |  |  ------------------
  |  |  |  |  283|  57.5M|#define RORc(word,i) ({ \
  |  |  |  |  284|  57.5M|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  285|  57.5M|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  286|  57.5M|            "=r" (__RORc_tmp) : \
  |  |  |  |  287|  57.5M|            "0" (__RORc_tmp), \
  |  |  |  |  288|  57.5M|            "I" (i)); \
  |  |  |  |  289|  57.5M|            __RORc_tmp; \
  |  |  |  |  290|  57.5M|   })
  |  |  ------------------
  ------------------
  323|  57.5M|            Te2(byte(s3, 1)) ^
  ------------------
  |  |  308|  57.5M|#define Te2(x) RORc(TE0[x], 16)
  |  |  ------------------
  |  |  |  |  283|  57.5M|#define RORc(word,i) ({ \
  |  |  |  |  284|  57.5M|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  285|  57.5M|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  286|  57.5M|            "=r" (__RORc_tmp) : \
  |  |  |  |  287|  57.5M|            "0" (__RORc_tmp), \
  |  |  |  |  288|  57.5M|            "I" (i)); \
  |  |  |  |  289|  57.5M|            __RORc_tmp; \
  |  |  |  |  290|  57.5M|   })
  |  |  ------------------
  ------------------
  324|  57.5M|            Te3(byte(s0, 0)) ^
  ------------------
  |  |  309|  57.5M|#define Te3(x) RORc(TE0[x], 24)
  |  |  ------------------
  |  |  |  |  283|  57.5M|#define RORc(word,i) ({ \
  |  |  |  |  284|  57.5M|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  285|  57.5M|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  286|  57.5M|            "=r" (__RORc_tmp) : \
  |  |  |  |  287|  57.5M|            "0" (__RORc_tmp), \
  |  |  |  |  288|  57.5M|            "I" (i)); \
  |  |  |  |  289|  57.5M|            __RORc_tmp; \
  |  |  |  |  290|  57.5M|   })
  |  |  ------------------
  ------------------
  325|  57.5M|            rk[1];
  326|  57.5M|        t2 =
  327|  57.5M|            Te0(byte(s2, 3)) ^
  ------------------
  |  |  306|  57.5M|#define Te0(x) TE0[x]
  ------------------
  328|  57.5M|            Te1(byte(s3, 2)) ^
  ------------------
  |  |  307|  57.5M|#define Te1(x) RORc(TE0[x], 8)
  |  |  ------------------
  |  |  |  |  283|  57.5M|#define RORc(word,i) ({ \
  |  |  |  |  284|  57.5M|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  285|  57.5M|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  286|  57.5M|            "=r" (__RORc_tmp) : \
  |  |  |  |  287|  57.5M|            "0" (__RORc_tmp), \
  |  |  |  |  288|  57.5M|            "I" (i)); \
  |  |  |  |  289|  57.5M|            __RORc_tmp; \
  |  |  |  |  290|  57.5M|   })
  |  |  ------------------
  ------------------
  329|  57.5M|            Te2(byte(s0, 1)) ^
  ------------------
  |  |  308|  57.5M|#define Te2(x) RORc(TE0[x], 16)
  |  |  ------------------
  |  |  |  |  283|  57.5M|#define RORc(word,i) ({ \
  |  |  |  |  284|  57.5M|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  285|  57.5M|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  286|  57.5M|            "=r" (__RORc_tmp) : \
  |  |  |  |  287|  57.5M|            "0" (__RORc_tmp), \
  |  |  |  |  288|  57.5M|            "I" (i)); \
  |  |  |  |  289|  57.5M|            __RORc_tmp; \
  |  |  |  |  290|  57.5M|   })
  |  |  ------------------
  ------------------
  330|  57.5M|            Te3(byte(s1, 0)) ^
  ------------------
  |  |  309|  57.5M|#define Te3(x) RORc(TE0[x], 24)
  |  |  ------------------
  |  |  |  |  283|  57.5M|#define RORc(word,i) ({ \
  |  |  |  |  284|  57.5M|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  285|  57.5M|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  286|  57.5M|            "=r" (__RORc_tmp) : \
  |  |  |  |  287|  57.5M|            "0" (__RORc_tmp), \
  |  |  |  |  288|  57.5M|            "I" (i)); \
  |  |  |  |  289|  57.5M|            __RORc_tmp; \
  |  |  |  |  290|  57.5M|   })
  |  |  ------------------
  ------------------
  331|  57.5M|            rk[2];
  332|  57.5M|        t3 =
  333|  57.5M|            Te0(byte(s3, 3)) ^
  ------------------
  |  |  306|  57.5M|#define Te0(x) TE0[x]
  ------------------
  334|  57.5M|            Te1(byte(s0, 2)) ^
  ------------------
  |  |  307|  57.5M|#define Te1(x) RORc(TE0[x], 8)
  |  |  ------------------
  |  |  |  |  283|  57.5M|#define RORc(word,i) ({ \
  |  |  |  |  284|  57.5M|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  285|  57.5M|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  286|  57.5M|            "=r" (__RORc_tmp) : \
  |  |  |  |  287|  57.5M|            "0" (__RORc_tmp), \
  |  |  |  |  288|  57.5M|            "I" (i)); \
  |  |  |  |  289|  57.5M|            __RORc_tmp; \
  |  |  |  |  290|  57.5M|   })
  |  |  ------------------
  ------------------
  335|  57.5M|            Te2(byte(s1, 1)) ^
  ------------------
  |  |  308|  57.5M|#define Te2(x) RORc(TE0[x], 16)
  |  |  ------------------
  |  |  |  |  283|  57.5M|#define RORc(word,i) ({ \
  |  |  |  |  284|  57.5M|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  285|  57.5M|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  286|  57.5M|            "=r" (__RORc_tmp) : \
  |  |  |  |  287|  57.5M|            "0" (__RORc_tmp), \
  |  |  |  |  288|  57.5M|            "I" (i)); \
  |  |  |  |  289|  57.5M|            __RORc_tmp; \
  |  |  |  |  290|  57.5M|   })
  |  |  ------------------
  ------------------
  336|  57.5M|            Te3(byte(s2, 0)) ^
  ------------------
  |  |  309|  57.5M|#define Te3(x) RORc(TE0[x], 24)
  |  |  ------------------
  |  |  |  |  283|  57.5M|#define RORc(word,i) ({ \
  |  |  |  |  284|  57.5M|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  285|  57.5M|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  286|  57.5M|            "=r" (__RORc_tmp) : \
  |  |  |  |  287|  57.5M|            "0" (__RORc_tmp), \
  |  |  |  |  288|  57.5M|            "I" (i)); \
  |  |  |  |  289|  57.5M|            __RORc_tmp; \
  |  |  |  |  290|  57.5M|   })
  |  |  ------------------
  ------------------
  337|  57.5M|            rk[3];
  338|  57.5M|        if (r == Nr-2) {
  ------------------
  |  Branch (338:13): [True: 5.85M, False: 51.7M]
  ------------------
  339|  5.85M|           break;
  340|  5.85M|        }
  341|  51.7M|        s0 = t0; s1 = t1; s2 = t2; s3 = t3;
  342|  51.7M|    }
  343|  5.85M|    rk += 4;
  344|       |
  345|       |#else
  346|       |
  347|       |    /*
  348|       |     * Nr - 1 full rounds:
  349|       |     */
  350|       |    r = Nr >> 1;
  351|       |    for (;;) {
  352|       |        t0 =
  353|       |            Te0(byte(s0, 3)) ^
  354|       |            Te1(byte(s1, 2)) ^
  355|       |            Te2(byte(s2, 1)) ^
  356|       |            Te3(byte(s3, 0)) ^
  357|       |            rk[4];
  358|       |        t1 =
  359|       |            Te0(byte(s1, 3)) ^
  360|       |            Te1(byte(s2, 2)) ^
  361|       |            Te2(byte(s3, 1)) ^
  362|       |            Te3(byte(s0, 0)) ^
  363|       |            rk[5];
  364|       |        t2 =
  365|       |            Te0(byte(s2, 3)) ^
  366|       |            Te1(byte(s3, 2)) ^
  367|       |            Te2(byte(s0, 1)) ^
  368|       |            Te3(byte(s1, 0)) ^
  369|       |            rk[6];
  370|       |        t3 =
  371|       |            Te0(byte(s3, 3)) ^
  372|       |            Te1(byte(s0, 2)) ^
  373|       |            Te2(byte(s1, 1)) ^
  374|       |            Te3(byte(s2, 0)) ^
  375|       |            rk[7];
  376|       |
  377|       |        rk += 8;
  378|       |        if (--r == 0) {
  379|       |            break;
  380|       |        }
  381|       |
  382|       |        s0 =
  383|       |            Te0(byte(t0, 3)) ^
  384|       |            Te1(byte(t1, 2)) ^
  385|       |            Te2(byte(t2, 1)) ^
  386|       |            Te3(byte(t3, 0)) ^
  387|       |            rk[0];
  388|       |        s1 =
  389|       |            Te0(byte(t1, 3)) ^
  390|       |            Te1(byte(t2, 2)) ^
  391|       |            Te2(byte(t3, 1)) ^
  392|       |            Te3(byte(t0, 0)) ^
  393|       |            rk[1];
  394|       |        s2 =
  395|       |            Te0(byte(t2, 3)) ^
  396|       |            Te1(byte(t3, 2)) ^
  397|       |            Te2(byte(t0, 1)) ^
  398|       |            Te3(byte(t1, 0)) ^
  399|       |            rk[2];
  400|       |        s3 =
  401|       |            Te0(byte(t3, 3)) ^
  402|       |            Te1(byte(t0, 2)) ^
  403|       |            Te2(byte(t1, 1)) ^
  404|       |            Te3(byte(t2, 0)) ^
  405|       |            rk[3];
  406|       |    }
  407|       |
  408|       |#endif
  409|       |
  410|       |    /*
  411|       |     * apply last round and
  412|       |     * map cipher state to byte array block:
  413|       |     */
  414|  5.85M|    s0 =
  415|  5.85M|        (Te4_3[byte(t0, 3)]) ^
  ------------------
  |  |  319|  5.85M|#define Te4_3 0xFF000000 & Te4
  ------------------
                      (Te4_3[byte(t0, 3)]) ^
  ------------------
  |  |  436|  5.85M|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
  416|  5.85M|        (Te4_2[byte(t1, 2)]) ^
  ------------------
  |  |  318|  5.85M|#define Te4_2 0x00FF0000 & Te4
  ------------------
                      (Te4_2[byte(t1, 2)]) ^
  ------------------
  |  |  436|  5.85M|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
  417|  5.85M|        (Te4_1[byte(t2, 1)]) ^
  ------------------
  |  |  317|  5.85M|#define Te4_1 0x0000FF00 & Te4
  ------------------
                      (Te4_1[byte(t2, 1)]) ^
  ------------------
  |  |  436|  5.85M|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
  418|  5.85M|        (Te4_0[byte(t3, 0)]) ^
  ------------------
  |  |  316|  5.85M|#define Te4_0 0x000000FF & Te4
  ------------------
                      (Te4_0[byte(t3, 0)]) ^
  ------------------
  |  |  436|  5.85M|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
  419|  5.85M|        rk[0];
  420|  5.85M|    STORE32H(s0, ct);
  ------------------
  |  |   62|  5.85M|#define STORE32H(x, y)                          \
  |  |   63|  5.85M|do { ulong32 __t = __builtin_bswap32 ((x));     \
  |  |   64|  5.85M|      XMEMCPY ((y), &__t, 4); } while(0)
  |  |  ------------------
  |  |  |  |   39|  5.85M|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (64:39): [Folded - Ignored]
  |  |  ------------------
  ------------------
  421|  5.85M|    s1 =
  422|  5.85M|        (Te4_3[byte(t1, 3)]) ^
  ------------------
  |  |  319|  5.85M|#define Te4_3 0xFF000000 & Te4
  ------------------
                      (Te4_3[byte(t1, 3)]) ^
  ------------------
  |  |  436|  5.85M|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
  423|  5.85M|        (Te4_2[byte(t2, 2)]) ^
  ------------------
  |  |  318|  5.85M|#define Te4_2 0x00FF0000 & Te4
  ------------------
                      (Te4_2[byte(t2, 2)]) ^
  ------------------
  |  |  436|  5.85M|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
  424|  5.85M|        (Te4_1[byte(t3, 1)]) ^
  ------------------
  |  |  317|  5.85M|#define Te4_1 0x0000FF00 & Te4
  ------------------
                      (Te4_1[byte(t3, 1)]) ^
  ------------------
  |  |  436|  5.85M|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
  425|  5.85M|        (Te4_0[byte(t0, 0)]) ^
  ------------------
  |  |  316|  5.85M|#define Te4_0 0x000000FF & Te4
  ------------------
                      (Te4_0[byte(t0, 0)]) ^
  ------------------
  |  |  436|  5.85M|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
  426|  5.85M|        rk[1];
  427|  5.85M|    STORE32H(s1, ct+4);
  ------------------
  |  |   62|  5.85M|#define STORE32H(x, y)                          \
  |  |   63|  5.85M|do { ulong32 __t = __builtin_bswap32 ((x));     \
  |  |   64|  5.85M|      XMEMCPY ((y), &__t, 4); } while(0)
  |  |  ------------------
  |  |  |  |   39|  5.85M|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (64:39): [Folded - Ignored]
  |  |  ------------------
  ------------------
  428|  5.85M|    s2 =
  429|  5.85M|        (Te4_3[byte(t2, 3)]) ^
  ------------------
  |  |  319|  5.85M|#define Te4_3 0xFF000000 & Te4
  ------------------
                      (Te4_3[byte(t2, 3)]) ^
  ------------------
  |  |  436|  5.85M|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
  430|  5.85M|        (Te4_2[byte(t3, 2)]) ^
  ------------------
  |  |  318|  5.85M|#define Te4_2 0x00FF0000 & Te4
  ------------------
                      (Te4_2[byte(t3, 2)]) ^
  ------------------
  |  |  436|  5.85M|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
  431|  5.85M|        (Te4_1[byte(t0, 1)]) ^
  ------------------
  |  |  317|  5.85M|#define Te4_1 0x0000FF00 & Te4
  ------------------
                      (Te4_1[byte(t0, 1)]) ^
  ------------------
  |  |  436|  5.85M|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
  432|  5.85M|        (Te4_0[byte(t1, 0)]) ^
  ------------------
  |  |  316|  5.85M|#define Te4_0 0x000000FF & Te4
  ------------------
                      (Te4_0[byte(t1, 0)]) ^
  ------------------
  |  |  436|  5.85M|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
  433|  5.85M|        rk[2];
  434|  5.85M|    STORE32H(s2, ct+8);
  ------------------
  |  |   62|  5.85M|#define STORE32H(x, y)                          \
  |  |   63|  5.85M|do { ulong32 __t = __builtin_bswap32 ((x));     \
  |  |   64|  5.85M|      XMEMCPY ((y), &__t, 4); } while(0)
  |  |  ------------------
  |  |  |  |   39|  5.85M|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (64:39): [Folded - Ignored]
  |  |  ------------------
  ------------------
  435|  5.85M|    s3 =
  436|  5.85M|        (Te4_3[byte(t3, 3)]) ^
  ------------------
  |  |  319|  5.85M|#define Te4_3 0xFF000000 & Te4
  ------------------
                      (Te4_3[byte(t3, 3)]) ^
  ------------------
  |  |  436|  5.85M|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
  437|  5.85M|        (Te4_2[byte(t0, 2)]) ^
  ------------------
  |  |  318|  5.85M|#define Te4_2 0x00FF0000 & Te4
  ------------------
                      (Te4_2[byte(t0, 2)]) ^
  ------------------
  |  |  436|  5.85M|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
  438|  5.85M|        (Te4_1[byte(t1, 1)]) ^
  ------------------
  |  |  317|  5.85M|#define Te4_1 0x0000FF00 & Te4
  ------------------
                      (Te4_1[byte(t1, 1)]) ^
  ------------------
  |  |  436|  5.85M|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
  439|  5.85M|        (Te4_0[byte(t2, 0)]) ^
  ------------------
  |  |  316|  5.85M|#define Te4_0 0x000000FF & Te4
  ------------------
                      (Te4_0[byte(t2, 0)]) ^
  ------------------
  |  |  436|  5.85M|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
  440|  5.85M|        rk[3];
  441|  5.85M|    STORE32H(s3, ct+12);
  ------------------
  |  |   62|  5.85M|#define STORE32H(x, y)                          \
  |  |   63|  5.85M|do { ulong32 __t = __builtin_bswap32 ((x));     \
  |  |   64|  5.85M|      XMEMCPY ((y), &__t, 4); } while(0)
  |  |  ------------------
  |  |  |  |   39|  5.85M|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (64:39): [Folded - Ignored]
  |  |  ------------------
  ------------------
  442|       |
  443|  5.85M|    return CRYPT_OK;
  444|  5.85M|}
aes.c:setup_mix:
   95|  39.2k|{
   96|  39.2k|   return (Te4_3[byte(temp, 2)]) ^
  ------------------
  |  |  319|  39.2k|#define Te4_3 0xFF000000 & Te4
  ------------------
                 return (Te4_3[byte(temp, 2)]) ^
  ------------------
  |  |  436|  39.2k|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
   97|  39.2k|          (Te4_2[byte(temp, 1)]) ^
  ------------------
  |  |  318|  39.2k|#define Te4_2 0x00FF0000 & Te4
  ------------------
                        (Te4_2[byte(temp, 1)]) ^
  ------------------
  |  |  436|  39.2k|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
   98|  39.2k|          (Te4_1[byte(temp, 0)]) ^
  ------------------
  |  |  317|  39.2k|#define Te4_1 0x0000FF00 & Te4
  ------------------
                        (Te4_1[byte(temp, 0)]) ^
  ------------------
  |  |  436|  39.2k|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
   99|  39.2k|          (Te4_0[byte(temp, 3)]);
  ------------------
  |  |  316|  39.2k|#define Te4_0 0x000000FF & Te4
  ------------------
                        (Te4_0[byte(temp, 3)]);
  ------------------
  |  |  436|  39.2k|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
  100|  39.2k|}
aes.c:setup_mix2:
  105|   147k|{
  106|   147k|   return Td0(255 & Te4[byte(temp, 3)]) ^
  ------------------
  |  |  311|   147k|#define Td0(x) TD0[x]
  ------------------
  107|   147k|          Td1(255 & Te4[byte(temp, 2)]) ^
  ------------------
  |  |  312|   147k|#define Td1(x) RORc(TD0[x], 8)
  |  |  ------------------
  |  |  |  |  283|   147k|#define RORc(word,i) ({ \
  |  |  |  |  284|   147k|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  285|   147k|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  286|   147k|            "=r" (__RORc_tmp) : \
  |  |  |  |  287|   147k|            "0" (__RORc_tmp), \
  |  |  |  |  288|   147k|            "I" (i)); \
  |  |  |  |  289|   147k|            __RORc_tmp; \
  |  |  |  |  290|   147k|   })
  |  |  ------------------
  ------------------
  108|   147k|          Td2(255 & Te4[byte(temp, 1)]) ^
  ------------------
  |  |  313|   147k|#define Td2(x) RORc(TD0[x], 16)
  |  |  ------------------
  |  |  |  |  283|   147k|#define RORc(word,i) ({ \
  |  |  |  |  284|   147k|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  285|   147k|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  286|   147k|            "=r" (__RORc_tmp) : \
  |  |  |  |  287|   147k|            "0" (__RORc_tmp), \
  |  |  |  |  288|   147k|            "I" (i)); \
  |  |  |  |  289|   147k|            __RORc_tmp; \
  |  |  |  |  290|   147k|   })
  |  |  ------------------
  ------------------
  109|   147k|          Td3(255 & Te4[byte(temp, 0)]);
  ------------------
  |  |  314|   147k|#define Td3(x) RORc(TD0[x], 24)
  |  |  ------------------
  |  |  |  |  283|   147k|#define RORc(word,i) ({ \
  |  |  |  |  284|   147k|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  285|   147k|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  286|   147k|            "=r" (__RORc_tmp) : \
  |  |  |  |  287|   147k|            "0" (__RORc_tmp), \
  |  |  |  |  288|   147k|            "I" (i)); \
  |  |  |  |  289|   147k|            __RORc_tmp; \
  |  |  |  |  290|   147k|   })
  |  |  ------------------
  ------------------
  110|   147k|}

sha1_init:
  164|  17.9k|{
  165|  17.9k|   LTC_ARGCHK(md != NULL);
  ------------------
  |  |   32|  17.9k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 17.9k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  166|  17.9k|   md->sha1.state[0] = 0x67452301UL;
  167|  17.9k|   md->sha1.state[1] = 0xefcdab89UL;
  168|  17.9k|   md->sha1.state[2] = 0x98badcfeUL;
  169|  17.9k|   md->sha1.state[3] = 0x10325476UL;
  170|  17.9k|   md->sha1.state[4] = 0xc3d2e1f0UL;
  171|  17.9k|   md->sha1.curlen = 0;
  172|  17.9k|   md->sha1.length = 0;
  173|  17.9k|   return CRYPT_OK;
  174|  17.9k|}
sha1_done:
  192|  44.8k|{
  193|  44.8k|    int i;
  194|       |
  195|  44.8k|    LTC_ARGCHK(md  != NULL);
  ------------------
  |  |   32|  44.8k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 44.8k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  196|  44.8k|    LTC_ARGCHK(out != NULL);
  ------------------
  |  |   32|  44.8k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 44.8k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  197|       |
  198|  44.8k|    if (md->sha1.curlen >= sizeof(md->sha1.buf)) {
  ------------------
  |  Branch (198:9): [True: 0, False: 44.8k]
  ------------------
  199|      0|       return CRYPT_INVALID_ARG;
  200|      0|    }
  201|       |
  202|       |    /* increase the length of the message */
  203|  44.8k|    md->sha1.length += md->sha1.curlen * 8;
  204|       |
  205|       |    /* append the '1' bit */
  206|  44.8k|    md->sha1.buf[md->sha1.curlen++] = (unsigned char)0x80;
  207|       |
  208|       |    /* if the length is currently above 56 bytes we append zeros
  209|       |     * then compress.  Then we can fall back to padding zeros and length
  210|       |     * encoding like normal.
  211|       |     */
  212|  44.8k|    if (md->sha1.curlen > 56) {
  ------------------
  |  Branch (212:9): [True: 291, False: 44.5k]
  ------------------
  213|    811|        while (md->sha1.curlen < 64) {
  ------------------
  |  Branch (213:16): [True: 520, False: 291]
  ------------------
  214|    520|            md->sha1.buf[md->sha1.curlen++] = (unsigned char)0;
  215|    520|        }
  216|    291|        sha1_compress(md, md->sha1.buf);
  217|    291|        md->sha1.curlen = 0;
  218|    291|    }
  219|       |
  220|       |    /* pad upto 56 bytes of zeroes */
  221|  1.14M|    while (md->sha1.curlen < 56) {
  ------------------
  |  Branch (221:12): [True: 1.10M, False: 44.8k]
  ------------------
  222|  1.10M|        md->sha1.buf[md->sha1.curlen++] = (unsigned char)0;
  223|  1.10M|    }
  224|       |
  225|       |    /* store length */
  226|  44.8k|    STORE64H(md->sha1.length, md->sha1.buf+56);
  ------------------
  |  |  101|  44.8k|#define STORE64H(x, y)                          \
  |  |  102|  44.8k|do { ulong64 __t = __builtin_bswap64 ((x));     \
  |  |  103|  44.8k|      XMEMCPY ((y), &__t, 8); } while(0)
  |  |  ------------------
  |  |  |  |   39|  44.8k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (103:39): [Folded - Ignored]
  |  |  ------------------
  ------------------
  227|  44.8k|    sha1_compress(md, md->sha1.buf);
  228|       |
  229|       |    /* copy output */
  230|   269k|    for (i = 0; i < 5; i++) {
  ------------------
  |  Branch (230:17): [True: 224k, False: 44.8k]
  ------------------
  231|   224k|        STORE32H(md->sha1.state[i], out+(4*i));
  ------------------
  |  |   62|   224k|#define STORE32H(x, y)                          \
  |  |   63|   224k|do { ulong32 __t = __builtin_bswap32 ((x));     \
  |  |   64|   224k|      XMEMCPY ((y), &__t, 4); } while(0)
  |  |  ------------------
  |  |  |  |   39|   224k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (64:39): [Folded - Ignored]
  |  |  ------------------
  ------------------
  232|   224k|    }
  233|       |#ifdef LTC_CLEAN_STACK
  234|       |    zeromem(md, sizeof(hash_state));
  235|       |#endif
  236|  44.8k|    return CRYPT_OK;
  237|  44.8k|}
sha1.c:sha1_compress:
   47|   724k|{
   48|   724k|    ulong32 a,b,c,d,e,W[80],i;
   49|   724k|#ifdef LTC_SMALL_CODE
   50|   724k|    ulong32 t;
   51|   724k|#endif
   52|       |
   53|       |    /* copy the state into 512-bits into W[0..15] */
   54|  12.3M|    for (i = 0; i < 16; i++) {
  ------------------
  |  Branch (54:17): [True: 11.5M, False: 724k]
  ------------------
   55|  11.5M|        LOAD32H(W[i], buf + (4*i));
  ------------------
  |  |   66|  11.5M|#define LOAD32H(x, y)                           \
  |  |   67|  11.5M|do { XMEMCPY (&(x), (y), 4);                    \
  |  |  ------------------
  |  |  |  |   39|  11.5M|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |   68|  11.5M|      (x) = __builtin_bswap32 ((x)); } while(0)
  |  |  ------------------
  |  |  |  Branch (68:46): [Folded - Ignored]
  |  |  ------------------
  ------------------
   56|  11.5M|    }
   57|       |
   58|       |    /* copy state */
   59|   724k|    a = md->sha1.state[0];
   60|   724k|    b = md->sha1.state[1];
   61|   724k|    c = md->sha1.state[2];
   62|   724k|    d = md->sha1.state[3];
   63|   724k|    e = md->sha1.state[4];
   64|       |
   65|       |    /* expand it */
   66|  47.1M|    for (i = 16; i < 80; i++) {
  ------------------
  |  Branch (66:18): [True: 46.3M, False: 724k]
  ------------------
   67|  46.3M|        W[i] = ROL(W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16], 1);
   68|  46.3M|    }
   69|       |
   70|       |    /* compress */
   71|       |    /* round one */
   72|   724k|    #define FF0(a,b,c,d,e,i) e = (ROLc(a, 5) + F0(b,c,d) + e + W[i] + 0x5a827999UL); b = ROLc(b, 30);
   73|   724k|    #define FF1(a,b,c,d,e,i) e = (ROLc(a, 5) + F1(b,c,d) + e + W[i] + 0x6ed9eba1UL); b = ROLc(b, 30);
   74|   724k|    #define FF2(a,b,c,d,e,i) e = (ROLc(a, 5) + F2(b,c,d) + e + W[i] + 0x8f1bbcdcUL); b = ROLc(b, 30);
   75|   724k|    #define FF3(a,b,c,d,e,i) e = (ROLc(a, 5) + F3(b,c,d) + e + W[i] + 0xca62c1d6UL); b = ROLc(b, 30);
   76|       |
   77|   724k|#ifdef LTC_SMALL_CODE
   78|       |
   79|  15.2M|    for (i = 0; i < 20; ) {
  ------------------
  |  Branch (79:17): [True: 14.4M, False: 724k]
  ------------------
   80|  14.4M|       FF0(a,b,c,d,e,i++); t = e; e = d; d = c; c = b; b = a; a = t;
  ------------------
  |  |   72|  14.4M|    #define FF0(a,b,c,d,e,i) e = (ROLc(a, 5) + F0(b,c,d) + e + W[i] + 0x5a827999UL); b = ROLc(b, 30);
  |  |  ------------------
  |  |  |  |  275|  14.4M|#define ROLc(word,i) ({ \
  |  |  |  |  276|  14.4M|   ulong32 __ROLc_tmp = (word); \
  |  |  |  |  277|  14.4M|   __asm__ ("roll %2, %0" : \
  |  |  |  |  278|  14.4M|            "=r" (__ROLc_tmp) : \
  |  |  |  |  279|  14.4M|            "0" (__ROLc_tmp), \
  |  |  |  |  280|  14.4M|            "I" (i)); \
  |  |  |  |  281|  14.4M|            __ROLc_tmp; \
  |  |  |  |  282|  14.4M|   })
  |  |  ------------------
  |  |                   #define FF0(a,b,c,d,e,i) e = (ROLc(a, 5) + F0(b,c,d) + e + W[i] + 0x5a827999UL); b = ROLc(b, 30);
  |  |  ------------------
  |  |  |  |   37|  14.4M|#define F0(x,y,z)  (z ^ (x & (y ^ z)))
  |  |  ------------------
  |  |                   #define FF0(a,b,c,d,e,i) e = (ROLc(a, 5) + F0(b,c,d) + e + W[i] + 0x5a827999UL); b = ROLc(b, 30);
  |  |  ------------------
  |  |  |  |  275|  14.4M|#define ROLc(word,i) ({ \
  |  |  |  |  276|  14.4M|   ulong32 __ROLc_tmp = (word); \
  |  |  |  |  277|  14.4M|   __asm__ ("roll %2, %0" : \
  |  |  |  |  278|  14.4M|            "=r" (__ROLc_tmp) : \
  |  |  |  |  279|  14.4M|            "0" (__ROLc_tmp), \
  |  |  |  |  280|  14.4M|            "I" (i)); \
  |  |  |  |  281|  14.4M|            __ROLc_tmp; \
  |  |  |  |  282|  14.4M|   })
  |  |  ------------------
  ------------------
   81|  14.4M|    }
   82|       |
   83|  15.2M|    for (; i < 40; ) {
  ------------------
  |  Branch (83:12): [True: 14.4M, False: 724k]
  ------------------
   84|  14.4M|       FF1(a,b,c,d,e,i++); t = e; e = d; d = c; c = b; b = a; a = t;
  ------------------
  |  |   73|  14.4M|    #define FF1(a,b,c,d,e,i) e = (ROLc(a, 5) + F1(b,c,d) + e + W[i] + 0x6ed9eba1UL); b = ROLc(b, 30);
  |  |  ------------------
  |  |  |  |  275|  14.4M|#define ROLc(word,i) ({ \
  |  |  |  |  276|  14.4M|   ulong32 __ROLc_tmp = (word); \
  |  |  |  |  277|  14.4M|   __asm__ ("roll %2, %0" : \
  |  |  |  |  278|  14.4M|            "=r" (__ROLc_tmp) : \
  |  |  |  |  279|  14.4M|            "0" (__ROLc_tmp), \
  |  |  |  |  280|  14.4M|            "I" (i)); \
  |  |  |  |  281|  14.4M|            __ROLc_tmp; \
  |  |  |  |  282|  14.4M|   })
  |  |  ------------------
  |  |                   #define FF1(a,b,c,d,e,i) e = (ROLc(a, 5) + F1(b,c,d) + e + W[i] + 0x6ed9eba1UL); b = ROLc(b, 30);
  |  |  ------------------
  |  |  |  |   38|  14.4M|#define F1(x,y,z)  (x ^ y ^ z)
  |  |  ------------------
  |  |                   #define FF1(a,b,c,d,e,i) e = (ROLc(a, 5) + F1(b,c,d) + e + W[i] + 0x6ed9eba1UL); b = ROLc(b, 30);
  |  |  ------------------
  |  |  |  |  275|  14.4M|#define ROLc(word,i) ({ \
  |  |  |  |  276|  14.4M|   ulong32 __ROLc_tmp = (word); \
  |  |  |  |  277|  14.4M|   __asm__ ("roll %2, %0" : \
  |  |  |  |  278|  14.4M|            "=r" (__ROLc_tmp) : \
  |  |  |  |  279|  14.4M|            "0" (__ROLc_tmp), \
  |  |  |  |  280|  14.4M|            "I" (i)); \
  |  |  |  |  281|  14.4M|            __ROLc_tmp; \
  |  |  |  |  282|  14.4M|   })
  |  |  ------------------
  ------------------
   85|  14.4M|    }
   86|       |
   87|  15.2M|    for (; i < 60; ) {
  ------------------
  |  Branch (87:12): [True: 14.4M, False: 724k]
  ------------------
   88|  14.4M|       FF2(a,b,c,d,e,i++); t = e; e = d; d = c; c = b; b = a; a = t;
  ------------------
  |  |   74|  14.4M|    #define FF2(a,b,c,d,e,i) e = (ROLc(a, 5) + F2(b,c,d) + e + W[i] + 0x8f1bbcdcUL); b = ROLc(b, 30);
  |  |  ------------------
  |  |  |  |  275|  14.4M|#define ROLc(word,i) ({ \
  |  |  |  |  276|  14.4M|   ulong32 __ROLc_tmp = (word); \
  |  |  |  |  277|  14.4M|   __asm__ ("roll %2, %0" : \
  |  |  |  |  278|  14.4M|            "=r" (__ROLc_tmp) : \
  |  |  |  |  279|  14.4M|            "0" (__ROLc_tmp), \
  |  |  |  |  280|  14.4M|            "I" (i)); \
  |  |  |  |  281|  14.4M|            __ROLc_tmp; \
  |  |  |  |  282|  14.4M|   })
  |  |  ------------------
  |  |                   #define FF2(a,b,c,d,e,i) e = (ROLc(a, 5) + F2(b,c,d) + e + W[i] + 0x8f1bbcdcUL); b = ROLc(b, 30);
  |  |  ------------------
  |  |  |  |   39|  14.4M|#define F2(x,y,z)  ((x & y) | (z & (x | y)))
  |  |  ------------------
  |  |                   #define FF2(a,b,c,d,e,i) e = (ROLc(a, 5) + F2(b,c,d) + e + W[i] + 0x8f1bbcdcUL); b = ROLc(b, 30);
  |  |  ------------------
  |  |  |  |  275|  14.4M|#define ROLc(word,i) ({ \
  |  |  |  |  276|  14.4M|   ulong32 __ROLc_tmp = (word); \
  |  |  |  |  277|  14.4M|   __asm__ ("roll %2, %0" : \
  |  |  |  |  278|  14.4M|            "=r" (__ROLc_tmp) : \
  |  |  |  |  279|  14.4M|            "0" (__ROLc_tmp), \
  |  |  |  |  280|  14.4M|            "I" (i)); \
  |  |  |  |  281|  14.4M|            __ROLc_tmp; \
  |  |  |  |  282|  14.4M|   })
  |  |  ------------------
  ------------------
   89|  14.4M|    }
   90|       |
   91|  15.2M|    for (; i < 80; ) {
  ------------------
  |  Branch (91:12): [True: 14.4M, False: 724k]
  ------------------
   92|  14.4M|       FF3(a,b,c,d,e,i++); t = e; e = d; d = c; c = b; b = a; a = t;
  ------------------
  |  |   75|  14.4M|    #define FF3(a,b,c,d,e,i) e = (ROLc(a, 5) + F3(b,c,d) + e + W[i] + 0xca62c1d6UL); b = ROLc(b, 30);
  |  |  ------------------
  |  |  |  |  275|  14.4M|#define ROLc(word,i) ({ \
  |  |  |  |  276|  14.4M|   ulong32 __ROLc_tmp = (word); \
  |  |  |  |  277|  14.4M|   __asm__ ("roll %2, %0" : \
  |  |  |  |  278|  14.4M|            "=r" (__ROLc_tmp) : \
  |  |  |  |  279|  14.4M|            "0" (__ROLc_tmp), \
  |  |  |  |  280|  14.4M|            "I" (i)); \
  |  |  |  |  281|  14.4M|            __ROLc_tmp; \
  |  |  |  |  282|  14.4M|   })
  |  |  ------------------
  |  |                   #define FF3(a,b,c,d,e,i) e = (ROLc(a, 5) + F3(b,c,d) + e + W[i] + 0xca62c1d6UL); b = ROLc(b, 30);
  |  |  ------------------
  |  |  |  |   40|  14.4M|#define F3(x,y,z)  (x ^ y ^ z)
  |  |  ------------------
  |  |                   #define FF3(a,b,c,d,e,i) e = (ROLc(a, 5) + F3(b,c,d) + e + W[i] + 0xca62c1d6UL); b = ROLc(b, 30);
  |  |  ------------------
  |  |  |  |  275|  14.4M|#define ROLc(word,i) ({ \
  |  |  |  |  276|  14.4M|   ulong32 __ROLc_tmp = (word); \
  |  |  |  |  277|  14.4M|   __asm__ ("roll %2, %0" : \
  |  |  |  |  278|  14.4M|            "=r" (__ROLc_tmp) : \
  |  |  |  |  279|  14.4M|            "0" (__ROLc_tmp), \
  |  |  |  |  280|  14.4M|            "I" (i)); \
  |  |  |  |  281|  14.4M|            __ROLc_tmp; \
  |  |  |  |  282|  14.4M|   })
  |  |  ------------------
  ------------------
   93|  14.4M|    }
   94|       |
   95|       |#else
   96|       |
   97|       |    for (i = 0; i < 20; ) {
   98|       |       FF0(a,b,c,d,e,i++);
   99|       |       FF0(e,a,b,c,d,i++);
  100|       |       FF0(d,e,a,b,c,i++);
  101|       |       FF0(c,d,e,a,b,i++);
  102|       |       FF0(b,c,d,e,a,i++);
  103|       |    }
  104|       |
  105|       |    /* round two */
  106|       |    for (; i < 40; )  {
  107|       |       FF1(a,b,c,d,e,i++);
  108|       |       FF1(e,a,b,c,d,i++);
  109|       |       FF1(d,e,a,b,c,i++);
  110|       |       FF1(c,d,e,a,b,i++);
  111|       |       FF1(b,c,d,e,a,i++);
  112|       |    }
  113|       |
  114|       |    /* round three */
  115|       |    for (; i < 60; )  {
  116|       |       FF2(a,b,c,d,e,i++);
  117|       |       FF2(e,a,b,c,d,i++);
  118|       |       FF2(d,e,a,b,c,i++);
  119|       |       FF2(c,d,e,a,b,i++);
  120|       |       FF2(b,c,d,e,a,i++);
  121|       |    }
  122|       |
  123|       |    /* round four */
  124|       |    for (; i < 80; )  {
  125|       |       FF3(a,b,c,d,e,i++);
  126|       |       FF3(e,a,b,c,d,i++);
  127|       |       FF3(d,e,a,b,c,i++);
  128|       |       FF3(c,d,e,a,b,i++);
  129|       |       FF3(b,c,d,e,a,i++);
  130|       |    }
  131|       |#endif
  132|       |
  133|   724k|    #undef FF0
  134|   724k|    #undef FF1
  135|   724k|    #undef FF2
  136|   724k|    #undef FF3
  137|       |
  138|       |    /* store */
  139|   724k|    md->sha1.state[0] = md->sha1.state[0] + a;
  140|   724k|    md->sha1.state[1] = md->sha1.state[1] + b;
  141|   724k|    md->sha1.state[2] = md->sha1.state[2] + c;
  142|   724k|    md->sha1.state[3] = md->sha1.state[3] + d;
  143|   724k|    md->sha1.state[4] = md->sha1.state[4] + e;
  144|       |
  145|   724k|    return CRYPT_OK;
  146|   724k|}

sha256_init:
  205|   292k|{
  206|   292k|    LTC_ARGCHK(md != NULL);
  ------------------
  |  |   32|   292k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 292k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  207|       |
  208|   292k|    md->sha256.curlen = 0;
  209|   292k|    md->sha256.length = 0;
  210|   292k|    md->sha256.state[0] = 0x6A09E667UL;
  211|   292k|    md->sha256.state[1] = 0xBB67AE85UL;
  212|   292k|    md->sha256.state[2] = 0x3C6EF372UL;
  213|   292k|    md->sha256.state[3] = 0xA54FF53AUL;
  214|   292k|    md->sha256.state[4] = 0x510E527FUL;
  215|   292k|    md->sha256.state[5] = 0x9B05688CUL;
  216|   292k|    md->sha256.state[6] = 0x1F83D9ABUL;
  217|   292k|    md->sha256.state[7] = 0x5BE0CD19UL;
  218|   292k|    return CRYPT_OK;
  219|   292k|}
sha256_done:
  237|   313k|{
  238|   313k|    int i;
  239|       |
  240|   313k|    LTC_ARGCHK(md  != NULL);
  ------------------
  |  |   32|   313k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 313k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  241|   313k|    LTC_ARGCHK(out != NULL);
  ------------------
  |  |   32|   313k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 313k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  242|       |
  243|   313k|    if (md->sha256.curlen >= sizeof(md->sha256.buf)) {
  ------------------
  |  Branch (243:9): [True: 0, False: 313k]
  ------------------
  244|      0|       return CRYPT_INVALID_ARG;
  245|      0|    }
  246|       |
  247|       |
  248|       |    /* increase the length of the message */
  249|   313k|    md->sha256.length += md->sha256.curlen * 8;
  250|       |
  251|       |    /* append the '1' bit */
  252|   313k|    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|   313k|    if (md->sha256.curlen > 56) {
  ------------------
  |  Branch (258:9): [True: 1.15k, False: 312k]
  ------------------
  259|  3.55k|        while (md->sha256.curlen < 64) {
  ------------------
  |  Branch (259:16): [True: 2.40k, False: 1.15k]
  ------------------
  260|  2.40k|            md->sha256.buf[md->sha256.curlen++] = (unsigned char)0;
  261|  2.40k|        }
  262|  1.15k|        sha256_compress(md, md->sha256.buf);
  263|  1.15k|        md->sha256.curlen = 0;
  264|  1.15k|    }
  265|       |
  266|       |    /* pad upto 56 bytes of zeroes */
  267|  7.28M|    while (md->sha256.curlen < 56) {
  ------------------
  |  Branch (267:12): [True: 6.97M, False: 313k]
  ------------------
  268|  6.97M|        md->sha256.buf[md->sha256.curlen++] = (unsigned char)0;
  269|  6.97M|    }
  270|       |
  271|       |    /* store length */
  272|   313k|    STORE64H(md->sha256.length, md->sha256.buf+56);
  ------------------
  |  |  101|   313k|#define STORE64H(x, y)                          \
  |  |  102|   313k|do { ulong64 __t = __builtin_bswap64 ((x));     \
  |  |  103|   313k|      XMEMCPY ((y), &__t, 8); } while(0)
  |  |  ------------------
  |  |  |  |   39|   313k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (103:39): [Folded - Ignored]
  |  |  ------------------
  ------------------
  273|   313k|    sha256_compress(md, md->sha256.buf);
  274|       |
  275|       |    /* copy output */
  276|  2.82M|    for (i = 0; i < 8; i++) {
  ------------------
  |  Branch (276:17): [True: 2.50M, False: 313k]
  ------------------
  277|  2.50M|        STORE32H(md->sha256.state[i], out+(4*i));
  ------------------
  |  |   62|  2.50M|#define STORE32H(x, y)                          \
  |  |   63|  2.50M|do { ulong32 __t = __builtin_bswap32 ((x));     \
  |  |   64|  2.50M|      XMEMCPY ((y), &__t, 4); } while(0)
  |  |  ------------------
  |  |  |  |   39|  2.50M|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (64:39): [Folded - Ignored]
  |  |  ------------------
  ------------------
  278|  2.50M|    }
  279|       |#ifdef LTC_CLEAN_STACK
  280|       |    zeromem(md, sizeof(hash_state));
  281|       |#endif
  282|   313k|    return CRYPT_OK;
  283|   313k|}
sha256.c:sha256_compress:
   71|  1.25M|{
   72|  1.25M|    ulong32 S[8], W[64], t0, t1;
   73|  1.25M|#ifdef LTC_SMALL_CODE
   74|  1.25M|    ulong32 t;
   75|  1.25M|#endif
   76|  1.25M|    int i;
   77|       |
   78|       |    /* copy state into S */
   79|  11.3M|    for (i = 0; i < 8; i++) {
  ------------------
  |  Branch (79:17): [True: 10.0M, False: 1.25M]
  ------------------
   80|  10.0M|        S[i] = md->sha256.state[i];
   81|  10.0M|    }
   82|       |
   83|       |    /* copy the state into 512-bits into W[0..15] */
   84|  21.4M|    for (i = 0; i < 16; i++) {
  ------------------
  |  Branch (84:17): [True: 20.1M, False: 1.25M]
  ------------------
   85|  20.1M|        LOAD32H(W[i], buf + (4*i));
  ------------------
  |  |   66|  20.1M|#define LOAD32H(x, y)                           \
  |  |   67|  20.1M|do { XMEMCPY (&(x), (y), 4);                    \
  |  |  ------------------
  |  |  |  |   39|  20.1M|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |   68|  20.1M|      (x) = __builtin_bswap32 ((x)); } while(0)
  |  |  ------------------
  |  |  |  Branch (68:46): [Folded - Ignored]
  |  |  ------------------
  ------------------
   86|  20.1M|    }
   87|       |
   88|       |    /* fill W[16..63] */
   89|  61.7M|    for (i = 16; i < 64; i++) {
  ------------------
  |  Branch (89:18): [True: 60.4M, False: 1.25M]
  ------------------
   90|  60.4M|        W[i] = Gamma1(W[i - 2]) + W[i - 7] + Gamma0(W[i - 15]) + W[i - 16];
  ------------------
  |  |   63|  60.4M|#define Gamma1(x)       (S(x, 17) ^ S(x, 19) ^ R(x, 10))
  |  |  ------------------
  |  |  |  |   58|  60.4M|#define S(x, n)         RORc((x),(n))
  |  |  |  |  ------------------
  |  |  |  |  |  |  283|  60.4M|#define RORc(word,i) ({ \
  |  |  |  |  |  |  284|  60.4M|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  |  |  285|  60.4M|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  |  |  286|  60.4M|            "=r" (__RORc_tmp) : \
  |  |  |  |  |  |  287|  60.4M|            "0" (__RORc_tmp), \
  |  |  |  |  |  |  288|  60.4M|            "I" (i)); \
  |  |  |  |  |  |  289|  60.4M|            __RORc_tmp; \
  |  |  |  |  |  |  290|  60.4M|   })
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define Gamma1(x)       (S(x, 17) ^ S(x, 19) ^ R(x, 10))
  |  |  ------------------
  |  |  |  |   58|  60.4M|#define S(x, n)         RORc((x),(n))
  |  |  |  |  ------------------
  |  |  |  |  |  |  283|  60.4M|#define RORc(word,i) ({ \
  |  |  |  |  |  |  284|  60.4M|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  |  |  285|  60.4M|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  |  |  286|  60.4M|            "=r" (__RORc_tmp) : \
  |  |  |  |  |  |  287|  60.4M|            "0" (__RORc_tmp), \
  |  |  |  |  |  |  288|  60.4M|            "I" (i)); \
  |  |  |  |  |  |  289|  60.4M|            __RORc_tmp; \
  |  |  |  |  |  |  290|  60.4M|   })
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define Gamma1(x)       (S(x, 17) ^ S(x, 19) ^ R(x, 10))
  |  |  ------------------
  |  |  |  |   59|  60.4M|#define R(x, n)         (((x)&0xFFFFFFFFUL)>>(n))
  |  |  ------------------
  ------------------
                      W[i] = Gamma1(W[i - 2]) + W[i - 7] + Gamma0(W[i - 15]) + W[i - 16];
  ------------------
  |  |   62|  60.4M|#define Gamma0(x)       (S(x, 7) ^ S(x, 18) ^ R(x, 3))
  |  |  ------------------
  |  |  |  |   58|  60.4M|#define S(x, n)         RORc((x),(n))
  |  |  |  |  ------------------
  |  |  |  |  |  |  283|  60.4M|#define RORc(word,i) ({ \
  |  |  |  |  |  |  284|  60.4M|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  |  |  285|  60.4M|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  |  |  286|  60.4M|            "=r" (__RORc_tmp) : \
  |  |  |  |  |  |  287|  60.4M|            "0" (__RORc_tmp), \
  |  |  |  |  |  |  288|  60.4M|            "I" (i)); \
  |  |  |  |  |  |  289|  60.4M|            __RORc_tmp; \
  |  |  |  |  |  |  290|  60.4M|   })
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define Gamma0(x)       (S(x, 7) ^ S(x, 18) ^ R(x, 3))
  |  |  ------------------
  |  |  |  |   58|  60.4M|#define S(x, n)         RORc((x),(n))
  |  |  |  |  ------------------
  |  |  |  |  |  |  283|  60.4M|#define RORc(word,i) ({ \
  |  |  |  |  |  |  284|  60.4M|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  |  |  285|  60.4M|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  |  |  286|  60.4M|            "=r" (__RORc_tmp) : \
  |  |  |  |  |  |  287|  60.4M|            "0" (__RORc_tmp), \
  |  |  |  |  |  |  288|  60.4M|            "I" (i)); \
  |  |  |  |  |  |  289|  60.4M|            __RORc_tmp; \
  |  |  |  |  |  |  290|  60.4M|   })
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define Gamma0(x)       (S(x, 7) ^ S(x, 18) ^ R(x, 3))
  |  |  ------------------
  |  |  |  |   59|  60.4M|#define R(x, n)         (((x)&0xFFFFFFFFUL)>>(n))
  |  |  ------------------
  ------------------
   91|  60.4M|    }
   92|       |
   93|       |    /* Compress */
   94|  1.25M|#ifdef LTC_SMALL_CODE
   95|  1.25M|#define RND(a,b,c,d,e,f,g,h,i)                         \
   96|  1.25M|     t0 = h + Sigma1(e) + Ch(e, f, g) + K[i] + W[i];   \
   97|  1.25M|     t1 = Sigma0(a) + Maj(a, b, c);                    \
   98|  1.25M|     d += t0;                                          \
   99|  1.25M|     h  = t0 + t1;
  100|       |
  101|  81.8M|     for (i = 0; i < 64; ++i) {
  ------------------
  |  Branch (101:18): [True: 80.6M, False: 1.25M]
  ------------------
  102|  80.6M|         RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],i);
  ------------------
  |  |   96|  80.6M|     t0 = h + Sigma1(e) + Ch(e, f, g) + K[i] + W[i];   \
  |  |  ------------------
  |  |  |  |   61|  80.6M|#define Sigma1(x)       (S(x, 6) ^ S(x, 11) ^ S(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |   58|  80.6M|#define S(x, n)         RORc((x),(n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  283|  80.6M|#define RORc(word,i) ({ \
  |  |  |  |  |  |  |  |  284|  80.6M|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  |  |  |  |  285|  80.6M|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  |  |  |  |  286|  80.6M|            "=r" (__RORc_tmp) : \
  |  |  |  |  |  |  |  |  287|  80.6M|            "0" (__RORc_tmp), \
  |  |  |  |  |  |  |  |  288|  80.6M|            "I" (i)); \
  |  |  |  |  |  |  |  |  289|  80.6M|            __RORc_tmp; \
  |  |  |  |  |  |  |  |  290|  80.6M|   })
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define Sigma1(x)       (S(x, 6) ^ S(x, 11) ^ S(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |   58|  80.6M|#define S(x, n)         RORc((x),(n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  283|  80.6M|#define RORc(word,i) ({ \
  |  |  |  |  |  |  |  |  284|  80.6M|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  |  |  |  |  285|  80.6M|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  |  |  |  |  286|  80.6M|            "=r" (__RORc_tmp) : \
  |  |  |  |  |  |  |  |  287|  80.6M|            "0" (__RORc_tmp), \
  |  |  |  |  |  |  |  |  288|  80.6M|            "I" (i)); \
  |  |  |  |  |  |  |  |  289|  80.6M|            __RORc_tmp; \
  |  |  |  |  |  |  |  |  290|  80.6M|   })
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define Sigma1(x)       (S(x, 6) ^ S(x, 11) ^ S(x, 25))
  |  |  |  |  ------------------
  |  |  |  |  |  |   58|  80.6M|#define S(x, n)         RORc((x),(n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  283|  80.6M|#define RORc(word,i) ({ \
  |  |  |  |  |  |  |  |  284|  80.6M|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  |  |  |  |  285|  80.6M|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  |  |  |  |  286|  80.6M|            "=r" (__RORc_tmp) : \
  |  |  |  |  |  |  |  |  287|  80.6M|            "0" (__RORc_tmp), \
  |  |  |  |  |  |  |  |  288|  80.6M|            "I" (i)); \
  |  |  |  |  |  |  |  |  289|  80.6M|            __RORc_tmp; \
  |  |  |  |  |  |  |  |  290|  80.6M|   })
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                    t0 = h + Sigma1(e) + Ch(e, f, g) + K[i] + W[i];   \
  |  |  ------------------
  |  |  |  |   56|  80.6M|#define Ch(x,y,z)       (z ^ (x & (y ^ z)))
  |  |  ------------------
  |  |   97|  80.6M|     t1 = Sigma0(a) + Maj(a, b, c);                    \
  |  |  ------------------
  |  |  |  |   60|  80.6M|#define Sigma0(x)       (S(x, 2) ^ S(x, 13) ^ S(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |   58|  80.6M|#define S(x, n)         RORc((x),(n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  283|  80.6M|#define RORc(word,i) ({ \
  |  |  |  |  |  |  |  |  284|  80.6M|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  |  |  |  |  285|  80.6M|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  |  |  |  |  286|  80.6M|            "=r" (__RORc_tmp) : \
  |  |  |  |  |  |  |  |  287|  80.6M|            "0" (__RORc_tmp), \
  |  |  |  |  |  |  |  |  288|  80.6M|            "I" (i)); \
  |  |  |  |  |  |  |  |  289|  80.6M|            __RORc_tmp; \
  |  |  |  |  |  |  |  |  290|  80.6M|   })
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define Sigma0(x)       (S(x, 2) ^ S(x, 13) ^ S(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |   58|  80.6M|#define S(x, n)         RORc((x),(n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  283|  80.6M|#define RORc(word,i) ({ \
  |  |  |  |  |  |  |  |  284|  80.6M|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  |  |  |  |  285|  80.6M|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  |  |  |  |  286|  80.6M|            "=r" (__RORc_tmp) : \
  |  |  |  |  |  |  |  |  287|  80.6M|            "0" (__RORc_tmp), \
  |  |  |  |  |  |  |  |  288|  80.6M|            "I" (i)); \
  |  |  |  |  |  |  |  |  289|  80.6M|            __RORc_tmp; \
  |  |  |  |  |  |  |  |  290|  80.6M|   })
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |               #define Sigma0(x)       (S(x, 2) ^ S(x, 13) ^ S(x, 22))
  |  |  |  |  ------------------
  |  |  |  |  |  |   58|  80.6M|#define S(x, n)         RORc((x),(n))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  283|  80.6M|#define RORc(word,i) ({ \
  |  |  |  |  |  |  |  |  284|  80.6M|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  |  |  |  |  285|  80.6M|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  |  |  |  |  286|  80.6M|            "=r" (__RORc_tmp) : \
  |  |  |  |  |  |  |  |  287|  80.6M|            "0" (__RORc_tmp), \
  |  |  |  |  |  |  |  |  288|  80.6M|            "I" (i)); \
  |  |  |  |  |  |  |  |  289|  80.6M|            __RORc_tmp; \
  |  |  |  |  |  |  |  |  290|  80.6M|   })
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                    t1 = Sigma0(a) + Maj(a, b, c);                    \
  |  |  ------------------
  |  |  |  |   57|  80.6M|#define Maj(x,y,z)      (((x | y) & z) | (x & y))
  |  |  ------------------
  |  |   98|  80.6M|     d += t0;                                          \
  |  |   99|  80.6M|     h  = t0 + t1;
  ------------------
  103|  80.6M|         t = S[7]; S[7] = S[6]; S[6] = S[5]; S[5] = S[4];
  104|  80.6M|         S[4] = S[3]; S[3] = S[2]; S[2] = S[1]; S[1] = S[0]; S[0] = t;
  105|  80.6M|     }
  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|  11.3M|    for (i = 0; i < 8; i++) {
  ------------------
  |  Branch (183:17): [True: 10.0M, False: 1.25M]
  ------------------
  184|  10.0M|        md->sha256.state[i] = md->sha256.state[i] + S[i];
  185|  10.0M|    }
  186|  1.25M|    return CRYPT_OK;
  187|  1.25M|}

sha384_init:
   42|  3.48k|{
   43|  3.48k|    LTC_ARGCHK(md != NULL);
  ------------------
  |  |   32|  3.48k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 3.48k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   44|       |
   45|  3.48k|    md->sha512.curlen = 0;
   46|  3.48k|    md->sha512.length = 0;
   47|  3.48k|    md->sha512.state[0] = CONST64(0xcbbb9d5dc1059ed8);
  ------------------
  |  |  200|  3.48k|   #define CONST64(n) n ## ULL
  ------------------
   48|  3.48k|    md->sha512.state[1] = CONST64(0x629a292a367cd507);
  ------------------
  |  |  200|  3.48k|   #define CONST64(n) n ## ULL
  ------------------
   49|  3.48k|    md->sha512.state[2] = CONST64(0x9159015a3070dd17);
  ------------------
  |  |  200|  3.48k|   #define CONST64(n) n ## ULL
  ------------------
   50|  3.48k|    md->sha512.state[3] = CONST64(0x152fecd8f70e5939);
  ------------------
  |  |  200|  3.48k|   #define CONST64(n) n ## ULL
  ------------------
   51|  3.48k|    md->sha512.state[4] = CONST64(0x67332667ffc00b31);
  ------------------
  |  |  200|  3.48k|   #define CONST64(n) n ## ULL
  ------------------
   52|  3.48k|    md->sha512.state[5] = CONST64(0x8eb44a8768581511);
  ------------------
  |  |  200|  3.48k|   #define CONST64(n) n ## ULL
  ------------------
   53|  3.48k|    md->sha512.state[6] = CONST64(0xdb0c2e0d64f98fa7);
  ------------------
  |  |  200|  3.48k|   #define CONST64(n) n ## ULL
  ------------------
   54|  3.48k|    md->sha512.state[7] = CONST64(0x47b5481dbefa4fa4);
  ------------------
  |  |  200|  3.48k|   #define CONST64(n) n ## ULL
  ------------------
   55|  3.48k|    return CRYPT_OK;
   56|  3.48k|}
sha384_done:
   65|  12.7k|{
   66|  12.7k|   unsigned char buf[64];
   67|       |
   68|  12.7k|   LTC_ARGCHK(md  != NULL);
  ------------------
  |  |   32|  12.7k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 12.7k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   69|  12.7k|   LTC_ARGCHK(out != NULL);
  ------------------
  |  |   32|  12.7k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 12.7k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   70|       |
   71|  12.7k|    if (md->sha512.curlen >= sizeof(md->sha512.buf)) {
  ------------------
  |  Branch (71:9): [True: 0, False: 12.7k]
  ------------------
   72|      0|       return CRYPT_INVALID_ARG;
   73|      0|    }
   74|       |
   75|  12.7k|   sha512_done(md, buf);
   76|  12.7k|   XMEMCPY(out, buf, 48);
  ------------------
  |  |   39|  12.7k|#define XMEMCPY  memcpy
  ------------------
   77|       |#ifdef LTC_CLEAN_STACK
   78|       |   zeromem(buf, sizeof(buf));
   79|       |#endif
   80|  12.7k|   return CRYPT_OK;
   81|  12.7k|}

sha512_init:
  174|  1.55k|{
  175|  1.55k|    LTC_ARGCHK(md != NULL);
  ------------------
  |  |   32|  1.55k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 1.55k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  176|  1.55k|    md->sha512.curlen = 0;
  177|  1.55k|    md->sha512.length = 0;
  178|  1.55k|    md->sha512.state[0] = CONST64(0x6a09e667f3bcc908);
  ------------------
  |  |  200|  1.55k|   #define CONST64(n) n ## ULL
  ------------------
  179|  1.55k|    md->sha512.state[1] = CONST64(0xbb67ae8584caa73b);
  ------------------
  |  |  200|  1.55k|   #define CONST64(n) n ## ULL
  ------------------
  180|  1.55k|    md->sha512.state[2] = CONST64(0x3c6ef372fe94f82b);
  ------------------
  |  |  200|  1.55k|   #define CONST64(n) n ## ULL
  ------------------
  181|  1.55k|    md->sha512.state[3] = CONST64(0xa54ff53a5f1d36f1);
  ------------------
  |  |  200|  1.55k|   #define CONST64(n) n ## ULL
  ------------------
  182|  1.55k|    md->sha512.state[4] = CONST64(0x510e527fade682d1);
  ------------------
  |  |  200|  1.55k|   #define CONST64(n) n ## ULL
  ------------------
  183|  1.55k|    md->sha512.state[5] = CONST64(0x9b05688c2b3e6c1f);
  ------------------
  |  |  200|  1.55k|   #define CONST64(n) n ## ULL
  ------------------
  184|  1.55k|    md->sha512.state[6] = CONST64(0x1f83d9abfb41bd6b);
  ------------------
  |  |  200|  1.55k|   #define CONST64(n) n ## ULL
  ------------------
  185|  1.55k|    md->sha512.state[7] = CONST64(0x5be0cd19137e2179);
  ------------------
  |  |  200|  1.55k|   #define CONST64(n) n ## ULL
  ------------------
  186|  1.55k|    return CRYPT_OK;
  187|  1.55k|}
sha512_done:
  205|  17.2k|{
  206|  17.2k|    int i;
  207|       |
  208|  17.2k|    LTC_ARGCHK(md  != NULL);
  ------------------
  |  |   32|  17.2k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 17.2k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  209|  17.2k|    LTC_ARGCHK(out != NULL);
  ------------------
  |  |   32|  17.2k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 17.2k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  210|       |
  211|  17.2k|    if (md->sha512.curlen >= sizeof(md->sha512.buf)) {
  ------------------
  |  Branch (211:9): [True: 0, False: 17.2k]
  ------------------
  212|      0|       return CRYPT_INVALID_ARG;
  213|      0|    }
  214|       |
  215|       |    /* increase the length of the message */
  216|  17.2k|    md->sha512.length += md->sha512.curlen * CONST64(8);
  ------------------
  |  |  200|  17.2k|   #define CONST64(n) n ## ULL
  ------------------
  217|       |
  218|       |    /* append the '1' bit */
  219|  17.2k|    md->sha512.buf[md->sha512.curlen++] = (unsigned char)0x80;
  220|       |
  221|       |    /* if the length is currently above 112 bytes we append zeros
  222|       |     * then compress.  Then we can fall back to padding zeros and length
  223|       |     * encoding like normal.
  224|       |     */
  225|  17.2k|    if (md->sha512.curlen > 112) {
  ------------------
  |  Branch (225:9): [True: 3.00k, False: 14.2k]
  ------------------
  226|  20.3k|        while (md->sha512.curlen < 128) {
  ------------------
  |  Branch (226:16): [True: 17.3k, False: 3.00k]
  ------------------
  227|  17.3k|            md->sha512.buf[md->sha512.curlen++] = (unsigned char)0;
  228|  17.3k|        }
  229|  3.00k|        sha512_compress(md, md->sha512.buf);
  230|  3.00k|        md->sha512.curlen = 0;
  231|  3.00k|    }
  232|       |
  233|       |    /* pad upto 120 bytes of zeroes
  234|       |     * note: that from 112 to 120 is the 64 MSB of the length.  We assume that you won't hash
  235|       |     * > 2^64 bits of data... :-)
  236|       |     */
  237|  1.05M|    while (md->sha512.curlen < 120) {
  ------------------
  |  Branch (237:12): [True: 1.03M, False: 17.2k]
  ------------------
  238|  1.03M|        md->sha512.buf[md->sha512.curlen++] = (unsigned char)0;
  239|  1.03M|    }
  240|       |
  241|       |    /* store length */
  242|  17.2k|    STORE64H(md->sha512.length, md->sha512.buf+120);
  ------------------
  |  |  101|  17.2k|#define STORE64H(x, y)                          \
  |  |  102|  17.2k|do { ulong64 __t = __builtin_bswap64 ((x));     \
  |  |  103|  17.2k|      XMEMCPY ((y), &__t, 8); } while(0)
  |  |  ------------------
  |  |  |  |   39|  17.2k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (103:39): [Folded - Ignored]
  |  |  ------------------
  ------------------
  243|  17.2k|    sha512_compress(md, md->sha512.buf);
  244|       |
  245|       |    /* copy output */
  246|   154k|    for (i = 0; i < 8; i++) {
  ------------------
  |  Branch (246:17): [True: 137k, False: 17.2k]
  ------------------
  247|   137k|        STORE64H(md->sha512.state[i], out+(8*i));
  ------------------
  |  |  101|   137k|#define STORE64H(x, y)                          \
  |  |  102|   137k|do { ulong64 __t = __builtin_bswap64 ((x));     \
  |  |  103|   137k|      XMEMCPY ((y), &__t, 8); } while(0)
  |  |  ------------------
  |  |  |  |   39|   137k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (103:39): [Folded - Ignored]
  |  |  ------------------
  ------------------
  248|   137k|    }
  249|       |#ifdef LTC_CLEAN_STACK
  250|       |    zeromem(md, sizeof(hash_state));
  251|       |#endif
  252|  17.2k|    return CRYPT_OK;
  253|  17.2k|}
sha512.c:sha512_compress:
   96|  40.5k|{
   97|  40.5k|    ulong64 S[8], W[80], t0, t1;
   98|  40.5k|    int i;
   99|       |
  100|       |    /* copy state into S */
  101|   364k|    for (i = 0; i < 8; i++) {
  ------------------
  |  Branch (101:17): [True: 324k, False: 40.5k]
  ------------------
  102|   324k|        S[i] = md->sha512.state[i];
  103|   324k|    }
  104|       |
  105|       |    /* copy the state into 1024-bits into W[0..15] */
  106|   689k|    for (i = 0; i < 16; i++) {
  ------------------
  |  Branch (106:17): [True: 648k, False: 40.5k]
  ------------------
  107|   648k|        LOAD64H(W[i], buf + (8*i));
  ------------------
  |  |  105|   648k|#define LOAD64H(x, y)                           \
  |  |  106|   648k|do { XMEMCPY (&(x), (y), 8);                    \
  |  |  ------------------
  |  |  |  |   39|   648k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  107|   648k|      (x) = __builtin_bswap64 ((x)); } while(0)
  |  |  ------------------
  |  |  |  Branch (107:46): [Folded - Ignored]
  |  |  ------------------
  ------------------
  108|   648k|    }
  109|       |
  110|       |    /* fill W[16..79] */
  111|  2.63M|    for (i = 16; i < 80; i++) {
  ------------------
  |  Branch (111:18): [True: 2.59M, False: 40.5k]
  ------------------
  112|  2.59M|        W[i] = Gamma1(W[i - 2]) + W[i - 7] + Gamma0(W[i - 15]) + W[i - 16];
  ------------------
  |  |   88|  2.59M|#define Gamma1(x)       (S(x, 19) ^ S(x, 61) ^ R(x, 6))
  |  |  ------------------
  |  |  |  |   83|  2.59M|#define S(x, n)         ROR64c(x, n)
  |  |  |  |  ------------------
  |  |  |  |  |  |  384|  2.59M|#define ROR64c(word,i) ({ \
  |  |  |  |  |  |  385|  2.59M|   ulong64 __ROR64c_tmp = word; \
  |  |  |  |  |  |  386|  2.59M|   __asm__ ("rorq %2, %0" : \
  |  |  |  |  |  |  387|  2.59M|            "=r" (__ROR64c_tmp) : \
  |  |  |  |  |  |  388|  2.59M|            "0" (__ROR64c_tmp), \
  |  |  |  |  |  |  389|  2.59M|            "J" (i)); \
  |  |  |  |  |  |  390|  2.59M|            __ROR64c_tmp; \
  |  |  |  |  |  |  391|  2.59M|   })
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define Gamma1(x)       (S(x, 19) ^ S(x, 61) ^ R(x, 6))
  |  |  ------------------
  |  |  |  |   83|  2.59M|#define S(x, n)         ROR64c(x, n)
  |  |  |  |  ------------------
  |  |  |  |  |  |  384|  2.59M|#define ROR64c(word,i) ({ \
  |  |  |  |  |  |  385|  2.59M|   ulong64 __ROR64c_tmp = word; \
  |  |  |  |  |  |  386|  2.59M|   __asm__ ("rorq %2, %0" : \
  |  |  |  |  |  |  387|  2.59M|            "=r" (__ROR64c_tmp) : \
  |  |  |  |  |  |  388|  2.59M|            "0" (__ROR64c_tmp), \
  |  |  |  |  |  |  389|  2.59M|            "J" (i)); \
  |  |  |  |  |  |  390|  2.59M|            __ROR64c_tmp; \
  |  |  |  |  |  |  391|  2.59M|   })
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define Gamma1(x)       (S(x, 19) ^ S(x, 61) ^ R(x, 6))
  |  |  ------------------
  |  |  |  |   84|  2.59M|#define R(x, n)         (((x)&CONST64(0xFFFFFFFFFFFFFFFF))>>((ulong64)n))
  |  |  |  |  ------------------
  |  |  |  |  |  |  200|  2.59M|   #define CONST64(n) n ## ULL
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      W[i] = Gamma1(W[i - 2]) + W[i - 7] + Gamma0(W[i - 15]) + W[i - 16];
  ------------------
  |  |   87|  2.59M|#define Gamma0(x)       (S(x, 1) ^ S(x, 8) ^ R(x, 7))
  |  |  ------------------
  |  |  |  |   83|  2.59M|#define S(x, n)         ROR64c(x, n)
  |  |  |  |  ------------------
  |  |  |  |  |  |  384|  2.59M|#define ROR64c(word,i) ({ \
  |  |  |  |  |  |  385|  2.59M|   ulong64 __ROR64c_tmp = word; \
  |  |  |  |  |  |  386|  2.59M|   __asm__ ("rorq %2, %0" : \
  |  |  |  |  |  |  387|  2.59M|            "=r" (__ROR64c_tmp) : \
  |  |  |  |  |  |  388|  2.59M|            "0" (__ROR64c_tmp), \
  |  |  |  |  |  |  389|  2.59M|            "J" (i)); \
  |  |  |  |  |  |  390|  2.59M|            __ROR64c_tmp; \
  |  |  |  |  |  |  391|  2.59M|   })
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define Gamma0(x)       (S(x, 1) ^ S(x, 8) ^ R(x, 7))
  |  |  ------------------
  |  |  |  |   83|  2.59M|#define S(x, n)         ROR64c(x, n)
  |  |  |  |  ------------------
  |  |  |  |  |  |  384|  2.59M|#define ROR64c(word,i) ({ \
  |  |  |  |  |  |  385|  2.59M|   ulong64 __ROR64c_tmp = word; \
  |  |  |  |  |  |  386|  2.59M|   __asm__ ("rorq %2, %0" : \
  |  |  |  |  |  |  387|  2.59M|            "=r" (__ROR64c_tmp) : \
  |  |  |  |  |  |  388|  2.59M|            "0" (__ROR64c_tmp), \
  |  |  |  |  |  |  389|  2.59M|            "J" (i)); \
  |  |  |  |  |  |  390|  2.59M|            __ROR64c_tmp; \
  |  |  |  |  |  |  391|  2.59M|   })
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define Gamma0(x)       (S(x, 1) ^ S(x, 8) ^ R(x, 7))
  |  |  ------------------
  |  |  |  |   84|  2.59M|#define R(x, n)         (((x)&CONST64(0xFFFFFFFFFFFFFFFF))>>((ulong64)n))
  |  |  |  |  ------------------
  |  |  |  |  |  |  200|  2.59M|   #define CONST64(n) n ## ULL
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  113|  2.59M|    }
  114|       |
  115|       |    /* Compress */
  116|  40.5k|#ifdef LTC_SMALL_CODE
  117|  3.28M|    for (i = 0; i < 80; i++) {
  ------------------
  |  Branch (117:17): [True: 3.24M, False: 40.5k]
  ------------------
  118|  3.24M|        t0 = S[7] + Sigma1(S[4]) + Ch(S[4], S[5], S[6]) + K[i] + W[i];
  ------------------
  |  |   86|  3.24M|#define Sigma1(x)       (S(x, 14) ^ S(x, 18) ^ S(x, 41))
  |  |  ------------------
  |  |  |  |   83|  3.24M|#define S(x, n)         ROR64c(x, n)
  |  |  |  |  ------------------
  |  |  |  |  |  |  384|  3.24M|#define ROR64c(word,i) ({ \
  |  |  |  |  |  |  385|  3.24M|   ulong64 __ROR64c_tmp = word; \
  |  |  |  |  |  |  386|  3.24M|   __asm__ ("rorq %2, %0" : \
  |  |  |  |  |  |  387|  3.24M|            "=r" (__ROR64c_tmp) : \
  |  |  |  |  |  |  388|  3.24M|            "0" (__ROR64c_tmp), \
  |  |  |  |  |  |  389|  3.24M|            "J" (i)); \
  |  |  |  |  |  |  390|  3.24M|            __ROR64c_tmp; \
  |  |  |  |  |  |  391|  3.24M|   })
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define Sigma1(x)       (S(x, 14) ^ S(x, 18) ^ S(x, 41))
  |  |  ------------------
  |  |  |  |   83|  3.24M|#define S(x, n)         ROR64c(x, n)
  |  |  |  |  ------------------
  |  |  |  |  |  |  384|  3.24M|#define ROR64c(word,i) ({ \
  |  |  |  |  |  |  385|  3.24M|   ulong64 __ROR64c_tmp = word; \
  |  |  |  |  |  |  386|  3.24M|   __asm__ ("rorq %2, %0" : \
  |  |  |  |  |  |  387|  3.24M|            "=r" (__ROR64c_tmp) : \
  |  |  |  |  |  |  388|  3.24M|            "0" (__ROR64c_tmp), \
  |  |  |  |  |  |  389|  3.24M|            "J" (i)); \
  |  |  |  |  |  |  390|  3.24M|            __ROR64c_tmp; \
  |  |  |  |  |  |  391|  3.24M|   })
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define Sigma1(x)       (S(x, 14) ^ S(x, 18) ^ S(x, 41))
  |  |  ------------------
  |  |  |  |   83|  3.24M|#define S(x, n)         ROR64c(x, n)
  |  |  |  |  ------------------
  |  |  |  |  |  |  384|  3.24M|#define ROR64c(word,i) ({ \
  |  |  |  |  |  |  385|  3.24M|   ulong64 __ROR64c_tmp = word; \
  |  |  |  |  |  |  386|  3.24M|   __asm__ ("rorq %2, %0" : \
  |  |  |  |  |  |  387|  3.24M|            "=r" (__ROR64c_tmp) : \
  |  |  |  |  |  |  388|  3.24M|            "0" (__ROR64c_tmp), \
  |  |  |  |  |  |  389|  3.24M|            "J" (i)); \
  |  |  |  |  |  |  390|  3.24M|            __ROR64c_tmp; \
  |  |  |  |  |  |  391|  3.24M|   })
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      t0 = S[7] + Sigma1(S[4]) + Ch(S[4], S[5], S[6]) + K[i] + W[i];
  ------------------
  |  |   81|  3.24M|#define Ch(x,y,z)       (z ^ (x & (y ^ z)))
  ------------------
  119|  3.24M|        t1 = Sigma0(S[0]) + Maj(S[0], S[1], S[2]);
  ------------------
  |  |   85|  3.24M|#define Sigma0(x)       (S(x, 28) ^ S(x, 34) ^ S(x, 39))
  |  |  ------------------
  |  |  |  |   83|  3.24M|#define S(x, n)         ROR64c(x, n)
  |  |  |  |  ------------------
  |  |  |  |  |  |  384|  3.24M|#define ROR64c(word,i) ({ \
  |  |  |  |  |  |  385|  3.24M|   ulong64 __ROR64c_tmp = word; \
  |  |  |  |  |  |  386|  3.24M|   __asm__ ("rorq %2, %0" : \
  |  |  |  |  |  |  387|  3.24M|            "=r" (__ROR64c_tmp) : \
  |  |  |  |  |  |  388|  3.24M|            "0" (__ROR64c_tmp), \
  |  |  |  |  |  |  389|  3.24M|            "J" (i)); \
  |  |  |  |  |  |  390|  3.24M|            __ROR64c_tmp; \
  |  |  |  |  |  |  391|  3.24M|   })
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define Sigma0(x)       (S(x, 28) ^ S(x, 34) ^ S(x, 39))
  |  |  ------------------
  |  |  |  |   83|  3.24M|#define S(x, n)         ROR64c(x, n)
  |  |  |  |  ------------------
  |  |  |  |  |  |  384|  3.24M|#define ROR64c(word,i) ({ \
  |  |  |  |  |  |  385|  3.24M|   ulong64 __ROR64c_tmp = word; \
  |  |  |  |  |  |  386|  3.24M|   __asm__ ("rorq %2, %0" : \
  |  |  |  |  |  |  387|  3.24M|            "=r" (__ROR64c_tmp) : \
  |  |  |  |  |  |  388|  3.24M|            "0" (__ROR64c_tmp), \
  |  |  |  |  |  |  389|  3.24M|            "J" (i)); \
  |  |  |  |  |  |  390|  3.24M|            __ROR64c_tmp; \
  |  |  |  |  |  |  391|  3.24M|   })
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define Sigma0(x)       (S(x, 28) ^ S(x, 34) ^ S(x, 39))
  |  |  ------------------
  |  |  |  |   83|  3.24M|#define S(x, n)         ROR64c(x, n)
  |  |  |  |  ------------------
  |  |  |  |  |  |  384|  3.24M|#define ROR64c(word,i) ({ \
  |  |  |  |  |  |  385|  3.24M|   ulong64 __ROR64c_tmp = word; \
  |  |  |  |  |  |  386|  3.24M|   __asm__ ("rorq %2, %0" : \
  |  |  |  |  |  |  387|  3.24M|            "=r" (__ROR64c_tmp) : \
  |  |  |  |  |  |  388|  3.24M|            "0" (__ROR64c_tmp), \
  |  |  |  |  |  |  389|  3.24M|            "J" (i)); \
  |  |  |  |  |  |  390|  3.24M|            __ROR64c_tmp; \
  |  |  |  |  |  |  391|  3.24M|   })
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      t1 = Sigma0(S[0]) + Maj(S[0], S[1], S[2]);
  ------------------
  |  |   82|  3.24M|#define Maj(x,y,z)      (((x | y) & z) | (x & y))
  ------------------
  120|  3.24M|        S[7] = S[6];
  121|  3.24M|        S[6] = S[5];
  122|  3.24M|        S[5] = S[4];
  123|  3.24M|        S[4] = S[3] + t0;
  124|  3.24M|        S[3] = S[2];
  125|  3.24M|        S[2] = S[1];
  126|  3.24M|        S[1] = S[0];
  127|  3.24M|        S[0] = t0 + t1;
  128|  3.24M|    }
  129|       |#else
  130|       |#define RND(a,b,c,d,e,f,g,h,i)                    \
  131|       |     t0 = h + Sigma1(e) + Ch(e, f, g) + K[i] + W[i];   \
  132|       |     t1 = Sigma0(a) + Maj(a, b, c);                  \
  133|       |     d += t0;                                        \
  134|       |     h  = t0 + t1;
  135|       |
  136|       |    for (i = 0; i < 80; i += 8) {
  137|       |        RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],i+0);
  138|       |        RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],i+1);
  139|       |        RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],i+2);
  140|       |        RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],i+3);
  141|       |        RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],i+4);
  142|       |        RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],i+5);
  143|       |        RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],i+6);
  144|       |        RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],i+7);
  145|       |    }
  146|       |#endif
  147|       |
  148|       |
  149|       |    /* feedback */
  150|   364k|    for (i = 0; i < 8; i++) {
  ------------------
  |  Branch (150:17): [True: 324k, False: 40.5k]
  ------------------
  151|   324k|        md->sha512.state[i] = md->sha512.state[i] + S[i];
  152|   324k|    }
  153|       |
  154|  40.5k|    return CRYPT_OK;
  155|  40.5k|}

sha1_process:
  491|  80.8k|int func_name (hash_state * md, const unsigned char *in, unsigned long inlen)               \
  492|  80.8k|{                                                                                           \
  493|  80.8k|    unsigned long n;                                                                        \
  494|  80.8k|    int           err;                                                                      \
  495|  80.8k|    LTC_ARGCHK(md != NULL);                                                                 \
  ------------------
  |  |   32|  80.8k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 80.8k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  496|  80.8k|    LTC_ARGCHK(in != NULL);                                                                 \
  ------------------
  |  |   32|  80.8k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 80.8k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  497|  80.8k|    if (md-> state_var .curlen > sizeof(md-> state_var .buf)) {                             \
  ------------------
  |  Branch (497:9): [True: 0, False: 80.8k]
  ------------------
  498|      0|       return CRYPT_INVALID_ARG;                                                            \
  499|      0|    }                                                                                       \
  500|  80.8k|    if ((md-> state_var .length + inlen) < md-> state_var .length) {                        \
  ------------------
  |  Branch (500:9): [True: 0, False: 80.8k]
  ------------------
  501|      0|      return CRYPT_HASH_OVERFLOW;                                                           \
  502|      0|    }                                                                                       \
  503|   829k|    while (inlen > 0) {                                                                     \
  ------------------
  |  Branch (503:12): [True: 748k, False: 80.8k]
  ------------------
  504|   748k|        if (md-> state_var .curlen == 0 && inlen >= block_size) {                           \
  ------------------
  |  Branch (504:13): [True: 697k, False: 50.8k]
  |  Branch (504:44): [True: 662k, False: 34.4k]
  ------------------
  505|   662k|           if ((err = compress_name (md, (unsigned char *)in)) != CRYPT_OK) {               \
  ------------------
  |  Branch (505:16): [True: 0, False: 662k]
  ------------------
  506|      0|              return err;                                                                   \
  507|      0|           }                                                                                \
  508|   662k|           md-> state_var .length += block_size * 8;                                        \
  509|   662k|           in             += block_size;                                                    \
  510|   662k|           inlen          -= block_size;                                                    \
  511|   662k|        } else {                                                                            \
  512|  85.3k|           n = MIN(inlen, (block_size - md-> state_var .curlen));                           \
  ------------------
  |  |  425|  85.3k|   #define MIN(x, y) ( ((x)<(y))?(x):(y) )
  |  |  ------------------
  |  |  |  Branch (425:24): [True: 68.7k, False: 16.5k]
  |  |  ------------------
  ------------------
  513|  85.3k|           XMEMCPY(md-> state_var .buf + md-> state_var.curlen, in, (size_t)n);             \
  ------------------
  |  |   39|  85.3k|#define XMEMCPY  memcpy
  ------------------
  514|  85.3k|           md-> state_var .curlen += n;                                                     \
  515|  85.3k|           in             += n;                                                             \
  516|  85.3k|           inlen          -= n;                                                             \
  517|  85.3k|           if (md-> state_var .curlen == block_size) {                                      \
  ------------------
  |  Branch (517:16): [True: 16.5k, False: 68.7k]
  ------------------
  518|  16.5k|              if ((err = compress_name (md, md-> state_var .buf)) != CRYPT_OK) {            \
  ------------------
  |  Branch (518:19): [True: 0, False: 16.5k]
  ------------------
  519|      0|                 return err;                                                                \
  520|      0|              }                                                                             \
  521|  16.5k|              md-> state_var .length += 8*block_size;                                       \
  522|  16.5k|              md-> state_var .curlen = 0;                                                   \
  523|  16.5k|           }                                                                                \
  524|  85.3k|       }                                                                                    \
  525|   748k|    }                                                                                       \
  526|  80.8k|    return CRYPT_OK;                                                                        \
  527|  80.8k|}
sha256_process:
  491|   638k|int func_name (hash_state * md, const unsigned char *in, unsigned long inlen)               \
  492|   638k|{                                                                                           \
  493|   638k|    unsigned long n;                                                                        \
  494|   638k|    int           err;                                                                      \
  495|   638k|    LTC_ARGCHK(md != NULL);                                                                 \
  ------------------
  |  |   32|   638k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 638k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  496|   638k|    LTC_ARGCHK(in != NULL);                                                                 \
  ------------------
  |  |   32|   638k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 638k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  497|   638k|    if (md-> state_var .curlen > sizeof(md-> state_var .buf)) {                             \
  ------------------
  |  Branch (497:9): [True: 0, False: 638k]
  ------------------
  498|      0|       return CRYPT_INVALID_ARG;                                                            \
  499|      0|    }                                                                                       \
  500|   638k|    if ((md-> state_var .length + inlen) < md-> state_var .length) {                        \
  ------------------
  |  Branch (500:9): [True: 0, False: 638k]
  ------------------
  501|      0|      return CRYPT_HASH_OVERFLOW;                                                           \
  502|      0|    }                                                                                       \
  503|  2.19M|    while (inlen > 0) {                                                                     \
  ------------------
  |  Branch (503:12): [True: 1.55M, False: 638k]
  ------------------
  504|  1.55M|        if (md-> state_var .curlen == 0 && inlen >= block_size) {                           \
  ------------------
  |  Branch (504:13): [True: 1.23M, False: 315k]
  |  Branch (504:44): [True: 911k, False: 326k]
  ------------------
  505|   911k|           if ((err = compress_name (md, (unsigned char *)in)) != CRYPT_OK) {               \
  ------------------
  |  Branch (505:16): [True: 0, False: 911k]
  ------------------
  506|      0|              return err;                                                                   \
  507|      0|           }                                                                                \
  508|   911k|           md-> state_var .length += block_size * 8;                                        \
  509|   911k|           in             += block_size;                                                    \
  510|   911k|           inlen          -= block_size;                                                    \
  511|   911k|        } else {                                                                            \
  512|   641k|           n = MIN(inlen, (block_size - md-> state_var .curlen));                           \
  ------------------
  |  |  425|   641k|   #define MIN(x, y) ( ((x)<(y))?(x):(y) )
  |  |  ------------------
  |  |  |  Branch (425:24): [True: 607k, False: 34.1k]
  |  |  ------------------
  ------------------
  513|   641k|           XMEMCPY(md-> state_var .buf + md-> state_var.curlen, in, (size_t)n);             \
  ------------------
  |  |   39|   641k|#define XMEMCPY  memcpy
  ------------------
  514|   641k|           md-> state_var .curlen += n;                                                     \
  515|   641k|           in             += n;                                                             \
  516|   641k|           inlen          -= n;                                                             \
  517|   641k|           if (md-> state_var .curlen == block_size) {                                      \
  ------------------
  |  Branch (517:16): [True: 34.1k, False: 607k]
  ------------------
  518|  34.1k|              if ((err = compress_name (md, md-> state_var .buf)) != CRYPT_OK) {            \
  ------------------
  |  Branch (518:19): [True: 0, False: 34.1k]
  ------------------
  519|      0|                 return err;                                                                \
  520|      0|              }                                                                             \
  521|  34.1k|              md-> state_var .length += 8*block_size;                                       \
  522|  34.1k|              md-> state_var .curlen = 0;                                                   \
  523|  34.1k|           }                                                                                \
  524|   641k|       }                                                                                    \
  525|  1.55M|    }                                                                                       \
  526|   638k|    return CRYPT_OK;                                                                        \
  527|   638k|}
sha512_process:
  491|  33.4k|int func_name (hash_state * md, const unsigned char *in, unsigned long inlen)               \
  492|  33.4k|{                                                                                           \
  493|  33.4k|    unsigned long n;                                                                        \
  494|  33.4k|    int           err;                                                                      \
  495|  33.4k|    LTC_ARGCHK(md != NULL);                                                                 \
  ------------------
  |  |   32|  33.4k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 33.4k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  496|  33.4k|    LTC_ARGCHK(in != NULL);                                                                 \
  ------------------
  |  |   32|  33.4k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 33.4k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  497|  33.4k|    if (md-> state_var .curlen > sizeof(md-> state_var .buf)) {                             \
  ------------------
  |  Branch (497:9): [True: 0, False: 33.4k]
  ------------------
  498|      0|       return CRYPT_INVALID_ARG;                                                            \
  499|      0|    }                                                                                       \
  500|  33.4k|    if ((md-> state_var .length + inlen) < md-> state_var .length) {                        \
  ------------------
  |  Branch (500:9): [True: 0, False: 33.4k]
  ------------------
  501|      0|      return CRYPT_HASH_OVERFLOW;                                                           \
  502|      0|    }                                                                                       \
  503|  87.2k|    while (inlen > 0) {                                                                     \
  ------------------
  |  Branch (503:12): [True: 53.7k, False: 33.4k]
  ------------------
  504|  53.7k|        if (md-> state_var .curlen == 0 && inlen >= block_size) {                           \
  ------------------
  |  Branch (504:13): [True: 25.3k, False: 28.4k]
  |  Branch (504:44): [True: 17.1k, False: 8.23k]
  ------------------
  505|  17.1k|           if ((err = compress_name (md, (unsigned char *)in)) != CRYPT_OK) {               \
  ------------------
  |  Branch (505:16): [True: 0, False: 17.1k]
  ------------------
  506|      0|              return err;                                                                   \
  507|      0|           }                                                                                \
  508|  17.1k|           md-> state_var .length += block_size * 8;                                        \
  509|  17.1k|           in             += block_size;                                                    \
  510|  17.1k|           inlen          -= block_size;                                                    \
  511|  36.6k|        } else {                                                                            \
  512|  36.6k|           n = MIN(inlen, (block_size - md-> state_var .curlen));                           \
  ------------------
  |  |  425|  36.6k|   #define MIN(x, y) ( ((x)<(y))?(x):(y) )
  |  |  ------------------
  |  |  |  Branch (425:24): [True: 33.4k, False: 3.19k]
  |  |  ------------------
  ------------------
  513|  36.6k|           XMEMCPY(md-> state_var .buf + md-> state_var.curlen, in, (size_t)n);             \
  ------------------
  |  |   39|  36.6k|#define XMEMCPY  memcpy
  ------------------
  514|  36.6k|           md-> state_var .curlen += n;                                                     \
  515|  36.6k|           in             += n;                                                             \
  516|  36.6k|           inlen          -= n;                                                             \
  517|  36.6k|           if (md-> state_var .curlen == block_size) {                                      \
  ------------------
  |  Branch (517:16): [True: 3.19k, False: 33.4k]
  ------------------
  518|  3.19k|              if ((err = compress_name (md, md-> state_var .buf)) != CRYPT_OK) {            \
  ------------------
  |  Branch (518:19): [True: 0, False: 3.19k]
  ------------------
  519|      0|                 return err;                                                                \
  520|      0|              }                                                                             \
  521|  3.19k|              md-> state_var .length += 8*block_size;                                       \
  522|  3.19k|              md-> state_var .curlen = 0;                                                   \
  523|  3.19k|           }                                                                                \
  524|  36.6k|       }                                                                                    \
  525|  53.7k|    }                                                                                       \
  526|  33.4k|    return CRYPT_OK;                                                                        \
  527|  33.4k|}

sha1.c:ROL:
  258|  46.3M|{
  259|  46.3M|   asm ("roll %%cl,%0"
  260|  46.3M|      :"=r" (word)
  261|  46.3M|      :"0" (word),"c" (i));
  262|  46.3M|   return word;
  263|  46.3M|}
chacha_crypt.c:ROL:
  258|  4.08G|{
  259|  4.08G|   asm ("roll %%cl,%0"
  260|  4.08G|      :"=r" (word)
  261|  4.08G|      :"0" (word),"c" (i));
  262|  4.08G|   return word;
  263|  4.08G|}

hmac_done:
   28|  21.6k|{
   29|  21.6k|    unsigned char buf[MAXBLOCKSIZE], isha[MAXBLOCKSIZE];
   30|  21.6k|    unsigned long hashsize, i;
   31|  21.6k|    int hash, err;
   32|       |
   33|  21.6k|    LTC_ARGCHK(hmac  != NULL);
  ------------------
  |  |   32|  21.6k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 21.6k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   34|  21.6k|    LTC_ARGCHK(out   != NULL);
  ------------------
  |  |   32|  21.6k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 21.6k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   35|       |
   36|       |    /* test hash */
   37|  21.6k|    hash = hmac->hash;
   38|  21.6k|    if((err = hash_is_valid(hash)) != CRYPT_OK) {
  ------------------
  |  Branch (38:8): [True: 0, False: 21.6k]
  ------------------
   39|      0|        return err;
   40|      0|    }
   41|       |
   42|       |    /* get the hash message digest size */
   43|  21.6k|    hashsize = hash_descriptor[hash].hashsize;
   44|       |
   45|  21.6k|    if ((err = hash_descriptor[hash].done(&hmac->md, isha)) != CRYPT_OK) {
  ------------------
  |  Branch (45:9): [True: 0, False: 21.6k]
  ------------------
   46|      0|       goto LBL_ERR;
   47|      0|    }
   48|       |
   49|       |    /* Create the second HMAC vector vector for step (3) */
   50|  1.40M|    for(i=0; i < LTC_HMAC_BLOCKSIZE; i++) {
  ------------------
  |  |   18|  1.40M|#define LTC_HMAC_BLOCKSIZE hash_descriptor[hash].blocksize
  ------------------
  |  Branch (50:14): [True: 1.38M, False: 21.6k]
  ------------------
   51|  1.38M|        buf[i] = hmac->key[i] ^ 0x5C;
   52|  1.38M|    }
   53|       |
   54|       |    /* Now calculate the "outer" hash for step (5), (6), and (7) */
   55|  21.6k|    if ((err = hash_descriptor[hash].init(&hmac->md)) != CRYPT_OK) {
  ------------------
  |  Branch (55:9): [True: 0, False: 21.6k]
  ------------------
   56|      0|       goto LBL_ERR;
   57|      0|    }
   58|  21.6k|    if ((err = hash_descriptor[hash].process(&hmac->md, buf, LTC_HMAC_BLOCKSIZE)) != CRYPT_OK) {
  ------------------
  |  |   18|  21.6k|#define LTC_HMAC_BLOCKSIZE hash_descriptor[hash].blocksize
  ------------------
  |  Branch (58:9): [True: 0, False: 21.6k]
  ------------------
   59|      0|       goto LBL_ERR;
   60|      0|    }
   61|  21.6k|    if ((err = hash_descriptor[hash].process(&hmac->md, isha, hashsize)) != CRYPT_OK) {
  ------------------
  |  Branch (61:9): [True: 0, False: 21.6k]
  ------------------
   62|      0|       goto LBL_ERR;
   63|      0|    }
   64|  21.6k|    if ((err = hash_descriptor[hash].done(&hmac->md, buf)) != CRYPT_OK) {
  ------------------
  |  Branch (64:9): [True: 0, False: 21.6k]
  ------------------
   65|      0|       goto LBL_ERR;
   66|      0|    }
   67|       |
   68|       |    /* copy to output  */
   69|   642k|    for (i = 0; i < hashsize && i < *outlen; i++) {
  ------------------
  |  Branch (69:17): [True: 621k, False: 21.6k]
  |  Branch (69:33): [True: 621k, False: 0]
  ------------------
   70|   621k|        out[i] = buf[i];
   71|   621k|    }
   72|  21.6k|    *outlen = i;
   73|       |
   74|  21.6k|    err = CRYPT_OK;
   75|  21.6k|LBL_ERR:
   76|  21.6k|    XFREE(hmac->key);
  ------------------
  |  |   17|  21.6k|#define XFREE m_free_direct
  ------------------
   77|       |#ifdef LTC_CLEAN_STACK
   78|       |    zeromem(isha, hashsize);
   79|       |    zeromem(buf,  hashsize);
   80|       |    zeromem(hmac, sizeof(*hmac));
   81|       |#endif
   82|       |
   83|  21.6k|    return err;
   84|  21.6k|}

hmac_init:
   29|  21.6k|{
   30|  21.6k|    unsigned char buf[MAXBLOCKSIZE];
   31|  21.6k|    unsigned long hashsize;
   32|  21.6k|    unsigned long i, z;
   33|  21.6k|    int err;
   34|       |
   35|  21.6k|    LTC_ARGCHK(hmac != NULL);
  ------------------
  |  |   32|  21.6k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 21.6k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   36|  21.6k|    LTC_ARGCHK(key  != NULL);
  ------------------
  |  |   32|  21.6k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 21.6k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   37|       |
   38|       |    /* valid hash? */
   39|  21.6k|    if ((err = hash_is_valid(hash)) != CRYPT_OK) {
  ------------------
  |  Branch (39:9): [True: 0, False: 21.6k]
  ------------------
   40|      0|        return err;
   41|      0|    }
   42|  21.6k|    hmac->hash = hash;
   43|  21.6k|    hashsize   = hash_descriptor[hash].hashsize;
   44|       |
   45|       |    /* valid key length? */
   46|  21.6k|    if (keylen == 0) {
  ------------------
  |  Branch (46:9): [True: 0, False: 21.6k]
  ------------------
   47|      0|        return CRYPT_INVALID_KEYSIZE;
   48|      0|    }
   49|       |
   50|       |    /* allocate memory for key */
   51|  21.6k|    hmac->key = XMALLOC(LTC_HMAC_BLOCKSIZE);
  ------------------
  |  |   16|  21.6k|#define XMALLOC m_malloc
  ------------------
                  hmac->key = XMALLOC(LTC_HMAC_BLOCKSIZE);
  ------------------
  |  |   18|  21.6k|#define LTC_HMAC_BLOCKSIZE hash_descriptor[hash].blocksize
  ------------------
   52|  21.6k|    if (hmac->key == NULL) {
  ------------------
  |  Branch (52:9): [True: 0, False: 21.6k]
  ------------------
   53|      0|       return CRYPT_MEM;
   54|      0|    }
   55|       |
   56|       |    /* (1) make sure we have a large enough key */
   57|  21.6k|    if(keylen > LTC_HMAC_BLOCKSIZE) {
  ------------------
  |  |   18|  21.6k|#define LTC_HMAC_BLOCKSIZE hash_descriptor[hash].blocksize
  ------------------
  |  Branch (57:8): [True: 0, False: 21.6k]
  ------------------
   58|      0|        z = LTC_HMAC_BLOCKSIZE;
  ------------------
  |  |   18|      0|#define LTC_HMAC_BLOCKSIZE hash_descriptor[hash].blocksize
  ------------------
   59|      0|        if ((err = hash_memory(hash, key, keylen, hmac->key, &z)) != CRYPT_OK) {
  ------------------
  |  Branch (59:13): [True: 0, False: 0]
  ------------------
   60|      0|           goto LBL_ERR;
   61|      0|        }
   62|      0|        keylen = hashsize;
   63|  21.6k|    } else {
   64|  21.6k|        XMEMCPY(hmac->key, key, (size_t)keylen);
  ------------------
  |  |   39|  21.6k|#define XMEMCPY  memcpy
  ------------------
   65|  21.6k|    }
   66|       |
   67|  21.6k|    if(keylen < LTC_HMAC_BLOCKSIZE) {
  ------------------
  |  |   18|  21.6k|#define LTC_HMAC_BLOCKSIZE hash_descriptor[hash].blocksize
  ------------------
  |  Branch (67:8): [True: 21.6k, False: 0]
  ------------------
   68|  21.6k|       zeromem((hmac->key) + keylen, (size_t)(LTC_HMAC_BLOCKSIZE - keylen));
  ------------------
  |  |   18|  21.6k|#define LTC_HMAC_BLOCKSIZE hash_descriptor[hash].blocksize
  ------------------
   69|  21.6k|    }
   70|       |
   71|       |    /* Create the initialization vector for step (3) */
   72|  1.40M|    for(i=0; i < LTC_HMAC_BLOCKSIZE;   i++) {
  ------------------
  |  |   18|  1.40M|#define LTC_HMAC_BLOCKSIZE hash_descriptor[hash].blocksize
  ------------------
  |  Branch (72:14): [True: 1.38M, False: 21.6k]
  ------------------
   73|  1.38M|       buf[i] = hmac->key[i] ^ 0x36;
   74|  1.38M|    }
   75|       |
   76|       |    /* Pre-pend that to the hash data */
   77|  21.6k|    if ((err = hash_descriptor[hash].init(&hmac->md)) != CRYPT_OK) {
  ------------------
  |  Branch (77:9): [True: 0, False: 21.6k]
  ------------------
   78|      0|       goto LBL_ERR;
   79|      0|    }
   80|       |
   81|  21.6k|    if ((err = hash_descriptor[hash].process(&hmac->md, buf, LTC_HMAC_BLOCKSIZE)) != CRYPT_OK) {
  ------------------
  |  |   18|  21.6k|#define LTC_HMAC_BLOCKSIZE hash_descriptor[hash].blocksize
  ------------------
  |  Branch (81:9): [True: 0, False: 21.6k]
  ------------------
   82|      0|       goto LBL_ERR;
   83|      0|    }
   84|  21.6k|    goto done;
   85|  21.6k|LBL_ERR:
   86|       |    /* free the key since we failed */
   87|      0|    XFREE(hmac->key);
  ------------------
  |  |   17|      0|#define XFREE m_free_direct
  ------------------
   88|  21.6k|done:
   89|       |#ifdef LTC_CLEAN_STACK
   90|       |   zeromem(buf, LTC_HMAC_BLOCKSIZE);
   91|       |#endif
   92|       |
   93|  21.6k|   return err;
   94|      0|}

hmac_process:
   26|  43.3k|{
   27|  43.3k|    int err;
   28|  43.3k|    LTC_ARGCHK(hmac != NULL);
  ------------------
  |  |   32|  43.3k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 43.3k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   29|  43.3k|    LTC_ARGCHK(in != NULL);
  ------------------
  |  |   32|  43.3k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 43.3k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   30|  43.3k|    if ((err = hash_is_valid(hmac->hash)) != CRYPT_OK) {
  ------------------
  |  Branch (30:9): [True: 0, False: 43.3k]
  ------------------
   31|      0|        return err;
   32|      0|    }
   33|  43.3k|    return hash_descriptor[hmac->hash].process(&hmac->md, in, inlen);
   34|  43.3k|}

poly1305_init:
   90|   214k|{
   91|   214k|   LTC_ARGCHK(st  != NULL);
  ------------------
  |  |   32|   214k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 214k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   92|   214k|   LTC_ARGCHK(key != NULL);
  ------------------
  |  |   32|   214k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 214k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   93|   214k|   LTC_ARGCHK(keylen == 32);
  ------------------
  |  |   32|   214k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 214k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   94|       |
   95|       |   /* r &= 0xffffffc0ffffffc0ffffffc0fffffff */
   96|   214k|   LOAD32L(st->r[0], key +  0); st->r[0] = (st->r[0]     ) & 0x3ffffff;
  ------------------
  |  |  167|   214k|  do { XMEMCPY(&(x), y, 4); x &= 0xFFFFFFFF; } while(0)
  |  |  ------------------
  |  |  |  |   39|   214k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (167:54): [Folded - Ignored]
  |  |  ------------------
  ------------------
   97|   214k|   LOAD32L(st->r[1], key +  3); st->r[1] = (st->r[1] >> 2) & 0x3ffff03;
  ------------------
  |  |  167|   214k|  do { XMEMCPY(&(x), y, 4); x &= 0xFFFFFFFF; } while(0)
  |  |  ------------------
  |  |  |  |   39|   214k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (167:54): [Folded - Ignored]
  |  |  ------------------
  ------------------
   98|   214k|   LOAD32L(st->r[2], key +  6); st->r[2] = (st->r[2] >> 4) & 0x3ffc0ff;
  ------------------
  |  |  167|   214k|  do { XMEMCPY(&(x), y, 4); x &= 0xFFFFFFFF; } while(0)
  |  |  ------------------
  |  |  |  |   39|   214k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (167:54): [Folded - Ignored]
  |  |  ------------------
  ------------------
   99|   214k|   LOAD32L(st->r[3], key +  9); st->r[3] = (st->r[3] >> 6) & 0x3f03fff;
  ------------------
  |  |  167|   214k|  do { XMEMCPY(&(x), y, 4); x &= 0xFFFFFFFF; } while(0)
  |  |  ------------------
  |  |  |  |   39|   214k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (167:54): [Folded - Ignored]
  |  |  ------------------
  ------------------
  100|   214k|   LOAD32L(st->r[4], key + 12); st->r[4] = (st->r[4] >> 8) & 0x00fffff;
  ------------------
  |  |  167|   214k|  do { XMEMCPY(&(x), y, 4); x &= 0xFFFFFFFF; } while(0)
  |  |  ------------------
  |  |  |  |   39|   214k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (167:54): [Folded - Ignored]
  |  |  ------------------
  ------------------
  101|       |
  102|       |   /* h = 0 */
  103|   214k|   st->h[0] = 0;
  104|   214k|   st->h[1] = 0;
  105|   214k|   st->h[2] = 0;
  106|   214k|   st->h[3] = 0;
  107|   214k|   st->h[4] = 0;
  108|       |
  109|       |   /* save pad for later */
  110|   214k|   LOAD32L(st->pad[0], key + 16);
  ------------------
  |  |  167|   214k|  do { XMEMCPY(&(x), y, 4); x &= 0xFFFFFFFF; } while(0)
  |  |  ------------------
  |  |  |  |   39|   214k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (167:54): [Folded - Ignored]
  |  |  ------------------
  ------------------
  111|   214k|   LOAD32L(st->pad[1], key + 20);
  ------------------
  |  |  167|   214k|  do { XMEMCPY(&(x), y, 4); x &= 0xFFFFFFFF; } while(0)
  |  |  ------------------
  |  |  |  |   39|   214k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (167:54): [Folded - Ignored]
  |  |  ------------------
  ------------------
  112|   214k|   LOAD32L(st->pad[2], key + 24);
  ------------------
  |  |  167|   214k|  do { XMEMCPY(&(x), y, 4); x &= 0xFFFFFFFF; } while(0)
  |  |  ------------------
  |  |  |  |   39|   214k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (167:54): [Folded - Ignored]
  |  |  ------------------
  ------------------
  113|   214k|   LOAD32L(st->pad[3], key + 28);
  ------------------
  |  |  167|   214k|  do { XMEMCPY(&(x), y, 4); x &= 0xFFFFFFFF; } while(0)
  |  |  ------------------
  |  |  |  |   39|   214k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (167:54): [Folded - Ignored]
  |  |  ------------------
  ------------------
  114|       |
  115|   214k|   st->leftover = 0;
  116|   214k|   st->final = 0;
  117|   214k|   return CRYPT_OK;
  118|   214k|}
poly1305_process:
  128|   214k|{
  129|   214k|   unsigned long i;
  130|       |
  131|   214k|   if (inlen == 0) return CRYPT_OK; /* nothing to do */
  ------------------
  |  Branch (131:8): [True: 0, False: 214k]
  ------------------
  132|   214k|   LTC_ARGCHK(st != NULL);
  ------------------
  |  |   32|   214k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 214k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  133|   214k|   LTC_ARGCHK(in != NULL);
  ------------------
  |  |   32|   214k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 214k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  134|       |
  135|       |   /* handle leftover */
  136|   214k|   if (st->leftover) {
  ------------------
  |  Branch (136:8): [True: 0, False: 214k]
  ------------------
  137|      0|      unsigned long want = (16 - st->leftover);
  138|      0|      if (want > inlen) want = inlen;
  ------------------
  |  Branch (138:11): [True: 0, False: 0]
  ------------------
  139|      0|      for (i = 0; i < want; i++) st->buffer[st->leftover + i] = in[i];
  ------------------
  |  Branch (139:19): [True: 0, False: 0]
  ------------------
  140|      0|      inlen -= want;
  141|      0|      in += want;
  142|      0|      st->leftover += want;
  143|      0|      if (st->leftover < 16) return CRYPT_OK;
  ------------------
  |  Branch (143:11): [True: 0, False: 0]
  ------------------
  144|      0|      _poly1305_block(st, st->buffer, 16);
  145|      0|      st->leftover = 0;
  146|      0|   }
  147|       |
  148|       |   /* process full blocks */
  149|   214k|   if (inlen >= 16) {
  ------------------
  |  Branch (149:8): [True: 214k, False: 0]
  ------------------
  150|   214k|      unsigned long want = (inlen & ~(16 - 1));
  151|   214k|      _poly1305_block(st, in, want);
  152|   214k|      in += want;
  153|   214k|      inlen -= want;
  154|   214k|   }
  155|       |
  156|       |   /* store leftover */
  157|   214k|   if (inlen) {
  ------------------
  |  Branch (157:8): [True: 214k, False: 0]
  ------------------
  158|  1.88M|      for (i = 0; i < inlen; i++) st->buffer[st->leftover + i] = in[i];
  ------------------
  |  Branch (158:19): [True: 1.66M, False: 214k]
  ------------------
  159|   214k|      st->leftover += inlen;
  160|   214k|   }
  161|   214k|   return CRYPT_OK;
  162|   214k|}
poly1305_done:
  172|   214k|{
  173|   214k|   ulong32 h0,h1,h2,h3,h4,c;
  174|   214k|   ulong32 g0,g1,g2,g3,g4;
  175|   214k|   ulong64 f;
  176|   214k|   ulong32 mask;
  177|       |
  178|   214k|   LTC_ARGCHK(st     != NULL);
  ------------------
  |  |   32|   214k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 214k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  179|   214k|   LTC_ARGCHK(mac    != NULL);
  ------------------
  |  |   32|   214k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 214k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  180|   214k|   LTC_ARGCHK(maclen != NULL);
  ------------------
  |  |   32|   214k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 214k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  181|   214k|   LTC_ARGCHK(*maclen >= 16);
  ------------------
  |  |   32|   214k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 214k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  182|       |
  183|       |   /* process the remaining block */
  184|   214k|   if (st->leftover) {
  ------------------
  |  Branch (184:8): [True: 214k, False: 0]
  ------------------
  185|   214k|      unsigned long i = st->leftover;
  186|   214k|      st->buffer[i++] = 1;
  187|  1.76M|      for (; i < 16; i++) st->buffer[i] = 0;
  ------------------
  |  Branch (187:14): [True: 1.54M, False: 214k]
  ------------------
  188|   214k|      st->final = 1;
  189|   214k|      _poly1305_block(st, st->buffer, 16);
  190|   214k|   }
  191|       |
  192|       |   /* fully carry h */
  193|   214k|   h0 = st->h[0];
  194|   214k|   h1 = st->h[1];
  195|   214k|   h2 = st->h[2];
  196|   214k|   h3 = st->h[3];
  197|   214k|   h4 = st->h[4];
  198|       |
  199|   214k|                c = h1 >> 26; h1 = h1 & 0x3ffffff;
  200|   214k|   h2 +=     c; c = h2 >> 26; h2 = h2 & 0x3ffffff;
  201|   214k|   h3 +=     c; c = h3 >> 26; h3 = h3 & 0x3ffffff;
  202|   214k|   h4 +=     c; c = h4 >> 26; h4 = h4 & 0x3ffffff;
  203|   214k|   h0 += c * 5; c = h0 >> 26; h0 = h0 & 0x3ffffff;
  204|   214k|   h1 +=     c;
  205|       |
  206|       |   /* compute h + -p */
  207|   214k|   g0 = h0 + 5; c = g0 >> 26; g0 &= 0x3ffffff;
  208|   214k|   g1 = h1 + c; c = g1 >> 26; g1 &= 0x3ffffff;
  209|   214k|   g2 = h2 + c; c = g2 >> 26; g2 &= 0x3ffffff;
  210|   214k|   g3 = h3 + c; c = g3 >> 26; g3 &= 0x3ffffff;
  211|   214k|   g4 = h4 + c - (1UL << 26);
  212|       |
  213|       |   /* select h if h < p, or h + -p if h >= p */
  214|   214k|   mask = (g4 >> 31) - 1;
  215|   214k|   g0 &= mask;
  216|   214k|   g1 &= mask;
  217|   214k|   g2 &= mask;
  218|   214k|   g3 &= mask;
  219|   214k|   g4 &= mask;
  220|   214k|   mask = ~mask;
  221|   214k|   h0 = (h0 & mask) | g0;
  222|   214k|   h1 = (h1 & mask) | g1;
  223|   214k|   h2 = (h2 & mask) | g2;
  224|   214k|   h3 = (h3 & mask) | g3;
  225|   214k|   h4 = (h4 & mask) | g4;
  226|       |
  227|       |   /* h = h % (2^128) */
  228|   214k|   h0 = ((h0      ) | (h1 << 26)) & 0xffffffff;
  229|   214k|   h1 = ((h1 >>  6) | (h2 << 20)) & 0xffffffff;
  230|   214k|   h2 = ((h2 >> 12) | (h3 << 14)) & 0xffffffff;
  231|   214k|   h3 = ((h3 >> 18) | (h4 <<  8)) & 0xffffffff;
  232|       |
  233|       |   /* mac = (h + pad) % (2^128) */
  234|   214k|   f = (ulong64)h0 + st->pad[0]            ; h0 = (ulong32)f;
  235|   214k|   f = (ulong64)h1 + st->pad[1] + (f >> 32); h1 = (ulong32)f;
  236|   214k|   f = (ulong64)h2 + st->pad[2] + (f >> 32); h2 = (ulong32)f;
  237|   214k|   f = (ulong64)h3 + st->pad[3] + (f >> 32); h3 = (ulong32)f;
  238|       |
  239|   214k|   STORE32L(h0, mac +  0);
  ------------------
  |  |  164|   214k|  do { ulong32 __t = (x); XMEMCPY(y, &__t, 4); } while(0)
  |  |  ------------------
  |  |  |  |   39|   214k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (164:56): [Folded - Ignored]
  |  |  ------------------
  ------------------
  240|   214k|   STORE32L(h1, mac +  4);
  ------------------
  |  |  164|   214k|  do { ulong32 __t = (x); XMEMCPY(y, &__t, 4); } while(0)
  |  |  ------------------
  |  |  |  |   39|   214k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (164:56): [Folded - Ignored]
  |  |  ------------------
  ------------------
  241|   214k|   STORE32L(h2, mac +  8);
  ------------------
  |  |  164|   214k|  do { ulong32 __t = (x); XMEMCPY(y, &__t, 4); } while(0)
  |  |  ------------------
  |  |  |  |   39|   214k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (164:56): [Folded - Ignored]
  |  |  ------------------
  ------------------
  242|   214k|   STORE32L(h3, mac + 12);
  ------------------
  |  |  164|   214k|  do { ulong32 __t = (x); XMEMCPY(y, &__t, 4); } while(0)
  |  |  ------------------
  |  |  |  |   39|   214k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (164:56): [Folded - Ignored]
  |  |  ------------------
  ------------------
  243|       |
  244|       |   /* zero out the state */
  245|   214k|   st->h[0] = 0;
  246|   214k|   st->h[1] = 0;
  247|   214k|   st->h[2] = 0;
  248|   214k|   st->h[3] = 0;
  249|   214k|   st->h[4] = 0;
  250|   214k|   st->r[0] = 0;
  251|   214k|   st->r[1] = 0;
  252|   214k|   st->r[2] = 0;
  253|   214k|   st->r[3] = 0;
  254|   214k|   st->r[4] = 0;
  255|   214k|   st->pad[0] = 0;
  256|   214k|   st->pad[1] = 0;
  257|   214k|   st->pad[2] = 0;
  258|   214k|   st->pad[3] = 0;
  259|       |
  260|   214k|   *maclen = 16;
  261|   214k|   return CRYPT_OK;
  262|   214k|}
poly1305.c:_poly1305_block:
   21|   429k|{
   22|   429k|   const unsigned long hibit = (st->final) ? 0 : (1UL << 24); /* 1 << 128 */
  ------------------
  |  Branch (22:32): [True: 214k, False: 214k]
  ------------------
   23|   429k|   ulong32 r0,r1,r2,r3,r4;
   24|   429k|   ulong32 s1,s2,s3,s4;
   25|   429k|   ulong32 h0,h1,h2,h3,h4;
   26|   429k|   ulong32 tmp;
   27|   429k|   ulong64 d0,d1,d2,d3,d4;
   28|   429k|   ulong32 c;
   29|       |
   30|   429k|   r0 = st->r[0];
   31|   429k|   r1 = st->r[1];
   32|   429k|   r2 = st->r[2];
   33|   429k|   r3 = st->r[3];
   34|   429k|   r4 = st->r[4];
   35|       |
   36|   429k|   s1 = r1 * 5;
   37|   429k|   s2 = r2 * 5;
   38|   429k|   s3 = r3 * 5;
   39|   429k|   s4 = r4 * 5;
   40|       |
   41|   429k|   h0 = st->h[0];
   42|   429k|   h1 = st->h[1];
   43|   429k|   h2 = st->h[2];
   44|   429k|   h3 = st->h[3];
   45|   429k|   h4 = st->h[4];
   46|       |
   47|  49.5M|   while (inlen >= 16) {
  ------------------
  |  Branch (47:11): [True: 49.1M, False: 429k]
  ------------------
   48|       |      /* h += in[i] */
   49|  49.1M|      LOAD32L(tmp, in+ 0); h0 += (tmp     ) & 0x3ffffff;
  ------------------
  |  |  167|  49.1M|  do { XMEMCPY(&(x), y, 4); x &= 0xFFFFFFFF; } while(0)
  |  |  ------------------
  |  |  |  |   39|  49.1M|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (167:54): [Folded - Ignored]
  |  |  ------------------
  ------------------
   50|  49.1M|      LOAD32L(tmp, in+ 3); h1 += (tmp >> 2) & 0x3ffffff;
  ------------------
  |  |  167|  49.1M|  do { XMEMCPY(&(x), y, 4); x &= 0xFFFFFFFF; } while(0)
  |  |  ------------------
  |  |  |  |   39|  49.1M|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (167:54): [Folded - Ignored]
  |  |  ------------------
  ------------------
   51|  49.1M|      LOAD32L(tmp, in+ 6); h2 += (tmp >> 4) & 0x3ffffff;
  ------------------
  |  |  167|  49.1M|  do { XMEMCPY(&(x), y, 4); x &= 0xFFFFFFFF; } while(0)
  |  |  ------------------
  |  |  |  |   39|  49.1M|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (167:54): [Folded - Ignored]
  |  |  ------------------
  ------------------
   52|  49.1M|      LOAD32L(tmp, in+ 9); h3 += (tmp >> 6) & 0x3ffffff;
  ------------------
  |  |  167|  49.1M|  do { XMEMCPY(&(x), y, 4); x &= 0xFFFFFFFF; } while(0)
  |  |  ------------------
  |  |  |  |   39|  49.1M|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (167:54): [Folded - Ignored]
  |  |  ------------------
  ------------------
   53|  49.1M|      LOAD32L(tmp, in+12); h4 += (tmp >> 8) | hibit;
  ------------------
  |  |  167|  49.1M|  do { XMEMCPY(&(x), y, 4); x &= 0xFFFFFFFF; } while(0)
  |  |  ------------------
  |  |  |  |   39|  49.1M|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (167:54): [Folded - Ignored]
  |  |  ------------------
  ------------------
   54|       |
   55|       |      /* h *= r */
   56|  49.1M|      d0 = ((ulong64)h0 * r0) + ((ulong64)h1 * s4) + ((ulong64)h2 * s3) + ((ulong64)h3 * s2) + ((ulong64)h4 * s1);
   57|  49.1M|      d1 = ((ulong64)h0 * r1) + ((ulong64)h1 * r0) + ((ulong64)h2 * s4) + ((ulong64)h3 * s3) + ((ulong64)h4 * s2);
   58|  49.1M|      d2 = ((ulong64)h0 * r2) + ((ulong64)h1 * r1) + ((ulong64)h2 * r0) + ((ulong64)h3 * s4) + ((ulong64)h4 * s3);
   59|  49.1M|      d3 = ((ulong64)h0 * r3) + ((ulong64)h1 * r2) + ((ulong64)h2 * r1) + ((ulong64)h3 * r0) + ((ulong64)h4 * s4);
   60|  49.1M|      d4 = ((ulong64)h0 * r4) + ((ulong64)h1 * r3) + ((ulong64)h2 * r2) + ((ulong64)h3 * r1) + ((ulong64)h4 * r0);
   61|       |
   62|       |      /* (partial) h %= p */
   63|  49.1M|                    c = (ulong32)(d0 >> 26); h0 = (ulong32)d0 & 0x3ffffff;
   64|  49.1M|      d1 += c;      c = (ulong32)(d1 >> 26); h1 = (ulong32)d1 & 0x3ffffff;
   65|  49.1M|      d2 += c;      c = (ulong32)(d2 >> 26); h2 = (ulong32)d2 & 0x3ffffff;
   66|  49.1M|      d3 += c;      c = (ulong32)(d3 >> 26); h3 = (ulong32)d3 & 0x3ffffff;
   67|  49.1M|      d4 += c;      c = (ulong32)(d4 >> 26); h4 = (ulong32)d4 & 0x3ffffff;
   68|  49.1M|      h0 += c * 5;  c =          (h0 >> 26); h0 =          h0 & 0x3ffffff;
   69|  49.1M|      h1 += c;
   70|       |
   71|  49.1M|      in += 16;
   72|  49.1M|      inlen -= 16;
   73|  49.1M|   }
   74|       |
   75|   429k|   st->h[0] = h0;
   76|   429k|   st->h[1] = h1;
   77|   429k|   st->h[2] = h2;
   78|   429k|   st->h[3] = h3;
   79|   429k|   st->h[4] = h4;
   80|   429k|}

cipher_is_valid:
   22|  25.2k|{
   23|  25.2k|   LTC_MUTEX_LOCK(&ltc_cipher_mutex);
   24|  25.2k|   if (idx < 0 || idx >= TAB_SIZE || cipher_descriptor[idx].name == NULL) {
  ------------------
  |  |   14|  50.4k|#define TAB_SIZE      5
  ------------------
  |  Branch (24:8): [True: 0, False: 25.2k]
  |  Branch (24:19): [True: 0, False: 25.2k]
  |  Branch (24:38): [True: 0, False: 25.2k]
  ------------------
   25|      0|      LTC_MUTEX_UNLOCK(&ltc_cipher_mutex);
   26|      0|      return CRYPT_INVALID_CIPHER;
   27|      0|   }
   28|  25.2k|   LTC_MUTEX_UNLOCK(&ltc_cipher_mutex);
   29|  25.2k|   return CRYPT_OK;
   30|  25.2k|}

find_cipher:
   22|  6.72k|{
   23|  6.72k|   int x;
   24|  6.72k|   LTC_ARGCHK(name != NULL);
  ------------------
  |  |   32|  6.72k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 6.72k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   25|  6.72k|   LTC_MUTEX_LOCK(&ltc_cipher_mutex);
   26|  6.72k|   for (x = 0; x < TAB_SIZE; x++) {
  ------------------
  |  |   14|  6.72k|#define TAB_SIZE      5
  ------------------
  |  Branch (26:16): [True: 6.72k, False: 0]
  ------------------
   27|  6.72k|       if (cipher_descriptor[x].name != NULL && !XSTRCMP(cipher_descriptor[x].name, name)) {
  ------------------
  |  |   54|  6.72k|#define XSTRCMP strcmp
  ------------------
  |  Branch (27:12): [True: 6.72k, False: 0]
  |  Branch (27:49): [True: 6.72k, False: 0]
  ------------------
   28|  6.72k|          LTC_MUTEX_UNLOCK(&ltc_cipher_mutex);
   29|  6.72k|          return x;
   30|  6.72k|       }
   31|  6.72k|   }
   32|      0|   LTC_MUTEX_UNLOCK(&ltc_cipher_mutex);
   33|      0|   return -1;
   34|  6.72k|}

find_hash:
   22|  3.55k|{
   23|  3.55k|   int x;
   24|  3.55k|   LTC_ARGCHK(name != NULL);
  ------------------
  |  |   32|  3.55k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 3.55k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   25|  3.55k|   LTC_MUTEX_LOCK(&ltc_hash_mutex);
   26|  6.93k|   for (x = 0; x < TAB_SIZE; x++) {
  ------------------
  |  |   14|  6.93k|#define TAB_SIZE      5
  ------------------
  |  Branch (26:16): [True: 6.93k, False: 0]
  ------------------
   27|  6.93k|       if (hash_descriptor[x].name != NULL && XSTRCMP(hash_descriptor[x].name, name) == 0) {
  ------------------
  |  |   54|  6.93k|#define XSTRCMP strcmp
  ------------------
  |  Branch (27:12): [True: 6.93k, False: 0]
  |  Branch (27:47): [True: 3.55k, False: 3.38k]
  ------------------
   28|  3.55k|          LTC_MUTEX_UNLOCK(&ltc_hash_mutex);
   29|  3.55k|          return x;
   30|  3.55k|       }
   31|  6.93k|   }
   32|      0|   LTC_MUTEX_UNLOCK(&ltc_hash_mutex);
   33|      0|   return -1;
   34|  3.55k|}

hash_is_valid:
   22|  86.7k|{
   23|  86.7k|   LTC_MUTEX_LOCK(&ltc_hash_mutex);
   24|  86.7k|   if (idx < 0 || idx >= TAB_SIZE || hash_descriptor[idx].name == NULL) {
  ------------------
  |  |   14|   173k|#define TAB_SIZE      5
  ------------------
  |  Branch (24:8): [True: 0, False: 86.7k]
  |  Branch (24:19): [True: 0, False: 86.7k]
  |  Branch (24:38): [True: 0, False: 86.7k]
  ------------------
   25|      0|      LTC_MUTEX_UNLOCK(&ltc_hash_mutex);
   26|      0|      return CRYPT_INVALID_HASH;
   27|      0|   }
   28|  86.7k|   LTC_MUTEX_UNLOCK(&ltc_hash_mutex);
   29|  86.7k|   return CRYPT_OK;
   30|  86.7k|}

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

zeromem:
   23|  21.6k|{
   24|  21.6k|   m_burn((void*)out, outlen);
   25|  21.6k|}

ctr_encrypt:
   87|  21.6k|{
   88|  21.6k|   int err, fr;
   89|       |
   90|  21.6k|   LTC_ARGCHK(pt != NULL);
  ------------------
  |  |   32|  21.6k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 21.6k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   91|  21.6k|   LTC_ARGCHK(ct != NULL);
  ------------------
  |  |   32|  21.6k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 21.6k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   92|  21.6k|   LTC_ARGCHK(ctr != NULL);
  ------------------
  |  |   32|  21.6k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 21.6k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   93|       |
   94|  21.6k|   if ((err = cipher_is_valid(ctr->cipher)) != CRYPT_OK) {
  ------------------
  |  Branch (94:8): [True: 0, False: 21.6k]
  ------------------
   95|      0|       return err;
   96|      0|   }
   97|       |
   98|       |   /* is blocklen/padlen valid? */
   99|  21.6k|   if ((ctr->blocklen < 1) || (ctr->blocklen > (int)sizeof(ctr->ctr)) ||
  ------------------
  |  Branch (99:8): [True: 0, False: 21.6k]
  |  Branch (99:31): [True: 0, False: 21.6k]
  ------------------
  100|  21.6k|       (ctr->padlen   < 0) || (ctr->padlen   > (int)sizeof(ctr->pad))) {
  ------------------
  |  Branch (100:8): [True: 0, False: 21.6k]
  |  Branch (100:31): [True: 0, False: 21.6k]
  ------------------
  101|      0|      return CRYPT_INVALID_ARG;
  102|      0|   }
  103|       |
  104|  21.6k|#ifdef LTC_FAST
  105|  21.6k|   if (ctr->blocklen % sizeof(LTC_FAST_TYPE)) {
  ------------------
  |  Branch (105:8): [True: 0, False: 21.6k]
  ------------------
  106|      0|      return CRYPT_INVALID_ARG;
  107|      0|   }
  108|  21.6k|#endif
  109|       |
  110|       |   /* handle acceleration only if pad is empty, accelerator is present and length is >= a block size */
  111|  21.6k|   if ((cipher_descriptor[ctr->cipher].accel_ctr_encrypt != NULL) && (len >= (unsigned long)ctr->blocklen)) {
  ------------------
  |  Branch (111:8): [True: 0, False: 21.6k]
  |  Branch (111:70): [True: 0, False: 0]
  ------------------
  112|      0|     if (ctr->padlen < ctr->blocklen) {
  ------------------
  |  Branch (112:10): [True: 0, False: 0]
  ------------------
  113|      0|       fr = ctr->blocklen - ctr->padlen;
  114|      0|       if ((err = _ctr_encrypt(pt, ct, fr, ctr)) != CRYPT_OK) {
  ------------------
  |  Branch (114:12): [True: 0, False: 0]
  ------------------
  115|      0|          return err;
  116|      0|       }
  117|      0|       pt += fr;
  118|      0|       ct += fr;
  119|      0|       len -= fr;
  120|      0|     }
  121|       |
  122|      0|     if (len >= (unsigned long)ctr->blocklen) {
  ------------------
  |  Branch (122:10): [True: 0, False: 0]
  ------------------
  123|      0|       if ((err = cipher_descriptor[ctr->cipher].accel_ctr_encrypt(pt, ct, len/ctr->blocklen, ctr->ctr, ctr->mode, &ctr->key)) != CRYPT_OK) {
  ------------------
  |  Branch (123:12): [True: 0, False: 0]
  ------------------
  124|      0|          return err;
  125|      0|       }
  126|      0|       pt += (len / ctr->blocklen) * ctr->blocklen;
  127|      0|       ct += (len / ctr->blocklen) * ctr->blocklen;
  128|      0|       len %= ctr->blocklen;
  129|      0|     }
  130|      0|   }
  131|       |
  132|  21.6k|   return _ctr_encrypt(pt, ct, len, ctr);
  133|  21.6k|}
ctr_encrypt.c:_ctr_encrypt:
   28|  21.6k|{
   29|  21.6k|   int x, err;
   30|       |
   31|  5.87M|   while (len) {
  ------------------
  |  Branch (31:11): [True: 5.85M, False: 21.6k]
  ------------------
   32|       |      /* is the pad empty? */
   33|  5.85M|      if (ctr->padlen == ctr->blocklen) {
  ------------------
  |  Branch (33:11): [True: 5.84M, False: 3.37k]
  ------------------
   34|       |         /* increment counter */
   35|  5.84M|         if (ctr->mode == CTR_COUNTER_LITTLE_ENDIAN) {
  ------------------
  |  |  859|  5.84M|#define CTR_COUNTER_LITTLE_ENDIAN    0x0000
  ------------------
  |  Branch (35:14): [True: 0, False: 5.84M]
  ------------------
   36|       |            /* little-endian */
   37|      0|            for (x = 0; x < ctr->ctrlen; x++) {
  ------------------
  |  Branch (37:25): [True: 0, False: 0]
  ------------------
   38|      0|               ctr->ctr[x] = (ctr->ctr[x] + (unsigned char)1) & (unsigned char)255;
   39|      0|               if (ctr->ctr[x] != (unsigned char)0) {
  ------------------
  |  Branch (39:20): [True: 0, False: 0]
  ------------------
   40|      0|                  break;
   41|      0|               }
   42|      0|            }
   43|  5.84M|         } else {
   44|       |            /* big-endian */
   45|  5.87M|            for (x = ctr->blocklen-1; x >= ctr->ctrlen; x--) {
  ------------------
  |  Branch (45:39): [True: 5.87M, False: 0]
  ------------------
   46|  5.87M|               ctr->ctr[x] = (ctr->ctr[x] + (unsigned char)1) & (unsigned char)255;
   47|  5.87M|               if (ctr->ctr[x] != (unsigned char)0) {
  ------------------
  |  Branch (47:20): [True: 5.84M, False: 22.9k]
  ------------------
   48|  5.84M|                  break;
   49|  5.84M|               }
   50|  5.87M|            }
   51|  5.84M|         }
   52|       |
   53|       |         /* encrypt it */
   54|  5.84M|         if ((err = cipher_descriptor[ctr->cipher].ecb_encrypt(ctr->ctr, ctr->pad, &ctr->key)) != CRYPT_OK) {
  ------------------
  |  Branch (54:14): [True: 0, False: 5.84M]
  ------------------
   55|      0|            return err;
   56|      0|         }
   57|  5.84M|         ctr->padlen = 0;
   58|  5.84M|      }
   59|  5.85M|#ifdef LTC_FAST
   60|  5.85M|      if ((ctr->padlen == 0) && (len >= (unsigned long)ctr->blocklen)) {
  ------------------
  |  Branch (60:11): [True: 5.85M, False: 0]
  |  Branch (60:33): [True: 5.85M, False: 0]
  ------------------
   61|  17.5M|         for (x = 0; x < ctr->blocklen; x += sizeof(LTC_FAST_TYPE)) {
  ------------------
  |  Branch (61:22): [True: 11.7M, False: 5.85M]
  ------------------
   62|  11.7M|            *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)ct + x)) = *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)pt + x)) ^
  ------------------
  |  |  244|  11.7M|   #define LTC_FAST_TYPE_PTR_CAST(x) ((LTC_FAST_TYPE*)(void*)(x))
  ------------------
                          *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)ct + x)) = *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)pt + x)) ^
  ------------------
  |  |  244|  11.7M|   #define LTC_FAST_TYPE_PTR_CAST(x) ((LTC_FAST_TYPE*)(void*)(x))
  ------------------
   63|  11.7M|                                                           *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)ctr->pad + x));
  ------------------
  |  |  244|  11.7M|   #define LTC_FAST_TYPE_PTR_CAST(x) ((LTC_FAST_TYPE*)(void*)(x))
  ------------------
   64|  11.7M|         }
   65|  5.85M|       pt         += ctr->blocklen;
   66|  5.85M|       ct         += ctr->blocklen;
   67|  5.85M|       len        -= ctr->blocklen;
   68|  5.85M|       ctr->padlen = ctr->blocklen;
   69|  5.85M|       continue;
   70|  5.85M|      }
   71|      0|#endif
   72|      0|      *ct++ = *pt++ ^ ctr->pad[ctr->padlen++];
   73|      0|      --len;
   74|      0|   }
   75|  21.6k|   return CRYPT_OK;
   76|  21.6k|}

ctr_start:
   35|  3.55k|{
   36|  3.55k|   int x, err;
   37|       |
   38|  3.55k|   LTC_ARGCHK(IV  != NULL);
  ------------------
  |  |   32|  3.55k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 3.55k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   39|  3.55k|   LTC_ARGCHK(key != NULL);
  ------------------
  |  |   32|  3.55k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 3.55k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   40|  3.55k|   LTC_ARGCHK(ctr != NULL);
  ------------------
  |  |   32|  3.55k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 3.55k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   41|       |
   42|       |   /* bad param? */
   43|  3.55k|   if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
  ------------------
  |  Branch (43:8): [True: 0, False: 3.55k]
  ------------------
   44|      0|      return err;
   45|      0|   }
   46|       |
   47|       |   /* ctrlen == counter width */
   48|  3.55k|   ctr->ctrlen   = (ctr_mode & 255) ? (ctr_mode & 255) : cipher_descriptor[cipher].block_length;
  ------------------
  |  Branch (48:20): [True: 0, False: 3.55k]
  ------------------
   49|  3.55k|   if (ctr->ctrlen > cipher_descriptor[cipher].block_length) {
  ------------------
  |  Branch (49:8): [True: 0, False: 3.55k]
  ------------------
   50|      0|      return CRYPT_INVALID_ARG;
   51|      0|   }
   52|       |
   53|  3.55k|   if ((ctr_mode & 0x1000) == CTR_COUNTER_BIG_ENDIAN) {
  ------------------
  |  |  860|  3.55k|#define CTR_COUNTER_BIG_ENDIAN       0x1000
  ------------------
  |  Branch (53:8): [True: 3.55k, False: 0]
  ------------------
   54|  3.55k|      ctr->ctrlen = cipher_descriptor[cipher].block_length - ctr->ctrlen;
   55|  3.55k|   }
   56|       |
   57|       |   /* setup cipher */
   58|  3.55k|   if ((err = cipher_descriptor[cipher].setup(key, keylen, num_rounds, &ctr->key)) != CRYPT_OK) {
  ------------------
  |  Branch (58:8): [True: 0, False: 3.55k]
  ------------------
   59|      0|      return err;
   60|      0|   }
   61|       |
   62|       |   /* copy ctr */
   63|  3.55k|   ctr->blocklen = cipher_descriptor[cipher].block_length;
   64|  3.55k|   ctr->cipher   = cipher;
   65|  3.55k|   ctr->padlen   = 0;
   66|  3.55k|   ctr->mode     = ctr_mode & 0x1000;
   67|  60.4k|   for (x = 0; x < ctr->blocklen; x++) {
  ------------------
  |  Branch (67:16): [True: 56.9k, False: 3.55k]
  ------------------
   68|  56.9k|       ctr->ctr[x] = IV[x];
   69|  56.9k|   }
   70|       |
   71|  3.55k|   if (ctr_mode & LTC_CTR_RFC3686) {
  ------------------
  |  |  861|  3.55k|#define LTC_CTR_RFC3686              0x2000
  ------------------
  |  Branch (71:8): [True: 0, False: 3.55k]
  ------------------
   72|       |      /* increment the IV as per RFC 3686 */
   73|      0|      if (ctr->mode == CTR_COUNTER_LITTLE_ENDIAN) {
  ------------------
  |  |  859|      0|#define CTR_COUNTER_LITTLE_ENDIAN    0x0000
  ------------------
  |  Branch (73:11): [True: 0, False: 0]
  ------------------
   74|       |         /* little-endian */
   75|      0|         for (x = 0; x < ctr->ctrlen; x++) {
  ------------------
  |  Branch (75:22): [True: 0, False: 0]
  ------------------
   76|      0|             ctr->ctr[x] = (ctr->ctr[x] + (unsigned char)1) & (unsigned char)255;
   77|      0|             if (ctr->ctr[x] != (unsigned char)0) {
  ------------------
  |  Branch (77:18): [True: 0, False: 0]
  ------------------
   78|      0|                break;
   79|      0|             }
   80|      0|         }
   81|      0|      } else {
   82|       |         /* big-endian */
   83|      0|         for (x = ctr->blocklen-1; x >= ctr->ctrlen; x--) {
  ------------------
  |  Branch (83:36): [True: 0, False: 0]
  ------------------
   84|      0|             ctr->ctr[x] = (ctr->ctr[x] + (unsigned char)1) & (unsigned char)255;
   85|      0|             if (ctr->ctr[x] != (unsigned char)0) {
  ------------------
  |  Branch (85:18): [True: 0, False: 0]
  ------------------
   86|      0|                break;
   87|      0|             }
   88|      0|         }
   89|      0|      }
   90|      0|   }
   91|       |
   92|  3.55k|   return cipher_descriptor[ctr->cipher].ecb_encrypt(ctr->ctr, ctr->pad, &ctr->key);
   93|  3.55k|}

chacha_crypt:
   55|   643k|{
   56|   643k|   unsigned char buf[64];
   57|   643k|   unsigned long i, j;
   58|       |
   59|   643k|   if (inlen == 0) return CRYPT_OK; /* nothing to do */
  ------------------
  |  Branch (59:8): [True: 0, False: 643k]
  ------------------
   60|       |
   61|   643k|   LTC_ARGCHK(st        != NULL);
  ------------------
  |  |   32|   643k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 643k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   62|   643k|   LTC_ARGCHK(in        != NULL);
  ------------------
  |  |   32|   643k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 643k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   63|   643k|   LTC_ARGCHK(out       != NULL);
  ------------------
  |  |   32|   643k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 643k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   64|   643k|   LTC_ARGCHK(st->ivlen != 0);
  ------------------
  |  |   32|   643k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 643k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   65|       |
   66|   643k|   if (st->ksleft > 0) {
  ------------------
  |  Branch (66:8): [True: 0, False: 643k]
  ------------------
   67|      0|      j = MIN(st->ksleft, inlen);
  ------------------
  |  |  425|      0|   #define MIN(x, y) ( ((x)<(y))?(x):(y) )
  |  |  ------------------
  |  |  |  Branch (425:24): [True: 0, False: 0]
  |  |  ------------------
  ------------------
   68|      0|      for (i = 0; i < j; ++i, st->ksleft--) out[i] = in[i] ^ st->kstream[64 - st->ksleft];
  ------------------
  |  Branch (68:19): [True: 0, False: 0]
  ------------------
   69|      0|      inlen -= j;
   70|      0|      if (inlen == 0) return CRYPT_OK;
  ------------------
  |  Branch (70:11): [True: 0, False: 0]
  ------------------
   71|      0|      out += j;
   72|      0|      in  += j;
   73|      0|   }
   74|  12.7M|   for (;;) {
   75|  12.7M|     _chacha_block(buf, st->input, st->rounds);
   76|  12.7M|     if (st->ivlen == 8) {
  ------------------
  |  Branch (76:10): [True: 12.7M, False: 0]
  ------------------
   77|       |       /* IV-64bit, increment 64bit counter */
   78|  12.7M|       if (0 == ++st->input[12] && 0 == ++st->input[13]) return CRYPT_OVERFLOW;
  ------------------
  |  Branch (78:12): [True: 0, False: 12.7M]
  |  Branch (78:36): [True: 0, False: 0]
  ------------------
   79|  12.7M|     }
   80|      0|     else {
   81|       |       /* IV-96bit, increment 32bit counter */
   82|      0|       if (0 == ++st->input[12]) return CRYPT_OVERFLOW;
  ------------------
  |  Branch (82:12): [True: 0, False: 0]
  ------------------
   83|      0|     }
   84|  12.7M|     if (inlen <= 64) {
  ------------------
  |  Branch (84:10): [True: 643k, False: 12.1M]
  ------------------
   85|  16.4M|       for (i = 0; i < inlen; ++i) out[i] = in[i] ^ buf[i];
  ------------------
  |  Branch (85:20): [True: 15.7M, False: 643k]
  ------------------
   86|   643k|       st->ksleft = 64 - inlen;
   87|  26.0M|       for (i = inlen; i < 64; ++i) st->kstream[i] = buf[i];
  ------------------
  |  Branch (87:24): [True: 25.4M, False: 643k]
  ------------------
   88|   643k|       return CRYPT_OK;
   89|   643k|     }
   90|   788M|     for (i = 0; i < 64; ++i) out[i] = in[i] ^ buf[i];
  ------------------
  |  Branch (90:18): [True: 776M, False: 12.1M]
  ------------------
   91|  12.1M|     inlen -= 64;
   92|  12.1M|     out += 64;
   93|  12.1M|     in  += 64;
   94|  12.1M|   }
   95|   643k|}
chacha_crypt.c:_chacha_block:
   26|  12.7M|{
   27|  12.7M|   ulong32 x[16];
   28|  12.7M|   int i;
   29|  12.7M|   XMEMCPY(x, input, sizeof(x));
  ------------------
  |  |   39|  12.7M|#define XMEMCPY  memcpy
  ------------------
   30|   140M|   for (i = rounds; i > 0; i -= 2) {
  ------------------
  |  Branch (30:21): [True: 127M, False: 12.7M]
  ------------------
   31|   127M|      QUARTERROUND(0, 4, 8,12)
  ------------------
  |  |   20|   127M|  x[a] += x[b]; x[d] = ROL(x[d] ^ x[a], 16); \
  |  |   21|   127M|  x[c] += x[d]; x[b] = ROL(x[b] ^ x[c], 12); \
  |  |   22|   127M|  x[a] += x[b]; x[d] = ROL(x[d] ^ x[a],  8); \
  |  |   23|   127M|  x[c] += x[d]; x[b] = ROL(x[b] ^ x[c],  7);
  ------------------
   32|   127M|      QUARTERROUND(1, 5, 9,13)
  ------------------
  |  |   20|   127M|  x[a] += x[b]; x[d] = ROL(x[d] ^ x[a], 16); \
  |  |   21|   127M|  x[c] += x[d]; x[b] = ROL(x[b] ^ x[c], 12); \
  |  |   22|   127M|  x[a] += x[b]; x[d] = ROL(x[d] ^ x[a],  8); \
  |  |   23|   127M|  x[c] += x[d]; x[b] = ROL(x[b] ^ x[c],  7);
  ------------------
   33|   127M|      QUARTERROUND(2, 6,10,14)
  ------------------
  |  |   20|   127M|  x[a] += x[b]; x[d] = ROL(x[d] ^ x[a], 16); \
  |  |   21|   127M|  x[c] += x[d]; x[b] = ROL(x[b] ^ x[c], 12); \
  |  |   22|   127M|  x[a] += x[b]; x[d] = ROL(x[d] ^ x[a],  8); \
  |  |   23|   127M|  x[c] += x[d]; x[b] = ROL(x[b] ^ x[c],  7);
  ------------------
   34|   127M|      QUARTERROUND(3, 7,11,15)
  ------------------
  |  |   20|   127M|  x[a] += x[b]; x[d] = ROL(x[d] ^ x[a], 16); \
  |  |   21|   127M|  x[c] += x[d]; x[b] = ROL(x[b] ^ x[c], 12); \
  |  |   22|   127M|  x[a] += x[b]; x[d] = ROL(x[d] ^ x[a],  8); \
  |  |   23|   127M|  x[c] += x[d]; x[b] = ROL(x[b] ^ x[c],  7);
  ------------------
   35|   127M|      QUARTERROUND(0, 5,10,15)
  ------------------
  |  |   20|   127M|  x[a] += x[b]; x[d] = ROL(x[d] ^ x[a], 16); \
  |  |   21|   127M|  x[c] += x[d]; x[b] = ROL(x[b] ^ x[c], 12); \
  |  |   22|   127M|  x[a] += x[b]; x[d] = ROL(x[d] ^ x[a],  8); \
  |  |   23|   127M|  x[c] += x[d]; x[b] = ROL(x[b] ^ x[c],  7);
  ------------------
   36|   127M|      QUARTERROUND(1, 6,11,12)
  ------------------
  |  |   20|   127M|  x[a] += x[b]; x[d] = ROL(x[d] ^ x[a], 16); \
  |  |   21|   127M|  x[c] += x[d]; x[b] = ROL(x[b] ^ x[c], 12); \
  |  |   22|   127M|  x[a] += x[b]; x[d] = ROL(x[d] ^ x[a],  8); \
  |  |   23|   127M|  x[c] += x[d]; x[b] = ROL(x[b] ^ x[c],  7);
  ------------------
   37|   127M|      QUARTERROUND(2, 7, 8,13)
  ------------------
  |  |   20|   127M|  x[a] += x[b]; x[d] = ROL(x[d] ^ x[a], 16); \
  |  |   21|   127M|  x[c] += x[d]; x[b] = ROL(x[b] ^ x[c], 12); \
  |  |   22|   127M|  x[a] += x[b]; x[d] = ROL(x[d] ^ x[a],  8); \
  |  |   23|   127M|  x[c] += x[d]; x[b] = ROL(x[b] ^ x[c],  7);
  ------------------
   38|   127M|      QUARTERROUND(3, 4, 9,14)
  ------------------
  |  |   20|   127M|  x[a] += x[b]; x[d] = ROL(x[d] ^ x[a], 16); \
  |  |   21|   127M|  x[c] += x[d]; x[b] = ROL(x[b] ^ x[c], 12); \
  |  |   22|   127M|  x[a] += x[b]; x[d] = ROL(x[d] ^ x[a],  8); \
  |  |   23|   127M|  x[c] += x[d]; x[b] = ROL(x[b] ^ x[c],  7);
  ------------------
   39|   127M|   }
   40|   217M|   for (i = 0; i < 16; ++i) {
  ------------------
  |  Branch (40:16): [True: 204M, False: 12.7M]
  ------------------
   41|   204M|     x[i] += input[i];
   42|   204M|     STORE32L(x[i], output + 4 * i);
  ------------------
  |  |  164|   204M|  do { ulong32 __t = (x); XMEMCPY(y, &__t, 4); } while(0)
  |  |  ------------------
  |  |  |  |   39|   204M|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (164:56): [Folded - Ignored]
  |  |  ------------------
  ------------------
   43|   204M|   }
   44|  12.7M|}

chacha_ivctr64:
   28|   643k|{
   29|   643k|   LTC_ARGCHK(st != NULL);
  ------------------
  |  |   32|   643k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 643k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   30|   643k|   LTC_ARGCHK(iv != NULL);
  ------------------
  |  |   32|   643k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 643k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   31|       |   /* 64bit IV + 64bit counter */
   32|   643k|   LTC_ARGCHK(ivlen == 8);
  ------------------
  |  |   32|   643k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 643k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   33|       |
   34|   643k|   st->input[12] = (ulong32)(counter & 0xFFFFFFFF);
   35|   643k|   st->input[13] = (ulong32)(counter >> 32);
   36|   643k|   LOAD32L(st->input[14], iv + 0);
  ------------------
  |  |  167|   643k|  do { XMEMCPY(&(x), y, 4); x &= 0xFFFFFFFF; } while(0)
  |  |  ------------------
  |  |  |  |   39|   643k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (167:54): [Folded - Ignored]
  |  |  ------------------
  ------------------
   37|   643k|   LOAD32L(st->input[15], iv + 4);
  ------------------
  |  |  167|   643k|  do { XMEMCPY(&(x), y, 4); x &= 0xFFFFFFFF; } while(0)
  |  |  ------------------
  |  |  |  |   39|   643k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (167:54): [Folded - Ignored]
  |  |  ------------------
  ------------------
   38|   643k|   st->ksleft = 0;
   39|   643k|   st->ivlen = ivlen;
   40|   643k|   return CRYPT_OK;
   41|   643k|}

chacha_keystream:
   27|   214k|{
   28|   214k|   if (outlen == 0) return CRYPT_OK; /* nothing to do */
  ------------------
  |  Branch (28:8): [True: 0, False: 214k]
  ------------------
   29|   214k|   LTC_ARGCHK(out != NULL);
  ------------------
  |  |   32|   214k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 214k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   30|   214k|   XMEMSET(out, 0, outlen);
  ------------------
  |  |   36|   214k|#define XMEMSET  memset
  ------------------
   31|   214k|   return chacha_crypt(st, out, outlen, out);
   32|   214k|}

chacha_setup:
   31|  11.4k|{
   32|  11.4k|   const char *constants;
   33|       |
   34|  11.4k|   LTC_ARGCHK(st  != NULL);
  ------------------
  |  |   32|  11.4k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 11.4k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   35|  11.4k|   LTC_ARGCHK(key != NULL);
  ------------------
  |  |   32|  11.4k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 11.4k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   36|  11.4k|   LTC_ARGCHK(keylen == 32 || keylen == 16);
  ------------------
  |  |   32|  11.4k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:34): [True: 11.4k, False: 0]
  |  |  |  Branch (32:34): [True: 0, False: 0]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   37|       |
   38|  11.4k|   if (rounds == 0) rounds = 20;
  ------------------
  |  Branch (38:8): [True: 0, False: 11.4k]
  ------------------
   39|       |
   40|  11.4k|   LOAD32L(st->input[4], key + 0);
  ------------------
  |  |  167|  11.4k|  do { XMEMCPY(&(x), y, 4); x &= 0xFFFFFFFF; } while(0)
  |  |  ------------------
  |  |  |  |   39|  11.4k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (167:54): [Folded - Ignored]
  |  |  ------------------
  ------------------
   41|  11.4k|   LOAD32L(st->input[5], key + 4);
  ------------------
  |  |  167|  11.4k|  do { XMEMCPY(&(x), y, 4); x &= 0xFFFFFFFF; } while(0)
  |  |  ------------------
  |  |  |  |   39|  11.4k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (167:54): [Folded - Ignored]
  |  |  ------------------
  ------------------
   42|  11.4k|   LOAD32L(st->input[6], key + 8);
  ------------------
  |  |  167|  11.4k|  do { XMEMCPY(&(x), y, 4); x &= 0xFFFFFFFF; } while(0)
  |  |  ------------------
  |  |  |  |   39|  11.4k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (167:54): [Folded - Ignored]
  |  |  ------------------
  ------------------
   43|  11.4k|   LOAD32L(st->input[7], key + 12);
  ------------------
  |  |  167|  11.4k|  do { XMEMCPY(&(x), y, 4); x &= 0xFFFFFFFF; } while(0)
  |  |  ------------------
  |  |  |  |   39|  11.4k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (167:54): [Folded - Ignored]
  |  |  ------------------
  ------------------
   44|  11.4k|   if (keylen == 32) { /* 256bit */
  ------------------
  |  Branch (44:8): [True: 11.4k, False: 0]
  ------------------
   45|  11.4k|      key += 16;
   46|  11.4k|      constants = sigma;
   47|  11.4k|   } else { /* 128bit */
   48|      0|      constants = tau;
   49|      0|   }
   50|  11.4k|   LOAD32L(st->input[8],  key + 0);
  ------------------
  |  |  167|  11.4k|  do { XMEMCPY(&(x), y, 4); x &= 0xFFFFFFFF; } while(0)
  |  |  ------------------
  |  |  |  |   39|  11.4k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (167:54): [Folded - Ignored]
  |  |  ------------------
  ------------------
   51|  11.4k|   LOAD32L(st->input[9],  key + 4);
  ------------------
  |  |  167|  11.4k|  do { XMEMCPY(&(x), y, 4); x &= 0xFFFFFFFF; } while(0)
  |  |  ------------------
  |  |  |  |   39|  11.4k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (167:54): [Folded - Ignored]
  |  |  ------------------
  ------------------
   52|  11.4k|   LOAD32L(st->input[10], key + 8);
  ------------------
  |  |  167|  11.4k|  do { XMEMCPY(&(x), y, 4); x &= 0xFFFFFFFF; } while(0)
  |  |  ------------------
  |  |  |  |   39|  11.4k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (167:54): [Folded - Ignored]
  |  |  ------------------
  ------------------
   53|  11.4k|   LOAD32L(st->input[11], key + 12);
  ------------------
  |  |  167|  11.4k|  do { XMEMCPY(&(x), y, 4); x &= 0xFFFFFFFF; } while(0)
  |  |  ------------------
  |  |  |  |   39|  11.4k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (167:54): [Folded - Ignored]
  |  |  ------------------
  ------------------
   54|  11.4k|   LOAD32L(st->input[0],  constants + 0);
  ------------------
  |  |  167|  11.4k|  do { XMEMCPY(&(x), y, 4); x &= 0xFFFFFFFF; } while(0)
  |  |  ------------------
  |  |  |  |   39|  11.4k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (167:54): [Folded - Ignored]
  |  |  ------------------
  ------------------
   55|  11.4k|   LOAD32L(st->input[1],  constants + 4);
  ------------------
  |  |  167|  11.4k|  do { XMEMCPY(&(x), y, 4); x &= 0xFFFFFFFF; } while(0)
  |  |  ------------------
  |  |  |  |   39|  11.4k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (167:54): [Folded - Ignored]
  |  |  ------------------
  ------------------
   56|  11.4k|   LOAD32L(st->input[2],  constants + 8);
  ------------------
  |  |  167|  11.4k|  do { XMEMCPY(&(x), y, 4); x &= 0xFFFFFFFF; } while(0)
  |  |  ------------------
  |  |  |  |   39|  11.4k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (167:54): [Folded - Ignored]
  |  |  ------------------
  ------------------
   57|  11.4k|   LOAD32L(st->input[3],  constants + 12);
  ------------------
  |  |  167|  11.4k|  do { XMEMCPY(&(x), y, 4); x &= 0xFFFFFFFF; } while(0)
  |  |  ------------------
  |  |  |  |   39|  11.4k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (167:54): [Folded - Ignored]
  |  |  ------------------
  ------------------
   58|  11.4k|   st->rounds = rounds; /* e.g. 20 for chacha20 */
   59|  11.4k|   st->ivlen = 0; /* will be set later by chacha_ivctr(32|64) */
   60|  11.4k|   return CRYPT_OK;
   61|  11.4k|}

mp_add:
    8|      3|{
    9|      3|   mp_sign sa, sb;
   10|      3|   mp_err err;
   11|       |
   12|       |   /* get sign of both inputs */
   13|      3|   sa = a->sign;
   14|      3|   sb = b->sign;
   15|       |
   16|       |   /* handle two cases, not four */
   17|      3|   if (sa == sb) {
  ------------------
  |  Branch (17:8): [True: 3, False: 0]
  ------------------
   18|       |      /* both positive or both negative */
   19|       |      /* add their magnitudes, copy the sign */
   20|      3|      c->sign = sa;
   21|      3|      err = s_mp_add(a, b, c);
   22|      3|   } else {
   23|       |      /* one positive, the other negative */
   24|       |      /* subtract the one with the greater magnitude from */
   25|       |      /* the one of the lesser magnitude.  The result gets */
   26|       |      /* the sign of the one with the greater magnitude. */
   27|      0|      if (mp_cmp_mag(a, b) == MP_LT) {
  ------------------
  |  |  154|      0|#define MP_LT        -1   /* less than */
  ------------------
  |  Branch (27:11): [True: 0, False: 0]
  ------------------
   28|      0|         c->sign = sb;
   29|      0|         err = s_mp_sub(b, a, c);
   30|      0|      } else {
   31|      0|         c->sign = sa;
   32|      0|         err = s_mp_sub(a, b, c);
   33|      0|      }
   34|      0|   }
   35|      3|   return err;
   36|      3|}

mp_add_d:
    8|    128|{
    9|    128|   mp_err     err;
   10|    128|   int ix, oldused;
   11|    128|   mp_digit *tmpa, *tmpc;
   12|       |
   13|       |   /* grow c as required */
   14|    128|   if (c->alloc < (a->used + 1)) {
  ------------------
  |  Branch (14:8): [True: 0, False: 128]
  ------------------
   15|      0|      if ((err = mp_grow(c, a->used + 1)) != MP_OKAY) {
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (15:11): [True: 0, False: 0]
  ------------------
   16|      0|         return err;
   17|      0|      }
   18|      0|   }
   19|       |
   20|       |   /* if a is negative and |a| >= b, call c = |a| - b */
   21|    128|   if ((a->sign == MP_NEG) && ((a->used > 1) || (a->dp[0] >= b))) {
  ------------------
  |  |  152|    128|#define MP_NEG        1   /* negative */
  ------------------
  |  Branch (21:8): [True: 0, False: 128]
  |  Branch (21:32): [True: 0, False: 0]
  |  Branch (21:49): [True: 0, False: 0]
  ------------------
   22|      0|      mp_int a_ = *a;
   23|       |      /* temporarily fix sign of a */
   24|      0|      a_.sign = MP_ZPOS;
  ------------------
  |  |  151|      0|#define MP_ZPOS       0   /* positive integer */
  ------------------
   25|       |
   26|       |      /* c = |a| - b */
   27|      0|      err = mp_sub_d(&a_, b, c);
   28|       |
   29|       |      /* fix sign  */
   30|      0|      c->sign = MP_NEG;
  ------------------
  |  |  152|      0|#define MP_NEG        1   /* negative */
  ------------------
   31|       |
   32|       |      /* clamp */
   33|      0|      mp_clamp(c);
   34|       |
   35|      0|      return err;
   36|      0|   }
   37|       |
   38|       |   /* old number of used digits in c */
   39|    128|   oldused = c->used;
   40|       |
   41|       |   /* source alias */
   42|    128|   tmpa    = a->dp;
   43|       |
   44|       |   /* destination alias */
   45|    128|   tmpc    = c->dp;
   46|       |
   47|       |   /* if a is positive */
   48|    128|   if (a->sign == MP_ZPOS) {
  ------------------
  |  |  151|    128|#define MP_ZPOS       0   /* positive integer */
  ------------------
  |  Branch (48:8): [True: 128, False: 0]
  ------------------
   49|       |      /* add digits, mu is carry */
   50|    128|      mp_digit mu = b;
   51|    466|      for (ix = 0; ix < a->used; ix++) {
  ------------------
  |  Branch (51:20): [True: 338, False: 128]
  ------------------
   52|    338|         *tmpc   = *tmpa++ + mu;
   53|    338|         mu      = *tmpc >> MP_DIGIT_BIT;
  ------------------
  |  |   82|    338|#   define MP_DIGIT_BIT 60
  ------------------
   54|    338|         *tmpc++ &= MP_MASK;
  ------------------
  |  |  106|    338|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|    338|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
   55|    338|      }
   56|       |      /* set final carry */
   57|    128|      ix++;
   58|    128|      *tmpc++  = mu;
   59|       |
   60|       |      /* setup size */
   61|    128|      c->used = a->used + 1;
   62|    128|   } else {
   63|       |      /* a was negative and |a| < b */
   64|      0|      c->used  = 1;
   65|       |
   66|       |      /* the result is a single digit */
   67|      0|      if (a->used == 1) {
  ------------------
  |  Branch (67:11): [True: 0, False: 0]
  ------------------
   68|      0|         *tmpc++  =  b - a->dp[0];
   69|      0|      } else {
   70|      0|         *tmpc++  =  b;
   71|      0|      }
   72|       |
   73|       |      /* setup count so the clearing of oldused
   74|       |       * can fall through correctly
   75|       |       */
   76|      0|      ix       = 1;
   77|      0|   }
   78|       |
   79|       |   /* sign always positive */
   80|    128|   c->sign = MP_ZPOS;
  ------------------
  |  |  151|    128|#define MP_ZPOS       0   /* positive integer */
  ------------------
   81|       |
   82|       |   /* now zero to oldused */
   83|    128|   MP_ZERO_DIGITS(tmpc, oldused - ix);
  ------------------
  |  |   89|    128|#  define MP_ZERO_DIGITS(mem, digits)                   \
  |  |   90|    128|do {                                                    \
  |  |   91|    128|   int zd_ = (digits);                                  \
  |  |   92|    128|   mp_digit* zm_ = (mem);                               \
  |  |   93|    128|   while (zd_-- > 0) {                                  \
  |  |  ------------------
  |  |  |  Branch (93:11): [True: 0, False: 128]
  |  |  ------------------
  |  |   94|      0|      *zm_++ = 0;                                       \
  |  |   95|      0|   }                                                    \
  |  |   96|    128|} while (0)
  |  |  ------------------
  |  |  |  Branch (96:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
   84|    128|   mp_clamp(c);
   85|       |
   86|    128|   return MP_OKAY;
  ------------------
  |  |  161|    128|#define MP_OKAY       0   /* no error */
  ------------------
   87|    128|}

mp_clamp:
   14|  56.7k|{
   15|       |   /* decrease used while the most significant digit is
   16|       |    * zero.
   17|       |    */
   18|  86.6k|   while ((a->used > 0) && (a->dp[a->used - 1] == 0u)) {
  ------------------
  |  Branch (18:11): [True: 74.1k, False: 12.4k]
  |  Branch (18:28): [True: 29.8k, False: 44.2k]
  ------------------
   19|  29.8k|      --(a->used);
   20|  29.8k|   }
   21|       |
   22|       |   /* reset the sign flag if used == 0 */
   23|  56.7k|   if (a->used == 0) {
  ------------------
  |  Branch (23:8): [True: 12.4k, False: 44.2k]
  ------------------
   24|  12.4k|      a->sign = MP_ZPOS;
  ------------------
  |  |  151|  12.4k|#define MP_ZPOS       0   /* positive integer */
  ------------------
   25|  12.4k|   }
   26|  56.7k|}

mp_clear:
    8|  27.8k|{
    9|       |   /* only do anything if a hasn't been freed previously */
   10|  27.8k|   if (a->dp != NULL) {
  ------------------
  |  Branch (10:8): [True: 21.5k, False: 6.34k]
  ------------------
   11|       |      /* free ram */
   12|  21.5k|      MP_FREE_DIGITS(a->dp, a->alloc);
  ------------------
  |  |   58|  21.5k|#  define MP_FREE_DIGITS(mem, digits)                   \
  |  |   59|  21.5k|do {                                                    \
  |  |   60|  21.5k|   int fd_ = (digits);                                  \
  |  |   61|  21.5k|   void* fm_ = (mem);                                   \
  |  |   62|  21.5k|   if (fm_ != NULL) {                                   \
  |  |  ------------------
  |  |  |  Branch (62:8): [True: 21.5k, False: 0]
  |  |  ------------------
  |  |   63|  21.5k|      size_t fs_ = sizeof (mp_digit) * (size_t)fd_;     \
  |  |   64|  21.5k|      MP_ZERO_BUFFER(fm_, fs_);                         \
  |  |  ------------------
  |  |  |  |   81|  21.5k|#  define MP_ZERO_BUFFER(mem, size)                     \
  |  |  |  |   82|  21.5k|do {                                                    \
  |  |  |  |   83|  21.5k|   size_t zs_ = (size);                                 \
  |  |  |  |   84|  21.5k|   char* zm_ = (char*)(mem);                            \
  |  |  |  |   85|  3.30M|   while (zs_-- > 0u) {                                 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (85:11): [True: 3.28M, False: 21.5k]
  |  |  |  |  ------------------
  |  |  |  |   86|  3.28M|      *zm_++ = '\0';                                    \
  |  |  |  |   87|  3.28M|   }                                                    \
  |  |  |  |   88|  21.5k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (88:10): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   65|  21.5k|      MP_FREE(fm_, fs_);                                \
  |  |  ------------------
  |  |  |  | 1324|  21.5k|#define MP_FREE      m_free_ltm
  |  |  ------------------
  |  |   66|  21.5k|   }                                                    \
  |  |   67|  21.5k|} while (0)
  |  |  ------------------
  |  |  |  Branch (67:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
   13|       |
   14|       |      /* reset members to make debugging easier */
   15|  21.5k|      a->dp    = NULL;
   16|  21.5k|      a->alloc = a->used = 0;
   17|  21.5k|      a->sign  = MP_ZPOS;
  ------------------
  |  |  151|  21.5k|#define MP_ZPOS       0   /* positive integer */
  ------------------
   18|  21.5k|   }
   19|  27.8k|}

mp_clear_multi:
    9|      1|{
   10|      1|   mp_int *next_mp = mp;
   11|      1|   va_list args;
   12|      1|   va_start(args, mp);
   13|      5|   while (next_mp != NULL) {
  ------------------
  |  Branch (13:11): [True: 4, False: 1]
  ------------------
   14|      4|      mp_clear(next_mp);
   15|      4|      next_mp = va_arg(args, mp_int *);
   16|      4|   }
   17|      1|   va_end(args);
   18|      1|}

mp_cmp:
    8|      5|{
    9|       |   /* compare based on sign */
   10|      5|   if (a->sign != b->sign) {
  ------------------
  |  Branch (10:8): [True: 0, False: 5]
  ------------------
   11|      0|      if (a->sign == MP_NEG) {
  ------------------
  |  |  152|      0|#define MP_NEG        1   /* negative */
  ------------------
  |  Branch (11:11): [True: 0, False: 0]
  ------------------
   12|      0|         return MP_LT;
  ------------------
  |  |  154|      0|#define MP_LT        -1   /* less than */
  ------------------
   13|      0|      } else {
   14|      0|         return MP_GT;
  ------------------
  |  |  156|      0|#define MP_GT         1   /* greater than */
  ------------------
   15|      0|      }
   16|      0|   }
   17|       |
   18|       |   /* compare digits */
   19|      5|   if (a->sign == MP_NEG) {
  ------------------
  |  |  152|      5|#define MP_NEG        1   /* negative */
  ------------------
  |  Branch (19:8): [True: 0, False: 5]
  ------------------
   20|       |      /* if negative compare opposite direction */
   21|      0|      return mp_cmp_mag(b, a);
   22|      5|   } else {
   23|      5|      return mp_cmp_mag(a, b);
   24|      5|   }
   25|      5|}

mp_cmp_d:
    8|      4|{
    9|       |   /* compare based on sign */
   10|      4|   if (a->sign == MP_NEG) {
  ------------------
  |  |  152|      4|#define MP_NEG        1   /* negative */
  ------------------
  |  Branch (10:8): [True: 0, False: 4]
  ------------------
   11|      0|      return MP_LT;
  ------------------
  |  |  154|      0|#define MP_LT        -1   /* less than */
  ------------------
   12|      0|   }
   13|       |
   14|       |   /* compare based on magnitude */
   15|      4|   if (a->used > 1) {
  ------------------
  |  Branch (15:8): [True: 4, False: 0]
  ------------------
   16|      4|      return MP_GT;
  ------------------
  |  |  156|      4|#define MP_GT         1   /* greater than */
  ------------------
   17|      4|   }
   18|       |
   19|       |   /* compare the only digit of a to b */
   20|      0|   if (a->dp[0] > b) {
  ------------------
  |  Branch (20:8): [True: 0, False: 0]
  ------------------
   21|      0|      return MP_GT;
  ------------------
  |  |  156|      0|#define MP_GT         1   /* greater than */
  ------------------
   22|      0|   } else if (a->dp[0] < b) {
  ------------------
  |  Branch (22:15): [True: 0, False: 0]
  ------------------
   23|      0|      return MP_LT;
  ------------------
  |  |  154|      0|#define MP_LT        -1   /* less than */
  ------------------
   24|      0|   } else {
   25|      0|      return MP_EQ;
  ------------------
  |  |  155|      0|#define MP_EQ         0   /* equal to */
  ------------------
   26|      0|   }
   27|      0|}

mp_cmp_mag:
    8|     28|{
    9|     28|   int     n;
   10|     28|   const mp_digit *tmpa, *tmpb;
   11|       |
   12|       |   /* compare based on # of non-zero digits */
   13|     28|   if (a->used > b->used) {
  ------------------
  |  Branch (13:8): [True: 2, False: 26]
  ------------------
   14|      2|      return MP_GT;
  ------------------
  |  |  156|      2|#define MP_GT         1   /* greater than */
  ------------------
   15|      2|   }
   16|       |
   17|     26|   if (a->used < b->used) {
  ------------------
  |  Branch (17:8): [True: 0, False: 26]
  ------------------
   18|      0|      return MP_LT;
  ------------------
  |  |  154|      0|#define MP_LT        -1   /* less than */
  ------------------
   19|      0|   }
   20|       |
   21|       |   /* alias for a */
   22|     26|   tmpa = a->dp + (a->used - 1);
   23|       |
   24|       |   /* alias for b */
   25|     26|   tmpb = b->dp + (a->used - 1);
   26|       |
   27|       |   /* compare based on digits  */
   28|     43|   for (n = 0; n < a->used; ++n, --tmpa, --tmpb) {
  ------------------
  |  Branch (28:16): [True: 42, False: 1]
  ------------------
   29|     42|      if (*tmpa > *tmpb) {
  ------------------
  |  Branch (29:11): [True: 11, False: 31]
  ------------------
   30|     11|         return MP_GT;
  ------------------
  |  |  156|     11|#define MP_GT         1   /* greater than */
  ------------------
   31|     11|      }
   32|       |
   33|     31|      if (*tmpa < *tmpb) {
  ------------------
  |  Branch (33:11): [True: 14, False: 17]
  ------------------
   34|     14|         return MP_LT;
  ------------------
  |  |  154|     14|#define MP_LT        -1   /* less than */
  ------------------
   35|     14|      }
   36|     31|   }
   37|      1|   return MP_EQ;
  ------------------
  |  |  155|      1|#define MP_EQ         0   /* equal to */
  ------------------
   38|     26|}

mp_copy:
    8|  37.1k|{
    9|  37.1k|   int n;
   10|  37.1k|   mp_digit *tmpa, *tmpb;
   11|  37.1k|   mp_err err;
   12|       |
   13|       |   /* if dst == src do nothing */
   14|  37.1k|   if (a == b) {
  ------------------
  |  Branch (14:8): [True: 27.8k, False: 9.28k]
  ------------------
   15|  27.8k|      return MP_OKAY;
  ------------------
  |  |  161|  27.8k|#define MP_OKAY       0   /* no error */
  ------------------
   16|  27.8k|   }
   17|       |
   18|       |   /* grow dest */
   19|  9.28k|   if (b->alloc < a->used) {
  ------------------
  |  Branch (19:8): [True: 0, False: 9.28k]
  ------------------
   20|      0|      if ((err = mp_grow(b, a->used)) != MP_OKAY) {
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (20:11): [True: 0, False: 0]
  ------------------
   21|      0|         return err;
   22|      0|      }
   23|      0|   }
   24|       |
   25|       |   /* zero b and copy the parameters over */
   26|       |   /* pointer aliases */
   27|       |
   28|       |   /* source */
   29|  9.28k|   tmpa = a->dp;
   30|       |
   31|       |   /* destination */
   32|  9.28k|   tmpb = b->dp;
   33|       |
   34|       |   /* copy all the digits */
   35|  18.5k|   for (n = 0; n < a->used; n++) {
  ------------------
  |  Branch (35:16): [True: 9.30k, False: 9.28k]
  ------------------
   36|  9.30k|      *tmpb++ = *tmpa++;
   37|  9.30k|   }
   38|       |
   39|       |   /* clear high digits */
   40|  9.28k|   MP_ZERO_DIGITS(tmpb, b->used - n);
  ------------------
  |  |   89|  9.28k|#  define MP_ZERO_DIGITS(mem, digits)                   \
  |  |   90|  9.28k|do {                                                    \
  |  |   91|  9.28k|   int zd_ = (digits);                                  \
  |  |   92|  9.28k|   mp_digit* zm_ = (mem);                               \
  |  |   93|  9.28k|   while (zd_-- > 0) {                                  \
  |  |  ------------------
  |  |  |  Branch (93:11): [True: 0, False: 9.28k]
  |  |  ------------------
  |  |   94|      0|      *zm_++ = 0;                                       \
  |  |   95|      0|   }                                                    \
  |  |   96|  9.28k|} while (0)
  |  |  ------------------
  |  |  |  Branch (96:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
   41|       |
   42|       |   /* copy used count and sign */
   43|  9.28k|   b->used = a->used;
   44|  9.28k|   b->sign = a->sign;
   45|  9.28k|   return MP_OKAY;
  ------------------
  |  |  161|  9.28k|#define MP_OKAY       0   /* no error */
  ------------------
   46|  9.28k|}

mp_count_bits:
    8|  18.5k|{
    9|  18.5k|   int     r;
   10|  18.5k|   mp_digit q;
   11|       |
   12|       |   /* shortcut */
   13|  18.5k|   if (MP_IS_ZERO(a)) {
  ------------------
  |  |  163|  18.5k|#define MP_IS_ZERO(a) ((a)->used == 0)
  |  |  ------------------
  |  |  |  Branch (163:23): [True: 0, False: 18.5k]
  |  |  ------------------
  ------------------
   14|      0|      return 0;
   15|      0|   }
   16|       |
   17|       |   /* get number of digits and add that */
   18|  18.5k|   r = (a->used - 1) * MP_DIGIT_BIT;
  ------------------
  |  |   82|  18.5k|#   define MP_DIGIT_BIT 60
  ------------------
   19|       |
   20|       |   /* take the last digit and count the bits in it */
   21|  18.5k|   q = a->dp[a->used - 1];
   22|   463k|   while (q > 0u) {
  ------------------
  |  Branch (22:11): [True: 445k, False: 18.5k]
  ------------------
   23|   445k|      ++r;
   24|   445k|      q >>= 1u;
   25|   445k|   }
   26|  18.5k|   return r;
   27|  18.5k|}

mp_div:
   87|      2|{
   88|      2|   mp_int  q, x, y, t1, t2;
   89|      2|   int     n, t, i, norm;
   90|      2|   mp_sign neg;
   91|      2|   mp_err  err;
   92|       |
   93|       |   /* is divisor zero ? */
   94|      2|   if (MP_IS_ZERO(b)) {
  ------------------
  |  |  163|      2|#define MP_IS_ZERO(a) ((a)->used == 0)
  |  |  ------------------
  |  |  |  Branch (163:23): [True: 0, False: 2]
  |  |  ------------------
  ------------------
   95|      0|      return MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
   96|      0|   }
   97|       |
   98|       |   /* if a < b then q=0, r = a */
   99|      2|   if (mp_cmp_mag(a, b) == MP_LT) {
  ------------------
  |  |  154|      2|#define MP_LT        -1   /* less than */
  ------------------
  |  Branch (99:8): [True: 0, False: 2]
  ------------------
  100|      0|      if (d != NULL) {
  ------------------
  |  Branch (100:11): [True: 0, False: 0]
  ------------------
  101|      0|         err = mp_copy(a, d);
  102|      0|      } else {
  103|      0|         err = MP_OKAY;
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
  104|      0|      }
  105|      0|      if (c != NULL) {
  ------------------
  |  Branch (105:11): [True: 0, False: 0]
  ------------------
  106|      0|         mp_zero(c);
  107|      0|      }
  108|      0|      return err;
  109|      0|   }
  110|       |
  111|      2|   if ((err = mp_init_size(&q, a->used + 2)) != MP_OKAY) {
  ------------------
  |  |  161|      2|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (111:8): [True: 0, False: 2]
  ------------------
  112|      0|      return err;
  113|      0|   }
  114|      2|   q.used = a->used + 2;
  115|       |
  116|      2|   if ((err = mp_init(&t1)) != MP_OKAY)                           goto LBL_Q;
  ------------------
  |  |  161|      2|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (116:8): [True: 0, False: 2]
  ------------------
  117|       |
  118|      2|   if ((err = mp_init(&t2)) != MP_OKAY)                           goto LBL_T1;
  ------------------
  |  |  161|      2|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (118:8): [True: 0, False: 2]
  ------------------
  119|       |
  120|      2|   if ((err = mp_init_copy(&x, a)) != MP_OKAY)                    goto LBL_T2;
  ------------------
  |  |  161|      2|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (120:8): [True: 0, False: 2]
  ------------------
  121|       |
  122|      2|   if ((err = mp_init_copy(&y, b)) != MP_OKAY)                    goto LBL_X;
  ------------------
  |  |  161|      2|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (122:8): [True: 0, False: 2]
  ------------------
  123|       |
  124|       |   /* fix the sign */
  125|      2|   neg = (a->sign == b->sign) ? MP_ZPOS : MP_NEG;
  ------------------
  |  |  151|      2|#define MP_ZPOS       0   /* positive integer */
  ------------------
                 neg = (a->sign == b->sign) ? MP_ZPOS : MP_NEG;
  ------------------
  |  |  152|      2|#define MP_NEG        1   /* negative */
  ------------------
  |  Branch (125:10): [True: 2, False: 0]
  ------------------
  126|      2|   x.sign = y.sign = MP_ZPOS;
  ------------------
  |  |  151|      2|#define MP_ZPOS       0   /* positive integer */
  ------------------
  127|       |
  128|       |   /* normalize both x and y, ensure that y >= b/2, [b == 2**MP_DIGIT_BIT] */
  129|      2|   norm = mp_count_bits(&y) % MP_DIGIT_BIT;
  ------------------
  |  |   82|      2|#   define MP_DIGIT_BIT 60
  ------------------
  130|      2|   if (norm < (MP_DIGIT_BIT - 1)) {
  ------------------
  |  |   82|      2|#   define MP_DIGIT_BIT 60
  ------------------
  |  Branch (130:8): [True: 2, False: 0]
  ------------------
  131|      2|      norm = (MP_DIGIT_BIT - 1) - norm;
  ------------------
  |  |   82|      2|#   define MP_DIGIT_BIT 60
  ------------------
  132|      2|      if ((err = mp_mul_2d(&x, norm, &x)) != MP_OKAY)             goto LBL_Y;
  ------------------
  |  |  161|      2|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (132:11): [True: 0, False: 2]
  ------------------
  133|      2|      if ((err = mp_mul_2d(&y, norm, &y)) != MP_OKAY)             goto LBL_Y;
  ------------------
  |  |  161|      2|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (133:11): [True: 0, False: 2]
  ------------------
  134|      2|   } else {
  135|      0|      norm = 0;
  136|      0|   }
  137|       |
  138|       |   /* note hac does 0 based, so if used==5 then its 0,1,2,3,4, e.g. use 4 */
  139|      2|   n = x.used - 1;
  140|      2|   t = y.used - 1;
  141|       |
  142|       |   /* while (x >= y*b**n-t) do { q[n-t] += 1; x -= y*b**{n-t} } */
  143|       |   /* y = y*b**{n-t} */
  144|      2|   if ((err = mp_lshd(&y, n - t)) != MP_OKAY)                     goto LBL_Y;
  ------------------
  |  |  161|      2|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (144:8): [True: 0, False: 2]
  ------------------
  145|       |
  146|      2|   while (mp_cmp(&x, &y) != MP_LT) {
  ------------------
  |  |  154|      2|#define MP_LT        -1   /* less than */
  ------------------
  |  Branch (146:11): [True: 0, False: 2]
  ------------------
  147|      0|      ++(q.dp[n - t]);
  148|      0|      if ((err = mp_sub(&x, &y, &x)) != MP_OKAY)                  goto LBL_Y;
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (148:11): [True: 0, False: 0]
  ------------------
  149|      0|   }
  150|       |
  151|       |   /* reset y by shifting it back down */
  152|      2|   mp_rshd(&y, n - t);
  153|       |
  154|       |   /* step 3. for i from n down to (t + 1) */
  155|     12|   for (i = n; i >= (t + 1); i--) {
  ------------------
  |  Branch (155:16): [True: 10, False: 2]
  ------------------
  156|     10|      if (i > x.used) {
  ------------------
  |  Branch (156:11): [True: 0, False: 10]
  ------------------
  157|      0|         continue;
  158|      0|      }
  159|       |
  160|       |      /* step 3.1 if xi == yt then set q{i-t-1} to b-1,
  161|       |       * otherwise set q{i-t-1} to (xi*b + x{i-1})/yt */
  162|     10|      if (x.dp[i] == y.dp[t]) {
  ------------------
  |  Branch (162:11): [True: 0, False: 10]
  ------------------
  163|      0|         q.dp[(i - t) - 1] = ((mp_digit)1 << (mp_digit)MP_DIGIT_BIT) - (mp_digit)1;
  ------------------
  |  |   82|      0|#   define MP_DIGIT_BIT 60
  ------------------
  164|     10|      } else {
  165|     10|         mp_word tmp;
  166|     10|         tmp = (mp_word)x.dp[i] << (mp_word)MP_DIGIT_BIT;
  ------------------
  |  |   82|     10|#   define MP_DIGIT_BIT 60
  ------------------
  167|     10|         tmp |= (mp_word)x.dp[i - 1];
  168|     10|         tmp /= (mp_word)y.dp[t];
  169|     10|         if (tmp > (mp_word)MP_MASK) {
  ------------------
  |  |  106|     10|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|     10|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
  |  Branch (169:14): [True: 0, False: 10]
  ------------------
  170|      0|            tmp = MP_MASK;
  ------------------
  |  |  106|      0|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|      0|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
  171|      0|         }
  172|     10|         q.dp[(i - t) - 1] = (mp_digit)(tmp & (mp_word)MP_MASK);
  ------------------
  |  |  106|     10|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|     10|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
  173|     10|      }
  174|       |
  175|       |      /* while (q{i-t-1} * (yt * b + y{t-1})) >
  176|       |               xi * b**2 + xi-1 * b + xi-2
  177|       |
  178|       |         do q{i-t-1} -= 1;
  179|       |      */
  180|     10|      q.dp[(i - t) - 1] = (q.dp[(i - t) - 1] + 1uL) & (mp_digit)MP_MASK;
  ------------------
  |  |  106|     10|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|     10|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
  181|     10|      do {
  182|     10|         q.dp[(i - t) - 1] = (q.dp[(i - t) - 1] - 1uL) & (mp_digit)MP_MASK;
  ------------------
  |  |  106|     10|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|     10|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
  183|       |
  184|       |         /* find left hand */
  185|     10|         mp_zero(&t1);
  186|     10|         t1.dp[0] = ((t - 1) < 0) ? 0u : y.dp[t - 1];
  ------------------
  |  Branch (186:21): [True: 0, False: 10]
  ------------------
  187|     10|         t1.dp[1] = y.dp[t];
  188|     10|         t1.used = 2;
  189|     10|         if ((err = mp_mul_d(&t1, q.dp[(i - t) - 1], &t1)) != MP_OKAY) goto LBL_Y;
  ------------------
  |  |  161|     10|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (189:14): [True: 0, False: 10]
  ------------------
  190|       |
  191|       |         /* find right hand */
  192|     10|         t2.dp[0] = ((i - 2) < 0) ? 0u : x.dp[i - 2];
  ------------------
  |  Branch (192:21): [True: 0, False: 10]
  ------------------
  193|     10|         t2.dp[1] = x.dp[i - 1]; /* i >= 1 always holds */
  194|     10|         t2.dp[2] = x.dp[i];
  195|     10|         t2.used = 3;
  196|     10|      } while (mp_cmp_mag(&t1, &t2) == MP_GT);
  ------------------
  |  |  156|     10|#define MP_GT         1   /* greater than */
  ------------------
  |  Branch (196:16): [True: 0, False: 10]
  ------------------
  197|       |
  198|       |      /* step 3.3 x = x - q{i-t-1} * y * b**{i-t-1} */
  199|     10|      if ((err = mp_mul_d(&y, q.dp[(i - t) - 1], &t1)) != MP_OKAY) goto LBL_Y;
  ------------------
  |  |  161|     10|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (199:11): [True: 0, False: 10]
  ------------------
  200|       |
  201|     10|      if ((err = mp_lshd(&t1, (i - t) - 1)) != MP_OKAY)           goto LBL_Y;
  ------------------
  |  |  161|     10|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (201:11): [True: 0, False: 10]
  ------------------
  202|       |
  203|     10|      if ((err = mp_sub(&x, &t1, &x)) != MP_OKAY)                 goto LBL_Y;
  ------------------
  |  |  161|     10|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (203:11): [True: 0, False: 10]
  ------------------
  204|       |
  205|       |      /* if x < 0 then { x = x + y*b**{i-t-1}; q{i-t-1} -= 1; } */
  206|     10|      if (x.sign == MP_NEG) {
  ------------------
  |  |  152|     10|#define MP_NEG        1   /* negative */
  ------------------
  |  Branch (206:11): [True: 0, False: 10]
  ------------------
  207|      0|         if ((err = mp_copy(&y, &t1)) != MP_OKAY)                 goto LBL_Y;
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (207:14): [True: 0, False: 0]
  ------------------
  208|      0|         if ((err = mp_lshd(&t1, (i - t) - 1)) != MP_OKAY)        goto LBL_Y;
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (208:14): [True: 0, False: 0]
  ------------------
  209|      0|         if ((err = mp_add(&x, &t1, &x)) != MP_OKAY)              goto LBL_Y;
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (209:14): [True: 0, False: 0]
  ------------------
  210|       |
  211|      0|         q.dp[(i - t) - 1] = (q.dp[(i - t) - 1] - 1uL) & MP_MASK;
  ------------------
  |  |  106|      0|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|      0|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
  212|      0|      }
  213|     10|   }
  214|       |
  215|       |   /* now q is the quotient and x is the remainder
  216|       |    * [which we have to normalize]
  217|       |    */
  218|       |
  219|       |   /* get sign before writing to c */
  220|      2|   x.sign = (x.used == 0) ? MP_ZPOS : a->sign;
  ------------------
  |  |  151|      0|#define MP_ZPOS       0   /* positive integer */
  ------------------
  |  Branch (220:13): [True: 0, False: 2]
  ------------------
  221|       |
  222|      2|   if (c != NULL) {
  ------------------
  |  Branch (222:8): [True: 0, False: 2]
  ------------------
  223|      0|      mp_clamp(&q);
  224|      0|      mp_exch(&q, c);
  225|      0|      c->sign = neg;
  226|      0|   }
  227|       |
  228|      2|   if (d != NULL) {
  ------------------
  |  Branch (228:8): [True: 2, False: 0]
  ------------------
  229|      2|      if ((err = mp_div_2d(&x, norm, &x, NULL)) != MP_OKAY)       goto LBL_Y;
  ------------------
  |  |  161|      2|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (229:11): [True: 0, False: 2]
  ------------------
  230|      2|      mp_exch(&x, d);
  231|      2|   }
  232|       |
  233|      2|   err = MP_OKAY;
  ------------------
  |  |  161|      2|#define MP_OKAY       0   /* no error */
  ------------------
  234|       |
  235|      2|LBL_Y:
  236|      2|   mp_clear(&y);
  237|      2|LBL_X:
  238|      2|   mp_clear(&x);
  239|      2|LBL_T2:
  240|      2|   mp_clear(&t2);
  241|      2|LBL_T1:
  242|      2|   mp_clear(&t1);
  243|      2|LBL_Q:
  244|      2|   mp_clear(&q);
  245|      2|   return err;
  246|      2|}

mp_div_2d:
    8|  27.8k|{
    9|  27.8k|   mp_digit D, r, rr;
   10|  27.8k|   int     x;
   11|  27.8k|   mp_err err;
   12|       |
   13|       |   /* if the shift count is <= 0 then we do no work */
   14|  27.8k|   if (b <= 0) {
  ------------------
  |  Branch (14:8): [True: 0, False: 27.8k]
  ------------------
   15|      0|      err = mp_copy(a, c);
   16|      0|      if (d != NULL) {
  ------------------
  |  Branch (16:11): [True: 0, False: 0]
  ------------------
   17|      0|         mp_zero(d);
   18|      0|      }
   19|      0|      return err;
   20|      0|   }
   21|       |
   22|       |   /* copy */
   23|  27.8k|   if ((err = mp_copy(a, c)) != MP_OKAY) {
  ------------------
  |  |  161|  27.8k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (23:8): [True: 0, False: 27.8k]
  ------------------
   24|      0|      return err;
   25|      0|   }
   26|       |   /* 'a' should not be used after here - it might be the same as d */
   27|       |
   28|       |   /* get the remainder */
   29|  27.8k|   if (d != NULL) {
  ------------------
  |  Branch (29:8): [True: 0, False: 27.8k]
  ------------------
   30|      0|      if ((err = mp_mod_2d(a, b, d)) != MP_OKAY) {
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (30:11): [True: 0, False: 0]
  ------------------
   31|      0|         return err;
   32|      0|      }
   33|      0|   }
   34|       |
   35|       |   /* shift by as many digits in the bit count */
   36|  27.8k|   if (b >= MP_DIGIT_BIT) {
  ------------------
  |  |   82|  27.8k|#   define MP_DIGIT_BIT 60
  ------------------
  |  Branch (36:8): [True: 0, False: 27.8k]
  ------------------
   37|      0|      mp_rshd(c, b / MP_DIGIT_BIT);
  ------------------
  |  |   82|      0|#   define MP_DIGIT_BIT 60
  ------------------
   38|      0|   }
   39|       |
   40|       |   /* shift any bit count < MP_DIGIT_BIT */
   41|  27.8k|   D = (mp_digit)(b % MP_DIGIT_BIT);
  ------------------
  |  |   82|  27.8k|#   define MP_DIGIT_BIT 60
  ------------------
   42|  27.8k|   if (D != 0u) {
  ------------------
  |  Branch (42:8): [True: 27.8k, False: 0]
  ------------------
   43|  27.8k|      mp_digit *tmpc, mask, shift;
   44|       |
   45|       |      /* mask */
   46|  27.8k|      mask = ((mp_digit)1 << D) - 1uL;
   47|       |
   48|       |      /* shift for lsb */
   49|  27.8k|      shift = (mp_digit)MP_DIGIT_BIT - D;
  ------------------
  |  |   82|  27.8k|#   define MP_DIGIT_BIT 60
  ------------------
   50|       |
   51|       |      /* alias */
   52|  27.8k|      tmpc = c->dp + (c->used - 1);
   53|       |
   54|       |      /* carry */
   55|  27.8k|      r = 0;
   56|  55.6k|      for (x = c->used - 1; x >= 0; x--) {
  ------------------
  |  Branch (56:29): [True: 27.8k, False: 27.8k]
  ------------------
   57|       |         /* get the lower  bits of this word in a temp */
   58|  27.8k|         rr = *tmpc & mask;
   59|       |
   60|       |         /* shift the current word and mix in the carry bits from the previous word */
   61|  27.8k|         *tmpc = (*tmpc >> D) | (r << shift);
   62|  27.8k|         --tmpc;
   63|       |
   64|       |         /* set the carry to the carry bits of the current word found above */
   65|  27.8k|         r = rr;
   66|  27.8k|      }
   67|  27.8k|   }
   68|  27.8k|   mp_clamp(c);
   69|  27.8k|   return MP_OKAY;
  ------------------
  |  |  161|  27.8k|#define MP_OKAY       0   /* no error */
  ------------------
   70|  27.8k|}

mp_exch:
   10|      4|{
   11|      4|   mp_int  t;
   12|       |
   13|      4|   t  = *a;
   14|      4|   *a = *b;
   15|      4|   *b = t;
   16|      4|}

mp_from_ubin:
    8|  2.87k|{
    9|  2.87k|   mp_err err;
   10|       |
   11|       |   /* make sure there are at least two digits */
   12|  2.87k|   if (a->alloc < 2) {
  ------------------
  |  Branch (12:8): [True: 0, False: 2.87k]
  ------------------
   13|      0|      if ((err = mp_grow(a, 2)) != MP_OKAY) {
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (13:11): [True: 0, False: 0]
  ------------------
   14|      0|         return err;
   15|      0|      }
   16|      0|   }
   17|       |
   18|       |   /* zero the int */
   19|  2.87k|   mp_zero(a);
   20|       |
   21|       |   /* read the bytes in */
   22|  28.6k|   while (size-- > 0u) {
  ------------------
  |  Branch (22:11): [True: 25.7k, False: 2.87k]
  ------------------
   23|  25.7k|      if ((err = mp_mul_2d(a, 8, a)) != MP_OKAY) {
  ------------------
  |  |  161|  25.7k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (23:11): [True: 0, False: 25.7k]
  ------------------
   24|      0|         return err;
   25|      0|      }
   26|       |
   27|  25.7k|#ifndef MP_8BIT
   28|  25.7k|      a->dp[0] |= *buf++;
   29|  25.7k|      a->used += 1;
   30|       |#else
   31|       |      a->dp[0] = (*buf & MP_MASK);
   32|       |      a->dp[1] |= ((*buf++ >> 7) & 1u);
   33|       |      a->used += 2;
   34|       |#endif
   35|  25.7k|   }
   36|  2.87k|   mp_clamp(a);
   37|  2.87k|   return MP_OKAY;
  ------------------
  |  |  161|  2.87k|#define MP_OKAY       0   /* no error */
  ------------------
   38|  2.87k|}

mp_grow:
    8|  1.54k|{
    9|  1.54k|   int     i;
   10|  1.54k|   mp_digit *tmp;
   11|       |
   12|       |   /* if the alloc size is smaller alloc more ram */
   13|  1.54k|   if (a->alloc < size) {
  ------------------
  |  Branch (13:8): [True: 1.54k, False: 0]
  ------------------
   14|       |      /* reallocate the array a->dp
   15|       |       *
   16|       |       * We store the return in a temporary variable
   17|       |       * in case the operation failed we don't want
   18|       |       * to overwrite the dp member of a.
   19|       |       */
   20|  1.54k|      tmp = (mp_digit *) MP_REALLOC(a->dp,
  ------------------
  |  | 1325|  1.54k|#define MP_REALLOC   m_realloc_ltm
  ------------------
   21|  1.54k|                                    (size_t)a->alloc * sizeof(mp_digit),
   22|  1.54k|                                    (size_t)size * sizeof(mp_digit));
   23|  1.54k|      if (tmp == NULL) {
  ------------------
  |  Branch (23:11): [True: 0, False: 1.54k]
  ------------------
   24|       |         /* reallocation failed but "a" is still valid [can be freed] */
   25|      0|         return MP_MEM;
  ------------------
  |  |  163|      0|#define MP_MEM        -2  /* out of mem */
  ------------------
   26|      0|      }
   27|       |
   28|       |      /* reallocation succeeded so set a->dp */
   29|  1.54k|      a->dp = tmp;
   30|       |
   31|       |      /* zero excess digits */
   32|  1.54k|      i        = a->alloc;
   33|  1.54k|      a->alloc = size;
   34|  1.54k|      MP_ZERO_DIGITS(a->dp + i, a->alloc - i);
  ------------------
  |  |   89|  1.54k|#  define MP_ZERO_DIGITS(mem, digits)                   \
  |  |   90|  1.54k|do {                                                    \
  |  |   91|  1.54k|   int zd_ = (digits);                                  \
  |  |   92|  1.54k|   mp_digit* zm_ = (mem);                               \
  |  |   93|  3.09k|   while (zd_-- > 0) {                                  \
  |  |  ------------------
  |  |  |  Branch (93:11): [True: 1.55k, False: 1.54k]
  |  |  ------------------
  |  |   94|  1.55k|      *zm_++ = 0;                                       \
  |  |   95|  1.55k|   }                                                    \
  |  |   96|  1.54k|} while (0)
  |  |  ------------------
  |  |  |  Branch (96:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
   35|  1.54k|   }
   36|  1.54k|   return MP_OKAY;
  ------------------
  |  |  161|  1.54k|#define MP_OKAY       0   /* no error */
  ------------------
   37|  1.54k|}

mp_init:
    8|  12.2k|{
    9|       |   /* allocate memory required and clear it */
   10|  12.2k|   a->dp = (mp_digit *) MP_CALLOC((size_t)MP_PREC, sizeof(mp_digit));
  ------------------
  |  | 1326|  12.2k|#define MP_CALLOC    m_calloc
  ------------------
                 a->dp = (mp_digit *) MP_CALLOC((size_t)MP_PREC, sizeof(mp_digit));
  ------------------
  |  |  177|  12.2k|#   define MP_PREC PRIVATE_MP_PREC
  |  |  ------------------
  |  |  |  |  193|  12.2k|#      define PRIVATE_MP_PREC 32        /* default digits of precision */
  |  |  ------------------
  ------------------
   11|  12.2k|   if (a->dp == NULL) {
  ------------------
  |  Branch (11:8): [True: 0, False: 12.2k]
  ------------------
   12|      0|      return MP_MEM;
  ------------------
  |  |  163|      0|#define MP_MEM        -2  /* out of mem */
  ------------------
   13|      0|   }
   14|       |
   15|       |   /* set the used to zero, allocated digits to the default precision
   16|       |    * and sign to positive */
   17|  12.2k|   a->used  = 0;
   18|  12.2k|   a->alloc = MP_PREC;
  ------------------
  |  |  177|  12.2k|#   define MP_PREC PRIVATE_MP_PREC
  |  |  ------------------
  |  |  |  |  193|  12.2k|#      define PRIVATE_MP_PREC 32        /* default digits of precision */
  |  |  ------------------
  ------------------
   19|  12.2k|   a->sign  = MP_ZPOS;
  ------------------
  |  |  151|  12.2k|#define MP_ZPOS       0   /* positive integer */
  ------------------
   20|       |
   21|  12.2k|   return MP_OKAY;
  ------------------
  |  |  161|  12.2k|#define MP_OKAY       0   /* no error */
  ------------------
   22|  12.2k|}

mp_init_copy:
    8|  9.28k|{
    9|  9.28k|   mp_err     err;
   10|       |
   11|  9.28k|   if ((err = mp_init_size(a, b->used)) != MP_OKAY) {
  ------------------
  |  |  161|  9.28k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (11:8): [True: 0, False: 9.28k]
  ------------------
   12|      0|      return err;
   13|      0|   }
   14|       |
   15|  9.28k|   if ((err = mp_copy(b, a)) != MP_OKAY) {
  ------------------
  |  |  161|  9.28k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (15:8): [True: 0, False: 9.28k]
  ------------------
   16|      0|      mp_clear(a);
   17|      0|   }
   18|       |
   19|  9.28k|   return err;
   20|  9.28k|}

mp_init_size:
    8|  9.28k|{
    9|  9.28k|   size = MP_MAX(MP_MIN_PREC, size);
  ------------------
  |  |  157|  9.28k|#define MP_MAX(x, y) (((x) > (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (157:23): [True: 9.27k, False: 8]
  |  |  ------------------
  ------------------
   10|       |
   11|       |   /* alloc mem */
   12|  9.28k|   a->dp = (mp_digit *) MP_CALLOC((size_t)size, sizeof(mp_digit));
  ------------------
  |  | 1326|  9.28k|#define MP_CALLOC    m_calloc
  ------------------
   13|  9.28k|   if (a->dp == NULL) {
  ------------------
  |  Branch (13:8): [True: 0, False: 9.28k]
  ------------------
   14|      0|      return MP_MEM;
  ------------------
  |  |  163|      0|#define MP_MEM        -2  /* out of mem */
  ------------------
   15|      0|   }
   16|       |
   17|       |   /* set the members */
   18|  9.28k|   a->used  = 0;
   19|  9.28k|   a->alloc = size;
   20|  9.28k|   a->sign  = MP_ZPOS;
  ------------------
  |  |  151|  9.28k|#define MP_ZPOS       0   /* positive integer */
  ------------------
   21|       |
   22|  9.28k|   return MP_OKAY;
  ------------------
  |  |  161|  9.28k|#define MP_OKAY       0   /* no error */
  ------------------
   23|  9.28k|}

mp_lshd:
    8|     12|{
    9|     12|   int x;
   10|     12|   mp_err err;
   11|     12|   mp_digit *top, *bottom;
   12|       |
   13|       |   /* if its less than zero return */
   14|     12|   if (b <= 0) {
  ------------------
  |  Branch (14:8): [True: 2, False: 10]
  ------------------
   15|      2|      return MP_OKAY;
  ------------------
  |  |  161|      2|#define MP_OKAY       0   /* no error */
  ------------------
   16|      2|   }
   17|       |   /* no need to shift 0 around */
   18|     10|   if (MP_IS_ZERO(a)) {
  ------------------
  |  |  163|     10|#define MP_IS_ZERO(a) ((a)->used == 0)
  |  |  ------------------
  |  |  |  Branch (163:23): [True: 0, False: 10]
  |  |  ------------------
  ------------------
   19|      0|      return MP_OKAY;
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
   20|      0|   }
   21|       |
   22|       |   /* grow to fit the new digits */
   23|     10|   if (a->alloc < (a->used + b)) {
  ------------------
  |  Branch (23:8): [True: 2, False: 8]
  ------------------
   24|      2|      if ((err = mp_grow(a, a->used + b)) != MP_OKAY) {
  ------------------
  |  |  161|      2|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (24:11): [True: 0, False: 2]
  ------------------
   25|      0|         return err;
   26|      0|      }
   27|      2|   }
   28|       |
   29|       |   /* increment the used by the shift amount then copy upwards */
   30|     10|   a->used += b;
   31|       |
   32|       |   /* top */
   33|     10|   top = a->dp + a->used - 1;
   34|       |
   35|       |   /* base */
   36|     10|   bottom = (a->dp + a->used - 1) - b;
   37|       |
   38|       |   /* much like mp_rshd this is implemented using a sliding window
   39|       |    * except the window goes the otherway around.  Copying from
   40|       |    * the bottom to the top.  see bn_mp_rshd.c for more info.
   41|       |    */
   42|     68|   for (x = a->used - 1; x >= b; x--) {
  ------------------
  |  Branch (42:26): [True: 58, False: 10]
  ------------------
   43|     58|      *top-- = *bottom--;
   44|     58|   }
   45|       |
   46|       |   /* zero the lower digits */
   47|     10|   MP_ZERO_DIGITS(a->dp, b);
  ------------------
  |  |   89|     10|#  define MP_ZERO_DIGITS(mem, digits)                   \
  |  |   90|     10|do {                                                    \
  |  |   91|     10|   int zd_ = (digits);                                  \
  |  |   92|     10|   mp_digit* zm_ = (mem);                               \
  |  |   93|     40|   while (zd_-- > 0) {                                  \
  |  |  ------------------
  |  |  |  Branch (93:11): [True: 30, False: 10]
  |  |  ------------------
  |  |   94|     30|      *zm_++ = 0;                                       \
  |  |   95|     30|   }                                                    \
  |  |   96|     10|} while (0)
  |  |  ------------------
  |  |  |  Branch (96:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
   48|       |
   49|     10|   return MP_OKAY;
  ------------------
  |  |  161|     10|#define MP_OKAY       0   /* no error */
  ------------------
   50|     10|}

mp_mod:
    8|      2|{
    9|      2|   mp_int  t;
   10|      2|   mp_err  err;
   11|       |
   12|      2|   if ((err = mp_init_size(&t, b->used)) != MP_OKAY) {
  ------------------
  |  |  161|      2|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (12:8): [True: 0, False: 2]
  ------------------
   13|      0|      return err;
   14|      0|   }
   15|       |
   16|      2|   if ((err = mp_div(a, b, NULL, &t)) != MP_OKAY) {
  ------------------
  |  |  161|      2|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (16:8): [True: 0, False: 2]
  ------------------
   17|      0|      goto LBL_ERR;
   18|      0|   }
   19|       |
   20|      2|   if (MP_IS_ZERO(&t) || (t.sign == b->sign)) {
  ------------------
  |  |  163|      4|#define MP_IS_ZERO(a) ((a)->used == 0)
  |  |  ------------------
  |  |  |  Branch (163:23): [True: 0, False: 2]
  |  |  ------------------
  ------------------
  |  Branch (20:26): [True: 2, False: 0]
  ------------------
   21|      2|      err = MP_OKAY;
  ------------------
  |  |  161|      2|#define MP_OKAY       0   /* no error */
  ------------------
   22|      2|      mp_exch(&t, c);
   23|      2|   } else {
   24|      0|      err = mp_add(b, &t, c);
   25|      0|   }
   26|       |
   27|      2|LBL_ERR:
   28|      2|   mp_clear(&t);
   29|      2|   return err;
   30|      2|}

mp_mul:
    8|      1|{
    9|      1|   mp_err err;
   10|      1|   int min_len = MP_MIN(a->used, b->used),
  ------------------
  |  |  156|      1|#define MP_MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (156:23): [True: 0, False: 1]
  |  |  ------------------
  ------------------
   11|      1|       max_len = MP_MAX(a->used, b->used),
  ------------------
  |  |  157|      1|#define MP_MAX(x, y) (((x) > (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (157:23): [True: 0, False: 1]
  |  |  ------------------
  ------------------
   12|      1|       digs = a->used + b->used + 1;
   13|      1|   mp_sign neg = (a->sign == b->sign) ? MP_ZPOS : MP_NEG;
  ------------------
  |  |  151|      1|#define MP_ZPOS       0   /* positive integer */
  ------------------
                 mp_sign neg = (a->sign == b->sign) ? MP_ZPOS : MP_NEG;
  ------------------
  |  |  152|      0|#define MP_NEG        1   /* negative */
  ------------------
  |  Branch (13:18): [True: 1, False: 0]
  ------------------
   14|       |
   15|      1|   if (MP_HAS(S_MP_BALANCE_MUL) &&
  ------------------
  |  |  150|      2|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|      1|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|      1|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [Folded - Ignored]
  |  |  ------------------
  ------------------
   16|       |       /* Check sizes. The smaller one needs to be larger than the Karatsuba cut-off.
   17|       |        * The bigger one needs to be at least about one MP_KARATSUBA_MUL_CUTOFF bigger
   18|       |        * to make some sense, but it depends on architecture, OS, position of the
   19|       |        * stars... so YMMV.
   20|       |        * Using it to cut the input into slices small enough for fast_s_mp_mul_digs
   21|       |        * was actually slower on the author's machine, but YMMV.
   22|       |        */
   23|      1|       (min_len >= MP_KARATSUBA_MUL_CUTOFF) &&
  ------------------
  |  |  121|      1|#  define MP_KARATSUBA_MUL_CUTOFF KARATSUBA_MUL_CUTOFF
  ------------------
  |  Branch (23:8): [True: 0, False: 1]
  ------------------
   24|      1|       ((max_len / 2) >= MP_KARATSUBA_MUL_CUTOFF) &&
  ------------------
  |  |  121|      0|#  define MP_KARATSUBA_MUL_CUTOFF KARATSUBA_MUL_CUTOFF
  ------------------
  |  Branch (24:8): [True: 0, False: 0]
  ------------------
   25|       |       /* Not much effect was observed below a ratio of 1:2, but again: YMMV. */
   26|      1|       (max_len >= (2 * min_len))) {
  ------------------
  |  Branch (26:8): [True: 0, False: 0]
  ------------------
   27|      0|      err = s_mp_balance_mul(a,b,c);
   28|      1|   } else if (MP_HAS(S_MP_TOOM_MUL) &&
  ------------------
  |  |  150|      2|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|      1|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|      1|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [Folded - Ignored]
  |  |  ------------------
  ------------------
   29|      1|              (min_len >= MP_TOOM_MUL_CUTOFF)) {
  ------------------
  |  |  123|      0|#  define MP_TOOM_MUL_CUTOFF      TOOM_MUL_CUTOFF
  ------------------
  |  Branch (29:15): [True: 0, False: 0]
  ------------------
   30|      0|      err = s_mp_toom_mul(a, b, c);
   31|      1|   } else if (MP_HAS(S_MP_KARATSUBA_MUL) &&
  ------------------
  |  |  150|      2|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|      1|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|      1|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [Folded - Ignored]
  |  |  ------------------
  ------------------
   32|      1|              (min_len >= MP_KARATSUBA_MUL_CUTOFF)) {
  ------------------
  |  |  121|      0|#  define MP_KARATSUBA_MUL_CUTOFF KARATSUBA_MUL_CUTOFF
  ------------------
  |  Branch (32:15): [True: 0, False: 0]
  ------------------
   33|      0|      err = s_mp_karatsuba_mul(a, b, c);
   34|      1|   } else if (MP_HAS(S_MP_MUL_DIGS_FAST) &&
  ------------------
  |  |  150|      2|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|      1|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|      1|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [Folded - Ignored]
  |  |  ------------------
  ------------------
   35|       |              /* can we use the fast multiplier?
   36|       |               *
   37|       |               * The fast multiplier can be used if the output will
   38|       |               * have less than MP_WARRAY digits and the number of
   39|       |               * digits won't affect carry propagation
   40|       |               */
   41|      1|              (digs < MP_WARRAY) &&
  ------------------
  |  |  172|      1|#define MP_WARRAY PRIVATE_MP_WARRAY
  |  |  ------------------
  |  |  |  |  203|      1|#define PRIVATE_MP_WARRAY (int)(1uLL << (((CHAR_BIT * sizeof(private_mp_word)) - (2 * MP_DIGIT_BIT)) + 1))
  |  |  |  |  ------------------
  |  |  |  |  |  |   82|      1|#   define MP_DIGIT_BIT 60
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (41:15): [True: 1, False: 0]
  ------------------
   42|      1|              (min_len <= MP_MAXFAST)) {
  ------------------
  |  |  168|      1|#define MP_MAXFAST              (int)(1uL << (MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT)))
  |  |  ------------------
  |  |  |  |  167|      1|#define MP_SIZEOF_BITS(type)    ((size_t)CHAR_BIT * sizeof(type))
  |  |  ------------------
  |  |               #define MP_MAXFAST              (int)(1uL << (MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT)))
  |  |  ------------------
  |  |  |  |   82|      1|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
  |  Branch (42:15): [True: 1, False: 0]
  ------------------
   43|      1|      err = s_mp_mul_digs_fast(a, b, c, digs);
   44|      1|   } else if (MP_HAS(S_MP_MUL_DIGS)) {
  ------------------
  |  |  150|      0|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|      0|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|      0|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [Folded - Ignored]
  |  |  ------------------
  ------------------
   45|      0|      err = s_mp_mul_digs(a, b, c, digs);
   46|      0|   } else {
   47|      0|      err = MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
   48|      0|   }
   49|      1|   c->sign = (c->used > 0) ? neg : MP_ZPOS;
  ------------------
  |  |  151|      1|#define MP_ZPOS       0   /* positive integer */
  ------------------
  |  Branch (49:14): [True: 1, False: 0]
  ------------------
   50|      1|   return err;
   51|      1|}

mp_mul_2d:
    8|  25.7k|{
    9|  25.7k|   mp_digit d;
   10|  25.7k|   mp_err   err;
   11|       |
   12|       |   /* copy */
   13|  25.7k|   if (a != c) {
  ------------------
  |  Branch (13:8): [True: 0, False: 25.7k]
  ------------------
   14|      0|      if ((err = mp_copy(a, c)) != MP_OKAY) {
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (14:11): [True: 0, False: 0]
  ------------------
   15|      0|         return err;
   16|      0|      }
   17|      0|   }
   18|       |
   19|  25.7k|   if (c->alloc < (c->used + (b / MP_DIGIT_BIT) + 1)) {
  ------------------
  |  |   82|  25.7k|#   define MP_DIGIT_BIT 60
  ------------------
  |  Branch (19:8): [True: 1.54k, False: 24.2k]
  ------------------
   20|  1.54k|      if ((err = mp_grow(c, c->used + (b / MP_DIGIT_BIT) + 1)) != MP_OKAY) {
  ------------------
  |  |   82|  1.54k|#   define MP_DIGIT_BIT 60
  ------------------
                    if ((err = mp_grow(c, c->used + (b / MP_DIGIT_BIT) + 1)) != MP_OKAY) {
  ------------------
  |  |  161|  1.54k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (20:11): [True: 0, False: 1.54k]
  ------------------
   21|      0|         return err;
   22|      0|      }
   23|  1.54k|   }
   24|       |
   25|       |   /* shift by as many digits in the bit count */
   26|  25.7k|   if (b >= MP_DIGIT_BIT) {
  ------------------
  |  |   82|  25.7k|#   define MP_DIGIT_BIT 60
  ------------------
  |  Branch (26:8): [True: 0, False: 25.7k]
  ------------------
   27|      0|      if ((err = mp_lshd(c, b / MP_DIGIT_BIT)) != MP_OKAY) {
  ------------------
  |  |   82|      0|#   define MP_DIGIT_BIT 60
  ------------------
                    if ((err = mp_lshd(c, b / MP_DIGIT_BIT)) != MP_OKAY) {
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (27:11): [True: 0, False: 0]
  ------------------
   28|      0|         return err;
   29|      0|      }
   30|      0|   }
   31|       |
   32|       |   /* shift any bit count < MP_DIGIT_BIT */
   33|  25.7k|   d = (mp_digit)(b % MP_DIGIT_BIT);
  ------------------
  |  |   82|  25.7k|#   define MP_DIGIT_BIT 60
  ------------------
   34|  25.7k|   if (d != 0u) {
  ------------------
  |  Branch (34:8): [True: 25.7k, False: 0]
  ------------------
   35|  25.7k|      mp_digit *tmpc, shift, mask, r, rr;
   36|  25.7k|      int x;
   37|       |
   38|       |      /* bitmask for carries */
   39|  25.7k|      mask = ((mp_digit)1 << d) - (mp_digit)1;
   40|       |
   41|       |      /* shift for msbs */
   42|  25.7k|      shift = (mp_digit)MP_DIGIT_BIT - d;
  ------------------
  |  |   82|  25.7k|#   define MP_DIGIT_BIT 60
  ------------------
   43|       |
   44|       |      /* alias */
   45|  25.7k|      tmpc = c->dp;
   46|       |
   47|       |      /* carry */
   48|  25.7k|      r    = 0;
   49|  1.01M|      for (x = 0; x < c->used; x++) {
  ------------------
  |  Branch (49:19): [True: 989k, False: 25.7k]
  ------------------
   50|       |         /* get the higher bits of the current word */
   51|   989k|         rr = (*tmpc >> shift) & mask;
   52|       |
   53|       |         /* shift the current word and OR in the carry */
   54|   989k|         *tmpc = ((*tmpc << d) | r) & MP_MASK;
  ------------------
  |  |  106|   989k|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|   989k|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
   55|   989k|         ++tmpc;
   56|       |
   57|       |         /* set the carry to the carry bits of the current word */
   58|   989k|         r = rr;
   59|   989k|      }
   60|       |
   61|       |      /* set final carry */
   62|  25.7k|      if (r != 0u) {
  ------------------
  |  Branch (62:11): [True: 2, False: 25.7k]
  ------------------
   63|      2|         c->dp[(c->used)++] = r;
   64|      2|      }
   65|  25.7k|   }
   66|  25.7k|   mp_clamp(c);
   67|  25.7k|   return MP_OKAY;
  ------------------
  |  |  161|  25.7k|#define MP_OKAY       0   /* no error */
  ------------------
   68|  25.7k|}

mp_mul_d:
    8|    148|{
    9|    148|   mp_digit u, *tmpa, *tmpc;
   10|    148|   mp_word  r;
   11|    148|   mp_err   err;
   12|    148|   int      ix, olduse;
   13|       |
   14|       |   /* make sure c is big enough to hold a*b */
   15|    148|   if (c->alloc < (a->used + 1)) {
  ------------------
  |  Branch (15:8): [True: 0, False: 148]
  ------------------
   16|      0|      if ((err = mp_grow(c, a->used + 1)) != MP_OKAY) {
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (16:11): [True: 0, False: 0]
  ------------------
   17|      0|         return err;
   18|      0|      }
   19|      0|   }
   20|       |
   21|       |   /* get the original destinations used count */
   22|    148|   olduse = c->used;
   23|       |
   24|       |   /* set the sign */
   25|    148|   c->sign = a->sign;
   26|       |
   27|       |   /* alias for a->dp [source] */
   28|    148|   tmpa = a->dp;
   29|       |
   30|       |   /* alias for c->dp [dest] */
   31|    148|   tmpc = c->dp;
   32|       |
   33|       |   /* zero carry */
   34|    148|   u = 0;
   35|       |
   36|       |   /* compute columns */
   37|    548|   for (ix = 0; ix < a->used; ix++) {
  ------------------
  |  Branch (37:17): [True: 400, False: 148]
  ------------------
   38|       |      /* compute product and carry sum for this term */
   39|    400|      r       = (mp_word)u + ((mp_word)*tmpa++ * (mp_word)b);
   40|       |
   41|       |      /* mask off higher bits to get a single digit */
   42|    400|      *tmpc++ = (mp_digit)(r & (mp_word)MP_MASK);
  ------------------
  |  |  106|    400|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|    400|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
   43|       |
   44|       |      /* send carry into next iteration */
   45|    400|      u       = (mp_digit)(r >> (mp_word)MP_DIGIT_BIT);
  ------------------
  |  |   82|    400|#   define MP_DIGIT_BIT 60
  ------------------
   46|    400|   }
   47|       |
   48|       |   /* store final carry [if any] and increment ix offset  */
   49|    148|   *tmpc++ = u;
   50|    148|   ++ix;
   51|       |
   52|       |   /* now zero digits above the top */
   53|    148|   MP_ZERO_DIGITS(tmpc, olduse - ix);
  ------------------
  |  |   89|    148|#  define MP_ZERO_DIGITS(mem, digits)                   \
  |  |   90|    148|do {                                                    \
  |  |   91|    148|   int zd_ = (digits);                                  \
  |  |   92|    148|   mp_digit* zm_ = (mem);                               \
  |  |   93|    148|   while (zd_-- > 0) {                                  \
  |  |  ------------------
  |  |  |  Branch (93:11): [True: 0, False: 148]
  |  |  ------------------
  |  |   94|      0|      *zm_++ = 0;                                       \
  |  |   95|      0|   }                                                    \
  |  |   96|    148|} while (0)
  |  |  ------------------
  |  |  |  Branch (96:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
   54|       |
   55|       |   /* set used count */
   56|    148|   c->used = a->used + 1;
   57|    148|   mp_clamp(c);
   58|       |
   59|    148|   return MP_OKAY;
  ------------------
  |  |  161|    148|#define MP_OKAY       0   /* no error */
  ------------------
   60|    148|}

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

mp_read_radix:
   10|      2|{
   11|      2|   mp_err   err;
   12|      2|   int      y;
   13|      2|   mp_sign  neg;
   14|      2|   unsigned pos;
   15|      2|   char     ch;
   16|       |
   17|       |   /* zero the digit bignum */
   18|      2|   mp_zero(a);
   19|       |
   20|       |   /* make sure the radix is ok */
   21|      2|   if ((radix < 2) || (radix > 64)) {
  ------------------
  |  Branch (21:8): [True: 0, False: 2]
  |  Branch (21:23): [True: 0, False: 2]
  ------------------
   22|      0|      return MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
   23|      0|   }
   24|       |
   25|       |   /* if the leading digit is a
   26|       |    * minus set the sign to negative.
   27|       |    */
   28|      2|   if (*str == '-') {
  ------------------
  |  Branch (28:8): [True: 0, False: 2]
  ------------------
   29|      0|      ++str;
   30|      0|      neg = MP_NEG;
  ------------------
  |  |  152|      0|#define MP_NEG        1   /* negative */
  ------------------
   31|      2|   } else {
   32|      2|      neg = MP_ZPOS;
  ------------------
  |  |  151|      2|#define MP_ZPOS       0   /* positive integer */
  ------------------
   33|      2|   }
   34|       |
   35|       |   /* set the integer to the default of zero */
   36|      2|   mp_zero(a);
   37|       |
   38|       |   /* process each digit of the string */
   39|    130|   while (*str != '\0') {
  ------------------
  |  Branch (39:11): [True: 128, False: 2]
  ------------------
   40|       |      /* if the radix <= 36 the conversion is case insensitive
   41|       |       * this allows numbers like 1AB and 1ab to represent the same  value
   42|       |       * [e.g. in hex]
   43|       |       */
   44|    128|      ch = (radix <= 36) ? (char)MP_TOUPPER((int)*str) : *str;
  ------------------
  |  |    6|    128|#define MP_TOUPPER(c) ((((c) >= 'a') && ((c) <= 'z')) ? (((c) + 'A') - 'a') : (c))
  |  |  ------------------
  |  |  |  Branch (6:25): [True: 0, False: 128]
  |  |  |  Branch (6:41): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (44:12): [True: 128, False: 0]
  ------------------
   45|    128|      pos = (unsigned)(ch - '(');
   46|    128|      if (mp_s_rmap_reverse_sz < pos) {
  ------------------
  |  Branch (46:11): [True: 0, False: 128]
  ------------------
   47|      0|         break;
   48|      0|      }
   49|    128|      y = (int)mp_s_rmap_reverse[pos];
   50|       |
   51|       |      /* if the char was found in the map
   52|       |       * and is less than the given radix add it
   53|       |       * to the number, otherwise exit the loop.
   54|       |       */
   55|    128|      if ((y == 0xff) || (y >= radix)) {
  ------------------
  |  Branch (55:11): [True: 0, False: 128]
  |  Branch (55:26): [True: 0, False: 128]
  ------------------
   56|      0|         break;
   57|      0|      }
   58|    128|      if ((err = mp_mul_d(a, (mp_digit)radix, a)) != MP_OKAY) {
  ------------------
  |  |  161|    128|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (58:11): [True: 0, False: 128]
  ------------------
   59|      0|         return err;
   60|      0|      }
   61|    128|      if ((err = mp_add_d(a, (mp_digit)y, a)) != MP_OKAY) {
  ------------------
  |  |  161|    128|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (61:11): [True: 0, False: 128]
  ------------------
   62|      0|         return err;
   63|      0|      }
   64|    128|      ++str;
   65|    128|   }
   66|       |
   67|       |   /* if an illegal character was found, fail. */
   68|      2|   if (!((*str == '\0') || (*str == '\r') || (*str == '\n'))) {
  ------------------
  |  Branch (68:10): [True: 2, False: 0]
  |  Branch (68:28): [True: 0, False: 0]
  |  Branch (68:46): [True: 0, False: 0]
  ------------------
   69|      0|      mp_zero(a);
   70|      0|      return MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
   71|      0|   }
   72|       |
   73|       |   /* set the sign only if a != 0 */
   74|      2|   if (!MP_IS_ZERO(a)) {
  ------------------
  |  |  163|      2|#define MP_IS_ZERO(a) ((a)->used == 0)
  ------------------
  |  Branch (74:8): [True: 2, False: 0]
  ------------------
   75|      2|      a->sign = neg;
   76|      2|   }
   77|      2|   return MP_OKAY;
  ------------------
  |  |  161|      2|#define MP_OKAY       0   /* no error */
  ------------------
   78|      2|}

mp_rshd:
    8|      2|{
    9|      2|   int     x;
   10|      2|   mp_digit *bottom, *top;
   11|       |
   12|       |   /* if b <= 0 then ignore it */
   13|      2|   if (b <= 0) {
  ------------------
  |  Branch (13:8): [True: 0, False: 2]
  ------------------
   14|      0|      return;
   15|      0|   }
   16|       |
   17|       |   /* if b > used then simply zero it and return */
   18|      2|   if (a->used <= b) {
  ------------------
  |  Branch (18:8): [True: 0, False: 2]
  ------------------
   19|      0|      mp_zero(a);
   20|      0|      return;
   21|      0|   }
   22|       |
   23|       |   /* shift the digits down */
   24|       |
   25|       |   /* bottom */
   26|      2|   bottom = a->dp;
   27|       |
   28|       |   /* top [offset into digits] */
   29|      2|   top = a->dp + b;
   30|       |
   31|       |   /* this is implemented as a sliding window where
   32|       |    * the window is b-digits long and digits from
   33|       |    * the top of the window are copied to the bottom
   34|       |    *
   35|       |    * e.g.
   36|       |
   37|       |    b-2 | b-1 | b0 | b1 | b2 | ... | bb |   ---->
   38|       |                /\                   |      ---->
   39|       |                 \-------------------/      ---->
   40|       |    */
   41|     12|   for (x = 0; x < (a->used - b); x++) {
  ------------------
  |  Branch (41:16): [True: 10, False: 2]
  ------------------
   42|     10|      *bottom++ = *top++;
   43|     10|   }
   44|       |
   45|       |   /* zero the top digits */
   46|      2|   MP_ZERO_DIGITS(bottom, a->used - x);
  ------------------
  |  |   89|      2|#  define MP_ZERO_DIGITS(mem, digits)                   \
  |  |   90|      2|do {                                                    \
  |  |   91|      2|   int zd_ = (digits);                                  \
  |  |   92|      2|   mp_digit* zm_ = (mem);                               \
  |  |   93|     12|   while (zd_-- > 0) {                                  \
  |  |  ------------------
  |  |  |  Branch (93:11): [True: 10, False: 2]
  |  |  ------------------
  |  |   94|     10|      *zm_++ = 0;                                       \
  |  |   95|     10|   }                                                    \
  |  |   96|      2|} while (0)
  |  |  ------------------
  |  |  |  Branch (96:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
   47|       |
   48|       |   /* remove excess digits */
   49|      2|   a->used -= b;
   50|      2|}

mp_set:
    8|      1|{
    9|      1|   a->dp[0] = b & MP_MASK;
  ------------------
  |  |  106|      1|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|      1|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
   10|      1|   a->sign  = MP_ZPOS;
  ------------------
  |  |  151|      1|#define MP_ZPOS       0   /* positive integer */
  ------------------
   11|      1|   a->used  = (a->dp[0] != 0u) ? 1 : 0;
  ------------------
  |  Branch (11:15): [True: 1, False: 0]
  ------------------
   12|      1|   MP_ZERO_DIGITS(a->dp + a->used, a->alloc - a->used);
  ------------------
  |  |   89|      1|#  define MP_ZERO_DIGITS(mem, digits)                   \
  |  |   90|      1|do {                                                    \
  |  |   91|      1|   int zd_ = (digits);                                  \
  |  |   92|      1|   mp_digit* zm_ = (mem);                               \
  |  |   93|     32|   while (zd_-- > 0) {                                  \
  |  |  ------------------
  |  |  |  Branch (93:11): [True: 31, False: 1]
  |  |  ------------------
  |  |   94|     31|      *zm_++ = 0;                                       \
  |  |   95|     31|   }                                                    \
  |  |   96|      1|} while (0)
  |  |  ------------------
  |  |  |  Branch (96:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
   13|      1|}

mp_sqr:
    8|      2|{
    9|      2|   mp_err err;
   10|      2|   if (MP_HAS(S_MP_TOOM_SQR) && /* use Toom-Cook? */
  ------------------
  |  |  150|      4|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|      2|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|      2|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [Folded - Ignored]
  |  |  ------------------
  ------------------
   11|      2|       (a->used >= MP_TOOM_SQR_CUTOFF)) {
  ------------------
  |  |  124|      0|#  define MP_TOOM_SQR_CUTOFF      TOOM_SQR_CUTOFF
  ------------------
  |  Branch (11:8): [True: 0, False: 0]
  ------------------
   12|      0|      err = s_mp_toom_sqr(a, b);
   13|      2|   } else if (MP_HAS(S_MP_KARATSUBA_SQR) &&  /* Karatsuba? */
  ------------------
  |  |  150|      4|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|      2|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|      2|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [Folded - Ignored]
  |  |  ------------------
  ------------------
   14|      2|              (a->used >= MP_KARATSUBA_SQR_CUTOFF)) {
  ------------------
  |  |  122|      0|#  define MP_KARATSUBA_SQR_CUTOFF KARATSUBA_SQR_CUTOFF
  ------------------
  |  Branch (14:15): [True: 0, False: 0]
  ------------------
   15|      0|      err = s_mp_karatsuba_sqr(a, b);
   16|      2|   } else if (MP_HAS(S_MP_SQR_FAST) && /* can we use the fast comba multiplier? */
  ------------------
  |  |  150|      4|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|      2|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|      2|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [Folded - Ignored]
  |  |  ------------------
  ------------------
   17|      2|              (((a->used * 2) + 1) < MP_WARRAY) &&
  ------------------
  |  |  172|      2|#define MP_WARRAY PRIVATE_MP_WARRAY
  |  |  ------------------
  |  |  |  |  203|      2|#define PRIVATE_MP_WARRAY (int)(1uLL << (((CHAR_BIT * sizeof(private_mp_word)) - (2 * MP_DIGIT_BIT)) + 1))
  |  |  |  |  ------------------
  |  |  |  |  |  |   82|      2|#   define MP_DIGIT_BIT 60
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (17:15): [True: 2, False: 0]
  ------------------
   18|      2|              (a->used < (MP_MAXFAST / 2))) {
  ------------------
  |  |  168|      2|#define MP_MAXFAST              (int)(1uL << (MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT)))
  |  |  ------------------
  |  |  |  |  167|      2|#define MP_SIZEOF_BITS(type)    ((size_t)CHAR_BIT * sizeof(type))
  |  |  ------------------
  |  |               #define MP_MAXFAST              (int)(1uL << (MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT)))
  |  |  ------------------
  |  |  |  |   82|      2|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
  |  Branch (18:15): [True: 2, False: 0]
  ------------------
   19|      2|      err = s_mp_sqr_fast(a, b);
   20|      2|   } else if (MP_HAS(S_MP_SQR)) {
  ------------------
  |  |  150|      0|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|      0|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|      0|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [Folded - Ignored]
  |  |  ------------------
  ------------------
   21|      0|      err = s_mp_sqr(a, b);
   22|      0|   } else {
   23|      0|      err = MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
   24|      0|   }
   25|      2|   b->sign = MP_ZPOS;
  ------------------
  |  |  151|      2|#define MP_ZPOS       0   /* positive integer */
  ------------------
   26|      2|   return err;
   27|      2|}

mp_sub:
    8|     11|{
    9|     11|   mp_sign sa = a->sign, sb = b->sign;
   10|     11|   mp_err err;
   11|       |
   12|     11|   if (sa != sb) {
  ------------------
  |  Branch (12:8): [True: 0, False: 11]
  ------------------
   13|       |      /* subtract a negative from a positive, OR */
   14|       |      /* subtract a positive from a negative. */
   15|       |      /* In either case, ADD their magnitudes, */
   16|       |      /* and use the sign of the first number. */
   17|      0|      c->sign = sa;
   18|      0|      err = s_mp_add(a, b, c);
   19|     11|   } else {
   20|       |      /* subtract a positive from a positive, OR */
   21|       |      /* subtract a negative from a negative. */
   22|       |      /* First, take the difference between their */
   23|       |      /* magnitudes, then... */
   24|     11|      if (mp_cmp_mag(a, b) != MP_LT) {
  ------------------
  |  |  154|     11|#define MP_LT        -1   /* less than */
  ------------------
  |  Branch (24:11): [True: 11, False: 0]
  ------------------
   25|       |         /* Copy the sign from the first */
   26|     11|         c->sign = sa;
   27|       |         /* The first has a larger or equal magnitude */
   28|     11|         err = s_mp_sub(a, b, c);
   29|     11|      } else {
   30|       |         /* The result has the *opposite* sign from */
   31|       |         /* the first number. */
   32|      0|         c->sign = (sa == MP_ZPOS) ? MP_NEG : MP_ZPOS;
  ------------------
  |  |  151|      0|#define MP_ZPOS       0   /* positive integer */
  ------------------
                       c->sign = (sa == MP_ZPOS) ? MP_NEG : MP_ZPOS;
  ------------------
  |  |  152|      0|#define MP_NEG        1   /* negative */
  ------------------
                       c->sign = (sa == MP_ZPOS) ? MP_NEG : MP_ZPOS;
  ------------------
  |  |  151|      0|#define MP_ZPOS       0   /* positive integer */
  ------------------
  |  Branch (32:20): [True: 0, False: 0]
  ------------------
   33|       |         /* The second has a larger magnitude */
   34|      0|         err = s_mp_sub(b, a, c);
   35|      0|      }
   36|     11|   }
   37|     11|   return err;
   38|     11|}

mp_to_ubin:
    8|  9.27k|{
    9|  9.27k|   size_t  x, count;
   10|  9.27k|   mp_err  err;
   11|  9.27k|   mp_int  t;
   12|       |
   13|  9.27k|   count = mp_ubin_size(a);
   14|  9.27k|   if (count > maxlen) {
  ------------------
  |  Branch (14:8): [True: 0, False: 9.27k]
  ------------------
   15|      0|      return MP_BUF;
  ------------------
  |  |  167|      0|#define MP_BUF        -5  /* buffer overflow, supplied buffer too small */
  ------------------
   16|      0|   }
   17|       |
   18|  9.27k|   if ((err = mp_init_copy(&t, a)) != MP_OKAY) {
  ------------------
  |  |  161|  9.27k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (18:8): [True: 0, False: 9.27k]
  ------------------
   19|      0|      return err;
   20|      0|   }
   21|       |
   22|  37.1k|   for (x = count; x --> 0u;) {
  ------------------
  |  Branch (22:20): [True: 27.8k, False: 9.27k]
  ------------------
   23|  27.8k|#ifndef MP_8BIT
   24|  27.8k|      buf[x] = (unsigned char)(t.dp[0] & 255u);
   25|       |#else
   26|       |      buf[x] = (unsigned char)(t.dp[0] | ((t.dp[1] & 1u) << 7));
   27|       |#endif
   28|  27.8k|      if ((err = mp_div_2d(&t, 8, &t, NULL)) != MP_OKAY) {
  ------------------
  |  |  161|  27.8k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (28:11): [True: 0, False: 27.8k]
  ------------------
   29|      0|         goto LBL_ERR;
   30|      0|      }
   31|  27.8k|   }
   32|       |
   33|  9.27k|   if (written != NULL) {
  ------------------
  |  Branch (33:8): [True: 9.27k, False: 0]
  ------------------
   34|  9.27k|      *written = count;
   35|  9.27k|   }
   36|       |
   37|  9.27k|LBL_ERR:
   38|  9.27k|   mp_clear(&t);
   39|  9.27k|   return err;
   40|  9.27k|}

mp_ubin_size:
    8|  9.27k|{
    9|  9.27k|   size_t size = (size_t)mp_count_bits(a);
   10|  9.27k|   return (size / 8u) + (((size & 7u) != 0u) ? 1u : 0u);
  ------------------
  |  Branch (10:26): [True: 0, False: 9.27k]
  ------------------
   11|  9.27k|}

mp_zero:
    8|  2.98k|{
    9|  2.98k|   a->sign = MP_ZPOS;
  ------------------
  |  |  151|  2.98k|#define MP_ZPOS       0   /* positive integer */
  ------------------
   10|  2.98k|   a->used = 0;
   11|  2.98k|   MP_ZERO_DIGITS(a->dp, a->alloc);
  ------------------
  |  |   89|  2.98k|#  define MP_ZERO_DIGITS(mem, digits)                   \
  |  |   90|  2.98k|do {                                                    \
  |  |   91|  2.98k|   int zd_ = (digits);                                  \
  |  |   92|  2.98k|   mp_digit* zm_ = (mem);                               \
  |  |   93|  98.5k|   while (zd_-- > 0) {                                  \
  |  |  ------------------
  |  |  |  Branch (93:11): [True: 95.5k, False: 2.98k]
  |  |  ------------------
  |  |   94|  95.5k|      *zm_++ = 0;                                       \
  |  |   95|  95.5k|   }                                                    \
  |  |   96|  2.98k|} while (0)
  |  |  ------------------
  |  |  |  Branch (96:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
   12|  2.98k|}

s_mp_add:
    8|      3|{
    9|      3|   const mp_int *x;
   10|      3|   mp_err err;
   11|      3|   int     olduse, min, max;
   12|       |
   13|       |   /* find sizes, we let |a| <= |b| which means we have to sort
   14|       |    * them.  "x" will point to the input with the most digits
   15|       |    */
   16|      3|   if (a->used > b->used) {
  ------------------
  |  Branch (16:8): [True: 3, False: 0]
  ------------------
   17|      3|      min = b->used;
   18|      3|      max = a->used;
   19|      3|      x = a;
   20|      3|   } else {
   21|      0|      min = a->used;
   22|      0|      max = b->used;
   23|      0|      x = b;
   24|      0|   }
   25|       |
   26|       |   /* init result */
   27|      3|   if (c->alloc < (max + 1)) {
  ------------------
  |  Branch (27:8): [True: 0, False: 3]
  ------------------
   28|      0|      if ((err = mp_grow(c, max + 1)) != MP_OKAY) {
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (28:11): [True: 0, False: 0]
  ------------------
   29|      0|         return err;
   30|      0|      }
   31|      0|   }
   32|       |
   33|       |   /* get old used digit count and set new one */
   34|      3|   olduse = c->used;
   35|      3|   c->used = max + 1;
   36|       |
   37|      3|   {
   38|      3|      mp_digit u, *tmpa, *tmpb, *tmpc;
   39|      3|      int i;
   40|       |
   41|       |      /* alias for digit pointers */
   42|       |
   43|       |      /* first input */
   44|      3|      tmpa = a->dp;
   45|       |
   46|       |      /* second input */
   47|      3|      tmpb = b->dp;
   48|       |
   49|       |      /* destination */
   50|      3|      tmpc = c->dp;
   51|       |
   52|       |      /* zero the carry */
   53|      3|      u = 0;
   54|     18|      for (i = 0; i < min; i++) {
  ------------------
  |  Branch (54:19): [True: 15, False: 3]
  ------------------
   55|       |         /* Compute the sum at one digit, T[i] = A[i] + B[i] + U */
   56|     15|         *tmpc = *tmpa++ + *tmpb++ + u;
   57|       |
   58|       |         /* U = carry bit of T[i] */
   59|     15|         u = *tmpc >> (mp_digit)MP_DIGIT_BIT;
  ------------------
  |  |   82|     15|#   define MP_DIGIT_BIT 60
  ------------------
   60|       |
   61|       |         /* take away carry bit from T[i] */
   62|     15|         *tmpc++ &= MP_MASK;
  ------------------
  |  |  106|     15|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|     15|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
   63|     15|      }
   64|       |
   65|       |      /* now copy higher words if any, that is in A+B
   66|       |       * if A or B has more digits add those in
   67|       |       */
   68|      3|      if (min != max) {
  ------------------
  |  Branch (68:11): [True: 3, False: 0]
  ------------------
   69|     15|         for (; i < max; i++) {
  ------------------
  |  Branch (69:17): [True: 12, False: 3]
  ------------------
   70|       |            /* T[i] = X[i] + U */
   71|     12|            *tmpc = x->dp[i] + u;
   72|       |
   73|       |            /* U = carry bit of T[i] */
   74|     12|            u = *tmpc >> (mp_digit)MP_DIGIT_BIT;
  ------------------
  |  |   82|     12|#   define MP_DIGIT_BIT 60
  ------------------
   75|       |
   76|       |            /* take away carry bit from T[i] */
   77|     12|            *tmpc++ &= MP_MASK;
  ------------------
  |  |  106|     12|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|     12|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
   78|     12|         }
   79|      3|      }
   80|       |
   81|       |      /* add carry */
   82|      3|      *tmpc++ = u;
   83|       |
   84|       |      /* clear digits above oldused */
   85|      3|      MP_ZERO_DIGITS(tmpc, olduse - c->used);
  ------------------
  |  |   89|      3|#  define MP_ZERO_DIGITS(mem, digits)                   \
  |  |   90|      3|do {                                                    \
  |  |   91|      3|   int zd_ = (digits);                                  \
  |  |   92|      3|   mp_digit* zm_ = (mem);                               \
  |  |   93|      3|   while (zd_-- > 0) {                                  \
  |  |  ------------------
  |  |  |  Branch (93:11): [True: 0, False: 3]
  |  |  ------------------
  |  |   94|      0|      *zm_++ = 0;                                       \
  |  |   95|      0|   }                                                    \
  |  |   96|      3|} while (0)
  |  |  ------------------
  |  |  |  Branch (96:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
   86|      3|   }
   87|       |
   88|      3|   mp_clamp(c);
   89|      3|   return MP_OKAY;
  ------------------
  |  |  161|      3|#define MP_OKAY       0   /* no error */
  ------------------
   90|      3|}

s_mp_mul_digs_fast:
   23|      1|{
   24|      1|   int      olduse, pa, ix, iz;
   25|      1|   mp_err   err;
   26|      1|   mp_digit W[MP_WARRAY];
   27|      1|   mp_word  _W;
   28|       |
   29|       |   /* grow the destination as required */
   30|      1|   if (c->alloc < digs) {
  ------------------
  |  Branch (30:8): [True: 1, False: 0]
  ------------------
   31|      1|      if ((err = mp_grow(c, digs)) != MP_OKAY) {
  ------------------
  |  |  161|      1|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (31:11): [True: 0, False: 1]
  ------------------
   32|      0|         return err;
   33|      0|      }
   34|      1|   }
   35|       |
   36|       |   /* number of output digits to produce */
   37|      1|   pa = MP_MIN(digs, a->used + b->used);
  ------------------
  |  |  156|      1|#define MP_MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (156:23): [True: 0, False: 1]
  |  |  ------------------
  ------------------
   38|       |
   39|       |   /* clear the carry */
   40|      1|   _W = 0;
   41|     11|   for (ix = 0; ix < pa; ix++) {
  ------------------
  |  Branch (41:17): [True: 10, False: 1]
  ------------------
   42|     10|      int      tx, ty;
   43|     10|      int      iy;
   44|     10|      mp_digit *tmpx, *tmpy;
   45|       |
   46|       |      /* get offsets into the two bignums */
   47|     10|      ty = MP_MIN(b->used-1, ix);
  ------------------
  |  |  156|     10|#define MP_MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (156:23): [True: 5, False: 5]
  |  |  ------------------
  ------------------
   48|     10|      tx = ix - ty;
   49|       |
   50|       |      /* setup temp aliases */
   51|     10|      tmpx = a->dp + tx;
   52|     10|      tmpy = b->dp + ty;
   53|       |
   54|       |      /* this is the number of times the loop will iterrate, essentially
   55|       |         while (tx++ < a->used && ty-- >= 0) { ... }
   56|       |       */
   57|     10|      iy = MP_MIN(a->used-tx, ty+1);
  ------------------
  |  |  156|     10|#define MP_MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (156:23): [True: 5, False: 5]
  |  |  ------------------
  ------------------
   58|       |
   59|       |      /* execute loop */
   60|     35|      for (iz = 0; iz < iy; ++iz) {
  ------------------
  |  Branch (60:20): [True: 25, False: 10]
  ------------------
   61|     25|         _W += (mp_word)*tmpx++ * (mp_word)*tmpy--;
   62|       |
   63|     25|      }
   64|       |
   65|       |      /* store term */
   66|     10|      W[ix] = (mp_digit)_W & MP_MASK;
  ------------------
  |  |  106|     10|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|     10|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
   67|       |
   68|       |      /* make next carry */
   69|     10|      _W = _W >> (mp_word)MP_DIGIT_BIT;
  ------------------
  |  |   82|     10|#   define MP_DIGIT_BIT 60
  ------------------
   70|     10|   }
   71|       |
   72|       |   /* setup dest */
   73|      1|   olduse  = c->used;
   74|      1|   c->used = pa;
   75|       |
   76|      1|   {
   77|      1|      mp_digit *tmpc;
   78|      1|      tmpc = c->dp;
   79|     11|      for (ix = 0; ix < pa; ix++) {
  ------------------
  |  Branch (79:20): [True: 10, False: 1]
  ------------------
   80|       |         /* now extract the previous digit [below the carry] */
   81|     10|         *tmpc++ = W[ix];
   82|     10|      }
   83|       |
   84|       |      /* clear unused digits [that existed in the old copy of c] */
   85|      1|      MP_ZERO_DIGITS(tmpc, olduse - ix);
  ------------------
  |  |   89|      1|#  define MP_ZERO_DIGITS(mem, digits)                   \
  |  |   90|      1|do {                                                    \
  |  |   91|      1|   int zd_ = (digits);                                  \
  |  |   92|      1|   mp_digit* zm_ = (mem);                               \
  |  |   93|      1|   while (zd_-- > 0) {                                  \
  |  |  ------------------
  |  |  |  Branch (93:11): [True: 0, False: 1]
  |  |  ------------------
  |  |   94|      0|      *zm_++ = 0;                                       \
  |  |   95|      0|   }                                                    \
  |  |   96|      1|} while (0)
  |  |  ------------------
  |  |  |  Branch (96:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
   86|      1|   }
   87|      1|   mp_clamp(c);
   88|      1|   return MP_OKAY;
  ------------------
  |  |  161|      1|#define MP_OKAY       0   /* no error */
  ------------------
   89|      1|}

s_mp_sqr_fast:
   17|      2|{
   18|      2|   int       olduse, pa, ix, iz;
   19|      2|   mp_digit  W[MP_WARRAY], *tmpx;
   20|      2|   mp_word   W1;
   21|      2|   mp_err    err;
   22|       |
   23|       |   /* grow the destination as required */
   24|      2|   pa = a->used + a->used;
   25|      2|   if (b->alloc < pa) {
  ------------------
  |  Branch (25:8): [True: 0, False: 2]
  ------------------
   26|      0|      if ((err = mp_grow(b, pa)) != MP_OKAY) {
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (26:11): [True: 0, False: 0]
  ------------------
   27|      0|         return err;
   28|      0|      }
   29|      0|   }
   30|       |
   31|       |   /* number of output digits to produce */
   32|      2|   W1 = 0;
   33|     22|   for (ix = 0; ix < pa; ix++) {
  ------------------
  |  Branch (33:17): [True: 20, False: 2]
  ------------------
   34|     20|      int      tx, ty, iy;
   35|     20|      mp_word  _W;
   36|     20|      mp_digit *tmpy;
   37|       |
   38|       |      /* clear counter */
   39|     20|      _W = 0;
   40|       |
   41|       |      /* get offsets into the two bignums */
   42|     20|      ty = MP_MIN(a->used-1, ix);
  ------------------
  |  |  156|     20|#define MP_MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (156:23): [True: 10, False: 10]
  |  |  ------------------
  ------------------
   43|     20|      tx = ix - ty;
   44|       |
   45|       |      /* setup temp aliases */
   46|     20|      tmpx = a->dp + tx;
   47|     20|      tmpy = a->dp + ty;
   48|       |
   49|       |      /* this is the number of times the loop will iterrate, essentially
   50|       |         while (tx++ < a->used && ty-- >= 0) { ... }
   51|       |       */
   52|     20|      iy = MP_MIN(a->used-tx, ty+1);
  ------------------
  |  |  156|     20|#define MP_MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (156:23): [True: 10, False: 10]
  |  |  ------------------
  ------------------
   53|       |
   54|       |      /* now for squaring tx can never equal ty
   55|       |       * we halve the distance since they approach at a rate of 2x
   56|       |       * and we have to round because odd cases need to be executed
   57|       |       */
   58|     20|      iy = MP_MIN(iy, ((ty-tx)+1)>>1);
  ------------------
  |  |  156|     20|#define MP_MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (156:23): [True: 0, False: 20]
  |  |  ------------------
  ------------------
   59|       |
   60|       |      /* execute loop */
   61|     40|      for (iz = 0; iz < iy; iz++) {
  ------------------
  |  Branch (61:20): [True: 20, False: 20]
  ------------------
   62|     20|         _W += (mp_word)*tmpx++ * (mp_word)*tmpy--;
   63|     20|      }
   64|       |
   65|       |      /* double the inner product and add carry */
   66|     20|      _W = _W + _W + W1;
   67|       |
   68|       |      /* even columns have the square term in them */
   69|     20|      if (((unsigned)ix & 1u) == 0u) {
  ------------------
  |  Branch (69:11): [True: 10, False: 10]
  ------------------
   70|     10|         _W += (mp_word)a->dp[ix>>1] * (mp_word)a->dp[ix>>1];
   71|     10|      }
   72|       |
   73|       |      /* store it */
   74|     20|      W[ix] = (mp_digit)_W & MP_MASK;
  ------------------
  |  |  106|     20|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|     20|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
   75|       |
   76|       |      /* make next carry */
   77|     20|      W1 = _W >> (mp_word)MP_DIGIT_BIT;
  ------------------
  |  |   82|     20|#   define MP_DIGIT_BIT 60
  ------------------
   78|     20|   }
   79|       |
   80|       |   /* setup dest */
   81|      2|   olduse  = b->used;
   82|      2|   b->used = a->used+a->used;
   83|       |
   84|      2|   {
   85|      2|      mp_digit *tmpb;
   86|      2|      tmpb = b->dp;
   87|     22|      for (ix = 0; ix < pa; ix++) {
  ------------------
  |  Branch (87:20): [True: 20, False: 2]
  ------------------
   88|     20|         *tmpb++ = W[ix] & MP_MASK;
  ------------------
  |  |  106|     20|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|     20|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
   89|     20|      }
   90|       |
   91|       |      /* clear unused digits [that existed in the old copy of c] */
   92|      2|      MP_ZERO_DIGITS(tmpb, olduse - ix);
  ------------------
  |  |   89|      2|#  define MP_ZERO_DIGITS(mem, digits)                   \
  |  |   90|      2|do {                                                    \
  |  |   91|      2|   int zd_ = (digits);                                  \
  |  |   92|      2|   mp_digit* zm_ = (mem);                               \
  |  |   93|      2|   while (zd_-- > 0) {                                  \
  |  |  ------------------
  |  |  |  Branch (93:11): [True: 0, False: 2]
  |  |  ------------------
  |  |   94|      0|      *zm_++ = 0;                                       \
  |  |   95|      0|   }                                                    \
  |  |   96|      2|} while (0)
  |  |  ------------------
  |  |  |  Branch (96:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
   93|      2|   }
   94|      2|   mp_clamp(b);
   95|      2|   return MP_OKAY;
  ------------------
  |  |  161|      2|#define MP_OKAY       0   /* no error */
  ------------------
   96|      2|}

s_mp_sub:
    8|     11|{
    9|     11|   int    olduse, min, max;
   10|     11|   mp_err err;
   11|       |
   12|       |   /* find sizes */
   13|     11|   min = b->used;
   14|     11|   max = a->used;
   15|       |
   16|       |   /* init result */
   17|     11|   if (c->alloc < max) {
  ------------------
  |  Branch (17:8): [True: 0, False: 11]
  ------------------
   18|      0|      if ((err = mp_grow(c, max)) != MP_OKAY) {
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (18:11): [True: 0, False: 0]
  ------------------
   19|      0|         return err;
   20|      0|      }
   21|      0|   }
   22|     11|   olduse = c->used;
   23|     11|   c->used = max;
   24|       |
   25|     11|   {
   26|     11|      mp_digit u, *tmpa, *tmpb, *tmpc;
   27|     11|      int i;
   28|       |
   29|       |      /* alias for digit pointers */
   30|     11|      tmpa = a->dp;
   31|     11|      tmpb = b->dp;
   32|     11|      tmpc = c->dp;
   33|       |
   34|       |      /* set carry to zero */
   35|     11|      u = 0;
   36|    100|      for (i = 0; i < min; i++) {
  ------------------
  |  Branch (36:19): [True: 89, False: 11]
  ------------------
   37|       |         /* T[i] = A[i] - B[i] - U */
   38|     89|         *tmpc = (*tmpa++ - *tmpb++) - u;
   39|       |
   40|       |         /* U = carry bit of T[i]
   41|       |          * Note this saves performing an AND operation since
   42|       |          * if a carry does occur it will propagate all the way to the
   43|       |          * MSB.  As a result a single shift is enough to get the carry
   44|       |          */
   45|     89|         u = *tmpc >> (MP_SIZEOF_BITS(mp_digit) - 1u);
  ------------------
  |  |  167|     89|#define MP_SIZEOF_BITS(type)    ((size_t)CHAR_BIT * sizeof(type))
  ------------------
   46|       |
   47|       |         /* Clear carry from T[i] */
   48|     89|         *tmpc++ &= MP_MASK;
  ------------------
  |  |  106|     89|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|     89|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
   49|     89|      }
   50|       |
   51|       |      /* now copy higher words if any, e.g. if A has more digits than B  */
   52|     11|      for (; i < max; i++) {
  ------------------
  |  Branch (52:14): [True: 0, False: 11]
  ------------------
   53|       |         /* T[i] = A[i] - U */
   54|      0|         *tmpc = *tmpa++ - u;
   55|       |
   56|       |         /* U = carry bit of T[i] */
   57|      0|         u = *tmpc >> (MP_SIZEOF_BITS(mp_digit) - 1u);
  ------------------
  |  |  167|      0|#define MP_SIZEOF_BITS(type)    ((size_t)CHAR_BIT * sizeof(type))
  ------------------
   58|       |
   59|       |         /* Clear carry from T[i] */
   60|      0|         *tmpc++ &= MP_MASK;
  ------------------
  |  |  106|      0|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|      0|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
   61|      0|      }
   62|       |
   63|       |      /* clear digits above used (since we may not have grown result above) */
   64|     11|      MP_ZERO_DIGITS(tmpc, olduse - c->used);
  ------------------
  |  |   89|     11|#  define MP_ZERO_DIGITS(mem, digits)                   \
  |  |   90|     11|do {                                                    \
  |  |   91|     11|   int zd_ = (digits);                                  \
  |  |   92|     11|   mp_digit* zm_ = (mem);                               \
  |  |   93|     11|   while (zd_-- > 0) {                                  \
  |  |  ------------------
  |  |  |  Branch (93:11): [True: 0, False: 11]
  |  |  ------------------
  |  |   94|      0|      *zm_++ = 0;                                       \
  |  |   95|      0|   }                                                    \
  |  |   96|     11|} while (0)
  |  |  ------------------
  |  |  |  Branch (96:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
   65|     11|   }
   66|       |
   67|     11|   mp_clamp(c);
   68|     11|   return MP_OKAY;
  ------------------
  |  |  161|     11|#define MP_OKAY       0   /* no error */
  ------------------
   69|     11|}

mp_set_ul:
  253|  9.27k|    {                                                                                  \
  254|  9.27k|        int i = 0;                                                                     \
  255|  18.5k|        while (b != 0u) {                                                              \
  ------------------
  |  Branch (255:16): [True: 9.27k, False: 9.27k]
  ------------------
  256|  9.27k|            a->dp[i++] = ((mp_digit)b & MP_MASK);                                      \
  ------------------
  |  |  106|  9.27k|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|  9.27k|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
  257|  9.27k|            if (MP_SIZEOF_BITS(type) <= MP_DIGIT_BIT) { break; }                       \
  ------------------
  |  |  167|  9.27k|#define MP_SIZEOF_BITS(type)    ((size_t)CHAR_BIT * sizeof(type))
  ------------------
                          if (MP_SIZEOF_BITS(type) <= MP_DIGIT_BIT) { break; }                       \
  ------------------
  |  |   82|  9.27k|#   define MP_DIGIT_BIT 60
  ------------------
  |  Branch (257:17): [Folded - Ignored]
  ------------------
  258|  9.27k|            b >>= ((MP_SIZEOF_BITS(type) <= MP_DIGIT_BIT) ? 0 : MP_DIGIT_BIT);         \
  ------------------
  |  |  167|  9.27k|#define MP_SIZEOF_BITS(type)    ((size_t)CHAR_BIT * sizeof(type))
  ------------------
                          b >>= ((MP_SIZEOF_BITS(type) <= MP_DIGIT_BIT) ? 0 : MP_DIGIT_BIT);         \
  ------------------
  |  |   82|  9.27k|#   define MP_DIGIT_BIT 60
  ------------------
                          b >>= ((MP_SIZEOF_BITS(type) <= MP_DIGIT_BIT) ? 0 : MP_DIGIT_BIT);         \
  ------------------
  |  |   82|  9.27k|#   define MP_DIGIT_BIT 60
  ------------------
  |  Branch (258:20): [Folded - Ignored]
  ------------------
  259|  9.27k|        }                                                                              \
  260|  9.27k|        a->used = i;                                                                   \
  261|  9.27k|        a->sign = MP_ZPOS;                                                             \
  ------------------
  |  |  151|  9.27k|#define MP_ZPOS       0   /* positive integer */
  ------------------
  262|  9.27k|        MP_ZERO_DIGITS(a->dp + a->used, a->alloc - a->used);                           \
  ------------------
  |  |   89|  9.27k|#  define MP_ZERO_DIGITS(mem, digits)                   \
  |  |   90|  9.27k|do {                                                    \
  |  |   91|  9.27k|   int zd_ = (digits);                                  \
  |  |   92|  9.27k|   mp_digit* zm_ = (mem);                               \
  |  |   93|   296k|   while (zd_-- > 0) {                                  \
  |  |  ------------------
  |  |  |  Branch (93:11): [True: 287k, False: 9.27k]
  |  |  ------------------
  |  |   94|   287k|      *zm_++ = 0;                                       \
  |  |   95|   287k|   }                                                    \
  |  |   96|  9.27k|} while (0)
  |  |  ------------------
  |  |  |  Branch (96:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
  263|  9.27k|    }

m_mp_init:
   31|  2.96k|void m_mp_init(mp_int *mp) {
   32|       |
   33|  2.96k|	if (mp_init(mp) != MP_OKAY) {
  ------------------
  |  |  161|  2.96k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (33:6): [True: 0, False: 2.96k]
  ------------------
   34|      0|		dropbear_exit("Mem alloc error");
   35|      0|	}
   36|  2.96k|}
m_mp_alloc_init_multi:
   56|  9.28k|{
   57|  9.28k|	mp_int** cur_arg = mp;
   58|  9.28k|	va_list args;
   59|       |
   60|  9.28k|	va_start(args, mp);        /* init args to next argument from caller */
   61|  18.5k|	while (cur_arg != NULL) {
  ------------------
  |  Branch (61:9): [True: 9.29k, False: 9.28k]
  ------------------
   62|  9.29k|		*cur_arg = m_malloc(sizeof(mp_int));
   63|  9.29k|		if (mp_init(*cur_arg) != MP_OKAY) {
  ------------------
  |  |  161|  9.29k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (63:7): [True: 0, False: 9.29k]
  ------------------
   64|      0|			dropbear_exit("Mem alloc error");
   65|      0|		}
   66|  9.29k|		cur_arg = va_arg(args, mp_int**);
   67|  9.29k|	}
   68|  9.28k|	va_end(args);
   69|  9.28k|}
hash_process_mp:
   96|  9.27k|				hash_state *hs, const mp_int *mp) {
   97|  9.27k|	buffer * buf;
   98|       |
   99|  9.27k|	buf = buf_new(512 + 20); /* max buffer is a 4096 bit key, 
  100|       |								plus header + some leeway*/
  101|  9.27k|	buf_putmpint(buf, mp);
  102|  9.27k|	hash_desc->process(hs, buf->data, buf->len);
  103|  9.27k|	buf_burn_free(buf);
  104|  9.27k|}

buf_new:
   41|   344k|buffer* buf_new(unsigned int size) {
   42|   344k|	buffer* buf;
   43|   344k|	if (size > BUF_MAX_SIZE) {
  ------------------
  |  |   35|   344k|#define BUF_MAX_SIZE 1000000000
  ------------------
  |  Branch (43:6): [True: 0, False: 344k]
  ------------------
   44|      0|		dropbear_exit("buf->size too big");
   45|      0|	}
   46|       |
   47|   344k|	buf = (buffer*)m_malloc(sizeof(buffer)+size);
   48|   344k|	buf->data = (unsigned char*)buf + sizeof(buffer);
   49|   344k|	buf->size = size;
   50|   344k|	return buf;
   51|   344k|}
buf_free:
   54|   309k|void buf_free(buffer* buf) {
   55|   309k|	m_free(buf);
  ------------------
  |  |   24|   309k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
   56|   309k|}
buf_burn_free:
   59|  32.6k|void buf_burn_free(buffer* buf) {
   60|  32.6k|	m_burn(buf->data, buf->size);
   61|  32.6k|	m_free(buf);
  ------------------
  |  |   24|  32.6k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
   62|  32.6k|}
buf_resize:
   67|  10.4k|buffer* buf_resize(buffer *buf, unsigned int newsize) {
   68|  10.4k|	if (newsize > BUF_MAX_SIZE) {
  ------------------
  |  |   35|  10.4k|#define BUF_MAX_SIZE 1000000000
  ------------------
  |  Branch (68:6): [True: 0, False: 10.4k]
  ------------------
   69|      0|		dropbear_exit("buf->size too big");
   70|      0|	}
   71|       |
   72|  10.4k|	buf = m_realloc(buf, sizeof(buffer)+newsize);
   73|  10.4k|	buf->data = (unsigned char*)buf + sizeof(buffer);
   74|  10.4k|	buf->size = newsize;
   75|  10.4k|	buf->len = MIN(newsize, buf->len);
   76|  10.4k|	buf->pos = MIN(newsize, buf->pos);
   77|  10.4k|	return buf;
   78|  10.4k|}
buf_newcopy:
   82|  11.5k|buffer* buf_newcopy(const buffer* buf) {
   83|       |	
   84|  11.5k|	buffer* ret;
   85|       |
   86|  11.5k|	ret = buf_new(buf->len);
   87|  11.5k|	ret->len = buf->len;
   88|  11.5k|	if (buf->len > 0) {
  ------------------
  |  Branch (88:6): [True: 11.5k, False: 0]
  ------------------
   89|  11.5k|		memcpy(ret->data, buf->data, buf->len);
   90|  11.5k|	}
   91|  11.5k|	return ret;
   92|  11.5k|}
buf_setlen:
   95|   595k|void buf_setlen(buffer* buf, unsigned int len) {
   96|   595k|	if (len > buf->size) {
  ------------------
  |  Branch (96:6): [True: 0, False: 595k]
  ------------------
   97|      0|		dropbear_exit("Bad buf_setlen");
   98|      0|	}
   99|   595k|	buf->len = len;
  100|   595k|	buf->pos = MIN(buf->pos, buf->len);
  101|   595k|}
buf_incrlen:
  104|   924k|void buf_incrlen(buffer* buf, unsigned int incr) {
  105|   924k|	if (incr > BUF_MAX_INCR || buf->len + incr > buf->size) {
  ------------------
  |  |   34|  1.84M|#define BUF_MAX_INCR 1000000000
  ------------------
  |  Branch (105:6): [True: 0, False: 924k]
  |  Branch (105:29): [True: 0, False: 924k]
  ------------------
  106|      0|		dropbear_exit("Bad buf_incrlen");
  107|      0|	}
  108|   924k|	buf->len += incr;
  109|   924k|}
buf_setpos:
  111|  2.57M|void buf_setpos(buffer* buf, unsigned int pos) {
  112|       |
  113|  2.57M|	if (pos > buf->len) {
  ------------------
  |  Branch (113:6): [True: 0, False: 2.57M]
  ------------------
  114|      0|		dropbear_exit("Bad buf_setpos");
  115|      0|	}
  116|  2.57M|	buf->pos = pos;
  117|  2.57M|}
buf_incrwritepos:
  120|  2.27M|void buf_incrwritepos(buffer* buf, unsigned int incr) {
  121|  2.27M|	if (incr > BUF_MAX_INCR || buf->pos + incr > buf->size) {
  ------------------
  |  |   34|  4.54M|#define BUF_MAX_INCR 1000000000
  ------------------
  |  Branch (121:6): [True: 0, False: 2.27M]
  |  Branch (121:29): [True: 0, False: 2.27M]
  ------------------
  122|      0|		dropbear_exit("Bad buf_incrwritepos");
  123|      0|	}
  124|  2.27M|	buf->pos += incr;
  125|  2.27M|	if (buf->pos > buf->len) {
  ------------------
  |  Branch (125:6): [True: 1.64M, False: 625k]
  ------------------
  126|  1.64M|		buf->len = buf->pos;
  127|  1.64M|	}
  128|  2.27M|}
buf_incrpos:
  131|  1.18M|void buf_incrpos(buffer* buf, unsigned int incr) {
  132|  1.18M|	if (incr > BUF_MAX_INCR 
  ------------------
  |  |   34|  2.37M|#define BUF_MAX_INCR 1000000000
  ------------------
  |  Branch (132:6): [True: 2, False: 1.18M]
  ------------------
  133|  1.18M|		|| (buf->pos + incr) > buf->len) {
  ------------------
  |  Branch (133:6): [True: 10, False: 1.18M]
  ------------------
  134|     12|		dropbear_exit("Bad buf_incrpos");
  135|     12|	}
  136|  1.18M|	buf->pos += incr;
  137|  1.18M|}
buf_decrpos:
  140|      4|void buf_decrpos(buffer* buf, unsigned int decr) {
  141|      4|	if (decr > buf->pos) {
  ------------------
  |  Branch (141:6): [True: 0, False: 4]
  ------------------
  142|      0|		dropbear_exit("Bad buf_decrpos");
  143|      0|	}
  144|      4|	buf->pos -= decr;
  145|      4|}
buf_getbyte:
  148|   364k|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|   364k|	if (buf->pos >= buf->len) {
  ------------------
  |  Branch (152:6): [True: 0, False: 364k]
  ------------------
  153|      0|		dropbear_exit("Bad buf_getbyte");
  154|      0|	}
  155|   364k|	return buf->data[buf->pos++];
  156|   364k|}
buf_getbool:
  159|  19.0k|unsigned char buf_getbool(buffer* buf) {
  160|       |
  161|  19.0k|	unsigned char b;
  162|  19.0k|	b = buf_getbyte(buf);
  163|  19.0k|	if (b != 0)
  ------------------
  |  Branch (163:6): [True: 7.88k, False: 11.1k]
  ------------------
  164|  7.88k|		b = 1;
  165|  19.0k|	return b;
  166|  19.0k|}
buf_putbyte:
  169|   703k|void buf_putbyte(buffer* buf, unsigned char val) {
  170|       |
  171|   703k|	if (buf->pos >= buf->len) {
  ------------------
  |  Branch (171:6): [True: 462k, False: 240k]
  ------------------
  172|   462k|		buf_incrlen(buf, 1);
  173|   462k|	}
  174|   703k|	buf->data[buf->pos] = val;
  175|   703k|	buf->pos++;
  176|   703k|}
buf_getptr:
  180|  4.27M|unsigned char* buf_getptr(const buffer* buf, unsigned int len) {
  181|       |
  182|  4.27M|	if (len > BUF_MAX_INCR || buf->pos + len > buf->len) {
  ------------------
  |  |   34|  8.55M|#define BUF_MAX_INCR 1000000000
  ------------------
  |  Branch (182:6): [True: 0, False: 4.27M]
  |  Branch (182:28): [True: 83, False: 4.27M]
  ------------------
  183|     83|		dropbear_exit("Bad buf_getptr");
  184|     83|	}
  185|  4.27M|	return &buf->data[buf->pos];
  186|  4.27M|}
buf_getwriteptr:
  190|  2.55M|unsigned char* buf_getwriteptr(const buffer* buf, unsigned int len) {
  191|       |
  192|  2.55M|	if (len > BUF_MAX_INCR || buf->pos + len > buf->size) {
  ------------------
  |  |   34|  5.11M|#define BUF_MAX_INCR 1000000000
  ------------------
  |  Branch (192:6): [True: 0, False: 2.55M]
  |  Branch (192:28): [True: 0, False: 2.55M]
  ------------------
  193|      0|		dropbear_exit("Bad buf_getwriteptr");
  194|      0|	}
  195|  2.55M|	return &buf->data[buf->pos];
  196|  2.55M|}
buf_getstring:
  201|   105k|char* buf_getstring(buffer* buf, unsigned int *retlen) {
  202|       |
  203|   105k|	unsigned int len;
  204|   105k|	char* ret;
  205|   105k|	void* src = NULL;
  206|   105k|	len = buf_getint(buf);
  207|   105k|	if (len > MAX_STRING_LEN) {
  ------------------
  |  |  228|   105k|#define MAX_STRING_LEN (MAX(MAX_CMD_LEN, 2400)) /* Sun SSH needs 2400 for algos,
  ------------------
  |  Branch (207:6): [True: 24, False: 105k]
  ------------------
  208|     24|		dropbear_exit("String too long");
  209|     24|	}
  210|       |
  211|   105k|	if (retlen != NULL) {
  ------------------
  |  Branch (211:6): [True: 105k, False: 445]
  ------------------
  212|   105k|		*retlen = len;
  213|   105k|	}
  214|   105k|	src = buf_getptr(buf, len);
  215|   105k|	ret = m_malloc(len+1);
  216|   105k|	memcpy(ret, src, len);
  217|   105k|	buf_incrpos(buf, len);
  218|   105k|	ret[len] = '\0';
  219|       |
  220|   105k|	return ret;
  221|   105k|}
buf_getstringbuf:
  246|  6.36k|buffer * buf_getstringbuf(buffer *buf) {
  247|  6.36k|	return buf_getstringbuf_int(buf, 0);
  248|  6.36k|}
buf_eatstring:
  257|  18.9k|void buf_eatstring(buffer *buf) {
  258|       |
  259|  18.9k|	buf_incrpos( buf, buf_getint(buf) );
  260|  18.9k|}
buf_getint:
  263|   223k|unsigned int buf_getint(buffer* buf) {
  264|   223k|	unsigned int ret;
  265|       |
  266|   223k|	LOAD32H(ret, buf_getptr(buf, 4));
  ------------------
  |  |   66|   223k|#define LOAD32H(x, y)                           \
  |  |   67|   223k|do { XMEMCPY (&(x), (y), 4);                    \
  |  |  ------------------
  |  |  |  |   39|   223k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |   68|   223k|      (x) = __builtin_bswap32 ((x)); } while(0)
  |  |  ------------------
  |  |  |  Branch (68:46): [Folded - Ignored]
  |  |  ------------------
  ------------------
  267|   223k|	buf_incrpos(buf, 4);
  268|   223k|	return ret;
  269|   223k|}
buf_putint:
  272|  1.21M|void buf_putint(buffer* buf, int unsigned val) {
  273|       |
  274|  1.21M|	STORE32H(val, buf_getwriteptr(buf, 4));
  ------------------
  |  |   62|  1.21M|#define STORE32H(x, y)                          \
  |  |   63|  1.21M|do { ulong32 __t = __builtin_bswap32 ((x));     \
  |  |   64|  1.21M|      XMEMCPY ((y), &__t, 4); } while(0)
  |  |  ------------------
  |  |  |  |   39|  1.21M|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (64:39): [Folded - Ignored]
  |  |  ------------------
  ------------------
  275|  1.21M|	buf_incrwritepos(buf, 4);
  276|       |
  277|  1.21M|}
buf_putstring:
  280|  60.1k|void buf_putstring(buffer* buf, const char* str, unsigned int len) {
  281|       |	
  282|  60.1k|	buf_putint(buf, len);
  283|  60.1k|	buf_putbytes(buf, (const unsigned char*)str, len);
  284|       |
  285|  60.1k|}
buf_putbytes:
  294|   368k|void buf_putbytes(buffer *buf, const unsigned char *bytes, unsigned int len) {
  295|   368k|	memcpy(buf_getwriteptr(buf, len), bytes, len);
  296|   368k|	buf_incrwritepos(buf, len);
  297|   368k|}
buf_putmpint:
  302|  9.27k|void buf_putmpint(buffer* buf, const mp_int * mp) {
  303|  9.27k|	size_t written;
  304|  9.27k|	unsigned int len, pad = 0;
  305|  9.27k|	TRACE2(("enter buf_putmpint"))
  306|       |
  307|  9.27k|	dropbear_assert(mp != NULL);
  ------------------
  |  |   83|  9.27k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 9.27k]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
  308|       |
  309|  9.27k|	if (mp_isneg(mp)) {
  ------------------
  |  |  295|  9.27k|#define mp_isneg(a)  (((a)->sign != MP_ZPOS) ? MP_YES : MP_NO)
  |  |  ------------------
  |  |  |  |  151|  9.27k|#define MP_ZPOS       0   /* positive integer */
  |  |  ------------------
  |  |               #define mp_isneg(a)  (((a)->sign != MP_ZPOS) ? MP_YES : MP_NO)
  |  |  ------------------
  |  |  |  |  158|      0|#define MP_YES        1
  |  |  ------------------
  |  |               #define mp_isneg(a)  (((a)->sign != MP_ZPOS) ? MP_YES : MP_NO)
  |  |  ------------------
  |  |  |  |  159|  9.27k|#define MP_NO         0
  |  |  ------------------
  |  |  |  Branch (295:22): [True: 0, False: 9.27k]
  |  |  |  Branch (295:23): [True: 0, False: 9.27k]
  |  |  ------------------
  ------------------
  310|      0|		dropbear_exit("negative bignum");
  311|      0|	}
  312|       |
  313|       |	/* zero check */
  314|  9.27k|	if (mp_iszero(mp)) {
  ------------------
  |  |  292|  9.27k|#define mp_iszero(a) (((a)->used == 0) ? MP_YES : MP_NO)
  |  |  ------------------
  |  |  |  |  158|      0|#define MP_YES        1
  |  |  ------------------
  |  |               #define mp_iszero(a) (((a)->used == 0) ? MP_YES : MP_NO)
  |  |  ------------------
  |  |  |  |  159|  9.27k|#define MP_NO         0
  |  |  ------------------
  |  |  |  Branch (292:22): [True: 0, False: 9.27k]
  |  |  |  Branch (292:23): [True: 0, False: 9.27k]
  |  |  ------------------
  ------------------
  315|      0|		len = 0;
  316|  9.27k|	} else {
  317|       |		/* SSH spec requires padding for mpints with the MSB set, this code
  318|       |		 * implements it */
  319|  9.27k|		len = mp_count_bits(mp);
  320|       |		/* if the top bit of MSB is set, we need to pad */
  321|  9.27k|		pad = (len%8 == 0) ? 1 : 0;
  ------------------
  |  Branch (321:9): [True: 9.27k, False: 0]
  ------------------
  322|  9.27k|		len = len / 8 + 1; /* don't worry about rounding, we need it for
  323|       |							  padding anyway when len%8 == 0 */
  324|       |
  325|  9.27k|	}
  326|       |
  327|       |	/* store the length */
  328|  9.27k|	buf_putint(buf, len);
  329|       |	
  330|       |	/* store the actual value */
  331|  9.27k|	if (len > 0) {
  ------------------
  |  Branch (331:6): [True: 9.27k, False: 0]
  ------------------
  332|  9.27k|		if (pad) {
  ------------------
  |  Branch (332:7): [True: 9.27k, False: 0]
  ------------------
  333|  9.27k|			buf_putbyte(buf, 0x00);
  334|  9.27k|		}
  335|  9.27k|		if (mp_to_ubin(mp, buf_getwriteptr(buf, len-pad), len-pad, &written) != MP_OKAY) {
  ------------------
  |  |  161|  9.27k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (335:7): [True: 0, False: 9.27k]
  ------------------
  336|      0|			dropbear_exit("mpint error");
  337|      0|		}
  338|  9.27k|		buf_incrwritepos(buf, written);
  339|  9.27k|	}
  340|       |
  341|  9.27k|	TRACE2(("leave buf_putmpint"))
  342|  9.27k|}
buf_getmpint:
  347|  2.97k|int buf_getmpint(buffer* buf, mp_int* mp) {
  348|       |
  349|  2.97k|	unsigned int len;
  350|  2.97k|	len = buf_getint(buf);
  351|       |	
  352|  2.97k|	if (len == 0) {
  ------------------
  |  Branch (352:6): [True: 98, False: 2.87k]
  ------------------
  353|     98|		mp_zero(mp);
  354|     98|		return DROPBEAR_SUCCESS;
  ------------------
  |  |  102|     98|#define DROPBEAR_SUCCESS 0
  ------------------
  355|     98|	}
  356|       |
  357|  2.87k|	if (len > BUF_MAX_MPINT) {
  ------------------
  |  |   38|  2.87k|#define BUF_MAX_MPINT (8240 / 8)
  ------------------
  |  Branch (357:6): [True: 1, False: 2.87k]
  ------------------
  358|      1|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  359|      1|	}
  360|       |
  361|       |	/* check for negative */
  362|  2.87k|	if (*buf_getptr(buf, 1) & (1 << (CHAR_BIT-1))) {
  ------------------
  |  Branch (362:6): [True: 1, False: 2.87k]
  ------------------
  363|      1|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  364|      1|	}
  365|       |
  366|  2.87k|	if (mp_from_ubin(mp, buf_getptr(buf, len), len) != MP_OKAY) {
  ------------------
  |  |  161|  2.87k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (366:6): [True: 0, False: 2.87k]
  ------------------
  367|      0|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
  368|      0|	}
  369|       |
  370|  2.87k|	buf_incrpos(buf, len);
  371|  2.87k|	return DROPBEAR_SUCCESS;
  ------------------
  |  |  102|  2.87k|#define DROPBEAR_SUCCESS 0
  ------------------
  372|  2.87k|}
buffer.c:buf_getstringbuf_int:
  224|  6.36k|static buffer * buf_getstringbuf_int(buffer *buf, int incllen) {
  225|  6.36k|	buffer *ret = NULL;
  226|  6.36k|	unsigned int len = buf_getint(buf);
  227|  6.36k|	int extra = 0;
  228|  6.36k|	if (len > MAX_STRING_LEN) {
  ------------------
  |  |  228|  6.36k|#define MAX_STRING_LEN (MAX(MAX_CMD_LEN, 2400)) /* Sun SSH needs 2400 for algos,
  ------------------
  |  Branch (228:6): [True: 1, False: 6.36k]
  ------------------
  229|      1|		dropbear_exit("String too long");
  230|      1|	}
  231|  6.36k|	if (incllen) {
  ------------------
  |  Branch (231:6): [True: 0, False: 6.36k]
  ------------------
  232|      0|		extra = 4;
  233|      0|	}
  234|  6.36k|	ret = buf_new(len+extra);
  235|  6.36k|	if (incllen) {
  ------------------
  |  Branch (235:6): [True: 0, False: 6.36k]
  ------------------
  236|      0|		buf_putint(ret, len);
  237|      0|	}
  238|  6.36k|	memcpy(buf_getwriteptr(ret, len), buf_getptr(buf, len), len);
  239|  6.36k|	buf_incrpos(buf, len);
  240|  6.36k|	buf_incrlen(ret, len);
  241|  6.36k|	buf_setpos(ret, 0);
  242|  6.36k|	return ret;
  243|  6.36k|}

chachapoly.c:dropbear_chachapoly_start:
   48|  5.72k|			int UNUSED(num_rounds), dropbear_chachapoly_state *state) {
   49|  5.72k|	int err;
   50|       |
   51|  5.72k|	TRACE2(("enter dropbear_chachapoly_start"))
   52|       |
   53|  5.72k|	if (keylen != CHACHA20_KEY_LEN*2) {
  ------------------
  |  |   33|  5.72k|#define CHACHA20_KEY_LEN 32
  ------------------
  |  Branch (53:6): [True: 0, False: 5.72k]
  ------------------
   54|      0|		return CRYPT_ERROR;
   55|      0|	}
   56|       |
   57|  5.72k|	if ((err = chacha_setup(&state->chacha, key,
  ------------------
  |  Branch (57:6): [True: 0, False: 5.72k]
  ------------------
   58|  5.72k|				CHACHA20_KEY_LEN, 20)) != CRYPT_OK) {
  ------------------
  |  |   33|  5.72k|#define CHACHA20_KEY_LEN 32
  ------------------
   59|      0|		return err;
   60|      0|	}
   61|       |
   62|  5.72k|	if ((err = chacha_setup(&state->header, key + CHACHA20_KEY_LEN,
  ------------------
  |  |   33|  5.72k|#define CHACHA20_KEY_LEN 32
  ------------------
  |  Branch (62:6): [True: 0, False: 5.72k]
  ------------------
   63|  5.72k|				CHACHA20_KEY_LEN, 20) != CRYPT_OK)) {
  ------------------
  |  |   33|  5.72k|#define CHACHA20_KEY_LEN 32
  ------------------
   64|      0|		return err;
   65|      0|	}
   66|       |
   67|  5.72k|	TRACE2(("leave dropbear_chachapoly_start"))
   68|  5.72k|	return CRYPT_OK;
   69|  5.72k|}
chachapoly.c:dropbear_chachapoly_crypt:
   74|   214k|			dropbear_chachapoly_state *state, int direction) {
   75|   214k|	poly1305_state poly;
   76|   214k|	unsigned char seqbuf[8], key[POLY1305_KEY_LEN], tag[POLY1305_TAG_LEN];
   77|   214k|	int err;
   78|       |
   79|   214k|	TRACE2(("enter dropbear_chachapoly_crypt"))
   80|       |
   81|   214k|	if (len < 4 || taglen != POLY1305_TAG_LEN) {
  ------------------
  |  |   36|   214k|#define POLY1305_TAG_LEN 16
  ------------------
  |  Branch (81:6): [True: 0, False: 214k]
  |  Branch (81:17): [True: 0, False: 214k]
  ------------------
   82|      0|		return CRYPT_ERROR;
   83|      0|	}
   84|       |
   85|   214k|	STORE64H((uint64_t)seq, seqbuf);
  ------------------
  |  |  101|   214k|#define STORE64H(x, y)                          \
  |  |  102|   214k|do { ulong64 __t = __builtin_bswap64 ((x));     \
  |  |  103|   214k|      XMEMCPY ((y), &__t, 8); } while(0)
  |  |  ------------------
  |  |  |  |   39|   214k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (103:39): [Folded - Ignored]
  |  |  ------------------
  ------------------
   86|   214k|	chacha_ivctr64(&state->chacha, seqbuf, sizeof(seqbuf), 0);
   87|   214k|	if ((err = chacha_keystream(&state->chacha, key, sizeof(key))) != CRYPT_OK) {
  ------------------
  |  Branch (87:6): [True: 0, False: 214k]
  ------------------
   88|      0|		return err;
   89|      0|	}
   90|       |
   91|   214k|	poly1305_init(&poly, key, sizeof(key));
   92|   214k|	if (direction == LTC_DECRYPT) {
  ------------------
  |  |   70|   214k|#define LTC_DECRYPT 1
  ------------------
  |  Branch (92:6): [True: 0, False: 214k]
  ------------------
   93|      0|		poly1305_process(&poly, in, len);
   94|      0|		poly1305_done(&poly, tag, &taglen);
   95|      0|		if (constant_time_memcmp(in + len, tag, taglen) != 0) {
  ------------------
  |  Branch (95:7): [True: 0, False: 0]
  ------------------
   96|      0|			return CRYPT_ERROR;
   97|      0|		}
   98|      0|	}
   99|       |
  100|   214k|	chacha_ivctr64(&state->header, seqbuf, sizeof(seqbuf), 0);
  101|   214k|	if ((err = chacha_crypt(&state->header, in, 4, out)) != CRYPT_OK) {
  ------------------
  |  Branch (101:6): [True: 0, False: 214k]
  ------------------
  102|      0|		return err;
  103|      0|	}
  104|       |
  105|   214k|	chacha_ivctr64(&state->chacha, seqbuf, sizeof(seqbuf), 1);
  106|   214k|	if ((err = chacha_crypt(&state->chacha, in + 4, len - 4, out + 4)) != CRYPT_OK) {
  ------------------
  |  Branch (106:6): [True: 0, False: 214k]
  ------------------
  107|      0|		return err;
  108|      0|	}
  109|       |
  110|   214k|	if (direction == LTC_ENCRYPT) {
  ------------------
  |  |   68|   214k|#define LTC_ENCRYPT 0
  ------------------
  |  Branch (110:6): [True: 214k, False: 0]
  ------------------
  111|   214k|		poly1305_process(&poly, out, len);
  112|   214k|		poly1305_done(&poly, out + len, &taglen);
  113|   214k|	}
  114|       |
  115|   214k|	TRACE2(("leave dropbear_chachapoly_crypt"))
  116|   214k|	return CRYPT_OK;
  117|   214k|}

cbuf_new:
   31|  4.11k|circbuffer * cbuf_new(unsigned int size) {
   32|       |
   33|  4.11k|	circbuffer *cbuf = NULL;
   34|       |
   35|  4.11k|	if (size > MAX_CBUF_SIZE) {
  ------------------
  |  |   29|  4.11k|#define MAX_CBUF_SIZE 100000000
  ------------------
  |  Branch (35:6): [True: 0, False: 4.11k]
  ------------------
   36|      0|		dropbear_exit("Bad cbuf size");
   37|      0|	}
   38|       |
   39|  4.11k|	cbuf = (circbuffer*)m_malloc(sizeof(circbuffer));
   40|       |	/* data is malloced on first write */
   41|  4.11k|	cbuf->data = NULL;
   42|  4.11k|	cbuf->used = 0;
   43|  4.11k|	cbuf->readpos = 0;
   44|  4.11k|	cbuf->writepos = 0;
   45|  4.11k|	cbuf->size = size;
   46|       |
   47|  4.11k|	return cbuf;
   48|  4.11k|}
cbuf_free:
   50|  4.11k|void cbuf_free(circbuffer * cbuf) {
   51|       |
   52|  4.11k|	if (cbuf->data) {
  ------------------
  |  Branch (52:6): [True: 0, False: 4.11k]
  ------------------
   53|      0|		m_burn(cbuf->data, cbuf->size);
   54|      0|		m_free(cbuf->data);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
   55|      0|	}
   56|  4.11k|	m_free(cbuf);
  ------------------
  |  |   24|  4.11k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
   57|  4.11k|}
cbuf_getused:
   59|   980k|unsigned int cbuf_getused(const circbuffer * cbuf) {
   60|       |
   61|   980k|	return cbuf->used;
   62|       |
   63|   980k|}
cbuf_getavail:
   65|     33|unsigned int cbuf_getavail(const circbuffer * cbuf) {
   66|       |
   67|     33|	return cbuf->size - cbuf->used;
   68|       |
   69|     33|}
cbuf_readptrs:
   91|     15|	unsigned char **p2, unsigned int *len2) {
   92|     15|	*p1 = &cbuf->data[cbuf->readpos];
   93|     15|	*len1 = MIN(cbuf->used, cbuf->size - cbuf->readpos);
   94|       |
   95|     15|	if (*len1 < cbuf->used) {
  ------------------
  |  Branch (95:6): [True: 0, False: 15]
  ------------------
   96|      0|		*p2 = cbuf->data;
   97|      0|		*len2 = cbuf->used - *len1;
   98|     15|	} else {
   99|     15|		*p2 = NULL;
  100|     15|		*len2 = 0;
  101|     15|	}
  102|     15|}

buf_put_algolist_all:
  315|  77.2k|void buf_put_algolist_all(buffer * buf, const algo_type localalgos[], int useall) {
  316|  77.2k|	unsigned int i, len;
  317|  77.2k|	unsigned int donefirst = 0;
  318|  77.2k|	unsigned int startpos;
  319|       |
  320|  77.2k|	startpos = buf->pos;
  321|       |	/* Placeholder for length */
  322|  77.2k|	buf_putint(buf, 0); 
  323|   367k|	for (i = 0; localalgos[i].name != NULL; i++) {
  ------------------
  |  Branch (323:14): [True: 289k, False: 77.2k]
  ------------------
  324|   289k|		if (localalgos[i].usable || useall) {
  ------------------
  |  Branch (324:7): [True: 280k, False: 9.65k]
  |  Branch (324:31): [True: 0, False: 9.65k]
  ------------------
  325|   280k|			if (donefirst) {
  ------------------
  |  Branch (325:8): [True: 202k, False: 77.2k]
  ------------------
  326|   202k|				buf_putbyte(buf, ',');
  327|   202k|			}
  328|   280k|			donefirst = 1;
  329|   280k|			len = strlen(localalgos[i].name);
  330|   280k|			buf_putbytes(buf, (const unsigned char *) localalgos[i].name, len);
  331|   280k|		}
  332|   289k|	}
  333|       |	/* Fill out the length */
  334|  77.2k|	len = buf->pos - startpos - 4;
  335|  77.2k|	buf_setpos(buf, startpos);
  336|  77.2k|	buf_putint(buf, len);
  337|  77.2k|	TRACE(("algolist add %d '%.*s'", len, len, buf_getptr(buf, len)))
  338|  77.2k|	buf_incrwritepos(buf, len);
  339|  77.2k|}
buf_put_algolist:
  341|  77.2k|void buf_put_algolist(buffer * buf, const algo_type localalgos[]) {
  342|  77.2k|	buf_put_algolist_all(buf, localalgos, 0);
  343|  77.2k|}
buf_has_algo:
  387|  11.0k|int buf_has_algo(buffer *buf, const char *algo) {
  388|  11.0k|	unsigned char* algolist = NULL;
  389|  11.0k|	unsigned int orig_pos = buf->pos;
  390|  11.0k|	unsigned int len, remotecount, i;
  391|  11.0k|	const char *remotenames[MAX_PROPOSED_ALGO];
  392|  11.0k|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  103|  11.0k|#define DROPBEAR_FAILURE -1
  ------------------
  393|       |
  394|  11.0k|	algolist = buf_getstring(buf, &len);
  395|  11.0k|	remotecount = MAX_PROPOSED_ALGO;
  ------------------
  |  |  209|  11.0k|#define MAX_PROPOSED_ALGO 50
  ------------------
  396|  11.0k|	get_algolist(algolist, len, remotenames, &remotecount);
  397|  59.0k|	for (i = 0; i < remotecount; i++)
  ------------------
  |  Branch (397:14): [True: 48.1k, False: 10.8k]
  ------------------
  398|  48.1k|	{
  399|  48.1k|		if (strcmp(remotenames[i], algo) == 0) {
  ------------------
  |  Branch (399:7): [True: 129, False: 48.0k]
  ------------------
  400|    129|			ret = DROPBEAR_SUCCESS;
  ------------------
  |  |  102|    129|#define DROPBEAR_SUCCESS 0
  ------------------
  401|    129|			break;
  402|    129|		}
  403|  48.1k|	}
  404|  11.0k|	if (algolist) {
  ------------------
  |  Branch (404:6): [True: 11.0k, False: 2]
  ------------------
  405|  11.0k|		m_free(algolist);
  ------------------
  |  |   24|  11.0k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  406|  11.0k|	}
  407|  11.0k|	buf_setpos(buf, orig_pos);
  408|  11.0k|	return ret;
  409|  11.0k|}
buf_match_algo:
  427|  76.0k|		int kexguess2, int *goodguess) {
  428|  76.0k|	char * algolist = NULL;
  429|  76.0k|	const char *remotenames[MAX_PROPOSED_ALGO], *localnames[MAX_PROPOSED_ALGO];
  430|  76.0k|	unsigned int len;
  431|  76.0k|	unsigned int remotecount, localcount, clicount, servcount, i, j;
  432|  76.0k|	algo_type * ret = NULL;
  433|  76.0k|	const char **clinames, **servnames;
  434|       |
  435|  76.0k|	if (goodguess) {
  ------------------
  |  Branch (435:6): [True: 19.1k, False: 56.9k]
  ------------------
  436|  19.1k|		*goodguess = 0;
  437|  19.1k|	}
  438|       |
  439|       |	/* get the comma-separated list from the buffer ie "algo1,algo2,algo3" */
  440|  76.0k|	algolist = buf_getstring(buf, &len);
  441|  76.0k|	DEBUG3(("buf_match_algo: %s", algolist))
  442|  76.0k|	remotecount = MAX_PROPOSED_ALGO;
  ------------------
  |  |  209|  76.0k|#define MAX_PROPOSED_ALGO 50
  ------------------
  443|  76.0k|	get_algolist(algolist, len, remotenames, &remotecount);
  444|       |
  445|   362k|	for (i = 0; localalgos[i].name != NULL; i++) {
  ------------------
  |  Branch (445:14): [True: 285k, False: 76.0k]
  ------------------
  446|   285k|		if (localalgos[i].usable) {
  ------------------
  |  Branch (446:7): [True: 276k, False: 9.58k]
  ------------------
  447|   276k|			localnames[i] = localalgos[i].name;
  448|   276k|		} else {
  449|  9.58k|			localnames[i] = NULL;
  450|  9.58k|		}
  451|   285k|	}
  452|  76.0k|	localcount = i;
  453|       |
  454|  76.0k|	if (IS_DROPBEAR_SERVER) {
  ------------------
  |  |  319|  76.0k|#define IS_DROPBEAR_SERVER (ses.isserver == 1)
  |  |  ------------------
  |  |  |  Branch (319:28): [True: 76.0k, False: 54]
  |  |  ------------------
  ------------------
  455|  76.0k|		clinames = remotenames;
  456|  76.0k|		clicount = remotecount;
  457|  76.0k|		servnames = localnames;
  458|  76.0k|		servcount = localcount;
  459|  76.0k|	} else {
  460|     54|		clinames = localnames;
  461|     54|		clicount = localcount;
  462|     54|		servnames = remotenames;
  463|     54|		servcount = remotecount;
  464|     54|	}
  465|       |
  466|       |	/* iterate and find the first match */
  467|   120k|	for (i = 0; i < clicount; i++) {
  ------------------
  |  Branch (467:14): [True: 108k, False: 12.0k]
  ------------------
  468|   444k|		for (j = 0; j < servcount; j++) {
  ------------------
  |  Branch (468:15): [True: 400k, False: 44.1k]
  ------------------
  469|   400k|			if (!(servnames[j] && clinames[i])) {
  ------------------
  |  Branch (469:10): [True: 378k, False: 21.6k]
  |  Branch (469:26): [True: 378k, False: 0]
  ------------------
  470|       |				/* unusable algos are NULL */
  471|  21.6k|				continue;
  472|  21.6k|			}
  473|   378k|			if (strcmp(servnames[j], clinames[i]) == 0) {
  ------------------
  |  Branch (473:8): [True: 63.9k, False: 314k]
  ------------------
  474|       |				/* set if it was a good guess */
  475|  63.9k|				if (goodguess != NULL) {
  ------------------
  |  Branch (475:9): [True: 19.0k, False: 44.8k]
  ------------------
  476|  19.0k|					if (kexguess2) {
  ------------------
  |  Branch (476:10): [True: 236, False: 18.8k]
  ------------------
  477|    236|						if (i == 0) {
  ------------------
  |  Branch (477:11): [True: 145, False: 91]
  ------------------
  478|    145|							*goodguess = 1;
  479|    145|						}
  480|  18.8k|					} else {
  481|  18.8k|						if (i == 0 && j == 0) {
  ------------------
  |  Branch (481:11): [True: 14.3k, False: 4.51k]
  |  Branch (481:21): [True: 6.72k, False: 7.61k]
  ------------------
  482|  6.72k|							*goodguess = 1;
  483|  6.72k|						}
  484|  18.8k|					}
  485|  19.0k|				}
  486|       |				/* set the algo to return */
  487|  63.9k|				if (IS_DROPBEAR_SERVER) {
  ------------------
  |  |  319|  63.9k|#define IS_DROPBEAR_SERVER (ses.isserver == 1)
  |  |  ------------------
  |  |  |  Branch (319:28): [True: 63.9k, False: 0]
  |  |  ------------------
  ------------------
  488|  63.9k|					ret = &localalgos[j];
  489|  63.9k|				} else {
  490|      0|					ret = &localalgos[i];
  491|      0|				}
  492|  63.9k|				goto out;
  493|  63.9k|			}
  494|   378k|		}
  495|   108k|	}
  496|       |
  497|  76.0k|out:
  498|  76.0k|	m_free(algolist);
  ------------------
  |  |   24|  76.0k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  499|  76.0k|	return ret;
  500|  76.0k|}
common-algo.c:void_start:
   50|  9.27k|			int UNUSED(keylen), int UNUSED(num_rounds), void* UNUSED(cipher_state)) {
   51|  9.27k|	return CRYPT_OK;
   52|  9.27k|}
common-algo.c:void_cipher:
   41|   108k|		unsigned long len, void* UNUSED(cipher_state)) {
   42|   108k|	if (in != out) {
  ------------------
  |  Branch (42:6): [True: 0, False: 108k]
  ------------------
   43|      0|		memmove(out, in, len);
   44|      0|	}
   45|   108k|	return CRYPT_OK;
   46|   108k|}
common-algo.c:dropbear_big_endian_ctr_start:
   91|  3.55k|		int num_rounds, symmetric_CTR *ctr) {
   92|  3.55k|	return ctr_start(cipher, IV, key, keylen, num_rounds, CTR_COUNTER_BIG_ENDIAN, ctr);
  ------------------
  |  |  860|  3.55k|#define CTR_COUNTER_BIG_ENDIAN       0x1000
  ------------------
   93|  3.55k|}
common-algo.c:get_algolist:
  350|  87.0k|				const char* *ret_list, unsigned int *ret_count) {
  351|  87.0k|	unsigned int max_count = *ret_count;
  352|  87.0k|	unsigned int i;
  353|       |
  354|  87.0k|	if (*ret_count == 0) {
  ------------------
  |  Branch (354:6): [True: 0, False: 87.0k]
  ------------------
  355|      0|		return;
  356|      0|	}
  357|  87.0k|	if (algolist_len > MAX_PROPOSED_ALGO*(MAX_NAME_LEN+1)) {
  ------------------
  |  |  209|  87.0k|#define MAX_PROPOSED_ALGO 50
  ------------------
              	if (algolist_len > MAX_PROPOSED_ALGO*(MAX_NAME_LEN+1)) {
  ------------------
  |  |  205|  87.0k|#define MAX_NAME_LEN 64 /* maximum length of a protocol name, isn't
  ------------------
  |  Branch (357:6): [True: 5, False: 87.0k]
  ------------------
  358|      5|		*ret_count = 0;
  359|      5|	}
  360|       |
  361|       |	/* ret_list will contain a list of the strings parsed out.
  362|       |	   We will have at least one string (even if it's just "") */
  363|  87.0k|	ret_list[0] = algolist;
  364|  87.0k|	*ret_count = 1;
  365|  1.77M|	for (i = 0; i < algolist_len; i++) {
  ------------------
  |  Branch (365:14): [True: 1.68M, False: 86.6k]
  ------------------
  366|  1.68M|		if (algolist[i] == '\0') {
  ------------------
  |  Branch (366:7): [True: 335, False: 1.68M]
  ------------------
  367|       |			/* someone is trying something strange */
  368|    335|			*ret_count = 0;
  369|    335|			return;
  370|    335|		}
  371|       |
  372|  1.68M|		if (algolist[i] == ',') {
  ------------------
  |  Branch (372:7): [True: 115k, False: 1.57M]
  ------------------
  373|   115k|			if (*ret_count >= max_count) {
  ------------------
  |  Branch (373:8): [True: 0, False: 115k]
  ------------------
  374|      0|				dropbear_exit("Too many remote algorithms");
  375|      0|				*ret_count = 0;
  376|      0|				return;
  377|      0|			}
  378|   115k|			algolist[i] = '\0';
  379|   115k|			ret_list[*ret_count] = &algolist[i+1];
  380|   115k|			(*ret_count)++;
  381|   115k|		}
  382|  1.68M|	}
  383|  87.0k|}

chaninitialise:
   70|  1.49k|void chaninitialise(const struct ChanType *chantypes[]) {
   71|       |
   72|       |	/* may as well create space for a single channel */
   73|  1.49k|	ses.channels = (struct Channel**)m_malloc(sizeof(struct Channel*));
   74|  1.49k|	ses.chansize = 1;
   75|  1.49k|	ses.channels[0] = NULL;
   76|  1.49k|	ses.chancount = 0;
   77|       |
   78|  1.49k|	ses.chantypes = chantypes;
   79|       |
   80|  1.49k|#if DROPBEAR_LISTENERS
   81|  1.49k|	listeners_initialise();
   82|  1.49k|#endif
   83|       |
   84|  1.49k|}
chancleanup:
   87|  1.49k|void chancleanup() {
   88|       |
   89|  1.49k|	unsigned int i;
   90|       |
   91|  1.49k|	TRACE(("enter chancleanup"))
   92|  5.94k|	for (i = 0; i < ses.chansize; i++) {
  ------------------
  |  Branch (92:14): [True: 4.45k, False: 1.49k]
  ------------------
   93|  4.45k|		if (ses.channels[i] != NULL) {
  ------------------
  |  Branch (93:7): [True: 3.13k, False: 1.31k]
  ------------------
   94|  3.13k|			TRACE(("channel %d closing", i))
   95|  3.13k|			remove_channel(ses.channels[i]);
   96|  3.13k|		}
   97|  4.45k|	}
   98|  1.49k|	m_free(ses.channels);
  ------------------
  |  |   24|  1.49k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
   99|  1.49k|	TRACE(("leave chancleanup"))
  100|  1.49k|}
getchannel:
  194|  7.95k|struct Channel* getchannel() {
  195|  7.95k|	return getchannel_msg(NULL);
  196|  7.95k|}
channelio:
  199|   456k|void channelio(const fd_set *readfds, const fd_set *writefds) {
  200|       |
  201|       |	/* Listeners such as TCP, X11, agent-auth */
  202|   456k|	struct Channel *channel;
  203|   456k|	unsigned int i;
  204|       |
  205|       |	/* foreach channel */
  206|  3.11M|	for (i = 0; i < ses.chansize; i++) {
  ------------------
  |  Branch (206:14): [True: 2.65M, False: 456k]
  ------------------
  207|       |		/* Close checking only needs to occur for channels that had IO events */
  208|  2.65M|		int do_check_close = 0;
  209|       |
  210|  2.65M|		channel = ses.channels[i];
  211|  2.65M|		if (channel == NULL) {
  ------------------
  |  Branch (211:7): [True: 481k, False: 2.17M]
  ------------------
  212|       |			/* only process in-use channels */
  213|   481k|			continue;
  214|   481k|		}
  215|       |
  216|       |		/* read data and send it over the wire */
  217|  2.17M|		if (channel->readfd >= 0 && FD_ISSET(channel->readfd, readfds)) {
  ------------------
  |  Branch (217:7): [True: 816k, False: 1.36M]
  ------------------
  218|   106k|			TRACE(("send normal readfd"))
  219|   106k|			send_msg_channel_data(channel, 0);
  220|   106k|			do_check_close = 1;
  221|   106k|		}
  222|       |
  223|       |		/* read stderr data and send it over the wire */
  224|  2.17M|		if (ERRFD_IS_READ(channel) && channel->errfd >= 0 
  ------------------
  |  |   59|  4.35M|#define ERRFD_IS_READ(channel) ((channel)->extrabuf == NULL)
  |  |  ------------------
  |  |  |  Branch (59:32): [True: 2.17M, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (224:33): [True: 783k, False: 1.39M]
  ------------------
  225|  2.17M|			&& FD_ISSET(channel->errfd, readfds)) {
  226|  99.8k|				TRACE(("send normal errfd"))
  227|  99.8k|				send_msg_channel_data(channel, 1);
  228|  99.8k|			do_check_close = 1;
  229|  99.8k|		}
  230|       |
  231|       |		/* write to program/pipe stdin */
  232|  2.17M|		if (channel->writefd >= 0 && FD_ISSET(channel->writefd, writefds)) {
  ------------------
  |  Branch (232:7): [True: 980k, False: 1.19M]
  ------------------
  233|      0|			writechannel(channel, channel->writefd, channel->writebuf, NULL, NULL);
  234|      0|			do_check_close = 1;
  235|      0|		}
  236|       |		
  237|       |		/* stderr for client mode */
  238|  2.17M|		if (ERRFD_IS_WRITE(channel)
  ------------------
  |  |   60|  4.35M|#define ERRFD_IS_WRITE(channel) (!ERRFD_IS_READ(channel))
  |  |  ------------------
  |  |  |  |   59|  2.17M|#define ERRFD_IS_READ(channel) ((channel)->extrabuf == NULL)
  |  |  ------------------
  |  |  |  Branch (60:33): [True: 0, False: 2.17M]
  |  |  ------------------
  ------------------
  239|  2.17M|				&& channel->errfd >= 0 && FD_ISSET(channel->errfd, writefds)) {
  ------------------
  |  Branch (239:8): [True: 0, False: 0]
  ------------------
  240|      0|			writechannel(channel, channel->errfd, channel->extrabuf, NULL, NULL);
  241|      0|			do_check_close = 1;
  242|      0|		}
  243|       |
  244|  2.17M|		if (ses.channel_signal_pending) {
  ------------------
  |  Branch (244:7): [True: 0, False: 2.17M]
  ------------------
  245|       |			/* SIGCHLD can change channel state for server sessions */
  246|      0|			do_check_close = 1;
  247|      0|		}
  248|       |	
  249|       |		/* handle any channel closing etc */
  250|  2.17M|		if (do_check_close) {
  ------------------
  |  Branch (250:7): [True: 183k, False: 1.99M]
  ------------------
  251|   183k|			check_close(channel);
  252|   183k|		}
  253|  2.17M|	}
  254|       |
  255|   456k|#if DROPBEAR_LISTENERS
  256|   456k|	handle_listeners(readfds);
  257|   456k|#endif
  258|   456k|}
channel_connect_done:
  347|     97|void channel_connect_done(int result, int sock, void* user_data, const char* errstring) {
  348|     97|	struct Channel *channel = user_data;
  349|       |
  350|     97|	TRACE(("enter channel_connect_done"))
  351|       |
  352|     97|	if (result == DROPBEAR_SUCCESS)
  ------------------
  |  |  102|     97|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (352:6): [True: 0, False: 97]
  ------------------
  353|      0|	{
  354|      0|		channel->readfd = channel->writefd = sock;
  355|      0|		channel->bidir_fd = 1;
  356|      0|		channel->conn_pending = NULL;
  357|      0|		send_msg_channel_open_confirmation(channel, channel->recvwindow,
  358|      0|				channel->recvmaxpacket);
  359|      0|		TRACE(("leave channel_connect_done: success"))
  360|      0|	}
  361|     97|	else
  362|     97|	{
  363|     97|		send_msg_channel_open_failure(channel->remotechan,
  364|     97|				SSH_OPEN_CONNECT_FAILED, errstring, "");
  ------------------
  |  |   34|     97|#define SSH_OPEN_CONNECT_FAILED                 2
  ------------------
  365|     97|		remove_channel(channel);
  366|     97|		TRACE(("leave check_in_progress: fail. internal errstring: %s", errstring))
  367|     97|	}
  368|     97|}
setchannelfds:
  541|   458k|void setchannelfds(fd_set *readfds, fd_set *writefds, int allow_reads) {
  542|       |	
  543|   458k|	unsigned int i;
  544|   458k|	struct Channel * channel;
  545|       |	
  546|  3.11M|	for (i = 0; i < ses.chansize; i++) {
  ------------------
  |  Branch (546:14): [True: 2.65M, False: 458k]
  ------------------
  547|       |
  548|  2.65M|		channel = ses.channels[i];
  549|  2.65M|		if (channel == NULL) {
  ------------------
  |  Branch (549:7): [True: 483k, False: 2.17M]
  ------------------
  550|   483k|			continue;
  551|   483k|		}
  552|       |
  553|       |		/* Stuff to put over the wire. 
  554|       |		Avoid queueing data to send if we're in the middle of a 
  555|       |		key re-exchange (!dataallowed), but still read from the 
  556|       |		FD if there's the possibility of "~."" to kill an 
  557|       |		interactive session (the read_mangler) */
  558|  2.17M|		if (channel->transwindow > 0
  ------------------
  |  Branch (558:7): [True: 2.09M, False: 76.3k]
  ------------------
  559|  2.17M|		   && ((ses.dataallowed && allow_reads) || channel->read_mangler)) {
  ------------------
  |  Branch (559:11): [True: 2.09M, False: 6.82k]
  |  Branch (559:30): [True: 1.48M, False: 603k]
  |  Branch (559:46): [True: 0, False: 610k]
  ------------------
  560|       |
  561|  1.48M|			if (channel->readfd >= 0) {
  ------------------
  |  Branch (561:8): [True: 510k, False: 978k]
  ------------------
  562|   510k|				FD_SET(channel->readfd, readfds);
  563|   510k|			}
  564|       |			
  565|  1.48M|			if (ERRFD_IS_READ(channel) && channel->errfd >= 0) {
  ------------------
  |  |   59|  2.97M|#define ERRFD_IS_READ(channel) ((channel)->extrabuf == NULL)
  |  |  ------------------
  |  |  |  Branch (59:32): [True: 1.48M, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (565:34): [True: 488k, False: 1.00M]
  ------------------
  566|   488k|					FD_SET(channel->errfd, readfds);
  567|   488k|			}
  568|  1.48M|		}
  569|       |
  570|       |		/* Stuff from the wire */
  571|  2.17M|		if (channel->writefd >= 0 && cbuf_getused(channel->writebuf) > 0) {
  ------------------
  |  Branch (571:7): [True: 980k, False: 1.19M]
  |  Branch (571:32): [True: 0, False: 980k]
  ------------------
  572|      0|				FD_SET(channel->writefd, writefds);
  573|      0|		}
  574|       |
  575|  2.17M|		if (ERRFD_IS_WRITE(channel) && channel->errfd >= 0 
  ------------------
  |  |   60|  4.35M|#define ERRFD_IS_WRITE(channel) (!ERRFD_IS_READ(channel))
  |  |  ------------------
  |  |  |  |   59|  2.17M|#define ERRFD_IS_READ(channel) ((channel)->extrabuf == NULL)
  |  |  ------------------
  |  |  |  Branch (60:33): [True: 0, False: 2.17M]
  |  |  ------------------
  ------------------
  |  Branch (575:34): [True: 0, False: 0]
  ------------------
  576|  2.17M|				&& cbuf_getused(channel->extrabuf) > 0) {
  ------------------
  |  Branch (576:8): [True: 0, False: 0]
  ------------------
  577|      0|				FD_SET(channel->errfd, writefds);
  578|      0|		}
  579|       |
  580|  2.17M|	} /* foreach channel */
  581|       |
  582|   458k|#if DROPBEAR_LISTENERS
  583|   458k|	set_listener_fds(readfds);
  584|   458k|#endif
  585|       |
  586|   458k|}
recv_msg_channel_eof:
  591|  1.45k|void recv_msg_channel_eof() {
  592|       |
  593|  1.45k|	struct Channel * channel;
  594|       |
  595|  1.45k|	TRACE(("enter recv_msg_channel_eof"))
  596|       |
  597|  1.45k|	channel = getchannel_msg("EOF");
  598|       |
  599|  1.45k|	channel->recv_eof = 1;
  600|       |
  601|  1.45k|	check_close(channel);
  602|  1.45k|	TRACE(("leave recv_msg_channel_eof"))
  603|  1.45k|}
recv_msg_channel_close:
  607|  1.01k|void recv_msg_channel_close() {
  608|       |
  609|  1.01k|	struct Channel * channel;
  610|       |
  611|  1.01k|	TRACE(("enter recv_msg_channel_close"))
  612|       |
  613|  1.01k|	channel = getchannel_msg("Close");
  614|       |
  615|  1.01k|	channel->recv_eof = 1;
  616|  1.01k|	channel->recv_close = 1;
  617|       |
  618|  1.01k|	check_close(channel);
  619|  1.01k|	TRACE(("leave recv_msg_channel_close"))
  620|  1.01k|}
recv_msg_channel_request:
  668|  7.35k|void recv_msg_channel_request() {
  669|       |
  670|  7.35k|	struct Channel *channel;
  671|       |
  672|  7.35k|	channel = getchannel();
  673|       |
  674|  7.35k|	TRACE(("enter recv_msg_channel_request %p", (void*)channel))
  675|       |
  676|  7.35k|	if (channel->type->reqhandler) {
  ------------------
  |  Branch (676:6): [True: 7.34k, False: 10]
  ------------------
  677|  7.34k|		channel->type->reqhandler(channel);
  678|  7.34k|	} else {
  679|     10|		int wantreply;
  680|     10|		buf_eatstring(ses.payload);
  681|     10|		wantreply = buf_getbool(ses.payload);
  682|     10|		if (wantreply) {
  ------------------
  |  Branch (682:7): [True: 0, False: 10]
  ------------------
  683|      0|			send_msg_channel_failure(channel);
  684|      0|		}
  685|     10|	}
  686|       |
  687|  7.35k|	TRACE(("leave recv_msg_channel_request"))
  688|       |
  689|  7.35k|}
recv_msg_channel_data:
  775|     79|void recv_msg_channel_data() {
  776|       |
  777|     79|	struct Channel *channel;
  778|       |
  779|     79|	channel = getchannel();
  780|       |
  781|     79|	common_recv_msg_channel_data(channel, channel->writefd, channel->writebuf);
  782|     79|}
common_recv_msg_channel_data:
  787|     78|		circbuffer * cbuf) {
  788|       |
  789|     78|	unsigned int datalen;
  790|     78|	unsigned int maxdata;
  791|     78|	unsigned int buflen;
  792|     78|	unsigned int len;
  793|     78|	unsigned int consumed;
  794|     78|	int res;
  795|       |
  796|     78|	TRACE(("enter recv_msg_channel_data"))
  797|       |
  798|     78|	if (channel->recv_eof) {
  ------------------
  |  Branch (798:6): [True: 0, False: 78]
  ------------------
  799|      0|		dropbear_exit("Received data after eof");
  800|      0|	}
  801|       |
  802|     78|	if (fd < 0 || !cbuf) {
  ------------------
  |  Branch (802:6): [True: 60, False: 18]
  |  Branch (802:16): [True: 0, False: 18]
  ------------------
  803|       |		/* If we have encountered failed write, the far side might still
  804|       |		 * be sending data without having yet received our close notification.
  805|       |		 * We just drop the data. */
  806|     60|		return;
  807|     60|	}
  808|       |
  809|     18|	datalen = buf_getint(ses.payload);
  810|     18|	TRACE(("length %d", datalen))
  811|       |
  812|     18|	maxdata = cbuf_getavail(cbuf);
  813|       |
  814|       |	/* Whilst the spec says we "MAY ignore data past the end" this could
  815|       |	 * lead to corrupted file transfers etc (chunks missed etc). It's better to
  816|       |	 * just die horribly */
  817|     18|	if (datalen > maxdata) {
  ------------------
  |  Branch (817:6): [True: 2, False: 16]
  ------------------
  818|      2|		dropbear_exit("Oversized packet");
  819|      2|	}
  820|       |
  821|     16|	dropbear_assert(channel->recvwindow >= datalen);
  ------------------
  |  |   83|     16|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 16]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
  822|     16|	channel->recvwindow -= datalen;
  823|     16|	dropbear_assert(channel->recvwindow <= opts.recv_window);
  ------------------
  |  |   83|     16|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 16]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
  824|       |
  825|       |	/* Attempt to write the data immediately without having to put it in the circular buffer */
  826|     16|	consumed = datalen;
  827|     16|	res = writechannel(channel, fd, cbuf, buf_getptr(ses.payload, datalen), &consumed);
  828|       |
  829|     16|	datalen -= consumed;
  830|     16|	buf_incrpos(ses.payload, consumed);
  831|       |
  832|       |
  833|       |	/* We may have to run throught twice, if the buffer wraps around. Can't
  834|       |	 * just "leave it for next time" like with writechannel, since this
  835|       |	 * is payload data.
  836|       |	 * If the writechannel() failed then remaining data is discarded */
  837|     16|	if (res == DROPBEAR_SUCCESS) {
  ------------------
  |  |  102|     16|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (837:6): [True: 0, False: 16]
  ------------------
  838|      0|		len = datalen;
  839|      0|		while (len > 0) {
  ------------------
  |  Branch (839:10): [True: 0, False: 0]
  ------------------
  840|      0|			buflen = cbuf_writelen(cbuf);
  841|      0|			buflen = MIN(buflen, len);
  842|       |
  843|      0|			memcpy(cbuf_writeptr(cbuf, buflen), 
  844|      0|					buf_getptr(ses.payload, buflen), buflen);
  845|      0|			cbuf_incrwrite(cbuf, buflen);
  846|      0|			buf_incrpos(ses.payload, buflen);
  847|      0|			len -= buflen;
  848|      0|		}
  849|      0|	}
  850|       |
  851|     16|	TRACE(("leave recv_msg_channel_data"))
  852|     16|}
recv_msg_channel_window_adjust:
  857|    526|void recv_msg_channel_window_adjust() {
  858|       |
  859|    526|	struct Channel * channel;
  860|    526|	unsigned int incr;
  861|       |	
  862|    526|	channel = getchannel();
  863|       |	
  864|    526|	incr = buf_getint(ses.payload);
  865|    526|	TRACE(("received window increment %d", incr))
  866|    526|	incr = MIN(incr, TRANS_MAX_WIN_INCR);
  867|       |	
  868|    526|	channel->transwindow += incr;
  869|    526|	channel->transwindow = MIN(channel->transwindow, TRANS_MAX_WINDOW);
  870|       |
  871|    526|}
recv_msg_channel_open:
  889|  5.01k|void recv_msg_channel_open() {
  890|       |
  891|  5.01k|	char *type;
  892|  5.01k|	unsigned int typelen;
  893|  5.01k|	unsigned int remotechan, transwindow, transmaxpacket;
  894|  5.01k|	struct Channel *channel;
  895|  5.01k|	const struct ChanType **cp;
  896|  5.01k|	const struct ChanType *chantype;
  897|  5.01k|	unsigned int errtype = SSH_OPEN_UNKNOWN_CHANNEL_TYPE;
  ------------------
  |  |   35|  5.01k|#define SSH_OPEN_UNKNOWN_CHANNEL_TYPE           3
  ------------------
  898|  5.01k|	int ret;
  899|       |
  900|       |
  901|  5.01k|	TRACE(("enter recv_msg_channel_open"))
  902|       |
  903|       |	/* get the packet contents */
  904|  5.01k|	type = buf_getstring(ses.payload, &typelen);
  905|       |
  906|  5.01k|	remotechan = buf_getint(ses.payload);
  907|  5.01k|	transwindow = buf_getint(ses.payload);
  908|  5.01k|	transwindow = MIN(transwindow, TRANS_MAX_WINDOW);
  909|  5.01k|	transmaxpacket = buf_getint(ses.payload);
  910|  5.01k|	transmaxpacket = MIN(transmaxpacket, TRANS_MAX_PAYLOAD_LEN);
  911|       |
  912|       |	/* figure what type of packet it is */
  913|  5.01k|	if (typelen > MAX_NAME_LEN) {
  ------------------
  |  |  205|  5.01k|#define MAX_NAME_LEN 64 /* maximum length of a protocol name, isn't
  ------------------
  |  Branch (913:6): [True: 70, False: 4.94k]
  ------------------
  914|     70|		goto failure;
  915|     70|	}
  916|       |
  917|       |	/* Get the channel type. Client and server style invokation will set up a
  918|       |	 * different list for ses.chantypes at startup. We just iterate through
  919|       |	 * this list and find the matching name */
  920|  4.94k|	for (cp = &ses.chantypes[0], chantype = (*cp); 
  921|  6.93k|			chantype != NULL;
  ------------------
  |  Branch (921:4): [True: 6.10k, False: 835]
  ------------------
  922|  6.10k|			cp++, chantype = (*cp)) {
  923|  6.10k|		if (strcmp(type, chantype->name) == 0) {
  ------------------
  |  Branch (923:7): [True: 4.11k, False: 1.98k]
  ------------------
  924|  4.11k|			break;
  925|  4.11k|		}
  926|  6.10k|	}
  927|       |
  928|  4.94k|	if (chantype == NULL) {
  ------------------
  |  Branch (928:6): [True: 833, False: 4.11k]
  ------------------
  929|    833|		TRACE(("No matching type for '%s'", type))
  930|    833|		goto failure;
  931|    833|	}
  932|       |
  933|  4.11k|	TRACE(("matched type '%s'", type))
  934|       |
  935|       |	/* create the channel */
  936|  4.11k|	channel = newchannel(remotechan, chantype, transwindow, transmaxpacket);
  937|       |
  938|  4.11k|	if (channel == NULL) {
  ------------------
  |  Branch (938:6): [True: 0, False: 4.11k]
  ------------------
  939|      0|		TRACE(("newchannel returned NULL"))
  940|      0|		errtype = SSH_OPEN_RESOURCE_SHORTAGE;
  ------------------
  |  |   36|      0|#define SSH_OPEN_RESOURCE_SHORTAGE              4
  ------------------
  941|      0|		goto failure;
  942|      0|	}
  943|       |
  944|  4.11k|	if (channel->type->inithandler) {
  ------------------
  |  Branch (944:6): [True: 4.11k, False: 2]
  ------------------
  945|  4.11k|		ret = channel->type->inithandler(channel);
  946|  4.11k|		if (ret == SSH_OPEN_IN_PROGRESS) {
  ------------------
  |  |   39|  4.11k|#define SSH_OPEN_IN_PROGRESS					99
  ------------------
  |  Branch (946:7): [True: 98, False: 4.01k]
  ------------------
  947|       |			/* We'll send the confirmation later */
  948|     98|			goto cleanup;
  949|     98|		}
  950|  4.01k|		if (ret > 0) {
  ------------------
  |  Branch (950:7): [True: 219, False: 3.79k]
  ------------------
  951|    219|			errtype = ret;
  952|    219|			remove_channel(channel);
  953|    219|			TRACE(("inithandler returned failure %d", ret))
  954|    219|			goto failure;
  955|    219|		}
  956|  4.01k|	}
  957|       |
  958|  3.79k|	update_channel_prio();
  959|       |
  960|       |	/* success */
  961|  3.79k|	send_msg_channel_open_confirmation(channel, channel->recvwindow,
  962|  3.79k|			channel->recvmaxpacket);
  963|  3.79k|	goto cleanup;
  964|       |
  965|  1.12k|failure:
  966|  1.12k|	TRACE(("recv_msg_channel_open failure"))
  967|  1.12k|	send_msg_channel_open_failure(remotechan, errtype, "", "");
  968|       |
  969|  5.00k|cleanup:
  970|  5.00k|	m_free(type);
  ------------------
  |  |   24|  5.00k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  971|       |
  972|  5.00k|	TRACE(("leave recv_msg_channel_open"))
  973|  5.00k|}
send_msg_channel_failure:
  976|  4.75k|void send_msg_channel_failure(const struct Channel *channel) {
  977|       |
  978|  4.75k|	TRACE(("enter send_msg_channel_failure"))
  979|       |
  980|  4.75k|	if (channel->sent_close) {
  ------------------
  |  Branch (980:6): [True: 257, False: 4.49k]
  ------------------
  981|    257|		TRACE(("Skipping sending msg_channel_failure for closed channel"))
  982|    257|		return;
  983|    257|	}
  984|  4.49k|	CHECKCLEARTOWRITE();
  985|       |
  986|  4.49k|	buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_FAILURE);
  ------------------
  |  |   76|  4.49k|#define SSH_MSG_CHANNEL_FAILURE                 100
  ------------------
  987|  4.49k|	buf_putint(ses.writepayload, channel->remotechan);
  988|       |
  989|  4.49k|	encrypt_packet();
  990|  4.49k|	TRACE(("leave send_msg_channel_failure"))
  991|  4.49k|}
send_msg_channel_success:
  994|  1.40k|void send_msg_channel_success(const struct Channel *channel) {
  995|       |
  996|  1.40k|	TRACE(("enter send_msg_channel_success"))
  997|  1.40k|	if (channel->sent_close) {
  ------------------
  |  Branch (997:6): [True: 384, False: 1.01k]
  ------------------
  998|    384|		TRACE(("Skipping sending msg_channel_success for closed channel"))
  999|    384|		return;
 1000|    384|	}
 1001|  1.01k|	CHECKCLEARTOWRITE();
 1002|       |
 1003|  1.01k|	buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_SUCCESS);
  ------------------
  |  |   75|  1.01k|#define SSH_MSG_CHANNEL_SUCCESS                 99
  ------------------
 1004|  1.01k|	buf_putint(ses.writepayload, channel->remotechan);
 1005|       |
 1006|  1.01k|	encrypt_packet();
 1007|  1.01k|	TRACE(("leave send_msg_channel_success"))
 1008|  1.01k|}
send_msg_request_failure:
 1192|    757|void send_msg_request_failure() {
 1193|    757|	CHECKCLEARTOWRITE();
 1194|    757|	buf_putbyte(ses.writepayload, SSH_MSG_REQUEST_FAILURE);
  ------------------
  |  |   65|    757|#define SSH_MSG_REQUEST_FAILURE                 82
  ------------------
 1195|    757|	encrypt_packet();
 1196|    757|}
common-channel.c:getchannel_msg:
  179|  10.4k|static struct Channel* getchannel_msg(const char* kind) {
  180|       |
  181|  10.4k|	unsigned int chan;
  182|       |
  183|  10.4k|	chan = buf_getint(ses.payload);
  184|  10.4k|	if (chan >= ses.chansize || ses.channels[chan] == NULL) {
  ------------------
  |  Branch (184:6): [True: 18, False: 10.4k]
  |  Branch (184:30): [True: 2, False: 10.4k]
  ------------------
  185|     20|		if (kind) {
  ------------------
  |  Branch (185:7): [True: 7, False: 13]
  ------------------
  186|      7|			dropbear_exit("%s for unknown channel %d", kind, chan);
  187|     13|		} else {
  188|     13|			dropbear_exit("Unknown channel %d", chan);
  189|     13|		}
  190|     20|	}
  191|  10.4k|	return ses.channels[chan];
  192|  10.4k|}
common-channel.c:check_close:
  276|   185k|static void check_close(struct Channel *channel) {
  277|   185k|	int close_allowed = 0;
  278|       |
  279|   185k|	TRACE2(("check_close: writefd %d, readfd %d, errfd %d, sent_close %d, recv_close %d",
  280|   185k|				channel->writefd, channel->readfd,
  281|   185k|				channel->errfd, channel->sent_close, channel->recv_close))
  282|   185k|	TRACE2(("writebuf size %d extrabuf size %d",
  283|   185k|				channel->writebuf ? cbuf_getused(channel->writebuf) : 0,
  284|   185k|				channel->extrabuf ? cbuf_getused(channel->extrabuf) : 0))
  285|       |
  286|       |	/* if a type-specific check_close is defined we will only exit
  287|       |	   once that has been triggered. this is only used for a server "session"
  288|       |	   channel, to ensure that the shell has exited (and the exit status
  289|       |	   retrieved) before we close things up. */
  290|   185k|	if (!channel->type->check_close
  ------------------
  |  Branch (290:6): [True: 0, False: 185k]
  ------------------
  291|   185k|		|| channel->sent_close
  ------------------
  |  Branch (291:6): [True: 892, False: 184k]
  ------------------
  292|   185k|		|| channel->type->check_close(channel)) {
  ------------------
  |  Branch (292:6): [True: 710, False: 184k]
  ------------------
  293|  1.60k|		close_allowed = 1;
  294|  1.60k|	}
  295|       |
  296|       |	/* In flushing mode we close FDs as soon as pipes are empty.
  297|       |	This is used to drain out FDs when the process exits, in the case
  298|       |	where the FD doesn't have EOF - "sleep 10&echo hello" case */
  299|   185k|	if (channel->flushing) {
  ------------------
  |  Branch (299:6): [True: 0, False: 185k]
  ------------------
  300|      0|		if (channel->readfd >= 0 && !fd_read_pending(channel->readfd)) {
  ------------------
  |  Branch (300:7): [True: 0, False: 0]
  |  Branch (300:31): [True: 0, False: 0]
  ------------------
  301|      0|			close_chan_fd(channel, channel->readfd, SHUT_RD);
  302|      0|		}
  303|      0|		if (ERRFD_IS_READ(channel)
  ------------------
  |  |   59|      0|#define ERRFD_IS_READ(channel) ((channel)->extrabuf == NULL)
  |  |  ------------------
  |  |  |  Branch (59:32): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  304|      0|			&& channel->errfd >= 0 && !fd_read_pending(channel->errfd)) {
  ------------------
  |  Branch (304:7): [True: 0, False: 0]
  |  Branch (304:30): [True: 0, False: 0]
  ------------------
  305|      0|			close_chan_fd(channel, channel->errfd, SHUT_RD);
  306|      0|		}
  307|      0|	}
  308|       |
  309|   185k|	if (channel->recv_close && !write_pending(channel) && close_allowed) {
  ------------------
  |  Branch (309:6): [True: 3.27k, False: 182k]
  |  Branch (309:29): [True: 3.27k, False: 0]
  |  Branch (309:56): [True: 663, False: 2.61k]
  ------------------
  310|    663|		if (!channel->sent_close) {
  ------------------
  |  Branch (310:7): [True: 67, False: 596]
  ------------------
  311|     67|			TRACE(("Sending MSG_CHANNEL_CLOSE in response to same."))
  312|     67|			send_msg_channel_close(channel);
  313|     67|		}
  314|    663|		remove_channel(channel);
  315|    663|		return;
  316|    663|	}
  317|       |
  318|   185k|	if ((channel->recv_eof && !write_pending(channel))
  ------------------
  |  Branch (318:7): [True: 7.31k, False: 177k]
  |  Branch (318:28): [True: 7.31k, False: 0]
  ------------------
  319|       |		/* have a server "session" and child has exited */
  320|   185k|		|| (channel->type->check_close && close_allowed)) {
  ------------------
  |  Branch (320:7): [True: 177k, False: 0]
  |  Branch (320:37): [True: 0, False: 177k]
  ------------------
  321|  7.31k|		close_chan_fd(channel, channel->writefd, SHUT_WR);
  322|  7.31k|	}
  323|       |
  324|       |	/* If we're not going to send any more data, send EOF */
  325|   185k|	if (!channel->sent_eof
  ------------------
  |  Branch (325:6): [True: 184k, False: 627]
  ------------------
  326|   185k|			&& channel->readfd == FD_CLOSED 
  ------------------
  |  |   57|   369k|#define FD_CLOSED (-1)
  ------------------
  |  Branch (326:7): [True: 18.0k, False: 166k]
  ------------------
  327|   185k|			&& (ERRFD_IS_WRITE(channel) || channel->errfd == FD_CLOSED)) {
  ------------------
  |  |   60|  36.1k|#define ERRFD_IS_WRITE(channel) (!ERRFD_IS_READ(channel))
  |  |  ------------------
  |  |  |  |   59|  18.0k|#define ERRFD_IS_READ(channel) ((channel)->extrabuf == NULL)
  |  |  ------------------
  |  |  |  Branch (60:33): [True: 0, False: 18.0k]
  |  |  ------------------
  ------------------
              			&& (ERRFD_IS_WRITE(channel) || channel->errfd == FD_CLOSED)) {
  ------------------
  |  |   57|  18.0k|#define FD_CLOSED (-1)
  ------------------
  |  Branch (327:35): [True: 702, False: 17.3k]
  ------------------
  328|    702|		send_msg_channel_eof(channel);
  329|    702|	}
  330|       |
  331|       |	/* And if we can't receive any more data from them either, close up */
  332|   185k|	if (channel->readfd == FD_CLOSED
  ------------------
  |  |   57|   370k|#define FD_CLOSED (-1)
  ------------------
  |  Branch (332:6): [True: 18.6k, False: 166k]
  ------------------
  333|   185k|			&& channel->writefd == FD_CLOSED
  ------------------
  |  |   57|   203k|#define FD_CLOSED (-1)
  ------------------
  |  Branch (333:7): [True: 3.62k, False: 15.0k]
  ------------------
  334|   185k|			&& (ERRFD_IS_WRITE(channel) || channel->errfd == FD_CLOSED)
  ------------------
  |  |   60|  7.24k|#define ERRFD_IS_WRITE(channel) (!ERRFD_IS_READ(channel))
  |  |  ------------------
  |  |  |  |   59|  3.62k|#define ERRFD_IS_READ(channel) ((channel)->extrabuf == NULL)
  |  |  ------------------
  |  |  |  Branch (60:33): [True: 0, False: 3.62k]
  |  |  ------------------
  ------------------
              			&& (ERRFD_IS_WRITE(channel) || channel->errfd == FD_CLOSED)
  ------------------
  |  |   57|  3.62k|#define FD_CLOSED (-1)
  ------------------
  |  Branch (334:35): [True: 1.22k, False: 2.40k]
  ------------------
  335|   185k|			&& !channel->sent_close
  ------------------
  |  Branch (335:7): [True: 985, False: 237]
  ------------------
  336|   185k|			&& close_allowed
  ------------------
  |  Branch (336:7): [True: 643, False: 342]
  ------------------
  337|   185k|			&& !write_pending(channel)) {
  ------------------
  |  Branch (337:7): [True: 643, False: 0]
  ------------------
  338|    643|		TRACE(("sending close, readfd is closed"))
  339|    643|		send_msg_channel_close(channel);
  340|    643|	}
  341|   185k|}
common-channel.c:close_chan_fd:
 1048|  9.75k|static void close_chan_fd(struct Channel *channel, int fd, int how) {
 1049|       |
 1050|  9.75k|	int closein = 0, closeout = 0;
 1051|       |
 1052|  9.75k|	if (channel->bidir_fd) {
  ------------------
  |  Branch (1052:6): [True: 0, False: 9.75k]
  ------------------
 1053|      0|		TRACE(("SHUTDOWN(%d, %d)", fd, how))
 1054|      0|		shutdown(fd, how);
 1055|      0|		if (how == 0) {
  ------------------
  |  Branch (1055:7): [True: 0, False: 0]
  ------------------
 1056|      0|			closeout = 1;
 1057|      0|		} else {
 1058|      0|			closein = 1;
 1059|      0|		}
 1060|  9.75k|	} else {
 1061|  9.75k|		TRACE(("CLOSE some fd %d", fd))
 1062|  9.75k|		m_close(fd);
 1063|  9.75k|		closein = closeout = 1;
 1064|  9.75k|	}
 1065|       |
 1066|  9.75k|	if (closeout && (fd == channel->readfd)) {
  ------------------
  |  Branch (1066:6): [True: 9.75k, False: 0]
  |  Branch (1066:18): [True: 5.90k, False: 3.85k]
  ------------------
 1067|  5.90k|		channel->readfd = FD_CLOSED;
  ------------------
  |  |   57|  5.90k|#define FD_CLOSED (-1)
  ------------------
 1068|  5.90k|	}
 1069|  9.75k|	if (closeout && ERRFD_IS_READ(channel) && (fd == channel->errfd)) {
  ------------------
  |  |   59|  19.5k|#define ERRFD_IS_READ(channel) ((channel)->extrabuf == NULL)
  |  |  ------------------
  |  |  |  Branch (59:32): [True: 9.75k, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (1069:6): [True: 9.75k, False: 0]
  |  Branch (1069:44): [True: 3.07k, False: 6.68k]
  ------------------
 1070|  3.07k|		channel->errfd = FD_CLOSED;
  ------------------
  |  |   57|  3.07k|#define FD_CLOSED (-1)
  ------------------
 1071|  3.07k|	}
 1072|       |
 1073|  9.75k|	if (closein && fd == channel->writefd) {
  ------------------
  |  Branch (1073:6): [True: 9.75k, False: 0]
  |  Branch (1073:17): [True: 9.46k, False: 297]
  ------------------
 1074|  9.46k|		channel->writefd = FD_CLOSED;
  ------------------
  |  |   57|  9.46k|#define FD_CLOSED (-1)
  ------------------
 1075|  9.46k|	}
 1076|  9.75k|	if (closein && ERRFD_IS_WRITE(channel) && (fd == channel->errfd)) {
  ------------------
  |  |   60|  19.5k|#define ERRFD_IS_WRITE(channel) (!ERRFD_IS_READ(channel))
  |  |  ------------------
  |  |  |  |   59|  9.75k|#define ERRFD_IS_READ(channel) ((channel)->extrabuf == NULL)
  |  |  ------------------
  |  |  |  Branch (60:33): [True: 0, False: 9.75k]
  |  |  ------------------
  ------------------
  |  Branch (1076:6): [True: 9.75k, False: 0]
  |  Branch (1076:44): [True: 0, False: 0]
  ------------------
 1077|      0|		channel->errfd = FD_CLOSED;
  ------------------
  |  |   57|      0|#define FD_CLOSED (-1)
  ------------------
 1078|      0|	}
 1079|       |
 1080|       |	/* if we called shutdown on it and all references are gone, then we 
 1081|       |	 * need to close() it to stop it lingering */
 1082|  9.75k|	if (channel->bidir_fd && channel->readfd == FD_CLOSED 
  ------------------
  |  |   57|  9.75k|#define FD_CLOSED (-1)
  ------------------
  |  Branch (1082:6): [True: 0, False: 9.75k]
  |  Branch (1082:27): [True: 0, False: 0]
  ------------------
 1083|  9.75k|		&& channel->writefd == FD_CLOSED && channel->errfd == FD_CLOSED) {
  ------------------
  |  |   57|  9.75k|#define FD_CLOSED (-1)
  ------------------
              		&& channel->writefd == FD_CLOSED && channel->errfd == FD_CLOSED) {
  ------------------
  |  |   57|      0|#define FD_CLOSED (-1)
  ------------------
  |  Branch (1083:6): [True: 0, False: 0]
  |  Branch (1083:39): [True: 0, False: 0]
  ------------------
 1084|      0|		TRACE(("CLOSE (finally) of %d", fd))
 1085|      0|		m_close(fd);
 1086|      0|	}
 1087|  9.75k|}
common-channel.c:write_pending:
  263|  11.2k|static unsigned int write_pending(const struct Channel * channel) {
  264|       |
  265|  11.2k|	if (channel->writefd >= 0 && cbuf_getused(channel->writebuf) > 0) {
  ------------------
  |  Branch (265:6): [True: 634, False: 10.6k]
  |  Branch (265:31): [True: 0, False: 634]
  ------------------
  266|      0|		return 1;
  267|  11.2k|	} else if (channel->errfd >= 0 && channel->extrabuf && 
  ------------------
  |  Branch (267:13): [True: 8.52k, False: 2.70k]
  |  Branch (267:36): [True: 0, False: 8.52k]
  ------------------
  268|  11.2k|			cbuf_getused(channel->extrabuf) > 0) {
  ------------------
  |  Branch (268:4): [True: 0, False: 0]
  ------------------
  269|      0|		return 1;
  270|      0|	}
  271|  11.2k|	return 0;
  272|  11.2k|}
common-channel.c:send_msg_channel_close:
  372|    710|static void send_msg_channel_close(struct Channel *channel) {
  373|       |
  374|    710|	TRACE(("enter send_msg_channel_close %p", (void*)channel))
  375|    710|	if (channel->type->closehandler) {
  ------------------
  |  Branch (375:6): [True: 710, False: 0]
  ------------------
  376|    710|		channel->type->closehandler(channel);
  377|    710|	}
  378|       |	
  379|    710|	CHECKCLEARTOWRITE();
  380|       |
  381|    710|	buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_CLOSE);
  ------------------
  |  |   73|    710|#define SSH_MSG_CHANNEL_CLOSE                   97
  ------------------
  382|    710|	buf_putint(ses.writepayload, channel->remotechan);
  383|       |
  384|    710|	encrypt_packet();
  385|       |
  386|    710|	channel->sent_eof = 1;
  387|    710|	channel->sent_close = 1;
  388|    710|	close_chan_fd(channel, channel->readfd, SHUT_RD);
  389|    710|	close_chan_fd(channel, channel->errfd, SHUT_RDWR);
  390|    710|	close_chan_fd(channel, channel->writefd, SHUT_WR);
  391|    710|	TRACE(("leave send_msg_channel_close"))
  392|    710|}
common-channel.c:send_msg_channel_eof:
  395|    702|static void send_msg_channel_eof(struct Channel *channel) {
  396|       |
  397|    702|	TRACE(("enter send_msg_channel_eof"))
  398|    702|	CHECKCLEARTOWRITE();
  399|       |
  400|    702|	buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_EOF);
  ------------------
  |  |   72|    702|#define SSH_MSG_CHANNEL_EOF                     96
  ------------------
  401|    702|	buf_putint(ses.writepayload, channel->remotechan);
  402|       |
  403|    702|	encrypt_packet();
  404|       |
  405|    702|	channel->sent_eof = 1;
  406|       |
  407|    702|	TRACE(("leave send_msg_channel_eof"))
  408|    702|}
common-channel.c:writechannel:
  513|     15|	const unsigned char *moredata, unsigned int *morelen) {
  514|     15|	int ret = DROPBEAR_SUCCESS;
  ------------------
  |  |  102|     15|#define DROPBEAR_SUCCESS 0
  ------------------
  515|     15|	TRACE(("enter writechannel fd %d", fd))
  516|     15|#ifdef HAVE_WRITEV
  517|     15|	ret = writechannel_writev(channel, fd, cbuf, moredata, morelen);
  518|       |#else
  519|       |	ret = writechannel_fallback(channel, fd, cbuf, moredata, morelen);
  520|       |#endif
  521|       |
  522|       |	/* Window adjust handling */
  523|     15|	if (channel->recvdonelen >= RECV_WINDOWEXTEND) {
  ------------------
  |  |  221|     15|#define RECV_WINDOWEXTEND (opts.recv_window / 3) /* We send a "window extend" every
  ------------------
  |  Branch (523:6): [True: 0, False: 15]
  ------------------
  524|      0|		send_msg_channel_window_adjust(channel, channel->recvdonelen);
  525|      0|		channel->recvwindow += channel->recvdonelen;
  526|      0|		channel->recvdonelen = 0;
  527|      0|	}
  528|       |
  529|     15|	dropbear_assert(channel->recvwindow <= opts.recv_window);
  ------------------
  |  |   83|     15|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 15]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
  530|     15|	dropbear_assert(channel->recvwindow <= cbuf_getavail(channel->writebuf));
  ------------------
  |  |   83|     15|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 15]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
  531|     15|	dropbear_assert(channel->extrabuf == NULL ||
  ------------------
  |  |   83|     15|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:39): [True: 15, False: 0]
  |  |  |  Branch (83:39): [True: 0, False: 0]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
  532|     15|			channel->recvwindow <= cbuf_getavail(channel->extrabuf));
  533|       |	
  534|     15|	TRACE(("leave writechannel"))
  535|     15|	return ret;
  536|     15|}
common-channel.c:writechannel_writev:
  442|     15|	const unsigned char *moredata, unsigned int *morelen) {
  443|       |
  444|     15|	struct iovec iov[3];
  445|     15|	unsigned char *circ_p1, *circ_p2;
  446|     15|	unsigned int circ_len1, circ_len2;
  447|     15|	int io_count = 0;
  448|       |
  449|     15|	ssize_t written;
  450|       |
  451|     15|	cbuf_readptrs(cbuf, &circ_p1, &circ_len1, &circ_p2, &circ_len2);
  452|       |
  453|     15|	if (circ_len1 > 0) {
  ------------------
  |  Branch (453:6): [True: 0, False: 15]
  ------------------
  454|      0|		TRACE(("circ1 %d", circ_len1))
  455|      0|		iov[io_count].iov_base = circ_p1;
  456|      0|		iov[io_count].iov_len = circ_len1;
  457|      0|		io_count++;
  458|      0|	}
  459|       |
  460|     15|	if (circ_len2 > 0) {
  ------------------
  |  Branch (460:6): [True: 0, False: 15]
  ------------------
  461|      0|		TRACE(("circ2 %d", circ_len2))
  462|      0|		iov[io_count].iov_base = circ_p2;
  463|      0|		iov[io_count].iov_len = circ_len2;
  464|      0|		io_count++;
  465|      0|	}
  466|       |
  467|     15|	if (morelen) {
  ------------------
  |  Branch (467:6): [True: 15, False: 0]
  ------------------
  468|     15|		assert(moredata);
  469|     15|		TRACE(("more %d", *morelen))
  470|     15|		iov[io_count].iov_base = (void*)moredata;
  471|     15|		iov[io_count].iov_len  = *morelen;
  472|     15|		io_count++;
  473|     15|	}
  474|       |
  475|     15|	if (io_count == 0) {
  ------------------
  |  Branch (475:6): [True: 0, False: 15]
  ------------------
  476|       |		/* writechannel may sometimes be called twice in a main loop iteration.
  477|       |		From common_recv_msg_channel_data() then channelio().
  478|       |		The second call may not have any data to write, so we just return. */
  479|      0|		TRACE(("leave writechannel, no data"))
  480|      0|		return DROPBEAR_SUCCESS;
  ------------------
  |  |  102|      0|#define DROPBEAR_SUCCESS 0
  ------------------
  481|      0|	}
  482|       |
  483|     15|	if (morelen) {
  ------------------
  |  Branch (483:6): [True: 15, False: 0]
  ------------------
  484|       |		/* Default return value, none consumed */
  485|     15|		*morelen = 0;
  486|     15|	}
  487|       |
  488|     15|	written = writev(fd, iov, io_count);
  489|       |
  490|     15|	if (written < 0) {
  ------------------
  |  Branch (490:6): [True: 15, False: 0]
  ------------------
  491|     15|		if (errno != EINTR && errno != EAGAIN) {
  ------------------
  |  Branch (491:7): [True: 15, False: 0]
  |  Branch (491:25): [True: 15, False: 0]
  ------------------
  492|     15|			TRACE(("channel IO write error fd %d %s", fd, strerror(errno)))
  493|     15|			close_chan_fd(channel, fd, SHUT_WR);
  494|     15|			return DROPBEAR_FAILURE;
  ------------------
  |  |  103|     15|#define DROPBEAR_FAILURE -1
  ------------------
  495|     15|		}
  496|     15|	} else {
  497|      0|		int cbuf_written = MIN(circ_len1+circ_len2, (unsigned int)written);
  498|      0|		cbuf_incrread(cbuf, cbuf_written);
  499|      0|		if (morelen) {
  ------------------
  |  Branch (499:7): [True: 0, False: 0]
  ------------------
  500|      0|			*morelen = written - cbuf_written;
  501|      0|		}
  502|      0|		channel->recvdonelen += written;
  503|      0|	}
  504|      0|	return DROPBEAR_SUCCESS;
  ------------------
  |  |  102|      0|#define DROPBEAR_SUCCESS 0
  ------------------
  505|     15|}
common-channel.c:remove_channel:
  624|  4.11k|static void remove_channel(struct Channel * channel) {
  625|       |
  626|  4.11k|	TRACE(("enter remove_channel"))
  627|  4.11k|	TRACE(("channel index is %d", channel->index))
  628|       |
  629|  4.11k|	cbuf_free(channel->writebuf);
  630|  4.11k|	channel->writebuf = NULL;
  631|       |
  632|  4.11k|	if (channel->extrabuf) {
  ------------------
  |  Branch (632:6): [True: 0, False: 4.11k]
  ------------------
  633|      0|		cbuf_free(channel->extrabuf);
  634|      0|		channel->extrabuf = NULL;
  635|      0|	}
  636|       |
  637|       |
  638|  4.11k|	if (IS_DROPBEAR_SERVER || (channel->writefd != STDOUT_FILENO)) {
  ------------------
  |  |  319|  8.22k|#define IS_DROPBEAR_SERVER (ses.isserver == 1)
  |  |  ------------------
  |  |  |  Branch (319:28): [True: 4.11k, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (638:28): [True: 0, False: 0]
  ------------------
  639|       |		/* close the FDs in case they haven't been done
  640|       |		 * yet (they might have been shutdown etc) */
  641|  4.11k|		TRACE(("CLOSE writefd %d", channel->writefd))
  642|  4.11k|		m_close(channel->writefd);
  643|  4.11k|		TRACE(("CLOSE readfd %d", channel->readfd))
  644|  4.11k|		m_close(channel->readfd);
  645|  4.11k|		TRACE(("CLOSE errfd %d", channel->errfd))
  646|  4.11k|		m_close(channel->errfd);
  647|  4.11k|	}
  648|       |
  649|  4.11k|	if (channel->type->cleanup) {
  ------------------
  |  Branch (649:6): [True: 3.78k, False: 323]
  ------------------
  650|  3.78k|		channel->type->cleanup(channel);
  651|  3.78k|	}
  652|       |
  653|  4.11k|	if (channel->conn_pending) {
  ------------------
  |  Branch (653:6): [True: 98, False: 4.01k]
  ------------------
  654|     98|		cancel_connect(channel->conn_pending);
  655|     98|	}
  656|       |
  657|  4.11k|	ses.channels[channel->index] = NULL;
  658|  4.11k|	m_free(channel);
  ------------------
  |  |   24|  4.11k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  659|  4.11k|	ses.chancount--;
  660|       |
  661|  4.11k|	update_channel_prio();
  662|       |
  663|  4.11k|	TRACE(("leave remove_channel"))
  664|  4.11k|}
common-channel.c:send_msg_channel_data:
  696|   206k|static void send_msg_channel_data(struct Channel *channel, int isextended) {
  697|       |
  698|   206k|	int len;
  699|   206k|	size_t maxlen, size_pos;
  700|   206k|	int fd;
  701|       |
  702|   206k|	CHECKCLEARTOWRITE();
  703|       |
  704|   206k|	TRACE(("enter send_msg_channel_data"))
  705|   206k|	dropbear_assert(!channel->sent_close);
  ------------------
  |  |   83|   206k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 1, False: 206k]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
  706|       |
  707|   206k|	if (isextended) {
  ------------------
  |  Branch (707:6): [True: 99.8k, False: 106k]
  ------------------
  708|  99.8k|		fd = channel->errfd;
  709|   106k|	} else {
  710|   106k|		fd = channel->readfd;
  711|   106k|	}
  712|   206k|	TRACE(("enter send_msg_channel_data isextended %d fd %d", isextended, fd))
  713|   206k|	dropbear_assert(fd >= 0);
  ------------------
  |  |   83|   206k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 206k]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
  714|       |
  715|   206k|	maxlen = MIN(channel->transwindow, channel->transmaxpacket);
  716|       |	/* -(1+4+4) is SSH_MSG_CHANNEL_DATA, channel number, string length, and 
  717|       |	 * exttype if is extended */
  718|   206k|	maxlen = MIN(maxlen, 
  719|   206k|			ses.writepayload->size - 1 - 4 - 4 - (isextended ? 4 : 0));
  720|   206k|	TRACE(("maxlen %zd", maxlen))
  721|   206k|	if (maxlen == 0) {
  ------------------
  |  Branch (721:6): [True: 1.50k, False: 205k]
  ------------------
  722|  1.50k|		TRACE(("leave send_msg_channel_data: no window"))
  723|  1.50k|		return;
  724|  1.50k|	}
  725|       |
  726|   205k|	buf_putbyte(ses.writepayload, 
  727|   205k|			isextended ? SSH_MSG_CHANNEL_EXTENDED_DATA : SSH_MSG_CHANNEL_DATA);
  ------------------
  |  |   71|  99.1k|#define SSH_MSG_CHANNEL_EXTENDED_DATA           95
  ------------------
              			isextended ? SSH_MSG_CHANNEL_EXTENDED_DATA : SSH_MSG_CHANNEL_DATA);
  ------------------
  |  |   70|   311k|#define SSH_MSG_CHANNEL_DATA                    94
  ------------------
  |  Branch (727:4): [True: 99.1k, False: 106k]
  ------------------
  728|   205k|	buf_putint(ses.writepayload, channel->remotechan);
  729|   205k|	if (isextended) {
  ------------------
  |  Branch (729:6): [True: 99.1k, False: 106k]
  ------------------
  730|  99.1k|		buf_putint(ses.writepayload, SSH_EXTENDED_DATA_STDERR);
  ------------------
  |  |   79|  99.1k|#define SSH_EXTENDED_DATA_STDERR	1
  ------------------
  731|  99.1k|	}
  732|       |	/* a dummy size first ...*/
  733|   205k|	size_pos = ses.writepayload->pos;
  734|   205k|	buf_putint(ses.writepayload, 0);
  735|       |
  736|       |	/* read the data */
  737|   205k|	len = read(fd, buf_getwriteptr(ses.writepayload, maxlen), maxlen);
  ------------------
  |  |   55|   205k|#define read(fd, buf, count) wrapfd_read(fd, buf, count)
  ------------------
  738|       |
  739|   205k|	if (len <= 0) {
  ------------------
  |  Branch (739:6): [True: 626, False: 204k]
  ------------------
  740|    626|		if (len == 0 || errno != EINTR) {
  ------------------
  |  Branch (740:7): [True: 0, False: 626]
  |  Branch (740:19): [True: 297, False: 329]
  ------------------
  741|       |			/* This will also get hit in the case of EAGAIN. The only
  742|       |			time we expect to receive EAGAIN is when we're flushing a FD,
  743|       |			in which case it can be treated the same as EOF */
  744|    297|			close_chan_fd(channel, fd, SHUT_RD);
  745|    297|		}
  746|    626|		buf_setpos(ses.writepayload, 0);
  747|    626|		buf_setlen(ses.writepayload, 0);
  748|    626|		TRACE(("leave send_msg_channel_data: len %d read err %d or EOF for fd %d", 
  749|    626|					len, errno, fd))
  750|    626|		return;
  751|    626|	}
  752|       |
  753|   204k|	if (channel->read_mangler) {
  ------------------
  |  Branch (753:6): [True: 0, False: 204k]
  ------------------
  754|      0|		channel->read_mangler(channel, buf_getwriteptr(ses.writepayload, len), &len);
  755|      0|		if (len == 0) {
  ------------------
  |  Branch (755:7): [True: 0, False: 0]
  ------------------
  756|      0|			buf_setpos(ses.writepayload, 0);
  757|      0|			buf_setlen(ses.writepayload, 0);
  758|      0|			return;
  759|      0|		}
  760|      0|	}
  761|       |
  762|   204k|	TRACE(("send_msg_channel_data: len %d fd %d", len, fd))
  763|   204k|	buf_incrwritepos(ses.writepayload, len);
  764|       |	/* ... real size here */
  765|   204k|	buf_setpos(ses.writepayload, size_pos);
  766|   204k|	buf_putint(ses.writepayload, len);
  767|       |
  768|   204k|	channel->transwindow -= len;
  769|       |
  770|   204k|	encrypt_packet();
  771|   204k|	TRACE(("leave send_msg_channel_data"))
  772|   204k|}
common-channel.c:newchannel:
  108|  4.11k|		unsigned int transwindow, unsigned int transmaxpacket) {
  109|       |
  110|  4.11k|	struct Channel * newchan;
  111|  4.11k|	unsigned int i, j;
  112|       |
  113|  4.11k|	TRACE(("enter newchannel"))
  114|       |	
  115|       |	/* first see if we can use existing channels */
  116|  56.8k|	for (i = 0; i < ses.chansize; i++) {
  ------------------
  |  Branch (116:14): [True: 55.8k, False: 985]
  ------------------
  117|  55.8k|		if (ses.channels[i] == NULL) {
  ------------------
  |  Branch (117:7): [True: 3.12k, False: 52.7k]
  ------------------
  118|  3.12k|			break;
  119|  3.12k|		}
  120|  55.8k|	}
  121|       |
  122|       |	/* otherwise extend the list */
  123|  4.11k|	if (i == ses.chansize) {
  ------------------
  |  Branch (123:6): [True: 985, False: 3.12k]
  ------------------
  124|    985|		if (ses.chansize >= MAX_CHANNELS) {
  ------------------
  |  |  225|    985|#define MAX_CHANNELS 1000 /* simple mem restriction, includes each tcp/x11
  ------------------
  |  Branch (124:7): [True: 0, False: 985]
  ------------------
  125|      0|			TRACE(("leave newchannel: max chans reached"))
  126|      0|			return NULL;
  127|      0|		}
  128|       |
  129|       |		/* extend the channels */
  130|    985|		ses.channels = (struct Channel**)m_realloc(ses.channels,
  131|    985|				(ses.chansize+CHAN_EXTEND_SIZE)*sizeof(struct Channel*));
  ------------------
  |  |   41|    985|#define CHAN_EXTEND_SIZE 3 /* how many extra slots to add when we need more */
  ------------------
  132|       |
  133|    985|		ses.chansize += CHAN_EXTEND_SIZE;
  ------------------
  |  |   41|    985|#define CHAN_EXTEND_SIZE 3 /* how many extra slots to add when we need more */
  ------------------
  134|       |
  135|       |		/* set the new channels to null */
  136|  3.94k|		for (j = i; j < ses.chansize; j++) {
  ------------------
  |  Branch (136:15): [True: 2.95k, False: 985]
  ------------------
  137|  2.95k|			ses.channels[j] = NULL;
  138|  2.95k|		}
  139|       |
  140|    985|	}
  141|       |	
  142|  4.11k|	newchan = (struct Channel*)m_malloc(sizeof(struct Channel));
  143|  4.11k|	newchan->type = type;
  144|  4.11k|	newchan->index = i;
  145|  4.11k|	newchan->sent_close = newchan->recv_close = 0;
  146|  4.11k|	newchan->sent_eof = newchan->recv_eof = 0;
  147|       |
  148|  4.11k|	newchan->remotechan = remotechan;
  149|  4.11k|	newchan->transwindow = transwindow;
  150|  4.11k|	newchan->transmaxpacket = transmaxpacket;
  151|       |	
  152|  4.11k|	newchan->typedata = NULL;
  153|  4.11k|	newchan->writefd = FD_UNINIT;
  ------------------
  |  |   56|  4.11k|#define FD_UNINIT (-2)
  ------------------
  154|  4.11k|	newchan->readfd = FD_UNINIT;
  ------------------
  |  |   56|  4.11k|#define FD_UNINIT (-2)
  ------------------
  155|  4.11k|	newchan->errfd = FD_CLOSED; /* this isn't always set to start with */
  ------------------
  |  |   57|  4.11k|#define FD_CLOSED (-1)
  ------------------
  156|  4.11k|	newchan->await_open = 0;
  157|       |
  158|  4.11k|	newchan->writebuf = cbuf_new(opts.recv_window);
  159|  4.11k|	newchan->recvwindow = opts.recv_window;
  160|       |
  161|  4.11k|	newchan->extrabuf = NULL; /* The user code can set it up */
  162|  4.11k|	newchan->recvdonelen = 0;
  163|  4.11k|	newchan->recvmaxpacket = RECV_MAX_CHANNEL_DATA_LEN;
  ------------------
  |  |   67|  4.11k|#define RECV_MAX_CHANNEL_DATA_LEN (RECV_MAX_PAYLOAD_LEN-(1+4+4))
  |  |  ------------------
  |  |  |  |  492|  4.11k|#define RECV_MAX_PAYLOAD_LEN 32768
  |  |  ------------------
  ------------------
  164|       |
  165|  4.11k|	newchan->prio = DROPBEAR_PRIO_NORMAL;
  166|       |
  167|  4.11k|	ses.channels[i] = newchan;
  168|  4.11k|	ses.chancount++;
  169|       |
  170|  4.11k|	TRACE(("leave newchannel"))
  171|       |
  172|  4.11k|	return newchan;
  173|  4.11k|}
common-channel.c:send_msg_channel_open_failure:
 1013|  1.21k|		int reason, const char *text, const char *lang) {
 1014|       |
 1015|  1.21k|	TRACE(("enter send_msg_channel_open_failure"))
 1016|  1.21k|	CHECKCLEARTOWRITE();
 1017|       |	
 1018|  1.21k|	buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_OPEN_FAILURE);
  ------------------
  |  |   68|  1.21k|#define SSH_MSG_CHANNEL_OPEN_FAILURE            92
  ------------------
 1019|  1.21k|	buf_putint(ses.writepayload, remotechan);
 1020|  1.21k|	buf_putint(ses.writepayload, reason);
 1021|  1.21k|	buf_putstring(ses.writepayload, text, strlen(text));
 1022|  1.21k|	buf_putstring(ses.writepayload, lang, strlen(lang));
 1023|       |
 1024|  1.21k|	encrypt_packet();
 1025|  1.21k|	TRACE(("leave send_msg_channel_open_failure"))
 1026|  1.21k|}
common-channel.c:send_msg_channel_open_confirmation:
 1032|  3.78k|		unsigned int recvmaxpacket) {
 1033|       |
 1034|  3.78k|	TRACE(("enter send_msg_channel_open_confirmation"))
 1035|  3.78k|	CHECKCLEARTOWRITE();
 1036|       |
 1037|  3.78k|	buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_OPEN_CONFIRMATION);
  ------------------
  |  |   67|  3.78k|#define SSH_MSG_CHANNEL_OPEN_CONFIRMATION       91 
  ------------------
 1038|  3.78k|	buf_putint(ses.writepayload, channel->remotechan);
 1039|  3.78k|	buf_putint(ses.writepayload, channel->index);
 1040|  3.78k|	buf_putint(ses.writepayload, recvwindow);
 1041|  3.78k|	buf_putint(ses.writepayload, recvmaxpacket);
 1042|       |
 1043|  3.78k|	encrypt_packet();
 1044|  3.78k|	TRACE(("leave send_msg_channel_open_confirmation"))
 1045|  3.78k|}

send_msg_kexinit:
   55|  9.65k|void send_msg_kexinit() {
   56|       |
   57|  9.65k|	CHECKCLEARTOWRITE();
   58|  9.65k|	buf_putbyte(ses.writepayload, SSH_MSG_KEXINIT);
  ------------------
  |  |   36|  9.65k|#define SSH_MSG_KEXINIT                20
  ------------------
   59|       |
   60|       |	/* cookie */
   61|  9.65k|	genrandom(buf_getwriteptr(ses.writepayload, 16), 16);
   62|  9.65k|	buf_incrwritepos(ses.writepayload, 16);
   63|       |
   64|       |	/* kex algos */
   65|  9.65k|	buf_put_algolist(ses.writepayload, sshkex);
   66|       |
   67|       |	/* server_host_key_algorithms */
   68|  9.65k|	buf_put_algolist(ses.writepayload, sigalgs);
   69|       |
   70|       |	/* encryption_algorithms_client_to_server */
   71|  9.65k|	buf_put_algolist(ses.writepayload, sshciphers);
   72|       |
   73|       |	/* encryption_algorithms_server_to_client */
   74|  9.65k|	buf_put_algolist(ses.writepayload, sshciphers);
   75|       |
   76|       |	/* mac_algorithms_client_to_server */
   77|  9.65k|	buf_put_algolist(ses.writepayload, sshhashes);
   78|       |
   79|       |	/* mac_algorithms_server_to_client */
   80|  9.65k|	buf_put_algolist(ses.writepayload, sshhashes);
   81|       |
   82|       |
   83|       |	/* compression_algorithms_client_to_server */
   84|  9.65k|	buf_put_algolist(ses.writepayload, ses.compress_algos);
   85|       |
   86|       |	/* compression_algorithms_server_to_client */
   87|  9.65k|	buf_put_algolist(ses.writepayload, ses.compress_algos);
   88|       |
   89|       |	/* languages_client_to_server */
   90|  9.65k|	buf_putstring(ses.writepayload, "", 0);
   91|       |
   92|       |	/* languages_server_to_client */
   93|  9.65k|	buf_putstring(ses.writepayload, "", 0);
   94|       |
   95|       |	/* first_kex_packet_follows */
   96|  9.65k|	buf_putbyte(ses.writepayload, (ses.send_kex_first_guess != NULL));
   97|       |
   98|       |	/* reserved unit32 */
   99|  9.65k|	buf_putint(ses.writepayload, 0);
  100|       |
  101|       |	/* set up transmitted kex packet buffer for hashing. 
  102|       |	 * This is freed after the end of the kex */
  103|  9.65k|	ses.transkexinit = buf_newcopy(ses.writepayload);
  104|       |
  105|  9.65k|	encrypt_packet();
  106|  9.65k|	ses.dataallowed = 0; /* don't send other packets during kex */
  107|       |
  108|  9.65k|	ses.kexstate.sentkexinit = 1;
  109|       |
  110|  9.65k|	ses.newkeys = (struct key_context*)m_malloc(sizeof(struct key_context));
  111|       |
  112|  9.65k|	if (ses.send_kex_first_guess) {
  ------------------
  |  Branch (112:6): [True: 0, False: 9.65k]
  ------------------
  113|      0|		ses.newkeys->algo_kex = first_usable_algo(sshkex)->data;
  114|      0|		ses.newkeys->algo_signature = first_usable_algo(sigalgs)->val;
  115|      0|		ses.newkeys->algo_hostkey = signkey_type_from_signature(ses.newkeys->algo_signature);
  116|      0|		ses.send_kex_first_guess();
  117|      0|	}
  118|       |
  119|  9.65k|	TRACE(("DATAALLOWED=0"))
  120|  9.65k|	TRACE(("-> KEXINIT"))
  121|       |
  122|  9.65k|}
send_msg_newkeys:
  166|  9.27k|void send_msg_newkeys() {
  167|       |
  168|  9.27k|	TRACE(("enter send_msg_newkeys"))
  169|       |
  170|       |	/* generate the kexinit request */
  171|  9.27k|	CHECKCLEARTOWRITE();
  172|  9.27k|	buf_putbyte(ses.writepayload, SSH_MSG_NEWKEYS);
  ------------------
  |  |   37|  9.27k|#define SSH_MSG_NEWKEYS                21
  ------------------
  173|  9.27k|	encrypt_packet();
  174|       |
  175|       |	
  176|       |	/* set up our state */
  177|  9.27k|	ses.kexstate.sentnewkeys = 1;
  178|  9.27k|	if (ses.kexstate.donefirstkex) {
  ------------------
  |  Branch (178:6): [True: 7.96k, False: 1.31k]
  ------------------
  179|  7.96k|		ses.kexstate.donesecondkex = 1;
  180|  7.96k|	}
  181|  9.27k|	ses.kexstate.donefirstkex = 1;
  182|  9.27k|	ses.dataallowed = 1; /* we can send other packets again now */
  183|  9.27k|	gen_new_keys();
  184|  9.27k|	switch_keys();
  185|       |
  186|  9.27k|	TRACE(("leave send_msg_newkeys"))
  187|  9.27k|}
recv_msg_newkeys:
  190|  9.07k|void recv_msg_newkeys() {
  191|       |
  192|  9.07k|	TRACE(("enter recv_msg_newkeys"))
  193|       |
  194|  9.07k|	ses.kexstate.recvnewkeys = 1;
  195|  9.07k|	switch_keys();
  196|       |	
  197|  9.07k|	TRACE(("leave recv_msg_newkeys"))
  198|  9.07k|}
kexfirstinitialise:
  202|  1.49k|void kexfirstinitialise() {
  203|  1.49k|#ifdef DISABLE_ZLIB
  204|  1.49k|	ses.compress_algos = ssh_nocompress;
  205|       |#else
  206|       |	switch (opts.compress_mode)
  207|       |	{
  208|       |		case DROPBEAR_COMPRESS_DELAYED:
  209|       |			ses.compress_algos = ssh_delaycompress;
  210|       |			break;
  211|       |
  212|       |		case DROPBEAR_COMPRESS_ON:
  213|       |			ses.compress_algos = ssh_compress;
  214|       |			break;
  215|       |
  216|       |		case DROPBEAR_COMPRESS_OFF:
  217|       |			ses.compress_algos = ssh_nocompress;
  218|       |			break;
  219|       |	}
  220|       |#endif
  221|  1.49k|	kexinitialise();
  222|  1.49k|}
recv_msg_kexinit:
  474|  9.58k|void recv_msg_kexinit() {
  475|       |	
  476|  9.58k|	unsigned int kexhashbuf_len = 0;
  477|  9.58k|	unsigned int remote_ident_len = 0;
  478|  9.58k|	unsigned int local_ident_len = 0;
  479|       |
  480|  9.58k|	TRACE(("<- KEXINIT"))
  481|  9.58k|	TRACE(("enter recv_msg_kexinit"))
  482|       |	
  483|  9.58k|	if (!ses.kexstate.sentkexinit) {
  ------------------
  |  Branch (483:6): [True: 8.16k, False: 1.42k]
  ------------------
  484|       |		/* we need to send a kex packet */
  485|  8.16k|		send_msg_kexinit();
  486|  8.16k|		TRACE(("continue recv_msg_kexinit: sent kexinit"))
  487|  8.16k|	}
  488|       |
  489|       |	/* "Once a party has sent a SSH_MSG_KEXINIT message ...
  490|       |	further SSH_MSG_KEXINIT messages MUST NOT be sent" */
  491|  9.58k|	if (ses.kexstate.recvkexinit) {
  ------------------
  |  Branch (491:6): [True: 0, False: 9.58k]
  ------------------
  492|      0|		dropbear_exit("Unexpected KEXINIT");
  493|      0|	}
  494|       |
  495|       |	/* start the kex hash */
  496|  9.58k|	local_ident_len = strlen(LOCAL_IDENT);
  ------------------
  |  |   10|  9.58k|#define LOCAL_IDENT "SSH-2.0-dropbear_" DROPBEAR_VERSION
  |  |  ------------------
  |  |  |  |    7|  9.58k|#define DROPBEAR_VERSION "2022.83"
  |  |  ------------------
  ------------------
  497|  9.58k|	remote_ident_len = strlen(ses.remoteident);
  498|       |
  499|  9.58k|	kexhashbuf_len = local_ident_len + remote_ident_len
  500|  9.58k|		+ ses.transkexinit->len + ses.payload->len
  501|  9.58k|		+ KEXHASHBUF_MAX_INTS;
  ------------------
  |  |  240|  9.58k|#define KEXHASHBUF_MAX_INTS (1700 + 130 + 130 + 130)
  ------------------
  502|       |
  503|  9.58k|	ses.kexhashbuf = buf_new(kexhashbuf_len);
  504|       |
  505|  9.58k|	if (IS_DROPBEAR_CLIENT) {
  ------------------
  |  |  320|  9.58k|#define IS_DROPBEAR_CLIENT (ses.isserver == 0)
  |  |  ------------------
  |  |  |  Branch (320:28): [True: 0, False: 9.58k]
  |  |  ------------------
  ------------------
  506|       |
  507|       |		/* read the peer's choice of algos */
  508|      0|		read_kex_algos();
  509|       |
  510|       |		/* V_C, the client's version string (CR and NL excluded) */
  511|      0|		buf_putstring(ses.kexhashbuf, LOCAL_IDENT, local_ident_len);
  ------------------
  |  |   10|      0|#define LOCAL_IDENT "SSH-2.0-dropbear_" DROPBEAR_VERSION
  |  |  ------------------
  |  |  |  |    7|      0|#define DROPBEAR_VERSION "2022.83"
  |  |  ------------------
  ------------------
  512|       |		/* V_S, the server's version string (CR and NL excluded) */
  513|      0|		buf_putstring(ses.kexhashbuf, ses.remoteident, remote_ident_len);
  514|       |
  515|       |		/* I_C, the payload of the client's SSH_MSG_KEXINIT */
  516|      0|		buf_putstring(ses.kexhashbuf,
  517|      0|			(const char*)ses.transkexinit->data, ses.transkexinit->len);
  518|       |		/* I_S, the payload of the server's SSH_MSG_KEXINIT */
  519|      0|		buf_setpos(ses.payload, ses.payload_beginning);
  520|      0|		buf_putstring(ses.kexhashbuf,
  521|      0|			(const char*)buf_getptr(ses.payload, ses.payload->len-ses.payload->pos),
  522|      0|			ses.payload->len-ses.payload->pos);
  523|      0|		ses.requirenext = SSH_MSG_KEXDH_REPLY;
  ------------------
  |  |   39|      0|#define SSH_MSG_KEXDH_REPLY            31
  ------------------
  524|  9.58k|	} else {
  525|       |		/* SERVER */
  526|       |
  527|       |		/* read the peer's choice of algos */
  528|  9.58k|		read_kex_algos();
  529|       |		/* V_C, the client's version string (CR and NL excluded) */
  530|  9.58k|		buf_putstring(ses.kexhashbuf, ses.remoteident, remote_ident_len);
  531|       |		/* V_S, the server's version string (CR and NL excluded) */
  532|  9.58k|		buf_putstring(ses.kexhashbuf, LOCAL_IDENT, local_ident_len);
  ------------------
  |  |   10|  9.58k|#define LOCAL_IDENT "SSH-2.0-dropbear_" DROPBEAR_VERSION
  |  |  ------------------
  |  |  |  |    7|  9.58k|#define DROPBEAR_VERSION "2022.83"
  |  |  ------------------
  ------------------
  533|       |
  534|       |		/* I_C, the payload of the client's SSH_MSG_KEXINIT */
  535|  9.58k|		buf_setpos(ses.payload, ses.payload_beginning);
  536|  9.58k|		buf_putstring(ses.kexhashbuf, 
  537|  9.58k|			(const char*)buf_getptr(ses.payload, ses.payload->len-ses.payload->pos),
  538|  9.58k|			ses.payload->len-ses.payload->pos);
  539|       |
  540|       |		/* I_S, the payload of the server's SSH_MSG_KEXINIT */
  541|  9.58k|		buf_putstring(ses.kexhashbuf,
  542|  9.58k|			(const char*)ses.transkexinit->data, ses.transkexinit->len);
  543|       |
  544|  9.58k|		ses.requirenext = SSH_MSG_KEXDH_INIT;
  ------------------
  |  |   38|  9.58k|#define SSH_MSG_KEXDH_INIT             30
  ------------------
  545|  9.58k|	}
  546|       |
  547|  9.58k|	buf_free(ses.transkexinit);
  548|  9.58k|	ses.transkexinit = NULL;
  549|       |	/* the rest of ses.kexhashbuf will be done after DH exchange */
  550|       |
  551|  9.58k|	ses.kexstate.recvkexinit = 1;
  552|       |
  553|  9.58k|	TRACE(("leave recv_msg_kexinit"))
  554|  9.58k|}
finish_kexhashbuf:
  786|  9.27k|void finish_kexhashbuf(void) {
  787|  9.27k|	hash_state hs;
  788|  9.27k|	const struct ltc_hash_descriptor *hash_desc = ses.newkeys->algo_kex->hash_desc;
  789|       |
  790|  9.27k|	hash_desc->init(&hs);
  791|  9.27k|	buf_setpos(ses.kexhashbuf, 0);
  792|  9.27k|	hash_desc->process(&hs, buf_getptr(ses.kexhashbuf, ses.kexhashbuf->len),
  793|  9.27k|			ses.kexhashbuf->len);
  794|  9.27k|	ses.hash = buf_new(hash_desc->hashsize);
  795|  9.27k|	hash_desc->done(&hs, buf_getwriteptr(ses.hash, hash_desc->hashsize));
  796|  9.27k|	buf_setlen(ses.hash, hash_desc->hashsize);
  797|       |
  798|       |#if defined(DEBUG_KEXHASH) && DEBUG_TRACE
  799|       |	if (!debug_trace) {
  800|       |		printhex("kexhashbuf", ses.kexhashbuf->data, ses.kexhashbuf->len);
  801|       |		printhex("kexhash", ses.hash->data, ses.hash->len);
  802|       |	}
  803|       |#endif
  804|       |
  805|  9.27k|	buf_burn_free(ses.kexhashbuf);
  806|  9.27k|	m_burn(&hs, sizeof(hash_state));
  807|  9.27k|	ses.kexhashbuf = NULL;
  808|       |	
  809|       |	/* first time around, we set the session_id to H */
  810|  9.27k|	if (ses.session_id == NULL) {
  ------------------
  |  Branch (810:6): [True: 1.31k, False: 7.96k]
  ------------------
  811|       |		/* create the session_id, this never needs freeing */
  812|  1.31k|		ses.session_id = buf_newcopy(ses.hash);
  813|  1.31k|	}
  814|  9.27k|}
common-kex.c:switch_keys:
  124|  18.3k|static void switch_keys() {
  125|  18.3k|	TRACE2(("enter switch_keys"))
  126|  18.3k|	if (!(ses.kexstate.sentkexinit && ses.kexstate.recvkexinit)) {
  ------------------
  |  Branch (126:8): [True: 18.3k, False: 8]
  |  Branch (126:36): [True: 18.3k, False: 0]
  ------------------
  127|      8|		dropbear_exit("Unexpected newkeys message");
  128|      8|	}
  129|       |
  130|  18.3k|	if (!ses.keys) {
  ------------------
  |  Branch (130:6): [True: 0, False: 18.3k]
  ------------------
  131|      0|		ses.keys = m_malloc(sizeof(*ses.newkeys));
  132|      0|	}
  133|  18.3k|	if (ses.kexstate.recvnewkeys && ses.newkeys->recv.valid) {
  ------------------
  |  Branch (133:6): [True: 9.06k, False: 9.27k]
  |  Branch (133:34): [True: 9.06k, False: 0]
  ------------------
  134|  9.06k|		TRACE(("switch_keys recv"))
  135|       |#ifndef DISABLE_ZLIB
  136|       |		gen_new_zstream_recv();
  137|       |#endif
  138|  9.06k|		ses.keys->recv = ses.newkeys->recv;
  139|  9.06k|		m_burn(&ses.newkeys->recv, sizeof(ses.newkeys->recv));
  140|  9.06k|		ses.newkeys->recv.valid = 0;
  141|  9.06k|	}
  142|  18.3k|	if (ses.kexstate.sentnewkeys && ses.newkeys->trans.valid) {
  ------------------
  |  Branch (142:6): [True: 18.3k, False: 0]
  |  Branch (142:34): [True: 9.27k, False: 9.06k]
  ------------------
  143|  9.27k|		TRACE(("switch_keys trans"))
  144|       |#ifndef DISABLE_ZLIB
  145|       |		gen_new_zstream_trans();
  146|       |#endif
  147|  9.27k|		ses.keys->trans = ses.newkeys->trans;
  148|  9.27k|		m_burn(&ses.newkeys->trans, sizeof(ses.newkeys->trans));
  149|  9.27k|		ses.newkeys->trans.valid = 0;
  150|  9.27k|	}
  151|  18.3k|	if (ses.kexstate.sentnewkeys && ses.kexstate.recvnewkeys)
  ------------------
  |  Branch (151:6): [True: 18.3k, False: 0]
  |  Branch (151:34): [True: 9.06k, False: 9.27k]
  ------------------
  152|  9.06k|	{
  153|  9.06k|		TRACE(("switch_keys done"))
  154|  9.06k|		ses.keys->algo_kex = ses.newkeys->algo_kex;
  155|  9.06k|		ses.keys->algo_hostkey = ses.newkeys->algo_hostkey;
  156|  9.06k|		ses.keys->algo_signature = ses.newkeys->algo_signature;
  157|  9.06k|		ses.keys->allow_compress = 0;
  158|  9.06k|		m_free(ses.newkeys);
  ------------------
  |  |   24|  9.06k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  159|  9.06k|		ses.newkeys = NULL;
  160|  9.06k|		kexinitialise();
  161|  9.06k|	}
  162|  18.3k|	TRACE2(("leave switch_keys"))
  163|  18.3k|}
common-kex.c:kexinitialise:
  225|  10.5k|static void kexinitialise() {
  226|       |
  227|  10.5k|	TRACE(("kexinitialise()"))
  228|       |
  229|       |	/* sent/recv'd MSG_KEXINIT */
  230|  10.5k|	ses.kexstate.sentkexinit = 0;
  231|  10.5k|	ses.kexstate.recvkexinit = 0;
  232|       |
  233|       |	/* sent/recv'd MSG_NEWKEYS */
  234|  10.5k|	ses.kexstate.recvnewkeys = 0;
  235|  10.5k|	ses.kexstate.sentnewkeys = 0;
  236|       |
  237|       |	/* first_packet_follows */
  238|  10.5k|	ses.kexstate.them_firstfollows = 0;
  239|       |
  240|  10.5k|	ses.kexstate.datatrans = 0;
  241|  10.5k|	ses.kexstate.datarecv = 0;
  242|       |
  243|  10.5k|	ses.kexstate.our_first_follows_matches = 0;
  244|       |
  245|  10.5k|	ses.kexstate.lastkextime = monotonic_now();
  246|       |
  247|  10.5k|}
common-kex.c:gen_new_keys:
  288|  9.27k|static void gen_new_keys() {
  289|       |
  290|  9.27k|	unsigned char C2S_IV[MAX_IV_LEN];
  291|  9.27k|	unsigned char C2S_key[MAX_KEY_LEN];
  292|  9.27k|	unsigned char S2C_IV[MAX_IV_LEN];
  293|  9.27k|	unsigned char S2C_key[MAX_KEY_LEN];
  294|       |	/* unsigned char key[MAX_KEY_LEN]; */
  295|  9.27k|	unsigned char *trans_IV, *trans_key, *recv_IV, *recv_key;
  296|       |
  297|  9.27k|	hash_state hs;
  298|  9.27k|	const struct ltc_hash_descriptor *hash_desc = ses.newkeys->algo_kex->hash_desc;
  299|  9.27k|	char mactransletter, macrecvletter; /* Client or server specific */
  300|       |
  301|  9.27k|	TRACE(("enter gen_new_keys"))
  302|       |	/* the dh_K and hash are the start of all hashes, we make use of that */
  303|       |
  304|  9.27k|	hash_desc->init(&hs);
  305|  9.27k|	hash_process_mp(hash_desc, &hs, ses.dh_K);
  306|  9.27k|	mp_clear(ses.dh_K);
  307|  9.27k|	m_free(ses.dh_K);
  ------------------
  |  |   24|  9.27k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  308|  9.27k|	hash_desc->process(&hs, ses.hash->data, ses.hash->len);
  309|  9.27k|	buf_burn_free(ses.hash);
  310|  9.27k|	ses.hash = NULL;
  311|       |
  312|  9.27k|	if (IS_DROPBEAR_CLIENT) {
  ------------------
  |  |  320|  9.27k|#define IS_DROPBEAR_CLIENT (ses.isserver == 0)
  |  |  ------------------
  |  |  |  Branch (320:28): [True: 0, False: 9.27k]
  |  |  ------------------
  ------------------
  313|      0|		trans_IV	= C2S_IV;
  314|      0|		recv_IV		= S2C_IV;
  315|      0|		trans_key	= C2S_key;
  316|      0|		recv_key	= S2C_key;
  317|      0|		mactransletter = 'E';
  318|      0|		macrecvletter = 'F';
  319|  9.27k|	} else {
  320|  9.27k|		trans_IV	= S2C_IV;
  321|  9.27k|		recv_IV		= C2S_IV;
  322|  9.27k|		trans_key	= S2C_key;
  323|  9.27k|		recv_key	= C2S_key;
  324|  9.27k|		mactransletter = 'F';
  325|  9.27k|		macrecvletter = 'E';
  326|  9.27k|	}
  327|       |
  328|  9.27k|	hashkeys(C2S_IV, sizeof(C2S_IV), &hs, 'A');
  329|  9.27k|	hashkeys(S2C_IV, sizeof(S2C_IV), &hs, 'B');
  330|  9.27k|	hashkeys(C2S_key, sizeof(C2S_key), &hs, 'C');
  331|  9.27k|	hashkeys(S2C_key, sizeof(S2C_key), &hs, 'D');
  332|       |
  333|  9.27k|	if (ses.newkeys->recv.algo_crypt->cipherdesc != NULL) {
  ------------------
  |  Branch (333:6): [True: 9.27k, False: 0]
  ------------------
  334|  9.27k|		int recv_cipher = -1;
  335|  9.27k|		if (ses.newkeys->recv.algo_crypt->cipherdesc->name != NULL) {
  ------------------
  |  Branch (335:7): [True: 3.16k, False: 6.11k]
  ------------------
  336|  3.16k|			recv_cipher = find_cipher(ses.newkeys->recv.algo_crypt->cipherdesc->name);
  337|  3.16k|			if (recv_cipher < 0) {
  ------------------
  |  Branch (337:8): [True: 0, False: 3.16k]
  ------------------
  338|      0|				dropbear_exit("Crypto error");
  339|      0|			}
  340|  3.16k|		}
  341|  9.27k|		if (ses.newkeys->recv.crypt_mode->start(recv_cipher, 
  ------------------
  |  Branch (341:7): [True: 0, False: 9.27k]
  ------------------
  342|  9.27k|				recv_IV, recv_key, 
  343|  9.27k|				ses.newkeys->recv.algo_crypt->keysize, 0, 
  344|  9.27k|				&ses.newkeys->recv.cipher_state) != CRYPT_OK) {
  345|      0|			dropbear_exit("Crypto error");
  346|      0|		}
  347|  9.27k|	}
  348|       |
  349|  9.27k|	if (ses.newkeys->trans.algo_crypt->cipherdesc != NULL) {
  ------------------
  |  Branch (349:6): [True: 9.27k, False: 0]
  ------------------
  350|  9.27k|		int trans_cipher = -1;
  351|  9.27k|		if (ses.newkeys->trans.algo_crypt->cipherdesc->name != NULL) {
  ------------------
  |  Branch (351:7): [True: 3.55k, False: 5.72k]
  ------------------
  352|  3.55k|			trans_cipher = find_cipher(ses.newkeys->trans.algo_crypt->cipherdesc->name);
  353|  3.55k|			if (trans_cipher < 0) {
  ------------------
  |  Branch (353:8): [True: 0, False: 3.55k]
  ------------------
  354|      0|				dropbear_exit("Crypto error");
  355|      0|			}
  356|  3.55k|		}
  357|  9.27k|		if (ses.newkeys->trans.crypt_mode->start(trans_cipher, 
  ------------------
  |  Branch (357:7): [True: 0, False: 9.27k]
  ------------------
  358|  9.27k|				trans_IV, trans_key, 
  359|  9.27k|				ses.newkeys->trans.algo_crypt->keysize, 0, 
  360|  9.27k|				&ses.newkeys->trans.cipher_state) != CRYPT_OK) {
  361|      0|			dropbear_exit("Crypto error");
  362|      0|		}
  363|  9.27k|	}
  364|       |
  365|  9.27k|	if (ses.newkeys->trans.algo_mac->hash_desc != NULL) {
  ------------------
  |  Branch (365:6): [True: 3.55k, False: 5.72k]
  ------------------
  366|  3.55k|		hashkeys(ses.newkeys->trans.mackey, 
  367|  3.55k|				ses.newkeys->trans.algo_mac->keysize, &hs, mactransletter);
  368|  3.55k|		ses.newkeys->trans.hash_index = find_hash(ses.newkeys->trans.algo_mac->hash_desc->name);
  369|  3.55k|	}
  370|       |
  371|  9.27k|	if (ses.newkeys->recv.algo_mac->hash_desc != NULL) {
  ------------------
  |  Branch (371:6): [True: 0, False: 9.27k]
  ------------------
  372|      0|		hashkeys(ses.newkeys->recv.mackey, 
  373|      0|				ses.newkeys->recv.algo_mac->keysize, &hs, macrecvletter);
  374|      0|		ses.newkeys->recv.hash_index = find_hash(ses.newkeys->recv.algo_mac->hash_desc->name);
  375|      0|	}
  376|       |
  377|       |	/* Ready to switch over */
  378|  9.27k|	ses.newkeys->trans.valid = 1;
  379|  9.27k|	ses.newkeys->recv.valid = 1;
  380|       |
  381|  9.27k|	m_burn(C2S_IV, sizeof(C2S_IV));
  382|  9.27k|	m_burn(C2S_key, sizeof(C2S_key));
  383|  9.27k|	m_burn(S2C_IV, sizeof(S2C_IV));
  384|  9.27k|	m_burn(S2C_key, sizeof(S2C_key));
  385|  9.27k|	m_burn(&hs, sizeof(hash_state));
  386|       |
  387|  9.27k|	TRACE(("leave gen_new_keys"))
  388|  9.27k|}
common-kex.c:hashkeys:
  256|  40.6k|		const hash_state * hs, const unsigned char X) {
  257|       |
  258|  40.6k|	const struct ltc_hash_descriptor *hash_desc = ses.newkeys->algo_kex->hash_desc;
  259|  40.6k|	hash_state hs2;
  260|  40.6k|	unsigned int offset;
  261|  40.6k|	unsigned char tmpout[MAX_HASH_SIZE];
  262|       |
  263|  40.6k|	memcpy(&hs2, hs, sizeof(hash_state));
  264|  40.6k|	hash_desc->process(&hs2, &X, 1);
  265|  40.6k|	hash_desc->process(&hs2, ses.session_id->data, ses.session_id->len);
  266|  40.6k|	hash_desc->done(&hs2, tmpout);
  267|  40.6k|	memcpy(out, tmpout, MIN(hash_desc->hashsize, outlen));
  268|  40.6k|	for (offset = hash_desc->hashsize; 
  269|  69.6k|			offset < outlen; 
  ------------------
  |  Branch (269:4): [True: 28.9k, False: 40.6k]
  ------------------
  270|  40.6k|			offset += hash_desc->hashsize)
  271|  28.9k|	{
  272|       |		/* need to extend */
  273|  28.9k|		memcpy(&hs2, hs, sizeof(hash_state));
  274|  28.9k|		hash_desc->process(&hs2, out, offset);
  275|  28.9k|		hash_desc->done(&hs2, tmpout);
  276|  28.9k|		memcpy(&out[offset], tmpout, MIN(outlen - offset, hash_desc->hashsize));
  277|  28.9k|	}
  278|  40.6k|	m_burn(&hs2, sizeof(hash_state));
  279|  40.6k|}
common-kex.c:read_kex_algos:
  818|  9.58k|static void read_kex_algos() {
  819|       |
  820|       |	/* for asymmetry */
  821|  9.58k|	algo_type * c2s_hash_algo = NULL;
  822|  9.58k|	algo_type * s2c_hash_algo = NULL;
  823|  9.58k|	algo_type * c2s_cipher_algo = NULL;
  824|  9.58k|	algo_type * s2c_cipher_algo = NULL;
  825|  9.58k|	algo_type * c2s_comp_algo = NULL;
  826|  9.58k|	algo_type * s2c_comp_algo = NULL;
  827|       |	/* the generic one */
  828|  9.58k|	algo_type * algo = NULL;
  829|       |
  830|       |	/* which algo couldn't match */
  831|  9.58k|	char * erralgo = NULL;
  832|       |
  833|  9.58k|	int goodguess = 0;
  834|  9.58k|	int allgood = 1; /* we AND this with each goodguess and see if its still
  835|       |						true after */
  836|  9.58k|	int kexguess2 = 0;
  837|       |
  838|  9.58k|	buf_incrpos(ses.payload, 16); /* start after the cookie */
  839|       |
  840|  9.58k|	memset(ses.newkeys, 0x0, sizeof(*ses.newkeys));
  841|       |
  842|       |	/* kex_algorithms */
  843|  9.58k|#if DROPBEAR_KEXGUESS2
  844|  9.58k|	if (buf_has_algo(ses.payload, KEXGUESS2_ALGO_NAME) == DROPBEAR_SUCCESS) {
  ------------------
  |  |  128|  9.58k|#define KEXGUESS2_ALGO_NAME "kexguess2@matt.ucc.asn.au"
  ------------------
              	if (buf_has_algo(ses.payload, KEXGUESS2_ALGO_NAME) == DROPBEAR_SUCCESS) {
  ------------------
  |  |  102|  9.58k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (844:6): [True: 121, False: 9.46k]
  ------------------
  845|    121|		kexguess2 = 1;
  846|    121|	}
  847|  9.58k|#endif
  848|       |
  849|  9.58k|#if DROPBEAR_EXT_INFO
  850|       |	/* Determine if SSH_MSG_EXT_INFO messages should be sent.
  851|       |	Should be done for the first key exchange. Only required on server side
  852|       |    for server-sig-algs */
  853|  9.58k|	if (IS_DROPBEAR_SERVER) {
  ------------------
  |  |  319|  9.58k|#define IS_DROPBEAR_SERVER (ses.isserver == 1)
  |  |  ------------------
  |  |  |  Branch (319:28): [True: 9.58k, False: 8]
  |  |  ------------------
  ------------------
  854|  9.58k|		if (!ses.kexstate.donefirstkex) {
  ------------------
  |  Branch (854:7): [True: 1.42k, False: 8.15k]
  ------------------
  855|  1.42k|			if (buf_has_algo(ses.payload, SSH_EXT_INFO_C) == DROPBEAR_SUCCESS) {
  ------------------
  |  |  100|  1.42k|#define SSH_EXT_INFO_C "ext-info-c"
  ------------------
              			if (buf_has_algo(ses.payload, SSH_EXT_INFO_C) == DROPBEAR_SUCCESS) {
  ------------------
  |  |  102|  1.42k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (855:8): [True: 8, False: 1.41k]
  ------------------
  856|      8|				ses.allow_ext_info = 1;
  857|      8|			}
  858|  1.42k|		}
  859|  9.58k|	}
  860|  9.58k|#endif
  861|       |
  862|  9.58k|	algo = buf_match_algo(ses.payload, sshkex, kexguess2, &goodguess);
  863|  9.58k|	allgood &= goodguess;
  864|  9.58k|	if (algo == NULL || algo->data == NULL) {
  ------------------
  |  Branch (864:6): [True: 38, False: 9.55k]
  |  Branch (864:22): [True: 5, False: 9.54k]
  ------------------
  865|       |		/* kexguess2, ext-info-c, ext-info-s should not match negotiation */
  866|     35|		erralgo = "kex";
  867|     35|		goto error;
  868|     35|	}
  869|  9.55k|	TRACE(("kexguess2 %d", kexguess2))
  870|  9.55k|	DEBUG3(("kex algo %s", algo->name))
  871|  9.55k|	ses.newkeys->algo_kex = algo->data;
  872|       |
  873|       |	/* server_host_key_algorithms */
  874|  9.55k|	algo = buf_match_algo(ses.payload, sigalgs, kexguess2, &goodguess);
  875|  9.55k|	allgood &= goodguess;
  876|  9.55k|	if (algo == NULL) {
  ------------------
  |  Branch (876:6): [True: 3, False: 9.55k]
  ------------------
  877|      3|		erralgo = "hostkey";
  878|      3|		goto error;
  879|      3|	}
  880|  9.55k|	DEBUG2(("hostkey algo %s", algo->name))
  881|  9.55k|	ses.newkeys->algo_signature = algo->val;
  882|  9.55k|	ses.newkeys->algo_hostkey = signkey_type_from_signature(ses.newkeys->algo_signature);
  883|       |
  884|       |	/* encryption_algorithms_client_to_server */
  885|  9.55k|	c2s_cipher_algo = buf_match_algo(ses.payload, sshciphers, 0, NULL);
  886|  9.55k|	if (c2s_cipher_algo == NULL) {
  ------------------
  |  Branch (886:6): [True: 14, False: 9.53k]
  ------------------
  887|     14|		erralgo = "enc c->s";
  888|     14|		goto error;
  889|     14|	}
  890|  9.53k|	DEBUG2(("enc  c2s is %s", c2s_cipher_algo->name))
  891|       |
  892|       |	/* encryption_algorithms_server_to_client */
  893|  9.53k|	s2c_cipher_algo = buf_match_algo(ses.payload, sshciphers, 0, NULL);
  894|  9.53k|	if (s2c_cipher_algo == NULL) {
  ------------------
  |  Branch (894:6): [True: 5, False: 9.53k]
  ------------------
  895|      5|		erralgo = "enc s->c";
  896|      5|		goto error;
  897|      5|	}
  898|  9.53k|	DEBUG2(("enc  s2c is %s", s2c_cipher_algo->name))
  899|       |
  900|       |	/* mac_algorithms_client_to_server */
  901|  9.53k|	c2s_hash_algo = buf_match_algo(ses.payload, sshhashes, 0, NULL);
  902|  9.53k|#if DROPBEAR_AEAD_MODE
  903|  9.53k|	if (((struct dropbear_cipher_mode*)c2s_cipher_algo->mode)->aead_crypt != NULL) {
  ------------------
  |  Branch (903:6): [True: 6.18k, False: 3.34k]
  ------------------
  904|  6.18k|		c2s_hash_algo = NULL;
  905|  6.18k|	} else
  906|  3.34k|#endif
  907|  3.34k|	if (c2s_hash_algo == NULL) {
  ------------------
  |  Branch (907:6): [True: 6, False: 3.34k]
  ------------------
  908|      6|		erralgo = "mac c->s";
  909|      6|		goto error;
  910|      6|	}
  911|  9.52k|	DEBUG2(("hmac c2s is %s", c2s_hash_algo ? c2s_hash_algo->name : "<implicit>"))
  912|       |
  913|       |	/* mac_algorithms_server_to_client */
  914|  9.52k|	s2c_hash_algo = buf_match_algo(ses.payload, sshhashes, 0, NULL);
  915|  9.52k|#if DROPBEAR_AEAD_MODE
  916|  9.52k|	if (((struct dropbear_cipher_mode*)s2c_cipher_algo->mode)->aead_crypt != NULL) {
  ------------------
  |  Branch (916:6): [True: 5.77k, False: 3.75k]
  ------------------
  917|  5.77k|		s2c_hash_algo = NULL;
  918|  5.77k|	} else
  919|  3.75k|#endif
  920|  3.75k|	if (s2c_hash_algo == NULL) {
  ------------------
  |  Branch (920:6): [True: 4, False: 3.74k]
  ------------------
  921|      4|		erralgo = "mac s->c";
  922|      4|		goto error;
  923|      4|	}
  924|  9.52k|	DEBUG2(("hmac s2c is %s", s2c_hash_algo ? s2c_hash_algo->name : "<implicit>"))
  925|       |
  926|       |	/* compression_algorithms_client_to_server */
  927|  9.52k|	c2s_comp_algo = buf_match_algo(ses.payload, ses.compress_algos, 0, NULL);
  928|  9.52k|	if (c2s_comp_algo == NULL) {
  ------------------
  |  Branch (928:6): [True: 2, False: 9.52k]
  ------------------
  929|      2|		erralgo = "comp c->s";
  930|      2|		goto error;
  931|      2|	}
  932|  9.52k|	DEBUG2(("comp c2s is %s", c2s_comp_algo->name))
  933|       |
  934|       |	/* compression_algorithms_server_to_client */
  935|  9.52k|	s2c_comp_algo = buf_match_algo(ses.payload, ses.compress_algos, 0, NULL);
  936|  9.52k|	if (s2c_comp_algo == NULL) {
  ------------------
  |  Branch (936:6): [True: 5, False: 9.51k]
  ------------------
  937|      5|		erralgo = "comp s->c";
  938|      5|		goto error;
  939|      5|	}
  940|  9.51k|	DEBUG2(("comp s2c is %s", s2c_comp_algo->name))
  941|       |
  942|       |	/* languages_client_to_server */
  943|  9.51k|	buf_eatstring(ses.payload);
  944|       |
  945|       |	/* languages_server_to_client */
  946|  9.51k|	buf_eatstring(ses.payload);
  947|       |
  948|       |	/* their first_kex_packet_follows */
  949|  9.51k|	if (buf_getbool(ses.payload)) {
  ------------------
  |  Branch (949:6): [True: 961, False: 8.55k]
  ------------------
  950|    961|		TRACE(("them kex firstfollows. allgood %d", allgood))
  951|    961|		ses.kexstate.them_firstfollows = 1;
  952|       |		/* if the guess wasn't good, we ignore the packet sent */
  953|    961|		if (!allgood) {
  ------------------
  |  Branch (953:7): [True: 154, False: 807]
  ------------------
  954|    154|			ses.ignorenext = 1;
  955|    154|		}
  956|    961|	}
  957|       |
  958|       |	/* Handle the asymmetry */
  959|  9.51k|	if (IS_DROPBEAR_CLIENT) {
  ------------------
  |  |  320|  9.51k|#define IS_DROPBEAR_CLIENT (ses.isserver == 0)
  |  |  ------------------
  |  |  |  Branch (320:28): [True: 0, False: 9.51k]
  |  |  ------------------
  ------------------
  960|      0|		ses.newkeys->recv.algo_crypt = 
  961|      0|			(struct dropbear_cipher*)s2c_cipher_algo->data;
  962|      0|		ses.newkeys->trans.algo_crypt = 
  963|      0|			(struct dropbear_cipher*)c2s_cipher_algo->data;
  964|      0|		ses.newkeys->recv.crypt_mode = 
  965|      0|			(struct dropbear_cipher_mode*)s2c_cipher_algo->mode;
  966|      0|		ses.newkeys->trans.crypt_mode =
  967|      0|			(struct dropbear_cipher_mode*)c2s_cipher_algo->mode;
  968|      0|		ses.newkeys->recv.algo_mac = 
  969|      0|#if DROPBEAR_AEAD_MODE
  970|      0|			s2c_hash_algo == NULL ? ses.newkeys->recv.crypt_mode->aead_mac :
  ------------------
  |  Branch (970:4): [True: 0, False: 0]
  ------------------
  971|      0|#endif
  972|      0|			(struct dropbear_hash*)s2c_hash_algo->data;
  973|      0|		ses.newkeys->trans.algo_mac = 
  974|      0|#if DROPBEAR_AEAD_MODE
  975|      0|			c2s_hash_algo == NULL ? ses.newkeys->trans.crypt_mode->aead_mac :
  ------------------
  |  Branch (975:4): [True: 0, False: 0]
  ------------------
  976|      0|#endif
  977|      0|			(struct dropbear_hash*)c2s_hash_algo->data;
  978|      0|		ses.newkeys->recv.algo_comp = s2c_comp_algo->val;
  979|      0|		ses.newkeys->trans.algo_comp = c2s_comp_algo->val;
  980|  9.51k|	} else {
  981|       |		/* SERVER */
  982|  9.51k|		ses.newkeys->recv.algo_crypt = 
  983|  9.51k|			(struct dropbear_cipher*)c2s_cipher_algo->data;
  984|  9.51k|		ses.newkeys->trans.algo_crypt = 
  985|  9.51k|			(struct dropbear_cipher*)s2c_cipher_algo->data;
  986|  9.51k|		ses.newkeys->recv.crypt_mode =
  987|  9.51k|			(struct dropbear_cipher_mode*)c2s_cipher_algo->mode;
  988|  9.51k|		ses.newkeys->trans.crypt_mode =
  989|  9.51k|			(struct dropbear_cipher_mode*)s2c_cipher_algo->mode;
  990|  9.51k|		ses.newkeys->recv.algo_mac = 
  991|  9.51k|#if DROPBEAR_AEAD_MODE
  992|  9.51k|			c2s_hash_algo == NULL ? ses.newkeys->recv.crypt_mode->aead_mac :
  ------------------
  |  Branch (992:4): [True: 6.16k, False: 3.34k]
  ------------------
  993|  9.51k|#endif
  994|  9.51k|			(struct dropbear_hash*)c2s_hash_algo->data;
  995|  9.51k|		ses.newkeys->trans.algo_mac = 
  996|  9.51k|#if DROPBEAR_AEAD_MODE
  997|  9.51k|			s2c_hash_algo == NULL ? ses.newkeys->trans.crypt_mode->aead_mac :
  ------------------
  |  Branch (997:4): [True: 5.76k, False: 3.75k]
  ------------------
  998|  9.51k|#endif
  999|  9.51k|			(struct dropbear_hash*)s2c_hash_algo->data;
 1000|  9.51k|		ses.newkeys->recv.algo_comp = c2s_comp_algo->val;
 1001|  9.51k|		ses.newkeys->trans.algo_comp = s2c_comp_algo->val;
 1002|  9.51k|	}
 1003|       |
 1004|  9.51k|#if DROPBEAR_FUZZ
 1005|  9.51k|	if (fuzz.fuzzing) {
  ------------------
  |  Branch (1005:6): [True: 9.44k, False: 69]
  ------------------
 1006|  9.44k|		fuzz_kex_fakealgos();
 1007|  9.44k|	}
 1008|  9.51k|#endif
 1009|       |
 1010|       |	/* reserved for future extensions */
 1011|  9.51k|	buf_getint(ses.payload);
 1012|       |
 1013|  9.51k|	if (ses.send_kex_first_guess && allgood) {
  ------------------
  |  Branch (1013:6): [True: 0, False: 9.51k]
  |  Branch (1013:34): [True: 0, False: 0]
  ------------------
 1014|      0|		TRACE(("our_first_follows_matches 1"))
 1015|      0|		ses.kexstate.our_first_follows_matches = 1;
 1016|      0|	}
 1017|  9.51k|	return;
 1018|       |
 1019|     74|error:
 1020|     74|	dropbear_exit("No matching algo %s", erralgo);
 1021|  9.52k|}

common_session_init:
   47|  1.49k|void common_session_init(int sock_in, int sock_out) {
   48|  1.49k|	time_t now;
   49|       |
   50|       |#if DEBUG_TRACE
   51|       |	debug_start_net();
   52|       |#endif
   53|       |
   54|  1.49k|	TRACE(("enter session_init"))
   55|       |
   56|  1.49k|	ses.sock_in = sock_in;
   57|  1.49k|	ses.sock_out = sock_out;
   58|  1.49k|	ses.maxfd = MAX(sock_in, sock_out);
   59|       |
   60|  1.49k|	if (sock_in >= 0) {
  ------------------
  |  Branch (60:6): [True: 1.49k, False: 0]
  ------------------
   61|  1.49k|		setnonblocking(sock_in);
   62|  1.49k|	}
   63|  1.49k|	if (sock_out >= 0) {
  ------------------
  |  Branch (63:6): [True: 1.49k, False: 0]
  ------------------
   64|  1.49k|		setnonblocking(sock_out);
   65|  1.49k|	}
   66|       |
   67|  1.49k|	ses.socket_prio = DROPBEAR_PRIO_NORMAL;
   68|       |	/* Sets it to lowdelay */
   69|  1.49k|	update_channel_prio();
   70|       |
   71|       |#if !DROPBEAR_SVR_MULTIUSER
   72|       |	/* A sanity check to prevent an accidental configuration option
   73|       |	   leaving multiuser systems exposed */
   74|       |	errno = 0;
   75|       |	getuid();
   76|       |	if (errno != ENOSYS) {
   77|       |		dropbear_exit("Non-multiuser Dropbear requires a non-multiuser kernel");
   78|       |	}
   79|       |#endif
   80|       |
   81|  1.49k|	now = monotonic_now();
   82|  1.49k|	ses.connect_time = now;
   83|  1.49k|	ses.last_packet_time_keepalive_recv = now;
   84|  1.49k|	ses.last_packet_time_idle = now;
   85|  1.49k|	ses.last_packet_time_any_sent = 0;
   86|  1.49k|	ses.last_packet_time_keepalive_sent = 0;
   87|       |	
   88|  1.49k|#if DROPBEAR_FUZZ
   89|  1.49k|	if (!fuzz.fuzzing)
  ------------------
  |  Branch (89:6): [True: 0, False: 1.49k]
  ------------------
   90|      0|#endif
   91|      0|	{
   92|      0|	if (pipe(ses.signal_pipe) < 0) {
  ------------------
  |  Branch (92:6): [True: 0, False: 0]
  ------------------
   93|      0|		dropbear_exit("Signal pipe failed");
   94|      0|	}
   95|      0|	setnonblocking(ses.signal_pipe[0]);
   96|      0|	setnonblocking(ses.signal_pipe[1]);
   97|      0|	ses.maxfd = MAX(ses.maxfd, ses.signal_pipe[0]);
   98|      0|	ses.maxfd = MAX(ses.maxfd, ses.signal_pipe[1]);
   99|      0|	}
  100|       |	
  101|  1.49k|	ses.writepayload = buf_new(TRANS_MAX_PAYLOAD_LEN);
  ------------------
  |  |  497|  1.49k|#define TRANS_MAX_PAYLOAD_LEN 16384
  ------------------
  102|  1.49k|	ses.transseq = 0;
  103|       |
  104|  1.49k|	ses.readbuf = NULL;
  105|  1.49k|	ses.payload = NULL;
  106|  1.49k|	ses.recvseq = 0;
  107|       |
  108|  1.49k|	initqueue(&ses.writequeue);
  109|       |
  110|  1.49k|	ses.requirenext = SSH_MSG_KEXINIT;
  ------------------
  |  |   36|  1.49k|#define SSH_MSG_KEXINIT                20
  ------------------
  111|  1.49k|	ses.dataallowed = 1; /* we can send data until we actually 
  112|       |							send the SSH_MSG_KEXINIT */
  113|  1.49k|	ses.ignorenext = 0;
  114|  1.49k|	ses.lastpacket = 0;
  115|  1.49k|	ses.reply_queue_head = NULL;
  116|  1.49k|	ses.reply_queue_tail = NULL;
  117|       |
  118|       |	/* set all the algos to none */
  119|  1.49k|	ses.keys = (struct key_context*)m_malloc(sizeof(struct key_context));
  120|  1.49k|	ses.newkeys = NULL;
  121|  1.49k|	ses.keys->recv.algo_crypt = &dropbear_nocipher;
  122|  1.49k|	ses.keys->trans.algo_crypt = &dropbear_nocipher;
  123|  1.49k|	ses.keys->recv.crypt_mode = &dropbear_mode_none;
  124|  1.49k|	ses.keys->trans.crypt_mode = &dropbear_mode_none;
  125|       |	
  126|  1.49k|	ses.keys->recv.algo_mac = &dropbear_nohash;
  127|  1.49k|	ses.keys->trans.algo_mac = &dropbear_nohash;
  128|       |
  129|  1.49k|	ses.keys->algo_kex = NULL;
  130|  1.49k|	ses.keys->algo_hostkey = -1;
  131|  1.49k|	ses.keys->recv.algo_comp = DROPBEAR_COMP_NONE;
  132|  1.49k|	ses.keys->trans.algo_comp = DROPBEAR_COMP_NONE;
  133|       |
  134|       |#ifndef DISABLE_ZLIB
  135|       |	ses.keys->recv.zstream = NULL;
  136|       |	ses.keys->trans.zstream = NULL;
  137|       |#endif
  138|       |
  139|       |	/* key exchange buffers */
  140|  1.49k|	ses.session_id = NULL;
  141|  1.49k|	ses.kexhashbuf = NULL;
  142|  1.49k|	ses.transkexinit = NULL;
  143|  1.49k|	ses.dh_K = NULL;
  144|  1.49k|	ses.remoteident = NULL;
  145|       |
  146|  1.49k|	ses.chantypes = NULL;
  147|       |
  148|  1.49k|	ses.allowprivport = 0;
  149|       |
  150|       |#if DROPBEAR_PLUGIN
  151|       |        ses.plugin_session = NULL;
  152|       |#endif
  153|       |
  154|  1.49k|	TRACE(("leave session_init"))
  155|  1.49k|}
session_loop:
  157|  1.49k|void session_loop(void(*loophandler)(void)) {
  158|       |
  159|  1.49k|	fd_set readfd, writefd;
  160|  1.49k|	struct timeval timeout;
  161|  1.49k|	int val;
  162|       |
  163|       |	/* main loop, select()s for all sockets in use */
  164|   458k|	for(;;) {
  165|   458k|		const int writequeue_has_space = (ses.writequeue_len <= 2*TRANS_MAX_PAYLOAD_LEN);
  ------------------
  |  |  497|   458k|#define TRANS_MAX_PAYLOAD_LEN 16384
  ------------------
  166|       |
  167|   458k|		timeout.tv_sec = select_timeout();
  168|   458k|		timeout.tv_usec = 0;
  169|   458k|		DROPBEAR_FD_ZERO(&writefd);
  ------------------
  |  |  104|   458k|#define DROPBEAR_FD_ZERO(fds) FD_ZERO(fds)
  ------------------
  170|   458k|		DROPBEAR_FD_ZERO(&readfd);
  ------------------
  |  |  104|   458k|#define DROPBEAR_FD_ZERO(fds) FD_ZERO(fds)
  ------------------
  171|       |
  172|   458k|		dropbear_assert(ses.payload == NULL);
  ------------------
  |  |   83|   458k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 458k]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
  173|       |
  174|       |		/* We get woken up when signal handlers write to this pipe.
  175|       |		   SIGCHLD in svr-chansession is the only one currently. */
  176|   458k|#if DROPBEAR_FUZZ
  177|   458k|		if (!fuzz.fuzzing) 
  ------------------
  |  Branch (177:7): [True: 0, False: 458k]
  ------------------
  178|      0|#endif
  179|      0|		{
  180|      0|		FD_SET(ses.signal_pipe[0], &readfd);
  181|      0|		}
  182|       |
  183|       |		/* set up for channels which can be read/written */
  184|   458k|		setchannelfds(&readfd, &writefd, writequeue_has_space);
  185|       |
  186|       |		/* Pending connections to test */
  187|   458k|		set_connect_fds(&writefd);
  188|       |
  189|       |		/* We delay reading from the input socket during initial setup until
  190|       |		after we have written out our initial KEXINIT packet (empty writequeue). 
  191|       |		This means our initial packet can be in-flight while we're doing a blocking
  192|       |		read for the remote ident.
  193|       |		We also avoid reading from the socket if the writequeue is full, that avoids
  194|       |		replies backing up */
  195|   458k|		if (ses.sock_in != -1 
  ------------------
  |  Branch (195:7): [True: 458k, False: 0]
  ------------------
  196|   458k|			&& (ses.remoteident || isempty(&ses.writequeue)) 
  ------------------
  |  Branch (196:8): [True: 453k, False: 4.49k]
  |  Branch (196:27): [True: 1.50k, False: 2.99k]
  ------------------
  197|   458k|			&& writequeue_has_space) {
  ------------------
  |  Branch (197:7): [True: 399k, False: 55.9k]
  ------------------
  198|   399k|			FD_SET(ses.sock_in, &readfd);
  199|   399k|		}
  200|       |
  201|       |		/* Ordering is important, this test must occur after any other function
  202|       |		might have queued packets (such as connection handlers) */
  203|   458k|		if (ses.sock_out != -1 && !isempty(&ses.writequeue)) {
  ------------------
  |  Branch (203:7): [True: 458k, False: 0]
  |  Branch (203:29): [True: 192k, False: 265k]
  ------------------
  204|   192k|			FD_SET(ses.sock_out, &writefd);
  205|   192k|		}
  206|       |
  207|   458k|		val = select(ses.maxfd+1, &readfd, &writefd, NULL, &timeout);
  ------------------
  |  |   53|   458k|        wrapfd_select(nfds, readfds, writefds, exceptfds, timeout)
  ------------------
  208|       |
  209|   458k|		if (ses.exitflag) {
  ------------------
  |  Branch (209:7): [True: 0, False: 458k]
  ------------------
  210|      0|			dropbear_exit("Terminated by signal");
  211|      0|		}
  212|       |		
  213|   458k|		if (val < 0 && errno != EINTR) {
  ------------------
  |  Branch (213:7): [True: 615, False: 457k]
  |  Branch (213:18): [True: 0, False: 615]
  ------------------
  214|      0|			dropbear_exit("Error in select");
  215|      0|		}
  216|       |
  217|   458k|		if (val <= 0) {
  ------------------
  |  Branch (217:7): [True: 15.7k, False: 442k]
  ------------------
  218|       |			/* If we were interrupted or the select timed out, we still
  219|       |			 * want to iterate over channels etc for reading, to handle
  220|       |			 * server processes exiting etc. 
  221|       |			 * We don't want to read/write FDs. */
  222|  15.7k|			DROPBEAR_FD_ZERO(&writefd);
  ------------------
  |  |  104|  15.7k|#define DROPBEAR_FD_ZERO(fds) FD_ZERO(fds)
  ------------------
  223|  15.7k|			DROPBEAR_FD_ZERO(&readfd);
  ------------------
  |  |  104|  15.7k|#define DROPBEAR_FD_ZERO(fds) FD_ZERO(fds)
  ------------------
  224|  15.7k|		}
  225|       |		
  226|       |		/* We'll just empty out the pipe if required. We don't do
  227|       |		any thing with the data, since the pipe's purpose is purely to
  228|       |		wake up the select() above. */
  229|   458k|		ses.channel_signal_pending = 0;
  230|   458k|		if (FD_ISSET(ses.signal_pipe[0], &readfd)) {
  231|      0|			char x;
  232|      0|			TRACE(("signal pipe set"))
  233|      0|			while (read(ses.signal_pipe[0], &x, 1) > 0) {}
  ------------------
  |  |   55|      0|#define read(fd, buf, count) wrapfd_read(fd, buf, count)
  ------------------
  |  Branch (233:11): [True: 0, False: 0]
  ------------------
  234|      0|			ses.channel_signal_pending = 1;
  235|      0|		}
  236|       |
  237|       |		/* check for auth timeout, rekeying required etc */
  238|   458k|		checktimeouts();
  239|       |
  240|       |		/* process session socket's incoming data */
  241|   458k|		if (ses.sock_in != -1) {
  ------------------
  |  Branch (241:7): [True: 458k, False: 0]
  ------------------
  242|   458k|			if (FD_ISSET(ses.sock_in, &readfd)) {
  243|   275k|				if (!ses.remoteident) {
  ------------------
  |  Branch (243:9): [True: 1.49k, False: 273k]
  ------------------
  244|       |					/* blocking read of the version string */
  245|  1.49k|					read_session_identification();
  246|   273k|				} else {
  247|   273k|					read_packet();
  248|   273k|				}
  249|   275k|			}
  250|       |			
  251|       |			/* Process the decrypted packet. After this, the read buffer
  252|       |			 * will be ready for a new packet */
  253|   458k|			if (ses.payload != NULL) {
  ------------------
  |  Branch (253:8): [True: 52.0k, False: 406k]
  ------------------
  254|  52.0k|				process_packet();
  255|  52.0k|			}
  256|   458k|		}
  257|       |
  258|       |		/* if required, flush out any queued reply packets that
  259|       |		were being held up during a KEX */
  260|   458k|		maybe_flush_reply_queue();
  261|       |
  262|   458k|		handle_connect_fds(&writefd);
  263|       |
  264|       |		/* loop handler prior to channelio, in case the server loophandler closes
  265|       |		channels on process exit */
  266|   458k|		loophandler();
  267|       |
  268|       |		/* process pipes etc for the channels, ses.dataallowed == 0
  269|       |		 * during rekeying ) */
  270|   458k|		channelio(&readfd, &writefd);
  271|       |
  272|       |		/* process session socket's outgoing data */
  273|   458k|		if (ses.sock_out != -1) {
  ------------------
  |  Branch (273:7): [True: 456k, False: 1.49k]
  ------------------
  274|   456k|			if (!isempty(&ses.writequeue)) {
  ------------------
  |  Branch (274:8): [True: 234k, False: 221k]
  ------------------
  275|   234k|				write_packet();
  276|   234k|			}
  277|   456k|		}
  278|       |
  279|   458k|	} /* for(;;) */
  280|       |	
  281|       |	/* Not reached */
  282|  1.49k|}
session_cleanup:
  293|  1.49k|void session_cleanup() {
  294|       |	
  295|  1.49k|	TRACE(("enter session_cleanup"))
  296|       |	
  297|       |	/* we can't cleanup if we don't know the session state */
  298|  1.49k|	if (!ses.init_done) {
  ------------------
  |  Branch (298:6): [True: 0, False: 1.49k]
  ------------------
  299|      0|		TRACE(("leave session_cleanup: !ses.init_done"))
  300|      0|		return;
  301|      0|	}
  302|       |
  303|       |	/* BEWARE of changing order of functions here. */
  304|       |
  305|       |	/* Must be before extra_session_cleanup() */
  306|  1.49k|	chancleanup();
  307|       |
  308|  1.49k|	if (ses.extra_session_cleanup) {
  ------------------
  |  Branch (308:6): [True: 1.49k, False: 0]
  ------------------
  309|  1.49k|		ses.extra_session_cleanup();
  310|  1.49k|	}
  311|       |
  312|       |	/* After these are freed most functions will fail */
  313|  1.49k|#if DROPBEAR_CLEANUP
  314|       |	/* listeners call cleanup functions, this should occur before
  315|       |	other session state is freed. */
  316|  1.49k|	remove_all_listeners();
  317|       |
  318|  1.49k|	remove_connect_pending();
  319|       |
  320|  8.54k|	while (!isempty(&ses.writequeue)) {
  ------------------
  |  Branch (320:9): [True: 7.04k, False: 1.49k]
  ------------------
  321|  7.04k|		buf_free(dequeue(&ses.writequeue));
  322|  7.04k|	}
  323|       |
  324|  1.49k|	m_free(ses.newkeys);
  ------------------
  |  |   24|  1.49k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  325|       |#ifndef DISABLE_ZLIB
  326|       |	if (ses.keys->recv.zstream != NULL) {
  327|       |		if (inflateEnd(ses.keys->recv.zstream) == Z_STREAM_ERROR) {
  328|       |			dropbear_exit("Crypto error");
  329|       |		}
  330|       |		m_free(ses.keys->recv.zstream);
  331|       |	}
  332|       |#endif
  333|       |
  334|  1.49k|	m_free(ses.remoteident);
  ------------------
  |  |   24|  1.49k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  335|  1.49k|	m_free(ses.authstate.pw_dir);
  ------------------
  |  |   24|  1.49k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  336|  1.49k|	m_free(ses.authstate.pw_name);
  ------------------
  |  |   24|  1.49k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  337|  1.49k|	m_free(ses.authstate.pw_shell);
  ------------------
  |  |   24|  1.49k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  338|  1.49k|	m_free(ses.authstate.pw_passwd);
  ------------------
  |  |   24|  1.49k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  339|  1.49k|	m_free(ses.authstate.username);
  ------------------
  |  |   24|  1.49k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  340|  1.49k|#endif
  341|       |
  342|  1.49k|	cleanup_buf(&ses.session_id);
  343|  1.49k|	cleanup_buf(&ses.hash);
  344|  1.49k|	cleanup_buf(&ses.payload);
  345|  1.49k|	cleanup_buf(&ses.readbuf);
  346|  1.49k|	cleanup_buf(&ses.writepayload);
  347|  1.49k|	cleanup_buf(&ses.kexhashbuf);
  348|  1.49k|	cleanup_buf(&ses.transkexinit);
  349|  1.49k|	if (ses.dh_K) {
  ------------------
  |  Branch (349:6): [True: 0, False: 1.49k]
  ------------------
  350|      0|		mp_clear(ses.dh_K);
  351|      0|	}
  352|  1.49k|	m_free(ses.dh_K);
  ------------------
  |  |   24|  1.49k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  353|       |
  354|  1.49k|	m_burn(ses.keys, sizeof(struct key_context));
  355|  1.49k|	m_free(ses.keys);
  ------------------
  |  |   24|  1.49k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  356|       |
  357|  1.49k|	TRACE(("leave session_cleanup"))
  358|  1.49k|}
send_session_identification:
  360|  1.49k|void send_session_identification() {
  361|  1.49k|	buffer *writebuf = buf_new(strlen(LOCAL_IDENT "\r\n") + 1);
  ------------------
  |  |   10|  1.49k|#define LOCAL_IDENT "SSH-2.0-dropbear_" DROPBEAR_VERSION
  ------------------
  362|  1.49k|	buf_putbytes(writebuf, (const unsigned char *) LOCAL_IDENT "\r\n", strlen(LOCAL_IDENT "\r\n"));
  ------------------
  |  |   10|  1.49k|#define LOCAL_IDENT "SSH-2.0-dropbear_" DROPBEAR_VERSION
  ------------------
              	buf_putbytes(writebuf, (const unsigned char *) LOCAL_IDENT "\r\n", strlen(LOCAL_IDENT "\r\n"));
  ------------------
  |  |   10|  1.49k|#define LOCAL_IDENT "SSH-2.0-dropbear_" DROPBEAR_VERSION
  ------------------
  363|  1.49k|	writebuf_enqueue(writebuf);
  364|  1.49k|}
ignore_recv_response:
  489|    348|void ignore_recv_response() {
  490|       |	/* Do nothing */
  491|    348|	TRACE(("Ignored msg_request_response"))
  492|    348|}
fill_passwd:
  630|  1.49k|void fill_passwd(const char* username) {
  631|  1.49k|	struct passwd *pw = NULL;
  632|  1.49k|	if (ses.authstate.pw_name)
  ------------------
  |  Branch (632:6): [True: 0, False: 1.49k]
  ------------------
  633|      0|		m_free(ses.authstate.pw_name);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  634|  1.49k|	if (ses.authstate.pw_dir)
  ------------------
  |  Branch (634:6): [True: 0, False: 1.49k]
  ------------------
  635|      0|		m_free(ses.authstate.pw_dir);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  636|  1.49k|	if (ses.authstate.pw_shell)
  ------------------
  |  Branch (636:6): [True: 0, False: 1.49k]
  ------------------
  637|      0|		m_free(ses.authstate.pw_shell);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  638|  1.49k|	if (ses.authstate.pw_passwd)
  ------------------
  |  Branch (638:6): [True: 0, False: 1.49k]
  ------------------
  639|      0|		m_free(ses.authstate.pw_passwd);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  640|       |
  641|  1.49k|	pw = getpwnam(username);
  ------------------
  |  |  108|  1.49k|#define getpwnam(x) fuzz_getpwnam(x)
  ------------------
  642|  1.49k|	if (!pw) {
  ------------------
  |  Branch (642:6): [True: 0, False: 1.49k]
  ------------------
  643|      0|		return;
  644|      0|	}
  645|  1.49k|	ses.authstate.pw_uid = pw->pw_uid;
  646|  1.49k|	ses.authstate.pw_gid = pw->pw_gid;
  647|  1.49k|	ses.authstate.pw_name = m_strdup(pw->pw_name);
  648|  1.49k|	ses.authstate.pw_dir = m_strdup(pw->pw_dir);
  649|  1.49k|	ses.authstate.pw_shell = m_strdup(pw->pw_shell);
  650|  1.49k|	{
  651|  1.49k|		char *passwd_crypt = pw->pw_passwd;
  652|  1.49k|#ifdef HAVE_SHADOW_H
  653|       |		/* get the shadow password if possible */
  654|  1.49k|		struct spwd *spasswd = getspnam(ses.authstate.pw_name);
  655|  1.49k|		if (spasswd && spasswd->sp_pwdp) {
  ------------------
  |  Branch (655:7): [True: 1.49k, False: 0]
  |  Branch (655:18): [True: 1.49k, False: 0]
  ------------------
  656|  1.49k|			passwd_crypt = spasswd->sp_pwdp;
  657|  1.49k|		}
  658|  1.49k|#endif
  659|  1.49k|		if (!passwd_crypt) {
  ------------------
  |  Branch (659:7): [True: 0, False: 1.49k]
  ------------------
  660|       |			/* android supposedly returns NULL */
  661|      0|			passwd_crypt = "!!";
  662|      0|		}
  663|  1.49k|		ses.authstate.pw_passwd = m_strdup(passwd_crypt);
  664|  1.49k|	}
  665|  1.49k|}
update_channel_prio:
  668|  10.9k|void update_channel_prio() {
  669|  10.9k|	enum dropbear_prio new_prio;
  670|  10.9k|	int any = 0;
  671|  10.9k|	unsigned int i;
  672|       |
  673|  10.9k|	TRACE(("update_channel_prio"))
  674|       |
  675|  10.9k|	if (ses.sock_out < 0) {
  ------------------
  |  Branch (675:6): [True: 1.93k, False: 9.01k]
  ------------------
  676|  1.93k|		TRACE(("leave update_channel_prio: no socket"))
  677|  1.93k|		return;
  678|  1.93k|	}
  679|       |
  680|  9.01k|	new_prio = DROPBEAR_PRIO_NORMAL;
  681|  38.9k|	for (i = 0; i < ses.chansize; i++) {
  ------------------
  |  Branch (681:14): [True: 35.4k, False: 3.49k]
  ------------------
  682|  35.4k|		struct Channel *channel = ses.channels[i];
  683|  35.4k|		if (!channel) {
  ------------------
  |  Branch (683:7): [True: 23.7k, False: 11.7k]
  ------------------
  684|  23.7k|			continue;
  685|  23.7k|		}
  686|  11.7k|		any = 1;
  687|  11.7k|		if (channel->prio == DROPBEAR_PRIO_LOWDELAY) {
  ------------------
  |  Branch (687:7): [True: 5.51k, False: 6.18k]
  ------------------
  688|  5.51k|			new_prio = DROPBEAR_PRIO_LOWDELAY;
  689|  5.51k|			break;
  690|  5.51k|		}
  691|  11.7k|	}
  692|       |
  693|  9.01k|	if (any == 0) {
  ------------------
  |  Branch (693:6): [True: 2.27k, False: 6.73k]
  ------------------
  694|       |		/* lowdelay during setup */
  695|  2.27k|		TRACE(("update_channel_prio: not any"))
  696|  2.27k|		new_prio = DROPBEAR_PRIO_LOWDELAY;
  697|  2.27k|	}
  698|       |
  699|  9.01k|	if (new_prio != ses.socket_prio) {
  ------------------
  |  Branch (699:6): [True: 3.17k, False: 5.84k]
  ------------------
  700|  3.17k|		TRACE(("Dropbear priority transitioning %d -> %d", ses.socket_prio, new_prio))
  701|  3.17k|		set_sock_priority(ses.sock_out, new_prio);
  702|  3.17k|		ses.socket_prio = new_prio;
  703|  3.17k|	}
  704|  9.01k|}
common-session.c:cleanup_buf:
  284|  10.4k|static void cleanup_buf(buffer **buf) {
  285|  10.4k|	if (!*buf) {
  ------------------
  |  Branch (285:6): [True: 5.64k, False: 4.82k]
  ------------------
  286|  5.64k|		return;
  287|  5.64k|	}
  288|  4.82k|	buf_burn_free(*buf);
  289|  4.82k|	*buf = NULL;
  290|  4.82k|}
common-session.c:read_session_identification:
  366|  1.49k|static void read_session_identification() {
  367|       |	/* max length of 255 chars */
  368|  1.49k|	char linebuf[256];
  369|  1.49k|	int len = 0;
  370|  1.49k|	char done = 0;
  371|  1.49k|	int i;
  372|       |
  373|       |	/* Servers may send other lines of data before sending the
  374|       |	 * version string, client must be able to process such lines.
  375|       |	 * If they send more than 50 lines, something is wrong */
  376|  1.49k|	for (i = IS_DROPBEAR_CLIENT ? 50 : 1; i > 0; i--) {
  ------------------
  |  |  320|  1.49k|#define IS_DROPBEAR_CLIENT (ses.isserver == 0)
  |  |  ------------------
  |  |  |  Branch (320:28): [True: 0, False: 1.49k]
  |  |  ------------------
  ------------------
  |  Branch (376:40): [True: 1.49k, False: 4]
  ------------------
  377|  1.49k|		len = ident_readln(ses.sock_in, linebuf, sizeof(linebuf));
  378|       |
  379|  1.49k|		if (len < 0 && errno != EINTR) {
  ------------------
  |  Branch (379:7): [True: 5, False: 1.49k]
  |  Branch (379:18): [True: 1, False: 4]
  ------------------
  380|       |			/* It failed */
  381|      1|			break;
  382|      1|		}
  383|       |
  384|  1.49k|		if (len >= 4 && memcmp(linebuf, "SSH-", 4) == 0) {
  ------------------
  |  Branch (384:7): [True: 1.49k, False: 4]
  |  Branch (384:19): [True: 1.49k, False: 0]
  ------------------
  385|       |			/* start of line matches */
  386|  1.49k|			done = 1;
  387|  1.49k|			break;
  388|  1.49k|		}
  389|  1.49k|	}
  390|       |
  391|  1.49k|	if (!done) {
  ------------------
  |  Branch (391:6): [True: 5, False: 1.49k]
  ------------------
  392|      5|		TRACE(("error reading remote ident: %s\n", strerror(errno)))
  393|      5|		ses.remoteclosed();
  394|  1.49k|	} else {
  395|       |		/* linebuf is already null terminated */
  396|  1.49k|		ses.remoteident = m_malloc(len);
  397|  1.49k|		memcpy(ses.remoteident, linebuf, len);
  398|  1.49k|	}
  399|       |
  400|       |	/* Shall assume that 2.x will be backwards compatible. */
  401|  1.49k|	if (strncmp(ses.remoteident, "SSH-2.", 6) != 0
  ------------------
  |  Branch (401:6): [True: 0, False: 1.49k]
  ------------------
  402|  1.49k|			&& strncmp(ses.remoteident, "SSH-1.99-", 9) != 0) {
  ------------------
  |  Branch (402:7): [True: 0, False: 0]
  ------------------
  403|      0|		dropbear_exit("Incompatible remote version '%s'", ses.remoteident);
  404|      0|	}
  405|       |
  406|  1.49k|	DEBUG1(("remoteident: %s", ses.remoteident))
  407|       |
  408|  1.49k|}
common-session.c:ident_readln:
  412|  1.49k|static int ident_readln(int fd, char* buf, int count) {
  413|       |	
  414|  1.49k|	char in;
  415|  1.49k|	int pos = 0;
  416|  1.49k|	int num = 0;
  417|  1.49k|	fd_set fds;
  418|  1.49k|	struct timeval timeout;
  419|       |
  420|  1.49k|	TRACE(("enter ident_readln"))
  421|       |
  422|  1.49k|	if (count < 1) {
  ------------------
  |  Branch (422:6): [True: 0, False: 1.49k]
  ------------------
  423|      0|		return -1;
  424|      0|	}
  425|       |
  426|  1.49k|	DROPBEAR_FD_ZERO(&fds);
  ------------------
  |  |  104|  1.49k|#define DROPBEAR_FD_ZERO(fds) FD_ZERO(fds)
  ------------------
  427|       |
  428|       |	/* select since it's a non-blocking fd */
  429|       |	
  430|       |	/* leave space to null-terminate */
  431|  44.2k|	while (pos < count-1) {
  ------------------
  |  Branch (431:9): [True: 44.2k, False: 0]
  ------------------
  432|       |
  433|  44.2k|		FD_SET(fd, &fds);
  434|       |
  435|  44.2k|		timeout.tv_sec = 1;
  436|  44.2k|		timeout.tv_usec = 0;
  437|  44.2k|		if (select(fd+1, &fds, NULL, NULL, &timeout) < 0) {
  ------------------
  |  |   53|  44.2k|        wrapfd_select(nfds, readfds, writefds, exceptfds, timeout)
  ------------------
  |  Branch (437:7): [True: 42, False: 44.2k]
  ------------------
  438|     42|			if (errno == EINTR) {
  ------------------
  |  Branch (438:8): [True: 42, False: 0]
  ------------------
  439|     42|				continue;
  440|     42|			}
  441|      0|			TRACE(("leave ident_readln: select error"))
  442|      0|			return -1;
  443|     42|		}
  444|       |
  445|  44.2k|		checktimeouts();
  446|       |		
  447|       |		/* Have to go one byte at a time, since we don't want to read past
  448|       |		 * the end, and have to somehow shove bytes back into the normal
  449|       |		 * packet reader */
  450|  44.2k|		if (FD_ISSET(fd, &fds)) {
  451|  44.2k|			num = read(fd, &in, 1);
  ------------------
  |  |   55|  44.2k|#define read(fd, buf, count) wrapfd_read(fd, buf, count)
  ------------------
  452|       |			/* a "\n" is a newline, "\r" we want to read in and keep going
  453|       |			 * so that it won't be read as part of the next line */
  454|  44.2k|			if (num < 0) {
  ------------------
  |  Branch (454:8): [True: 62, False: 44.1k]
  ------------------
  455|       |				/* error */
  456|     62|				if (errno == EINTR) {
  ------------------
  |  Branch (456:9): [True: 62, False: 0]
  ------------------
  457|     62|					continue; /* not a real error */
  458|     62|				}
  459|      0|				TRACE(("leave ident_readln: read error"))
  460|      0|				return -1;
  461|     62|			}
  462|  44.1k|			if (num == 0) {
  ------------------
  |  Branch (462:8): [True: 5, False: 44.1k]
  ------------------
  463|       |				/* EOF */
  464|      5|				TRACE(("leave ident_readln: EOF"))
  465|      5|				return -1;
  466|      5|			}
  467|       |
  468|  44.1k|#if DROPBEAR_FUZZ
  469|  44.1k|			fuzz_dump(&in, 1);
  470|  44.1k|#endif
  471|       |
  472|  44.1k|			if (in == '\n') {
  ------------------
  |  Branch (472:8): [True: 1.49k, False: 42.6k]
  ------------------
  473|       |				/* end of ident string */
  474|  1.49k|				break;
  475|  1.49k|			}
  476|       |			/* we don't want to include '\r's */
  477|  42.6k|			if (in != '\r') {
  ------------------
  |  Branch (477:8): [True: 31.0k, False: 11.6k]
  ------------------
  478|  31.0k|				buf[pos] = in;
  479|  31.0k|				pos++;
  480|  31.0k|			}
  481|  42.6k|		}
  482|  44.2k|	}
  483|       |
  484|  1.49k|	buf[pos] = '\0';
  485|  1.49k|	TRACE(("leave ident_readln: return %d", pos+1))
  486|  1.49k|	return pos+1;
  487|  1.49k|}
common-session.c:checktimeouts:
  533|   502k|static void checktimeouts() {
  534|       |
  535|   502k|	time_t now;
  536|   502k|	now = monotonic_now();
  537|       |
  538|   502k|	if (IS_DROPBEAR_SERVER && ses.connect_time != 0
  ------------------
  |  |  319|  1.00M|#define IS_DROPBEAR_SERVER (ses.isserver == 1)
  |  |  ------------------
  |  |  |  Branch (319:28): [True: 502k, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (538:28): [True: 502k, False: 0]
  ------------------
  539|   502k|		&& elapsed(now, ses.connect_time) >= AUTH_TIMEOUT) {
  ------------------
  |  |   31|   502k|#define AUTH_TIMEOUT 300 /* we choose 5 minutes */
  ------------------
  |  Branch (539:6): [True: 0, False: 502k]
  ------------------
  540|      0|			dropbear_close("Timeout before auth");
  541|      0|	}
  542|       |
  543|       |	/* we can't rekey if we haven't done remote ident exchange yet */
  544|   502k|	if (ses.remoteident == NULL) {
  ------------------
  |  Branch (544:6): [True: 48.7k, False: 453k]
  ------------------
  545|  48.7k|		return;
  546|  48.7k|	}
  547|       |
  548|   453k|	if (!ses.kexstate.sentkexinit
  ------------------
  |  Branch (548:6): [True: 346k, False: 106k]
  ------------------
  549|   453k|			&& (elapsed(now, ses.kexstate.lastkextime) >= KEX_REKEY_TIMEOUT
  ------------------
  |  |   24|   693k|#define KEX_REKEY_TIMEOUT (3600 * 8)
  ------------------
  |  Branch (549:8): [True: 0, False: 346k]
  ------------------
  550|   346k|			|| ses.kexstate.datarecv+ses.kexstate.datatrans >= KEX_REKEY_DATA)) {
  ------------------
  |  |   27|   346k|#define KEX_REKEY_DATA (1<<30) /* 2^30 == 1GB, this value must be < INT_MAX */
  ------------------
  |  Branch (550:7): [True: 0, False: 346k]
  ------------------
  551|      0|		TRACE(("rekeying after timeout or max data reached"))
  552|      0|		send_msg_kexinit();
  553|      0|	}
  554|       |
  555|   453k|	if (opts.keepalive_secs > 0 && ses.authstate.authdone) {
  ------------------
  |  Branch (555:6): [True: 0, False: 453k]
  |  Branch (555:33): [True: 0, False: 0]
  ------------------
  556|       |		/* Avoid sending keepalives prior to auth - those are
  557|       |		not valid pre-auth packet types */
  558|       |
  559|       |		/* Send keepalives if we've been idle */
  560|      0|		if (elapsed(now, ses.last_packet_time_any_sent) >= opts.keepalive_secs) {
  ------------------
  |  Branch (560:7): [True: 0, False: 0]
  ------------------
  561|      0|			send_msg_keepalive();
  562|      0|		}
  563|       |
  564|       |		/* Also send an explicit keepalive message to trigger a response
  565|       |		if the remote end hasn't sent us anything */
  566|      0|		if (elapsed(now, ses.last_packet_time_keepalive_recv) >= opts.keepalive_secs
  ------------------
  |  Branch (566:7): [True: 0, False: 0]
  ------------------
  567|      0|			&& elapsed(now, ses.last_packet_time_keepalive_sent) >= opts.keepalive_secs) {
  ------------------
  |  Branch (567:7): [True: 0, False: 0]
  ------------------
  568|      0|			send_msg_keepalive();
  569|      0|		}
  570|       |
  571|      0|		if (elapsed(now, ses.last_packet_time_keepalive_recv)
  ------------------
  |  Branch (571:7): [True: 0, False: 0]
  ------------------
  572|      0|			>= opts.keepalive_secs * DEFAULT_KEEPALIVE_LIMIT) {
  ------------------
  |  |  510|      0|#define DEFAULT_KEEPALIVE_LIMIT 3
  ------------------
  573|      0|			dropbear_exit("Keepalive timeout");
  574|      0|		}
  575|      0|	}
  576|       |
  577|   453k|	if (opts.idle_timeout_secs > 0
  ------------------
  |  Branch (577:6): [True: 0, False: 453k]
  ------------------
  578|   453k|			&& elapsed(now, ses.last_packet_time_idle) >= opts.idle_timeout_secs) {
  ------------------
  |  Branch (578:7): [True: 0, False: 0]
  ------------------
  579|      0|		dropbear_close("Idle timeout");
  580|      0|	}
  581|   453k|}
common-session.c:elapsed:
  523|  1.52M|static long elapsed(time_t now, time_t prev) {
  524|  1.52M|	time_t del = now - prev;
  525|  1.52M|	if (del > LONG_MAX) {
  ------------------
  |  Branch (525:6): [True: 0, False: 1.52M]
  ------------------
  526|      0|		return LONG_MAX;
  527|      0|	}
  528|  1.52M|	return (long)del;
  529|  1.52M|}
common-session.c:select_timeout:
  594|   458k|static long select_timeout() {
  595|       |	/* determine the minimum timeout that might be required, so
  596|       |	as to avoid waking when unneccessary */
  597|   458k|	long timeout = KEX_REKEY_TIMEOUT;
  ------------------
  |  |   24|   458k|#define KEX_REKEY_TIMEOUT (3600 * 8)
  ------------------
  598|   458k|	time_t now = monotonic_now();
  599|       |
  600|   458k|	if (!ses.kexstate.sentkexinit) {
  ------------------
  |  Branch (600:6): [True: 346k, False: 111k]
  ------------------
  601|   346k|		update_timeout(KEX_REKEY_TIMEOUT, now, ses.kexstate.lastkextime, &timeout);
  ------------------
  |  |   24|   346k|#define KEX_REKEY_TIMEOUT (3600 * 8)
  ------------------
  602|   346k|	}
  603|       |
  604|   458k|	if (ses.authstate.authdone != 1 && IS_DROPBEAR_SERVER) {
  ------------------
  |  |  319|      0|#define IS_DROPBEAR_SERVER (ses.isserver == 1)
  |  |  ------------------
  |  |  |  Branch (319:28): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (604:6): [True: 0, False: 458k]
  ------------------
  605|       |		/* AUTH_TIMEOUT is only relevant before authdone */
  606|      0|		update_timeout(AUTH_TIMEOUT, now, ses.connect_time, &timeout);
  ------------------
  |  |   31|      0|#define AUTH_TIMEOUT 300 /* we choose 5 minutes */
  ------------------
  607|      0|	}
  608|       |
  609|   458k|	if (ses.authstate.authdone) {
  ------------------
  |  Branch (609:6): [True: 458k, False: 0]
  ------------------
  610|   458k|		update_timeout(opts.keepalive_secs, now,
  611|   458k|			MAX(ses.last_packet_time_keepalive_recv, ses.last_packet_time_keepalive_sent),
  612|   458k|			&timeout);
  613|   458k|	}
  614|       |
  615|   458k|	update_timeout(opts.idle_timeout_secs, now, ses.last_packet_time_idle,
  616|   458k|		&timeout);
  617|       |
  618|       |	/* clamp negative timeouts to zero - event has already triggered */
  619|   458k|	return MAX(timeout, 0);
  620|   458k|}
common-session.c:update_timeout:
  583|  1.26M|static void update_timeout(long limit, time_t now, time_t last_event, long * timeout) {
  584|  1.26M|	TRACE2(("update_timeout limit %ld, now %llu, last %llu, timeout %ld",
  585|  1.26M|		limit,
  586|  1.26M|		(unsigned long long)now,
  587|  1.26M|		(unsigned long long)last_event, *timeout))
  588|  1.26M|	if (last_event > 0 && limit > 0) {
  ------------------
  |  Branch (588:6): [True: 1.26M, False: 0]
  |  Branch (588:24): [True: 346k, False: 916k]
  ------------------
  589|   346k|		*timeout = MIN(*timeout, elapsed(now, last_event) + limit);
  590|   346k|		TRACE2(("new timeout %ld", *timeout))
  591|   346k|	}
  592|  1.26M|}

strlcpy:
   93|     32|size_t strlcpy(char *dst, const char *src, size_t size) {
   94|       |
   95|     32|	size_t i;
   96|       |
   97|       |	/* this is undefined, though size==0 -> return 0 */
   98|     32|	if (size < 1) {
  ------------------
  |  Branch (98:6): [True: 0, False: 32]
  ------------------
   99|      0|		return 0;
  100|      0|	}
  101|       |
  102|    344|	for (i = 0; i < size-1; i++) {
  ------------------
  |  Branch (102:14): [True: 344, False: 0]
  ------------------
  103|    344|		if (src[i] == '\0') {
  ------------------
  |  Branch (103:7): [True: 32, False: 312]
  ------------------
  104|     32|			break;
  105|    312|		} else {
  106|    312|			dst[i] = src[i];
  107|    312|		}
  108|    344|	}
  109|       |
  110|     32|	dst[i] = '\0';
  111|     32|	return strlen(src);
  112|       |
  113|     32|}

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_burn:
    5|   422k|void m_burn(void *data, unsigned int len) {
    6|       |
    7|       |#if defined(HAVE_MEMSET_S)
    8|       |	memset_s(data, len, 0x0, len);
    9|       |#elif defined(HAVE_EXPLICIT_BZERO)
   10|   422k|	explicit_bzero(data, len);
   11|       |#else
   12|       |	/* This must be volatile to avoid compiler optimisation */
   13|       |	volatile void *p = data;
   14|       |	memset((void*)p, 0x0, len);
   15|       |#endif
   16|   422k|}

m_calloc:
    5|  21.5k|void * m_calloc(size_t nmemb, size_t size) {
    6|  21.5k|    if (SIZE_T_MAX / nmemb < size) {
  ------------------
  |  |  166|  21.5k|#define SIZE_T_MAX ULONG_MAX
  ------------------
  |  Branch (6:9): [True: 0, False: 21.5k]
  ------------------
    7|      0|        dropbear_exit("m_calloc failed");
    8|      0|    }
    9|  21.5k|    return m_malloc(nmemb*size);
   10|  21.5k|}
m_strdup:
   12|  22.4k|void * m_strdup(const char * str) {
   13|  22.4k|    char* ret;
   14|  22.4k|    unsigned int len;
   15|  22.4k|    len = strlen(str);
   16|       |
   17|  22.4k|    ret = m_malloc(len+1);
   18|  22.4k|    if (ret == NULL) {
  ------------------
  |  Branch (18:9): [True: 0, False: 22.4k]
  ------------------
   19|      0|        dropbear_exit("m_strdup failed");
   20|      0|    }
   21|  22.4k|    memcpy(ret, str, len+1);
   22|  22.4k|    return ret;
   23|  22.4k|}
m_malloc_set_epoch:
   76|  1.49k|void m_malloc_set_epoch(unsigned int epoch) {
   77|  1.49k|    current_epoch = epoch;
   78|  1.49k|}
m_malloc_free_epoch:
   80|  1.49k|void m_malloc_free_epoch(unsigned int epoch, int dofree) {
   81|  1.49k|    struct dbmalloc_header* header;
   82|  1.49k|    struct dbmalloc_header* nextheader = NULL;
   83|  1.49k|    struct dbmalloc_header* oldstaple = staple;
   84|  1.49k|    staple = NULL;
   85|       |    /* free allocations from this epoch, create a new staple-anchored list from
   86|       |    the remainder */
   87|  1.55M|    for (header = oldstaple; header; header = nextheader)
  ------------------
  |  Branch (87:30): [True: 1.55M, False: 1.49k]
  ------------------
   88|  1.55M|    {
   89|  1.55M|        nextheader = header->next;
   90|  1.55M|        if (header->epoch == epoch) {
  ------------------
  |  Branch (90:13): [True: 355, False: 1.55M]
  ------------------
   91|    355|            if (dofree) {
  ------------------
  |  Branch (91:17): [True: 355, False: 0]
  ------------------
   92|    355|                free(header);
   93|    355|            }
   94|  1.55M|        } else {
   95|  1.55M|            header->prev = NULL;
   96|  1.55M|            header->next = NULL;
   97|  1.55M|            put_alloc(header);
   98|  1.55M|        }
   99|  1.55M|    }
  100|  1.49k|}
m_malloc:
  131|   805k|void * m_malloc(size_t size) {
  132|   805k|    char* mem = NULL;
  133|   805k|    struct dbmalloc_header* header = NULL;
  134|       |
  135|   805k|    if (size == 0 || size > 1e9) {
  ------------------
  |  Branch (135:9): [True: 0, False: 805k]
  |  Branch (135:22): [True: 0, False: 805k]
  ------------------
  136|      0|        dropbear_exit("m_malloc failed");
  137|      0|    }
  138|       |
  139|   805k|    size = size + sizeof(struct dbmalloc_header);
  140|       |
  141|   805k|    mem = calloc(1, size);
  142|   805k|    if (mem == NULL) {
  ------------------
  |  Branch (142:9): [True: 0, False: 805k]
  ------------------
  143|      0|        dropbear_exit("m_malloc failed");
  144|      0|    }
  145|   805k|    header = (struct dbmalloc_header*)mem;
  146|   805k|    put_alloc(header);
  147|   805k|    header->epoch = current_epoch;
  148|   805k|    return &mem[sizeof(struct dbmalloc_header)];
  149|   805k|}
m_realloc:
  151|  13.5k|void * m_realloc(void* ptr, size_t size) {
  152|  13.5k|    char* mem = NULL;
  153|  13.5k|    struct dbmalloc_header* header = NULL;
  154|  13.5k|    if (size == 0 || size > 1e9) {
  ------------------
  |  Branch (154:9): [True: 0, False: 13.5k]
  |  Branch (154:22): [True: 0, False: 13.5k]
  ------------------
  155|      0|        dropbear_exit("m_realloc failed");
  156|      0|    }
  157|       |
  158|  13.5k|    header = get_header(ptr);
  159|  13.5k|    remove_alloc(header);
  160|       |
  161|  13.5k|    size = size + sizeof(struct dbmalloc_header);
  162|  13.5k|    mem = realloc(header, size);
  163|  13.5k|    if (mem == NULL) {
  ------------------
  |  Branch (163:9): [True: 0, False: 13.5k]
  ------------------
  164|      0|        dropbear_exit("m_realloc failed");
  165|      0|    }
  166|       |
  167|  13.5k|    header = (struct dbmalloc_header*)mem;
  168|  13.5k|    put_alloc(header);
  169|  13.5k|    return &mem[sizeof(struct dbmalloc_header)];
  170|  13.5k|}
m_free_direct:
  172|   819k|void m_free_direct(void* ptr) {
  173|   819k|    struct dbmalloc_header* header = NULL;
  174|   819k|    if (!ptr) {
  ------------------
  |  Branch (174:9): [True: 16.7k, False: 802k]
  ------------------
  175|  16.7k|        return;
  176|  16.7k|    }
  177|   802k|    header = get_header(ptr);
  178|   802k|    remove_alloc(header);
  179|   802k|    free(header);
  180|   802k|}
m_realloc_ltm:
  184|  1.54k|void * m_realloc_ltm(void* ptr, size_t oldsize, size_t newsize) {
  185|  1.54k|   (void)oldsize;
  186|  1.54k|   return m_realloc(ptr, newsize);
  187|  1.54k|}
m_free_ltm:
  189|  21.5k|void m_free_ltm(void *mem, size_t size) {
  190|  21.5k|   (void)size;
  191|  21.5k|   m_free_direct(mem);
  192|  21.5k|}
dbmalloc.c:put_alloc:
  102|  2.37M|static void put_alloc(struct dbmalloc_header *header) {
  103|  2.37M|    assert(header->next == NULL);
  104|  2.37M|    assert(header->prev == NULL);
  105|  2.37M|    if (staple) {
  ------------------
  |  Branch (105:9): [True: 2.37M, False: 1.49k]
  ------------------
  106|  2.37M|        staple->prev = header;
  107|  2.37M|    }
  108|  2.37M|    header->next = staple;
  109|  2.37M|    staple = header;
  110|  2.37M|}
dbmalloc.c:get_header:
  126|   816k|static struct dbmalloc_header* get_header(void* ptr) {
  127|   816k|    char* bptr = ptr;
  128|   816k|    return (struct dbmalloc_header*)&bptr[-sizeof(struct dbmalloc_header)];
  129|   816k|}
dbmalloc.c:remove_alloc:
  112|   816k|static void remove_alloc(struct dbmalloc_header *header) {
  113|   816k|    if (header->prev) {
  ------------------
  |  Branch (113:9): [True: 581k, False: 234k]
  ------------------
  114|   581k|        header->prev->next = header->next;
  115|   581k|    }
  116|   816k|    if (header->next) {
  ------------------
  |  Branch (116:9): [True: 816k, False: 0]
  ------------------
  117|   816k|        header->next->prev = header->prev;
  118|   816k|    }
  119|   816k|    if (staple == header) {
  ------------------
  |  Branch (119:9): [True: 234k, False: 581k]
  ------------------
  120|   234k|        staple = header->next;
  121|   234k|    }
  122|   816k|    header->prev = NULL;
  123|   816k|    header->next = NULL;
  124|   816k|}

fuzz_seed:
  153|  1.49k|void fuzz_seed(const unsigned char* dat, unsigned int len) {
  154|  1.49k|	hash_state hs;
  155|  1.49k|	sha256_init(&hs);
  156|  1.49k|	sha256_process(&hs, "fuzzfuzzfuzz", strlen("fuzzfuzzfuzz"));
  157|  1.49k|	sha256_process(&hs, dat, len);
  158|  1.49k|	sha256_done(&hs, hashpool);
  159|  1.49k|	counter = 0;
  160|  1.49k|	donerandinit = 1;
  161|  1.49k|}
genrandom:
  316|   251k|void genrandom(unsigned char* buf, unsigned int len) {
  317|       |
  318|   251k|	hash_state hs;
  319|   251k|	unsigned char hash[SHA256_HASH_SIZE];
  320|   251k|	unsigned int copylen;
  321|       |
  322|   251k|	if (!donerandinit) {
  ------------------
  |  Branch (322:6): [True: 0, False: 251k]
  ------------------
  323|      0|		dropbear_exit("seedrandom not done");
  324|      0|	}
  325|       |
  326|   503k|	while (len > 0) {
  ------------------
  |  Branch (326:9): [True: 251k, False: 251k]
  ------------------
  327|   251k|		sha256_init(&hs);
  328|   251k|		sha256_process(&hs, (void*)hashpool, sizeof(hashpool));
  329|   251k|		sha256_process(&hs, (void*)&counter, sizeof(counter));
  330|   251k|		sha256_done(&hs, hash);
  331|       |
  332|   251k|		counter++;
  333|   251k|		if (counter > MAX_COUNTER) {
  ------------------
  |  |   35|   251k|#define MAX_COUNTER (1<<30)
  ------------------
  |  Branch (333:7): [True: 0, False: 251k]
  ------------------
  334|      0|			seedrandom();
  335|      0|		}
  336|       |
  337|   251k|		copylen = MIN(len, SHA256_HASH_SIZE);
  338|   251k|		memcpy(buf, hash, copylen);
  339|   251k|		len -= copylen;
  340|   251k|		buf += copylen;
  341|   251k|	}
  342|   251k|	m_burn(hash, sizeof(hash));
  343|   251k|}

dropbear_close:
   95|  1.03k|void dropbear_close(const char* format, ...) {
   96|       |
   97|  1.03k|	va_list param;
   98|       |
   99|  1.03k|	va_start(param, format);
  100|  1.03k|	_dropbear_exit(EXIT_SUCCESS, format, param);
  101|      0|	va_end(param);
  102|       |
  103|      0|}
dropbear_exit:
  105|    458|void dropbear_exit(const char* format, ...) {
  106|       |
  107|    458|	va_list param;
  108|       |
  109|    458|	va_start(param, format);
  110|    458|	_dropbear_exit(EXIT_FAILURE, format, param);
  111|      0|	va_end(param);
  112|      0|}
fail_assert:
  132|      1|void fail_assert(const char* expr, const char* file, int line) {
  133|      1|	dropbear_exit("Failed assertion (%s:%d): `%s'", file, line, expr);
  134|      1|}
dropbear_log:
  148|  3.75k|void dropbear_log(int priority, const char* format, ...) {
  149|       |
  150|  3.75k|	va_list param;
  151|       |
  152|  3.75k|	va_start(param, format);
  153|  3.75k|	_dropbear_log(priority, format, param);
  154|  3.75k|	va_end(param);
  155|  3.75k|}
spawn_command:
  275|  1.55k|		int *ret_writefd, int *ret_readfd, int *ret_errfd, pid_t *ret_pid) {
  276|  1.55k|	int infds[2];
  277|  1.55k|	int outfds[2];
  278|  1.55k|	int errfds[2];
  279|  1.55k|	pid_t pid;
  280|       |
  281|  1.55k|	const int FDIN = 0;
  282|  1.55k|	const int FDOUT = 1;
  283|       |
  284|  1.55k|#if DROPBEAR_FUZZ
  285|  1.55k|	if (fuzz.fuzzing) {
  ------------------
  |  Branch (285:6): [True: 1.55k, False: 0]
  ------------------
  286|  1.55k|		return fuzz_spawn_command(ret_writefd, ret_readfd, ret_errfd, ret_pid);
  287|  1.55k|	}
  288|      0|#endif
  289|       |
  290|       |	/* redirect stdin/stdout/stderr */
  291|      0|	if (pipe(infds) != 0) {
  ------------------
  |  Branch (291:6): [True: 0, False: 0]
  ------------------
  292|      0|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
  293|      0|	}
  294|      0|	if (pipe(outfds) != 0) {
  ------------------
  |  Branch (294:6): [True: 0, False: 0]
  ------------------
  295|      0|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
  296|      0|	}
  297|      0|	if (ret_errfd && pipe(errfds) != 0) {
  ------------------
  |  Branch (297:6): [True: 0, False: 0]
  |  Branch (297:19): [True: 0, False: 0]
  ------------------
  298|      0|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
  299|      0|	}
  300|       |
  301|       |#if DROPBEAR_VFORK
  302|       |	pid = vfork();
  303|       |#else
  304|      0|	pid = fork();
  305|      0|#endif
  306|       |
  307|      0|	if (pid < 0) {
  ------------------
  |  Branch (307:6): [True: 0, False: 0]
  ------------------
  308|      0|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
  309|      0|	}
  310|       |
  311|      0|	if (!pid) {
  ------------------
  |  Branch (311:6): [True: 0, False: 0]
  ------------------
  312|       |		/* child */
  313|       |
  314|      0|		TRACE(("back to normal sigchld"))
  315|       |		/* Revert to normal sigchld handling */
  316|      0|		if (signal(SIGCHLD, SIG_DFL) == SIG_ERR) {
  ------------------
  |  Branch (316:7): [True: 0, False: 0]
  ------------------
  317|      0|			dropbear_exit("signal() error");
  318|      0|		}
  319|       |
  320|       |		/* redirect stdin/stdout */
  321|       |
  322|      0|		if ((dup2(infds[FDIN], STDIN_FILENO) < 0) ||
  ------------------
  |  Branch (322:7): [True: 0, False: 0]
  ------------------
  323|      0|			(dup2(outfds[FDOUT], STDOUT_FILENO) < 0) ||
  ------------------
  |  Branch (323:4): [True: 0, False: 0]
  ------------------
  324|      0|			(ret_errfd && dup2(errfds[FDOUT], STDERR_FILENO) < 0)) {
  ------------------
  |  Branch (324:5): [True: 0, False: 0]
  |  Branch (324:18): [True: 0, False: 0]
  ------------------
  325|      0|			TRACE(("leave noptycommand: error redirecting FDs"))
  326|      0|			dropbear_exit("Child dup2() failure");
  327|      0|		}
  328|       |
  329|      0|		close(infds[FDOUT]);
  ------------------
  |  |   56|      0|#define close(fd) wrapfd_close(fd)
  ------------------
  330|      0|		close(infds[FDIN]);
  ------------------
  |  |   56|      0|#define close(fd) wrapfd_close(fd)
  ------------------
  331|      0|		close(outfds[FDIN]);
  ------------------
  |  |   56|      0|#define close(fd) wrapfd_close(fd)
  ------------------
  332|      0|		close(outfds[FDOUT]);
  ------------------
  |  |   56|      0|#define close(fd) wrapfd_close(fd)
  ------------------
  333|      0|		if (ret_errfd)
  ------------------
  |  Branch (333:7): [True: 0, False: 0]
  ------------------
  334|      0|		{
  335|      0|			close(errfds[FDIN]);
  ------------------
  |  |   56|      0|#define close(fd) wrapfd_close(fd)
  ------------------
  336|      0|			close(errfds[FDOUT]);
  ------------------
  |  |   56|      0|#define close(fd) wrapfd_close(fd)
  ------------------
  337|      0|		}
  338|       |
  339|      0|		exec_fn(exec_data);
  340|       |		/* not reached */
  341|      0|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
  342|      0|	} else {
  343|       |		/* parent */
  344|      0|		close(infds[FDIN]);
  ------------------
  |  |   56|      0|#define close(fd) wrapfd_close(fd)
  ------------------
  345|      0|		close(outfds[FDOUT]);
  ------------------
  |  |   56|      0|#define close(fd) wrapfd_close(fd)
  ------------------
  346|       |
  347|      0|		setnonblocking(outfds[FDIN]);
  348|      0|		setnonblocking(infds[FDOUT]);
  349|       |
  350|      0|		if (ret_errfd) {
  ------------------
  |  Branch (350:7): [True: 0, False: 0]
  ------------------
  351|      0|			close(errfds[FDOUT]);
  ------------------
  |  |   56|      0|#define close(fd) wrapfd_close(fd)
  ------------------
  352|      0|			setnonblocking(errfds[FDIN]);
  353|      0|		}
  354|       |
  355|      0|		if (ret_pid) {
  ------------------
  |  Branch (355:7): [True: 0, False: 0]
  ------------------
  356|      0|			*ret_pid = pid;
  357|      0|		}
  358|       |
  359|      0|		*ret_writefd = infds[FDOUT];
  360|      0|		*ret_readfd = outfds[FDIN];
  361|      0|		if (ret_errfd) {
  ------------------
  |  Branch (361:7): [True: 0, False: 0]
  ------------------
  362|      0|			*ret_errfd = errfds[FDIN];
  363|      0|		}
  364|      0|		return DROPBEAR_SUCCESS;
  ------------------
  |  |  102|      0|#define DROPBEAR_SUCCESS 0
  ------------------
  365|      0|	}
  366|      0|}
m_close:
  560|  23.1k|void m_close(int fd) {
  561|  23.1k|	int val;
  562|       |
  563|  23.1k|	if (fd < 0) {
  ------------------
  |  Branch (563:6): [True: 17.4k, False: 5.70k]
  ------------------
  564|  17.4k|		return;
  565|  17.4k|	}
  566|       |
  567|  5.70k|	do {
  568|  5.70k|		val = close(fd);
  ------------------
  |  |   56|  5.70k|#define close(fd) wrapfd_close(fd)
  ------------------
  569|  5.70k|	} while (val < 0 && errno == EINTR);
  ------------------
  |  Branch (569:11): [True: 0, False: 5.70k]
  |  Branch (569:22): [True: 0, False: 0]
  ------------------
  570|       |
  571|  5.70k|	if (val < 0 && errno != EBADF) {
  ------------------
  |  Branch (571:6): [True: 0, False: 5.70k]
  |  Branch (571:17): [True: 0, False: 0]
  ------------------
  572|       |		/* Linux says EIO can happen */
  573|      0|		dropbear_exit("Error closing fd %d, %s", fd, strerror(errno));
  574|      0|	}
  575|  5.70k|}
setnonblocking:
  577|  2.99k|void setnonblocking(int fd) {
  578|       |
  579|  2.99k|	TRACE(("setnonblocking: %d", fd))
  580|       |
  581|  2.99k|#if DROPBEAR_FUZZ
  582|  2.99k|	if (fuzz.fuzzing) {
  ------------------
  |  Branch (582:6): [True: 2.99k, False: 0]
  ------------------
  583|  2.99k|		return;
  584|  2.99k|	}
  585|      0|#endif
  586|       |
  587|      0|	if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
  ------------------
  |  Branch (587:6): [True: 0, False: 0]
  ------------------
  588|      0|		if (errno == ENODEV) {
  ------------------
  |  Branch (588:7): [True: 0, False: 0]
  ------------------
  589|       |			/* Some devices (like /dev/null redirected in)
  590|       |			 * can't be set to non-blocking */
  591|      0|			TRACE(("ignoring ENODEV for setnonblocking"))
  592|      0|		} else {
  593|      0|		{
  594|      0|			dropbear_exit("Couldn't set nonblocking");
  595|      0|		}
  596|      0|		}
  597|      0|	}
  598|      0|	TRACE(("leave setnonblocking"))
  599|      0|}
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|}
expand_homedir_path:
  638|     66|char * expand_homedir_path(const char *inpath) {
  639|     66|	struct passwd *pw = NULL;
  640|     66|	if (strncmp(inpath, "~/", 2) == 0) {
  ------------------
  |  Branch (640:6): [True: 0, False: 66]
  ------------------
  641|      0|		char *homedir = getenv("HOME");
  642|       |
  643|      0|		if (!homedir) {
  ------------------
  |  Branch (643:7): [True: 0, False: 0]
  ------------------
  644|      0|			pw = getpwuid(getuid());
  ------------------
  |  |  109|      0|#define getpwuid(x) fuzz_getpwuid(x)
  ------------------
  645|      0|			if (pw) {
  ------------------
  |  Branch (645:8): [True: 0, False: 0]
  ------------------
  646|      0|				homedir = pw->pw_dir;
  647|      0|			}
  648|      0|		}
  649|       |
  650|      0|		if (homedir) {
  ------------------
  |  Branch (650:7): [True: 0, False: 0]
  ------------------
  651|      0|			int len = strlen(inpath)-2 + strlen(homedir) + 2;
  652|      0|			char *buf = m_malloc(len);
  653|      0|			snprintf(buf, len, "%s/%s", homedir, inpath+2);
  654|      0|			return buf;
  655|      0|		}
  656|      0|	}
  657|       |
  658|       |	/* Fallback */
  659|     66|	return m_strdup(inpath);
  660|     66|}
gettime_wrapper:
  675|  1.26M|void gettime_wrapper(struct timespec *now) {
  676|  1.26M|	struct timeval tv;
  677|  1.26M|#if DROPBEAR_FUZZ
  678|  1.26M|	if (fuzz.fuzzing) {
  ------------------
  |  Branch (678:6): [True: 1.26M, False: 0]
  ------------------
  679|       |		/* time stands still when fuzzing */
  680|  1.26M|		now->tv_sec = 5;
  681|  1.26M|		now->tv_nsec = 0;
  682|  1.26M|	}
  683|  1.26M|#endif
  684|       |
  685|  1.26M|#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
  686|       |	/* POSIX monotonic clock. Newer Linux, BSD, MacOSX >10.12 */
  687|  1.26M|	if (clock_gettime(CLOCK_MONOTONIC, now) == 0) {
  ------------------
  |  Branch (687:6): [True: 1.26M, False: 0]
  ------------------
  688|  1.26M|		return;
  689|  1.26M|	}
  690|      0|#endif
  691|       |
  692|      0|#if defined(__linux__) && defined(SYS_clock_gettime)
  693|      0|	{
  694|       |	/* Old linux toolchain - kernel might support it but not the build headers */
  695|       |	/* Also glibc <2.17 requires -lrt which we neglect to add */
  696|      0|	static int linux_monotonic_failed = 0;
  697|      0|	if (!linux_monotonic_failed) {
  ------------------
  |  Branch (697:6): [True: 0, False: 0]
  ------------------
  698|       |		/* CLOCK_MONOTONIC isn't in some headers */
  699|      0|		int clock_source_monotonic = 1; 
  700|      0|		if (syscall(SYS_clock_gettime, clock_source_monotonic, now) == 0) {
  ------------------
  |  Branch (700:7): [True: 0, False: 0]
  ------------------
  701|      0|			return;
  702|      0|		} else {
  703|       |			/* Don't try again */
  704|      0|			linux_monotonic_failed = 1;
  705|      0|		}
  706|      0|	}
  707|      0|	}
  708|      0|#endif /* linux fallback clock_gettime */
  709|       |
  710|       |#if defined(HAVE_MACH_ABSOLUTE_TIME)
  711|       |	{
  712|       |	/* OS X pre 10.12, see https://developer.apple.com/library/mac/qa/qa1398/_index.html */
  713|       |	static mach_timebase_info_data_t timebase_info;
  714|       |	uint64_t scaled_time;
  715|       |	if (timebase_info.denom == 0) {
  716|       |		mach_timebase_info(&timebase_info);
  717|       |	}
  718|       |	scaled_time = mach_absolute_time() * timebase_info.numer / timebase_info.denom;
  719|       |	now->tv_sec = scaled_time / 1000000000;
  720|       |	now->tv_nsec = scaled_time % 1000000000;
  721|       |	}
  722|       |#endif /* osx mach_absolute_time */
  723|       |
  724|       |	/* Fallback for everything else - this will sometimes go backwards */
  725|      0|	gettimeofday(&tv, NULL);
  726|      0|	now->tv_sec = tv.tv_sec;
  727|      0|	now->tv_nsec = 1000*(long)tv.tv_usec;
  728|      0|}
monotonic_now:
  731|  1.26M|time_t monotonic_now() {
  732|  1.26M|	struct timespec ts;
  733|  1.26M|	gettime_wrapper(&ts);
  734|  1.26M|	return ts.tv_sec;
  735|  1.26M|}

buf_get_dss_pub_key:
   46|      1|int buf_get_dss_pub_key(buffer* buf, dropbear_dss_key *key) {
   47|      1|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
   48|       |
   49|      1|	TRACE(("enter buf_get_dss_pub_key"))
   50|      1|	dropbear_assert(key != NULL);
  ------------------
  |  |   83|      1|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 1]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
   51|      1|	m_mp_alloc_init_multi(&key->p, &key->q, &key->g, &key->y, NULL);
   52|      1|	key->x = NULL;
   53|       |
   54|      1|	buf_incrpos(buf, 4+SSH_SIGNKEY_DSS_LEN); /* int + "ssh-dss" */
  ------------------
  |  |  111|      1|#define SSH_SIGNKEY_DSS_LEN 7
  ------------------
   55|      1|	if (buf_getmpint(buf, key->p) == DROPBEAR_FAILURE
  ------------------
  |  |  103|      2|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (55:6): [True: 0, False: 1]
  ------------------
   56|      1|	 || buf_getmpint(buf, key->q) == DROPBEAR_FAILURE
  ------------------
  |  |  103|      2|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (56:6): [True: 0, False: 1]
  ------------------
   57|      1|	 || buf_getmpint(buf, key->g) == DROPBEAR_FAILURE
  ------------------
  |  |  103|      2|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (57:6): [True: 0, False: 1]
  ------------------
   58|      1|	 || buf_getmpint(buf, key->y) == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (58:6): [True: 0, False: 1]
  ------------------
   59|      0|		TRACE(("leave buf_get_dss_pub_key: failed reading mpints"))
   60|      0|		ret = DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
   61|      0|		goto out;
   62|      0|	}
   63|       |
   64|      1|	if (mp_count_bits(key->p) != DSS_P_BITS) {
  ------------------
  |  |   44|      1|#define DSS_P_BITS 1024
  ------------------
  |  Branch (64:6): [True: 0, False: 1]
  ------------------
   65|      0|		dropbear_log(LOG_WARNING, "Bad DSS p");
   66|      0|		ret = DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
   67|      0|		goto out;
   68|      0|	}
   69|       |
   70|      1|	if (mp_count_bits(key->q) != DSS_Q_BITS) {
  ------------------
  |  |   45|      1|#define DSS_Q_BITS 160
  ------------------
  |  Branch (70:6): [True: 0, False: 1]
  ------------------
   71|      0|		dropbear_log(LOG_WARNING, "Bad DSS q");
   72|      0|		ret = DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
   73|      0|		goto out;
   74|      0|	}
   75|       |
   76|       |	/* test 1 < g < p */
   77|      1|	if (mp_cmp_d(key->g, 1) != MP_GT) {
  ------------------
  |  |  156|      1|#define MP_GT         1   /* greater than */
  ------------------
  |  Branch (77:6): [True: 0, False: 1]
  ------------------
   78|      0|		dropbear_log(LOG_WARNING, "Bad DSS g");
   79|      0|		ret = DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
   80|      0|		goto out;
   81|      0|	}
   82|      1|	if (mp_cmp(key->g, key->p) != MP_LT) {
  ------------------
  |  |  154|      1|#define MP_LT        -1   /* less than */
  ------------------
  |  Branch (82:6): [True: 0, False: 1]
  ------------------
   83|      0|		dropbear_log(LOG_WARNING, "Bad DSS g");
   84|      0|		ret = DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
   85|      0|		goto out;
   86|      0|	}
   87|       |
   88|      1|	ret = DROPBEAR_SUCCESS;
  ------------------
  |  |  102|      1|#define DROPBEAR_SUCCESS 0
  ------------------
   89|      1|	TRACE(("leave buf_get_dss_pub_key: success"))
   90|      1|out:
   91|      1|	if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (91:6): [True: 0, False: 1]
  ------------------
   92|      0|		m_mp_free_multi(&key->p, &key->q, &key->g, &key->y, NULL);
   93|      0|	}
   94|      1|	return ret;
   95|      1|}
buf_get_dss_priv_key:
  100|      1|int buf_get_dss_priv_key(buffer* buf, dropbear_dss_key *key) {
  101|       |
  102|      1|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  103|       |
  104|      1|	dropbear_assert(key != NULL);
  ------------------
  |  |   83|      1|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 1]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
  105|       |
  106|      1|	ret = buf_get_dss_pub_key(buf, key);
  107|      1|	if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (107:6): [True: 0, False: 1]
  ------------------
  108|      0|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
  109|      0|	}
  110|       |
  111|      1|	m_mp_alloc_init_multi(&key->x, NULL);
  112|      1|	ret = buf_getmpint(buf, key->x);
  113|      1|	if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (113:6): [True: 0, False: 1]
  ------------------
  114|      0|		m_mp_free_multi(&key->x, NULL);
  115|      0|	}
  116|       |
  117|      1|	return ret;
  118|      1|}
dss_key_free:
  122|      1|void dss_key_free(dropbear_dss_key *key) {
  123|       |
  124|      1|	TRACE2(("enter dsa_key_free"))
  125|      1|	if (key == NULL) {
  ------------------
  |  Branch (125:6): [True: 1, False: 0]
  ------------------
  126|      1|		TRACE2(("enter dsa_key_free: key == NULL"))
  127|      1|		return;
  128|      1|	}
  129|      0|	m_mp_free_multi(&key->p, &key->q, &key->g, &key->y, &key->x, NULL);
  130|      0|	m_free(key);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  131|      0|	TRACE2(("leave dsa_key_free"))
  132|      0|}

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|}
new_ecc_key:
   75|      1|ecc_key * new_ecc_key(void) {
   76|      1|	ecc_key *key = m_malloc(sizeof(*key));
   77|      1|	m_mp_alloc_init_multi((mp_int**)&key->pubkey.x, (mp_int**)&key->pubkey.y, 
   78|      1|		(mp_int**)&key->pubkey.z, (mp_int**)&key->k, NULL);
   79|      1|	return key;
   80|      1|}
buf_get_ecc_raw_pubkey:
  147|      1|ecc_key * buf_get_ecc_raw_pubkey(buffer *buf, const struct dropbear_ecc_curve *curve) {
  148|      1|	ecc_key *key = NULL;
  149|      1|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  150|      1|	const unsigned int size = curve->dp->size;
  151|      1|	unsigned char first;
  152|       |
  153|      1|	TRACE(("enter buf_get_ecc_raw_pubkey"))
  154|       |
  155|      1|	buf_setpos(buf, 0);
  156|      1|	first = buf_getbyte(buf);
  157|      1|	if (first == 2 || first == 3) {
  ------------------
  |  Branch (157:6): [True: 0, False: 1]
  |  Branch (157:20): [True: 0, False: 1]
  ------------------
  158|      0|		dropbear_log(LOG_WARNING, "Dropbear doesn't support ECC point compression");
  159|      0|		return NULL;
  160|      0|	}
  161|      1|	if (first != 4 || buf->len != 1+2*size) {
  ------------------
  |  Branch (161:6): [True: 0, False: 1]
  |  Branch (161:20): [True: 0, False: 1]
  ------------------
  162|      0|		TRACE(("leave, wrong size"))
  163|      0|		return NULL;
  164|      0|	}
  165|       |
  166|      1|	key = new_ecc_key();
  167|      1|	key->dp = curve->dp;
  168|       |
  169|      1|	if (mp_from_ubin(key->pubkey.x, buf_getptr(buf, size), size) != MP_OKAY) {
  ------------------
  |  |  161|      1|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (169:6): [True: 0, False: 1]
  ------------------
  170|      0|		TRACE(("failed to read x"))
  171|      0|		goto out;
  172|      0|	}
  173|      1|	buf_incrpos(buf, size);
  174|       |
  175|      1|	if (mp_from_ubin(key->pubkey.y, buf_getptr(buf, size), size) != MP_OKAY) {
  ------------------
  |  |  161|      1|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (175:6): [True: 0, False: 1]
  ------------------
  176|      0|		TRACE(("failed to read y"))
  177|      0|		goto out;
  178|      0|	}
  179|      1|	buf_incrpos(buf, size);
  180|       |
  181|      1|	mp_set(key->pubkey.z, 1);
  182|       |
  183|      1|	if (ecc_is_point(key) != CRYPT_OK) {
  ------------------
  |  Branch (183:6): [True: 0, False: 1]
  ------------------
  184|      0|		TRACE(("failed, not a point"))
  185|      0|		goto out;
  186|      0|	}
  187|       |
  188|       |   /* SEC1 3.2.3.1 Check that Q != 0 */
  189|      1|	if (mp_cmp_d(key->pubkey.x, 0) == LTC_MP_EQ) {
  ------------------
  |  |   13|      1|#define LTC_MP_EQ    0
  ------------------
  |  Branch (189:6): [True: 0, False: 1]
  ------------------
  190|      0|		TRACE(("failed, x == 0"))
  191|      0|		goto out;
  192|      0|	}
  193|      1|	if (mp_cmp_d(key->pubkey.y, 0) == LTC_MP_EQ) {
  ------------------
  |  |   13|      1|#define LTC_MP_EQ    0
  ------------------
  |  Branch (193:6): [True: 0, False: 1]
  ------------------
  194|      0|		TRACE(("failed, y == 0"))
  195|      0|		goto out;
  196|      0|	}
  197|       |
  198|      1|	ret = DROPBEAR_SUCCESS;
  ------------------
  |  |  102|      1|#define DROPBEAR_SUCCESS 0
  ------------------
  199|       |
  200|      1|	out:
  201|      1|	if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (201:6): [True: 0, False: 1]
  ------------------
  202|      0|		if (key) {
  ------------------
  |  Branch (202:7): [True: 0, False: 0]
  ------------------
  203|      0|			ecc_free(key);
  204|      0|			m_free(key);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  205|      0|			key = NULL;
  206|      0|		}
  207|      0|	}
  208|       |
  209|      1|	return key;
  210|       |
  211|      1|}
ecc.c:ecc_is_point:
   85|      1|{
   86|      1|	mp_int *prime, *b, *t1, *t2;
   87|      1|	int err;
   88|       |	
   89|      1|	m_mp_alloc_init_multi(&prime, &b, &t1, &t2, NULL);
   90|       |	
   91|       |   /* load prime and b */
   92|      1|	if ((err = mp_read_radix(prime, key->dp->prime, 16)) != CRYPT_OK)                          { goto error; }
  ------------------
  |  Branch (92:6): [True: 0, False: 1]
  ------------------
   93|      1|	if ((err = mp_read_radix(b, key->dp->B, 16)) != CRYPT_OK)                                  { goto error; }
  ------------------
  |  Branch (93:6): [True: 0, False: 1]
  ------------------
   94|       |	
   95|       |   /* compute y^2 */
   96|      1|	if ((err = mp_sqr(key->pubkey.y, t1)) != CRYPT_OK)                                         { goto error; }
  ------------------
  |  Branch (96:6): [True: 0, False: 1]
  ------------------
   97|       |	
   98|       |   /* compute x^3 */
   99|      1|	if ((err = mp_sqr(key->pubkey.x, t2)) != CRYPT_OK)                                         { goto error; }
  ------------------
  |  Branch (99:6): [True: 0, False: 1]
  ------------------
  100|      1|	if ((err = mp_mod(t2, prime, t2)) != CRYPT_OK)                                             { goto error; }
  ------------------
  |  Branch (100:6): [True: 0, False: 1]
  ------------------
  101|      1|	if ((err = mp_mul(key->pubkey.x, t2, t2)) != CRYPT_OK)                                     { goto error; }
  ------------------
  |  Branch (101:6): [True: 0, False: 1]
  ------------------
  102|       |	
  103|       |   /* compute y^2 - x^3 */
  104|      1|	if ((err = mp_sub(t1, t2, t1)) != CRYPT_OK)                                                { goto error; }
  ------------------
  |  Branch (104:6): [True: 0, False: 1]
  ------------------
  105|       |	
  106|       |   /* compute y^2 - x^3 + 3x */
  107|      1|	if ((err = mp_add(t1, key->pubkey.x, t1)) != CRYPT_OK)                                     { goto error; }
  ------------------
  |  Branch (107:6): [True: 0, False: 1]
  ------------------
  108|      1|	if ((err = mp_add(t1, key->pubkey.x, t1)) != CRYPT_OK)                                     { goto error; }
  ------------------
  |  Branch (108:6): [True: 0, False: 1]
  ------------------
  109|      1|	if ((err = mp_add(t1, key->pubkey.x, t1)) != CRYPT_OK)                                     { goto error; }
  ------------------
  |  Branch (109:6): [True: 0, False: 1]
  ------------------
  110|      1|	if ((err = mp_mod(t1, prime, t1)) != CRYPT_OK)                                             { goto error; }
  ------------------
  |  Branch (110:6): [True: 0, False: 1]
  ------------------
  111|      1|	while (mp_cmp_d(t1, 0) == LTC_MP_LT) {
  ------------------
  |  |   12|      1|#define LTC_MP_LT   -1
  ------------------
  |  Branch (111:9): [True: 0, False: 1]
  ------------------
  112|      0|		if ((err = mp_add(t1, prime, t1)) != CRYPT_OK)                                          { goto error; }
  ------------------
  |  Branch (112:7): [True: 0, False: 0]
  ------------------
  113|      0|	}
  114|      1|	while (mp_cmp(t1, prime) != LTC_MP_LT) {
  ------------------
  |  |   12|      1|#define LTC_MP_LT   -1
  ------------------
  |  Branch (114:9): [True: 0, False: 1]
  ------------------
  115|      0|		if ((err = mp_sub(t1, prime, t1)) != CRYPT_OK)                                          { goto error; }
  ------------------
  |  Branch (115:7): [True: 0, False: 0]
  ------------------
  116|      0|	}
  117|       |	
  118|       |   /* compare to b */
  119|      1|	if (mp_cmp(t1, b) != LTC_MP_EQ) {
  ------------------
  |  |   13|      1|#define LTC_MP_EQ    0
  ------------------
  |  Branch (119:6): [True: 0, False: 1]
  ------------------
  120|      0|		err = CRYPT_INVALID_PACKET;
  121|      1|	} else {
  122|      1|		err = CRYPT_OK;
  123|      1|	}
  124|       |	
  125|      1|	error:
  126|      1|	mp_clear_multi(prime, b, t1, t2, NULL);
  127|      1|	m_free(prime);
  ------------------
  |  |   24|      1|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  128|      1|	m_free(b);
  ------------------
  |  |   24|      1|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  129|      1|	m_free(t1);
  ------------------
  |  |   24|      1|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  130|      1|	m_free(t2);
  ------------------
  |  |   24|      1|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  131|      1|	return err;
  132|      1|}

signkey_is_ecdsa:
   11|      4|{
   12|      4|	return type == DROPBEAR_SIGNKEY_ECDSA_NISTP256
  ------------------
  |  Branch (12:9): [True: 1, False: 3]
  ------------------
   13|      4|		|| type == DROPBEAR_SIGNKEY_ECDSA_NISTP384
  ------------------
  |  Branch (13:6): [True: 0, False: 3]
  ------------------
   14|      4|		|| type == DROPBEAR_SIGNKEY_ECDSA_NISTP521;
  ------------------
  |  Branch (14:6): [True: 0, False: 3]
  ------------------
   15|      4|}
buf_get_ecdsa_pub_key:
   77|      1|ecc_key *buf_get_ecdsa_pub_key(buffer* buf) {
   78|      1|	unsigned char *key_ident = NULL, *identifier = NULL;
   79|      1|	unsigned int key_ident_len, identifier_len;
   80|      1|	buffer *q_buf = NULL;
   81|      1|	struct dropbear_ecc_curve **curve;
   82|      1|	ecc_key *new_key = NULL;
   83|       |
   84|       |	/* string   "ecdsa-sha2-[identifier]" or "sk-ecdsa-sha2-nistp256@openssh.com" */
   85|      1|	key_ident = (unsigned char*)buf_getstring(buf, &key_ident_len);
   86|       |	/* string   "[identifier]" */
   87|      1|	identifier = (unsigned char*)buf_getstring(buf, &identifier_len);
   88|       |
   89|      1|	if (strcmp (key_ident, "sk-ecdsa-sha2-nistp256@openssh.com") == 0) {
  ------------------
  |  Branch (89:6): [True: 0, False: 1]
  ------------------
   90|      0|		if (strcmp (identifier, "nistp256") != 0) {
  ------------------
  |  Branch (90:7): [True: 0, False: 0]
  ------------------
   91|      0|			TRACE(("mismatching identifiers"))
   92|      0|			goto out;
   93|      0|		}
   94|      1|	} else {
   95|      1|		if (key_ident_len != identifier_len + strlen ("ecdsa-sha2-")) {
  ------------------
  |  Branch (95:7): [True: 0, False: 1]
  ------------------
   96|      0|			TRACE(("Bad identifier lengths"))
   97|      0|			goto out;
   98|      0|		}
   99|      1|		if (memcmp(&key_ident[strlen ("ecdsa-sha2-")], identifier, identifier_len) != 0) {
  ------------------
  |  Branch (99:7): [True: 0, False: 1]
  ------------------
  100|      0|			TRACE(("mismatching identifiers"))
  101|      0|			goto out;
  102|      0|		}
  103|      1|	}
  104|       |
  105|      1|	for (curve = dropbear_ecc_curves; *curve; curve++) {
  ------------------
  |  Branch (105:36): [True: 1, False: 0]
  ------------------
  106|      1|		if (memcmp(identifier, (char*)(*curve)->name, strlen((char*)(*curve)->name)) == 0) {
  ------------------
  |  Branch (106:7): [True: 1, False: 0]
  ------------------
  107|      1|			break;
  108|      1|		}
  109|      1|	}
  110|      1|	if (!*curve) {
  ------------------
  |  Branch (110:6): [True: 0, False: 1]
  ------------------
  111|      0|		TRACE(("couldn't match ecc curve"))
  112|      0|		goto out;
  113|      0|	}
  114|       |
  115|       |	/* string Q */
  116|      1|	q_buf = buf_getstringbuf(buf);
  117|      1|	new_key = buf_get_ecc_raw_pubkey(q_buf, *curve);
  118|       |
  119|      1|out:
  120|      1|	m_free(key_ident);
  ------------------
  |  |   24|      1|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  121|      1|	m_free(identifier);
  ------------------
  |  |   24|      1|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  122|      1|	if (q_buf) {
  ------------------
  |  Branch (122:6): [True: 1, False: 0]
  ------------------
  123|      1|		buf_free(q_buf);
  124|      1|		q_buf = NULL;
  125|      1|	}
  126|      1|	TRACE(("leave buf_get_ecdsa_pub_key"))	
  127|      1|	return new_key;
  128|      1|}
buf_get_ecdsa_priv_key:
  130|      1|ecc_key *buf_get_ecdsa_priv_key(buffer *buf) {
  131|      1|	ecc_key *new_key = NULL;
  132|      1|	TRACE(("enter buf_get_ecdsa_priv_key"))
  133|      1|	new_key = buf_get_ecdsa_pub_key(buf);
  134|      1|	if (!new_key) {
  ------------------
  |  Branch (134:6): [True: 0, False: 1]
  ------------------
  135|      0|		return NULL;
  136|      0|	}
  137|       |
  138|      1|	if (buf_getmpint(buf, new_key->k) != DROPBEAR_SUCCESS) {
  ------------------
  |  |  102|      1|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (138:6): [True: 0, False: 1]
  ------------------
  139|      0|		ecc_free(new_key);
  140|      0|		m_free(new_key);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  141|      0|		return NULL;
  142|      0|	}
  143|       |
  144|      1|	return new_key;
  145|      1|}

buf_get_ed25519_priv_key:
   78|      1|int buf_get_ed25519_priv_key(buffer *buf, dropbear_ed25519_key *key) {
   79|       |
   80|      1|	unsigned int len;
   81|       |
   82|      1|	TRACE(("enter buf_get_ed25519_priv_key"))
   83|      1|	dropbear_assert(key != NULL);
  ------------------
  |  |   83|      1|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 1]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
   84|       |
   85|      1|	buf_incrpos(buf, 4+SSH_SIGNKEY_ED25519_LEN); /* int + "ssh-ed25519" */
  ------------------
  |  |  115|      1|#define SSH_SIGNKEY_ED25519_LEN 11
  ------------------
   86|       |
   87|      1|	len = buf_getint(buf);
   88|      1|	if (len != CURVE25519_LEN*2 || buf->len - buf->pos < len) {
  ------------------
  |  |   34|      1|#define CURVE25519_LEN 32
  ------------------
  |  Branch (88:6): [True: 0, False: 1]
  |  Branch (88:33): [True: 0, False: 1]
  ------------------
   89|      0|		TRACE(("leave buf_get_ed25519_priv_key: failure"))
   90|      0|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
   91|      0|	}
   92|       |
   93|      1|	memcpy(key->priv, buf_getptr(buf, CURVE25519_LEN), CURVE25519_LEN);
  ------------------
  |  |   34|      1|#define CURVE25519_LEN 32
  ------------------
              	memcpy(key->priv, buf_getptr(buf, CURVE25519_LEN), CURVE25519_LEN);
  ------------------
  |  |   34|      1|#define CURVE25519_LEN 32
  ------------------
   94|      1|	buf_incrpos(buf, CURVE25519_LEN);
  ------------------
  |  |   34|      1|#define CURVE25519_LEN 32
  ------------------
   95|      1|	memcpy(key->pub, buf_getptr(buf, CURVE25519_LEN), CURVE25519_LEN);
  ------------------
  |  |   34|      1|#define CURVE25519_LEN 32
  ------------------
              	memcpy(key->pub, buf_getptr(buf, CURVE25519_LEN), CURVE25519_LEN);
  ------------------
  |  |   34|      1|#define CURVE25519_LEN 32
  ------------------
   96|      1|	buf_incrpos(buf, CURVE25519_LEN);
  ------------------
  |  |   34|      1|#define CURVE25519_LEN 32
  ------------------
   97|       |
   98|      1|	TRACE(("leave buf_get_ed25519_priv_key: success"))
   99|      1|	return DROPBEAR_SUCCESS;
  ------------------
  |  |  102|      1|#define DROPBEAR_SUCCESS 0
  ------------------
  100|      1|}
ed25519_key_free:
  103|      1|void ed25519_key_free(dropbear_ed25519_key *key) {
  104|       |
  105|      1|	TRACE2(("enter ed25519_key_free"))
  106|       |
  107|      1|	if (key == NULL) {
  ------------------
  |  Branch (107:6): [True: 1, False: 0]
  ------------------
  108|      1|		TRACE2(("leave ed25519_key_free: key == NULL"))
  109|      1|		return;
  110|      1|	}
  111|      0|	m_burn(key->priv, CURVE25519_LEN);
  ------------------
  |  |   34|      0|#define CURVE25519_LEN 32
  ------------------
  112|      0|	m_free(key);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  113|       |
  114|      0|	TRACE2(("leave ed25519_key_free"))
  115|      0|}

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

listeners_initialise:
   30|  1.49k|void listeners_initialise() {
   31|       |
   32|       |	/* just one slot to start with */
   33|  1.49k|	ses.listeners = (struct Listener**)m_malloc(sizeof(struct Listener*));
   34|  1.49k|	ses.listensize = 1;
   35|  1.49k|	ses.listeners[0] = NULL;
   36|       |
   37|  1.49k|}
set_listener_fds:
   39|   458k|void set_listener_fds(fd_set * readfds) {
   40|       |
   41|   458k|	unsigned int i, j;
   42|   458k|	struct Listener *listener;
   43|       |
   44|       |	/* check each in turn */
   45|   916k|	for (i = 0; i < ses.listensize; i++) {
  ------------------
  |  Branch (45:14): [True: 458k, False: 458k]
  ------------------
   46|   458k|		listener = ses.listeners[i];
   47|   458k|		if (listener != NULL) {
  ------------------
  |  Branch (47:7): [True: 0, False: 458k]
  ------------------
   48|      0|			for (j = 0; j < listener->nsocks; j++) {
  ------------------
  |  Branch (48:16): [True: 0, False: 0]
  ------------------
   49|      0|				FD_SET(listener->socks[j], readfds);
   50|      0|			}
   51|      0|		}
   52|   458k|	}
   53|   458k|}
handle_listeners:
   56|   456k|void handle_listeners(const fd_set * readfds) {
   57|       |
   58|   456k|	unsigned int i, j;
   59|   456k|	struct Listener *listener;
   60|   456k|	int sock;
   61|       |
   62|       |	/* check each in turn */
   63|   913k|	for (i = 0; i < ses.listensize; i++) {
  ------------------
  |  Branch (63:14): [True: 456k, False: 456k]
  ------------------
   64|   456k|		listener = ses.listeners[i];
   65|   456k|		if (listener != NULL) {
  ------------------
  |  Branch (65:7): [True: 0, False: 456k]
  ------------------
   66|      0|			for (j = 0; j < listener->nsocks; j++) {
  ------------------
  |  Branch (66:16): [True: 0, False: 0]
  ------------------
   67|      0|				sock = listener->socks[j];
   68|      0|				if (FD_ISSET(sock, readfds)) {
   69|      0|					listener->acceptor(listener, sock);
   70|      0|				}
   71|      0|			}
   72|      0|		}
   73|   456k|	}
   74|   456k|} /* Woo brace matching */
get_listener:
  136|     68|		int (*match)(const void*, const void*)) {
  137|       |
  138|     68|	unsigned int i;
  139|     68|	struct Listener* listener;
  140|       |
  141|    136|	for (i = 0, listener = ses.listeners[i]; i < ses.listensize; i++) {
  ------------------
  |  Branch (141:43): [True: 68, False: 68]
  ------------------
  142|     68|		if (listener && listener->type == type
  ------------------
  |  Branch (142:7): [True: 0, False: 68]
  |  Branch (142:19): [True: 0, False: 0]
  ------------------
  143|     68|				&& match(typedata, listener->typedata)) {
  ------------------
  |  Branch (143:8): [True: 0, False: 0]
  ------------------
  144|      0|			return listener;
  145|      0|		}
  146|     68|	}
  147|       |
  148|     68|	return NULL;
  149|     68|}
remove_all_listeners:
  166|  1.49k|void remove_all_listeners(void) {
  167|  1.49k|	unsigned int i;
  168|  2.99k|	for (i = 0; i < ses.listensize; i++) {
  ------------------
  |  Branch (168:14): [True: 1.49k, False: 1.49k]
  ------------------
  169|  1.49k|		if (ses.listeners[i]) {
  ------------------
  |  Branch (169:7): [True: 0, False: 1.49k]
  ------------------
  170|      0|			remove_listener(ses.listeners[i]);
  171|      0|		}
  172|  1.49k|	}
  173|  1.49k|	m_free(ses.listeners);
  ------------------
  |  |   24|  1.49k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  174|  1.49k|}

login_logout:
  219|      8|{
  220|      8|	li->type = LTYPE_LOGOUT;
  ------------------
  |  |  119|      8|#define LTYPE_LOGOUT   8
  ------------------
  221|      8|	return login_write(li);
  222|      8|}
login_alloc_entry:
  237|      8|{
  238|      8|	struct logininfo *newli;
  239|       |
  240|      8|	newli = (struct logininfo *) m_malloc (sizeof(*newli));
  241|      8|	(void)login_init_entry(newli, pid, username, hostname, line);
  242|      8|	return newli;
  243|      8|}
login_free_entry:
  249|      8|{
  250|      8|	m_free(li);
  ------------------
  |  |   24|      8|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  251|      8|}
login_init_entry:
  265|      8|{
  266|      8|	struct passwd *pw;
  267|       |
  268|      8|	memset(li, 0, sizeof(*li));
  269|       |
  270|      8|	li->pid = pid;
  271|       |
  272|       |	/* set the line information */
  273|      8|	if (line)
  ------------------
  |  Branch (273:6): [True: 8, False: 0]
  ------------------
  274|      8|		line_fullname(li->line, line, sizeof(li->line));
  275|       |
  276|      8|	if (username) {
  ------------------
  |  Branch (276:6): [True: 0, False: 8]
  ------------------
  277|      0|		strlcpy(li->username, username, sizeof(li->username));
  278|      0|		pw = getpwnam(li->username);
  ------------------
  |  |  108|      0|#define getpwnam(x) fuzz_getpwnam(x)
  ------------------
  279|      0|		if (pw == NULL)
  ------------------
  |  Branch (279:7): [True: 0, False: 0]
  ------------------
  280|      0|			dropbear_exit("login_init_entry: Cannot find user \"%s\"",
  281|      0|					li->username);
  282|      0|		li->uid = pw->pw_uid;
  283|      0|	}
  284|       |
  285|      8|	if (hostname)
  ------------------
  |  Branch (285:6): [True: 8, False: 0]
  ------------------
  286|      8|		strlcpy(li->hostname, hostname, sizeof(li->hostname));
  287|       |
  288|      8|	return 1;
  289|      8|}
login_set_current_time:
  299|      8|{
  300|      8|	struct timeval tv;
  301|       |
  302|      8|	gettimeofday(&tv, NULL);
  303|       |
  304|      8|	li->tv_sec = tv.tv_sec;
  305|      8|	li->tv_usec = tv.tv_usec;
  306|      8|}
login_write:
  314|      8|{
  315|      8|#ifndef HAVE_CYGWIN
  316|      8|	if ((int)geteuid() != 0) {
  ------------------
  |  Branch (316:6): [True: 0, False: 8]
  ------------------
  317|      0|	  return 1;
  318|      0|	}
  319|      8|#endif
  320|       |
  321|       |	/* set the timestamp */
  322|      8|	login_set_current_time(li);
  323|      8|#ifdef USE_LOGIN
  324|      8|	syslogin_write_entry(li);
  325|      8|#endif
  326|      8|#ifdef USE_LASTLOG
  327|      8|	if (li->type == LTYPE_LOGIN) {
  ------------------
  |  |  118|      8|#define LTYPE_LOGIN    7
  ------------------
  |  Branch (327:6): [True: 0, False: 8]
  ------------------
  328|      0|		lastlog_write_entry(li);
  329|      0|	}
  330|      8|#endif
  331|       |#ifdef USE_UTMP
  332|       |	utmp_write_entry(li);
  333|       |#endif
  334|       |#ifdef USE_WTMP
  335|       |	wtmp_write_entry(li);
  336|       |#endif
  337|       |#ifdef USE_UTMPX
  338|       |	utmpx_write_entry(li);
  339|       |#endif
  340|       |#ifdef USE_WTMPX
  341|       |	wtmpx_write_entry(li);
  342|       |#endif
  343|      8|	return 0;
  344|      8|}
line_fullname:
  391|      8|{
  392|      8|	memset(dst, '\0', dstsize);
  393|      8|	if ((strncmp(src, "/dev/", 5) == 0) || (dstsize < (strlen(src) + 5))) {
  ------------------
  |  Branch (393:6): [True: 8, False: 0]
  |  Branch (393:41): [True: 0, False: 0]
  ------------------
  394|      8|		strlcpy(dst, src, dstsize);
  395|      8|	} else {
  396|      0|		strlcpy(dst, "/dev/", dstsize);
  397|      0|		strlcat(dst, src, dstsize);
  398|      0|	}
  399|      8|	return dst;
  400|      8|}
line_stripname:
  405|      8|{
  406|      8|	memset(dst, '\0', dstsize);
  407|      8|	if (strncmp(src, "/dev/", 5) == 0)
  ------------------
  |  Branch (407:6): [True: 8, False: 0]
  ------------------
  408|      8|		strlcpy(dst, src + 5, dstsize);
  409|      0|	else
  410|      0|		strlcpy(dst, src, dstsize);
  411|      8|	return dst;
  412|      8|}
syslogin_write_entry:
 1243|      8|{
 1244|      8|	switch (li->type) {
 1245|      0|	case LTYPE_LOGIN:
  ------------------
  |  |  118|      0|#define LTYPE_LOGIN    7
  ------------------
  |  Branch (1245:2): [True: 0, False: 8]
  ------------------
 1246|      0|		return syslogin_perform_login(li);
 1247|      8|	case LTYPE_LOGOUT:
  ------------------
  |  |  119|      8|#define LTYPE_LOGOUT   8
  ------------------
  |  Branch (1247:2): [True: 8, False: 0]
  ------------------
 1248|      8|		return syslogin_perform_logout(li);
 1249|      0|	default:
  ------------------
  |  Branch (1249:2): [True: 0, False: 8]
  ------------------
 1250|      0|		dropbear_log(LOG_WARNING, "syslogin_write_entry: Invalid type field");
 1251|      0|		return 0;
 1252|      8|	}
 1253|      8|}
loginrec.c:syslogin_perform_logout:
 1220|      8|{
 1221|      8|# ifdef HAVE_LOGOUT
 1222|      8|	char line[8];
 1223|       |
 1224|      8|	(void)line_stripname(line, li->line, sizeof(line));
 1225|       |
 1226|      8|	if (!logout(line)) {
  ------------------
  |  Branch (1226:6): [True: 8, False: 0]
  ------------------
 1227|      8|		dropbear_log(LOG_WARNING, "syslogin_perform_logout: logout(%s) returned an error: %s", line, strerror(errno));
 1228|      8|#  ifdef HAVE_LOGWTMP
 1229|      8|	} else {
 1230|      0|		logwtmp(line, "", "");
 1231|      0|#  endif
 1232|      0|	}
 1233|       |	/* FIXME: (ATL - if the need arises) What to do if we have
 1234|       |	 * login, but no logout?  what if logout but no logwtmp? All
 1235|       |	 * routines are in libutil so they should all be there,
 1236|       |	 * but... */
 1237|      8|# endif
 1238|      8|	return 1;
 1239|      8|}

cancel_connect:
   52|     98|void cancel_connect(struct dropbear_progress_connection *c) {
   53|     98|	c->cb = cancel_callback;
   54|     98|	c->cb_data = NULL;
   55|     98|}
connect_remote:
  180|     98|{
  181|     98|	struct dropbear_progress_connection *c = NULL;
  182|     98|	int err;
  183|     98|	struct addrinfo hints;
  184|       |
  185|     98|	c = m_malloc(sizeof(*c));
  186|     98|	c->remotehost = m_strdup(remotehost);
  187|     98|	c->remoteport = m_strdup(remoteport);
  188|     98|	c->sock = -1;
  189|     98|	c->cb = cb;
  190|     98|	c->cb_data = cb_data;
  191|     98|	c->prio = prio;
  192|       |
  193|     98|	list_append(&ses.conn_pending, c);
  194|       |
  195|     98|#if DROPBEAR_FUZZ
  196|     98|	if (fuzz.fuzzing) {
  ------------------
  |  Branch (196:6): [True: 98, False: 0]
  ------------------
  197|     98|		c->errstring = m_strdup("fuzzing connect_remote always fails");
  198|     98|		return c;
  199|     98|	}
  200|      0|#endif
  201|       |
  202|      0|	memset(&hints, 0, sizeof(hints));
  203|      0|	hints.ai_socktype = SOCK_STREAM;
  204|      0|	hints.ai_family = AF_UNSPEC;
  205|       |
  206|      0|	err = getaddrinfo(remotehost, remoteport, &hints, &c->res);
  207|      0|	if (err) {
  ------------------
  |  Branch (207:6): [True: 0, False: 0]
  ------------------
  208|      0|		int len;
  209|      0|		len = 100 + strlen(gai_strerror(err));
  210|      0|		c->errstring = (char*)m_malloc(len);
  211|      0|		snprintf(c->errstring, len, "Error resolving '%s' port '%s'. %s", 
  212|      0|				remotehost, remoteport, gai_strerror(err));
  213|      0|		TRACE(("Error resolving: %s", gai_strerror(err)))
  214|      0|	} else {
  215|      0|		c->res_iter = c->res;
  216|      0|	}
  217|       |	
  218|      0|	if (bind_address) {
  ------------------
  |  Branch (218:6): [True: 0, False: 0]
  ------------------
  219|      0|		c->bind_address = m_strdup(bind_address);
  220|      0|	}
  221|      0|	if (bind_port) {
  ------------------
  |  Branch (221:6): [True: 0, False: 0]
  ------------------
  222|      0|		c->bind_port = m_strdup(bind_port);
  223|      0|	}
  224|       |
  225|      0|	return c;
  226|     98|}
remove_connect_pending:
  228|  1.49k|void remove_connect_pending() {
  229|  1.49k|	while (ses.conn_pending.first) {
  ------------------
  |  Branch (229:9): [True: 1, False: 1.49k]
  ------------------
  230|      1|		struct dropbear_progress_connection *c = ses.conn_pending.first->item;
  231|      1|		remove_connect(c, ses.conn_pending.first);
  232|      1|	}
  233|  1.49k|}
set_connect_fds:
  236|   458k|void set_connect_fds(fd_set *writefd) {
  237|   458k|	m_list_elem *iter;
  238|   458k|	iter = ses.conn_pending.first;
  239|   458k|	while (iter) {
  ------------------
  |  Branch (239:9): [True: 97, False: 458k]
  ------------------
  240|     97|		m_list_elem *next_iter = iter->next;
  241|     97|		struct dropbear_progress_connection *c = iter->item;
  242|       |		/* Set one going */
  243|     97|		while (c->res_iter && c->sock < 0) {
  ------------------
  |  Branch (243:10): [True: 0, False: 97]
  |  Branch (243:25): [True: 0, False: 0]
  ------------------
  244|      0|			connect_try_next(c);
  245|      0|		}
  246|     97|		if (c->sock >= 0) {
  ------------------
  |  Branch (246:7): [True: 0, False: 97]
  ------------------
  247|      0|			FD_SET(c->sock, writefd);
  248|     97|		} else {
  249|       |			/* Final failure */
  250|     97|			if (!c->errstring) {
  ------------------
  |  Branch (250:8): [True: 0, False: 97]
  ------------------
  251|      0|				c->errstring = m_strdup("unexpected failure");
  252|      0|			}
  253|     97|			c->cb(DROPBEAR_FAILURE, -1, c->cb_data, c->errstring);
  ------------------
  |  |  103|     97|#define DROPBEAR_FAILURE -1
  ------------------
  254|     97|			remove_connect(c, iter);
  255|     97|		}
  256|     97|		iter = next_iter;
  257|     97|	}
  258|   458k|}
handle_connect_fds:
  260|   456k|void handle_connect_fds(const fd_set *writefd) {
  261|   456k|	m_list_elem *iter;
  262|   456k|	for (iter = ses.conn_pending.first; iter; iter = iter->next) {
  ------------------
  |  Branch (262:38): [True: 98, False: 456k]
  ------------------
  263|     98|		int val;
  264|     98|		socklen_t vallen = sizeof(val);
  265|     98|		struct dropbear_progress_connection *c = iter->item;
  266|       |
  267|     98|		if (c->sock < 0 || !FD_ISSET(c->sock, writefd)) {
  ------------------
  |  Branch (267:7): [True: 98, False: 0]
  |  Branch (267:22): [True: 0, False: 0]
  ------------------
  268|     98|			continue;
  269|     98|		}
  270|       |
  271|      0|		TRACE(("handling %s port %s socket %d", c->remotehost, c->remoteport, c->sock));
  272|       |
  273|      0|		if (getsockopt(c->sock, SOL_SOCKET, SO_ERROR, &val, &vallen) != 0) {
  ------------------
  |  Branch (273:7): [True: 0, False: 0]
  ------------------
  274|      0|			TRACE(("handle_connect_fds getsockopt(%d) SO_ERROR failed: %s", c->sock, strerror(errno)))
  275|       |			/* This isn't expected to happen - Unix has surprises though, continue gracefully. */
  276|      0|			m_close(c->sock);
  277|      0|			c->sock = -1;
  278|      0|		} else if (val != 0) {
  ------------------
  |  Branch (278:14): [True: 0, False: 0]
  ------------------
  279|       |			/* Connect failed */
  280|      0|			TRACE(("connect to %s port %s failed.", c->remotehost, c->remoteport))
  281|      0|			m_close(c->sock);
  282|      0|			c->sock = -1;
  283|       |
  284|      0|			m_free(c->errstring);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  285|      0|			c->errstring = m_strdup(strerror(val));
  286|      0|		} else {
  287|       |			/* New connection has been established */
  288|      0|			c->cb(DROPBEAR_SUCCESS, c->sock, c->cb_data, NULL);
  ------------------
  |  |  102|      0|#define DROPBEAR_SUCCESS 0
  ------------------
  289|      0|			remove_connect(c, iter);
  290|      0|			TRACE(("leave handle_connect_fds - success"))
  291|       |			/* Must return here - remove_connect() invalidates iter */
  292|      0|			return; 
  293|      0|		}
  294|      0|	}
  295|   456k|}
packet_queue_to_iovec:
  301|   234k|void packet_queue_to_iovec(const struct Queue *queue, struct iovec *iov, unsigned int *iov_count) {
  302|   234k|	struct Link *l;
  303|   234k|	unsigned int i;
  304|   234k|	int len;
  305|   234k|	buffer *writebuf;
  306|       |
  307|       |#ifndef IOV_MAX
  308|       |	#if defined(__CYGWIN__) && !defined(UIO_MAXIOV)
  309|       |		#define IOV_MAX 1024
  310|       |	#elif defined(__sgi)
  311|       |		#define IOV_MAX 512 
  312|       |	#else 
  313|       |		#define IOV_MAX UIO_MAXIOV
  314|       |	#endif
  315|       |#endif
  316|       |
  317|   234k|	*iov_count = MIN(MIN(queue->count, IOV_MAX), *iov_count);
  318|       |
  319|  2.77M|	for (l = queue->head, i = 0; i < *iov_count; l = l->link, i++)
  ------------------
  |  Branch (319:31): [True: 2.53M, False: 234k]
  ------------------
  320|  2.53M|	{
  321|  2.53M|		writebuf = (buffer*)l->item;
  322|  2.53M|		len = writebuf->len - writebuf->pos;
  323|  2.53M|		dropbear_assert(len > 0);
  ------------------
  |  |   83|  2.53M|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 2.53M]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
  324|  2.53M|		TRACE2(("write_packet writev #%d len %d/%d", i,
  325|  2.53M|				len, writebuf->len))
  326|  2.53M|		iov[i].iov_base = buf_getptr(writebuf, len);
  327|  2.53M|		iov[i].iov_len = len;
  328|  2.53M|	}
  329|   234k|}
packet_queue_consume:
  331|   234k|void packet_queue_consume(struct Queue *queue, ssize_t written) {
  332|   234k|	buffer *writebuf;
  333|   234k|	int len;
  334|   469k|	while (written > 0) {
  ------------------
  |  Branch (334:9): [True: 234k, False: 234k]
  ------------------
  335|   234k|		writebuf = (buffer*)examine(queue);
  336|   234k|		len = writebuf->len - writebuf->pos;
  337|   234k|		if (len > written) {
  ------------------
  |  Branch (337:7): [True: 0, False: 234k]
  ------------------
  338|       |			/* partial buffer write */
  339|      0|			buf_incrpos(writebuf, written);
  340|      0|			written = 0;
  341|   234k|		} else {
  342|   234k|			written -= len;
  343|   234k|			dequeue(queue);
  344|   234k|			buf_free(writebuf);
  345|   234k|		}
  346|   234k|	}
  347|   234k|}
set_sock_priority:
  367|  3.17k|void set_sock_priority(int sock, enum dropbear_prio prio) {
  368|       |
  369|  3.17k|	int rc;
  370|  3.17k|	int val;
  371|       |
  372|  3.17k|#if DROPBEAR_FUZZ
  373|  3.17k|	if (fuzz.fuzzing) {
  ------------------
  |  Branch (373:6): [True: 3.17k, False: 0]
  ------------------
  374|  3.17k|		TRACE(("fuzzing skips set_sock_prio"))
  375|  3.17k|		return;
  376|  3.17k|	}
  377|      0|#endif
  378|       |	/* Don't log ENOTSOCK errors so that this can harmlessly be called
  379|       |	 * on a client '-J' proxy pipe */
  380|       |
  381|      0|	if (opts.disable_ip_tos == 0) {
  ------------------
  |  Branch (381:6): [True: 0, False: 0]
  ------------------
  382|      0|#ifdef IP_TOS
  383|       |	/* Set the DSCP field for outbound IP packet priority.
  384|       |	rfc4594 has some guidance to meanings.
  385|       |
  386|       |	We set AF21 as "Low-Latency" class for interactive (tty session,
  387|       |	also handshake/setup packets). Other traffic is left at the default.
  388|       |
  389|       |	OpenSSH at present uses AF21/CS1, rationale
  390|       |	https://cvsweb.openbsd.org/src/usr.bin/ssh/readconf.c#rev1.284
  391|       |
  392|       |	Old Dropbear/OpenSSH and Debian/Ubuntu OpenSSH (at Jan 2022) use
  393|       |	IPTOS_LOWDELAY/IPTOS_THROUGHPUT
  394|       |
  395|       |	DSCP constants are from Linux headers, applicable to other platforms
  396|       |	such as macos.
  397|       |	*/
  398|      0|	if (prio == DROPBEAR_PRIO_LOWDELAY) {
  ------------------
  |  Branch (398:6): [True: 0, False: 0]
  ------------------
  399|      0|		val = 0x48; /* IPTOS_DSCP_AF21 */
  400|      0|	} else {
  401|      0|		val = 0; /* default */
  402|      0|	}
  403|      0|#if defined(IPPROTO_IPV6) && defined(IPV6_TCLASS)
  404|      0|	rc = setsockopt(sock, IPPROTO_IPV6, IPV6_TCLASS, (void*)&val, sizeof(val));
  405|      0|	if (rc < 0 && errno != ENOTSOCK) {
  ------------------
  |  Branch (405:6): [True: 0, False: 0]
  |  Branch (405:16): [True: 0, False: 0]
  ------------------
  406|      0|		TRACE(("Couldn't set IPV6_TCLASS (%s)", strerror(errno)));
  407|      0|	}
  408|      0|#endif
  409|      0|	rc = setsockopt(sock, IPPROTO_IP, IP_TOS, (void*)&val, sizeof(val));
  410|      0|	if (rc < 0 && errno != ENOTSOCK) {
  ------------------
  |  Branch (410:6): [True: 0, False: 0]
  |  Branch (410:16): [True: 0, False: 0]
  ------------------
  411|      0|		TRACE(("Couldn't set IP_TOS (%s)", strerror(errno)));
  412|      0|	}
  413|      0|#endif /* IP_TOS */
  414|      0|	}
  415|       |
  416|      0|#ifdef HAVE_LINUX_PKT_SCHED_H
  417|       |	/* Set scheduling priority within the local Linux network stack */
  418|      0|	if (prio == DROPBEAR_PRIO_LOWDELAY) {
  ------------------
  |  Branch (418:6): [True: 0, False: 0]
  ------------------
  419|      0|		val = TC_PRIO_INTERACTIVE;
  420|      0|	} else {
  421|      0|		val = 0;
  422|      0|	}
  423|       |	/* linux specific, sets QoS class. see tc-prio(8) */
  424|      0|	rc = setsockopt(sock, SOL_SOCKET, SO_PRIORITY, (void*) &val, sizeof(val));
  425|      0|	if (rc < 0 && errno != ENOTSOCK) {
  ------------------
  |  Branch (425:6): [True: 0, False: 0]
  |  Branch (425:16): [True: 0, False: 0]
  ------------------
  426|      0|		TRACE(("Couldn't set SO_PRIORITY (%s)", strerror(errno)))
  427|      0|    }
  428|      0|#endif
  429|       |
  430|      0|}
dropbear_listen:
  470|  1.22k|		int *socks, unsigned int sockcount, char **errstring, int *maxfd) {
  471|       |
  472|  1.22k|	struct addrinfo hints, *res = NULL, *res0 = NULL;
  473|  1.22k|	int err;
  474|  1.22k|	unsigned int nsock;
  475|  1.22k|	struct linger linger;
  476|  1.22k|	int val;
  477|  1.22k|	int sock;
  478|  1.22k|	uint16_t *allocated_lport_p = NULL;
  479|  1.22k|	int allocated_lport = 0;
  480|       |	
  481|  1.22k|	TRACE(("enter dropbear_listen"))
  482|       |
  483|  1.22k|#if DROPBEAR_FUZZ
  484|  1.22k|	if (fuzz.fuzzing) {
  ------------------
  |  Branch (484:6): [True: 1.22k, False: 0]
  ------------------
  485|  1.22k|		return fuzz_dropbear_listen(address, port, socks, sockcount, errstring, maxfd);
  486|  1.22k|	}
  487|      0|#endif
  488|       |	
  489|      0|	memset(&hints, 0, sizeof(hints));
  490|      0|	hints.ai_family = AF_UNSPEC; /* TODO: let them flag v4 only etc */
  491|      0|	hints.ai_socktype = SOCK_STREAM;
  492|       |
  493|       |	/* for calling getaddrinfo:
  494|       |	 address == NULL and !AI_PASSIVE: local loopback
  495|       |	 address == NULL and AI_PASSIVE: all interfaces
  496|       |	 address != NULL: whatever the address says */
  497|      0|	if (!address) {
  ------------------
  |  Branch (497:6): [True: 0, False: 0]
  ------------------
  498|      0|		TRACE(("dropbear_listen: local loopback"))
  499|      0|	} else {
  500|      0|		if (address[0] == '\0') {
  ------------------
  |  Branch (500:7): [True: 0, False: 0]
  ------------------
  501|      0|			TRACE(("dropbear_listen: all interfaces"))
  502|      0|			address = NULL;
  503|      0|		}
  504|      0|		hints.ai_flags = AI_PASSIVE;
  505|      0|	}
  506|      0|	err = getaddrinfo(address, port, &hints, &res0);
  507|       |
  508|      0|	if (err) {
  ------------------
  |  Branch (508:6): [True: 0, False: 0]
  ------------------
  509|      0|		if (errstring != NULL && *errstring == NULL) {
  ------------------
  |  Branch (509:7): [True: 0, False: 0]
  |  Branch (509:28): [True: 0, False: 0]
  ------------------
  510|      0|			int len;
  511|      0|			len = 20 + strlen(gai_strerror(err));
  512|      0|			*errstring = (char*)m_malloc(len);
  513|      0|			snprintf(*errstring, len, "Error resolving: %s", gai_strerror(err));
  514|      0|		}
  515|      0|		if (res0) {
  ------------------
  |  Branch (515:7): [True: 0, False: 0]
  ------------------
  516|      0|			freeaddrinfo(res0);
  517|      0|			res0 = NULL;
  518|      0|		}
  519|      0|		TRACE(("leave dropbear_listen: failed resolving"))
  520|      0|		return -1;
  521|      0|	}
  522|       |
  523|       |	/* When listening on server-assigned-port 0
  524|       |	 * the assigned ports may differ for address families (v4/v6)
  525|       |	 * causing problems for tcpip-forward.
  526|       |	 * Caller can do a get_socket_address to discover assigned-port
  527|       |	 * hence, use same port for all address families */
  528|      0|	allocated_lport = 0;
  529|      0|	nsock = 0;
  530|      0|	for (res = res0; res != NULL && nsock < sockcount;
  ------------------
  |  Branch (530:19): [True: 0, False: 0]
  |  Branch (530:34): [True: 0, False: 0]
  ------------------
  531|      0|			res = res->ai_next) {
  532|      0|		if (allocated_lport > 0) {
  ------------------
  |  Branch (532:7): [True: 0, False: 0]
  ------------------
  533|      0|			if (AF_INET == res->ai_family) {
  ------------------
  |  Branch (533:8): [True: 0, False: 0]
  ------------------
  534|      0|				allocated_lport_p = &((struct sockaddr_in *)res->ai_addr)->sin_port;
  535|      0|			} else if (AF_INET6 == res->ai_family) {
  ------------------
  |  Branch (535:15): [True: 0, False: 0]
  ------------------
  536|      0|				allocated_lport_p = &((struct sockaddr_in6 *)res->ai_addr)->sin6_port;
  537|      0|			}
  538|      0|			*allocated_lport_p = htons(allocated_lport);
  539|      0|		}
  540|       |
  541|       |		/* Get a socket */
  542|      0|		socks[nsock] = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
  543|      0|		sock = socks[nsock]; /* For clarity */
  544|      0|		if (sock < 0) {
  ------------------
  |  Branch (544:7): [True: 0, False: 0]
  ------------------
  545|      0|			err = errno;
  546|      0|			TRACE(("socket() failed"))
  547|      0|			continue;
  548|      0|		}
  549|       |
  550|       |		/* Various useful socket options */
  551|      0|		val = 1;
  552|       |		/* set to reuse, quick timeout */
  553|      0|		setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void*) &val, sizeof(val));
  554|      0|		linger.l_onoff = 1;
  555|      0|		linger.l_linger = 5;
  556|      0|		setsockopt(sock, SOL_SOCKET, SO_LINGER, (void*)&linger, sizeof(linger));
  557|       |
  558|      0|#if defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY)
  559|      0|		if (res->ai_family == AF_INET6) {
  ------------------
  |  Branch (559:7): [True: 0, False: 0]
  ------------------
  560|      0|			int on = 1;
  561|      0|			if (setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, 
  ------------------
  |  Branch (561:8): [True: 0, False: 0]
  ------------------
  562|      0|						&on, sizeof(on)) == -1) {
  563|      0|				dropbear_log(LOG_WARNING, "Couldn't set IPV6_V6ONLY");
  564|      0|			}
  565|      0|		}
  566|      0|#endif
  567|      0|		set_sock_nodelay(sock);
  568|       |
  569|      0|		if (bind(sock, res->ai_addr, res->ai_addrlen) < 0) {
  ------------------
  |  Branch (569:7): [True: 0, False: 0]
  ------------------
  570|      0|			err = errno;
  571|      0|			close(sock);
  ------------------
  |  |   56|      0|#define close(fd) wrapfd_close(fd)
  ------------------
  572|      0|			TRACE(("bind(%s) failed", port))
  573|      0|			continue;
  574|      0|		}
  575|       |
  576|      0|		if (listen(sock, DROPBEAR_LISTEN_BACKLOG) < 0) {
  ------------------
  |  |  349|      0|#define DROPBEAR_LISTEN_BACKLOG MAX_CHANNELS
  |  |  ------------------
  |  |  |  |  225|      0|#define MAX_CHANNELS 1000 /* simple mem restriction, includes each tcp/x11
  |  |  ------------------
  ------------------
  |  Branch (576:7): [True: 0, False: 0]
  ------------------
  577|      0|			err = errno;
  578|      0|			close(sock);
  ------------------
  |  |   56|      0|#define close(fd) wrapfd_close(fd)
  ------------------
  579|      0|			TRACE(("listen() failed"))
  580|      0|			continue;
  581|      0|		}
  582|       |
  583|      0|		if (0 == allocated_lport) {
  ------------------
  |  Branch (583:7): [True: 0, False: 0]
  ------------------
  584|      0|			allocated_lport = get_sock_port(sock);
  585|      0|		}
  586|       |
  587|      0|		*maxfd = MAX(*maxfd, sock);
  588|      0|		nsock++;
  589|      0|	}
  590|       |
  591|      0|	if (res0) {
  ------------------
  |  Branch (591:6): [True: 0, False: 0]
  ------------------
  592|      0|		freeaddrinfo(res0);
  593|      0|		res0 = NULL;
  594|      0|	}
  595|       |
  596|      0|	if (nsock == 0) {
  ------------------
  |  Branch (596:6): [True: 0, False: 0]
  ------------------
  597|      0|		if (errstring != NULL && *errstring == NULL) {
  ------------------
  |  Branch (597:7): [True: 0, False: 0]
  |  Branch (597:28): [True: 0, False: 0]
  ------------------
  598|      0|			int len;
  599|      0|			len = 20 + strlen(strerror(err));
  600|      0|			*errstring = (char*)m_malloc(len);
  601|      0|			snprintf(*errstring, len, "Error listening: %s", strerror(err));
  602|      0|		}
  603|      0|		TRACE(("leave dropbear_listen: failure, %s", strerror(err)))
  604|      0|		return -1;
  605|      0|	}
  606|       |
  607|      0|	TRACE(("leave dropbear_listen: success, %d socks bound", nsock))
  608|      0|	return nsock;
  609|      0|}
get_socket_address:
  613|  5.57k|{
  614|  5.57k|	struct sockaddr_storage addr;
  615|  5.57k|	socklen_t addrlen;
  616|       |
  617|  5.57k|#if DROPBEAR_FUZZ
  618|  5.57k|	if (fuzz.fuzzing) {
  ------------------
  |  Branch (618:6): [True: 5.57k, False: 0]
  ------------------
  619|  5.57k|		fuzz_get_socket_address(fd, local_host, local_port, remote_host, remote_port, host_lookup);
  620|  5.57k|		return;
  621|  5.57k|	}
  622|      0|#endif
  623|       |	
  624|      0|	if (local_host || local_port) {
  ------------------
  |  Branch (624:6): [True: 0, False: 0]
  |  Branch (624:20): [True: 0, False: 0]
  ------------------
  625|      0|		addrlen = sizeof(addr);
  626|      0|		if (getsockname(fd, (struct sockaddr*)&addr, &addrlen) < 0) {
  ------------------
  |  Branch (626:7): [True: 0, False: 0]
  ------------------
  627|      0|			dropbear_exit("Failed socket address: %s", strerror(errno));
  628|      0|		}
  629|      0|		getaddrstring(&addr, local_host, local_port, host_lookup);		
  630|      0|	}
  631|      0|	if (remote_host || remote_port) {
  ------------------
  |  Branch (631:6): [True: 0, False: 0]
  |  Branch (631:21): [True: 0, False: 0]
  ------------------
  632|      0|		addrlen = sizeof(addr);
  633|      0|		if (getpeername(fd, (struct sockaddr*)&addr, &addrlen) < 0) {
  ------------------
  |  Branch (633:7): [True: 0, False: 0]
  ------------------
  634|      0|			dropbear_exit("Failed socket address: %s", strerror(errno));
  635|      0|		}
  636|      0|		getaddrstring(&addr, remote_host, remote_port, host_lookup);		
  637|      0|	}
  638|      0|}
netio.c:remove_connect:
   29|     98|static void remove_connect(struct dropbear_progress_connection *c, m_list_elem *iter) {
   30|     98|	if (c->res) {
  ------------------
  |  Branch (30:6): [True: 0, False: 98]
  ------------------
   31|      0|		freeaddrinfo(c->res);
   32|      0|	}
   33|     98|	m_free(c->remotehost);
  ------------------
  |  |   24|     98|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
   34|     98|	m_free(c->remoteport);
  ------------------
  |  |   24|     98|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
   35|     98|	m_free(c->errstring);
  ------------------
  |  |   24|     98|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
   36|     98|	m_free(c->bind_address);
  ------------------
  |  |   24|     98|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
   37|     98|	m_free(c->bind_port);
  ------------------
  |  |   24|     98|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
   38|     98|	m_free(c);
  ------------------
  |  |   24|     98|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
   39|       |
   40|     98|	if (iter) {
  ------------------
  |  Branch (40:6): [True: 98, False: 0]
  ------------------
   41|     98|		list_remove(iter);
   42|     98|	}
   43|     98|}

write_packet:
   58|   234k|void write_packet() {
   59|       |
   60|   234k|	ssize_t written;
   61|   234k|#if defined(HAVE_WRITEV) && (defined(IOV_MAX) || defined(UIO_MAXIOV))
   62|       |	/* 50 is somewhat arbitrary */
   63|   234k|	unsigned int iov_count = 50;
   64|   234k|	struct iovec iov[50];
   65|       |#else
   66|       |	int len;
   67|       |	buffer* writebuf;
   68|       |#endif
   69|       |	
   70|   234k|	TRACE2(("enter write_packet"))
   71|   234k|	dropbear_assert(!isempty(&ses.writequeue));
  ------------------
  |  |   83|   234k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 234k]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
   72|       |
   73|   234k|#if defined(HAVE_WRITEV) && (defined(IOV_MAX) || defined(UIO_MAXIOV))
   74|       |
   75|   234k|	packet_queue_to_iovec(&ses.writequeue, iov, &iov_count);
   76|       |	/* This may return EAGAIN. The main loop sometimes
   77|       |	calls write_packet() without bothering to test with select() since
   78|       |	it's likely to be necessary */
   79|   234k|#if DROPBEAR_FUZZ
   80|   234k|	if (fuzz.fuzzing) {
  ------------------
  |  Branch (80:6): [True: 234k, False: 0]
  ------------------
   81|       |		/* pretend to write one packet at a time */
   82|       |		/* TODO(fuzz): randomise amount written based on the fuzz input */
   83|   234k|		written = iov[0].iov_len;
   84|   234k|	}
   85|      0|	else
   86|      0|#endif
   87|      0|	{
   88|      0|	written = writev(ses.sock_out, iov, iov_count);
   89|      0|	if (written < 0) {
  ------------------
  |  Branch (89:6): [True: 0, False: 0]
  ------------------
   90|      0|		if (errno == EINTR || errno == EAGAIN) {
  ------------------
  |  Branch (90:7): [True: 0, False: 0]
  |  Branch (90:25): [True: 0, False: 0]
  ------------------
   91|      0|			TRACE2(("leave write_packet: EINTR"))
   92|      0|			return;
   93|      0|		} else {
   94|      0|			dropbear_exit("Error writing: %s", strerror(errno));
   95|      0|		}
   96|      0|	}
   97|      0|	}
   98|       |
   99|   234k|	packet_queue_consume(&ses.writequeue, written);
  100|   234k|	ses.writequeue_len -= written;
  101|       |
  102|   234k|	if (written == 0) {
  ------------------
  |  Branch (102:6): [True: 0, False: 234k]
  ------------------
  103|      0|		ses.remoteclosed();
  104|      0|	}
  105|       |
  106|       |#else /* No writev () */
  107|       |#if DROPBEAR_FUZZ
  108|       |	_Static_assert(0, "No fuzzing code for no-writev writes");
  109|       |#endif
  110|       |	/* Get the next buffer in the queue of encrypted packets to write*/
  111|       |	writebuf = (buffer*)examine(&ses.writequeue);
  112|       |
  113|       |	len = writebuf->len - writebuf->pos;
  114|       |	dropbear_assert(len > 0);
  115|       |	/* Try to write as much as possible */
  116|       |	written = write(ses.sock_out, buf_getptr(writebuf, len), len);
  117|       |
  118|       |	if (written < 0) {
  119|       |		if (errno == EINTR || errno == EAGAIN) {
  120|       |			TRACE2(("leave writepacket: EINTR"))
  121|       |			return;
  122|       |		} else {
  123|       |			dropbear_exit("Error writing: %s", strerror(errno));
  124|       |		}
  125|       |	} 
  126|       |
  127|       |	if (written == 0) {
  128|       |		ses.remoteclosed();
  129|       |	}
  130|       |
  131|       |	ses.writequeue_len -= written;
  132|       |
  133|       |	if (written == len) {
  134|       |		/* We've finished with the packet, free it */
  135|       |		dequeue(&ses.writequeue);
  136|       |		buf_free(writebuf);
  137|       |		writebuf = NULL;
  138|       |	} else {
  139|       |		/* More packet left to write, leave it in the queue for later */
  140|       |		buf_incrpos(writebuf, written);
  141|       |	}
  142|       |#endif /* writev */
  143|       |
  144|   234k|	TRACE2(("leave write_packet"))
  145|   234k|}
read_packet:
  150|   273k|void read_packet() {
  151|       |
  152|   273k|	int len;
  153|   273k|	unsigned int maxlen;
  154|   273k|	unsigned char blocksize;
  155|       |
  156|   273k|	TRACE2(("enter read_packet"))
  157|   273k|	blocksize = ses.keys->recv.algo_crypt->blocksize;
  158|       |	
  159|   273k|	if (ses.readbuf == NULL || ses.readbuf->len < blocksize) {
  ------------------
  |  Branch (159:6): [True: 53.2k, False: 220k]
  |  Branch (159:29): [True: 96.0k, False: 124k]
  ------------------
  160|   149k|		int ret;
  161|       |		/* In the first blocksize of a packet */
  162|       |
  163|       |		/* Read the first blocksize of the packet, so we can decrypt it and
  164|       |		 * find the length of the whole packet */
  165|   149k|		ret = read_packet_init();
  166|       |
  167|   149k|		if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|   149k|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (167:7): [True: 96.0k, False: 53.2k]
  ------------------
  168|       |			/* didn't read enough to determine the length */
  169|  96.0k|			TRACE2(("leave read_packet: packetinit done"))
  170|  96.0k|			return;
  171|  96.0k|		}
  172|   149k|	}
  173|       |
  174|       |	/* Attempt to read the remainder of the packet, note that there
  175|       |	 * mightn't be any available (EAGAIN) */
  176|   177k|	maxlen = ses.readbuf->len - ses.readbuf->pos;
  177|   177k|	if (maxlen == 0) {
  ------------------
  |  Branch (177:6): [True: 8.51k, False: 169k]
  ------------------
  178|       |		/* Occurs when the packet is only a single block long and has all
  179|       |		 * been read in read_packet_init().  Usually means that MAC is disabled
  180|       |		 */
  181|  8.51k|		len = 0;
  182|   169k|	} else {
  183|   169k|		len = read(ses.sock_in, buf_getptr(ses.readbuf, maxlen), maxlen);
  ------------------
  |  |   55|   169k|#define read(fd, buf, count) wrapfd_read(fd, buf, count)
  ------------------
  184|       |
  185|   169k|		if (len == 0) {
  ------------------
  |  Branch (185:7): [True: 129, False: 169k]
  ------------------
  186|    129|			ses.remoteclosed();
  187|    129|		}
  188|       |
  189|   169k|		if (len < 0) {
  ------------------
  |  Branch (189:7): [True: 215, False: 169k]
  ------------------
  190|    215|			if (errno == EINTR || errno == EAGAIN) {
  ------------------
  |  Branch (190:8): [True: 212, False: 3]
  |  Branch (190:26): [True: 0, False: 3]
  ------------------
  191|    212|				TRACE2(("leave read_packet: EINTR or EAGAIN"))
  192|    212|				return;
  193|    212|			} else {
  194|      3|				dropbear_exit("Error reading: %s", strerror(errno));
  195|      3|			}
  196|    215|		}
  197|       |
  198|   169k|		buf_incrpos(ses.readbuf, len);
  199|   169k|	}
  200|       |
  201|   177k|	if ((unsigned int)len == maxlen) {
  ------------------
  |  Branch (201:6): [True: 52.0k, False: 125k]
  ------------------
  202|       |		/* The whole packet has been read */
  203|  52.0k|		decrypt_packet();
  204|       |		/* The main select() loop process_packet() to
  205|       |		 * handle the packet contents... */
  206|  52.0k|	}
  207|   177k|	TRACE2(("leave read_packet"))
  208|   177k|}
decrypt_packet:
  298|  52.0k|void decrypt_packet() {
  299|       |
  300|  52.0k|	unsigned char blocksize;
  301|  52.0k|	unsigned char macsize;
  302|  52.0k|	unsigned int padlen;
  303|  52.0k|	unsigned int len;
  304|       |
  305|  52.0k|	TRACE2(("enter decrypt_packet"))
  306|  52.0k|	blocksize = ses.keys->recv.algo_crypt->blocksize;
  307|  52.0k|	macsize = ses.keys->recv.algo_mac->hashsize;
  308|       |
  309|  52.0k|	ses.kexstate.datarecv += ses.readbuf->len;
  310|       |
  311|  52.0k|#if DROPBEAR_AEAD_MODE
  312|  52.0k|	if (ses.keys->recv.crypt_mode->aead_crypt) {
  ------------------
  |  Branch (312:6): [True: 0, False: 52.0k]
  ------------------
  313|       |		/* first blocksize is not decrypted yet */
  314|      0|		buf_setpos(ses.readbuf, 0);
  315|       |
  316|       |		/* decrypt it in-place */
  317|      0|		len = ses.readbuf->len - macsize - ses.readbuf->pos;
  318|      0|		if (ses.keys->recv.crypt_mode->aead_crypt(ses.recvseq,
  ------------------
  |  Branch (318:7): [True: 0, False: 0]
  ------------------
  319|      0|					buf_getptr(ses.readbuf, len + macsize),
  320|      0|					buf_getwriteptr(ses.readbuf, len),
  321|      0|					len, macsize,
  322|      0|					&ses.keys->recv.cipher_state, LTC_DECRYPT) != CRYPT_OK) {
  ------------------
  |  |   70|      0|#define LTC_DECRYPT 1
  ------------------
  323|      0|			dropbear_exit("Error decrypting");
  324|      0|		}
  325|      0|		buf_incrpos(ses.readbuf, len);
  326|      0|	} else
  327|  52.0k|#endif
  328|  52.0k|	{
  329|       |		/* we've already decrypted the first blocksize in read_packet_init */
  330|  52.0k|		buf_setpos(ses.readbuf, blocksize);
  331|       |
  332|       |		/* decrypt it in-place */
  333|  52.0k|		len = ses.readbuf->len - macsize - ses.readbuf->pos;
  334|  52.0k|		if (ses.keys->recv.crypt_mode->decrypt(
  ------------------
  |  Branch (334:7): [True: 0, False: 52.0k]
  ------------------
  335|  52.0k|					buf_getptr(ses.readbuf, len), 
  336|  52.0k|					buf_getwriteptr(ses.readbuf, len),
  337|  52.0k|					len,
  338|  52.0k|					&ses.keys->recv.cipher_state) != CRYPT_OK) {
  339|      0|			dropbear_exit("Error decrypting");
  340|      0|		}
  341|  52.0k|		buf_incrpos(ses.readbuf, len);
  342|       |
  343|       |		/* check the hmac */
  344|  52.0k|		if (checkmac() != DROPBEAR_SUCCESS) {
  ------------------
  |  |  102|  52.0k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (344:7): [True: 0, False: 52.0k]
  ------------------
  345|      0|			dropbear_exit("Integrity error");
  346|      0|		}
  347|       |
  348|  52.0k|	}
  349|       |	
  350|  52.0k|#if DROPBEAR_FUZZ
  351|  52.0k|	fuzz_dump(ses.readbuf->data, ses.readbuf->len);
  352|  52.0k|#endif
  353|       |
  354|       |	/* get padding length */
  355|  52.0k|	buf_setpos(ses.readbuf, PACKET_PADDING_OFF);
  ------------------
  |  |   48|  52.0k|#define PACKET_PADDING_OFF 4
  ------------------
  356|  52.0k|	padlen = buf_getbyte(ses.readbuf);
  357|       |		
  358|       |	/* payload length */
  359|       |	/* - 4 - 1 is for LEN and PADLEN values */
  360|  52.0k|	len = ses.readbuf->len - padlen - 4 - 1 - macsize;
  361|  52.0k|	if ((len > RECV_MAX_PAYLOAD_LEN+ZLIB_COMPRESS_EXPANSION) || (len < 1)) {
  ------------------
  |  |  492|  52.0k|#define RECV_MAX_PAYLOAD_LEN 32768
  ------------------
              	if ((len > RECV_MAX_PAYLOAD_LEN+ZLIB_COMPRESS_EXPANSION) || (len < 1)) {
  ------------------
  |  |   50|  52.0k|#define ZLIB_COMPRESS_EXPANSION (((RECV_MAX_PAYLOAD_LEN/16384)+1)*5 + 6)
  |  |  ------------------
  |  |  |  |  492|  52.0k|#define RECV_MAX_PAYLOAD_LEN 32768
  |  |  ------------------
  ------------------
  |  Branch (361:6): [True: 7, False: 52.0k]
  |  Branch (361:62): [True: 0, False: 52.0k]
  ------------------
  362|      7|		dropbear_exit("Bad packet size %u", len);
  363|      7|	}
  364|       |
  365|  52.0k|	buf_setpos(ses.readbuf, PACKET_PAYLOAD_OFF);
  ------------------
  |  |   49|  52.0k|#define PACKET_PAYLOAD_OFF 5
  ------------------
  366|       |
  367|       |#ifndef DISABLE_ZLIB
  368|       |	if (is_compress_recv()) {
  369|       |		/* decompress */
  370|       |		ses.payload = buf_decompress(ses.readbuf, len);
  371|       |		buf_setpos(ses.payload, 0);
  372|       |		ses.payload_beginning = 0;
  373|       |		buf_free(ses.readbuf);
  374|       |	} else 
  375|       |#endif
  376|  52.0k|	{
  377|  52.0k|		ses.payload = ses.readbuf;
  378|  52.0k|		ses.payload_beginning = ses.payload->pos;
  379|  52.0k|		buf_setlen(ses.payload, ses.payload->pos + len);
  380|  52.0k|	}
  381|  52.0k|	ses.readbuf = NULL;
  382|       |
  383|  52.0k|	ses.recvseq++;
  384|       |
  385|  52.0k|	TRACE2(("leave decrypt_packet"))
  386|  52.0k|}
maybe_flush_reply_queue:
  495|   456k|void maybe_flush_reply_queue() {
  496|   456k|	struct packetlist *tmp_item = NULL, *curr_item = NULL;
  497|   456k|	if (!ses.dataallowed)
  ------------------
  |  Branch (497:6): [True: 65.0k, False: 391k]
  ------------------
  498|  65.0k|	{
  499|  65.0k|		TRACE(("maybe_empty_reply_queue - no data allowed"))
  500|  65.0k|		return;
  501|  65.0k|	}
  502|       |		
  503|   392k|	for (curr_item = ses.reply_queue_head; curr_item; ) {
  ------------------
  |  Branch (503:41): [True: 462, False: 391k]
  ------------------
  504|    462|		CHECKCLEARTOWRITE();
  505|    462|		buf_putbytes(ses.writepayload,
  506|    462|			curr_item->payload->data, curr_item->payload->len);
  507|       |			
  508|    462|		buf_free(curr_item->payload);
  509|    462|		tmp_item = curr_item;
  510|    462|		curr_item = curr_item->next;
  511|    462|		m_free(tmp_item);
  ------------------
  |  |   24|    462|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  512|    462|		encrypt_packet();
  513|    462|	}
  514|   391k|	ses.reply_queue_head = ses.reply_queue_tail = NULL;
  515|   391k|}
encrypt_packet:
  519|   241k|void encrypt_packet() {
  520|       |
  521|   241k|	unsigned char padlen;
  522|   241k|	unsigned char blocksize, mac_size;
  523|   241k|	buffer * writebuf; /* the packet which will go on the wire. This is 
  524|       |	                      encrypted in-place. */
  525|   241k|	unsigned char packet_type;
  526|   241k|	unsigned int len, encrypt_buf_size;
  527|   241k|	unsigned char mac_bytes[MAX_MAC_LEN];
  528|       |
  529|   241k|	time_t now;
  530|       |	
  531|   241k|	TRACE2(("enter encrypt_packet()"))
  532|       |
  533|   241k|	buf_setpos(ses.writepayload, 0);
  534|   241k|	packet_type = buf_getbyte(ses.writepayload);
  535|   241k|	buf_setpos(ses.writepayload, 0);
  536|       |
  537|   241k|	TRACE2(("encrypt_packet type is %d", packet_type))
  538|       |	
  539|   241k|	if ((!ses.dataallowed && !packet_is_okay_kex(packet_type))) {
  ------------------
  |  Branch (539:7): [True: 11.3k, False: 229k]
  |  Branch (539:27): [True: 542, False: 10.8k]
  ------------------
  540|       |		/* During key exchange only particular packets are allowed.
  541|       |			Since this packet_type isn't OK we just enqueue it to send 
  542|       |			after the KEX, see maybe_flush_reply_queue */
  543|    542|		enqueue_reply_packet();
  544|    542|		return;
  545|    542|	}
  546|       |		
  547|   240k|	blocksize = ses.keys->trans.algo_crypt->blocksize;
  548|   240k|	mac_size = ses.keys->trans.algo_mac->hashsize;
  549|       |
  550|       |	/* Encrypted packet len is payload+5. We need to then make sure
  551|       |	 * there is enough space for padding or MIN_PACKET_LEN. 
  552|       |	 * Add extra 3 since we need at least 4 bytes of padding */
  553|   240k|	encrypt_buf_size = (ses.writepayload->len+4+1) 
  554|   240k|		+ MAX(MIN_PACKET_LEN, blocksize) + 3
  555|       |	/* add space for the MAC at the end */
  556|   240k|				+ mac_size
  557|       |#ifndef DISABLE_ZLIB
  558|       |	/* some extra in case 'compression' makes it larger */
  559|       |				+ ZLIB_COMPRESS_EXPANSION
  560|       |#endif
  561|       |	/* and an extra cleartext (stripped before transmission) byte for the
  562|       |	 * packet type */
  563|   240k|				+ 1;
  564|       |
  565|   240k|	writebuf = buf_new(encrypt_buf_size);
  566|   240k|	buf_setlen(writebuf, PACKET_PAYLOAD_OFF);
  ------------------
  |  |   49|   240k|#define PACKET_PAYLOAD_OFF 5
  ------------------
  567|   240k|	buf_setpos(writebuf, PACKET_PAYLOAD_OFF);
  ------------------
  |  |   49|   240k|#define PACKET_PAYLOAD_OFF 5
  ------------------
  568|       |
  569|       |#ifndef DISABLE_ZLIB
  570|       |	/* compression */
  571|       |	if (is_compress_trans()) {
  572|       |		buf_compress(writebuf, ses.writepayload, ses.writepayload->len);
  573|       |	} else
  574|       |#endif
  575|   240k|	{
  576|   240k|		memcpy(buf_getwriteptr(writebuf, ses.writepayload->len),
  577|   240k|				buf_getptr(ses.writepayload, ses.writepayload->len),
  578|   240k|				ses.writepayload->len);
  579|   240k|		buf_incrwritepos(writebuf, ses.writepayload->len);
  580|   240k|	}
  581|       |
  582|       |	/* finished with payload */
  583|   240k|	buf_setpos(ses.writepayload, 0);
  584|   240k|	buf_setlen(ses.writepayload, 0);
  585|       |
  586|       |	/* length of padding - packet length excluding the packetlength uint32
  587|       |	 * field in aead mode must be a multiple of blocksize, with a minimum of
  588|       |	 * 4 bytes of padding */
  589|   240k|	len = writebuf->len;
  590|   240k|#if DROPBEAR_AEAD_MODE
  591|   240k|	if (ses.keys->trans.crypt_mode->aead_crypt) {
  ------------------
  |  Branch (591:6): [True: 214k, False: 25.9k]
  ------------------
  592|   214k|		len -= 4;
  593|   214k|	}
  594|   240k|#endif
  595|   240k|	padlen = blocksize - len % blocksize;
  596|   240k|	if (padlen < 4) {
  ------------------
  |  Branch (596:6): [True: 82.8k, False: 157k]
  ------------------
  597|  82.8k|		padlen += blocksize;
  598|  82.8k|	}
  599|       |	/* check for min packet length */
  600|   240k|	if (writebuf->len + padlen < MIN_PACKET_LEN) {
  ------------------
  |  |  213|   240k|#define MIN_PACKET_LEN 16
  ------------------
  |  Branch (600:6): [True: 5.75k, False: 234k]
  ------------------
  601|  5.75k|		padlen += blocksize;
  602|  5.75k|	}
  603|       |
  604|   240k|	buf_setpos(writebuf, 0);
  605|       |	/* packet length excluding the packetlength uint32 */
  606|   240k|	buf_putint(writebuf, writebuf->len + padlen - 4);
  607|       |
  608|       |	/* padding len */
  609|   240k|	buf_putbyte(writebuf, padlen);
  610|       |	/* actual padding */
  611|   240k|	buf_setpos(writebuf, writebuf->len);
  612|   240k|	buf_incrlen(writebuf, padlen);
  613|   240k|	genrandom(buf_getptr(writebuf, padlen), padlen);
  614|       |
  615|   240k|#if DROPBEAR_AEAD_MODE
  616|   240k|	if (ses.keys->trans.crypt_mode->aead_crypt) {
  ------------------
  |  Branch (616:6): [True: 214k, False: 25.9k]
  ------------------
  617|       |		/* do the actual encryption, in-place */
  618|   214k|		buf_setpos(writebuf, 0);
  619|       |		/* encrypt it in-place*/
  620|   214k|		len = writebuf->len;
  621|   214k|		buf_incrlen(writebuf, mac_size);
  622|   214k|		if (ses.keys->trans.crypt_mode->aead_crypt(ses.transseq,
  ------------------
  |  Branch (622:7): [True: 0, False: 214k]
  ------------------
  623|   214k|					buf_getptr(writebuf, len),
  624|   214k|					buf_getwriteptr(writebuf, len + mac_size),
  625|   214k|					len, mac_size,
  626|   214k|					&ses.keys->trans.cipher_state, LTC_ENCRYPT) != CRYPT_OK) {
  ------------------
  |  |   68|   214k|#define LTC_ENCRYPT 0
  ------------------
  627|      0|			dropbear_exit("Error encrypting");
  628|      0|		}
  629|   214k|		buf_incrpos(writebuf, len + mac_size);
  630|   214k|	} else
  631|  25.9k|#endif
  632|  25.9k|	{
  633|  25.9k|		make_mac(ses.transseq, &ses.keys->trans, writebuf, writebuf->len, mac_bytes);
  634|       |
  635|       |		/* do the actual encryption, in-place */
  636|  25.9k|		buf_setpos(writebuf, 0);
  637|       |		/* encrypt it in-place*/
  638|  25.9k|		len = writebuf->len;
  639|  25.9k|		if (ses.keys->trans.crypt_mode->encrypt(
  ------------------
  |  Branch (639:7): [True: 0, False: 25.9k]
  ------------------
  640|  25.9k|					buf_getptr(writebuf, len),
  641|  25.9k|					buf_getwriteptr(writebuf, len),
  642|  25.9k|					len,
  643|  25.9k|					&ses.keys->trans.cipher_state) != CRYPT_OK) {
  644|      0|			dropbear_exit("Error encrypting");
  645|      0|		}
  646|  25.9k|		buf_incrpos(writebuf, len);
  647|       |
  648|       |		/* stick the MAC on it */
  649|  25.9k|		buf_putbytes(writebuf, mac_bytes, mac_size);
  650|  25.9k|	}
  651|       |
  652|       |	/* Update counts */
  653|   240k|	ses.kexstate.datatrans += writebuf->len;
  654|       |
  655|   240k|	writebuf_enqueue(writebuf);
  656|       |
  657|       |	/* Update counts */
  658|   240k|	ses.transseq++;
  659|       |
  660|   240k|	now = monotonic_now();
  661|   240k|	ses.last_packet_time_any_sent = now;
  662|       |	/* idle timeout shouldn't be affected by responses to keepalives.
  663|       |	send_msg_keepalive() itself also does tricks with 
  664|       |	ses.last_packet_idle_time - read that if modifying this code */
  665|   240k|	if (packet_type != SSH_MSG_REQUEST_FAILURE
  ------------------
  |  |   65|   480k|#define SSH_MSG_REQUEST_FAILURE                 82
  ------------------
  |  Branch (665:6): [True: 239k, False: 757]
  ------------------
  666|   240k|		&& packet_type != SSH_MSG_UNIMPLEMENTED
  ------------------
  |  |   31|   480k|#define SSH_MSG_UNIMPLEMENTED          3
  ------------------
  |  Branch (666:6): [True: 236k, False: 3.69k]
  ------------------
  667|   240k|		&& packet_type != SSH_MSG_IGNORE) {
  ------------------
  |  |   30|   236k|#define SSH_MSG_IGNORE                 2
  ------------------
  |  Branch (667:6): [True: 236k, False: 0]
  ------------------
  668|   236k|		ses.last_packet_time_idle = now;
  669|       |
  670|   236k|	}
  671|       |
  672|   240k|	TRACE2(("leave encrypt_packet()"))
  673|   240k|}
writebuf_enqueue:
  675|   241k|void writebuf_enqueue(buffer * writebuf) {
  676|       |	/* enqueue the packet for sending. It will get freed after transmission. */
  677|   241k|	buf_setpos(writebuf, 0);
  678|   241k|	enqueue(&ses.writequeue, (void*)writebuf);
  679|   241k|	ses.writequeue_len += writebuf->len;
  680|   241k|}
packet.c:read_packet_init:
  214|   149k|static int read_packet_init() {
  215|       |
  216|   149k|	unsigned int maxlen;
  217|   149k|	int slen;
  218|   149k|	unsigned int len, plen;
  219|   149k|	unsigned int blocksize;
  220|   149k|	unsigned int macsize;
  221|       |
  222|       |
  223|   149k|	blocksize = ses.keys->recv.algo_crypt->blocksize;
  224|   149k|	macsize = ses.keys->recv.algo_mac->hashsize;
  225|       |
  226|   149k|	if (ses.readbuf == NULL) {
  ------------------
  |  Branch (226:6): [True: 53.2k, False: 96.0k]
  ------------------
  227|       |		/* start of a new packet */
  228|  53.2k|		ses.readbuf = buf_new(INIT_READBUF);
  ------------------
  |  |   51|  53.2k|#define INIT_READBUF 128
  ------------------
  229|  53.2k|	}
  230|       |
  231|   149k|	maxlen = blocksize - ses.readbuf->pos;
  232|       |			
  233|       |	/* read the rest of the packet if possible */
  234|   149k|	slen = read(ses.sock_in, buf_getwriteptr(ses.readbuf, maxlen),
  ------------------
  |  |   55|   149k|#define read(fd, buf, count) wrapfd_read(fd, buf, count)
  ------------------
  235|   149k|			maxlen);
  236|   149k|	if (slen == 0) {
  ------------------
  |  Branch (236:6): [True: 900, False: 148k]
  ------------------
  237|    900|		ses.remoteclosed();
  238|    900|	}
  239|   149k|	if (slen < 0) {
  ------------------
  |  Branch (239:6): [True: 99, False: 149k]
  ------------------
  240|     99|		if (errno == EINTR || errno == EAGAIN) {
  ------------------
  |  Branch (240:7): [True: 94, False: 5]
  |  Branch (240:25): [True: 0, False: 5]
  ------------------
  241|     94|			TRACE2(("leave read_packet_init: EINTR"))
  242|     94|			return DROPBEAR_FAILURE;
  ------------------
  |  |  103|     94|#define DROPBEAR_FAILURE -1
  ------------------
  243|     94|		}
  244|      5|		dropbear_exit("Error reading: %s", strerror(errno));
  245|     99|	}
  246|       |
  247|   149k|	buf_incrwritepos(ses.readbuf, slen);
  248|       |
  249|   149k|	if ((unsigned int)slen != maxlen) {
  ------------------
  |  Branch (249:6): [True: 95.9k, False: 53.2k]
  ------------------
  250|       |		/* don't have enough bytes to determine length, get next time */
  251|  95.9k|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|  95.9k|#define DROPBEAR_FAILURE -1
  ------------------
  252|  95.9k|	}
  253|       |
  254|       |	/* now we have the first block, need to get packet length, so we decrypt
  255|       |	 * the first block (only need first 4 bytes) */
  256|  53.2k|	buf_setpos(ses.readbuf, 0);
  257|  53.2k|#if DROPBEAR_AEAD_MODE
  258|  53.2k|	if (ses.keys->recv.crypt_mode->aead_crypt) {
  ------------------
  |  Branch (258:6): [True: 0, False: 53.2k]
  ------------------
  259|      0|		if (ses.keys->recv.crypt_mode->aead_getlength(ses.recvseq,
  ------------------
  |  Branch (259:7): [True: 0, False: 0]
  ------------------
  260|      0|					buf_getptr(ses.readbuf, blocksize), &plen,
  261|      0|					blocksize,
  262|      0|					&ses.keys->recv.cipher_state) != CRYPT_OK) {
  263|      0|			dropbear_exit("Error decrypting");
  264|      0|		}
  265|      0|		len = plen + 4 + macsize;
  266|      0|	} else
  267|  53.2k|#endif
  268|  53.2k|	{
  269|  53.2k|		if (ses.keys->recv.crypt_mode->decrypt(buf_getptr(ses.readbuf, blocksize), 
  ------------------
  |  Branch (269:7): [True: 0, False: 53.2k]
  ------------------
  270|  53.2k|					buf_getwriteptr(ses.readbuf, blocksize),
  271|  53.2k|					blocksize,
  272|  53.2k|					&ses.keys->recv.cipher_state) != CRYPT_OK) {
  273|      0|			dropbear_exit("Error decrypting");
  274|      0|		}
  275|  53.2k|		plen = buf_getint(ses.readbuf) + 4;
  276|  53.2k|		len = plen + macsize;
  277|  53.2k|	}
  278|       |
  279|  53.2k|	TRACE2(("packet size is %u, block %u mac %u", len, blocksize, macsize))
  280|       |
  281|       |
  282|       |	/* check packet length */
  283|  53.2k|	if ((len > RECV_MAX_PACKET_LEN) ||
  ------------------
  |  |  215|  53.2k|#define RECV_MAX_PACKET_LEN (MAX(35000, ((RECV_MAX_PAYLOAD_LEN)+100)))
  ------------------
  |  Branch (283:6): [True: 985, False: 52.2k]
  ------------------
  284|  53.2k|		(plen < blocksize) ||
  ------------------
  |  Branch (284:3): [True: 21, False: 52.2k]
  ------------------
  285|  53.2k|		(plen % blocksize != 0)) {
  ------------------
  |  Branch (285:3): [True: 34, False: 52.1k]
  ------------------
  286|    140|		dropbear_exit("Integrity error (bad packet size %u)", len);
  287|    140|	}
  288|       |
  289|  53.0k|	if (len > ses.readbuf->size) {
  ------------------
  |  Branch (289:6): [True: 10.4k, False: 42.6k]
  ------------------
  290|  10.4k|		ses.readbuf = buf_resize(ses.readbuf, len);		
  291|  10.4k|	}
  292|  53.0k|	buf_setlen(ses.readbuf, len);
  293|  53.0k|	buf_setpos(ses.readbuf, blocksize);
  294|  53.0k|	return DROPBEAR_SUCCESS;
  ------------------
  |  |  102|  53.0k|#define DROPBEAR_SUCCESS 0
  ------------------
  295|  53.2k|}
packet.c:checkmac:
  390|  52.0k|static int checkmac() {
  391|       |
  392|  52.0k|	unsigned char mac_bytes[MAX_MAC_LEN];
  393|  52.0k|	unsigned int mac_size, contents_len;
  394|       |	
  395|  52.0k|	mac_size = ses.keys->recv.algo_mac->hashsize;
  396|  52.0k|	contents_len = ses.readbuf->len - mac_size;
  397|       |
  398|  52.0k|	buf_setpos(ses.readbuf, 0);
  399|  52.0k|	make_mac(ses.recvseq, &ses.keys->recv, ses.readbuf, contents_len, mac_bytes);
  400|       |
  401|  52.0k|#if DROPBEAR_FUZZ
  402|  52.0k|	if (fuzz.fuzzing) {
  ------------------
  |  Branch (402:6): [True: 52.0k, False: 0]
  ------------------
  403|       |	 	/* fail 1 in 2000 times to test error path. */
  404|  52.0k|		unsigned int value = 0;
  405|  52.0k|		if (mac_size > sizeof(value)) {
  ------------------
  |  Branch (405:7): [True: 0, False: 52.0k]
  ------------------
  406|      0|			memcpy(&value, mac_bytes, sizeof(value));
  407|      0|		}
  408|  52.0k|		if (value % 2000 == 99) {
  ------------------
  |  Branch (408:7): [True: 0, False: 52.0k]
  ------------------
  409|      0|			return DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
  410|      0|		}
  411|  52.0k|		return DROPBEAR_SUCCESS;
  ------------------
  |  |  102|  52.0k|#define DROPBEAR_SUCCESS 0
  ------------------
  412|  52.0k|	}
  413|      0|#endif
  414|       |
  415|       |	/* compare the hash */
  416|      0|	buf_setpos(ses.readbuf, contents_len);
  417|      0|	if (constant_time_memcmp(mac_bytes, buf_getptr(ses.readbuf, mac_size), mac_size) != 0) {
  ------------------
  |  Branch (417:6): [True: 0, False: 0]
  ------------------
  418|      0|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
  419|      0|	} else {
  420|      0|		return DROPBEAR_SUCCESS;
  ------------------
  |  |  102|      0|#define DROPBEAR_SUCCESS 0
  ------------------
  421|      0|	}
  422|      0|}
packet.c:packet_is_okay_kex:
  464|  11.3k|static int packet_is_okay_kex(unsigned char type) {
  465|  11.3k|	if (type >= SSH_MSG_USERAUTH_REQUEST) {
  ------------------
  |  |   42|  11.3k|#define SSH_MSG_USERAUTH_REQUEST            50
  ------------------
  |  Branch (465:6): [True: 542, False: 10.8k]
  ------------------
  466|    542|		return 0;
  467|    542|	}
  468|  10.8k|	if (type == SSH_MSG_SERVICE_REQUEST || type == SSH_MSG_SERVICE_ACCEPT) {
  ------------------
  |  |   33|  21.6k|#define SSH_MSG_SERVICE_REQUEST        5
  ------------------
              	if (type == SSH_MSG_SERVICE_REQUEST || type == SSH_MSG_SERVICE_ACCEPT) {
  ------------------
  |  |   34|  10.8k|#define SSH_MSG_SERVICE_ACCEPT         6
  ------------------
  |  Branch (468:6): [True: 0, False: 10.8k]
  |  Branch (468:41): [True: 0, False: 10.8k]
  ------------------
  469|      0|		return 0;
  470|      0|	}
  471|  10.8k|	if (type == SSH_MSG_KEXINIT) {
  ------------------
  |  |   36|  10.8k|#define SSH_MSG_KEXINIT                20
  ------------------
  |  Branch (471:6): [True: 0, False: 10.8k]
  ------------------
  472|       |		/* XXX should this die horribly if !dataallowed ?? */
  473|      0|		return 0;
  474|      0|	}
  475|  10.8k|	return 1;
  476|  10.8k|}
packet.c:enqueue_reply_packet:
  478|    542|static void enqueue_reply_packet() {
  479|    542|	struct packetlist * new_item = NULL;
  480|    542|	new_item = m_malloc(sizeof(struct packetlist));
  481|    542|	new_item->next = NULL;
  482|       |	
  483|    542|	new_item->payload = buf_newcopy(ses.writepayload);
  484|    542|	buf_setpos(ses.writepayload, 0);
  485|    542|	buf_setlen(ses.writepayload, 0);
  486|       |	
  487|    542|	if (ses.reply_queue_tail) {
  ------------------
  |  Branch (487:6): [True: 308, False: 234]
  ------------------
  488|    308|		ses.reply_queue_tail->next = new_item;
  489|    308|	} else {
  490|    234|		ses.reply_queue_head = new_item;
  491|    234|	}
  492|    542|	ses.reply_queue_tail = new_item;
  493|    542|}
packet.c:make_mac:
  687|  78.0k|		unsigned char *output_mac) {
  688|  78.0k|	unsigned char seqbuf[4];
  689|  78.0k|	unsigned long bufsize;
  690|  78.0k|	hmac_state hmac;
  691|       |
  692|  78.0k|	if (key_state->algo_mac->hashsize > 0) {
  ------------------
  |  Branch (692:6): [True: 21.6k, False: 56.3k]
  ------------------
  693|       |		/* calculate the mac */
  694|  21.6k|		if (hmac_init(&hmac, 
  ------------------
  |  Branch (694:7): [True: 0, False: 21.6k]
  ------------------
  695|  21.6k|					key_state->hash_index,
  696|  21.6k|					key_state->mackey,
  697|  21.6k|					key_state->algo_mac->keysize) != CRYPT_OK) {
  698|      0|			dropbear_exit("HMAC error");
  699|      0|		}
  700|       |	
  701|       |		/* sequence number */
  702|  21.6k|		STORE32H(seqno, seqbuf);
  ------------------
  |  |   62|  21.6k|#define STORE32H(x, y)                          \
  |  |   63|  21.6k|do { ulong32 __t = __builtin_bswap32 ((x));     \
  |  |   64|  21.6k|      XMEMCPY ((y), &__t, 4); } while(0)
  |  |  ------------------
  |  |  |  |   39|  21.6k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (64:39): [Folded - Ignored]
  |  |  ------------------
  ------------------
  703|  21.6k|		if (hmac_process(&hmac, seqbuf, 4) != CRYPT_OK) {
  ------------------
  |  Branch (703:7): [True: 0, False: 21.6k]
  ------------------
  704|      0|			dropbear_exit("HMAC error");
  705|      0|		}
  706|       |	
  707|       |		/* the actual contents */
  708|  21.6k|		buf_setpos(clear_buf, 0);
  709|  21.6k|		if (hmac_process(&hmac, 
  ------------------
  |  Branch (709:7): [True: 0, False: 21.6k]
  ------------------
  710|  21.6k|					buf_getptr(clear_buf, clear_len),
  711|  21.6k|					clear_len) != CRYPT_OK) {
  712|      0|			dropbear_exit("HMAC error");
  713|      0|		}
  714|       |	
  715|  21.6k|		bufsize = MAX_MAC_LEN;
  ------------------
  |  |  134|  21.6k|#define MAX_MAC_LEN 32
  ------------------
  716|  21.6k|		if (hmac_done(&hmac, output_mac, &bufsize) != CRYPT_OK) {
  ------------------
  |  Branch (716:7): [True: 0, False: 21.6k]
  ------------------
  717|      0|			dropbear_exit("HMAC error");
  718|      0|		}
  719|  21.6k|	}
  720|  78.0k|	TRACE2(("leave writemac"))
  721|  78.0k|}

process_packet:
   43|  52.0k|void process_packet() {
   44|       |
   45|  52.0k|	unsigned char type;
   46|  52.0k|	unsigned int i;
   47|  52.0k|	time_t now;
   48|       |
   49|  52.0k|	TRACE2(("enter process_packet"))
   50|       |
   51|  52.0k|	type = buf_getbyte(ses.payload);
   52|  52.0k|	TRACE(("process_packet: packet type = %d,  len %d", type, ses.payload->len))
   53|       |
   54|  52.0k|	now = monotonic_now();
   55|  52.0k|	ses.last_packet_time_keepalive_recv = now;
   56|       |
   57|       |	/* These packets we can receive at any time */
   58|  52.0k|	switch(type) {
  ------------------
  |  Branch (58:9): [True: 51.1k, False: 867]
  ------------------
   59|       |
   60|    289|		case SSH_MSG_IGNORE:
  ------------------
  |  |   30|    289|#define SSH_MSG_IGNORE                 2
  ------------------
  |  Branch (60:3): [True: 289, False: 51.7k]
  ------------------
   61|    289|			goto out;
   62|    397|		case SSH_MSG_DEBUG:
  ------------------
  |  |   32|    397|#define SSH_MSG_DEBUG                  4
  ------------------
  |  Branch (62:3): [True: 397, False: 51.6k]
  ------------------
   63|    397|			goto out;
   64|       |
   65|    178|		case SSH_MSG_UNIMPLEMENTED:
  ------------------
  |  |   31|    178|#define SSH_MSG_UNIMPLEMENTED          3
  ------------------
  |  Branch (65:3): [True: 178, False: 51.8k]
  ------------------
   66|       |			/* debugging XXX */
   67|    178|			TRACE(("SSH_MSG_UNIMPLEMENTED"))
   68|    178|			goto out;
   69|       |			
   70|      3|		case SSH_MSG_DISCONNECT:
  ------------------
  |  |   29|      3|#define SSH_MSG_DISCONNECT             1
  ------------------
  |  Branch (70:3): [True: 3, False: 52.0k]
  ------------------
   71|       |			/* TODO cleanup? */
   72|      3|			dropbear_close("Disconnect received");
   73|  52.0k|	}
   74|       |
   75|       |	/* Ignore these packet types so that keepalives don't interfere with
   76|       |	idle detection. This is slightly incorrect since a tcp forwarded
   77|       |	global request with failure won't trigger the idle timeout,
   78|       |	but that's probably acceptable */
   79|  51.1k|	if (!(type == SSH_MSG_GLOBAL_REQUEST 
  ------------------
  |  |   63|   102k|#define SSH_MSG_GLOBAL_REQUEST                  80
  ------------------
  |  Branch (79:8): [True: 2.22k, False: 48.9k]
  ------------------
   80|  51.1k|		|| type == SSH_MSG_REQUEST_FAILURE
  ------------------
  |  |   65|   100k|#define SSH_MSG_REQUEST_FAILURE                 82
  ------------------
  |  Branch (80:6): [True: 85, False: 48.8k]
  ------------------
   81|  51.1k|		|| type == SSH_MSG_CHANNEL_FAILURE)) {
  ------------------
  |  |   76|  48.8k|#define SSH_MSG_CHANNEL_FAILURE                 100
  ------------------
  |  Branch (81:6): [True: 72, False: 48.7k]
  ------------------
   82|  48.7k|		ses.last_packet_time_idle = now;
   83|  48.7k|	}
   84|       |
   85|       |	/* This applies for KEX, where the spec says the next packet MUST be
   86|       |	 * NEWKEYS */
   87|  51.1k|	if (ses.requirenext != 0) {
  ------------------
  |  Branch (87:6): [True: 22.3k, False: 28.8k]
  ------------------
   88|  22.3k|		if (ses.requirenext == type)
  ------------------
  |  Branch (88:7): [True: 19.9k, False: 2.35k]
  ------------------
   89|  19.9k|		{
   90|       |			/* Got what we expected */
   91|  19.9k|			TRACE(("got expected packet %d during kexinit", type))
   92|  19.9k|		}
   93|  2.35k|		else
   94|  2.35k|		{
   95|       |			/* RFC4253 7.1 - various messages are allowed at this point.
   96|       |			The only ones we know about have already been handled though,
   97|       |			so just return "unimplemented" */
   98|  2.35k|			if (type >= 1 && type <= 49
  ------------------
  |  Branch (98:8): [True: 2.34k, False: 12]
  |  Branch (98:21): [True: 2.33k, False: 9]
  ------------------
   99|  2.35k|				&& type != SSH_MSG_SERVICE_REQUEST
  ------------------
  |  |   33|  4.69k|#define SSH_MSG_SERVICE_REQUEST        5
  ------------------
  |  Branch (99:8): [True: 2.33k, False: 0]
  ------------------
  100|  2.35k|				&& type != SSH_MSG_SERVICE_ACCEPT
  ------------------
  |  |   34|  4.69k|#define SSH_MSG_SERVICE_ACCEPT         6
  ------------------
  |  Branch (100:8): [True: 2.33k, False: 0]
  ------------------
  101|  2.35k|				&& type != SSH_MSG_KEXINIT)
  ------------------
  |  |   36|  2.33k|#define SSH_MSG_KEXINIT                20
  ------------------
  |  Branch (101:8): [True: 2.33k, False: 1]
  ------------------
  102|  2.33k|			{
  103|  2.33k|				TRACE(("unknown allowed packet during kexinit"))
  104|  2.33k|				recv_unimplemented();
  105|  2.33k|				goto out;
  106|  2.33k|			}
  107|     22|			else
  108|     22|			{
  109|     22|				TRACE(("disallowed packet during kexinit"))
  110|     22|				dropbear_exit("Unexpected packet type %d, expected %d", type,
  111|     22|						ses.requirenext);
  112|     22|			}
  113|  2.35k|		}
  114|  22.3k|	}
  115|       |
  116|       |	/* Check if we should ignore this packet. Used currently only for
  117|       |	 * KEX code, with first_kex_packet_follows */
  118|  48.8k|	if (ses.ignorenext) {
  ------------------
  |  Branch (118:6): [True: 132, False: 48.6k]
  ------------------
  119|    132|		TRACE(("Ignoring packet, type = %d", type))
  120|    132|		ses.ignorenext = 0;
  121|    132|		goto out;
  122|    132|	}
  123|       |
  124|       |	/* Only clear the flag after we have checked ignorenext */
  125|  48.6k|	if (ses.requirenext != 0 && ses.requirenext == type)
  ------------------
  |  Branch (125:6): [True: 19.8k, False: 28.8k]
  |  Branch (125:30): [True: 19.8k, False: 0]
  ------------------
  126|  19.8k|	{
  127|  19.8k|		ses.requirenext = 0;
  128|  19.8k|	}
  129|       |
  130|       |
  131|       |	/* Kindly the protocol authors gave all the preauth packets type values
  132|       |	 * less-than-or-equal-to 60 ( == MAX_UNAUTH_PACKET_TYPE ).
  133|       |	 * NOTE: if the protocol changes and new types are added, revisit this 
  134|       |	 * assumption */
  135|  48.6k|	if ( !ses.authstate.authdone && type > MAX_UNAUTH_PACKET_TYPE ) {
  ------------------
  |  |   38|      0|#define MAX_UNAUTH_PACKET_TYPE SSH_MSG_USERAUTH_PK_OK
  |  |  ------------------
  |  |  |  |   52|      0|#define SSH_MSG_USERAUTH_PK_OK				60
  |  |  ------------------
  ------------------
  |  Branch (135:7): [True: 0, False: 48.6k]
  |  Branch (135:34): [True: 0, False: 0]
  ------------------
  136|      0|		dropbear_exit("Received message %d before userauth", type);
  137|      0|	}
  138|       |
  139|   366k|	for (i = 0; ; i++) {
  140|   366k|		if (ses.packettypes[i].type == 0) {
  ------------------
  |  Branch (140:7): [True: 1.36k, False: 364k]
  ------------------
  141|       |			/* end of list */
  142|  1.36k|			break;
  143|  1.36k|		}
  144|       |
  145|   364k|		if (ses.packettypes[i].type == type) {
  ------------------
  |  Branch (145:7): [True: 47.3k, False: 317k]
  ------------------
  146|  47.3k|			ses.packettypes[i].handler();
  147|  47.3k|			goto out;
  148|  47.3k|		}
  149|   364k|	}
  150|       |
  151|       |	
  152|       |	/* TODO do something more here? */
  153|  1.36k|	TRACE(("preauth unknown packet"))
  154|  1.36k|	recv_unimplemented();
  155|       |
  156|  51.7k|out:
  157|  51.7k|	ses.lastpacket = type;
  158|  51.7k|	buf_free(ses.payload);
  159|  51.7k|	ses.payload = NULL;
  160|       |
  161|  51.7k|	TRACE2(("leave process_packet"))
  162|  51.7k|}
process-packet.c:recv_unimplemented:
  170|  3.69k|static void recv_unimplemented() {
  171|       |
  172|  3.69k|	CHECKCLEARTOWRITE();
  173|       |
  174|  3.69k|	buf_putbyte(ses.writepayload, SSH_MSG_UNIMPLEMENTED);
  ------------------
  |  |   31|  3.69k|#define SSH_MSG_UNIMPLEMENTED          3
  ------------------
  175|       |	/* the decryption routine increments the sequence number, we must
  176|       |	 * decrement */
  177|  3.69k|	buf_putint(ses.writepayload, ses.recvseq - 1);
  178|       |
  179|  3.69k|	encrypt_packet();
  180|  3.69k|}

initqueue:
   29|  1.49k|void initqueue(struct Queue* queue) {
   30|       |
   31|  1.49k|	queue->head = NULL;
   32|  1.49k|	queue->tail = NULL;
   33|  1.49k|	queue->count = 0;
   34|  1.49k|}
isempty:
   36|  1.63M|int isempty(const struct Queue* queue) {
   37|       |
   38|  1.63M|	return (queue->head == NULL);
   39|  1.63M|}
dequeue:
   41|   241k|void* dequeue(struct Queue* queue) {
   42|       |
   43|   241k|	void* ret;
   44|   241k|	struct Link* oldhead;
   45|   241k|	dropbear_assert(!isempty(queue));
  ------------------
  |  |   83|   241k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 241k]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
   46|       |	
   47|   241k|	ret = queue->head->item;
   48|   241k|	oldhead = queue->head;
   49|       |	
   50|   241k|	if (oldhead->link != NULL) {
  ------------------
  |  Branch (50:6): [True: 197k, False: 44.5k]
  ------------------
   51|   197k|		queue->head = oldhead->link;
   52|   197k|	} else {
   53|  44.5k|		queue->head = NULL;
   54|  44.5k|		queue->tail = NULL;
   55|  44.5k|		TRACE(("empty queue dequeing"))
   56|  44.5k|	}
   57|       |
   58|   241k|	m_free(oldhead);
  ------------------
  |  |   24|   241k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
   59|   241k|	queue->count--;
   60|   241k|	return ret;
   61|   241k|}
examine:
   63|   234k|void *examine(const struct Queue* queue) {
   64|       |
   65|   234k|	dropbear_assert(!isempty(queue));
  ------------------
  |  |   83|   234k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 234k]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
   66|   234k|	return queue->head->item;
   67|   234k|}
enqueue:
   69|   241k|void enqueue(struct Queue* queue, void* item) {
   70|       |
   71|   241k|	struct Link* newlink;
   72|       |
   73|   241k|	newlink = (struct Link*)m_malloc(sizeof(struct Link));
   74|       |
   75|   241k|	newlink->item = item;
   76|   241k|	newlink->link = NULL;
   77|       |
   78|   241k|	if (queue->tail != NULL) {
  ------------------
  |  Branch (78:6): [True: 197k, False: 44.5k]
  ------------------
   79|   197k|		queue->tail->link = newlink;
   80|   197k|	}
   81|   241k|	queue->tail = newlink;
   82|       |
   83|   241k|	if (queue->head == NULL) {
  ------------------
  |  Branch (83:6): [True: 44.5k, False: 197k]
  ------------------
   84|  44.5k|		queue->head = newlink;
   85|  44.5k|	}
   86|   241k|	queue->count++;
   87|   241k|}

buf_get_rsa_pub_key:
   53|      1|int buf_get_rsa_pub_key(buffer* buf, dropbear_rsa_key *key) {
   54|       |
   55|      1|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
   56|      1|	TRACE(("enter buf_get_rsa_pub_key"))
   57|      1|	dropbear_assert(key != NULL);
  ------------------
  |  |   83|      1|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 1]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
   58|      1|	m_mp_alloc_init_multi(&key->e, &key->n, NULL);
   59|      1|	key->d = NULL;
   60|      1|	key->p = NULL;
   61|      1|	key->q = NULL;
   62|       |
   63|      1|	buf_incrpos(buf, 4+SSH_SIGNKEY_RSA_LEN); /* int + "ssh-rsa" */
  ------------------
  |  |  113|      1|#define SSH_SIGNKEY_RSA_LEN 7
  ------------------
   64|       |
   65|      1|	if (buf_getmpint(buf, key->e) == DROPBEAR_FAILURE
  ------------------
  |  |  103|      2|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (65:6): [True: 0, False: 1]
  ------------------
   66|      1|	 || buf_getmpint(buf, key->n) == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (66:6): [True: 0, False: 1]
  ------------------
   67|      0|		TRACE(("leave buf_get_rsa_pub_key: failure"))
   68|      0|		goto out;
   69|      0|	}
   70|       |
   71|      1|	if (mp_count_bits(key->n) < MIN_RSA_KEYLEN) {
  ------------------
  |  |   65|      1|#define MIN_RSA_KEYLEN 1024
  ------------------
  |  Branch (71:6): [True: 0, False: 1]
  ------------------
   72|      0|		dropbear_log(LOG_WARNING, "RSA key too short");
   73|      0|		goto out;
   74|      0|	}
   75|       |
   76|       |	/* 64 bit is limit used by openssl, so we won't block any keys in the wild */
   77|      1|	if (mp_count_bits(key->e) > 64) {
  ------------------
  |  Branch (77:6): [True: 0, False: 1]
  ------------------
   78|      0|		dropbear_log(LOG_WARNING, "RSA key bad e");
   79|      0|		goto out;
   80|      0|	}
   81|       |
   82|      1|	TRACE(("leave buf_get_rsa_pub_key: success"))
   83|      1|	ret = DROPBEAR_SUCCESS;
  ------------------
  |  |  102|      1|#define DROPBEAR_SUCCESS 0
  ------------------
   84|      1|out:
   85|      1|	if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (85:6): [True: 0, False: 1]
  ------------------
   86|      0|		m_mp_free_multi(&key->e, &key->n, NULL);
   87|      0|	}
   88|      1|	return ret;
   89|      1|}
buf_get_rsa_priv_key:
   94|      1|int buf_get_rsa_priv_key(buffer* buf, dropbear_rsa_key *key) {
   95|      1|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
   96|       |
   97|      1|	TRACE(("enter buf_get_rsa_priv_key"))
   98|      1|	dropbear_assert(key != NULL);
  ------------------
  |  |   83|      1|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 1]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
   99|       |
  100|      1|	if (buf_get_rsa_pub_key(buf, key) == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (100:6): [True: 0, False: 1]
  ------------------
  101|      0|		TRACE(("leave buf_get_rsa_priv_key: pub: ret == DROPBEAR_FAILURE"))
  102|      0|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
  103|      0|	}
  104|       |	
  105|      1|	key->d = NULL;
  106|      1|	key->p = NULL;
  107|      1|	key->q = NULL;
  108|       |
  109|      1|	m_mp_alloc_init_multi(&key->d, NULL);
  110|      1|	if (buf_getmpint(buf, key->d) == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (110:6): [True: 0, False: 1]
  ------------------
  111|      0|		TRACE(("leave buf_get_rsa_priv_key: d: ret == DROPBEAR_FAILURE"))
  112|      0|		goto out;
  113|      0|	}
  114|       |
  115|      1|	if (buf->pos == buf->len) {
  ------------------
  |  Branch (115:6): [True: 0, False: 1]
  ------------------
  116|       |		/* old Dropbear private keys didn't keep p and q, so we will ignore them*/
  117|      1|	} else {
  118|      1|		m_mp_alloc_init_multi(&key->p, &key->q, NULL);
  119|       |
  120|      1|		if (buf_getmpint(buf, key->p) == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (120:7): [True: 0, False: 1]
  ------------------
  121|      0|			TRACE(("leave buf_get_rsa_priv_key: p: ret == DROPBEAR_FAILURE"))
  122|      0|			goto out;
  123|      0|		}
  124|       |
  125|      1|		if (buf_getmpint(buf, key->q) == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (125:7): [True: 0, False: 1]
  ------------------
  126|      0|			TRACE(("leave buf_get_rsa_priv_key: q: ret == DROPBEAR_FAILURE"))
  127|      0|			goto out;
  128|      0|		}
  129|      1|	}
  130|       |
  131|      1|	ret = DROPBEAR_SUCCESS;
  ------------------
  |  |  102|      1|#define DROPBEAR_SUCCESS 0
  ------------------
  132|      1|out:
  133|      1|	if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (133:6): [True: 0, False: 1]
  ------------------
  134|      0|		m_mp_free_multi(&key->d, &key->p, &key->q, NULL);
  135|      0|	}
  136|      1|	TRACE(("leave buf_get_rsa_priv_key"))
  137|      1|	return ret;
  138|      1|}
rsa_key_free:
  142|      1|void rsa_key_free(dropbear_rsa_key *key) {
  143|       |
  144|      1|	TRACE2(("enter rsa_key_free"))
  145|       |
  146|      1|	if (key == NULL) {
  ------------------
  |  Branch (146:6): [True: 1, False: 0]
  ------------------
  147|      1|		TRACE2(("leave rsa_key_free: key == NULL"))
  148|      1|		return;
  149|      1|	}
  150|      0|	m_mp_free_multi(&key->d, &key->e, &key->p, &key->q, &key->n, NULL);
  151|      0|	m_free(key);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  152|      0|	TRACE2(("leave rsa_key_free"))
  153|      0|}

new_sign_key:
   62|      1|sign_key * new_sign_key() {
   63|       |
   64|      1|	sign_key * ret;
   65|       |
   66|      1|	ret = (sign_key*)m_malloc(sizeof(sign_key));
   67|      1|	ret->type = DROPBEAR_SIGNKEY_NONE;
   68|      1|	ret->source = SIGNKEY_SOURCE_INVALID;
   69|      1|	return ret;
   70|      1|}
signkey_type_from_name:
   86|      4|enum signkey_type signkey_type_from_name(const char* name, unsigned int namelen) {
   87|      4|	int i;
   88|     13|	for (i = 0; i < DROPBEAR_SIGNKEY_NUM_NAMED; i++) {
  ------------------
  |  Branch (88:14): [True: 13, False: 0]
  ------------------
   89|     13|		const char *fixed_name = signkey_names[i];
   90|     13|		if (namelen == strlen(fixed_name)
  ------------------
  |  Branch (90:7): [True: 5, False: 8]
  ------------------
   91|     13|			&& memcmp(fixed_name, name, namelen) == 0) {
  ------------------
  |  Branch (91:7): [True: 4, False: 1]
  ------------------
   92|       |
   93|      4|#if DROPBEAR_ECDSA
   94|       |			/* Some of the ECDSA key sizes are defined even if they're not compiled in */
   95|      4|			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|      4|				) {
  106|      0|				TRACE(("attempt to use ecdsa type %d not compiled in", i))
  107|      0|				return DROPBEAR_SIGNKEY_NONE;
  108|      0|			}
  109|      4|#endif
  110|       |
  111|      4|			return (enum signkey_type)i;
  112|      4|		}
  113|     13|	}
  114|       |
  115|      0|	TRACE(("signkey_type_from_name unexpected key type."))
  116|       |
  117|      0|	return DROPBEAR_SIGNKEY_NONE;
  118|      4|}
signkey_type_from_signature:
  173|  9.54k|enum signkey_type signkey_type_from_signature(enum signature_type sigtype) {
  174|  9.54k|#if DROPBEAR_RSA
  175|  9.54k|#if DROPBEAR_RSA_SHA256
  176|  9.54k|	if (sigtype == DROPBEAR_SIGNATURE_RSA_SHA256) {
  ------------------
  |  Branch (176:6): [True: 99, False: 9.44k]
  ------------------
  177|     99|		return DROPBEAR_SIGNKEY_RSA;
  178|     99|	}
  179|  9.44k|#endif
  180|  9.44k|#if DROPBEAR_RSA_SHA1
  181|  9.44k|	if (sigtype == DROPBEAR_SIGNATURE_RSA_SHA1) {
  ------------------
  |  Branch (181:6): [True: 139, False: 9.30k]
  ------------------
  182|    139|		return DROPBEAR_SIGNKEY_RSA;
  183|    139|	}
  184|  9.30k|#endif
  185|  9.30k|#endif /* DROPBEAR_RSA */
  186|  9.30k|	assert((int)sigtype < (int)DROPBEAR_SIGNKEY_NUM_NAMED);
  187|  9.30k|	return (enum signkey_type)sigtype;
  188|  9.30k|}
signkey_key_ptr:
  193|      1|signkey_key_ptr(sign_key *key, enum signkey_type type) {
  194|      1|	switch (type) {
  195|      0|#if DROPBEAR_ED25519
  196|      0|		case DROPBEAR_SIGNKEY_ED25519:
  ------------------
  |  Branch (196:3): [True: 0, False: 1]
  ------------------
  197|      0|#if DROPBEAR_SK_ED25519
  198|      0|		case DROPBEAR_SIGNKEY_SK_ED25519:
  ------------------
  |  Branch (198:3): [True: 0, False: 1]
  ------------------
  199|      0|#endif
  200|      0|			return (void**)&key->ed25519key;
  201|      0|#endif
  202|      0|#if DROPBEAR_ECDSA
  203|      0|#if DROPBEAR_ECC_256
  204|      1|		case DROPBEAR_SIGNKEY_ECDSA_NISTP256:
  ------------------
  |  Branch (204:3): [True: 1, False: 0]
  ------------------
  205|      1|#if DROPBEAR_SK_ECDSA
  206|      1|		case DROPBEAR_SIGNKEY_SK_ECDSA_NISTP256:
  ------------------
  |  Branch (206:3): [True: 0, False: 1]
  ------------------
  207|      1|#endif
  208|      1|			return (void**)&key->ecckey256;
  209|      0|#endif
  210|      0|#if DROPBEAR_ECC_384
  211|      0|		case DROPBEAR_SIGNKEY_ECDSA_NISTP384:
  ------------------
  |  Branch (211:3): [True: 0, False: 1]
  ------------------
  212|      0|			return (void**)&key->ecckey384;
  213|      0|#endif
  214|      0|#if DROPBEAR_ECC_521
  215|      0|		case DROPBEAR_SIGNKEY_ECDSA_NISTP521:
  ------------------
  |  Branch (215:3): [True: 0, False: 1]
  ------------------
  216|      0|			return (void**)&key->ecckey521;
  217|      0|#endif
  218|      0|#endif /* DROPBEAR_ECDSA */
  219|      0|#if DROPBEAR_RSA
  220|      0|		case DROPBEAR_SIGNKEY_RSA:
  ------------------
  |  Branch (220:3): [True: 0, False: 1]
  ------------------
  221|      0|			return (void**)&key->rsakey;
  222|      0|#endif
  223|      0|#if DROPBEAR_DSS
  224|      0|		case DROPBEAR_SIGNKEY_DSS:
  ------------------
  |  Branch (224:3): [True: 0, False: 1]
  ------------------
  225|      0|			return (void**)&key->dsskey;
  226|      0|#endif
  227|      0|		default:
  ------------------
  |  Branch (227:3): [True: 0, False: 1]
  ------------------
  228|      0|			return NULL;
  229|      1|	}
  230|      1|}
buf_get_priv_key:
  339|      4|int buf_get_priv_key(buffer *buf, sign_key *key, enum signkey_type *type) {
  340|       |
  341|      4|	char *ident;
  342|      4|	unsigned int len;
  343|      4|	enum signkey_type keytype;
  344|      4|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  103|      4|#define DROPBEAR_FAILURE -1
  ------------------
  345|       |
  346|      4|	TRACE2(("enter buf_get_priv_key"))
  347|       |
  348|      4|	ident = buf_getstring(buf, &len);
  349|      4|	keytype = signkey_type_from_name(ident, len);
  350|      4|	m_free(ident);
  ------------------
  |  |   24|      4|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  351|       |
  352|      4|	if (*type != DROPBEAR_SIGNKEY_ANY && *type != keytype) {
  ------------------
  |  Branch (352:6): [True: 4, False: 0]
  |  Branch (352:39): [True: 0, False: 4]
  ------------------
  353|      0|		TRACE(("wrong key type: %d %d", *type, keytype))
  354|      0|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
  355|      0|	}
  356|       |
  357|      4|	*type = keytype;
  358|       |
  359|       |	/* Rewind the buffer back before "ssh-rsa" etc */
  360|      4|	buf_decrpos(buf, len + 4);
  361|       |
  362|      4|#if DROPBEAR_DSS
  363|      4|	if (keytype == DROPBEAR_SIGNKEY_DSS) {
  ------------------
  |  Branch (363:6): [True: 1, False: 3]
  ------------------
  364|      1|		dss_key_free(key->dsskey);
  365|      1|		key->dsskey = m_malloc(sizeof(*key->dsskey));
  366|      1|		ret = buf_get_dss_priv_key(buf, key->dsskey);
  367|      1|		if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (367:7): [True: 0, False: 1]
  ------------------
  368|      0|			dss_key_free(key->dsskey);
  369|      0|			key->dsskey = NULL;
  370|      0|		}
  371|      1|	}
  372|      4|#endif
  373|      4|#if DROPBEAR_RSA
  374|      4|	if (keytype == DROPBEAR_SIGNKEY_RSA) {
  ------------------
  |  Branch (374:6): [True: 1, False: 3]
  ------------------
  375|      1|		rsa_key_free(key->rsakey);
  376|      1|		key->rsakey = m_malloc(sizeof(*key->rsakey));
  377|      1|		ret = buf_get_rsa_priv_key(buf, key->rsakey);
  378|      1|		if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (378:7): [True: 0, False: 1]
  ------------------
  379|      0|			rsa_key_free(key->rsakey);
  380|      0|			key->rsakey = NULL;
  381|      0|		}
  382|      1|	}
  383|      4|#endif
  384|      4|#if DROPBEAR_ECDSA
  385|      4|	if (signkey_is_ecdsa(keytype)) {
  ------------------
  |  Branch (385:6): [True: 1, False: 3]
  ------------------
  386|      1|		ecc_key **eck = (ecc_key**)signkey_key_ptr(key, keytype);
  387|      1|		if (eck) {
  ------------------
  |  Branch (387:7): [True: 1, False: 0]
  ------------------
  388|      1|			if (*eck) {
  ------------------
  |  Branch (388:8): [True: 0, False: 1]
  ------------------
  389|      0|				ecc_free(*eck);
  390|      0|				m_free(*eck);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  391|      0|				*eck = NULL;
  392|      0|			}
  393|      1|			*eck = buf_get_ecdsa_priv_key(buf);
  394|      1|			if (*eck) {
  ------------------
  |  Branch (394:8): [True: 1, False: 0]
  ------------------
  395|      1|				ret = DROPBEAR_SUCCESS;
  ------------------
  |  |  102|      1|#define DROPBEAR_SUCCESS 0
  ------------------
  396|      1|			}
  397|      1|		}
  398|      1|	}
  399|      4|#endif
  400|      4|#if DROPBEAR_ED25519
  401|      4|	if (keytype == DROPBEAR_SIGNKEY_ED25519) {
  ------------------
  |  Branch (401:6): [True: 1, False: 3]
  ------------------
  402|      1|		ed25519_key_free(key->ed25519key);
  403|      1|		key->ed25519key = m_malloc(sizeof(*key->ed25519key));
  404|      1|		ret = buf_get_ed25519_priv_key(buf, key->ed25519key);
  405|      1|		if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (405:7): [True: 0, False: 1]
  ------------------
  406|      0|			m_free(key->ed25519key);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  407|      0|			key->ed25519key = NULL;
  408|      0|		}
  409|      1|	}
  410|      4|#endif
  411|       |
  412|      4|	TRACE2(("leave buf_get_priv_key"))
  413|       |
  414|      4|	return ret;
  415|       |	
  416|      4|}

pty_allocate:
   50|      8|{
   51|      8|#if defined(HAVE_OPENPTY)
   52|       |	/* exists in recent (4.4) BSDs and OSF/1 */
   53|      8|	char *name;
   54|      8|	int i;
   55|       |
   56|      8|	i = openpty(ptyfd, ttyfd, NULL, NULL, NULL);
   57|      8|	if (i < 0) {
  ------------------
  |  Branch (57:6): [True: 0, False: 8]
  ------------------
   58|      0|		dropbear_log(LOG_WARNING, 
   59|      0|				"pty_allocate: openpty: %.100s", strerror(errno));
   60|      0|		return 0;
   61|      0|	}
   62|      8|	name = ttyname(*ttyfd);
   63|      8|	if (!name) {
  ------------------
  |  Branch (63:6): [True: 0, False: 8]
  ------------------
   64|      0|		dropbear_exit("ttyname fails for openpty device");
   65|      0|	}
   66|       |
   67|      8|	strlcpy(namebuf, name, namebuflen);	/* possible truncation */
   68|      8|	return 1;
   69|       |#else /* HAVE_OPENPTY */
   70|       |#ifdef HAVE__GETPTY
   71|       |	/*
   72|       |	 * _getpty(3) exists in SGI Irix 4.x, 5.x & 6.x -- it generates more
   73|       |	 * pty's automagically when needed
   74|       |	 */
   75|       |	char *slave;
   76|       |
   77|       |	slave = _getpty(ptyfd, O_RDWR, 0622, 0);
   78|       |	if (slave == NULL) {
   79|       |		dropbear_log(LOG_WARNING,
   80|       |				"pty_allocate: _getpty: %.100s", strerror(errno));
   81|       |		return 0;
   82|       |	}
   83|       |	strlcpy(namebuf, slave, namebuflen);
   84|       |	/* Open the slave side. */
   85|       |	*ttyfd = open(namebuf, O_RDWR | O_NOCTTY);
   86|       |	if (*ttyfd < 0) {
   87|       |		dropbear_log(LOG_WARNING,
   88|       |				"pty_allocate error: ttyftd open error");
   89|       |		close(*ptyfd);
   90|       |		return 0;
   91|       |	}
   92|       |	return 1;
   93|       |#else /* HAVE__GETPTY */
   94|       |#if defined(USE_DEV_PTMX)
   95|       |	/*
   96|       |	 * This code is used e.g. on Solaris 2.x.  (Note that Solaris 2.3
   97|       |	 * also has bsd-style ptys, but they simply do not work.)
   98|       |	 *
   99|       |	 * Linux systems may have the /dev/ptmx device, but this code won't work.
  100|       |	 */
  101|       |	int ptm;
  102|       |	char *pts;
  103|       |
  104|       |	ptm = open("/dev/ptmx", O_RDWR | O_NOCTTY);
  105|       |	if (ptm < 0) {
  106|       |		dropbear_log(LOG_WARNING,
  107|       |				"pty_allocate: /dev/ptmx: %.100s", strerror(errno));
  108|       |		return 0;
  109|       |	}
  110|       |	if (grantpt(ptm) < 0) {
  111|       |		dropbear_log(LOG_WARNING,
  112|       |				"grantpt: %.100s", strerror(errno));
  113|       |		return 0;
  114|       |	}
  115|       |	if (unlockpt(ptm) < 0) {
  116|       |		dropbear_log(LOG_WARNING,
  117|       |				"unlockpt: %.100s", strerror(errno));
  118|       |		return 0;
  119|       |	}
  120|       |	pts = ptsname(ptm);
  121|       |	if (pts == NULL) {
  122|       |		dropbear_log(LOG_WARNING,
  123|       |				"Slave pty side name could not be obtained.");
  124|       |	}
  125|       |	strlcpy(namebuf, pts, namebuflen);
  126|       |	*ptyfd = ptm;
  127|       |
  128|       |	/* Open the slave side. */
  129|       |	*ttyfd = open(namebuf, O_RDWR | O_NOCTTY);
  130|       |	if (*ttyfd < 0) {
  131|       |		dropbear_log(LOG_ERR,
  132|       |			"error opening pts %.100s: %.100s", namebuf, strerror(errno));
  133|       |		close(*ptyfd);
  134|       |		return 0;
  135|       |	}
  136|       |#if !defined(HAVE_CYGWIN) && defined(I_PUSH)
  137|       |	/*
  138|       |	 * Push the appropriate streams modules, as described in Solaris pts(7).
  139|       |	 * HP-UX pts(7) doesn't have ttcompat module.
  140|       |	 */
  141|       |	if (ioctl(*ttyfd, I_PUSH, "ptem") < 0) {
  142|       |		dropbear_log(LOG_WARNING,
  143|       |				"ioctl I_PUSH ptem: %.100s", strerror(errno));
  144|       |	}
  145|       |	if (ioctl(*ttyfd, I_PUSH, "ldterm") < 0) {
  146|       |		dropbear_log(LOG_WARNING,
  147|       |			"ioctl I_PUSH ldterm: %.100s", strerror(errno));
  148|       |	}
  149|       |#ifndef __hpux
  150|       |	if (ioctl(*ttyfd, I_PUSH, "ttcompat") < 0) {
  151|       |		dropbear_log(LOG_WARNING,
  152|       |			"ioctl I_PUSH ttcompat: %.100s", strerror(errno));
  153|       |	}
  154|       |#endif
  155|       |#endif
  156|       |	return 1;
  157|       |#else /* USE_DEV_PTMX */
  158|       |#ifdef HAVE_DEV_PTS_AND_PTC
  159|       |	/* AIX-style pty code. */
  160|       |	const char *name;
  161|       |
  162|       |	*ptyfd = open("/dev/ptc", O_RDWR | O_NOCTTY);
  163|       |	if (*ptyfd < 0) {
  164|       |		dropbear_log(LOG_ERR,
  165|       |			"Could not open /dev/ptc: %.100s", strerror(errno));
  166|       |		return 0;
  167|       |	}
  168|       |	name = ttyname(*ptyfd);
  169|       |	if (!name) {
  170|       |		dropbear_exit("ttyname fails for /dev/ptc device");
  171|       |	}
  172|       |	strlcpy(namebuf, name, namebuflen);
  173|       |	*ttyfd = open(name, O_RDWR | O_NOCTTY);
  174|       |	if (*ttyfd < 0) {
  175|       |		dropbear_log(LOG_ERR,
  176|       |			"Could not open pty slave side %.100s: %.100s",
  177|       |		    name, strerror(errno));
  178|       |		close(*ptyfd);
  179|       |		return 0;
  180|       |	}
  181|       |	return 1;
  182|       |#else /* HAVE_DEV_PTS_AND_PTC */
  183|       |
  184|       |	/* BSD-style pty code. */
  185|       |	char buf[64];
  186|       |	int i;
  187|       |	const char *ptymajors = "pqrstuvwxyzabcdefghijklmnoABCDEFGHIJKLMNOPQRSTUVWXYZ";
  188|       |	const char *ptyminors = "0123456789abcdef";
  189|       |	int num_minors = strlen(ptyminors);
  190|       |	int num_ptys = strlen(ptymajors) * num_minors;
  191|       |	struct termios tio;
  192|       |
  193|       |	for (i = 0; i < num_ptys; i++) {
  194|       |		snprintf(buf, sizeof buf, "/dev/pty%c%c", ptymajors[i / num_minors],
  195|       |			 ptyminors[i % num_minors]);
  196|       |		snprintf(namebuf, namebuflen, "/dev/tty%c%c",
  197|       |		    ptymajors[i / num_minors], ptyminors[i % num_minors]);
  198|       |
  199|       |		*ptyfd = open(buf, O_RDWR | O_NOCTTY);
  200|       |		if (*ptyfd < 0) {
  201|       |			/* Try SCO style naming */
  202|       |			snprintf(buf, sizeof buf, "/dev/ptyp%d", i);
  203|       |			snprintf(namebuf, namebuflen, "/dev/ttyp%d", i);
  204|       |			*ptyfd = open(buf, O_RDWR | O_NOCTTY);
  205|       |			if (*ptyfd < 0) {
  206|       |				continue;
  207|       |			}
  208|       |		}
  209|       |
  210|       |		/* Open the slave side. */
  211|       |		*ttyfd = open(namebuf, O_RDWR | O_NOCTTY);
  212|       |		if (*ttyfd < 0) {
  213|       |			dropbear_log(LOG_ERR,
  214|       |				"pty_allocate: %.100s: %.100s", namebuf, strerror(errno));
  215|       |			close(*ptyfd);
  216|       |			return 0;
  217|       |		}
  218|       |		/* set tty modes to a sane state for broken clients */
  219|       |		if (tcgetattr(*ptyfd, &tio) < 0) {
  220|       |			dropbear_log(LOG_WARNING,
  221|       |				"ptyallocate: tty modes failed: %.100s", strerror(errno));
  222|       |		} else {
  223|       |			tio.c_lflag |= (ECHO | ISIG | ICANON);
  224|       |			tio.c_oflag |= (OPOST | ONLCR);
  225|       |			tio.c_iflag |= ICRNL;
  226|       |
  227|       |			/* Set the new modes for the terminal. */
  228|       |			if (tcsetattr(*ptyfd, TCSANOW, &tio) < 0) {
  229|       |				dropbear_log(LOG_WARNING,
  230|       |					"Setting tty modes for pty failed: %.100s",
  231|       |					strerror(errno));
  232|       |			}
  233|       |		}
  234|       |
  235|       |		return 1;
  236|       |	}
  237|       |	dropbear_log(LOG_WARNING, "Failed to open any /dev/pty?? devices");
  238|       |	return 0;
  239|       |#endif /* HAVE_DEV_PTS_AND_PTC */
  240|       |#endif /* USE_DEV_PTMX */
  241|       |#endif /* HAVE__GETPTY */
  242|       |#endif /* HAVE_OPENPTY */
  243|      8|}
pty_release:
  249|      8|{
  250|      8|	if (chown(tty_name, (uid_t) 0, (gid_t) 0) < 0
  ------------------
  |  Branch (250:6): [True: 0, False: 8]
  ------------------
  251|      8|			&& (errno != ENOENT)) {
  ------------------
  |  Branch (251:7): [True: 0, False: 0]
  ------------------
  252|      0|		dropbear_log(LOG_ERR,
  253|      0|				"chown %.100s 0 0 failed: %.100s", tty_name, strerror(errno));
  254|      0|	}
  255|      8|	if (chmod(tty_name, (mode_t) 0666) < 0
  ------------------
  |  Branch (255:6): [True: 0, False: 8]
  ------------------
  256|      8|			&& (errno != ENOENT)) {
  ------------------
  |  Branch (256:7): [True: 0, False: 0]
  ------------------
  257|      0|		dropbear_log(LOG_ERR,
  258|      0|			"chmod %.100s 0666 failed: %.100s", tty_name, strerror(errno));
  259|      0|	}
  260|      8|}
pty_change_window_size:
  345|      1|{
  346|      1|	struct winsize w;
  347|       |
  348|      1|	w.ws_row = row;
  349|      1|	w.ws_col = col;
  350|      1|	w.ws_xpixel = xpixel;
  351|      1|	w.ws_ypixel = ypixel;
  352|      1|	(void) ioctl(ptyfd, TIOCSWINSZ, &w);
  353|      1|}
pty_setowner:
  357|      8|{
  358|      8|	struct group *grp;
  359|      8|	gid_t gid;
  360|      8|	mode_t mode;
  361|      8|	struct stat st;
  362|       |
  363|       |	/* Determine the group to make the owner of the tty. */
  364|      8|	grp = getgrnam("tty");
  365|      8|	if (grp) {
  ------------------
  |  Branch (365:6): [True: 8, False: 0]
  ------------------
  366|      8|		gid = grp->gr_gid;
  367|      8|		mode = S_IRUSR | S_IWUSR | S_IWGRP;
  368|      8|	} else {
  369|      0|		gid = pw->pw_gid;
  370|      0|		mode = S_IRUSR | S_IWUSR | S_IWGRP | S_IWOTH;
  371|      0|	}
  372|       |
  373|       |	/*
  374|       |	 * Change owner and mode of the tty as required.
  375|       |	 * Warn but continue if filesystem is read-only and the uids match/
  376|       |	 * tty is owned by root.
  377|       |	 */
  378|      8|	if (stat(tty_name, &st)) {
  ------------------
  |  Branch (378:6): [True: 0, False: 8]
  ------------------
  379|      0|		dropbear_exit("pty_setowner: stat(%.101s) failed: %.100s",
  380|      0|				tty_name, strerror(errno));
  381|      0|	}
  382|       |
  383|       |	/* Allow either "tty" gid or user's own gid. On Linux with openpty()
  384|       |	 * this varies depending on the devpts mount options */
  385|      8|	if (st.st_uid != pw->pw_uid || !(st.st_gid == gid || st.st_gid == pw->pw_gid)) {
  ------------------
  |  Branch (385:6): [True: 0, False: 8]
  |  Branch (385:35): [True: 8, False: 0]
  |  Branch (385:55): [True: 0, False: 0]
  ------------------
  386|      0|		if (chown(tty_name, pw->pw_uid, gid) < 0) {
  ------------------
  |  Branch (386:7): [True: 0, False: 0]
  ------------------
  387|      0|			if (errno == EROFS &&
  ------------------
  |  Branch (387:8): [True: 0, False: 0]
  ------------------
  388|      0|			    (st.st_uid == pw->pw_uid || st.st_uid == 0)) {
  ------------------
  |  Branch (388:9): [True: 0, False: 0]
  |  Branch (388:36): [True: 0, False: 0]
  ------------------
  389|      0|				dropbear_log(LOG_ERR,
  390|      0|					"chown(%.100s, %u, %u) failed: %.100s",
  391|      0|						tty_name, (unsigned int)pw->pw_uid, (unsigned int)gid,
  392|      0|						strerror(errno));
  393|      0|			} else {
  394|      0|				dropbear_exit("chown(%.100s, %u, %u) failed: %.100s",
  395|      0|				    tty_name, (unsigned int)pw->pw_uid, (unsigned int)gid,
  396|      0|				    strerror(errno));
  397|      0|			}
  398|      0|		}
  399|      0|	}
  400|       |
  401|      8|	if ((st.st_mode & (S_IRWXU|S_IRWXG|S_IRWXO)) != mode) {
  ------------------
  |  Branch (401:6): [True: 0, False: 8]
  ------------------
  402|      0|		if (chmod(tty_name, mode) < 0) {
  ------------------
  |  Branch (402:7): [True: 0, False: 0]
  ------------------
  403|      0|			if (errno == EROFS &&
  ------------------
  |  Branch (403:8): [True: 0, False: 0]
  ------------------
  404|      0|			    (st.st_mode & (S_IRGRP | S_IROTH)) == 0) {
  ------------------
  |  Branch (404:8): [True: 0, False: 0]
  ------------------
  405|      0|				dropbear_log(LOG_ERR,
  406|      0|					"chmod(%.100s, 0%o) failed: %.100s",
  407|      0|					tty_name, mode, strerror(errno));
  408|      0|			} else {
  409|      0|				dropbear_exit("chmod(%.100s, 0%o) failed: %.100s",
  410|      0|				    tty_name, mode, strerror(errno));
  411|      0|			}
  412|      0|		}
  413|      0|	}
  414|      8|}

svr_agentcleanup:
  140|  3.78k|void svr_agentcleanup(struct ChanSess * chansess) {
  141|       |
  142|  3.78k|	char *path = NULL;
  143|  3.78k|	uid_t uid;
  144|  3.78k|	gid_t gid;
  145|  3.78k|	int len;
  146|       |
  147|  3.78k|	if (chansess->agentlistener != NULL) {
  ------------------
  |  Branch (147:6): [True: 0, False: 3.78k]
  ------------------
  148|      0|		remove_listener(chansess->agentlistener);
  149|      0|		chansess->agentlistener = NULL;
  150|      0|	}
  151|       |
  152|  3.78k|	if (chansess->agentfile != NULL && chansess->agentdir != NULL) {
  ------------------
  |  Branch (152:6): [True: 0, False: 3.78k]
  |  Branch (152:37): [True: 0, False: 0]
  ------------------
  153|       |
  154|      0|#if DROPBEAR_SVR_MULTIUSER
  155|       |		/* Remove the dir as the user. That way they can't cause problems except
  156|       |		 * for themselves */
  157|      0|		uid = getuid();
  158|      0|		gid = getgid();
  159|      0|		if ((setegid(ses.authstate.pw_gid)) < 0 ||
  ------------------
  |  Branch (159:7): [True: 0, False: 0]
  ------------------
  160|      0|			(seteuid(ses.authstate.pw_uid)) < 0) {
  ------------------
  |  Branch (160:4): [True: 0, False: 0]
  ------------------
  161|      0|			dropbear_exit("Failed to set euid");
  162|      0|		}
  163|      0|#endif
  164|       |
  165|       |		/* 2 for "/" and "\0" */
  166|      0|		len = strlen(chansess->agentdir) + strlen(chansess->agentfile) + 2;
  167|       |
  168|      0|		path = m_malloc(len);
  169|      0|		snprintf(path, len, "%s/%s", chansess->agentdir, chansess->agentfile);
  170|      0|		unlink(path);
  171|      0|		m_free(path);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  172|       |
  173|      0|		rmdir(chansess->agentdir);
  174|       |
  175|      0|#if DROPBEAR_SVR_MULTIUSER
  176|      0|		if ((seteuid(uid)) < 0 ||
  ------------------
  |  Branch (176:7): [True: 0, False: 0]
  ------------------
  177|      0|			(setegid(gid)) < 0) {
  ------------------
  |  Branch (177:4): [True: 0, False: 0]
  ------------------
  178|      0|			dropbear_exit("Failed to revert euid");
  179|      0|		}
  180|      0|#endif
  181|       |
  182|      0|		m_free(chansess->agentfile);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  183|      0|		m_free(chansess->agentdir);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  184|      0|	}
  185|       |
  186|  3.78k|}

svr_authinitialise:
   42|  1.49k|void svr_authinitialise() {
   43|  1.49k|	memset(&ses.authstate, 0, sizeof(ses.authstate));
   44|  1.49k|#if DROPBEAR_SVR_PUBKEY_AUTH
   45|  1.49k|	ses.authstate.authtypes |= AUTH_TYPE_PUBKEY;
  ------------------
  |  |   88|  1.49k|#define AUTH_TYPE_PUBKEY    (1 << 1)
  ------------------
   46|  1.49k|#endif
   47|  1.49k|#if DROPBEAR_SVR_PASSWORD_AUTH || DROPBEAR_SVR_PAM_AUTH
   48|  1.49k|	if (!svr_opts.noauthpass) {
  ------------------
  |  Branch (48:6): [True: 1.49k, False: 0]
  ------------------
   49|  1.49k|		ses.authstate.authtypes |= AUTH_TYPE_PASSWORD;
  ------------------
  |  |   89|  1.49k|#define AUTH_TYPE_PASSWORD  (1 << 2)
  ------------------
   50|  1.49k|	}
   51|  1.49k|#endif
   52|  1.49k|}
recv_msg_userauth_request:
   73|    634|void recv_msg_userauth_request() {
   74|       |
   75|    634|	char *username = NULL, *servicename = NULL, *methodname = NULL;
   76|    634|	unsigned int userlen, servicelen, methodlen;
   77|    634|	int valid_user = 0;
   78|       |
   79|    634|	TRACE(("enter recv_msg_userauth_request"))
   80|       |
   81|       |	/* for compensating failure delay */
   82|    634|	gettime_wrapper(&ses.authstate.auth_starttime);
   83|       |
   84|       |	/* ignore packets if auth is already done */
   85|    634|	if (ses.authstate.authdone == 1) {
  ------------------
  |  Branch (85:6): [True: 634, False: 0]
  ------------------
   86|    634|		TRACE(("leave recv_msg_userauth_request: authdone already"))
   87|    634|		return;
   88|    634|	}
   89|       |
   90|       |	/* send the banner if it exists, it will only exist once */
   91|      0|	if (svr_opts.banner) {
  ------------------
  |  Branch (91:6): [True: 0, False: 0]
  ------------------
   92|      0|		send_msg_userauth_banner(svr_opts.banner);
   93|      0|		buf_free(svr_opts.banner);
   94|      0|		svr_opts.banner = NULL;
   95|      0|	}
   96|       |
   97|      0|	username = buf_getstring(ses.payload, &userlen);
   98|      0|	servicename = buf_getstring(ses.payload, &servicelen);
   99|      0|	methodname = buf_getstring(ses.payload, &methodlen);
  100|       |
  101|       |	/* only handle 'ssh-connection' currently */
  102|      0|	if (servicelen != SSH_SERVICE_CONNECTION_LEN
  ------------------
  |  |  107|      0|#define SSH_SERVICE_CONNECTION_LEN 14
  ------------------
  |  Branch (102:6): [True: 0, False: 0]
  ------------------
  103|      0|			&& (strncmp(servicename, SSH_SERVICE_CONNECTION,
  ------------------
  |  |  106|      0|#define SSH_SERVICE_CONNECTION "ssh-connection"
  ------------------
  |  Branch (103:7): [True: 0, False: 0]
  ------------------
  104|      0|					SSH_SERVICE_CONNECTION_LEN) != 0)) {
  ------------------
  |  |  107|      0|#define SSH_SERVICE_CONNECTION_LEN 14
  ------------------
  105|       |		
  106|       |		/* TODO - disconnect here */
  107|      0|		m_free(username);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  108|      0|		m_free(servicename);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  109|      0|		m_free(methodname);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  110|      0|		dropbear_exit("unknown service in auth");
  111|      0|	}
  112|       |
  113|       |	/* check username is good before continuing. 
  114|       |	 * the 'incrfail' varies depending on the auth method to
  115|       |	 * avoid giving away which users exist on the system through
  116|       |	 * the time delay. */
  117|      0|	if (checkusername(username, userlen) == DROPBEAR_SUCCESS) {
  ------------------
  |  |  102|      0|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (117:6): [True: 0, False: 0]
  ------------------
  118|      0|		valid_user = 1;
  119|      0|	}
  120|       |
  121|       |	/* user wants to know what methods are supported */
  122|      0|	if (methodlen == AUTH_METHOD_NONE_LEN &&
  ------------------
  |  |   93|      0|#define AUTH_METHOD_NONE_LEN 4
  ------------------
  |  Branch (122:6): [True: 0, False: 0]
  ------------------
  123|      0|			strncmp(methodname, AUTH_METHOD_NONE,
  ------------------
  |  |   92|      0|#define AUTH_METHOD_NONE "none"
  ------------------
  |  Branch (123:4): [True: 0, False: 0]
  ------------------
  124|      0|				AUTH_METHOD_NONE_LEN) == 0) {
  ------------------
  |  |   93|      0|#define AUTH_METHOD_NONE_LEN 4
  ------------------
  125|      0|		TRACE(("recv_msg_userauth_request: 'none' request"))
  126|      0|		if (valid_user
  ------------------
  |  Branch (126:7): [True: 0, False: 0]
  ------------------
  127|      0|				&& svr_opts.allowblankpass
  ------------------
  |  Branch (127:8): [True: 0, False: 0]
  ------------------
  128|      0|				&& !svr_opts.noauthpass
  ------------------
  |  Branch (128:8): [True: 0, False: 0]
  ------------------
  129|      0|				&& !(svr_opts.norootpass && ses.authstate.pw_uid == 0) 
  ------------------
  |  Branch (129:10): [True: 0, False: 0]
  |  Branch (129:33): [True: 0, False: 0]
  ------------------
  130|      0|				&& ses.authstate.pw_passwd[0] == '\0') 
  ------------------
  |  Branch (130:8): [True: 0, False: 0]
  ------------------
  131|      0|		{
  132|      0|			dropbear_log(LOG_NOTICE, 
  133|      0|					"Auth succeeded with blank password for '%s' from %s",
  134|      0|					ses.authstate.pw_name,
  135|      0|					svr_ses.addrstring);
  136|      0|			send_msg_userauth_success();
  137|      0|			goto out;
  138|      0|		}
  139|      0|		else
  140|      0|		{
  141|       |			/* 'none' has no failure delay */
  142|      0|			send_msg_userauth_failure(0, 0);
  143|      0|			goto out;
  144|      0|		}
  145|      0|	}
  146|       |	
  147|      0|#if DROPBEAR_SVR_PASSWORD_AUTH
  148|      0|	if (!svr_opts.noauthpass &&
  ------------------
  |  Branch (148:6): [True: 0, False: 0]
  ------------------
  149|      0|			!(svr_opts.norootpass && ses.authstate.pw_uid == 0) ) {
  ------------------
  |  Branch (149:6): [True: 0, False: 0]
  |  Branch (149:29): [True: 0, False: 0]
  ------------------
  150|       |		/* user wants to try password auth */
  151|      0|		if (methodlen == AUTH_METHOD_PASSWORD_LEN &&
  ------------------
  |  |   97|      0|#define AUTH_METHOD_PASSWORD_LEN 8
  ------------------
  |  Branch (151:7): [True: 0, False: 0]
  ------------------
  152|      0|				strncmp(methodname, AUTH_METHOD_PASSWORD,
  ------------------
  |  |   96|      0|#define AUTH_METHOD_PASSWORD "password"
  ------------------
  |  Branch (152:5): [True: 0, False: 0]
  ------------------
  153|      0|					AUTH_METHOD_PASSWORD_LEN) == 0) {
  ------------------
  |  |   97|      0|#define AUTH_METHOD_PASSWORD_LEN 8
  ------------------
  154|      0|			svr_auth_password(valid_user);
  155|      0|			goto out;
  156|      0|		}
  157|      0|	}
  158|      0|#endif
  159|       |
  160|       |#if DROPBEAR_SVR_PAM_AUTH
  161|       |	if (!svr_opts.noauthpass &&
  162|       |			!(svr_opts.norootpass && ses.authstate.pw_uid == 0) ) {
  163|       |		/* user wants to try password auth */
  164|       |		if (methodlen == AUTH_METHOD_PASSWORD_LEN &&
  165|       |				strncmp(methodname, AUTH_METHOD_PASSWORD,
  166|       |					AUTH_METHOD_PASSWORD_LEN) == 0) {
  167|       |			svr_auth_pam(valid_user);
  168|       |			goto out;
  169|       |		}
  170|       |	}
  171|       |#endif
  172|       |
  173|      0|#if DROPBEAR_SVR_PUBKEY_AUTH
  174|       |	/* user wants to try pubkey auth */
  175|      0|	if (methodlen == AUTH_METHOD_PUBKEY_LEN &&
  ------------------
  |  |   95|      0|#define AUTH_METHOD_PUBKEY_LEN 9
  ------------------
  |  Branch (175:6): [True: 0, False: 0]
  ------------------
  176|      0|			strncmp(methodname, AUTH_METHOD_PUBKEY,
  ------------------
  |  |   94|      0|#define AUTH_METHOD_PUBKEY "publickey"
  ------------------
  |  Branch (176:4): [True: 0, False: 0]
  ------------------
  177|      0|				AUTH_METHOD_PUBKEY_LEN) == 0) {
  ------------------
  |  |   95|      0|#define AUTH_METHOD_PUBKEY_LEN 9
  ------------------
  178|      0|		svr_auth_pubkey(valid_user);
  179|      0|		goto out;
  180|      0|	}
  181|      0|#endif
  182|       |
  183|       |	/* nothing matched, we just fail with a delay */
  184|      0|	send_msg_userauth_failure(0, 1);
  185|       |
  186|      0|out:
  187|       |
  188|      0|	m_free(username);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  189|      0|	m_free(servicename);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  190|      0|	m_free(methodname);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  191|      0|}

svr_pubkey_allows_tcpfwd:
   65|  2.55k|int svr_pubkey_allows_tcpfwd() {
   66|  2.55k|	if (ses.authstate.pubkey_options 
  ------------------
  |  Branch (66:6): [True: 0, False: 2.55k]
  ------------------
   67|  2.55k|		&& ses.authstate.pubkey_options->no_port_forwarding_flag) {
  ------------------
  |  Branch (67:6): [True: 0, False: 0]
  ------------------
   68|      0|		return 0;
   69|      0|	}
   70|  2.55k|	return 1;
   71|  2.55k|}
svr_pubkey_allows_pty:
   84|    167|int svr_pubkey_allows_pty() {
   85|    167|	if (ses.authstate.pubkey_options 
  ------------------
  |  Branch (85:6): [True: 0, False: 167]
  ------------------
   86|    167|		&& ses.authstate.pubkey_options->no_pty_flag) {
  ------------------
  |  Branch (86:6): [True: 0, False: 0]
  ------------------
   87|      0|		return 0;
   88|      0|	}
   89|    167|	return 1;
   90|    167|}
svr_pubkey_allows_local_tcpfwd:
   94|     98|int svr_pubkey_allows_local_tcpfwd(const char *host, unsigned int port) {
   95|     98|	if (ses.authstate.pubkey_options
  ------------------
  |  Branch (95:6): [True: 0, False: 98]
  ------------------
   96|     98|		&& ses.authstate.pubkey_options->permit_open_destinations) {
  ------------------
  |  Branch (96:6): [True: 0, False: 0]
  ------------------
   97|      0|		m_list_elem *iter = ses.authstate.pubkey_options->permit_open_destinations->first;
   98|      0|		while (iter) {
  ------------------
  |  Branch (98:10): [True: 0, False: 0]
  ------------------
   99|      0|			struct PermitTCPFwdEntry *entry = (struct PermitTCPFwdEntry*)iter->item;
  100|      0|			if (strcmp(entry->host, host) == 0) {
  ------------------
  |  Branch (100:8): [True: 0, False: 0]
  ------------------
  101|      0|				if ((entry->port == PUBKEY_OPTIONS_ANY_PORT) || (entry->port == port)) {
  ------------------
  |  |  101|      0|#define PUBKEY_OPTIONS_ANY_PORT UINT_MAX
  ------------------
  |  Branch (101:9): [True: 0, False: 0]
  |  Branch (101:53): [True: 0, False: 0]
  ------------------
  102|      0|					return 1;
  103|      0|				}
  104|      0|			}
  105|       |
  106|      0|			iter = iter->next;
  107|      0|		}
  108|       |
  109|      0|		return 0;
  110|      0|	}
  111|       |
  112|     98|	return 1;
  113|     98|}
svr_pubkey_set_forced_command:
  117|  2.58k|void svr_pubkey_set_forced_command(struct ChanSess *chansess) {
  118|  2.58k|	if (ses.authstate.pubkey_options && ses.authstate.pubkey_options->forced_command) {
  ------------------
  |  Branch (118:6): [True: 0, False: 2.58k]
  |  Branch (118:38): [True: 0, False: 0]
  ------------------
  119|      0|		TRACE(("Forced command '%s'", ses.authstate.pubkey_options->forced_command))
  120|      0|		if (chansess->cmd) {
  ------------------
  |  Branch (120:7): [True: 0, False: 0]
  ------------------
  121|       |			/* original_command takes ownership */
  122|      0|			chansess->original_command = chansess->cmd;
  123|      0|			chansess->cmd = NULL;
  124|      0|		} else {
  125|      0|			chansess->original_command = m_strdup("");
  126|      0|		}
  127|      0|		chansess->cmd = m_strdup(ses.authstate.pubkey_options->forced_command);
  128|       |#if LOG_COMMANDS
  129|       |		dropbear_log(LOG_INFO, "Command forced to '%s'", chansess->original_command);
  130|       |#endif
  131|      0|	}
  132|  2.58k|}
svr_pubkey_options_cleanup:
  135|  1.49k|void svr_pubkey_options_cleanup() {
  136|  1.49k|	if (ses.authstate.pubkey_options) {
  ------------------
  |  Branch (136:6): [True: 0, False: 1.49k]
  ------------------
  137|      0|		if (ses.authstate.pubkey_options->forced_command) {
  ------------------
  |  Branch (137:7): [True: 0, False: 0]
  ------------------
  138|      0|			m_free(ses.authstate.pubkey_options->forced_command);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  139|      0|		}
  140|      0|		if (ses.authstate.pubkey_options->permit_open_destinations) {
  ------------------
  |  Branch (140:7): [True: 0, False: 0]
  ------------------
  141|      0|			m_list_elem *iter = ses.authstate.pubkey_options->permit_open_destinations->first;
  142|      0|			while (iter) {
  ------------------
  |  Branch (142:11): [True: 0, False: 0]
  ------------------
  143|      0|				struct PermitTCPFwdEntry *entry = (struct PermitTCPFwdEntry*)list_remove(iter);
  144|      0|				m_free(entry->host);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  145|      0|				m_free(entry);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  146|      0|				iter = ses.authstate.pubkey_options->permit_open_destinations->first;
  147|      0|			}
  148|      0|			m_free(ses.authstate.pubkey_options->permit_open_destinations);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  149|      0|		}
  150|      0|		m_free(ses.authstate.pubkey_options);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  151|      0|	}
  152|  1.49k|	if (ses.authstate.pubkey_info) {
  ------------------
  |  Branch (152:6): [True: 0, False: 1.49k]
  ------------------
  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.49k|}

svr_chansess_checksignal:
   95|   456k|void svr_chansess_checksignal(void) {
   96|   456k|	int status;
   97|   456k|	pid_t pid;
   98|       |
   99|   456k|	if (!ses.channel_signal_pending) {
  ------------------
  |  Branch (99:6): [True: 456k, False: 0]
  ------------------
  100|   456k|		return;
  101|   456k|	}
  102|       |
  103|      0|	while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
  ------------------
  |  Branch (103:9): [True: 0, False: 0]
  ------------------
  104|      0|		unsigned int i;
  105|      0|		struct exitinfo *ex = NULL;
  106|      0|		TRACE(("svr_chansess_checksignal : pid %d", pid))
  107|       |
  108|      0|		ex = NULL;
  109|       |		/* find the corresponding chansess */
  110|      0|		for (i = 0; i < svr_ses.childpidsize; i++) {
  ------------------
  |  Branch (110:15): [True: 0, False: 0]
  ------------------
  111|      0|			if (svr_ses.childpids[i].pid == pid) {
  ------------------
  |  Branch (111:8): [True: 0, False: 0]
  ------------------
  112|      0|				TRACE(("found match session"));
  113|      0|				ex = &svr_ses.childpids[i].chansess->exit;
  114|      0|				break;
  115|      0|			}
  116|      0|		}
  117|       |
  118|       |		/* If the pid wasn't matched, then we might have hit the race mentioned
  119|       |		 * above. So we just store the info for the parent to deal with */
  120|      0|		if (ex == NULL) {
  ------------------
  |  Branch (120:7): [True: 0, False: 0]
  ------------------
  121|      0|			TRACE(("using lastexit"));
  122|      0|			ex = &svr_ses.lastexit;
  123|      0|		}
  124|       |
  125|      0|		ex->exitpid = pid;
  126|      0|		if (WIFEXITED(status)) {
  127|      0|			ex->exitstatus = WEXITSTATUS(status);
  128|      0|		}
  129|      0|		if (WIFSIGNALED(status)) {
  130|      0|			ex->exitsignal = WTERMSIG(status);
  131|      0|#if !defined(AIX) && defined(WCOREDUMP)
  132|      0|			ex->exitcore = WCOREDUMP(status);
  133|       |#else
  134|       |			ex->exitcore = 0;
  135|       |#endif
  136|      0|		} else {
  137|       |			/* we use this to determine how pid exited */
  138|      0|			ex->exitsignal = -1;
  139|      0|		}
  140|      0|	}
  141|      0|}
svr_chansessinitialise:
 1077|  1.49k|void svr_chansessinitialise() {
 1078|       |
 1079|  1.49k|	struct sigaction sa_chld;
 1080|       |
 1081|       |	/* single child process intially */
 1082|  1.49k|	svr_ses.childpids = (struct ChildPid*)m_malloc(sizeof(struct ChildPid));
 1083|  1.49k|	svr_ses.childpids[0].pid = -1; /* unused */
 1084|  1.49k|	svr_ses.childpids[0].chansess = NULL;
 1085|  1.49k|	svr_ses.childpidsize = 1;
 1086|  1.49k|	svr_ses.lastexit.exitpid = -1; /* Nothing has exited yet */
 1087|  1.49k|	sa_chld.sa_handler = sesssigchild_handler;
 1088|  1.49k|	sa_chld.sa_flags = SA_NOCLDSTOP;
 1089|  1.49k|	sigemptyset(&sa_chld.sa_mask);
 1090|  1.49k|	if (sigaction(SIGCHLD, &sa_chld, NULL) < 0) {
  ------------------
  |  Branch (1090:6): [True: 0, False: 1.49k]
  ------------------
 1091|      0|		dropbear_exit("signal() error");
 1092|      0|	}
 1093|       |	
 1094|  1.49k|}
svr-chansession.c:sesscheckclose:
   77|   184k|static int sesscheckclose(struct Channel *channel) {
   78|   184k|	struct ChanSess *chansess = (struct ChanSess*)channel->typedata;
   79|   184k|	TRACE(("sesscheckclose, pid %d, exitpid %d", chansess->pid, chansess->exit.exitpid))
   80|       |
   81|   184k|	if (chansess->exit.exitpid != -1) {
  ------------------
  |  Branch (81:6): [True: 0, False: 184k]
  ------------------
   82|      0|		channel->flushing = 1;
   83|      0|	}
   84|   184k|	return chansess->pid == 0 || chansess->exit.exitpid != -1;
  ------------------
  |  Branch (84:9): [True: 710, False: 184k]
  |  Branch (84:31): [True: 0, False: 184k]
  ------------------
   85|   184k|}
svr-chansession.c:newchansess:
  241|  3.78k|static int newchansess(struct Channel *channel) {
  242|       |
  243|  3.78k|	struct ChanSess *chansess;
  244|       |
  245|  3.78k|	TRACE(("new chansess %p", (void*)channel))
  246|       |
  247|  3.78k|	dropbear_assert(channel->typedata == NULL);
  ------------------
  |  |   83|  3.78k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 3.78k]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
  248|       |
  249|  3.78k|	chansess = (struct ChanSess*)m_malloc(sizeof(struct ChanSess));
  250|  3.78k|	chansess->cmd = NULL;
  251|  3.78k|	chansess->connection_string = NULL;
  252|  3.78k|	chansess->client_string = NULL;
  253|  3.78k|	chansess->pid = 0;
  254|       |
  255|       |	/* pty details */
  256|  3.78k|	chansess->master = -1;
  257|  3.78k|	chansess->slave = -1;
  258|  3.78k|	chansess->tty = NULL;
  259|  3.78k|	chansess->term = NULL;
  260|       |
  261|  3.78k|	chansess->exit.exitpid = -1;
  262|       |
  263|  3.78k|	channel->typedata = chansess;
  264|       |
  265|       |#if DROPBEAR_X11FWD
  266|       |	chansess->x11listener = NULL;
  267|       |	chansess->x11authprot = NULL;
  268|       |	chansess->x11authcookie = NULL;
  269|       |#endif
  270|       |
  271|  3.78k|#if DROPBEAR_SVR_AGENTFWD
  272|  3.78k|	chansess->agentlistener = NULL;
  273|  3.78k|	chansess->agentfile = NULL;
  274|  3.78k|	chansess->agentdir = NULL;
  275|  3.78k|#endif
  276|       |
  277|       |	/* Will drop to DROPBEAR_PRIO_NORMAL if a non-tty command starts */
  278|  3.78k|	channel->prio = DROPBEAR_PRIO_LOWDELAY;
  279|       |
  280|  3.78k|	return 0;
  281|       |
  282|  3.78k|}
svr-chansession.c:closechansess:
  293|    710|static void closechansess(const struct Channel *channel) {
  294|    710|	struct ChanSess *chansess;
  295|       |
  296|    710|	TRACE(("enter closechansess"))
  297|       |
  298|    710|	chansess = (struct ChanSess*)channel->typedata;
  299|       |
  300|    710|	if (chansess == NULL) {
  ------------------
  |  Branch (300:6): [True: 0, False: 710]
  ------------------
  301|      0|		TRACE(("leave closechansess: chansess == NULL"))
  302|      0|		return;
  303|      0|	}
  304|       |
  305|    710|	send_exitsignalstatus(channel);
  306|    710|	TRACE(("leave closechansess"))
  307|    710|}
svr-chansession.c:send_exitsignalstatus:
  170|    710|static void send_exitsignalstatus(const struct Channel *channel) {
  171|       |
  172|    710|	struct ChanSess *chansess = (struct ChanSess*)channel->typedata;
  173|       |
  174|    710|	if (chansess->exit.exitpid >= 0) {
  ------------------
  |  Branch (174:6): [True: 0, False: 710]
  ------------------
  175|      0|		if (chansess->exit.exitsignal > 0) {
  ------------------
  |  Branch (175:7): [True: 0, False: 0]
  ------------------
  176|      0|			send_msg_chansess_exitsignal(channel, chansess);
  177|      0|		} else {
  178|      0|			send_msg_chansess_exitstatus(channel, chansess);
  179|      0|		}
  180|      0|	}
  181|    710|}
svr-chansession.c:cleanupchansess:
  310|  3.78k|static void cleanupchansess(const struct Channel *channel) {
  311|       |
  312|  3.78k|	struct ChanSess *chansess;
  313|  3.78k|	unsigned int i;
  314|  3.78k|	struct logininfo *li;
  315|       |
  316|  3.78k|	TRACE(("enter closechansess"))
  317|       |
  318|  3.78k|	chansess = (struct ChanSess*)channel->typedata;
  319|       |
  320|  3.78k|	if (chansess == NULL) {
  ------------------
  |  Branch (320:6): [True: 0, False: 3.78k]
  ------------------
  321|      0|		TRACE(("leave closechansess: chansess == NULL"))
  322|      0|		return;
  323|      0|	}
  324|       |
  325|  3.78k|	m_free(chansess->cmd);
  ------------------
  |  |   24|  3.78k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  326|  3.78k|	m_free(chansess->term);
  ------------------
  |  |   24|  3.78k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  327|  3.78k|	m_free(chansess->original_command);
  ------------------
  |  |   24|  3.78k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  328|       |
  329|  3.78k|	if (chansess->tty) {
  ------------------
  |  Branch (329:6): [True: 8, False: 3.78k]
  ------------------
  330|       |		/* write the utmp/wtmp login record */
  331|      8|		li = chansess_login_alloc(chansess);
  332|      8|		login_logout(li);
  333|      8|		login_free_entry(li);
  334|       |
  335|      8|		pty_release(chansess->tty);
  336|      8|		m_free(chansess->tty);
  ------------------
  |  |   24|      8|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  337|      8|	}
  338|       |
  339|       |#if DROPBEAR_X11FWD
  340|       |	x11cleanup(chansess);
  341|       |#endif
  342|       |
  343|  3.78k|#if DROPBEAR_SVR_AGENTFWD
  344|  3.78k|	svr_agentcleanup(chansess);
  345|  3.78k|#endif
  346|       |
  347|       |	/* clear child pid entries */
  348|  12.9k|	for (i = 0; i < svr_ses.childpidsize; i++) {
  ------------------
  |  Branch (348:14): [True: 9.14k, False: 3.78k]
  ------------------
  349|  9.14k|		if (svr_ses.childpids[i].chansess == chansess) {
  ------------------
  |  Branch (349:7): [True: 1.55k, False: 7.59k]
  ------------------
  350|  1.55k|			dropbear_assert(svr_ses.childpids[i].pid > 0);
  ------------------
  |  |   83|  1.55k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 1.55k]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
  351|  1.55k|			TRACE(("closing pid %d", svr_ses.childpids[i].pid))
  352|  1.55k|			TRACE(("exitpid is %d", chansess->exit.exitpid))
  353|  1.55k|			svr_ses.childpids[i].pid = -1;
  354|  1.55k|			svr_ses.childpids[i].chansess = NULL;
  355|  1.55k|		}
  356|  9.14k|	}
  357|       |				
  358|  3.78k|	m_free(chansess);
  ------------------
  |  |   24|  3.78k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  359|       |
  360|  3.78k|	TRACE(("leave closechansess"))
  361|  3.78k|}
svr-chansession.c:chansess_login_alloc:
  285|      8|chansess_login_alloc(const struct ChanSess *chansess) {
  286|      8|	struct logininfo * li;
  287|      8|	li = login_alloc_entry(chansess->pid, ses.authstate.username,
  288|      8|			svr_ses.remotehost, chansess->tty);
  289|      8|	return li;
  290|      8|}
svr-chansession.c:chansessionrequest:
  365|  7.34k|static void chansessionrequest(struct Channel *channel) {
  366|       |
  367|  7.34k|	char * type = NULL;
  368|  7.34k|	unsigned int typelen;
  369|  7.34k|	unsigned char wantreply;
  370|  7.34k|	int ret = 1;
  371|  7.34k|	struct ChanSess *chansess;
  372|       |
  373|  7.34k|	TRACE(("enter chansessionrequest"))
  374|       |
  375|  7.34k|	type = buf_getstring(ses.payload, &typelen);
  376|  7.34k|	wantreply = buf_getbool(ses.payload);
  377|       |
  378|  7.34k|	if (typelen > MAX_NAME_LEN) {
  ------------------
  |  |  205|  7.34k|#define MAX_NAME_LEN 64 /* maximum length of a protocol name, isn't
  ------------------
  |  Branch (378:6): [True: 70, False: 7.27k]
  ------------------
  379|     70|		TRACE(("leave chansessionrequest: type too long")) /* XXX send error?*/
  380|     70|		goto out;
  381|     70|	}
  382|       |
  383|  7.27k|	chansess = (struct ChanSess*)channel->typedata;
  384|  7.27k|	dropbear_assert(chansess != NULL);
  ------------------
  |  |   83|  7.27k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 7.27k]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
  385|  7.27k|	TRACE(("type is %s", type))
  386|       |
  387|  7.27k|	if (strcmp(type, "window-change") == 0) {
  ------------------
  |  Branch (387:6): [True: 63, False: 7.20k]
  ------------------
  388|     63|		ret = sessionwinchange(chansess);
  389|  7.20k|	} else if (strcmp(type, "shell") == 0) {
  ------------------
  |  Branch (389:13): [True: 4.71k, False: 2.49k]
  ------------------
  390|  4.71k|		ret = sessioncommand(channel, chansess, 0, 0);
  391|  4.71k|	} else if (strcmp(type, "pty-req") == 0) {
  ------------------
  |  Branch (391:13): [True: 167, False: 2.32k]
  ------------------
  392|    167|		ret = sessionpty(chansess);
  393|  2.32k|	} else if (strcmp(type, "exec") == 0) {
  ------------------
  |  Branch (393:13): [True: 175, False: 2.15k]
  ------------------
  394|    175|		ret = sessioncommand(channel, chansess, 1, 0);
  395|  2.15k|	} else if (strcmp(type, "subsystem") == 0) {
  ------------------
  |  Branch (395:13): [True: 290, False: 1.86k]
  ------------------
  396|    290|		ret = sessioncommand(channel, chansess, 1, 1);
  397|       |#if DROPBEAR_X11FWD
  398|       |	} else if (strcmp(type, "x11-req") == 0) {
  399|       |		ret = x11req(chansess);
  400|       |#endif
  401|    290|#if DROPBEAR_SVR_AGENTFWD
  402|  1.86k|	} else if (strcmp(type, "auth-agent-req@openssh.com") == 0) {
  ------------------
  |  Branch (402:13): [True: 0, False: 1.86k]
  ------------------
  403|      0|		ret = svr_agentreq(chansess);
  404|      0|#endif
  405|  1.86k|	} else if (strcmp(type, "signal") == 0) {
  ------------------
  |  Branch (405:13): [True: 506, False: 1.35k]
  ------------------
  406|    506|		ret = sessionsignal(chansess);
  407|  1.35k|	} else {
  408|       |		/* etc, todo "env", "subsystem" */
  409|  1.35k|	}
  410|       |
  411|  7.31k|out:
  412|       |
  413|  7.31k|	if (wantreply) {
  ------------------
  |  Branch (413:6): [True: 6.15k, False: 1.16k]
  ------------------
  414|  6.15k|		if (ret == DROPBEAR_SUCCESS) {
  ------------------
  |  |  102|  6.15k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (414:7): [True: 1.40k, False: 4.75k]
  ------------------
  415|  1.40k|			send_msg_channel_success(channel);
  416|  4.75k|		} else {
  417|  4.75k|			send_msg_channel_failure(channel);
  418|  4.75k|		}
  419|  6.15k|	}
  420|       |
  421|  7.31k|	m_free(type);
  ------------------
  |  |   24|  7.31k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  422|  7.31k|	TRACE(("leave chansessionrequest"))
  423|  7.31k|}
svr-chansession.c:sessionwinchange:
  467|     71|static int sessionwinchange(const struct ChanSess *chansess) {
  468|       |
  469|     71|	int termc, termr, termw, termh;
  470|       |
  471|     71|	if (chansess->master < 0) {
  ------------------
  |  Branch (471:6): [True: 63, False: 8]
  ------------------
  472|       |		/* haven't got a pty yet */
  473|     63|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|     63|#define DROPBEAR_FAILURE -1
  ------------------
  474|     63|	}
  475|       |			
  476|      8|	termc = buf_getint(ses.payload);
  477|      8|	termr = buf_getint(ses.payload);
  478|      8|	termw = buf_getint(ses.payload);
  479|      8|	termh = buf_getint(ses.payload);
  480|       |	
  481|      8|	pty_change_window_size(chansess->master, termr, termc, termw, termh);
  482|       |
  483|      8|	return DROPBEAR_SUCCESS;
  ------------------
  |  |  102|      8|#define DROPBEAR_SUCCESS 0
  ------------------
  484|     71|}
svr-chansession.c:sessioncommand:
  658|  5.18k|		int iscmd, int issubsys) {
  659|       |
  660|  5.18k|	unsigned int cmdlen = 0;
  661|  5.18k|	int ret;
  662|       |
  663|  5.18k|	TRACE(("enter sessioncommand %d", channel->index))
  664|       |
  665|  5.18k|	if (chansess->pid != 0) {
  ------------------
  |  Branch (665:6): [True: 2.36k, False: 2.81k]
  ------------------
  666|       |		/* Note that only one command can _succeed_. The client might try
  667|       |		 * one command (which fails), then try another. Ie fallback
  668|       |		 * from sftp to scp */
  669|  2.36k|		TRACE(("leave sessioncommand, already have a command"))
  670|  2.36k|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|  2.36k|#define DROPBEAR_FAILURE -1
  ------------------
  671|  2.36k|	}
  672|       |
  673|  2.81k|	if (iscmd) {
  ------------------
  |  Branch (673:6): [True: 405, False: 2.40k]
  ------------------
  674|       |		/* "exec" */
  675|    405|		if (chansess->cmd == NULL) {
  ------------------
  |  Branch (675:7): [True: 405, False: 0]
  ------------------
  676|    405|			chansess->cmd = buf_getstring(ses.payload, &cmdlen);
  677|       |
  678|    405|			if (cmdlen > MAX_CMD_LEN) {
  ------------------
  |  |   75|    405|#define MAX_CMD_LEN 9000 /* max length of a command */
  ------------------
  |  Branch (678:8): [True: 0, False: 405]
  ------------------
  679|      0|				m_free(chansess->cmd);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  680|       |				/* TODO - send error - too long ? */
  681|      0|				TRACE(("leave sessioncommand, command too long %d", cmdlen))
  682|      0|				return DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
  683|      0|			}
  684|    405|		}
  685|    405|		if (issubsys) {
  ------------------
  |  Branch (685:7): [True: 290, False: 115]
  ------------------
  686|    290|#if DROPBEAR_SFTPSERVER
  687|    290|			if ((cmdlen == 4) && strncmp(chansess->cmd, "sftp", 4) == 0) {
  ------------------
  |  Branch (687:8): [True: 130, False: 160]
  |  Branch (687:25): [True: 65, False: 65]
  ------------------
  688|     65|				char *expand_path = expand_homedir_path(SFTPSERVER_PATH);
  ------------------
  |  |  463|     65|#define SFTPSERVER_PATH "/usr/libexec/sftp-server"
  ------------------
  689|     65|				m_free(chansess->cmd);
  ------------------
  |  |   24|     65|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  690|     65|				chansess->cmd = m_strdup(expand_path);
  691|     65|				m_free(expand_path);
  ------------------
  |  |   24|     65|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  692|     65|			} else 
  693|    225|#endif
  694|    225|			{
  695|    225|				m_free(chansess->cmd);
  ------------------
  |  |   24|    225|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  696|    225|				TRACE(("leave sessioncommand, unknown subsystem"))
  697|    225|				return DROPBEAR_FAILURE;
  ------------------
  |  |  103|    225|#define DROPBEAR_FAILURE -1
  ------------------
  698|    225|			}
  699|    290|		}
  700|    405|	}
  701|       |	
  702|       |
  703|       |	/* take global command into account */
  704|  2.58k|	if (svr_opts.forced_command) {
  ------------------
  |  Branch (704:6): [True: 0, False: 2.58k]
  ------------------
  705|      0|		if (chansess->cmd) {
  ------------------
  |  Branch (705:7): [True: 0, False: 0]
  ------------------
  706|      0|			chansess->original_command = chansess->cmd;
  707|      0|		} else {
  708|      0|			chansess->original_command = m_strdup("");
  709|      0|		}
  710|      0|		chansess->cmd = m_strdup(svr_opts.forced_command);
  711|  2.58k|	} else {
  712|       |		/* take public key option 'command' into account */
  713|  2.58k|		svr_pubkey_set_forced_command(chansess);
  714|  2.58k|	}
  715|       |
  716|       |
  717|       |#if LOG_COMMANDS
  718|       |	if (chansess->cmd) {
  719|       |		dropbear_log(LOG_INFO, "User %s executing '%s'", 
  720|       |						ses.authstate.pw_name, chansess->cmd);
  721|       |	} else {
  722|       |		dropbear_log(LOG_INFO, "User %s executing login shell", 
  723|       |						ses.authstate.pw_name);
  724|       |	}
  725|       |#endif
  726|       |
  727|       |	/* uClinux will vfork(), so there'll be a race as 
  728|       |	connection_string is freed below. */
  729|  2.58k|#if !DROPBEAR_VFORK
  730|  2.58k|	make_connection_string(chansess);
  731|  2.58k|#endif
  732|       |
  733|  2.58k|	if (chansess->term == NULL) {
  ------------------
  |  Branch (733:6): [True: 1.55k, False: 1.03k]
  ------------------
  734|       |		/* no pty */
  735|  1.55k|		ret = noptycommand(channel, chansess);
  736|  1.55k|		if (ret == DROPBEAR_SUCCESS) {
  ------------------
  |  |  102|  1.55k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (736:7): [True: 1.55k, False: 0]
  ------------------
  737|  1.55k|			channel->prio = DROPBEAR_PRIO_NORMAL;
  738|  1.55k|			update_channel_prio();
  739|  1.55k|		}
  740|  1.55k|	} else {
  741|       |		/* want pty */
  742|  1.03k|		ret = ptycommand(channel, chansess);
  743|  1.03k|	}
  744|       |
  745|  2.58k|#if !DROPBEAR_VFORK
  746|  2.58k|	m_free(chansess->connection_string);
  ------------------
  |  |   24|  2.58k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  747|  2.58k|	m_free(chansess->client_string);
  ------------------
  |  |   24|  2.58k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  748|  2.58k|#endif
  749|       |
  750|  2.58k|	if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|  2.58k|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (750:6): [True: 1.03k, False: 1.55k]
  ------------------
  751|  1.03k|		m_free(chansess->cmd);
  ------------------
  |  |   24|  1.03k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  752|  1.03k|	}
  753|  2.58k|	TRACE(("leave sessioncommand, ret %d", ret))
  754|  2.58k|	return ret;
  755|  2.81k|}
svr-chansession.c:make_connection_string:
  630|  2.58k|static void make_connection_string(struct ChanSess *chansess) {
  631|  2.58k|	char *local_ip, *local_port, *remote_ip, *remote_port;
  632|  2.58k|	size_t len;
  633|  2.58k|	get_socket_address(ses.sock_in, &local_ip, &local_port, &remote_ip, &remote_port, 0);
  634|       |
  635|       |	/* "remoteip remoteport localip localport" */
  636|  2.58k|	len = strlen(local_ip) + strlen(remote_ip) + 20;
  637|  2.58k|	chansess->connection_string = m_malloc(len);
  638|  2.58k|	snprintf(chansess->connection_string, len, "%s %s %s %s", remote_ip, remote_port, local_ip, local_port);
  639|       |
  640|       |	/* deprecated but bash only loads .bashrc if SSH_CLIENT is set */ 
  641|       |	/* "remoteip remoteport localport" */
  642|  2.58k|	len = strlen(remote_ip) + 20;
  643|  2.58k|	chansess->client_string = m_malloc(len);
  644|  2.58k|	snprintf(chansess->client_string, len, "%s %s %s", remote_ip, remote_port, local_port);
  645|       |
  646|  2.58k|	m_free(local_ip);
  ------------------
  |  |   24|  2.58k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  647|  2.58k|	m_free(local_port);
  ------------------
  |  |   24|  2.58k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  648|  2.58k|	m_free(remote_ip);
  ------------------
  |  |   24|  2.58k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  649|  2.58k|	m_free(remote_port);
  ------------------
  |  |   24|  2.58k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  650|  2.58k|}
svr-chansession.c:noptycommand:
  760|  1.55k|static int noptycommand(struct Channel *channel, struct ChanSess *chansess) {
  761|  1.55k|	int ret;
  762|       |
  763|  1.55k|	TRACE(("enter noptycommand"))
  764|  1.55k|	ret = spawn_command(execchild, chansess, 
  765|  1.55k|			&channel->writefd, &channel->readfd, &channel->errfd,
  766|  1.55k|			&chansess->pid);
  767|       |
  768|  1.55k|	if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|  1.55k|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (768:6): [True: 0, False: 1.55k]
  ------------------
  769|      0|		return ret;
  770|      0|	}
  771|       |
  772|  1.55k|	ses.maxfd = MAX(ses.maxfd, channel->writefd);
  773|  1.55k|	ses.maxfd = MAX(ses.maxfd, channel->readfd);
  774|  1.55k|	ses.maxfd = MAX(ses.maxfd, channel->errfd);
  775|  1.55k|	channel->bidir_fd = 0;
  776|       |
  777|  1.55k|	addchildpid(chansess, chansess->pid);
  778|       |
  779|  1.55k|	if (svr_ses.lastexit.exitpid != -1) {
  ------------------
  |  Branch (779:6): [True: 0, False: 1.55k]
  ------------------
  780|      0|		unsigned int i;
  781|      0|		TRACE(("parent side: lastexitpid is %d", svr_ses.lastexit.exitpid))
  782|       |		/* The child probably exited and the signal handler triggered
  783|       |		 * possibly before we got around to adding the childpid. So we fill
  784|       |		 * out its data manually */
  785|      0|		for (i = 0; i < svr_ses.childpidsize; i++) {
  ------------------
  |  Branch (785:15): [True: 0, False: 0]
  ------------------
  786|      0|			if (svr_ses.childpids[i].pid == svr_ses.lastexit.exitpid) {
  ------------------
  |  Branch (786:8): [True: 0, False: 0]
  ------------------
  787|      0|				TRACE(("found match for lastexitpid"))
  788|      0|				svr_ses.childpids[i].chansess->exit = svr_ses.lastexit;
  789|      0|				svr_ses.lastexit.exitpid = -1;
  790|      0|				break;
  791|      0|			}
  792|      0|		}
  793|      0|	}
  794|       |
  795|  1.55k|	TRACE(("leave noptycommand"))
  796|  1.55k|	return DROPBEAR_SUCCESS;
  ------------------
  |  |  102|  1.55k|#define DROPBEAR_SUCCESS 0
  ------------------
  797|  1.55k|}
svr-chansession.c:addchildpid:
  924|  1.55k|static void addchildpid(struct ChanSess *chansess, pid_t pid) {
  925|       |
  926|  1.55k|	unsigned int i;
  927|  2.97k|	for (i = 0; i < svr_ses.childpidsize; i++) {
  ------------------
  |  Branch (927:14): [True: 2.39k, False: 574]
  ------------------
  928|  2.39k|		if (svr_ses.childpids[i].pid == -1) {
  ------------------
  |  Branch (928:7): [True: 984, False: 1.41k]
  ------------------
  929|    984|			break;
  930|    984|		}
  931|  2.39k|	}
  932|       |
  933|       |	/* need to increase size */
  934|  1.55k|	if (i == svr_ses.childpidsize) {
  ------------------
  |  Branch (934:6): [True: 574, False: 984]
  ------------------
  935|    574|		svr_ses.childpids = (struct ChildPid*)m_realloc(svr_ses.childpids,
  936|    574|				sizeof(struct ChildPid) * (svr_ses.childpidsize+1));
  937|    574|		svr_ses.childpidsize++;
  938|    574|	}
  939|       |	
  940|  1.55k|	TRACE(("addchildpid %d pid %d for chansess %p", i, pid, chansess))
  941|  1.55k|	svr_ses.childpids[i].pid = pid;
  942|  1.55k|	svr_ses.childpids[i].chansess = chansess;
  943|       |
  944|  1.55k|}
svr-chansession.c:ptycommand:
  802|  1.03k|static int ptycommand(struct Channel *channel, struct ChanSess *chansess) {
  803|       |
  804|  1.03k|	pid_t pid;
  805|  1.03k|	struct logininfo *li = NULL;
  806|  1.03k|#if DO_MOTD
  807|  1.03k|	buffer * motdbuf = NULL;
  808|  1.03k|	int len;
  809|  1.03k|	struct stat sb;
  810|  1.03k|	char *hushpath = NULL;
  811|  1.03k|#endif
  812|       |
  813|  1.03k|	TRACE(("enter ptycommand"))
  814|       |
  815|       |	/* we need to have a pty allocated */
  816|  1.03k|	if (chansess->master == -1 || chansess->tty == NULL) {
  ------------------
  |  Branch (816:6): [True: 1.03k, False: 0]
  |  Branch (816:32): [True: 0, False: 0]
  ------------------
  817|  1.03k|		dropbear_log(LOG_WARNING, "No pty was allocated, couldn't execute");
  818|  1.03k|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|  1.03k|#define DROPBEAR_FAILURE -1
  ------------------
  819|  1.03k|	}
  820|       |	
  821|       |#if DROPBEAR_VFORK
  822|       |	pid = vfork();
  823|       |#else
  824|      0|	pid = fork();
  825|      0|#endif
  826|      0|	if (pid < 0)
  ------------------
  |  Branch (826:6): [True: 0, False: 0]
  ------------------
  827|      0|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
  828|       |
  829|      0|	if (pid == 0) {
  ------------------
  |  Branch (829:6): [True: 0, False: 0]
  ------------------
  830|       |		/* child */
  831|       |		
  832|      0|		TRACE(("back to normal sigchld"))
  833|       |		/* Revert to normal sigchld handling */
  834|      0|		if (signal(SIGCHLD, SIG_DFL) == SIG_ERR) {
  ------------------
  |  Branch (834:7): [True: 0, False: 0]
  ------------------
  835|      0|			dropbear_exit("signal() error");
  836|      0|		}
  837|       |		
  838|       |		/* redirect stdin/stdout/stderr */
  839|      0|		close(chansess->master);
  ------------------
  |  |   56|      0|#define close(fd) wrapfd_close(fd)
  ------------------
  840|       |
  841|      0|		pty_make_controlling_tty(&chansess->slave, chansess->tty);
  842|       |		
  843|      0|		if ((dup2(chansess->slave, STDIN_FILENO) < 0) ||
  ------------------
  |  Branch (843:7): [True: 0, False: 0]
  ------------------
  844|      0|			(dup2(chansess->slave, STDOUT_FILENO) < 0)) {
  ------------------
  |  Branch (844:4): [True: 0, False: 0]
  ------------------
  845|      0|			TRACE(("leave ptycommand: error redirecting filedesc"))
  846|      0|			return DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
  847|      0|			}
  848|       |
  849|       |		/* write the utmp/wtmp login record - must be after changing the
  850|       |		 * terminal used for stdout with the dup2 above, otherwise
  851|       |		 * the wtmp login will not be recorded */
  852|      0|		li = chansess_login_alloc(chansess);
  853|      0|		login_login(li);
  854|      0|		login_free_entry(li);
  855|       |
  856|       |		/* Can now dup2 stderr. Messages from login_login() have gone
  857|       |		to the parent stderr */
  858|      0|		if (dup2(chansess->slave, STDERR_FILENO) < 0) {
  ------------------
  |  Branch (858:7): [True: 0, False: 0]
  ------------------
  859|      0|			TRACE(("leave ptycommand: error redirecting filedesc"))
  860|      0|			return DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
  861|      0|		}
  862|       |
  863|      0|		close(chansess->slave);
  ------------------
  |  |   56|      0|#define close(fd) wrapfd_close(fd)
  ------------------
  864|       |
  865|      0|#if DO_MOTD
  866|      0|		if (svr_opts.domotd && !chansess->cmd) {
  ------------------
  |  Branch (866:7): [True: 0, False: 0]
  |  Branch (866:26): [True: 0, False: 0]
  ------------------
  867|       |			/* don't show the motd if ~/.hushlogin exists */
  868|       |
  869|       |			/* 12 == strlen("/.hushlogin\0") */
  870|      0|			len = strlen(ses.authstate.pw_dir) + 12; 
  871|       |
  872|      0|			hushpath = m_malloc(len);
  873|      0|			snprintf(hushpath, len, "%s/.hushlogin", ses.authstate.pw_dir);
  874|       |
  875|      0|			if (stat(hushpath, &sb) < 0) {
  ------------------
  |  Branch (875:8): [True: 0, False: 0]
  ------------------
  876|      0|				char *expand_path = NULL;
  877|       |				/* more than a screenful is stupid IMHO */
  878|      0|				motdbuf = buf_new(80 * 25);
  879|      0|				expand_path = expand_homedir_path(MOTD_FILENAME);
  ------------------
  |  |  329|      0|#define MOTD_FILENAME "/etc/motd"
  ------------------
  880|      0|				if (buf_readfile(motdbuf, expand_path) == DROPBEAR_SUCCESS) {
  ------------------
  |  |  102|      0|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (880:9): [True: 0, False: 0]
  ------------------
  881|      0|					buf_setpos(motdbuf, 0);
  882|      0|					while (motdbuf->pos != motdbuf->len) {
  ------------------
  |  Branch (882:13): [True: 0, False: 0]
  ------------------
  883|      0|						len = motdbuf->len - motdbuf->pos;
  884|      0|						len = write(STDOUT_FILENO, 
  ------------------
  |  |   54|      0|#define write(fd, buf, count) wrapfd_write(fd, buf, count)
  ------------------
  885|      0|								buf_getptr(motdbuf, len), len);
  886|      0|						buf_incrpos(motdbuf, len);
  887|      0|					}
  888|      0|				}
  889|      0|				m_free(expand_path);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  890|      0|				buf_free(motdbuf);
  891|       |
  892|      0|			}
  893|      0|			m_free(hushpath);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  894|      0|		}
  895|      0|#endif /* DO_MOTD */
  896|       |
  897|      0|		execchild(chansess);
  898|       |		/* not reached */
  899|       |
  900|      0|	} else {
  901|       |		/* parent */
  902|      0|		TRACE(("continue ptycommand: parent"))
  903|      0|		chansess->pid = pid;
  904|       |
  905|       |		/* add a child pid */
  906|      0|		addchildpid(chansess, pid);
  907|       |
  908|      0|		close(chansess->slave);
  ------------------
  |  |   56|      0|#define close(fd) wrapfd_close(fd)
  ------------------
  909|      0|		channel->writefd = chansess->master;
  910|      0|		channel->readfd = chansess->master;
  911|       |		/* don't need to set stderr here */
  912|      0|		ses.maxfd = MAX(ses.maxfd, chansess->master);
  913|      0|		channel->bidir_fd = 1;
  914|       |
  915|      0|		setnonblocking(chansess->master);
  916|       |
  917|      0|	}
  918|       |
  919|      0|	TRACE(("leave ptycommand"))
  920|      0|	return DROPBEAR_SUCCESS;
  ------------------
  |  |  102|      0|#define DROPBEAR_SUCCESS 0
  ------------------
  921|      0|}
svr-chansession.c:sessionpty:
  580|    167|static int sessionpty(struct ChanSess * chansess) {
  581|       |
  582|    167|	unsigned int termlen;
  583|    167|	char namebuf[65];
  584|    167|	struct passwd * pw = NULL;
  585|       |
  586|    167|	TRACE(("enter sessionpty"))
  587|       |
  588|    167|	if (!svr_pubkey_allows_pty()) {
  ------------------
  |  Branch (588:6): [True: 0, False: 167]
  ------------------
  589|      0|		TRACE(("leave sessionpty : pty forbidden by public key option"))
  590|      0|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
  591|      0|	}
  592|       |
  593|    167|	chansess->term = buf_getstring(ses.payload, &termlen);
  594|    167|	if (termlen > MAX_TERM_LEN) {
  ------------------
  |  |   76|    167|#define MAX_TERM_LEN 200 /* max length of TERM name */
  ------------------
  |  Branch (594:6): [True: 154, False: 13]
  ------------------
  595|       |		/* TODO send disconnect ? */
  596|    154|		TRACE(("leave sessionpty: term len too long"))
  597|    154|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|    154|#define DROPBEAR_FAILURE -1
  ------------------
  598|    154|	}
  599|       |
  600|       |	/* allocate the pty */
  601|     13|	if (chansess->master != -1) {
  ------------------
  |  Branch (601:6): [True: 0, False: 13]
  ------------------
  602|      0|		dropbear_exit("Multiple pty requests");
  603|      0|	}
  604|     13|	if (pty_allocate(&chansess->master, &chansess->slave, namebuf, 64) == 0) {
  ------------------
  |  Branch (604:6): [True: 0, False: 13]
  ------------------
  605|      0|		TRACE(("leave sessionpty: failed to allocate pty"))
  606|      0|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
  607|      0|	}
  608|       |	
  609|     13|	chansess->tty = m_strdup(namebuf);
  610|     13|	if (!chansess->tty) {
  ------------------
  |  Branch (610:6): [True: 0, False: 13]
  ------------------
  611|      0|		dropbear_exit("Out of memory"); /* TODO disconnect */
  612|      0|	}
  613|       |
  614|     13|	pw = getpwnam(ses.authstate.pw_name);
  ------------------
  |  |  108|     13|#define getpwnam(x) fuzz_getpwnam(x)
  ------------------
  615|     13|	if (!pw)
  ------------------
  |  Branch (615:6): [True: 0, False: 13]
  ------------------
  616|      0|		dropbear_exit("getpwnam failed after succeeding previously");
  617|     13|	pty_setowner(pw, chansess->tty);
  618|       |
  619|       |	/* Set up the rows/col counts */
  620|     13|	sessionwinchange(chansess);
  621|       |
  622|       |	/* Read the terminal modes */
  623|     13|	get_termmodes(chansess);
  624|       |
  625|     13|	TRACE(("leave sessionpty"))
  626|     13|	return DROPBEAR_SUCCESS;
  ------------------
  |  |  102|     13|#define DROPBEAR_SUCCESS 0
  ------------------
  627|     13|}
svr-chansession.c:get_termmodes:
  486|      1|static void get_termmodes(const struct ChanSess *chansess) {
  487|       |
  488|      1|	struct termios termio;
  489|      1|	unsigned char opcode;
  490|      1|	unsigned int value;
  491|      1|	const struct TermCode * termcode;
  492|      1|	unsigned int len;
  493|       |
  494|      1|	TRACE(("enter get_termmodes"))
  495|       |
  496|       |	/* Term modes */
  497|       |	/* We'll ignore errors and continue if we can't set modes.
  498|       |	 * We're ignoring baud rates since they seem evil */
  499|      1|	if (tcgetattr(chansess->master, &termio) == -1) {
  ------------------
  |  Branch (499:6): [True: 0, False: 1]
  ------------------
  500|      0|		return;
  501|      0|	}
  502|       |
  503|      1|	len = buf_getint(ses.payload);
  504|      1|	TRACE(("term mode str %d p->l %d p->p %d", 
  505|      1|				len, ses.payload->len , ses.payload->pos));
  506|      1|	if (len != ses.payload->len - ses.payload->pos) {
  ------------------
  |  Branch (506:6): [True: 1, False: 0]
  ------------------
  507|      1|		dropbear_exit("Bad term mode string");
  508|      1|	}
  509|       |
  510|      0|	if (len == 0) {
  ------------------
  |  Branch (510:6): [True: 0, False: 0]
  ------------------
  511|      0|		TRACE(("leave get_termmodes: empty terminal modes string"))
  512|      0|		return;
  513|      0|	}
  514|       |
  515|      0|	while (((opcode = buf_getbyte(ses.payload)) != 0x00) && opcode <= 159) {
  ------------------
  |  Branch (515:9): [True: 0, False: 0]
  |  Branch (515:58): [True: 0, False: 0]
  ------------------
  516|       |
  517|       |		/* must be before checking type, so that value is consumed even if
  518|       |		 * we don't use it */
  519|      0|		value = buf_getint(ses.payload);
  520|       |
  521|       |		/* handle types of code */
  522|      0|		if (opcode > MAX_TERMCODE) {
  ------------------
  |  |   35|      0|#define MAX_TERMCODE 93
  ------------------
  |  Branch (522:7): [True: 0, False: 0]
  ------------------
  523|      0|			continue;
  524|      0|		}
  525|      0|		termcode = &termcodes[(unsigned int)opcode];
  526|       |		
  527|       |
  528|      0|		switch (termcode->type) {
  ------------------
  |  Branch (528:11): [True: 0, False: 0]
  ------------------
  529|       |
  530|      0|			case TERMCODE_NONE:
  ------------------
  |  |   28|      0|#define TERMCODE_NONE 0
  ------------------
  |  Branch (530:4): [True: 0, False: 0]
  ------------------
  531|      0|				break;
  532|       |
  533|      0|			case TERMCODE_CONTROLCHAR:
  ------------------
  |  |   33|      0|#define TERMCODE_CONTROLCHAR 5
  ------------------
  |  Branch (533:4): [True: 0, False: 0]
  ------------------
  534|      0|				termio.c_cc[termcode->mapcode] = value;
  535|      0|				break;
  536|       |
  537|      0|			case TERMCODE_INPUT:
  ------------------
  |  |   30|      0|#define TERMCODE_INPUT 2
  ------------------
  |  Branch (537:4): [True: 0, False: 0]
  ------------------
  538|      0|				if (value) {
  ------------------
  |  Branch (538:9): [True: 0, False: 0]
  ------------------
  539|      0|					termio.c_iflag |= termcode->mapcode;
  540|      0|				} else {
  541|      0|					termio.c_iflag &= ~(termcode->mapcode);
  542|      0|				}
  543|      0|				break;
  544|       |
  545|      0|			case TERMCODE_OUTPUT:
  ------------------
  |  |   31|      0|#define TERMCODE_OUTPUT 3
  ------------------
  |  Branch (545:4): [True: 0, False: 0]
  ------------------
  546|      0|				if (value) {
  ------------------
  |  Branch (546:9): [True: 0, False: 0]
  ------------------
  547|      0|					termio.c_oflag |= termcode->mapcode;
  548|      0|				} else {
  549|      0|					termio.c_oflag &= ~(termcode->mapcode);
  550|      0|				}
  551|      0|				break;
  552|       |
  553|      0|			case TERMCODE_LOCAL:
  ------------------
  |  |   32|      0|#define TERMCODE_LOCAL 4
  ------------------
  |  Branch (553:4): [True: 0, False: 0]
  ------------------
  554|      0|				if (value) {
  ------------------
  |  Branch (554:9): [True: 0, False: 0]
  ------------------
  555|      0|					termio.c_lflag |= termcode->mapcode;
  556|      0|				} else {
  557|      0|					termio.c_lflag &= ~(termcode->mapcode);
  558|      0|				}
  559|      0|				break;
  560|       |
  561|      0|			case TERMCODE_CONTROL:
  ------------------
  |  |   29|      0|#define TERMCODE_CONTROL 1
  ------------------
  |  Branch (561:4): [True: 0, False: 0]
  ------------------
  562|      0|				if (value) {
  ------------------
  |  Branch (562:9): [True: 0, False: 0]
  ------------------
  563|      0|					termio.c_cflag |= termcode->mapcode;
  564|      0|				} else {
  565|      0|					termio.c_cflag &= ~(termcode->mapcode);
  566|      0|				}
  567|      0|				break;
  568|       |				
  569|      0|		}
  570|      0|	}
  571|      0|	if (tcsetattr(chansess->master, TCSANOW, &termio) < 0) {
  ------------------
  |  Branch (571:6): [True: 0, False: 0]
  ------------------
  572|      0|		dropbear_log(LOG_INFO, "Error setting terminal attributes");
  573|      0|	}
  574|      0|	TRACE(("leave get_termmodes"))
  575|      0|}
svr-chansession.c:sessionsignal:
  427|    506|static int sessionsignal(const struct ChanSess *chansess) {
  428|    506|	TRACE(("sessionsignal"))
  429|       |
  430|    506|	int sig = 0;
  431|    506|	char* signame = NULL;
  432|    506|	int i;
  433|       |
  434|    506|	if (chansess->pid == 0) {
  ------------------
  |  Branch (434:6): [True: 100, False: 406]
  ------------------
  435|    100|		TRACE(("sessionsignal: done no pid"))
  436|       |		/* haven't got a process pid yet */
  437|    100|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|    100|#define DROPBEAR_FAILURE -1
  ------------------
  438|    100|	}
  439|       |
  440|    406|	signame = buf_getstring(ses.payload, NULL);
  441|       |
  442|  4.00k|	for (i = 0; signames[i].name != NULL; i++) {
  ------------------
  |  Branch (442:14): [True: 3.78k, False: 221]
  ------------------
  443|  3.78k|		if (strcmp(signames[i].name, signame) == 0) {
  ------------------
  |  Branch (443:7): [True: 185, False: 3.60k]
  ------------------
  444|    185|			sig = signames[i].signal;
  445|    185|			break;
  446|    185|		}
  447|  3.78k|	}
  448|       |
  449|    406|	m_free(signame);
  ------------------
  |  |   24|    406|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  450|       |
  451|    406|	TRACE(("sessionsignal: pid %d signal %d", (int)chansess->pid, sig))
  452|    406|	if (sig == 0) {
  ------------------
  |  Branch (452:6): [True: 220, False: 186]
  ------------------
  453|       |		/* failed */
  454|    220|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|    220|#define DROPBEAR_FAILURE -1
  ------------------
  455|    220|	}
  456|       |			
  457|    186|	if (kill(chansess->pid, sig) < 0) {
  ------------------
  |  |   57|    186|#define kill(pid, sig) fuzz_kill(pid, sig)
  ------------------
  |  Branch (457:6): [True: 0, False: 186]
  ------------------
  458|      0|		TRACE(("sessionsignal: kill() errored"))
  459|      0|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
  460|      0|	} 
  461|       |
  462|    186|	return DROPBEAR_SUCCESS;
  ------------------
  |  |  102|    186|#define DROPBEAR_SUCCESS 0
  ------------------
  463|    186|}

recv_msg_kexdh_init:
   49|  9.32k|void recv_msg_kexdh_init() {
   50|  9.32k|	DEF_MP_INT(dh_e);
  ------------------
  |  |   80|  9.32k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
   51|  9.32k|	buffer *ecdh_qs = NULL;
   52|       |
   53|  9.32k|	TRACE(("enter recv_msg_kexdh_init"))
   54|  9.32k|	if (!ses.kexstate.recvkexinit) {
  ------------------
  |  Branch (54:6): [True: 5, False: 9.32k]
  ------------------
   55|      5|		dropbear_exit("Premature kexdh_init message received");
   56|      5|	}
   57|       |
   58|  9.32k|	switch (ses.newkeys->algo_kex->mode) {
  ------------------
  |  Branch (58:10): [True: 0, False: 9.32k]
  ------------------
   59|      0|#if DROPBEAR_NORMAL_DH
   60|  2.96k|		case DROPBEAR_KEX_NORMAL_DH:
  ------------------
  |  Branch (60:3): [True: 2.96k, False: 6.36k]
  ------------------
   61|  2.96k|			m_mp_init(&dh_e);
   62|  2.96k|			if (buf_getmpint(ses.payload, &dh_e) != DROPBEAR_SUCCESS) {
  ------------------
  |  |  102|  2.96k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (62:8): [True: 2, False: 2.96k]
  ------------------
   63|      2|				dropbear_exit("Bad kex value");
   64|      2|			}
   65|  2.96k|			break;
   66|  2.96k|#endif
   67|  2.96k|#if DROPBEAR_ECDH
   68|  2.96k|		case DROPBEAR_KEX_ECDH:
  ------------------
  |  Branch (68:3): [True: 2.52k, False: 6.80k]
  ------------------
   69|  2.52k|#endif
   70|  2.52k|#if DROPBEAR_CURVE25519
   71|  6.36k|		case DROPBEAR_KEX_CURVE25519:
  ------------------
  |  Branch (71:3): [True: 3.83k, False: 5.48k]
  ------------------
   72|  6.36k|#endif
   73|  6.36k|#if DROPBEAR_ECDH || DROPBEAR_CURVE25519
   74|  6.36k|			ecdh_qs = buf_getstringbuf(ses.payload);
   75|  6.36k|			break;
   76|  9.32k|#endif
   77|  9.32k|	}
   78|  9.31k|	if (ses.payload->pos != ses.payload->len) {
  ------------------
  |  Branch (78:6): [True: 39, False: 9.27k]
  ------------------
   79|     39|		dropbear_exit("Bad kex value");
   80|     39|	}
   81|       |
   82|  9.27k|	send_msg_kexdh_reply(&dh_e, ecdh_qs);
   83|       |
   84|  9.27k|	mp_clear(&dh_e);
   85|  9.27k|	if (ecdh_qs) {
  ------------------
  |  Branch (85:6): [True: 6.34k, False: 2.93k]
  ------------------
   86|  6.34k|		buf_free(ecdh_qs);
   87|  6.34k|		ecdh_qs = NULL;
   88|  6.34k|	}
   89|       |
   90|  9.27k|	send_msg_newkeys();
   91|       |
   92|  9.27k|#if DROPBEAR_EXT_INFO
   93|       |	/* Only send it following the first newkeys */
   94|  9.27k|	if (!ses.kexstate.donesecondkex && ses.allow_ext_info) {
  ------------------
  |  Branch (94:6): [True: 1.31k, False: 7.96k]
  |  Branch (94:37): [True: 8, False: 1.30k]
  ------------------
   95|      8|		send_msg_ext_info();
   96|      8|	}
   97|  9.27k|#endif
   98|       |
   99|  9.27k|	ses.requirenext = SSH_MSG_NEWKEYS;
  ------------------
  |  |   37|  9.27k|#define SSH_MSG_NEWKEYS                21
  ------------------
  100|  9.27k|	TRACE(("leave recv_msg_kexdh_init"))
  101|  9.27k|}
svr-kex.c:send_msg_kexdh_reply:
  189|  9.27k|static void send_msg_kexdh_reply(mp_int *dh_e, buffer *ecdh_qs) {
  190|  9.27k|	TRACE(("enter send_msg_kexdh_reply"))
  191|       |
  192|       |	/* we can start creating the kexdh_reply packet */
  193|  9.27k|	CHECKCLEARTOWRITE();
  194|       |
  195|  9.27k|#if DROPBEAR_DELAY_HOSTKEY
  196|  9.27k|	if (svr_opts.delay_hostkey)
  ------------------
  |  Branch (196:6): [True: 0, False: 9.27k]
  ------------------
  197|      0|	{
  198|      0|		svr_ensure_hostkey();
  199|      0|	}
  200|  9.27k|#endif
  201|       |
  202|  9.27k|#if DROPBEAR_FUZZ
  203|  9.27k|	if (fuzz.fuzzing && fuzz.skip_kexmaths) {
  ------------------
  |  Branch (203:6): [True: 9.27k, False: 0]
  |  Branch (203:22): [True: 9.27k, False: 0]
  ------------------
  204|  9.27k|		fuzz_fake_send_kexdh_reply();
  205|  9.27k|		return;
  206|  9.27k|	}
  207|      0|#endif
  208|       |
  209|      0|	buf_putbyte(ses.writepayload, SSH_MSG_KEXDH_REPLY);
  ------------------
  |  |   39|      0|#define SSH_MSG_KEXDH_REPLY            31
  ------------------
  210|      0|	buf_put_pub_key(ses.writepayload, svr_opts.hostkey,
  211|      0|			ses.newkeys->algo_hostkey);
  212|       |
  213|      0|	switch (ses.newkeys->algo_kex->mode) {
  ------------------
  |  Branch (213:10): [True: 0, False: 0]
  ------------------
  214|      0|#if DROPBEAR_NORMAL_DH
  215|      0|		case DROPBEAR_KEX_NORMAL_DH:
  ------------------
  |  Branch (215:3): [True: 0, False: 0]
  ------------------
  216|      0|			{
  217|      0|			struct kex_dh_param * dh_param = gen_kexdh_param();
  218|      0|			kexdh_comb_key(dh_param, dh_e, svr_opts.hostkey);
  219|       |
  220|       |			/* put f */
  221|      0|			buf_putmpint(ses.writepayload, &dh_param->pub);
  222|      0|			free_kexdh_param(dh_param);
  223|      0|			}
  224|      0|			break;
  225|      0|#endif
  226|      0|#if DROPBEAR_ECDH
  227|      0|		case DROPBEAR_KEX_ECDH:
  ------------------
  |  Branch (227:3): [True: 0, False: 0]
  ------------------
  228|      0|			{
  229|      0|			struct kex_ecdh_param *ecdh_param = gen_kexecdh_param();
  230|      0|			kexecdh_comb_key(ecdh_param, ecdh_qs, svr_opts.hostkey);
  231|       |
  232|      0|			buf_put_ecc_raw_pubkey_string(ses.writepayload, &ecdh_param->key);
  233|      0|			free_kexecdh_param(ecdh_param);
  234|      0|			}
  235|      0|			break;
  236|      0|#endif
  237|      0|#if DROPBEAR_CURVE25519
  238|      0|		case DROPBEAR_KEX_CURVE25519:
  ------------------
  |  Branch (238:3): [True: 0, False: 0]
  ------------------
  239|      0|			{
  240|      0|			struct kex_curve25519_param *param = gen_kexcurve25519_param();
  241|      0|			kexcurve25519_comb_key(param, ecdh_qs, svr_opts.hostkey);
  242|       |
  243|      0|			buf_putstring(ses.writepayload, param->pub, CURVE25519_LEN);
  ------------------
  |  |  106|      0|#define CURVE25519_LEN 32
  ------------------
  244|      0|			free_kexcurve25519_param(param);
  245|      0|			}
  246|      0|			break;
  247|      0|#endif
  248|      0|	}
  249|       |
  250|       |	/* calc the signature */
  251|      0|	buf_put_sign(ses.writepayload, svr_opts.hostkey, 
  252|      0|			ses.newkeys->algo_signature, ses.hash);
  253|       |
  254|       |	/* the SSH_MSG_KEXDH_REPLY is done */
  255|      0|	encrypt_packet();
  256|       |
  257|      0|	TRACE(("leave send_msg_kexdh_reply"))
  258|      0|}
svr-kex.c:send_msg_ext_info:
  262|      8|static void send_msg_ext_info(void) {
  263|      8|	TRACE(("enter send_msg_ext_info"))
  264|       |
  265|      8|	buf_putbyte(ses.writepayload, SSH_MSG_EXT_INFO);
  ------------------
  |  |   35|      8|#define SSH_MSG_EXT_INFO               7
  ------------------
  266|       |	/* nr-extensions */
  267|      8|	buf_putint(ses.writepayload, 1);
  268|       |
  269|      8|	buf_putstring(ses.writepayload, SSH_SERVER_SIG_ALGS, strlen(SSH_SERVER_SIG_ALGS));
  ------------------
  |  |  101|      8|#define SSH_SERVER_SIG_ALGS "server-sig-algs"
  ------------------
              	buf_putstring(ses.writepayload, SSH_SERVER_SIG_ALGS, strlen(SSH_SERVER_SIG_ALGS));
  ------------------
  |  |  101|      8|#define SSH_SERVER_SIG_ALGS "server-sig-algs"
  ------------------
  270|      8|	buf_put_algolist_all(ses.writepayload, sigalgs, 1);
  271|       |	
  272|      8|	encrypt_packet();
  273|       |
  274|      8|	TRACE(("leave send_msg_ext_info"))
  275|      8|}

svr_getopts:
  134|      1|void svr_getopts(int argc, char ** argv) {
  135|       |
  136|      1|	unsigned int i, j;
  137|      1|	char ** next = NULL;
  138|      1|	int nextisport = 0;
  139|      1|	char* recv_window_arg = NULL;
  140|      1|	char* keepalive_arg = NULL;
  141|      1|	char* idle_timeout_arg = NULL;
  142|      1|	char* maxauthtries_arg = NULL;
  143|      1|	char* reexec_fd_arg = NULL;
  144|      1|	char* keyfile = NULL;
  145|      1|	char c;
  146|       |#if DROPBEAR_PLUGIN
  147|       |        char* pubkey_plugin = NULL;
  148|       |#endif
  149|       |
  150|       |
  151|       |	/* see printhelp() for options */
  152|      1|	svr_opts.bannerfile = NULL;
  153|      1|	svr_opts.banner = NULL;
  154|      1|	svr_opts.forced_command = NULL;
  155|      1|	svr_opts.forkbg = 1;
  156|      1|	svr_opts.norootlogin = 0;
  157|      1|#ifdef HAVE_GETGROUPLIST
  158|      1|	svr_opts.restrict_group = NULL;
  159|      1|	svr_opts.restrict_group_gid = 0;
  160|      1|#endif
  161|      1|	svr_opts.noauthpass = 0;
  162|      1|	svr_opts.norootpass = 0;
  163|      1|	svr_opts.allowblankpass = 0;
  164|      1|	svr_opts.multiauthmethod = 0;
  165|      1|	svr_opts.maxauthtries = MAX_AUTH_TRIES;
  ------------------
  |  |  428|      1|#define MAX_AUTH_TRIES 10
  ------------------
  166|      1|	svr_opts.inetdmode = 0;
  167|      1|	svr_opts.portcount = 0;
  168|      1|	svr_opts.hostkey = NULL;
  169|      1|	svr_opts.delay_hostkey = 0;
  170|      1|	svr_opts.pidfile = expand_homedir_path(DROPBEAR_PIDFILE);
  ------------------
  |  |  444|      1|#define DROPBEAR_PIDFILE "/var/run/dropbear.pid"
  ------------------
  171|      1|#if DROPBEAR_SVR_LOCALTCPFWD
  172|      1|	svr_opts.nolocaltcp = 0;
  173|      1|#endif
  174|      1|#if DROPBEAR_SVR_REMOTETCPFWD
  175|      1|	svr_opts.noremotetcp = 0;
  176|      1|#endif
  177|       |#if DROPBEAR_PLUGIN
  178|       |        svr_opts.pubkey_plugin = NULL;
  179|       |        svr_opts.pubkey_plugin_options = NULL;
  180|       |#endif
  181|      1|	svr_opts.pass_on_env = 0;
  182|      1|	svr_opts.reexec_childpipe = -1;
  183|       |
  184|       |#ifndef DISABLE_ZLIB
  185|       |	opts.compress_mode = DROPBEAR_COMPRESS_DELAYED;
  186|       |#endif 
  187|       |
  188|       |	/* not yet
  189|       |	opts.ipv4 = 1;
  190|       |	opts.ipv6 = 1;
  191|       |	*/
  192|      1|#if DO_MOTD
  193|      1|	svr_opts.domotd = 1;
  194|      1|#endif
  195|      1|#ifndef DISABLE_SYSLOG
  196|      1|	opts.usingsyslog = 1;
  197|      1|#endif
  198|      1|	opts.recv_window = DEFAULT_RECV_WINDOW;
  ------------------
  |  |  487|      1|#define DEFAULT_RECV_WINDOW 24576
  ------------------
  199|      1|	opts.keepalive_secs = DEFAULT_KEEPALIVE;
  ------------------
  |  |  503|      1|#define DEFAULT_KEEPALIVE 0
  ------------------
  200|      1|	opts.idle_timeout_secs = DEFAULT_IDLE_TIMEOUT;
  ------------------
  |  |  516|      1|#define DEFAULT_IDLE_TIMEOUT 0
  ------------------
  201|       |	
  202|      1|#if DROPBEAR_SVR_REMOTETCPFWD
  203|      1|	opts.listen_fwd_all = 0;
  204|      1|#endif
  205|      1|	opts.disable_ip_tos = 0;
  206|       |
  207|      2|	for (i = 1; i < (unsigned int)argc; i++) {
  ------------------
  |  Branch (207:14): [True: 1, False: 1]
  ------------------
  208|      1|		if (argv[i][0] != '-' || argv[i][1] == '\0')
  ------------------
  |  Branch (208:7): [True: 0, False: 1]
  |  Branch (208:28): [True: 0, False: 1]
  ------------------
  209|      0|			dropbear_exit("Invalid argument: %s", argv[i]);
  210|       |
  211|      2|		for (j = 1; (c = argv[i][j]) != '\0' && !next && !nextisport; j++) {
  ------------------
  |  Branch (211:15): [True: 1, False: 1]
  |  Branch (211:43): [True: 1, False: 0]
  |  Branch (211:52): [True: 1, False: 0]
  ------------------
  212|      1|			switch (c) {
  213|      0|				case 'b':
  ------------------
  |  Branch (213:5): [True: 0, False: 1]
  ------------------
  214|      0|					next = &svr_opts.bannerfile;
  215|      0|					break;
  216|      0|				case 'c':
  ------------------
  |  Branch (216:5): [True: 0, False: 1]
  ------------------
  217|      0|					next = &svr_opts.forced_command;
  218|      0|					break;
  219|      0|				case 'd':
  ------------------
  |  Branch (219:5): [True: 0, False: 1]
  ------------------
  220|      0|				case 'r':
  ------------------
  |  Branch (220:5): [True: 0, False: 1]
  ------------------
  221|      0|					next = &keyfile;
  222|      0|					break;
  223|      0|				case 'R':
  ------------------
  |  Branch (223:5): [True: 0, False: 1]
  ------------------
  224|      0|					svr_opts.delay_hostkey = 1;
  225|      0|					break;
  226|      0|				case 'F':
  ------------------
  |  Branch (226:5): [True: 0, False: 1]
  ------------------
  227|      0|					svr_opts.forkbg = 0;
  228|      0|					break;
  229|      0|#ifndef DISABLE_SYSLOG
  230|      1|				case 'E':
  ------------------
  |  Branch (230:5): [True: 1, False: 0]
  ------------------
  231|      1|					opts.usingsyslog = 0;
  232|      1|					break;
  233|      0|#endif
  234|      0|				case 'e':
  ------------------
  |  Branch (234:5): [True: 0, False: 1]
  ------------------
  235|      0|					svr_opts.pass_on_env = 1;
  236|      0|					break;
  237|       |
  238|      0|#if DROPBEAR_SVR_LOCALTCPFWD
  239|      0|				case 'j':
  ------------------
  |  Branch (239:5): [True: 0, False: 1]
  ------------------
  240|      0|					svr_opts.nolocaltcp = 1;
  241|      0|					break;
  242|      0|#endif
  243|      0|#if DROPBEAR_SVR_REMOTETCPFWD
  244|      0|				case 'k':
  ------------------
  |  Branch (244:5): [True: 0, False: 1]
  ------------------
  245|      0|					svr_opts.noremotetcp = 1;
  246|      0|					break;
  247|      0|				case 'a':
  ------------------
  |  Branch (247:5): [True: 0, False: 1]
  ------------------
  248|      0|					opts.listen_fwd_all = 1;
  249|      0|					break;
  250|      0|#endif
  251|      0|#if INETD_MODE
  252|      0|				case 'i':
  ------------------
  |  Branch (252:5): [True: 0, False: 1]
  ------------------
  253|      0|					svr_opts.inetdmode = 1;
  254|      0|					break;
  255|      0|#endif
  256|      0|#if DROPBEAR_DO_REEXEC && NON_INETD_MODE
  257|       |				/* For internal use by re-exec */
  258|      0|				case '2':
  ------------------
  |  Branch (258:5): [True: 0, False: 1]
  ------------------
  259|      0|					next = &reexec_fd_arg;
  260|      0|					break;
  261|      0|#endif
  262|      0|				case 'p':
  ------------------
  |  Branch (262:5): [True: 0, False: 1]
  ------------------
  263|      0|					nextisport = 1;
  264|      0|					break;
  265|      0|				case 'P':
  ------------------
  |  Branch (265:5): [True: 0, False: 1]
  ------------------
  266|      0|					next = &svr_opts.pidfile;
  267|      0|					break;
  268|      0|#if DO_MOTD
  269|       |				/* motd is displayed by default, -m turns it off */
  270|      0|				case 'm':
  ------------------
  |  Branch (270:5): [True: 0, False: 1]
  ------------------
  271|      0|					svr_opts.domotd = 0;
  272|      0|					break;
  273|      0|#endif
  274|      0|				case 'w':
  ------------------
  |  Branch (274:5): [True: 0, False: 1]
  ------------------
  275|      0|					svr_opts.norootlogin = 1;
  276|      0|					break;
  277|      0|#ifdef HAVE_GETGROUPLIST
  278|      0|				case 'G':
  ------------------
  |  Branch (278:5): [True: 0, False: 1]
  ------------------
  279|      0|					next = &svr_opts.restrict_group;
  280|      0|					break;
  281|      0|#endif
  282|      0|				case 'W':
  ------------------
  |  Branch (282:5): [True: 0, False: 1]
  ------------------
  283|      0|					next = &recv_window_arg;
  284|      0|					break;
  285|      0|				case 'K':
  ------------------
  |  Branch (285:5): [True: 0, False: 1]
  ------------------
  286|      0|					next = &keepalive_arg;
  287|      0|					break;
  288|      0|				case 'I':
  ------------------
  |  Branch (288:5): [True: 0, False: 1]
  ------------------
  289|      0|					next = &idle_timeout_arg;
  290|      0|					break;
  291|      0|				case 'T':
  ------------------
  |  Branch (291:5): [True: 0, False: 1]
  ------------------
  292|      0|					next = &maxauthtries_arg;
  293|      0|					break;
  294|      0|#if DROPBEAR_SVR_PASSWORD_AUTH || DROPBEAR_SVR_PAM_AUTH
  295|      0|				case 's':
  ------------------
  |  Branch (295:5): [True: 0, False: 1]
  ------------------
  296|      0|					svr_opts.noauthpass = 1;
  297|      0|					break;
  298|      0|				case 'g':
  ------------------
  |  Branch (298:5): [True: 0, False: 1]
  ------------------
  299|      0|					svr_opts.norootpass = 1;
  300|      0|					break;
  301|      0|				case 'B':
  ------------------
  |  Branch (301:5): [True: 0, False: 1]
  ------------------
  302|      0|					svr_opts.allowblankpass = 1;
  303|      0|					break;
  304|      0|				case 't':
  ------------------
  |  Branch (304:5): [True: 0, False: 1]
  ------------------
  305|      0|					svr_opts.multiauthmethod = 1;
  306|      0|					break;
  307|      0|#endif
  308|      0|				case 'h':
  ------------------
  |  Branch (308:5): [True: 0, False: 1]
  ------------------
  309|      0|					printhelp(argv[0]);
  310|      0|					exit(EXIT_SUCCESS);
  311|      0|					break;
  312|      0|				case 'u':
  ------------------
  |  Branch (312:5): [True: 0, False: 1]
  ------------------
  313|       |					/* backwards compatibility with old urandom option */
  314|      0|					break;
  315|       |#if DROPBEAR_PLUGIN
  316|       |                                case 'A':
  317|       |                                        next = &pubkey_plugin;
  318|       |                                        break;
  319|       |#endif
  320|       |#if DEBUG_TRACE
  321|       |				case 'v':
  322|       |					debug_trace++;
  323|       |					break;
  324|       |#endif
  325|      0|				case 'V':
  ------------------
  |  Branch (325:5): [True: 0, False: 1]
  ------------------
  326|      0|					print_version();
  327|      0|					exit(EXIT_SUCCESS);
  328|      0|					break;
  329|      0|				case 'z':
  ------------------
  |  Branch (329:5): [True: 0, False: 1]
  ------------------
  330|      0|					opts.disable_ip_tos = 1;
  331|      0|					break;
  332|      0|				default:
  ------------------
  |  Branch (332:5): [True: 0, False: 1]
  ------------------
  333|      0|					fprintf(stderr, "Invalid option -%c\n", c);
  ------------------
  |  |  100|      0|#define stderr (fuzz.fake_stderr)
  ------------------
  334|      0|					printhelp(argv[0]);
  335|      0|					exit(EXIT_FAILURE);
  336|      0|					break;
  337|      1|			}
  338|      1|		}
  339|       |
  340|      1|		if (!next && !nextisport)
  ------------------
  |  Branch (340:7): [True: 1, False: 0]
  |  Branch (340:16): [True: 1, False: 0]
  ------------------
  341|      1|			continue;
  342|       |
  343|      0|		if (c == '\0') {
  ------------------
  |  Branch (343:7): [True: 0, False: 0]
  ------------------
  344|      0|			i++;
  345|      0|			j = 0;
  346|      0|			if (!argv[i]) {
  ------------------
  |  Branch (346:8): [True: 0, False: 0]
  ------------------
  347|      0|				dropbear_exit("Missing argument");
  348|      0|			}
  349|      0|		}
  350|       |
  351|      0|		if (nextisport) {
  ------------------
  |  Branch (351:7): [True: 0, False: 0]
  ------------------
  352|      0|			addportandaddress(&argv[i][j]);
  353|      0|			nextisport = 0;
  354|      0|		} else if (next) {
  ------------------
  |  Branch (354:14): [True: 0, False: 0]
  ------------------
  355|      0|			*next = &argv[i][j];
  356|      0|			if (*next == NULL) {
  ------------------
  |  Branch (356:8): [True: 0, False: 0]
  ------------------
  357|      0|				dropbear_exit("Invalid null argument");
  358|      0|			}
  359|      0|			next = NULL;
  360|       |
  361|      0|			if (keyfile) {
  ------------------
  |  Branch (361:8): [True: 0, False: 0]
  ------------------
  362|      0|				addhostkey(keyfile);
  363|      0|				keyfile = NULL;
  364|      0|			}
  365|      0|		}
  366|      0|	}
  367|       |
  368|       |	/* Set up listening ports */
  369|      1|	if (svr_opts.portcount == 0) {
  ------------------
  |  Branch (369:6): [True: 1, False: 0]
  ------------------
  370|      1|		svr_opts.ports[0] = m_strdup(DROPBEAR_DEFPORT);
  ------------------
  |  |   23|      1|#define DROPBEAR_DEFPORT "22"
  ------------------
  371|      1|		svr_opts.addresses[0] = m_strdup(DROPBEAR_DEFADDRESS);
  ------------------
  |  |   28|      1|#define DROPBEAR_DEFADDRESS ""
  ------------------
  372|      1|		svr_opts.portcount = 1;
  373|      1|	}
  374|       |
  375|      1|	if (svr_opts.bannerfile) {
  ------------------
  |  Branch (375:6): [True: 0, False: 1]
  ------------------
  376|      0|		struct stat buf;
  377|      0|		if (stat(svr_opts.bannerfile, &buf) != 0) {
  ------------------
  |  Branch (377:7): [True: 0, False: 0]
  ------------------
  378|      0|			dropbear_exit("Error opening banner file '%s'",
  379|      0|					svr_opts.bannerfile);
  380|      0|		}
  381|       |		
  382|      0|		if (buf.st_size > MAX_BANNER_SIZE) {
  ------------------
  |  |   68|      0|#define MAX_BANNER_SIZE 2050 /* this is 25*80 chars, any more is foolish */
  ------------------
  |  Branch (382:7): [True: 0, False: 0]
  ------------------
  383|      0|			dropbear_exit("Banner file too large, max is %d bytes",
  384|      0|					MAX_BANNER_SIZE);
  ------------------
  |  |   68|      0|#define MAX_BANNER_SIZE 2050 /* this is 25*80 chars, any more is foolish */
  ------------------
  385|      0|		}
  386|       |
  387|      0|		svr_opts.banner = buf_new(buf.st_size);
  388|      0|		if (buf_readfile(svr_opts.banner, svr_opts.bannerfile)!=DROPBEAR_SUCCESS) {
  ------------------
  |  |  102|      0|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (388:7): [True: 0, False: 0]
  ------------------
  389|      0|			dropbear_exit("Error reading banner file '%s'",
  390|      0|					svr_opts.bannerfile);
  391|      0|		}
  392|      0|		buf_setpos(svr_opts.banner, 0);
  393|      0|	}
  394|       |
  395|      1|#ifdef HAVE_GETGROUPLIST
  396|      1|	if (svr_opts.restrict_group) {
  ------------------
  |  Branch (396:6): [True: 0, False: 1]
  ------------------
  397|      0|		struct group *restrictedgroup = getgrnam(svr_opts.restrict_group);
  398|       |
  399|      0|		if (restrictedgroup){
  ------------------
  |  Branch (399:7): [True: 0, False: 0]
  ------------------
  400|      0|			svr_opts.restrict_group_gid = restrictedgroup->gr_gid;
  401|      0|		} else {
  402|      0|			dropbear_exit("Cannot restrict logins to group '%s' as the group does not exist", svr_opts.restrict_group);
  403|      0|		}
  404|      0|	}
  405|      1|#endif
  406|       |
  407|      1|	if (recv_window_arg) {
  ------------------
  |  Branch (407:6): [True: 0, False: 1]
  ------------------
  408|      0|		parse_recv_window(recv_window_arg);
  409|      0|	}
  410|       |
  411|      1|	if (maxauthtries_arg) {
  ------------------
  |  Branch (411:6): [True: 0, False: 1]
  ------------------
  412|      0|		unsigned int val = 0;
  413|      0|		if (m_str_to_uint(maxauthtries_arg, &val) == DROPBEAR_FAILURE 
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (413:7): [True: 0, False: 0]
  ------------------
  414|      0|			|| val == 0) {
  ------------------
  |  Branch (414:7): [True: 0, False: 0]
  ------------------
  415|      0|			dropbear_exit("Bad maxauthtries '%s'", maxauthtries_arg);
  416|      0|		}
  417|      0|		svr_opts.maxauthtries = val;
  418|      0|	}
  419|       |
  420|       |
  421|      1|	if (keepalive_arg) {
  ------------------
  |  Branch (421:6): [True: 0, False: 1]
  ------------------
  422|      0|		unsigned int val;
  423|      0|		if (m_str_to_uint(keepalive_arg, &val) == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (423:7): [True: 0, False: 0]
  ------------------
  424|      0|			dropbear_exit("Bad keepalive '%s'", keepalive_arg);
  425|      0|		}
  426|      0|		opts.keepalive_secs = val;
  427|      0|	}
  428|       |
  429|      1|	if (idle_timeout_arg) {
  ------------------
  |  Branch (429:6): [True: 0, False: 1]
  ------------------
  430|      0|		unsigned int val;
  431|      0|		if (m_str_to_uint(idle_timeout_arg, &val) == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (431:7): [True: 0, False: 0]
  ------------------
  432|      0|			dropbear_exit("Bad idle_timeout '%s'", idle_timeout_arg);
  433|      0|		}
  434|      0|		opts.idle_timeout_secs = val;
  435|      0|	}
  436|       |
  437|      1|	if (svr_opts.forced_command) {
  ------------------
  |  Branch (437:6): [True: 0, False: 1]
  ------------------
  438|      0|		dropbear_log(LOG_INFO, "Forced command set to '%s'", svr_opts.forced_command);
  439|      0|	}
  440|       |
  441|      1|	if (reexec_fd_arg) {
  ------------------
  |  Branch (441:6): [True: 0, False: 1]
  ------------------
  442|      0|		if (m_str_to_uint(reexec_fd_arg, &svr_opts.reexec_childpipe) == DROPBEAR_FAILURE
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (442:7): [True: 0, False: 0]
  ------------------
  443|      0|			|| svr_opts.reexec_childpipe < 0) {
  ------------------
  |  Branch (443:7): [True: 0, False: 0]
  ------------------
  444|      0|			dropbear_exit("Bad -2");
  445|      0|		}
  446|      0|	}
  447|       |
  448|      1|#if INETD_MODE
  449|      1|	if (svr_opts.inetdmode && (
  ------------------
  |  Branch (449:6): [True: 0, False: 1]
  |  Branch (449:28): [True: 0, False: 0]
  ------------------
  450|      0|		opts.usingsyslog == 0
  451|       |#if DEBUG_TRACE
  452|       |		|| debug_trace
  453|       |#endif
  454|      0|		)) {
  455|       |		/* log output goes to stderr which would get sent over the inetd network socket */
  456|      0|		dropbear_exit("Dropbear inetd mode is incompatible with debug -v or non-syslog");
  457|      0|	}
  458|      1|#endif
  459|       |
  460|      1|	if (svr_opts.multiauthmethod && svr_opts.noauthpass) {
  ------------------
  |  Branch (460:6): [True: 0, False: 1]
  |  Branch (460:34): [True: 0, False: 0]
  ------------------
  461|      0|		dropbear_exit("-t and -s are incompatible");
  462|      0|	}
  463|       |
  464|       |#if DROPBEAR_PLUGIN
  465|       |	if (pubkey_plugin) {
  466|       |		svr_opts.pubkey_plugin = m_strdup(pubkey_plugin);
  467|       |		char *args = strchr(svr_opts.pubkey_plugin, ',');
  468|       |		if (args) {
  469|       |			*args='\0';
  470|       |			++args;
  471|       |		}
  472|       |		svr_opts.pubkey_plugin_options = args;
  473|       |	}
  474|       |#endif
  475|      1|}

recv_msg_service_request:
   37|    672|void recv_msg_service_request() {
   38|       |
   39|    672|	char * name;
   40|    672|	unsigned int len;
   41|       |
   42|    672|	TRACE(("enter recv_msg_service_request"))
   43|       |
   44|    672|	name = buf_getstring(ses.payload, &len);
   45|       |
   46|       |	/* ssh-userauth */
   47|    672|	if (len == SSH_SERVICE_USERAUTH_LEN && 
  ------------------
  |  |  105|  1.34k|#define SSH_SERVICE_USERAUTH_LEN 12
  ------------------
  |  Branch (47:6): [True: 96, False: 576]
  ------------------
   48|    672|			strncmp(SSH_SERVICE_USERAUTH, name, len) == 0) {
  ------------------
  |  |  104|     96|#define SSH_SERVICE_USERAUTH "ssh-userauth"
  ------------------
  |  Branch (48:4): [True: 96, False: 0]
  ------------------
   49|       |
   50|     96|		send_msg_service_accept(name, len);
   51|     96|		m_free(name);
  ------------------
  |  |   24|     96|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
   52|     96|		TRACE(("leave recv_msg_service_request: done ssh-userauth"))
   53|     96|		return;
   54|     96|	}
   55|       |
   56|       |	/* ssh-connection */
   57|    576|	if (len == SSH_SERVICE_CONNECTION_LEN &&
  ------------------
  |  |  107|  1.15k|#define SSH_SERVICE_CONNECTION_LEN 14
  ------------------
  |  Branch (57:6): [True: 567, False: 9]
  ------------------
   58|    576|			(strncmp(SSH_SERVICE_CONNECTION, name, len) == 0)) {
  ------------------
  |  |  106|    567|#define SSH_SERVICE_CONNECTION "ssh-connection"
  ------------------
  |  Branch (58:4): [True: 566, False: 1]
  ------------------
   59|    566|		if (ses.authstate.authdone != 1) {
  ------------------
  |  Branch (59:7): [True: 0, False: 566]
  ------------------
   60|      0|			dropbear_exit("Request for connection before auth");
   61|      0|		}
   62|       |
   63|    566|		send_msg_service_accept(name, len);
   64|    566|		m_free(name);
  ------------------
  |  |   24|    566|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
   65|    566|		TRACE(("leave recv_msg_service_request: done ssh-connection"))
   66|    566|		return;
   67|    566|	}
   68|       |
   69|     10|	m_free(name);
  ------------------
  |  |   24|     10|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
   70|       |	/* TODO this should be a MSG_DISCONNECT */
   71|     10|	dropbear_exit("Unrecognised SSH_MSG_SERVICE_REQUEST");
   72|       |
   73|       |
   74|    576|}
svr-service.c:send_msg_service_accept:
   76|    662|static void send_msg_service_accept(const char *name, int len) {
   77|       |
   78|    662|	TRACE(("accepting service %s", name))
   79|       |
   80|    662|	CHECKCLEARTOWRITE();
   81|       |
   82|    662|	buf_putbyte(ses.writepayload, SSH_MSG_SERVICE_ACCEPT);
  ------------------
  |  |   34|    662|#define SSH_MSG_SERVICE_ACCEPT         6
  ------------------
   83|    662|	buf_putstring(ses.writepayload, name, len);
   84|       |
   85|    662|	encrypt_packet();
   86|       |
   87|    662|}

svr_session:
  105|  1.49k|void svr_session(int sock, int childpipe) {
  106|  1.49k|	char *host, *port;
  107|  1.49k|	size_t len;
  108|       |
  109|  1.49k|	common_session_init(sock, sock);
  110|       |
  111|       |	/* Initialise server specific parts of the session */
  112|  1.49k|	svr_ses.childpipe = childpipe;
  113|       |#if DROPBEAR_VFORK
  114|       |	svr_ses.server_pid = getpid();
  115|       |#endif
  116|       |
  117|       |	/* for logging the remote address */
  118|  1.49k|	get_socket_address(ses.sock_in, NULL, NULL, &host, &port, 0);
  119|  1.49k|	len = strlen(host) + strlen(port) + 2;
  120|  1.49k|	svr_ses.addrstring = m_malloc(len);
  121|  1.49k|	snprintf(svr_ses.addrstring, len, "%s:%s", host, port);
  122|  1.49k|	m_free(host);
  ------------------
  |  |   24|  1.49k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  123|  1.49k|	m_free(port);
  ------------------
  |  |   24|  1.49k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  124|       |
  125|       |#if DROPBEAR_PLUGIN
  126|       |        /* Initializes the PLUGIN Plugin */
  127|       |        svr_ses.plugin_handle = NULL;
  128|       |        svr_ses.plugin_instance = NULL;
  129|       |        if (svr_opts.pubkey_plugin) {
  130|       |#if DEBUG_TRACE
  131|       |            const int verbose = debug_trace;
  132|       |#else
  133|       |            const int verbose = 0;
  134|       |#endif
  135|       |            PubkeyExtPlugin_newFn  pluginConstructor;
  136|       |
  137|       |            /* RTLD_NOW: fails if not all the symbols are resolved now. Better fail now than at run-time */
  138|       |            svr_ses.plugin_handle = dlopen(svr_opts.pubkey_plugin, RTLD_NOW);
  139|       |            if (svr_ses.plugin_handle == NULL) {
  140|       |                dropbear_exit("failed to load external pubkey plugin '%s': %s", svr_opts.pubkey_plugin, dlerror());
  141|       |            }
  142|       |            pluginConstructor = (PubkeyExtPlugin_newFn)dlsym(svr_ses.plugin_handle, DROPBEAR_PUBKEY_PLUGIN_FNNAME_NEW);
  143|       |            if (!pluginConstructor) {
  144|       |                dropbear_exit("plugin constructor method not found in external pubkey plugin");
  145|       |            }
  146|       |
  147|       |            /* Create an instance of the plugin */
  148|       |            svr_ses.plugin_instance = pluginConstructor(verbose, svr_opts.pubkey_plugin_options, svr_ses.addrstring);
  149|       |            if (svr_ses.plugin_instance == NULL) {
  150|       |                dropbear_exit("external plugin initialization failed");
  151|       |            }
  152|       |            /* Check if the plugin is compatible */
  153|       |            if ( (svr_ses.plugin_instance->api_version[0] != DROPBEAR_PLUGIN_VERSION_MAJOR) ||
  154|       |                 (svr_ses.plugin_instance->api_version[1] < DROPBEAR_PLUGIN_VERSION_MINOR) ) {
  155|       |                dropbear_exit("plugin version check failed: "
  156|       |                              "Dropbear=%d.%d, plugin=%d.%d",
  157|       |                        DROPBEAR_PLUGIN_VERSION_MAJOR, DROPBEAR_PLUGIN_VERSION_MINOR,
  158|       |                        svr_ses.plugin_instance->api_version[0], svr_ses.plugin_instance->api_version[1]);
  159|       |            }
  160|       |            if (svr_ses.plugin_instance->api_version[1] > DROPBEAR_PLUGIN_VERSION_MINOR) {
  161|       |                dropbear_log(LOG_WARNING, "plugin API newer than dropbear API: "
  162|       |                              "Dropbear=%d.%d, plugin=%d.%d",
  163|       |                        DROPBEAR_PLUGIN_VERSION_MAJOR, DROPBEAR_PLUGIN_VERSION_MINOR,
  164|       |                        svr_ses.plugin_instance->api_version[0], svr_ses.plugin_instance->api_version[1]);
  165|       |            }
  166|       |            dropbear_log(LOG_INFO, "successfully loaded and initialized pubkey plugin '%s'", svr_opts.pubkey_plugin);
  167|       |        }
  168|       |#endif
  169|       |
  170|  1.49k|	svr_authinitialise();
  171|  1.49k|	chaninitialise(svr_chantypes);
  172|  1.49k|	svr_chansessinitialise();
  173|  1.49k|	svr_algos_initialise();
  174|       |
  175|  1.49k|	get_socket_address(ses.sock_in, NULL, NULL, 
  176|  1.49k|			&svr_ses.remotehost, NULL, 1);
  177|       |
  178|       |	/* set up messages etc */
  179|  1.49k|	ses.remoteclosed = svr_remoteclosed;
  180|  1.49k|	ses.extra_session_cleanup = svr_session_cleanup;
  181|       |
  182|       |	/* packet handlers */
  183|  1.49k|	ses.packettypes = svr_packettypes;
  184|       |
  185|  1.49k|	ses.isserver = 1;
  186|       |
  187|       |	/* We're ready to go now */
  188|  1.49k|	ses.init_done = 1;
  189|       |
  190|       |	/* exchange identification, version etc */
  191|  1.49k|	send_session_identification();
  192|       |	
  193|  1.49k|	kexfirstinitialise(); /* initialise the kex state */
  194|       |
  195|       |	/* start off with key exchange */
  196|  1.49k|	send_msg_kexinit();
  197|       |
  198|  1.49k|#if DROPBEAR_FUZZ
  199|  1.49k|    if (fuzz.fuzzing) {
  ------------------
  |  Branch (199:9): [True: 1.49k, False: 0]
  ------------------
  200|  1.49k|        fuzz_svr_hook_preloop();
  201|  1.49k|    }
  202|  1.49k|#endif
  203|       |
  204|       |	/* Run the main for-loop. */
  205|  1.49k|	session_loop(svr_chansess_checksignal);
  206|       |
  207|       |	/* Not reached */
  208|       |
  209|  1.49k|}
svr_dropbear_exit:
  212|  1.49k|void svr_dropbear_exit(int exitcode, const char* format, va_list param) {
  213|  1.49k|	char exitmsg[150];
  214|  1.49k|	char fullmsg[300];
  215|  1.49k|	char fromaddr[60];
  216|  1.49k|	int i;
  217|  1.49k|	int add_delay = 0;
  218|       |
  219|       |#if DROPBEAR_PLUGIN
  220|       |	if ((ses.plugin_session != NULL)) {
  221|       |		svr_ses.plugin_instance->delete_session(ses.plugin_session);
  222|       |	}
  223|       |	ses.plugin_session = NULL;
  224|       |	svr_opts.pubkey_plugin_options = NULL;
  225|       |	m_free(svr_opts.pubkey_plugin);
  226|       |#endif
  227|       |
  228|       |	/* Render the formatted exit message */
  229|  1.49k|	vsnprintf(exitmsg, sizeof(exitmsg), format, param);
  230|       |
  231|       |	/* svr_ses.addrstring may not be set for some early exits, or for
  232|       |	the listener process */
  233|  1.49k|	fromaddr[0] = '\0';
  234|  1.49k|	if (svr_ses.addrstring) {
  ------------------
  |  Branch (234:6): [True: 1.49k, False: 0]
  ------------------
  235|  1.49k|	    snprintf(fromaddr, sizeof(fromaddr), " from <%s>", svr_ses.addrstring);
  236|  1.49k|    }
  237|       |
  238|       |	/* Add the prefix depending on session/auth state */
  239|  1.49k|	if (!ses.init_done) {
  ------------------
  |  Branch (239:6): [True: 0, False: 1.49k]
  ------------------
  240|       |		/* before session init */
  241|      0|		snprintf(fullmsg, sizeof(fullmsg), "Early exit%s: %s", fromaddr, exitmsg);
  242|  1.49k|	} else if (ses.authstate.authdone) {
  ------------------
  |  Branch (242:13): [True: 1.49k, False: 0]
  ------------------
  243|       |		/* user has authenticated */
  244|  1.49k|		snprintf(fullmsg, sizeof(fullmsg),
  245|  1.49k|				"Exit (%s)%s: %s", 
  246|  1.49k|				ses.authstate.pw_name, fromaddr, exitmsg);
  247|  1.49k|	} else if (ses.authstate.pw_name) {
  ------------------
  |  Branch (247:13): [True: 0, False: 0]
  ------------------
  248|       |		/* we have a potential user */
  249|      0|		snprintf(fullmsg, sizeof(fullmsg), 
  250|      0|				"Exit before auth%s: (user '%s', %u fails): %s",
  251|      0|				fromaddr, ses.authstate.pw_name, ses.authstate.failcount, exitmsg);
  252|      0|		add_delay = 1;
  253|      0|	} else {
  254|       |		/* before userauth */
  255|      0|		snprintf(fullmsg, sizeof(fullmsg), "Exit before auth%s: %s", fromaddr, exitmsg);
  256|      0|		add_delay = 1;
  257|      0|	}
  258|       |
  259|  1.49k|	dropbear_log(LOG_INFO, "%s", fullmsg);
  260|       |
  261|       |	/* To make it harder for attackers, introduce a delay to keep an
  262|       |	 * unauthenticated session open a bit longer, thus blocking a connection
  263|       |	 * slot until after the delay. Without this, while there is a limit on
  264|       |	 * the amount of attempts an attacker can make at the same time
  265|       |	 * (MAX_UNAUTH_PER_IP), the time taken by dropbear to handle one attempt
  266|       |	 * is still short and thus for each of the allowed parallel attempts
  267|       |	 * many attempts can be chained one after the other. The attempt rate is
  268|       |	 * then:
  269|       |	 *     "MAX_UNAUTH_PER_IP / <process time of one attempt>".
  270|       |	 * With the delay, this rate becomes:
  271|       |	 *     "MAX_UNAUTH_PER_IP / UNAUTH_CLOSE_DELAY".
  272|       |	 */
  273|  1.49k|	if ((add_delay != 0) && (UNAUTH_CLOSE_DELAY > 0)) {
  ------------------
  |  |  436|      0|#define UNAUTH_CLOSE_DELAY 0
  ------------------
  |  Branch (273:6): [True: 0, False: 1.49k]
  |  Branch (273:26): [Folded - Ignored]
  ------------------
  274|      0|		TRACE(("svr_dropbear_exit: start delay of %d seconds", UNAUTH_CLOSE_DELAY));
  275|      0|		sleep(UNAUTH_CLOSE_DELAY);
  ------------------
  |  |  436|      0|#define UNAUTH_CLOSE_DELAY 0
  ------------------
  276|      0|		TRACE(("svr_dropbear_exit: end delay of %d seconds", UNAUTH_CLOSE_DELAY));
  277|      0|	}
  278|       |
  279|       |#if DROPBEAR_VFORK
  280|       |	/* For uclinux only the main server process should cleanup - we don't want
  281|       |	 * forked children doing that */
  282|       |	if (svr_ses.server_pid == getpid())
  283|       |#endif
  284|  1.49k|	{
  285|       |		/* must be after we've done with username etc */
  286|  1.49k|		session_cleanup();
  287|  1.49k|	}
  288|       |
  289|  1.49k|#if DROPBEAR_FUZZ
  290|       |	/* longjmp before cleaning up svr_opts */
  291|  1.49k|    if (fuzz.do_jmp) {
  ------------------
  |  Branch (291:9): [True: 1.49k, False: 0]
  ------------------
  292|  1.49k|        longjmp(fuzz.jmp, 1);
  293|  1.49k|    }
  294|      0|#endif
  295|       |
  296|      0|	if (svr_opts.hostkey) {
  ------------------
  |  Branch (296:6): [True: 0, False: 0]
  ------------------
  297|      0|		sign_key_free(svr_opts.hostkey);
  298|      0|		svr_opts.hostkey = NULL;
  299|      0|	}
  300|      0|	for (i = 0; i < DROPBEAR_MAX_PORTS; i++) {
  ------------------
  |  |   80|      0|#define DROPBEAR_MAX_PORTS 10 /* max number of ports which can be specified,
  ------------------
  |  Branch (300:14): [True: 0, False: 0]
  ------------------
  301|      0|		m_free(svr_opts.addresses[i]);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  302|      0|		m_free(svr_opts.ports[i]);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  303|      0|	}
  304|       |
  305|       |    
  306|      0|	exit(exitcode);
  307|       |
  308|  1.49k|}
svr-session.c:svr_session_cleanup:
   83|  1.49k|svr_session_cleanup(void) {
   84|       |	/* free potential public key options */
   85|  1.49k|	svr_pubkey_options_cleanup();
   86|       |
   87|  1.49k|	m_free(svr_ses.addrstring);
  ------------------
  |  |   24|  1.49k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
   88|  1.49k|	m_free(svr_ses.remotehost);
  ------------------
  |  |   24|  1.49k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
   89|  1.49k|	m_free(svr_ses.childpids);
  ------------------
  |  |   24|  1.49k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
   90|  1.49k|	svr_ses.childpidsize = 0;
   91|       |
   92|       |#if DROPBEAR_PLUGIN
   93|       |        if (svr_ses.plugin_handle != NULL) {
   94|       |            if (svr_ses.plugin_instance) {
   95|       |                svr_ses.plugin_instance->delete_plugin(svr_ses.plugin_instance);
   96|       |                svr_ses.plugin_instance = NULL;
   97|       |            }
   98|       |
   99|       |            dlclose(svr_ses.plugin_handle);
  100|       |            svr_ses.plugin_handle = NULL;
  101|       |        }
  102|       |#endif
  103|  1.49k|}
svr-session.c:svr_remoteclosed:
  348|  1.03k|static void svr_remoteclosed() {
  349|       |
  350|  1.03k|	m_close(ses.sock_in);
  351|  1.03k|	if (ses.sock_in != ses.sock_out) {
  ------------------
  |  Branch (351:6): [True: 0, False: 1.03k]
  ------------------
  352|      0|		m_close(ses.sock_out);
  353|      0|	}
  354|  1.03k|	ses.sock_in = -1;
  355|  1.03k|	ses.sock_out = -1;
  356|  1.03k|	dropbear_close("Exited normally");
  357|       |
  358|  1.03k|}
svr-session.c:svr_algos_initialise:
  360|  1.49k|static void svr_algos_initialise(void) {
  361|  1.49k|	algo_type *algo;
  362|  14.9k|	for (algo = sshkex; algo->name; algo++) {
  ------------------
  |  Branch (362:22): [True: 13.4k, False: 1.49k]
  ------------------
  363|       |#if DROPBEAR_DH_GROUP1 && DROPBEAR_DH_GROUP1_CLIENTONLY
  364|       |		if (strcmp(algo->name, "diffie-hellman-group1-sha1") == 0) {
  365|       |			algo->usable = 0;
  366|       |		}
  367|       |#endif
  368|  13.4k|#if DROPBEAR_EXT_INFO
  369|  13.4k|		if (strcmp(algo->name, SSH_EXT_INFO_C) == 0) {
  ------------------
  |  |  100|  13.4k|#define SSH_EXT_INFO_C "ext-info-c"
  ------------------
  |  Branch (369:7): [True: 1.49k, False: 11.9k]
  ------------------
  370|  1.49k|			algo->usable = 0;
  371|  1.49k|		}
  372|  13.4k|#endif
  373|  13.4k|	}
  374|  1.49k|}

recv_msg_global_request_remotetcp:
   73|  2.22k|void recv_msg_global_request_remotetcp() {
   74|       |
   75|  2.22k|	char* reqname = NULL;
   76|  2.22k|	unsigned int namelen;
   77|  2.22k|	unsigned int wantreply = 0;
   78|  2.22k|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  103|  2.22k|#define DROPBEAR_FAILURE -1
  ------------------
   79|       |
   80|  2.22k|	TRACE(("enter recv_msg_global_request_remotetcp"))
   81|       |
   82|  2.22k|	if (svr_opts.noremotetcp || !svr_pubkey_allows_tcpfwd()) {
  ------------------
  |  Branch (82:6): [True: 0, False: 2.22k]
  |  Branch (82:30): [True: 0, False: 2.22k]
  ------------------
   83|      0|		TRACE(("leave recv_msg_global_request_remotetcp: remote tcp forwarding disabled"))
   84|      0|		goto out;
   85|      0|	}
   86|       |
   87|  2.22k|	reqname = buf_getstring(ses.payload, &namelen);
   88|  2.22k|	wantreply = buf_getbool(ses.payload);
   89|       |
   90|  2.22k|	if (namelen > MAX_NAME_LEN) {
  ------------------
  |  |  205|  2.22k|#define MAX_NAME_LEN 64 /* maximum length of a protocol name, isn't
  ------------------
  |  Branch (90:6): [True: 65, False: 2.16k]
  ------------------
   91|     65|		TRACE(("name len is wrong: %d", namelen))
   92|     65|		goto out;
   93|     65|	}
   94|       |
   95|  2.16k|	if (strcmp("tcpip-forward", reqname) == 0) {
  ------------------
  |  Branch (95:6): [True: 1.63k, False: 525]
  ------------------
   96|  1.63k|		int allocated_listen_port = 0;
   97|  1.63k|		ret = svr_remotetcpreq(&allocated_listen_port);
   98|       |		/* client expects-port-number-to-make-use-of-server-allocated-ports */
   99|  1.63k|		if (DROPBEAR_SUCCESS == ret) {
  ------------------
  |  |  102|  1.63k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (99:7): [True: 0, False: 1.63k]
  ------------------
  100|      0|			CHECKCLEARTOWRITE();
  101|      0|			buf_putbyte(ses.writepayload, SSH_MSG_REQUEST_SUCCESS);
  ------------------
  |  |   64|      0|#define SSH_MSG_REQUEST_SUCCESS                 81
  ------------------
  102|      0|			buf_putint(ses.writepayload, allocated_listen_port);
  103|      0|			encrypt_packet();
  104|      0|			wantreply = 0; /* avoid out: below sending another reply */
  105|      0|		}
  106|  1.63k|	} else if (strcmp("cancel-tcpip-forward", reqname) == 0) {
  ------------------
  |  Branch (106:13): [True: 109, False: 416]
  ------------------
  107|    109|		ret = svr_cancelremotetcp();
  108|    416|	} else {
  109|    416|		TRACE(("reqname isn't tcpip-forward: '%s'", reqname))
  110|    416|	}
  111|       |
  112|  2.22k|out:
  113|  2.22k|	if (wantreply) {
  ------------------
  |  Branch (113:6): [True: 757, False: 1.46k]
  ------------------
  114|    757|		if (ret == DROPBEAR_SUCCESS) {
  ------------------
  |  |  102|    757|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (114:7): [True: 0, False: 757]
  ------------------
  115|      0|			send_msg_request_success();
  116|    757|		} else {
  117|    757|			send_msg_request_failure();
  118|    757|		}
  119|    757|	}
  120|       |
  121|  2.22k|	m_free(reqname);
  ------------------
  |  |   24|  2.22k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  122|       |
  123|  2.22k|	TRACE(("leave recv_msg_global_request"))
  124|  2.22k|}
svr-tcpfwd.c:svr_cancelremotetcp:
  136|    109|static int svr_cancelremotetcp() {
  137|       |
  138|    109|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  103|    109|#define DROPBEAR_FAILURE -1
  ------------------
  139|    109|	char * bindaddr = NULL;
  140|    109|	unsigned int addrlen;
  141|    109|	unsigned int port;
  142|    109|	struct Listener * listener = NULL;
  143|    109|	struct TCPListener tcpinfo;
  144|       |
  145|    109|	TRACE(("enter cancelremotetcp"))
  146|       |
  147|    109|	bindaddr = buf_getstring(ses.payload, &addrlen);
  148|    109|	if (addrlen > MAX_HOST_LEN) {
  ------------------
  |  |   78|    109|#define MAX_HOST_LEN 254 /* max hostname len for tcp fwding */
  ------------------
  |  Branch (148:6): [True: 37, False: 72]
  ------------------
  149|     37|		TRACE(("addr len too long: %d", addrlen))
  150|     37|		goto out;
  151|     37|	}
  152|       |
  153|     72|	port = buf_getint(ses.payload);
  154|       |
  155|     72|	tcpinfo.sendaddr = NULL;
  156|     72|	tcpinfo.sendport = 0;
  157|     72|	tcpinfo.listenaddr = bindaddr;
  158|     72|	tcpinfo.listenport = port;
  159|     72|	listener = get_listener(CHANNEL_ID_TCPFORWARDED, &tcpinfo, matchtcp);
  ------------------
  |  |   76|     72|#define CHANNEL_ID_TCPFORWARDED 0x43612c67
  ------------------
  160|     72|	if (listener) {
  ------------------
  |  Branch (160:6): [True: 0, False: 72]
  ------------------
  161|      0|		remove_listener( listener );
  162|      0|		ret = DROPBEAR_SUCCESS;
  ------------------
  |  |  102|      0|#define DROPBEAR_SUCCESS 0
  ------------------
  163|      0|	}
  164|       |
  165|    105|out:
  166|    105|	m_free(bindaddr);
  ------------------
  |  |   24|    105|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  167|    105|	TRACE(("leave cancelremotetcp"))
  168|    105|	return ret;
  169|     72|}
svr-tcpfwd.c:svr_remotetcpreq:
  171|  1.63k|static int svr_remotetcpreq(int *allocated_listen_port) {
  172|       |
  173|  1.63k|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  103|  1.63k|#define DROPBEAR_FAILURE -1
  ------------------
  174|  1.63k|	char * request_addr = NULL;
  175|  1.63k|	unsigned int addrlen;
  176|  1.63k|	struct TCPListener *tcpinfo = NULL;
  177|  1.63k|	unsigned int port;
  178|  1.63k|	struct Listener *listener = NULL;
  179|       |
  180|  1.63k|	TRACE(("enter remotetcpreq"))
  181|       |
  182|  1.63k|	request_addr = buf_getstring(ses.payload, &addrlen);
  183|  1.63k|	if (addrlen > MAX_HOST_LEN) {
  ------------------
  |  |   78|  1.63k|#define MAX_HOST_LEN 254 /* max hostname len for tcp fwding */
  ------------------
  |  Branch (183:6): [True: 38, False: 1.60k]
  ------------------
  184|     38|		TRACE(("addr len too long: %d", addrlen))
  185|     38|		goto out;
  186|     38|	}
  187|       |
  188|  1.60k|	port = buf_getint(ses.payload);
  189|       |
  190|  1.60k|	if (port != 0) {
  ------------------
  |  Branch (190:6): [True: 1.52k, False: 74]
  ------------------
  191|  1.52k|		if (port < 1 || port > 65535) {
  ------------------
  |  Branch (191:7): [True: 0, False: 1.52k]
  |  Branch (191:19): [True: 64, False: 1.46k]
  ------------------
  192|     64|			TRACE(("invalid port: %d", port))
  193|     64|			goto out;
  194|     64|		}
  195|       |
  196|  1.46k|		if (!ses.allowprivport && port < IPPORT_RESERVED) {
  ------------------
  |  Branch (196:7): [True: 1.46k, False: 0]
  |  Branch (196:29): [True: 309, False: 1.15k]
  ------------------
  197|    309|			TRACE(("can't assign port < 1024 for non-root"))
  198|    309|			goto out;
  199|    309|		}
  200|  1.46k|	}
  201|       |
  202|  1.22k|	tcpinfo = (struct TCPListener*)m_malloc(sizeof(struct TCPListener));
  203|  1.22k|	tcpinfo->sendaddr = NULL;
  204|  1.22k|	tcpinfo->sendport = 0;
  205|  1.22k|	tcpinfo->listenport = port;
  206|  1.22k|	tcpinfo->chantype = &svr_chan_tcpremote;
  207|  1.22k|	tcpinfo->tcp_type = forwarded;
  208|       |
  209|  1.22k|	tcpinfo->request_listenaddr = request_addr;
  210|  1.22k|	if (!opts.listen_fwd_all || (strcmp(request_addr, "localhost") == 0) ) {
  ------------------
  |  Branch (210:6): [True: 1.22k, False: 0]
  |  Branch (210:30): [True: 0, False: 0]
  ------------------
  211|       |		/* NULL means "localhost only" */
  212|  1.22k|		tcpinfo->listenaddr = NULL;
  213|  1.22k|	}
  214|      4|	else
  215|      4|	{
  216|      4|		tcpinfo->listenaddr = m_strdup(request_addr);
  217|      4|	}
  218|       |
  219|  1.22k|	ret = listen_tcpfwd(tcpinfo, &listener);
  220|  1.22k|	if (DROPBEAR_SUCCESS == ret) {
  ------------------
  |  |  102|  1.22k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (220:6): [True: 0, False: 1.22k]
  ------------------
  221|      0|		tcpinfo->listenport = get_sock_port(listener->socks[0]);
  222|      0|		*allocated_listen_port = tcpinfo->listenport;
  223|      0|	}
  224|       |
  225|  1.63k|out:
  226|  1.63k|	if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|  1.63k|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (226:6): [True: 1.63k, False: 0]
  ------------------
  227|       |		/* we only free it if a listener wasn't created, since the listener
  228|       |		 * has to remember it if it's to be cancelled */
  229|  1.63k|		m_free(request_addr);
  ------------------
  |  |   24|  1.63k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  230|  1.63k|		m_free(tcpinfo);
  ------------------
  |  |   24|  1.63k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  231|  1.63k|	}
  232|       |
  233|  1.63k|	TRACE(("leave remotetcpreq"))
  234|       |
  235|  1.63k|	return ret;
  236|  1.22k|}
svr-tcpfwd.c:newtcpdirect:
  253|    323|static int newtcpdirect(struct Channel * channel) {
  254|       |
  255|    323|	char* desthost = NULL;
  256|    323|	unsigned int destport;
  257|    323|	char* orighost = NULL;
  258|    323|	unsigned int origport;
  259|    323|	char portstring[NI_MAXSERV];
  260|    323|	unsigned int len;
  261|    323|	int err = SSH_OPEN_ADMINISTRATIVELY_PROHIBITED;
  ------------------
  |  |   33|    323|#define SSH_OPEN_ADMINISTRATIVELY_PROHIBITED    1
  ------------------
  262|       |
  263|    323|	TRACE(("newtcpdirect channel %d", channel->index))
  264|       |
  265|    323|	if (svr_opts.nolocaltcp || !svr_pubkey_allows_tcpfwd()) {
  ------------------
  |  Branch (265:6): [True: 0, False: 323]
  |  Branch (265:29): [True: 0, False: 323]
  ------------------
  266|      0|		TRACE(("leave newtcpdirect: local tcp forwarding disabled"))
  267|      0|		goto out;
  268|      0|	}
  269|       |
  270|    323|	desthost = buf_getstring(ses.payload, &len);
  271|    323|	if (len > MAX_HOST_LEN) {
  ------------------
  |  |   78|    323|#define MAX_HOST_LEN 254 /* max hostname len for tcp fwding */
  ------------------
  |  Branch (271:6): [True: 71, False: 252]
  ------------------
  272|     71|		TRACE(("leave newtcpdirect: desthost too long"))
  273|     71|		goto out;
  274|     71|	}
  275|       |
  276|    252|	destport = buf_getint(ses.payload);
  277|       |	
  278|    252|	orighost = buf_getstring(ses.payload, &len);
  279|    252|	if (len > MAX_HOST_LEN) {
  ------------------
  |  |   78|    252|#define MAX_HOST_LEN 254 /* max hostname len for tcp fwding */
  ------------------
  |  Branch (279:6): [True: 36, False: 216]
  ------------------
  280|     36|		TRACE(("leave newtcpdirect: orighost too long"))
  281|     36|		goto out;
  282|     36|	}
  283|       |
  284|    216|	origport = buf_getint(ses.payload);
  285|       |
  286|       |	/* best be sure */
  287|    216|	if (origport > 65535 || destport > 65535) {
  ------------------
  |  Branch (287:6): [True: 48, False: 168]
  |  Branch (287:26): [True: 70, False: 98]
  ------------------
  288|    112|		TRACE(("leave newtcpdirect: port > 65535"))
  289|    112|		goto out;
  290|    112|	}
  291|       |
  292|    104|	if (!svr_pubkey_allows_local_tcpfwd(desthost, destport)) {
  ------------------
  |  Branch (292:6): [True: 0, False: 104]
  ------------------
  293|      0|		TRACE(("leave newtcpdirect: local tcp forwarding not permitted to requested destination"));
  294|      0|		goto out;
  295|      0|	}
  296|       |
  297|    104|	snprintf(portstring, sizeof(portstring), "%u", destport);
  298|    104|	channel->conn_pending = connect_remote(desthost, portstring, channel_connect_done,
  299|    104|		channel, NULL, NULL, DROPBEAR_PRIO_NORMAL);
  300|       |
  301|    104|	err = SSH_OPEN_IN_PROGRESS;
  ------------------
  |  |   39|    104|#define SSH_OPEN_IN_PROGRESS					99
  ------------------
  302|       |
  303|    317|out:
  304|    317|	m_free(desthost);
  ------------------
  |  |   24|    317|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  305|    317|	m_free(orighost);
  ------------------
  |  |   24|    317|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  306|    317|	TRACE(("leave newtcpdirect: err %d", err))
  307|    317|	return err;
  308|    104|}

listen_tcpfwd:
  106|  1.22k|int listen_tcpfwd(struct TCPListener* tcpinfo, struct Listener **ret_listener) {
  107|       |
  108|  1.22k|	char portstring[NI_MAXSERV];
  109|  1.22k|	int socks[DROPBEAR_MAX_SOCKS];
  110|  1.22k|	int nsocks;
  111|  1.22k|	struct Listener *listener;
  112|  1.22k|	char* errstring = NULL;
  113|       |
  114|  1.22k|	TRACE(("enter listen_tcpfwd"))
  115|       |
  116|       |	/* first we try to bind, so don't need to do so much cleanup on failure */
  117|  1.22k|	snprintf(portstring, sizeof(portstring), "%u", tcpinfo->listenport);
  118|       |
  119|  1.22k|	nsocks = dropbear_listen(tcpinfo->listenaddr, portstring, socks, 
  120|  1.22k|			DROPBEAR_MAX_SOCKS, &errstring, &ses.maxfd);
  ------------------
  |  |  242|  1.22k|#define DROPBEAR_MAX_SOCKS 2 /* IPv4, IPv6 are all we'll get for now. Revisit
  ------------------
  121|  1.22k|	if (nsocks < 0) {
  ------------------
  |  Branch (121:6): [True: 1.22k, False: 0]
  ------------------
  122|  1.22k|		dropbear_log(LOG_INFO, "TCP forward failed: %s", errstring);
  123|  1.22k|		m_free(errstring);
  ------------------
  |  |   24|  1.22k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  124|  1.22k|		TRACE(("leave listen_tcpfwd: dropbear_listen failed"))
  125|  1.22k|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|  1.22k|#define DROPBEAR_FAILURE -1
  ------------------
  126|  1.22k|	}
  127|      0|	m_free(errstring);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  128|       |	
  129|       |	/* new_listener will close the socks if it fails */
  130|      0|	listener = new_listener(socks, nsocks, CHANNEL_ID_TCPFORWARDED, tcpinfo, 
  ------------------
  |  |   76|      0|#define CHANNEL_ID_TCPFORWARDED 0x43612c67
  ------------------
  131|      0|			tcp_acceptor, cleanup_tcp);
  132|       |
  133|      0|	if (listener == NULL) {
  ------------------
  |  Branch (133:6): [True: 0, False: 0]
  ------------------
  134|      0|		TRACE(("leave listen_tcpfwd: listener failed"))
  135|      0|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
  136|      0|	}
  137|       |
  138|      0|	if (ret_listener) {
  ------------------
  |  Branch (138:6): [True: 0, False: 0]
  ------------------
  139|      0|		*ret_listener = listener;
  140|      0|	}
  141|       |
  142|      0|	TRACE(("leave listen_tcpfwd: success"))
  143|      0|	return DROPBEAR_SUCCESS;
  ------------------
  |  |  102|      0|#define DROPBEAR_SUCCESS 0
  ------------------
  144|      0|}

