fuzz_early_setup:
   23|      2|void fuzz_early_setup(void) {
   24|       |    /* Set stderr to point to normal stderr by default */
   25|       |    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|       |        assert(fuzz.fake_stderr);
  ------------------
  |  Branch (53:9): [True: 0, False: 1]
  |  Branch (53:9): [True: 1, False: 0]
  ------------------
   54|      1|    }
   55|      1|}
fuzz_set_input:
   57|  2.84k|int fuzz_set_input(const uint8_t *Data, size_t Size) {
   58|       |
   59|  2.84k|    fuzz.input->data = (unsigned char*)Data;
   60|  2.84k|    fuzz.input->size = Size;
   61|  2.84k|    fuzz.input->len = Size;
   62|  2.84k|    fuzz.input->pos = 0;
   63|       |
   64|  2.84k|    memset(&ses, 0x0, sizeof(ses));
   65|  2.84k|    memset(&svr_ses, 0x0, sizeof(svr_ses));
   66|  2.84k|    memset(&cli_ses, 0x0, sizeof(cli_ses));
   67|  2.84k|    wrapfd_setup(fuzz.input);
   68|       |    // printhex("input", fuzz.input->data, fuzz.input->len);
   69|       |
   70|  2.84k|    fuzz_seed(fuzz.input->data, MIN(fuzz.input->len, 16));
  ------------------
  |  Branch (70:33): [True: 269, False: 2.57k]
  ------------------
   71|       |
   72|  2.84k|    return DROPBEAR_SUCCESS;
  ------------------
  |  |  111|  2.84k|#define DROPBEAR_SUCCESS 0
  ------------------
   73|  2.84k|}
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|  2.84k|void fuzz_svr_hook_preloop() {
  106|  2.84k|    if (fuzz.svr_postauth) {
  ------------------
  |  Branch (106:9): [True: 0, False: 2.84k]
  ------------------
  107|      0|        ses.authstate.authdone = 1;
  108|      0|        fill_passwd("root");
  109|      0|    }
  110|  2.84k|}
fuzz_kex_fakealgos:
  197|  6.53k|void fuzz_kex_fakealgos(void) {
  198|  6.53k|    ses.newkeys->recv.crypt_mode = &dropbear_mode_none;
  199|  6.53k|    ses.newkeys->recv.algo_mac = &dropbear_nohash;
  200|  6.53k|}
fuzz_get_socket_address:
  203|  5.68k|                        char **remote_host, char **remote_port, int UNUSED(host_lookup)) {
  204|  5.68k|    if (local_host) {
  ------------------
  |  Branch (204:9): [True: 0, False: 5.68k]
  ------------------
  205|      0|        *local_host = m_strdup("fuzzlocalhost");
  206|      0|    }
  207|  5.68k|    if (local_port) {
  ------------------
  |  Branch (207:9): [True: 0, False: 5.68k]
  ------------------
  208|      0|        *local_port = m_strdup("1234");
  209|      0|    }
  210|  5.68k|    if (remote_host) {
  ------------------
  |  Branch (210:9): [True: 5.68k, False: 0]
  ------------------
  211|  5.68k|        *remote_host = m_strdup("fuzzremotehost");
  212|  5.68k|    }
  213|  5.68k|    if (remote_port) {
  ------------------
  |  Branch (213:9): [True: 2.84k, False: 2.84k]
  ------------------
  214|  2.84k|        *remote_port = m_strdup("9876");
  215|  2.84k|    }
  216|  5.68k|}
fuzz_fake_send_kexdh_reply:
  219|  6.16k|void fuzz_fake_send_kexdh_reply(void) {
  220|  6.16k|    assert(!ses.dh_K);
  ------------------
  |  Branch (220:5): [True: 0, False: 6.16k]
  |  Branch (220:5): [True: 6.16k, False: 0]
  ------------------
  221|  6.16k|    m_mp_alloc_init_multi(&ses.dh_K, NULL);
  222|  6.16k|    mp_set_ul(ses.dh_K, 12345678uL);
  223|  6.16k|    finish_kexhashbuf();
  224|  6.16k|}
fuzz_run_server:
  264|  2.84k|int fuzz_run_server(const uint8_t *Data, size_t Size, int skip_kexmaths, int postauth) {
  265|  2.84k|    static int once = 0;
  266|  2.84k|    if (!once) {
  ------------------
  |  Branch (266:9): [True: 1, False: 2.84k]
  ------------------
  267|      1|        fuzz_svr_setup();
  268|      1|        fuzz.skip_kexmaths = skip_kexmaths;
  269|      1|        once = 1;
  270|      1|    }
  271|       |
  272|  2.84k|    fuzz.svr_postauth = postauth;
  273|       |
  274|  2.84k|    if (fuzz_set_input(Data, Size) == DROPBEAR_FAILURE) {
  ------------------
  |  |  112|  2.84k|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (274:9): [True: 0, False: 2.84k]
  ------------------
  275|      0|        return 0;
  276|      0|    }
  277|       |
  278|  2.84k|    uint32_t wrapseed;
  279|  2.84k|    genrandom((void*)&wrapseed, sizeof(wrapseed));
  280|  2.84k|    wrapfd_setseed(wrapseed);
  281|       |
  282|  2.84k|    int fakesock = wrapfd_new_fuzzinput();
  283|       |
  284|  2.84k|    m_malloc_set_epoch(1);
  285|  2.84k|    fuzz.do_jmp = 1;
  286|  2.84k|    if (setjmp(fuzz.jmp) == 0) {
  ------------------
  |  Branch (286:9): [True: 2.84k, False: 0]
  ------------------
  287|  2.84k|        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|  2.84k|}
fuzz_dump:
  345|   103k|void fuzz_dump(const unsigned char* data, size_t len) {
  346|   103k|    if (fuzz.dumping) {
  ------------------
  |  Branch (346:9): [True: 0, False: 103k]
  ------------------
  347|      0|        TRACE(("dump %zu", len))
  348|       |        assert(atomicio(vwrite, fuzz.recv_dumpfd, (void*)data, len) == len);
  ------------------
  |  Branch (348:9): [True: 0, False: 0]
  |  Branch (348:9): [True: 0, False: 0]
  ------------------
  349|      0|    }
  350|   103k|}
fuzz_getpwnam:
  373|    483|struct passwd* fuzz_getpwnam(const char *login) {
  374|    483|    if (!fuzz.fuzzing) {
  ------------------
  |  Branch (374:9): [True: 0, False: 483]
  ------------------
  375|      0|        return getpwnam(login);
  376|      0|    }
  377|    483|    if (strcmp(login, pwd_other.pw_name) == 0) {
  ------------------
  |  Branch (377:9): [True: 0, False: 483]
  ------------------
  378|      0|        return &pwd_other;
  379|      0|    }
  380|    483|    if (strcmp(login, pwd_root.pw_name) == 0) {
  ------------------
  |  Branch (380:9): [True: 5, False: 478]
  ------------------
  381|      5|        return &pwd_root;
  382|      5|    }
  383|    478|    return NULL;
  384|    483|}
fuzz-common.c:fuzz_dropbear_log:
   84|  3.32k|static void fuzz_dropbear_log(int UNUSED(priority), const char* UNUSED(format), va_list UNUSED(param)) {
   85|       |    /* No print */
   86|  3.32k|}
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) {
  ------------------
  |  |  112|      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) {
  ------------------
  |  |  112|      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) {
  ------------------
  |  |  112|      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) {
  ------------------
  |  |  112|      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);
  ------------------
  |  |  243|      2|#define RECV_MAX_PACKET_LEN (MAX(35000, ((RECV_MAX_PAYLOAD_LEN)+100)))
  ------------------
  |  Branch (130:29): [True: 2, Folded]
  ------------------
  131|      2|    alloc_packetB = buf_new(RECV_MAX_PACKET_LEN);
  ------------------
  |  |  243|      2|#define RECV_MAX_PACKET_LEN (MAX(35000, ((RECV_MAX_PAYLOAD_LEN)+100)))
  ------------------
  |  Branch (131:29): [True: 2, Folded]
  ------------------
  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);
  ------------------
  |  |  243|  1.00k|#define RECV_MAX_PACKET_LEN (MAX(35000, ((RECV_MAX_PAYLOAD_LEN)+100)))
  ------------------
  |  Branch (134:31): [True: 1.00k, Folded]
  ------------------
  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|       |        packets2[i] = buf_new(RECV_MAX_PACKET_LEN);
  ------------------
  |  |  243|  1.00k|#define RECV_MAX_PACKET_LEN (MAX(35000, ((RECV_MAX_PAYLOAD_LEN)+100)))
  ------------------
  |  Branch (137:31): [True: 1.00k, Folded]
  ------------------
  138|  1.00k|    }
  139|      2|}

wrapfd_setup:
   32|  2.84k|void wrapfd_setup(buffer *buf) {
   33|  2.84k|	TRACE(("wrapfd_setup"))
   34|       |
   35|       |	// clean old ones
   36|  2.84k|	int i;
   37|  22.7k|	for (i = 0; i <= wrapfd_maxfd; i++) {
  ------------------
  |  Branch (37:14): [True: 19.9k, False: 2.84k]
  ------------------
   38|  19.9k|		if (wrap_fds[i].mode != UNUSED) {
  ------------------
  |  Branch (38:7): [True: 1.60k, False: 18.2k]
  ------------------
   39|  1.60k|			wrapfd_remove(i);
   40|  1.60k|		}
   41|  19.9k|	}
   42|  2.84k|	wrapfd_maxfd = -1;
   43|       |
   44|  2.84k|	memset(rand_state, 0x0, sizeof(rand_state));
   45|  2.84k|	wrapfd_setseed(50);
   46|  2.84k|	input_buf = buf;
   47|  2.84k|}
wrapfd_setseed:
   49|  5.68k|void wrapfd_setseed(uint32_t seed) {
   50|  5.68k|	memcpy(rand_state, &seed, sizeof(seed));
   51|  5.68k|	nrand48(rand_state);
   52|  5.68k|}
wrapfd_new_fuzzinput:
   54|  2.84k|int wrapfd_new_fuzzinput() {
   55|  2.84k|	if (devnull_fd == -1) {
  ------------------
  |  Branch (55:6): [True: 1, False: 2.84k]
  ------------------
   56|      1|		devnull_fd = open("/dev/null", O_RDONLY);
   57|      1|		assert(devnull_fd != -1);
  ------------------
  |  Branch (57:3): [True: 0, False: 1]
  |  Branch (57:3): [True: 1, False: 0]
  ------------------
   58|      1|	}
   59|       |
   60|  2.84k|	int fd = dup(devnull_fd);
   61|  2.84k|	assert(fd != -1);
  ------------------
  |  Branch (61:2): [True: 0, False: 2.84k]
  |  Branch (61:2): [True: 2.84k, False: 0]
  ------------------
   62|  2.84k|	assert(wrap_fds[fd].mode == UNUSED);
  ------------------
  |  Branch (62:2): [True: 0, False: 2.84k]
  |  Branch (62:2): [True: 2.84k, False: 0]
  ------------------
   63|  2.84k|	wrap_fds[fd].mode = COMMONBUF;
   64|  2.84k|	wrap_fds[fd].closein = 0;
   65|  2.84k|	wrap_fds[fd].closeout = 0;
   66|  2.84k|	wrapfd_maxfd = MAX(fd, wrapfd_maxfd);
  ------------------
  |  Branch (66:17): [True: 2.84k, False: 0]
  ------------------
   67|       |
   68|  2.84k|	return fd;
   69|  2.84k|}
wrapfd_close:
  105|  1.24k|int wrapfd_close(int fd) {
  106|  1.24k|	if (fd >= 0 && fd <= IOWRAP_MAXFD && wrap_fds[fd].mode != UNUSED) {
  ------------------
  |  |    9|  2.48k|#define IOWRAP_MAXFD (FD_SETSIZE-1)
  ------------------
  |  Branch (106:6): [True: 1.24k, False: 0]
  |  Branch (106:17): [True: 1.24k, False: 0]
  |  Branch (106:39): [True: 1.24k, False: 0]
  ------------------
  107|  1.24k|		wrapfd_remove(fd);
  108|  1.24k|		return 0;
  109|  1.24k|	} else {
  110|      0|		return close(fd);
  111|      0|	}
  112|  1.24k|}
wrapfd_read:
  114|   274k|int wrapfd_read(int fd, void *out, size_t count) {
  115|   274k|	size_t maxread;
  116|       |
  117|   274k|	if (!fuzz.wrapfds) {
  ------------------
  |  Branch (117:6): [True: 0, False: 274k]
  ------------------
  118|      0|		return read(fd, out, count);
  119|      0|	}
  120|       |
  121|   274k|	if (fd < 0 || fd > IOWRAP_MAXFD || wrap_fds[fd].mode == UNUSED) {
  ------------------
  |  |    9|   548k|#define IOWRAP_MAXFD (FD_SETSIZE-1)
  ------------------
  |  Branch (121:6): [True: 0, False: 274k]
  |  Branch (121:16): [True: 0, False: 274k]
  |  Branch (121:37): [True: 0, False: 274k]
  ------------------
  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|   274k|	assert(count != 0);
  ------------------
  |  Branch (128:2): [True: 0, False: 274k]
  |  Branch (128:2): [True: 274k, False: 0]
  ------------------
  129|       |
  130|   274k|	if (wrap_fds[fd].closein || erand48(rand_state) < CHANCE_CLOSE) {
  ------------------
  |  Branch (130:6): [True: 0, False: 274k]
  |  Branch (130:30): [True: 8, False: 274k]
  ------------------
  131|      8|		wrap_fds[fd].closein = 1;
  132|      8|		errno = ECONNRESET;
  133|      8|		return -1;
  134|      8|	}
  135|       |
  136|   274k|	if (erand48(rand_state) < CHANCE_INTR) {
  ------------------
  |  Branch (136:6): [True: 327, False: 273k]
  ------------------
  137|    327|		errno = EINTR;
  138|    327|		return -1;
  139|    327|	}
  140|       |
  141|   273k|	if (input_buf && wrap_fds[fd].mode == COMMONBUF) {
  ------------------
  |  Branch (141:6): [True: 273k, False: 0]
  |  Branch (141:19): [True: 273k, False: 0]
  ------------------
  142|   273k|		maxread = MIN(input_buf->len - input_buf->pos, count);
  ------------------
  |  Branch (142:13): [True: 1.76k, False: 272k]
  ------------------
  143|       |		/* returns 0 if buf is EOF, as intended */
  144|   273k|		if (maxread > 0) {
  ------------------
  |  Branch (144:7): [True: 272k, False: 1.19k]
  ------------------
  145|   272k|			maxread = nrand48(rand_state) % maxread + 1;
  146|   272k|		}
  147|   273k|		memcpy(out, buf_getptr(input_buf, maxread), maxread);
  148|   273k|		buf_incrpos(input_buf, maxread);
  149|   273k|		return maxread;
  150|   273k|	}
  151|       |
  152|       |	// return fixed output, of random length
  153|      0|	maxread = MIN(MAX_RANDOM_IN, count);
  ------------------
  |  Branch (153:12): [True: 0, False: 0]
  ------------------
  154|      0|	maxread = nrand48(rand_state) % maxread + 1;
  155|      0|	memset(out, 0xef, maxread);
  156|      0|	return maxread;
  157|   273k|}
wrapfd_select:
  196|   273k|	fd_set *exceptfds, struct timeval *timeout) {
  197|   273k|	int i, nset, sel;
  198|   273k|	int ret = 0;
  199|   273k|	int fdlist[IOWRAP_MAXFD+1];
  200|       |
  201|   273k|	if (!fuzz.wrapfds) {
  ------------------
  |  Branch (201:6): [True: 0, False: 273k]
  ------------------
  202|      0|		return select(nfds, readfds, writefds, exceptfds, timeout);
  203|      0|	}
  204|       |
  205|   273k|	assert(nfds <= IOWRAP_MAXFD+1);
  ------------------
  |  Branch (205:2): [True: 0, False: 273k]
  |  Branch (205:2): [True: 273k, False: 0]
  ------------------
  206|       |
  207|   273k|	if (erand48(rand_state) < CHANCE_INTR) {
  ------------------
  |  Branch (207:6): [True: 318, False: 273k]
  ------------------
  208|    318|		errno = EINTR;
  209|    318|		return -1;
  210|    318|	}
  211|       |
  212|       |	/* read */
  213|   273k|	if (readfds != NULL && erand48(rand_state) < CHANCE_READ1) {
  ------------------
  |  Branch (213:6): [True: 273k, False: 0]
  |  Branch (213:25): [True: 255k, False: 17.7k]
  ------------------
  214|  2.04M|		for (i = 0, nset = 0; i < nfds; i++) {
  ------------------
  |  Branch (214:25): [True: 1.78M, False: 255k]
  ------------------
  215|  1.78M|			if (FD_ISSET(i, readfds)) {
  ------------------
  |  Branch (215:8): [True: 249k, False: 1.53M]
  ------------------
  216|   249k|				assert(wrap_fds[i].mode != UNUSED);
  ------------------
  |  Branch (216:5): [True: 0, False: 249k]
  |  Branch (216:5): [True: 249k, False: 0]
  ------------------
  217|   249k|				fdlist[nset] = i;
  218|   249k|				nset++;
  219|   249k|			}
  220|  1.78M|		}
  221|   255k|		DROPBEAR_FD_ZERO(readfds);
  ------------------
  |  |  106|   255k|#define DROPBEAR_FD_ZERO(fds) FD_ZERO(fds)
  ------------------
  |  Branch (221:3): [Folded, False: 255k]
  ------------------
  222|       |
  223|   255k|		if (nset > 0) {
  ------------------
  |  Branch (223:7): [True: 249k, False: 5.59k]
  ------------------
  224|       |			/* set one */
  225|   249k|			sel = fdlist[nrand48(rand_state) % nset];
  226|   249k|			FD_SET(sel, readfds);
  227|   249k|			ret++;
  228|       |
  229|   249k|			if (erand48(rand_state) < CHANCE_READ2) {
  ------------------
  |  Branch (229:8): [True: 122k, False: 127k]
  ------------------
  230|   122k|				sel = fdlist[nrand48(rand_state) % nset];
  231|   122k|				if (!FD_ISSET(sel, readfds)) {
  ------------------
  |  Branch (231:9): [True: 0, False: 122k]
  ------------------
  232|      0|					FD_SET(sel, readfds);
  233|      0|					ret++;
  234|      0|				}
  235|   122k|			}
  236|   249k|		}
  237|   255k|	}
  238|       |
  239|       |	/* write */
  240|   273k|	if (writefds != NULL && erand48(rand_state) < CHANCE_WRITE1) {
  ------------------
  |  Branch (240:6): [True: 212k, False: 61.1k]
  |  Branch (240:26): [True: 201k, False: 10.2k]
  ------------------
  241|  1.61M|		for (i = 0, nset = 0; i < nfds; i++) {
  ------------------
  |  Branch (241:25): [True: 1.41M, False: 201k]
  ------------------
  242|  1.41M|			if (FD_ISSET(i, writefds)) {
  ------------------
  |  Branch (242:8): [True: 5.69k, False: 1.40M]
  ------------------
  243|  5.69k|				assert(wrap_fds[i].mode != UNUSED);
  ------------------
  |  Branch (243:5): [True: 0, False: 5.69k]
  |  Branch (243:5): [True: 5.69k, False: 0]
  ------------------
  244|  5.69k|				fdlist[nset] = i;
  245|  5.69k|				nset++;
  246|  5.69k|			}
  247|  1.41M|		}
  248|   201k|		DROPBEAR_FD_ZERO(writefds);
  ------------------
  |  |  106|   201k|#define DROPBEAR_FD_ZERO(fds) FD_ZERO(fds)
  ------------------
  |  Branch (248:3): [Folded, False: 201k]
  ------------------
  249|       |
  250|       |		/* set one */
  251|   201k|		if (nset > 0) {
  ------------------
  |  Branch (251:7): [True: 5.69k, False: 196k]
  ------------------
  252|  5.69k|			sel = fdlist[nrand48(rand_state) % nset];
  253|  5.69k|			FD_SET(sel, writefds);
  254|  5.69k|			ret++;
  255|       |
  256|  5.69k|			if (erand48(rand_state) < CHANCE_WRITE2) {
  ------------------
  |  Branch (256:8): [True: 1.19k, False: 4.50k]
  ------------------
  257|  1.19k|				sel = fdlist[nrand48(rand_state) % nset];
  258|  1.19k|				if (!FD_ISSET(sel, writefds)) {
  ------------------
  |  Branch (258:9): [True: 0, False: 1.19k]
  ------------------
  259|      0|					FD_SET(sel, writefds);
  260|      0|					ret++;
  261|      0|				}
  262|  1.19k|			}
  263|  5.69k|		}
  264|   201k|	}
  265|   273k|	return ret;
  266|   273k|}
fuzz-wrapfd.c:wrapfd_remove:
   96|  2.84k|static void wrapfd_remove(int fd) {
   97|  2.84k|	TRACE(("wrapfd_remove %d", fd))
   98|  2.84k|	assert(fd >= 0);
  ------------------
  |  Branch (98:2): [True: 0, False: 2.84k]
  |  Branch (98:2): [True: 2.84k, False: 0]
  ------------------
   99|  2.84k|	assert(fd <= IOWRAP_MAXFD);
  ------------------
  |  Branch (99:2): [True: 0, False: 2.84k]
  |  Branch (99:2): [True: 2.84k, False: 0]
  ------------------
  100|  2.84k|	assert(wrap_fds[fd].mode != UNUSED);
  ------------------
  |  Branch (100:2): [True: 0, False: 2.84k]
  |  Branch (100:2): [True: 2.84k, False: 0]
  ------------------
  101|  2.84k|	wrap_fds[fd].mode = UNUSED;
  102|  2.84k|	close(fd);
  103|  2.84k|}

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

rijndael_setup:
  123|  5.49k|{
  124|  5.49k|    int i;
  125|  5.49k|    ulong32 temp, *rk;
  126|  5.49k|#ifndef ENCRYPT_ONLY
  127|  5.49k|    ulong32 *rrk;
  128|  5.49k|#endif
  129|  5.49k|    LTC_ARGCHK(key  != NULL);
  ------------------
  |  |   32|  5.49k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 5.49k]
  |  |  |  Branch (32:87): [Folded, False: 5.49k]
  |  |  ------------------
  ------------------
  130|  5.49k|    LTC_ARGCHK(skey != NULL);
  ------------------
  |  |   32|  5.49k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 5.49k]
  |  |  |  Branch (32:87): [Folded, False: 5.49k]
  |  |  ------------------
  ------------------
  131|       |
  132|  5.49k|    if (keylen != 16 && keylen != 24 && keylen != 32) {
  ------------------
  |  Branch (132:9): [True: 3.12k, False: 2.37k]
  |  Branch (132:25): [True: 3.12k, False: 0]
  |  Branch (132:41): [True: 0, False: 3.12k]
  ------------------
  133|      0|       return CRYPT_INVALID_KEYSIZE;
  134|      0|    }
  135|       |
  136|  5.49k|    if (num_rounds != 0 && num_rounds != (10 + ((keylen/8)-2)*2)) {
  ------------------
  |  Branch (136:9): [True: 0, False: 5.49k]
  |  Branch (136:28): [True: 0, False: 0]
  ------------------
  137|      0|       return CRYPT_INVALID_ROUNDS;
  138|      0|    }
  139|       |
  140|  5.49k|    skey->rijndael.Nr = 10 + ((keylen/8)-2)*2;
  141|       |
  142|       |    /* setup the forward key */
  143|  5.49k|    i                 = 0;
  144|  5.49k|    rk                = skey->rijndael.eK;
  145|  5.49k|    LOAD32H(rk[0], key     );
  ------------------
  |  |   66|  5.49k|#define LOAD32H(x, y)                           \
  |  |   67|  5.49k|do { XMEMCPY (&(x), (y), 4);                    \
  |  |  ------------------
  |  |  |  |   39|  5.49k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |   68|  5.49k|      (x) = __builtin_bswap32 ((x)); } while(0)
  |  |  ------------------
  |  |  |  Branch (68:46): [Folded, False: 5.49k]
  |  |  ------------------
  ------------------
  146|  5.49k|    LOAD32H(rk[1], key +  4);
  ------------------
  |  |   66|  5.49k|#define LOAD32H(x, y)                           \
  |  |   67|  5.49k|do { XMEMCPY (&(x), (y), 4);                    \
  |  |  ------------------
  |  |  |  |   39|  5.49k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |   68|  5.49k|      (x) = __builtin_bswap32 ((x)); } while(0)
  |  |  ------------------
  |  |  |  Branch (68:46): [Folded, False: 5.49k]
  |  |  ------------------
  ------------------
  147|  5.49k|    LOAD32H(rk[2], key +  8);
  ------------------
  |  |   66|  5.49k|#define LOAD32H(x, y)                           \
  |  |   67|  5.49k|do { XMEMCPY (&(x), (y), 4);                    \
  |  |  ------------------
  |  |  |  |   39|  5.49k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |   68|  5.49k|      (x) = __builtin_bswap32 ((x)); } while(0)
  |  |  ------------------
  |  |  |  Branch (68:46): [Folded, False: 5.49k]
  |  |  ------------------
  ------------------
  148|  5.49k|    LOAD32H(rk[3], key + 12);
  ------------------
  |  |   66|  5.49k|#define LOAD32H(x, y)                           \
  |  |   67|  5.49k|do { XMEMCPY (&(x), (y), 4);                    \
  |  |  ------------------
  |  |  |  |   39|  5.49k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |   68|  5.49k|      (x) = __builtin_bswap32 ((x)); } while(0)
  |  |  ------------------
  |  |  |  Branch (68:46): [Folded, False: 5.49k]
  |  |  ------------------
  ------------------
  149|  5.49k|    if (keylen == 16) {
  ------------------
  |  Branch (149:9): [True: 2.37k, False: 3.12k]
  ------------------
  150|  23.7k|        for (;;) {
  151|  23.7k|            temp  = rk[3];
  152|  23.7k|            rk[4] = rk[0] ^ setup_mix(temp) ^ rcon[i];
  153|  23.7k|            rk[5] = rk[1] ^ rk[4];
  154|  23.7k|            rk[6] = rk[2] ^ rk[5];
  155|  23.7k|            rk[7] = rk[3] ^ rk[6];
  156|  23.7k|            if (++i == 10) {
  ------------------
  |  Branch (156:17): [True: 2.37k, False: 21.3k]
  ------------------
  157|  2.37k|               break;
  158|  2.37k|            }
  159|  21.3k|            rk += 4;
  160|  21.3k|        }
  161|  3.12k|    } else if (keylen == 24) {
  ------------------
  |  Branch (161:16): [True: 0, False: 3.12k]
  ------------------
  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, False: 0]
  |  |  ------------------
  ------------------
  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, False: 0]
  |  |  ------------------
  ------------------
  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|  3.12k|    } else if (keylen == 32) {
  ------------------
  |  Branch (181:16): [True: 3.12k, False: 0]
  ------------------
  182|  3.12k|        LOAD32H(rk[4], key + 16);
  ------------------
  |  |   66|  3.12k|#define LOAD32H(x, y)                           \
  |  |   67|  3.12k|do { XMEMCPY (&(x), (y), 4);                    \
  |  |  ------------------
  |  |  |  |   39|  3.12k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |   68|  3.12k|      (x) = __builtin_bswap32 ((x)); } while(0)
  |  |  ------------------
  |  |  |  Branch (68:46): [Folded, False: 3.12k]
  |  |  ------------------
  ------------------
  183|  3.12k|        LOAD32H(rk[5], key + 20);
  ------------------
  |  |   66|  3.12k|#define LOAD32H(x, y)                           \
  |  |   67|  3.12k|do { XMEMCPY (&(x), (y), 4);                    \
  |  |  ------------------
  |  |  |  |   39|  3.12k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |   68|  3.12k|      (x) = __builtin_bswap32 ((x)); } while(0)
  |  |  ------------------
  |  |  |  Branch (68:46): [Folded, False: 3.12k]
  |  |  ------------------
  ------------------
  184|  3.12k|        LOAD32H(rk[6], key + 24);
  ------------------
  |  |   66|  3.12k|#define LOAD32H(x, y)                           \
  |  |   67|  3.12k|do { XMEMCPY (&(x), (y), 4);                    \
  |  |  ------------------
  |  |  |  |   39|  3.12k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |   68|  3.12k|      (x) = __builtin_bswap32 ((x)); } while(0)
  |  |  ------------------
  |  |  |  Branch (68:46): [Folded, False: 3.12k]
  |  |  ------------------
  ------------------
  185|  3.12k|        LOAD32H(rk[7], key + 28);
  ------------------
  |  |   66|  3.12k|#define LOAD32H(x, y)                           \
  |  |   67|  3.12k|do { XMEMCPY (&(x), (y), 4);                    \
  |  |  ------------------
  |  |  |  |   39|  3.12k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |   68|  3.12k|      (x) = __builtin_bswap32 ((x)); } while(0)
  |  |  ------------------
  |  |  |  Branch (68:46): [Folded, False: 3.12k]
  |  |  ------------------
  ------------------
  186|  21.8k|        for (;;) {
  187|       |        #ifdef _MSC_VER
  188|       |            temp = skey->rijndael.eK[rk - skey->rijndael.eK + 7];
  189|       |        #else
  190|  21.8k|            temp = rk[7];
  191|  21.8k|        #endif
  192|  21.8k|            rk[ 8] = rk[ 0] ^ setup_mix(temp) ^ rcon[i];
  193|  21.8k|            rk[ 9] = rk[ 1] ^ rk[ 8];
  194|  21.8k|            rk[10] = rk[ 2] ^ rk[ 9];
  195|  21.8k|            rk[11] = rk[ 3] ^ rk[10];
  196|  21.8k|            if (++i == 7) {
  ------------------
  |  Branch (196:17): [True: 3.12k, False: 18.7k]
  ------------------
  197|  3.12k|                break;
  198|  3.12k|            }
  199|  18.7k|            temp = rk[11];
  200|  18.7k|            rk[12] = rk[ 4] ^ setup_mix(RORc(temp, 8));
  ------------------
  |  |  283|  18.7k|#define RORc(word,i) ({ \
  |  |  284|  18.7k|   ulong32 __RORc_tmp = (word); \
  |  |  285|  18.7k|   __asm__ ("rorl %2, %0" : \
  |  |  286|  18.7k|            "=r" (__RORc_tmp) : \
  |  |  287|  18.7k|            "0" (__RORc_tmp), \
  |  |  288|  18.7k|            "I" (i)); \
  |  |  289|  18.7k|            __RORc_tmp; \
  |  |  290|  18.7k|   })
  ------------------
  201|  18.7k|            rk[13] = rk[ 5] ^ rk[12];
  202|  18.7k|            rk[14] = rk[ 6] ^ rk[13];
  203|  18.7k|            rk[15] = rk[ 7] ^ rk[14];
  204|  18.7k|            rk += 8;
  205|  18.7k|        }
  206|  3.12k|    } else {
  207|       |       /* this can't happen */
  208|       |       /* coverity[dead_error_line] */
  209|      0|       return CRYPT_ERROR;
  210|      0|    }
  211|       |
  212|  5.49k|#ifndef ENCRYPT_ONLY
  213|       |    /* setup the inverse key now */
  214|  5.49k|    rk   = skey->rijndael.dK;
  215|  5.49k|    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|  5.49k|    *rk++ = *rrk++;
  220|  5.49k|    *rk++ = *rrk++;
  221|  5.49k|    *rk++ = *rrk++;
  222|  5.49k|    *rk   = *rrk;
  223|  5.49k|    rk -= 3; rrk -= 3;
  224|       |
  225|  67.4k|    for (i = 1; i < skey->rijndael.Nr; i++) {
  ------------------
  |  Branch (225:17): [True: 61.9k, False: 5.49k]
  ------------------
  226|  61.9k|        rrk -= 4;
  227|  61.9k|        rk  += 4;
  228|  61.9k|    #ifdef LTC_SMALL_CODE
  229|  61.9k|        temp = rrk[0];
  230|  61.9k|        rk[0] = setup_mix2(temp);
  231|  61.9k|        temp = rrk[1];
  232|  61.9k|        rk[1] = setup_mix2(temp);
  233|  61.9k|        temp = rrk[2];
  234|  61.9k|        rk[2] = setup_mix2(temp);
  235|  61.9k|        temp = rrk[3];
  236|  61.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|  61.9k|    }
  265|       |
  266|       |    /* copy last */
  267|  5.49k|    rrk -= 4;
  268|  5.49k|    rk  += 4;
  269|  5.49k|    *rk++ = *rrk++;
  270|  5.49k|    *rk++ = *rrk++;
  271|  5.49k|    *rk++ = *rrk++;
  272|  5.49k|    *rk   = *rrk;
  273|  5.49k|#endif /* ENCRYPT_ONLY */
  274|       |
  275|  5.49k|    return CRYPT_OK;
  276|  5.49k|}
rijndael_ecb_encrypt:
  290|   146k|{
  291|   146k|    ulong32 s0, s1, s2, s3, t0, t1, t2, t3, *rk;
  292|   146k|    int Nr, r;
  293|       |
  294|   146k|    LTC_ARGCHK(pt != NULL);
  ------------------
  |  |   32|   146k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 146k]
  |  |  |  Branch (32:87): [Folded, False: 146k]
  |  |  ------------------
  ------------------
  295|   146k|    LTC_ARGCHK(ct != NULL);
  ------------------
  |  |   32|   146k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 146k]
  |  |  |  Branch (32:87): [Folded, False: 146k]
  |  |  ------------------
  ------------------
  296|   146k|    LTC_ARGCHK(skey != NULL);
  ------------------
  |  |   32|   146k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 146k]
  |  |  |  Branch (32:87): [Folded, False: 146k]
  |  |  ------------------
  ------------------
  297|       |
  298|   146k|    Nr = skey->rijndael.Nr;
  299|   146k|    rk = skey->rijndael.eK;
  300|       |
  301|       |    /*
  302|       |     * map byte array block to cipher state
  303|       |     * and add initial round key:
  304|       |     */
  305|   146k|    LOAD32H(s0, pt      ); s0 ^= rk[0];
  ------------------
  |  |   66|   146k|#define LOAD32H(x, y)                           \
  |  |   67|   146k|do { XMEMCPY (&(x), (y), 4);                    \
  |  |  ------------------
  |  |  |  |   39|   146k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |   68|   146k|      (x) = __builtin_bswap32 ((x)); } while(0)
  |  |  ------------------
  |  |  |  Branch (68:46): [Folded, False: 146k]
  |  |  ------------------
  ------------------
  306|   146k|    LOAD32H(s1, pt  +  4); s1 ^= rk[1];
  ------------------
  |  |   66|   146k|#define LOAD32H(x, y)                           \
  |  |   67|   146k|do { XMEMCPY (&(x), (y), 4);                    \
  |  |  ------------------
  |  |  |  |   39|   146k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |   68|   146k|      (x) = __builtin_bswap32 ((x)); } while(0)
  |  |  ------------------
  |  |  |  Branch (68:46): [Folded, False: 146k]
  |  |  ------------------
  ------------------
  307|   146k|    LOAD32H(s2, pt  +  8); s2 ^= rk[2];
  ------------------
  |  |   66|   146k|#define LOAD32H(x, y)                           \
  |  |   67|   146k|do { XMEMCPY (&(x), (y), 4);                    \
  |  |  ------------------
  |  |  |  |   39|   146k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |   68|   146k|      (x) = __builtin_bswap32 ((x)); } while(0)
  |  |  ------------------
  |  |  |  Branch (68:46): [Folded, False: 146k]
  |  |  ------------------
  ------------------
  308|   146k|    LOAD32H(s3, pt  + 12); s3 ^= rk[3];
  ------------------
  |  |   66|   146k|#define LOAD32H(x, y)                           \
  |  |   67|   146k|do { XMEMCPY (&(x), (y), 4);                    \
  |  |  ------------------
  |  |  |  |   39|   146k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |   68|   146k|      (x) = __builtin_bswap32 ((x)); } while(0)
  |  |  ------------------
  |  |  |  Branch (68:46): [Folded, False: 146k]
  |  |  ------------------
  ------------------
  309|       |
  310|   146k|#ifdef LTC_SMALL_CODE
  311|       |
  312|  1.69M|    for (r = 0; ; r++) {
  313|  1.69M|        rk += 4;
  314|  1.69M|        t0 =
  315|  1.69M|            Te0(byte(s0, 3)) ^
  ------------------
  |  |  306|  1.69M|#define Te0(x) TE0[x]
  ------------------
  316|  1.69M|            Te1(byte(s1, 2)) ^
  ------------------
  |  |  307|  1.69M|#define Te1(x) RORc(TE0[x], 8)
  |  |  ------------------
  |  |  |  |  283|  1.69M|#define RORc(word,i) ({ \
  |  |  |  |  284|  1.69M|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  285|  1.69M|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  286|  1.69M|            "=r" (__RORc_tmp) : \
  |  |  |  |  287|  1.69M|            "0" (__RORc_tmp), \
  |  |  |  |  288|  1.69M|            "I" (i)); \
  |  |  |  |  289|  1.69M|            __RORc_tmp; \
  |  |  |  |  290|  1.69M|   })
  |  |  ------------------
  ------------------
  317|  1.69M|            Te2(byte(s2, 1)) ^
  ------------------
  |  |  308|  1.69M|#define Te2(x) RORc(TE0[x], 16)
  |  |  ------------------
  |  |  |  |  283|  1.69M|#define RORc(word,i) ({ \
  |  |  |  |  284|  1.69M|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  285|  1.69M|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  286|  1.69M|            "=r" (__RORc_tmp) : \
  |  |  |  |  287|  1.69M|            "0" (__RORc_tmp), \
  |  |  |  |  288|  1.69M|            "I" (i)); \
  |  |  |  |  289|  1.69M|            __RORc_tmp; \
  |  |  |  |  290|  1.69M|   })
  |  |  ------------------
  ------------------
  318|  1.69M|            Te3(byte(s3, 0)) ^
  ------------------
  |  |  309|  1.69M|#define Te3(x) RORc(TE0[x], 24)
  |  |  ------------------
  |  |  |  |  283|  1.69M|#define RORc(word,i) ({ \
  |  |  |  |  284|  1.69M|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  285|  1.69M|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  286|  1.69M|            "=r" (__RORc_tmp) : \
  |  |  |  |  287|  1.69M|            "0" (__RORc_tmp), \
  |  |  |  |  288|  1.69M|            "I" (i)); \
  |  |  |  |  289|  1.69M|            __RORc_tmp; \
  |  |  |  |  290|  1.69M|   })
  |  |  ------------------
  ------------------
  319|  1.69M|            rk[0];
  320|  1.69M|        t1 =
  321|  1.69M|            Te0(byte(s1, 3)) ^
  ------------------
  |  |  306|  1.69M|#define Te0(x) TE0[x]
  ------------------
  322|  1.69M|            Te1(byte(s2, 2)) ^
  ------------------
  |  |  307|  1.69M|#define Te1(x) RORc(TE0[x], 8)
  |  |  ------------------
  |  |  |  |  283|  1.69M|#define RORc(word,i) ({ \
  |  |  |  |  284|  1.69M|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  285|  1.69M|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  286|  1.69M|            "=r" (__RORc_tmp) : \
  |  |  |  |  287|  1.69M|            "0" (__RORc_tmp), \
  |  |  |  |  288|  1.69M|            "I" (i)); \
  |  |  |  |  289|  1.69M|            __RORc_tmp; \
  |  |  |  |  290|  1.69M|   })
  |  |  ------------------
  ------------------
  323|  1.69M|            Te2(byte(s3, 1)) ^
  ------------------
  |  |  308|  1.69M|#define Te2(x) RORc(TE0[x], 16)
  |  |  ------------------
  |  |  |  |  283|  1.69M|#define RORc(word,i) ({ \
  |  |  |  |  284|  1.69M|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  285|  1.69M|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  286|  1.69M|            "=r" (__RORc_tmp) : \
  |  |  |  |  287|  1.69M|            "0" (__RORc_tmp), \
  |  |  |  |  288|  1.69M|            "I" (i)); \
  |  |  |  |  289|  1.69M|            __RORc_tmp; \
  |  |  |  |  290|  1.69M|   })
  |  |  ------------------
  ------------------
  324|  1.69M|            Te3(byte(s0, 0)) ^
  ------------------
  |  |  309|  1.69M|#define Te3(x) RORc(TE0[x], 24)
  |  |  ------------------
  |  |  |  |  283|  1.69M|#define RORc(word,i) ({ \
  |  |  |  |  284|  1.69M|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  285|  1.69M|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  286|  1.69M|            "=r" (__RORc_tmp) : \
  |  |  |  |  287|  1.69M|            "0" (__RORc_tmp), \
  |  |  |  |  288|  1.69M|            "I" (i)); \
  |  |  |  |  289|  1.69M|            __RORc_tmp; \
  |  |  |  |  290|  1.69M|   })
  |  |  ------------------
  ------------------
  325|  1.69M|            rk[1];
  326|  1.69M|        t2 =
  327|  1.69M|            Te0(byte(s2, 3)) ^
  ------------------
  |  |  306|  1.69M|#define Te0(x) TE0[x]
  ------------------
  328|  1.69M|            Te1(byte(s3, 2)) ^
  ------------------
  |  |  307|  1.69M|#define Te1(x) RORc(TE0[x], 8)
  |  |  ------------------
  |  |  |  |  283|  1.69M|#define RORc(word,i) ({ \
  |  |  |  |  284|  1.69M|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  285|  1.69M|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  286|  1.69M|            "=r" (__RORc_tmp) : \
  |  |  |  |  287|  1.69M|            "0" (__RORc_tmp), \
  |  |  |  |  288|  1.69M|            "I" (i)); \
  |  |  |  |  289|  1.69M|            __RORc_tmp; \
  |  |  |  |  290|  1.69M|   })
  |  |  ------------------
  ------------------
  329|  1.69M|            Te2(byte(s0, 1)) ^
  ------------------
  |  |  308|  1.69M|#define Te2(x) RORc(TE0[x], 16)
  |  |  ------------------
  |  |  |  |  283|  1.69M|#define RORc(word,i) ({ \
  |  |  |  |  284|  1.69M|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  285|  1.69M|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  286|  1.69M|            "=r" (__RORc_tmp) : \
  |  |  |  |  287|  1.69M|            "0" (__RORc_tmp), \
  |  |  |  |  288|  1.69M|            "I" (i)); \
  |  |  |  |  289|  1.69M|            __RORc_tmp; \
  |  |  |  |  290|  1.69M|   })
  |  |  ------------------
  ------------------
  330|  1.69M|            Te3(byte(s1, 0)) ^
  ------------------
  |  |  309|  1.69M|#define Te3(x) RORc(TE0[x], 24)
  |  |  ------------------
  |  |  |  |  283|  1.69M|#define RORc(word,i) ({ \
  |  |  |  |  284|  1.69M|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  285|  1.69M|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  286|  1.69M|            "=r" (__RORc_tmp) : \
  |  |  |  |  287|  1.69M|            "0" (__RORc_tmp), \
  |  |  |  |  288|  1.69M|            "I" (i)); \
  |  |  |  |  289|  1.69M|            __RORc_tmp; \
  |  |  |  |  290|  1.69M|   })
  |  |  ------------------
  ------------------
  331|  1.69M|            rk[2];
  332|  1.69M|        t3 =
  333|  1.69M|            Te0(byte(s3, 3)) ^
  ------------------
  |  |  306|  1.69M|#define Te0(x) TE0[x]
  ------------------
  334|  1.69M|            Te1(byte(s0, 2)) ^
  ------------------
  |  |  307|  1.69M|#define Te1(x) RORc(TE0[x], 8)
  |  |  ------------------
  |  |  |  |  283|  1.69M|#define RORc(word,i) ({ \
  |  |  |  |  284|  1.69M|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  285|  1.69M|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  286|  1.69M|            "=r" (__RORc_tmp) : \
  |  |  |  |  287|  1.69M|            "0" (__RORc_tmp), \
  |  |  |  |  288|  1.69M|            "I" (i)); \
  |  |  |  |  289|  1.69M|            __RORc_tmp; \
  |  |  |  |  290|  1.69M|   })
  |  |  ------------------
  ------------------
  335|  1.69M|            Te2(byte(s1, 1)) ^
  ------------------
  |  |  308|  1.69M|#define Te2(x) RORc(TE0[x], 16)
  |  |  ------------------
  |  |  |  |  283|  1.69M|#define RORc(word,i) ({ \
  |  |  |  |  284|  1.69M|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  285|  1.69M|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  286|  1.69M|            "=r" (__RORc_tmp) : \
  |  |  |  |  287|  1.69M|            "0" (__RORc_tmp), \
  |  |  |  |  288|  1.69M|            "I" (i)); \
  |  |  |  |  289|  1.69M|            __RORc_tmp; \
  |  |  |  |  290|  1.69M|   })
  |  |  ------------------
  ------------------
  336|  1.69M|            Te3(byte(s2, 0)) ^
  ------------------
  |  |  309|  1.69M|#define Te3(x) RORc(TE0[x], 24)
  |  |  ------------------
  |  |  |  |  283|  1.69M|#define RORc(word,i) ({ \
  |  |  |  |  284|  1.69M|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  285|  1.69M|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  286|  1.69M|            "=r" (__RORc_tmp) : \
  |  |  |  |  287|  1.69M|            "0" (__RORc_tmp), \
  |  |  |  |  288|  1.69M|            "I" (i)); \
  |  |  |  |  289|  1.69M|            __RORc_tmp; \
  |  |  |  |  290|  1.69M|   })
  |  |  ------------------
  ------------------
  337|  1.69M|            rk[3];
  338|  1.69M|        if (r == Nr-2) {
  ------------------
  |  Branch (338:13): [True: 146k, False: 1.55M]
  ------------------
  339|   146k|           break;
  340|   146k|        }
  341|  1.55M|        s0 = t0; s1 = t1; s2 = t2; s3 = t3;
  342|  1.55M|    }
  343|   146k|    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|   146k|    s0 =
  415|   146k|        (Te4_3[byte(t0, 3)]) ^
  ------------------
  |  |  319|   146k|#define Te4_3 0xFF000000 & Te4
  ------------------
                      (Te4_3[byte(t0, 3)]) ^
  ------------------
  |  |  436|   146k|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
  416|   146k|        (Te4_2[byte(t1, 2)]) ^
  ------------------
  |  |  318|   146k|#define Te4_2 0x00FF0000 & Te4
  ------------------
                      (Te4_2[byte(t1, 2)]) ^
  ------------------
  |  |  436|   146k|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
  417|   146k|        (Te4_1[byte(t2, 1)]) ^
  ------------------
  |  |  317|   146k|#define Te4_1 0x0000FF00 & Te4
  ------------------
                      (Te4_1[byte(t2, 1)]) ^
  ------------------
  |  |  436|   146k|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
  418|   146k|        (Te4_0[byte(t3, 0)]) ^
  ------------------
  |  |  316|   146k|#define Te4_0 0x000000FF & Te4
  ------------------
                      (Te4_0[byte(t3, 0)]) ^
  ------------------
  |  |  436|   146k|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
  419|   146k|        rk[0];
  420|   146k|    STORE32H(s0, ct);
  ------------------
  |  |   62|   146k|#define STORE32H(x, y)                          \
  |  |   63|   146k|do { ulong32 __t = __builtin_bswap32 ((x));     \
  |  |   64|   146k|      XMEMCPY ((y), &__t, 4); } while(0)
  |  |  ------------------
  |  |  |  |   39|   146k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (64:39): [Folded, False: 146k]
  |  |  ------------------
  ------------------
  421|   146k|    s1 =
  422|   146k|        (Te4_3[byte(t1, 3)]) ^
  ------------------
  |  |  319|   146k|#define Te4_3 0xFF000000 & Te4
  ------------------
                      (Te4_3[byte(t1, 3)]) ^
  ------------------
  |  |  436|   146k|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
  423|   146k|        (Te4_2[byte(t2, 2)]) ^
  ------------------
  |  |  318|   146k|#define Te4_2 0x00FF0000 & Te4
  ------------------
                      (Te4_2[byte(t2, 2)]) ^
  ------------------
  |  |  436|   146k|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
  424|   146k|        (Te4_1[byte(t3, 1)]) ^
  ------------------
  |  |  317|   146k|#define Te4_1 0x0000FF00 & Te4
  ------------------
                      (Te4_1[byte(t3, 1)]) ^
  ------------------
  |  |  436|   146k|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
  425|   146k|        (Te4_0[byte(t0, 0)]) ^
  ------------------
  |  |  316|   146k|#define Te4_0 0x000000FF & Te4
  ------------------
                      (Te4_0[byte(t0, 0)]) ^
  ------------------
  |  |  436|   146k|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
  426|   146k|        rk[1];
  427|   146k|    STORE32H(s1, ct+4);
  ------------------
  |  |   62|   146k|#define STORE32H(x, y)                          \
  |  |   63|   146k|do { ulong32 __t = __builtin_bswap32 ((x));     \
  |  |   64|   146k|      XMEMCPY ((y), &__t, 4); } while(0)
  |  |  ------------------
  |  |  |  |   39|   146k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (64:39): [Folded, False: 146k]
  |  |  ------------------
  ------------------
  428|   146k|    s2 =
  429|   146k|        (Te4_3[byte(t2, 3)]) ^
  ------------------
  |  |  319|   146k|#define Te4_3 0xFF000000 & Te4
  ------------------
                      (Te4_3[byte(t2, 3)]) ^
  ------------------
  |  |  436|   146k|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
  430|   146k|        (Te4_2[byte(t3, 2)]) ^
  ------------------
  |  |  318|   146k|#define Te4_2 0x00FF0000 & Te4
  ------------------
                      (Te4_2[byte(t3, 2)]) ^
  ------------------
  |  |  436|   146k|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
  431|   146k|        (Te4_1[byte(t0, 1)]) ^
  ------------------
  |  |  317|   146k|#define Te4_1 0x0000FF00 & Te4
  ------------------
                      (Te4_1[byte(t0, 1)]) ^
  ------------------
  |  |  436|   146k|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
  432|   146k|        (Te4_0[byte(t1, 0)]) ^
  ------------------
  |  |  316|   146k|#define Te4_0 0x000000FF & Te4
  ------------------
                      (Te4_0[byte(t1, 0)]) ^
  ------------------
  |  |  436|   146k|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
  433|   146k|        rk[2];
  434|   146k|    STORE32H(s2, ct+8);
  ------------------
  |  |   62|   146k|#define STORE32H(x, y)                          \
  |  |   63|   146k|do { ulong32 __t = __builtin_bswap32 ((x));     \
  |  |   64|   146k|      XMEMCPY ((y), &__t, 4); } while(0)
  |  |  ------------------
  |  |  |  |   39|   146k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (64:39): [Folded, False: 146k]
  |  |  ------------------
  ------------------
  435|   146k|    s3 =
  436|   146k|        (Te4_3[byte(t3, 3)]) ^
  ------------------
  |  |  319|   146k|#define Te4_3 0xFF000000 & Te4
  ------------------
                      (Te4_3[byte(t3, 3)]) ^
  ------------------
  |  |  436|   146k|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
  437|   146k|        (Te4_2[byte(t0, 2)]) ^
  ------------------
  |  |  318|   146k|#define Te4_2 0x00FF0000 & Te4
  ------------------
                      (Te4_2[byte(t0, 2)]) ^
  ------------------
  |  |  436|   146k|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
  438|   146k|        (Te4_1[byte(t1, 1)]) ^
  ------------------
  |  |  317|   146k|#define Te4_1 0x0000FF00 & Te4
  ------------------
                      (Te4_1[byte(t1, 1)]) ^
  ------------------
  |  |  436|   146k|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
  439|   146k|        (Te4_0[byte(t2, 0)]) ^
  ------------------
  |  |  316|   146k|#define Te4_0 0x000000FF & Te4
  ------------------
                      (Te4_0[byte(t2, 0)]) ^
  ------------------
  |  |  436|   146k|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
  440|   146k|        rk[3];
  441|   146k|    STORE32H(s3, ct+12);
  ------------------
  |  |   62|   146k|#define STORE32H(x, y)                          \
  |  |   63|   146k|do { ulong32 __t = __builtin_bswap32 ((x));     \
  |  |   64|   146k|      XMEMCPY ((y), &__t, 4); } while(0)
  |  |  ------------------
  |  |  |  |   39|   146k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (64:39): [Folded, False: 146k]
  |  |  ------------------
  ------------------
  442|       |
  443|   146k|    return CRYPT_OK;
  444|   146k|}
aes.c:setup_mix:
   95|  64.3k|{
   96|  64.3k|   return (Te4_3[byte(temp, 2)]) ^
  ------------------
  |  |  319|  64.3k|#define Te4_3 0xFF000000 & Te4
  ------------------
                 return (Te4_3[byte(temp, 2)]) ^
  ------------------
  |  |  436|  64.3k|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
   97|  64.3k|          (Te4_2[byte(temp, 1)]) ^
  ------------------
  |  |  318|  64.3k|#define Te4_2 0x00FF0000 & Te4
  ------------------
                        (Te4_2[byte(temp, 1)]) ^
  ------------------
  |  |  436|  64.3k|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
   98|  64.3k|          (Te4_1[byte(temp, 0)]) ^
  ------------------
  |  |  317|  64.3k|#define Te4_1 0x0000FF00 & Te4
  ------------------
                        (Te4_1[byte(temp, 0)]) ^
  ------------------
  |  |  436|  64.3k|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
   99|  64.3k|          (Te4_0[byte(temp, 3)]);
  ------------------
  |  |  316|  64.3k|#define Te4_0 0x000000FF & Te4
  ------------------
                        (Te4_0[byte(temp, 3)]);
  ------------------
  |  |  436|  64.3k|   #define byte(x, n) (((x) >> (8 * (n))) & 255)
  ------------------
  100|  64.3k|}
aes.c:setup_mix2:
  105|   247k|{
  106|   247k|   return Td0(255 & Te4[byte(temp, 3)]) ^
  ------------------
  |  |  311|   247k|#define Td0(x) TD0[x]
  ------------------
  107|   247k|          Td1(255 & Te4[byte(temp, 2)]) ^
  ------------------
  |  |  312|   247k|#define Td1(x) RORc(TD0[x], 8)
  |  |  ------------------
  |  |  |  |  283|   247k|#define RORc(word,i) ({ \
  |  |  |  |  284|   247k|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  285|   247k|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  286|   247k|            "=r" (__RORc_tmp) : \
  |  |  |  |  287|   247k|            "0" (__RORc_tmp), \
  |  |  |  |  288|   247k|            "I" (i)); \
  |  |  |  |  289|   247k|            __RORc_tmp; \
  |  |  |  |  290|   247k|   })
  |  |  ------------------
  ------------------
  108|   247k|          Td2(255 & Te4[byte(temp, 1)]) ^
  ------------------
  |  |  313|   247k|#define Td2(x) RORc(TD0[x], 16)
  |  |  ------------------
  |  |  |  |  283|   247k|#define RORc(word,i) ({ \
  |  |  |  |  284|   247k|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  285|   247k|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  286|   247k|            "=r" (__RORc_tmp) : \
  |  |  |  |  287|   247k|            "0" (__RORc_tmp), \
  |  |  |  |  288|   247k|            "I" (i)); \
  |  |  |  |  289|   247k|            __RORc_tmp; \
  |  |  |  |  290|   247k|   })
  |  |  ------------------
  ------------------
  109|   247k|          Td3(255 & Te4[byte(temp, 0)]);
  ------------------
  |  |  314|   247k|#define Td3(x) RORc(TD0[x], 24)
  |  |  ------------------
  |  |  |  |  283|   247k|#define RORc(word,i) ({ \
  |  |  |  |  284|   247k|   ulong32 __RORc_tmp = (word); \
  |  |  |  |  285|   247k|   __asm__ ("rorl %2, %0" : \
  |  |  |  |  286|   247k|            "=r" (__RORc_tmp) : \
  |  |  |  |  287|   247k|            "0" (__RORc_tmp), \
  |  |  |  |  288|   247k|            "I" (i)); \
  |  |  |  |  289|   247k|            __RORc_tmp; \
  |  |  |  |  290|   247k|   })
  |  |  ------------------
  ------------------
  110|   247k|}

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

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

sha512_init:
  174|  1.57k|{
  175|  1.57k|    LTC_ARGCHK(md != NULL);
  ------------------
  |  |   32|  1.57k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 1.57k]
  |  |  |  Branch (32:87): [Folded, False: 1.57k]
  |  |  ------------------
  ------------------
  176|  1.57k|    md->sha512.curlen = 0;
  177|  1.57k|    md->sha512.length = 0;
  178|  1.57k|    md->sha512.state[0] = CONST64(0x6a09e667f3bcc908);
  ------------------
  |  |  200|  1.57k|   #define CONST64(n) n ## ULL
  ------------------
  179|  1.57k|    md->sha512.state[1] = CONST64(0xbb67ae8584caa73b);
  ------------------
  |  |  200|  1.57k|   #define CONST64(n) n ## ULL
  ------------------
  180|  1.57k|    md->sha512.state[2] = CONST64(0x3c6ef372fe94f82b);
  ------------------
  |  |  200|  1.57k|   #define CONST64(n) n ## ULL
  ------------------
  181|  1.57k|    md->sha512.state[3] = CONST64(0xa54ff53a5f1d36f1);
  ------------------
  |  |  200|  1.57k|   #define CONST64(n) n ## ULL
  ------------------
  182|  1.57k|    md->sha512.state[4] = CONST64(0x510e527fade682d1);
  ------------------
  |  |  200|  1.57k|   #define CONST64(n) n ## ULL
  ------------------
  183|  1.57k|    md->sha512.state[5] = CONST64(0x9b05688c2b3e6c1f);
  ------------------
  |  |  200|  1.57k|   #define CONST64(n) n ## ULL
  ------------------
  184|  1.57k|    md->sha512.state[6] = CONST64(0x1f83d9abfb41bd6b);
  ------------------
  |  |  200|  1.57k|   #define CONST64(n) n ## ULL
  ------------------
  185|  1.57k|    md->sha512.state[7] = CONST64(0x5be0cd19137e2179);
  ------------------
  |  |  200|  1.57k|   #define CONST64(n) n ## ULL
  ------------------
  186|  1.57k|    return CRYPT_OK;
  187|  1.57k|}
sha512_done:
  205|  7.67k|{
  206|  7.67k|    int i;
  207|       |
  208|  7.67k|    LTC_ARGCHK(md  != NULL);
  ------------------
  |  |   32|  7.67k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 7.67k]
  |  |  |  Branch (32:87): [Folded, False: 7.67k]
  |  |  ------------------
  ------------------
  209|  7.67k|    LTC_ARGCHK(out != NULL);
  ------------------
  |  |   32|  7.67k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 7.67k]
  |  |  |  Branch (32:87): [Folded, False: 7.67k]
  |  |  ------------------
  ------------------
  210|       |
  211|  7.67k|    if (md->sha512.curlen >= sizeof(md->sha512.buf)) {
  ------------------
  |  Branch (211:9): [True: 0, False: 7.67k]
  ------------------
  212|      0|       return CRYPT_INVALID_ARG;
  213|      0|    }
  214|       |
  215|       |    /* increase the length of the message */
  216|  7.67k|    md->sha512.length += md->sha512.curlen * CONST64(8);
  ------------------
  |  |  200|  7.67k|   #define CONST64(n) n ## ULL
  ------------------
  217|       |
  218|       |    /* append the '1' bit */
  219|  7.67k|    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|  7.67k|    if (md->sha512.curlen > 112) {
  ------------------
  |  Branch (225:9): [True: 1.48k, False: 6.18k]
  ------------------
  226|  9.83k|        while (md->sha512.curlen < 128) {
  ------------------
  |  Branch (226:16): [True: 8.35k, False: 1.48k]
  ------------------
  227|  8.35k|            md->sha512.buf[md->sha512.curlen++] = (unsigned char)0;
  228|  8.35k|        }
  229|  1.48k|        sha512_compress(md, md->sha512.buf);
  230|  1.48k|        md->sha512.curlen = 0;
  231|  1.48k|    }
  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|   689k|    while (md->sha512.curlen < 120) {
  ------------------
  |  Branch (237:12): [True: 681k, False: 7.67k]
  ------------------
  238|   681k|        md->sha512.buf[md->sha512.curlen++] = (unsigned char)0;
  239|   681k|    }
  240|       |
  241|       |    /* store length */
  242|  7.67k|    STORE64H(md->sha512.length, md->sha512.buf+120);
  ------------------
  |  |  101|  7.67k|#define STORE64H(x, y)                          \
  |  |  102|  7.67k|do { ulong64 __t = __builtin_bswap64 ((x));     \
  |  |  103|  7.67k|      XMEMCPY ((y), &__t, 8); } while(0)
  |  |  ------------------
  |  |  |  |   39|  7.67k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (103:39): [Folded, False: 7.67k]
  |  |  ------------------
  ------------------
  243|  7.67k|    sha512_compress(md, md->sha512.buf);
  244|       |
  245|       |    /* copy output */
  246|  69.0k|    for (i = 0; i < 8; i++) {
  ------------------
  |  Branch (246:17): [True: 61.3k, False: 7.67k]
  ------------------
  247|  61.3k|        STORE64H(md->sha512.state[i], out+(8*i));
  ------------------
  |  |  101|  61.3k|#define STORE64H(x, y)                          \
  |  |  102|  61.3k|do { ulong64 __t = __builtin_bswap64 ((x));     \
  |  |  103|  61.3k|      XMEMCPY ((y), &__t, 8); } while(0)
  |  |  ------------------
  |  |  |  |   39|  61.3k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (103:39): [Folded, False: 61.3k]
  |  |  ------------------
  ------------------
  248|  61.3k|    }
  249|       |#ifdef LTC_CLEAN_STACK
  250|       |    zeromem(md, sizeof(hash_state));
  251|       |#endif
  252|  7.67k|    return CRYPT_OK;
  253|  7.67k|}
sha512.c:sha512_compress:
   96|  22.2k|{
   97|  22.2k|    ulong64 S[8], W[80], t0, t1;
   98|  22.2k|    int i;
   99|       |
  100|       |    /* copy state into S */
  101|   199k|    for (i = 0; i < 8; i++) {
  ------------------
  |  Branch (101:17): [True: 177k, False: 22.2k]
  ------------------
  102|   177k|        S[i] = md->sha512.state[i];
  103|   177k|    }
  104|       |
  105|       |    /* copy the state into 1024-bits into W[0..15] */
  106|   377k|    for (i = 0; i < 16; i++) {
  ------------------
  |  Branch (106:17): [True: 355k, False: 22.2k]
  ------------------
  107|   355k|        LOAD64H(W[i], buf + (8*i));
  ------------------
  |  |  105|   355k|#define LOAD64H(x, y)                           \
  |  |  106|   355k|do { XMEMCPY (&(x), (y), 8);                    \
  |  |  ------------------
  |  |  |  |   39|   355k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  107|   355k|      (x) = __builtin_bswap64 ((x)); } while(0)
  |  |  ------------------
  |  |  |  Branch (107:46): [Folded, False: 355k]
  |  |  ------------------
  ------------------
  108|   355k|    }
  109|       |
  110|       |    /* fill W[16..79] */
  111|  1.44M|    for (i = 16; i < 80; i++) {
  ------------------
  |  Branch (111:18): [True: 1.42M, False: 22.2k]
  ------------------
  112|  1.42M|        W[i] = Gamma1(W[i - 2]) + W[i - 7] + Gamma0(W[i - 15]) + W[i - 16];
  ------------------
  |  |   88|  1.42M|#define Gamma1(x)       (S(x, 19) ^ S(x, 61) ^ R(x, 6))
  |  |  ------------------
  |  |  |  |   83|  1.42M|#define S(x, n)         ROR64c(x, n)
  |  |  |  |  ------------------
  |  |  |  |  |  |  384|  1.42M|#define ROR64c(word,i) ({ \
  |  |  |  |  |  |  385|  1.42M|   ulong64 __ROR64c_tmp = word; \
  |  |  |  |  |  |  386|  1.42M|   __asm__ ("rorq %2, %0" : \
  |  |  |  |  |  |  387|  1.42M|            "=r" (__ROR64c_tmp) : \
  |  |  |  |  |  |  388|  1.42M|            "0" (__ROR64c_tmp), \
  |  |  |  |  |  |  389|  1.42M|            "J" (i)); \
  |  |  |  |  |  |  390|  1.42M|            __ROR64c_tmp; \
  |  |  |  |  |  |  391|  1.42M|   })
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define Gamma1(x)       (S(x, 19) ^ S(x, 61) ^ R(x, 6))
  |  |  ------------------
  |  |  |  |   83|  1.42M|#define S(x, n)         ROR64c(x, n)
  |  |  |  |  ------------------
  |  |  |  |  |  |  384|  1.42M|#define ROR64c(word,i) ({ \
  |  |  |  |  |  |  385|  1.42M|   ulong64 __ROR64c_tmp = word; \
  |  |  |  |  |  |  386|  1.42M|   __asm__ ("rorq %2, %0" : \
  |  |  |  |  |  |  387|  1.42M|            "=r" (__ROR64c_tmp) : \
  |  |  |  |  |  |  388|  1.42M|            "0" (__ROR64c_tmp), \
  |  |  |  |  |  |  389|  1.42M|            "J" (i)); \
  |  |  |  |  |  |  390|  1.42M|            __ROR64c_tmp; \
  |  |  |  |  |  |  391|  1.42M|   })
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define Gamma1(x)       (S(x, 19) ^ S(x, 61) ^ R(x, 6))
  |  |  ------------------
  |  |  |  |   84|  1.42M|#define R(x, n)         (((x)&CONST64(0xFFFFFFFFFFFFFFFF))>>((ulong64)n))
  |  |  |  |  ------------------
  |  |  |  |  |  |  200|  1.42M|   #define CONST64(n) n ## ULL
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      W[i] = Gamma1(W[i - 2]) + W[i - 7] + Gamma0(W[i - 15]) + W[i - 16];
  ------------------
  |  |   87|  1.42M|#define Gamma0(x)       (S(x, 1) ^ S(x, 8) ^ R(x, 7))
  |  |  ------------------
  |  |  |  |   83|  1.42M|#define S(x, n)         ROR64c(x, n)
  |  |  |  |  ------------------
  |  |  |  |  |  |  384|  1.42M|#define ROR64c(word,i) ({ \
  |  |  |  |  |  |  385|  1.42M|   ulong64 __ROR64c_tmp = word; \
  |  |  |  |  |  |  386|  1.42M|   __asm__ ("rorq %2, %0" : \
  |  |  |  |  |  |  387|  1.42M|            "=r" (__ROR64c_tmp) : \
  |  |  |  |  |  |  388|  1.42M|            "0" (__ROR64c_tmp), \
  |  |  |  |  |  |  389|  1.42M|            "J" (i)); \
  |  |  |  |  |  |  390|  1.42M|            __ROR64c_tmp; \
  |  |  |  |  |  |  391|  1.42M|   })
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define Gamma0(x)       (S(x, 1) ^ S(x, 8) ^ R(x, 7))
  |  |  ------------------
  |  |  |  |   83|  1.42M|#define S(x, n)         ROR64c(x, n)
  |  |  |  |  ------------------
  |  |  |  |  |  |  384|  1.42M|#define ROR64c(word,i) ({ \
  |  |  |  |  |  |  385|  1.42M|   ulong64 __ROR64c_tmp = word; \
  |  |  |  |  |  |  386|  1.42M|   __asm__ ("rorq %2, %0" : \
  |  |  |  |  |  |  387|  1.42M|            "=r" (__ROR64c_tmp) : \
  |  |  |  |  |  |  388|  1.42M|            "0" (__ROR64c_tmp), \
  |  |  |  |  |  |  389|  1.42M|            "J" (i)); \
  |  |  |  |  |  |  390|  1.42M|            __ROR64c_tmp; \
  |  |  |  |  |  |  391|  1.42M|   })
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define Gamma0(x)       (S(x, 1) ^ S(x, 8) ^ R(x, 7))
  |  |  ------------------
  |  |  |  |   84|  1.42M|#define R(x, n)         (((x)&CONST64(0xFFFFFFFFFFFFFFFF))>>((ulong64)n))
  |  |  |  |  ------------------
  |  |  |  |  |  |  200|  1.42M|   #define CONST64(n) n ## ULL
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  113|  1.42M|    }
  114|       |
  115|       |    /* Compress */
  116|  22.2k|#ifdef LTC_SMALL_CODE
  117|  1.79M|    for (i = 0; i < 80; i++) {
  ------------------
  |  Branch (117:17): [True: 1.77M, False: 22.2k]
  ------------------
  118|  1.77M|        t0 = S[7] + Sigma1(S[4]) + Ch(S[4], S[5], S[6]) + K[i] + W[i];
  ------------------
  |  |   86|  1.77M|#define Sigma1(x)       (S(x, 14) ^ S(x, 18) ^ S(x, 41))
  |  |  ------------------
  |  |  |  |   83|  1.77M|#define S(x, n)         ROR64c(x, n)
  |  |  |  |  ------------------
  |  |  |  |  |  |  384|  1.77M|#define ROR64c(word,i) ({ \
  |  |  |  |  |  |  385|  1.77M|   ulong64 __ROR64c_tmp = word; \
  |  |  |  |  |  |  386|  1.77M|   __asm__ ("rorq %2, %0" : \
  |  |  |  |  |  |  387|  1.77M|            "=r" (__ROR64c_tmp) : \
  |  |  |  |  |  |  388|  1.77M|            "0" (__ROR64c_tmp), \
  |  |  |  |  |  |  389|  1.77M|            "J" (i)); \
  |  |  |  |  |  |  390|  1.77M|            __ROR64c_tmp; \
  |  |  |  |  |  |  391|  1.77M|   })
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define Sigma1(x)       (S(x, 14) ^ S(x, 18) ^ S(x, 41))
  |  |  ------------------
  |  |  |  |   83|  1.77M|#define S(x, n)         ROR64c(x, n)
  |  |  |  |  ------------------
  |  |  |  |  |  |  384|  1.77M|#define ROR64c(word,i) ({ \
  |  |  |  |  |  |  385|  1.77M|   ulong64 __ROR64c_tmp = word; \
  |  |  |  |  |  |  386|  1.77M|   __asm__ ("rorq %2, %0" : \
  |  |  |  |  |  |  387|  1.77M|            "=r" (__ROR64c_tmp) : \
  |  |  |  |  |  |  388|  1.77M|            "0" (__ROR64c_tmp), \
  |  |  |  |  |  |  389|  1.77M|            "J" (i)); \
  |  |  |  |  |  |  390|  1.77M|            __ROR64c_tmp; \
  |  |  |  |  |  |  391|  1.77M|   })
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define Sigma1(x)       (S(x, 14) ^ S(x, 18) ^ S(x, 41))
  |  |  ------------------
  |  |  |  |   83|  1.77M|#define S(x, n)         ROR64c(x, n)
  |  |  |  |  ------------------
  |  |  |  |  |  |  384|  1.77M|#define ROR64c(word,i) ({ \
  |  |  |  |  |  |  385|  1.77M|   ulong64 __ROR64c_tmp = word; \
  |  |  |  |  |  |  386|  1.77M|   __asm__ ("rorq %2, %0" : \
  |  |  |  |  |  |  387|  1.77M|            "=r" (__ROR64c_tmp) : \
  |  |  |  |  |  |  388|  1.77M|            "0" (__ROR64c_tmp), \
  |  |  |  |  |  |  389|  1.77M|            "J" (i)); \
  |  |  |  |  |  |  390|  1.77M|            __ROR64c_tmp; \
  |  |  |  |  |  |  391|  1.77M|   })
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      t0 = S[7] + Sigma1(S[4]) + Ch(S[4], S[5], S[6]) + K[i] + W[i];
  ------------------
  |  |   81|  1.77M|#define Ch(x,y,z)       (z ^ (x & (y ^ z)))
  ------------------
  119|  1.77M|        t1 = Sigma0(S[0]) + Maj(S[0], S[1], S[2]);
  ------------------
  |  |   85|  1.77M|#define Sigma0(x)       (S(x, 28) ^ S(x, 34) ^ S(x, 39))
  |  |  ------------------
  |  |  |  |   83|  1.77M|#define S(x, n)         ROR64c(x, n)
  |  |  |  |  ------------------
  |  |  |  |  |  |  384|  1.77M|#define ROR64c(word,i) ({ \
  |  |  |  |  |  |  385|  1.77M|   ulong64 __ROR64c_tmp = word; \
  |  |  |  |  |  |  386|  1.77M|   __asm__ ("rorq %2, %0" : \
  |  |  |  |  |  |  387|  1.77M|            "=r" (__ROR64c_tmp) : \
  |  |  |  |  |  |  388|  1.77M|            "0" (__ROR64c_tmp), \
  |  |  |  |  |  |  389|  1.77M|            "J" (i)); \
  |  |  |  |  |  |  390|  1.77M|            __ROR64c_tmp; \
  |  |  |  |  |  |  391|  1.77M|   })
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define Sigma0(x)       (S(x, 28) ^ S(x, 34) ^ S(x, 39))
  |  |  ------------------
  |  |  |  |   83|  1.77M|#define S(x, n)         ROR64c(x, n)
  |  |  |  |  ------------------
  |  |  |  |  |  |  384|  1.77M|#define ROR64c(word,i) ({ \
  |  |  |  |  |  |  385|  1.77M|   ulong64 __ROR64c_tmp = word; \
  |  |  |  |  |  |  386|  1.77M|   __asm__ ("rorq %2, %0" : \
  |  |  |  |  |  |  387|  1.77M|            "=r" (__ROR64c_tmp) : \
  |  |  |  |  |  |  388|  1.77M|            "0" (__ROR64c_tmp), \
  |  |  |  |  |  |  389|  1.77M|            "J" (i)); \
  |  |  |  |  |  |  390|  1.77M|            __ROR64c_tmp; \
  |  |  |  |  |  |  391|  1.77M|   })
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define Sigma0(x)       (S(x, 28) ^ S(x, 34) ^ S(x, 39))
  |  |  ------------------
  |  |  |  |   83|  1.77M|#define S(x, n)         ROR64c(x, n)
  |  |  |  |  ------------------
  |  |  |  |  |  |  384|  1.77M|#define ROR64c(word,i) ({ \
  |  |  |  |  |  |  385|  1.77M|   ulong64 __ROR64c_tmp = word; \
  |  |  |  |  |  |  386|  1.77M|   __asm__ ("rorq %2, %0" : \
  |  |  |  |  |  |  387|  1.77M|            "=r" (__ROR64c_tmp) : \
  |  |  |  |  |  |  388|  1.77M|            "0" (__ROR64c_tmp), \
  |  |  |  |  |  |  389|  1.77M|            "J" (i)); \
  |  |  |  |  |  |  390|  1.77M|            __ROR64c_tmp; \
  |  |  |  |  |  |  391|  1.77M|   })
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      t1 = Sigma0(S[0]) + Maj(S[0], S[1], S[2]);
  ------------------
  |  |   82|  1.77M|#define Maj(x,y,z)      (((x | y) & z) | (x & y))
  ------------------
  120|  1.77M|        S[7] = S[6];
  121|  1.77M|        S[6] = S[5];
  122|  1.77M|        S[5] = S[4];
  123|  1.77M|        S[4] = S[3] + t0;
  124|  1.77M|        S[3] = S[2];
  125|  1.77M|        S[2] = S[1];
  126|  1.77M|        S[1] = S[0];
  127|  1.77M|        S[0] = t0 + t1;
  128|  1.77M|    }
  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|   199k|    for (i = 0; i < 8; i++) {
  ------------------
  |  Branch (150:17): [True: 177k, False: 22.2k]
  ------------------
  151|   177k|        md->sha512.state[i] = md->sha512.state[i] + S[i];
  152|   177k|    }
  153|       |
  154|  22.2k|    return CRYPT_OK;
  155|  22.2k|}

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

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

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

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

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

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

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

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

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

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

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

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, False: 1]
  |  |  ------------------
  ------------------
   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|  14.1k|{
   24|  14.1k|   m_burn((void*)out, outlen);
   25|  14.1k|}

ctr_encrypt:
   87|  14.1k|{
   88|  14.1k|   int err, fr;
   89|       |
   90|  14.1k|   LTC_ARGCHK(pt != NULL);
  ------------------
  |  |   32|  14.1k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 14.1k]
  |  |  |  Branch (32:87): [Folded, False: 14.1k]
  |  |  ------------------
  ------------------
   91|  14.1k|   LTC_ARGCHK(ct != NULL);
  ------------------
  |  |   32|  14.1k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 14.1k]
  |  |  |  Branch (32:87): [Folded, False: 14.1k]
  |  |  ------------------
  ------------------
   92|  14.1k|   LTC_ARGCHK(ctr != NULL);
  ------------------
  |  |   32|  14.1k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 14.1k]
  |  |  |  Branch (32:87): [Folded, False: 14.1k]
  |  |  ------------------
  ------------------
   93|       |
   94|  14.1k|   if ((err = cipher_is_valid(ctr->cipher)) != CRYPT_OK) {
  ------------------
  |  Branch (94:8): [True: 0, False: 14.1k]
  ------------------
   95|      0|       return err;
   96|      0|   }
   97|       |
   98|       |   /* is blocklen/padlen valid? */
   99|  14.1k|   if ((ctr->blocklen < 1) || (ctr->blocklen > (int)sizeof(ctr->ctr)) ||
  ------------------
  |  Branch (99:8): [True: 0, False: 14.1k]
  |  Branch (99:31): [True: 0, False: 14.1k]
  ------------------
  100|  14.1k|       (ctr->padlen   < 0) || (ctr->padlen   > (int)sizeof(ctr->pad))) {
  ------------------
  |  Branch (100:8): [True: 0, False: 14.1k]
  |  Branch (100:31): [True: 0, False: 14.1k]
  ------------------
  101|      0|      return CRYPT_INVALID_ARG;
  102|      0|   }
  103|       |
  104|  14.1k|#ifdef LTC_FAST
  105|  14.1k|   if (ctr->blocklen % sizeof(LTC_FAST_TYPE)) {
  ------------------
  |  Branch (105:8): [True: 0, False: 14.1k]
  ------------------
  106|      0|      return CRYPT_INVALID_ARG;
  107|      0|   }
  108|  14.1k|#endif
  109|       |
  110|       |   /* handle acceleration only if pad is empty, accelerator is present and length is >= a block size */
  111|  14.1k|   if ((cipher_descriptor[ctr->cipher].accel_ctr_encrypt != NULL) && (len >= (unsigned long)ctr->blocklen)) {
  ------------------
  |  Branch (111:8): [True: 0, False: 14.1k]
  |  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|  14.1k|   return _ctr_encrypt(pt, ct, len, ctr);
  133|  14.1k|}
ctr_encrypt.c:_ctr_encrypt:
   28|  14.1k|{
   29|  14.1k|   int x, err;
   30|       |
   31|   159k|   while (len) {
  ------------------
  |  Branch (31:11): [True: 145k, False: 14.1k]
  ------------------
   32|       |      /* is the pad empty? */
   33|   145k|      if (ctr->padlen == ctr->blocklen) {
  ------------------
  |  Branch (33:11): [True: 140k, False: 4.81k]
  ------------------
   34|       |         /* increment counter */
   35|   140k|         if (ctr->mode == CTR_COUNTER_LITTLE_ENDIAN) {
  ------------------
  |  |  859|   140k|#define CTR_COUNTER_LITTLE_ENDIAN    0x0000
  ------------------
  |  Branch (35:14): [True: 0, False: 140k]
  ------------------
   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|   140k|         } else {
   44|       |            /* big-endian */
   45|   141k|            for (x = ctr->blocklen-1; x >= ctr->ctrlen; x--) {
  ------------------
  |  Branch (45:39): [True: 141k, False: 0]
  ------------------
   46|   141k|               ctr->ctr[x] = (ctr->ctr[x] + (unsigned char)1) & (unsigned char)255;
   47|   141k|               if (ctr->ctr[x] != (unsigned char)0) {
  ------------------
  |  Branch (47:20): [True: 140k, False: 545]
  ------------------
   48|   140k|                  break;
   49|   140k|               }
   50|   141k|            }
   51|   140k|         }
   52|       |
   53|       |         /* encrypt it */
   54|   140k|         if ((err = cipher_descriptor[ctr->cipher].ecb_encrypt(ctr->ctr, ctr->pad, &ctr->key)) != CRYPT_OK) {
  ------------------
  |  Branch (54:14): [True: 0, False: 140k]
  ------------------
   55|      0|            return err;
   56|      0|         }
   57|   140k|         ctr->padlen = 0;
   58|   140k|      }
   59|   145k|#ifdef LTC_FAST
   60|   145k|      if ((ctr->padlen == 0) && (len >= (unsigned long)ctr->blocklen)) {
  ------------------
  |  Branch (60:11): [True: 145k, False: 0]
  |  Branch (60:33): [True: 145k, False: 0]
  ------------------
   61|   436k|         for (x = 0; x < ctr->blocklen; x += sizeof(LTC_FAST_TYPE)) {
  ------------------
  |  Branch (61:22): [True: 290k, False: 145k]
  ------------------
   62|   290k|            *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)ct + x)) = *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)pt + x)) ^
  ------------------
  |  |  244|   290k|   #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|   290k|   #define LTC_FAST_TYPE_PTR_CAST(x) ((LTC_FAST_TYPE*)(void*)(x))
  ------------------
   63|   290k|                                                           *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)ctr->pad + x));
  ------------------
  |  |  244|   290k|   #define LTC_FAST_TYPE_PTR_CAST(x) ((LTC_FAST_TYPE*)(void*)(x))
  ------------------
   64|   290k|         }
   65|   145k|       pt         += ctr->blocklen;
   66|   145k|       ct         += ctr->blocklen;
   67|   145k|       len        -= ctr->blocklen;
   68|   145k|       ctr->padlen = ctr->blocklen;
   69|   145k|       continue;
   70|   145k|      }
   71|      0|#endif
   72|      0|      *ct++ = *pt++ ^ ctr->pad[ctr->padlen++];
   73|      0|      --len;
   74|      0|   }
   75|  14.1k|   return CRYPT_OK;
   76|  14.1k|}

ctr_start:
   35|  5.49k|{
   36|  5.49k|   int x, err;
   37|       |
   38|  5.49k|   LTC_ARGCHK(IV  != NULL);
  ------------------
  |  |   32|  5.49k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 5.49k]
  |  |  |  Branch (32:87): [Folded, False: 5.49k]
  |  |  ------------------
  ------------------
   39|  5.49k|   LTC_ARGCHK(key != NULL);
  ------------------
  |  |   32|  5.49k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 5.49k]
  |  |  |  Branch (32:87): [Folded, False: 5.49k]
  |  |  ------------------
  ------------------
   40|  5.49k|   LTC_ARGCHK(ctr != NULL);
  ------------------
  |  |   32|  5.49k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 5.49k]
  |  |  |  Branch (32:87): [Folded, False: 5.49k]
  |  |  ------------------
  ------------------
   41|       |
   42|       |   /* bad param? */
   43|  5.49k|   if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
  ------------------
  |  Branch (43:8): [True: 0, False: 5.49k]
  ------------------
   44|      0|      return err;
   45|      0|   }
   46|       |
   47|       |   /* ctrlen == counter width */
   48|  5.49k|   ctr->ctrlen   = (ctr_mode & 255) ? (ctr_mode & 255) : cipher_descriptor[cipher].block_length;
  ------------------
  |  Branch (48:20): [True: 0, False: 5.49k]
  ------------------
   49|  5.49k|   if (ctr->ctrlen > cipher_descriptor[cipher].block_length) {
  ------------------
  |  Branch (49:8): [True: 0, False: 5.49k]
  ------------------
   50|      0|      return CRYPT_INVALID_ARG;
   51|      0|   }
   52|       |
   53|  5.49k|   if ((ctr_mode & 0x1000) == CTR_COUNTER_BIG_ENDIAN) {
  ------------------
  |  |  860|  5.49k|#define CTR_COUNTER_BIG_ENDIAN       0x1000
  ------------------
  |  Branch (53:8): [True: 5.49k, False: 0]
  ------------------
   54|  5.49k|      ctr->ctrlen = cipher_descriptor[cipher].block_length - ctr->ctrlen;
   55|  5.49k|   }
   56|       |
   57|       |   /* setup cipher */
   58|  5.49k|   if ((err = cipher_descriptor[cipher].setup(key, keylen, num_rounds, &ctr->key)) != CRYPT_OK) {
  ------------------
  |  Branch (58:8): [True: 0, False: 5.49k]
  ------------------
   59|      0|      return err;
   60|      0|   }
   61|       |
   62|       |   /* copy ctr */
   63|  5.49k|   ctr->blocklen = cipher_descriptor[cipher].block_length;
   64|  5.49k|   ctr->cipher   = cipher;
   65|  5.49k|   ctr->padlen   = 0;
   66|  5.49k|   ctr->mode     = ctr_mode & 0x1000;
   67|  93.3k|   for (x = 0; x < ctr->blocklen; x++) {
  ------------------
  |  Branch (67:16): [True: 87.9k, False: 5.49k]
  ------------------
   68|  87.9k|       ctr->ctr[x] = IV[x];
   69|  87.9k|   }
   70|       |
   71|  5.49k|   if (ctr_mode & LTC_CTR_RFC3686) {
  ------------------
  |  |  861|  5.49k|#define LTC_CTR_RFC3686              0x2000
  ------------------
  |  Branch (71:8): [True: 0, False: 5.49k]
  ------------------
   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|  5.49k|   return cipher_descriptor[ctr->cipher].ecb_encrypt(ctr->ctr, ctr->pad, &ctr->key);
   93|  5.49k|}

chacha_crypt:
   55|  10.5k|{
   56|  10.5k|   unsigned char buf[64];
   57|  10.5k|   unsigned long i, j;
   58|       |
   59|  10.5k|   if (inlen == 0) return CRYPT_OK; /* nothing to do */
  ------------------
  |  Branch (59:8): [True: 0, False: 10.5k]
  ------------------
   60|       |
   61|  10.5k|   LTC_ARGCHK(st        != NULL);
  ------------------
  |  |   32|  10.5k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 10.5k]
  |  |  |  Branch (32:87): [Folded, False: 10.5k]
  |  |  ------------------
  ------------------
   62|  10.5k|   LTC_ARGCHK(in        != NULL);
  ------------------
  |  |   32|  10.5k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 10.5k]
  |  |  |  Branch (32:87): [Folded, False: 10.5k]
  |  |  ------------------
  ------------------
   63|  10.5k|   LTC_ARGCHK(out       != NULL);
  ------------------
  |  |   32|  10.5k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 10.5k]
  |  |  |  Branch (32:87): [Folded, False: 10.5k]
  |  |  ------------------
  ------------------
   64|  10.5k|   LTC_ARGCHK(st->ivlen != 0);
  ------------------
  |  |   32|  10.5k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 10.5k]
  |  |  |  Branch (32:87): [Folded, False: 10.5k]
  |  |  ------------------
  ------------------
   65|       |
   66|  10.5k|   if (st->ksleft > 0) {
  ------------------
  |  Branch (66:8): [True: 0, False: 10.5k]
  ------------------
   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|  14.5k|   for (;;) {
   75|  14.5k|     _chacha_block(buf, st->input, st->rounds);
   76|  14.5k|     if (st->ivlen == 8) {
  ------------------
  |  Branch (76:10): [True: 14.5k, False: 0]
  ------------------
   77|       |       /* IV-64bit, increment 64bit counter */
   78|  14.5k|       if (0 == ++st->input[12] && 0 == ++st->input[13]) return CRYPT_OVERFLOW;
  ------------------
  |  Branch (78:12): [True: 0, False: 14.5k]
  |  Branch (78:36): [True: 0, False: 0]
  ------------------
   79|  14.5k|     }
   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|  14.5k|     if (inlen <= 64) {
  ------------------
  |  Branch (84:10): [True: 10.5k, False: 3.98k]
  ------------------
   85|   201k|       for (i = 0; i < inlen; ++i) out[i] = in[i] ^ buf[i];
  ------------------
  |  Branch (85:20): [True: 191k, False: 10.5k]
  ------------------
   86|  10.5k|       st->ksleft = 64 - inlen;
   87|   493k|       for (i = inlen; i < 64; ++i) st->kstream[i] = buf[i];
  ------------------
  |  Branch (87:24): [True: 482k, False: 10.5k]
  ------------------
   88|  10.5k|       return CRYPT_OK;
   89|  10.5k|     }
   90|   259k|     for (i = 0; i < 64; ++i) out[i] = in[i] ^ buf[i];
  ------------------
  |  Branch (90:18): [True: 255k, False: 3.98k]
  ------------------
   91|  3.98k|     inlen -= 64;
   92|  3.98k|     out += 64;
   93|  3.98k|     in  += 64;
   94|  3.98k|   }
   95|  10.5k|}
chacha_crypt.c:_chacha_block:
   26|  14.5k|{
   27|  14.5k|   ulong32 x[16];
   28|  14.5k|   int i;
   29|  14.5k|   XMEMCPY(x, input, sizeof(x));
  ------------------
  |  |   39|  14.5k|#define XMEMCPY  memcpy
  ------------------
   30|   159k|   for (i = rounds; i > 0; i -= 2) {
  ------------------
  |  Branch (30:21): [True: 145k, False: 14.5k]
  ------------------
   31|   145k|      QUARTERROUND(0, 4, 8,12)
  ------------------
  |  |   20|   145k|  x[a] += x[b]; x[d] = ROL(x[d] ^ x[a], 16); \
  |  |   21|   145k|  x[c] += x[d]; x[b] = ROL(x[b] ^ x[c], 12); \
  |  |   22|   145k|  x[a] += x[b]; x[d] = ROL(x[d] ^ x[a],  8); \
  |  |   23|   145k|  x[c] += x[d]; x[b] = ROL(x[b] ^ x[c],  7);
  ------------------
   32|   145k|      QUARTERROUND(1, 5, 9,13)
  ------------------
  |  |   20|   145k|  x[a] += x[b]; x[d] = ROL(x[d] ^ x[a], 16); \
  |  |   21|   145k|  x[c] += x[d]; x[b] = ROL(x[b] ^ x[c], 12); \
  |  |   22|   145k|  x[a] += x[b]; x[d] = ROL(x[d] ^ x[a],  8); \
  |  |   23|   145k|  x[c] += x[d]; x[b] = ROL(x[b] ^ x[c],  7);
  ------------------
   33|   145k|      QUARTERROUND(2, 6,10,14)
  ------------------
  |  |   20|   145k|  x[a] += x[b]; x[d] = ROL(x[d] ^ x[a], 16); \
  |  |   21|   145k|  x[c] += x[d]; x[b] = ROL(x[b] ^ x[c], 12); \
  |  |   22|   145k|  x[a] += x[b]; x[d] = ROL(x[d] ^ x[a],  8); \
  |  |   23|   145k|  x[c] += x[d]; x[b] = ROL(x[b] ^ x[c],  7);
  ------------------
   34|   145k|      QUARTERROUND(3, 7,11,15)
  ------------------
  |  |   20|   145k|  x[a] += x[b]; x[d] = ROL(x[d] ^ x[a], 16); \
  |  |   21|   145k|  x[c] += x[d]; x[b] = ROL(x[b] ^ x[c], 12); \
  |  |   22|   145k|  x[a] += x[b]; x[d] = ROL(x[d] ^ x[a],  8); \
  |  |   23|   145k|  x[c] += x[d]; x[b] = ROL(x[b] ^ x[c],  7);
  ------------------
   35|   145k|      QUARTERROUND(0, 5,10,15)
  ------------------
  |  |   20|   145k|  x[a] += x[b]; x[d] = ROL(x[d] ^ x[a], 16); \
  |  |   21|   145k|  x[c] += x[d]; x[b] = ROL(x[b] ^ x[c], 12); \
  |  |   22|   145k|  x[a] += x[b]; x[d] = ROL(x[d] ^ x[a],  8); \
  |  |   23|   145k|  x[c] += x[d]; x[b] = ROL(x[b] ^ x[c],  7);
  ------------------
   36|   145k|      QUARTERROUND(1, 6,11,12)
  ------------------
  |  |   20|   145k|  x[a] += x[b]; x[d] = ROL(x[d] ^ x[a], 16); \
  |  |   21|   145k|  x[c] += x[d]; x[b] = ROL(x[b] ^ x[c], 12); \
  |  |   22|   145k|  x[a] += x[b]; x[d] = ROL(x[d] ^ x[a],  8); \
  |  |   23|   145k|  x[c] += x[d]; x[b] = ROL(x[b] ^ x[c],  7);
  ------------------
   37|   145k|      QUARTERROUND(2, 7, 8,13)
  ------------------
  |  |   20|   145k|  x[a] += x[b]; x[d] = ROL(x[d] ^ x[a], 16); \
  |  |   21|   145k|  x[c] += x[d]; x[b] = ROL(x[b] ^ x[c], 12); \
  |  |   22|   145k|  x[a] += x[b]; x[d] = ROL(x[d] ^ x[a],  8); \
  |  |   23|   145k|  x[c] += x[d]; x[b] = ROL(x[b] ^ x[c],  7);
  ------------------
   38|   145k|      QUARTERROUND(3, 4, 9,14)
  ------------------
  |  |   20|   145k|  x[a] += x[b]; x[d] = ROL(x[d] ^ x[a], 16); \
  |  |   21|   145k|  x[c] += x[d]; x[b] = ROL(x[b] ^ x[c], 12); \
  |  |   22|   145k|  x[a] += x[b]; x[d] = ROL(x[d] ^ x[a],  8); \
  |  |   23|   145k|  x[c] += x[d]; x[b] = ROL(x[b] ^ x[c],  7);
  ------------------
   39|   145k|   }
   40|   246k|   for (i = 0; i < 16; ++i) {
  ------------------
  |  Branch (40:16): [True: 232k, False: 14.5k]
  ------------------
   41|   232k|     x[i] += input[i];
   42|   232k|     STORE32L(x[i], output + 4 * i);
  ------------------
  |  |  164|   232k|  do { ulong32 __t = (x); XMEMCPY(y, &__t, 4); } while(0)
  |  |  ------------------
  |  |  |  |   39|   232k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (164:56): [Folded, False: 232k]
  |  |  ------------------
  ------------------
   43|   232k|   }
   44|  14.5k|}

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

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

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

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, False: 128]
  |  |  ------------------
  ------------------
   84|    128|   mp_clamp(c);
   85|       |
   86|    128|   return MP_OKAY;
  ------------------
  |  |  161|    128|#define MP_OKAY       0   /* no error */
  ------------------
   87|    128|}

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

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

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|       |   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|  24.6k|{
    9|  24.6k|   int n;
   10|  24.6k|   mp_digit *tmpa, *tmpb;
   11|  24.6k|   mp_err err;
   12|       |
   13|       |   /* if dst == src do nothing */
   14|  24.6k|   if (a == b) {
  ------------------
  |  Branch (14:8): [True: 18.5k, False: 6.17k]
  ------------------
   15|  18.5k|      return MP_OKAY;
  ------------------
  |  |  161|  18.5k|#define MP_OKAY       0   /* no error */
  ------------------
   16|  18.5k|   }
   17|       |
   18|       |   /* grow dest */
   19|  6.17k|   if (b->alloc < a->used) {
  ------------------
  |  Branch (19:8): [True: 0, False: 6.17k]
  ------------------
   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|  6.17k|   tmpa = a->dp;
   30|       |
   31|       |   /* destination */
   32|  6.17k|   tmpb = b->dp;
   33|       |
   34|       |   /* copy all the digits */
   35|  12.3k|   for (n = 0; n < a->used; n++) {
  ------------------
  |  Branch (35:16): [True: 6.19k, False: 6.17k]
  ------------------
   36|  6.19k|      *tmpb++ = *tmpa++;
   37|  6.19k|   }
   38|       |
   39|       |   /* clear high digits */
   40|  6.17k|   MP_ZERO_DIGITS(tmpb, b->used - n);
  ------------------
  |  |   89|  6.17k|#  define MP_ZERO_DIGITS(mem, digits)                   \
  |  |   90|  6.17k|do {                                                    \
  |  |   91|  6.17k|   int zd_ = (digits);                                  \
  |  |   92|  6.17k|   mp_digit* zm_ = (mem);                               \
  |  |   93|  6.17k|   while (zd_-- > 0) {                                  \
  |  |  ------------------
  |  |  |  Branch (93:11): [True: 0, False: 6.17k]
  |  |  ------------------
  |  |   94|      0|      *zm_++ = 0;                                       \
  |  |   95|      0|   }                                                    \
  |  |   96|  6.17k|} while (0)
  |  |  ------------------
  |  |  |  Branch (96:10): [Folded, False: 6.17k]
  |  |  ------------------
  ------------------
   41|       |
   42|       |   /* copy used count and sign */
   43|  6.17k|   b->used = a->used;
   44|  6.17k|   b->sign = a->sign;
   45|  6.17k|   return MP_OKAY;
  ------------------
  |  |  161|  6.17k|#define MP_OKAY       0   /* no error */
  ------------------
   46|  6.17k|}

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

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|  18.5k|{
    9|  18.5k|   mp_digit D, r, rr;
   10|  18.5k|   int     x;
   11|  18.5k|   mp_err err;
   12|       |
   13|       |   /* if the shift count is <= 0 then we do no work */
   14|  18.5k|   if (b <= 0) {
  ------------------
  |  Branch (14:8): [True: 0, False: 18.5k]
  ------------------
   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|  18.5k|   if ((err = mp_copy(a, c)) != MP_OKAY) {
  ------------------
  |  |  161|  18.5k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (23:8): [True: 0, False: 18.5k]
  ------------------
   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|  18.5k|   if (d != NULL) {
  ------------------
  |  Branch (29:8): [True: 0, False: 18.5k]
  ------------------
   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|  18.5k|   if (b >= MP_DIGIT_BIT) {
  ------------------
  |  |   82|  18.5k|#   define MP_DIGIT_BIT 60
  ------------------
  |  Branch (36:8): [True: 0, False: 18.5k]
  ------------------
   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|  18.5k|   D = (mp_digit)(b % MP_DIGIT_BIT);
  ------------------
  |  |   82|  18.5k|#   define MP_DIGIT_BIT 60
  ------------------
   42|  18.5k|   if (D != 0u) {
  ------------------
  |  Branch (42:8): [True: 18.5k, False: 0]
  ------------------
   43|  18.5k|      mp_digit *tmpc, mask, shift;
   44|       |
   45|       |      /* mask */
   46|  18.5k|      mask = ((mp_digit)1 << D) - 1uL;
   47|       |
   48|       |      /* shift for lsb */
   49|  18.5k|      shift = (mp_digit)MP_DIGIT_BIT - D;
  ------------------
  |  |   82|  18.5k|#   define MP_DIGIT_BIT 60
  ------------------
   50|       |
   51|       |      /* alias */
   52|  18.5k|      tmpc = c->dp + (c->used - 1);
   53|       |
   54|       |      /* carry */
   55|  18.5k|      r = 0;
   56|  37.0k|      for (x = c->used - 1; x >= 0; x--) {
  ------------------
  |  Branch (56:29): [True: 18.5k, False: 18.5k]
  ------------------
   57|       |         /* get the lower  bits of this word in a temp */
   58|  18.5k|         rr = *tmpc & mask;
   59|       |
   60|       |         /* shift the current word and mix in the carry bits from the previous word */
   61|  18.5k|         *tmpc = (*tmpc >> D) | (r << shift);
   62|  18.5k|         --tmpc;
   63|       |
   64|       |         /* set the carry to the carry bits of the current word found above */
   65|  18.5k|         r = rr;
   66|  18.5k|      }
   67|  18.5k|   }
   68|  18.5k|   mp_clamp(c);
   69|  18.5k|   return MP_OKAY;
  ------------------
  |  |  161|  18.5k|#define MP_OKAY       0   /* no error */
  ------------------
   70|  18.5k|}

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|    125|{
    9|    125|   mp_err err;
   10|       |
   11|       |   /* make sure there are at least two digits */
   12|    125|   if (a->alloc < 2) {
  ------------------
  |  Branch (12:8): [True: 0, False: 125]
  ------------------
   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|    125|   mp_zero(a);
   20|       |
   21|       |   /* read the bytes in */
   22|  16.9k|   while (size-- > 0u) {
  ------------------
  |  Branch (22:11): [True: 16.8k, False: 125]
  ------------------
   23|  16.8k|      if ((err = mp_mul_2d(a, 8, a)) != MP_OKAY) {
  ------------------
  |  |  161|  16.8k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (23:11): [True: 0, False: 16.8k]
  ------------------
   24|      0|         return err;
   25|      0|      }
   26|       |
   27|  16.8k|#ifndef MP_8BIT
   28|  16.8k|      a->dp[0] |= *buf++;
   29|  16.8k|      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|  16.8k|   }
   36|    125|   mp_clamp(a);
   37|    125|   return MP_OKAY;
  ------------------
  |  |  161|    125|#define MP_OKAY       0   /* no error */
  ------------------
   38|    125|}

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

mp_init:
    8|  7.94k|{
    9|       |   /* allocate memory required and clear it */
   10|  7.94k|   a->dp = (mp_digit *) MP_CALLOC((size_t)MP_PREC, sizeof(mp_digit));
  ------------------
  |  | 1326|  7.94k|#define MP_CALLOC    m_calloc
  ------------------
                 a->dp = (mp_digit *) MP_CALLOC((size_t)MP_PREC, sizeof(mp_digit));
  ------------------
  |  |  177|  7.94k|#   define MP_PREC PRIVATE_MP_PREC
  |  |  ------------------
  |  |  |  |  193|  7.94k|#      define PRIVATE_MP_PREC 32        /* default digits of precision */
  |  |  ------------------
  ------------------
   11|  7.94k|   if (a->dp == NULL) {
  ------------------
  |  Branch (11:8): [True: 0, False: 7.94k]
  ------------------
   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|  7.94k|   a->used  = 0;
   18|  7.94k|   a->alloc = MP_PREC;
  ------------------
  |  |  177|  7.94k|#   define MP_PREC PRIVATE_MP_PREC
  |  |  ------------------
  |  |  |  |  193|  7.94k|#      define PRIVATE_MP_PREC 32        /* default digits of precision */
  |  |  ------------------
  ------------------
   19|  7.94k|   a->sign  = MP_ZPOS;
  ------------------
  |  |  151|  7.94k|#define MP_ZPOS       0   /* positive integer */
  ------------------
   20|       |
   21|  7.94k|   return MP_OKAY;
  ------------------
  |  |  161|  7.94k|#define MP_OKAY       0   /* no error */
  ------------------
   22|  7.94k|}

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

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

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

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, False: 148]
  |  |  ------------------
  ------------------
   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, False: 2]
  |  |  ------------------
  ------------------
   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, False: 1]
  |  |  ------------------
  ------------------
   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, False: 2]
  |  |  ------------------
  ------------------
   11|      0|       (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, False: 2]
  |  |  ------------------
  ------------------
   14|      0|              (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): [True: 2, Folded]
  |  |  ------------------
  ------------------
   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): [True: 0, Folded]
  |  |  ------------------
  ------------------
   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|  6.16k|{
    9|  6.16k|   size_t  x, count;
   10|  6.16k|   mp_err  err;
   11|  6.16k|   mp_int  t;
   12|       |
   13|  6.16k|   count = mp_ubin_size(a);
   14|  6.16k|   if (count > maxlen) {
  ------------------
  |  Branch (14:8): [True: 0, False: 6.16k]
  ------------------
   15|      0|      return MP_BUF;
  ------------------
  |  |  167|      0|#define MP_BUF        -5  /* buffer overflow, supplied buffer too small */
  ------------------
   16|      0|   }
   17|       |
   18|  6.16k|   if ((err = mp_init_copy(&t, a)) != MP_OKAY) {
  ------------------
  |  |  161|  6.16k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (18:8): [True: 0, False: 6.16k]
  ------------------
   19|      0|      return err;
   20|      0|   }
   21|       |
   22|  24.6k|   for (x = count; x --> 0u;) {
  ------------------
  |  Branch (22:20): [True: 18.5k, False: 6.16k]
  ------------------
   23|  18.5k|#ifndef MP_8BIT
   24|  18.5k|      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|  18.5k|      if ((err = mp_div_2d(&t, 8, &t, NULL)) != MP_OKAY) {
  ------------------
  |  |  161|  18.5k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (28:11): [True: 0, False: 18.5k]
  ------------------
   29|      0|         goto LBL_ERR;
   30|      0|      }
   31|  18.5k|   }
   32|       |
   33|  6.16k|   if (written != NULL) {
  ------------------
  |  Branch (33:8): [True: 6.16k, False: 0]
  ------------------
   34|  6.16k|      *written = count;
   35|  6.16k|   }
   36|       |
   37|  6.16k|LBL_ERR:
   38|  6.16k|   mp_clear(&t);
   39|  6.16k|   return err;
   40|  6.16k|}

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

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

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

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

buf_new:
   41|   120k|buffer* buf_new(unsigned int size) {
   42|   120k|	buffer* buf;
   43|   120k|	if (size > BUF_MAX_SIZE) {
  ------------------
  |  |   35|   120k|#define BUF_MAX_SIZE 1000000000
  ------------------
  |  Branch (43:6): [True: 0, False: 120k]
  ------------------
   44|      0|		dropbear_exit("buf->size too big");
   45|      0|	}
   46|       |
   47|   120k|	buf = (buffer*)m_malloc(sizeof(buffer)+size);
   48|   120k|	buf->data = (unsigned char*)buf + sizeof(buffer);
   49|   120k|	buf->size = size;
   50|   120k|	return buf;
   51|   120k|}
buf_free:
   54|  91.1k|void buf_free(buffer* buf) {
   55|       |	m_free(buf);
  ------------------
  |  |   24|  91.1k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 91.1k]
  |  |  ------------------
  ------------------
   56|  91.1k|}
buf_burn_free:
   59|  27.5k|void buf_burn_free(buffer* buf) {
   60|  27.5k|	m_burn(buf->data, buf->size);
   61|       |	m_free(buf);
  ------------------
  |  |   24|  27.5k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 27.5k]
  |  |  ------------------
  ------------------
   62|  27.5k|}
buf_resize:
   67|  7.53k|buffer* buf_resize(buffer *buf, unsigned int newsize) {
   68|  7.53k|	if (newsize > BUF_MAX_SIZE) {
  ------------------
  |  |   35|  7.53k|#define BUF_MAX_SIZE 1000000000
  ------------------
  |  Branch (68:6): [True: 0, False: 7.53k]
  ------------------
   69|      0|		dropbear_exit("buf->size too big");
   70|      0|	}
   71|       |
   72|  7.53k|	buf = m_realloc(buf, sizeof(buffer)+newsize);
   73|  7.53k|	buf->data = (unsigned char*)buf + sizeof(buffer);
   74|  7.53k|	buf->size = newsize;
   75|  7.53k|	buf->len = MIN(newsize, buf->len);
  ------------------
  |  Branch (75:13): [True: 0, False: 7.53k]
  ------------------
   76|       |	buf->pos = MIN(newsize, buf->pos);
  ------------------
  |  Branch (76:13): [True: 0, False: 7.53k]
  ------------------
   77|  7.53k|	return buf;
   78|  7.53k|}
buf_newcopy:
   82|  9.20k|buffer* buf_newcopy(const buffer* buf) {
   83|       |	
   84|  9.20k|	buffer* ret;
   85|       |
   86|  9.20k|	ret = buf_new(buf->len);
   87|  9.20k|	ret->len = buf->len;
   88|  9.20k|	if (buf->len > 0) {
  ------------------
  |  Branch (88:6): [True: 9.20k, False: 0]
  ------------------
   89|  9.20k|		memcpy(ret->data, buf->data, buf->len);
   90|  9.20k|	}
   91|  9.20k|	return ret;
   92|  9.20k|}
buf_setlen:
   95|   161k|void buf_setlen(buffer* buf, unsigned int len) {
   96|   161k|	if (len > buf->size) {
  ------------------
  |  Branch (96:6): [True: 0, False: 161k]
  ------------------
   97|      0|		dropbear_exit("Bad buf_setlen");
   98|      0|	}
   99|   161k|	buf->len = len;
  100|       |	buf->pos = MIN(buf->pos, buf->len);
  ------------------
  |  Branch (100:13): [True: 126k, False: 35.3k]
  ------------------
  101|   161k|}
buf_incrlen:
  104|   209k|void buf_incrlen(buffer* buf, unsigned int incr) {
  105|   209k|	if (incr > BUF_MAX_INCR || buf->len + incr > buf->size) {
  ------------------
  |  |   34|   418k|#define BUF_MAX_INCR 1000000000
  ------------------
  |  Branch (105:6): [True: 0, False: 209k]
  |  Branch (105:29): [True: 0, False: 209k]
  ------------------
  106|      0|		dropbear_exit("Bad buf_incrlen");
  107|      0|	}
  108|   209k|	buf->len += incr;
  109|   209k|}
buf_setpos:
  111|   644k|void buf_setpos(buffer* buf, unsigned int pos) {
  112|       |
  113|   644k|	if (pos > buf->len) {
  ------------------
  |  Branch (113:6): [True: 0, False: 644k]
  ------------------
  114|      0|		dropbear_exit("Bad buf_setpos");
  115|      0|	}
  116|   644k|	buf->pos = pos;
  117|   644k|}
buf_incrwritepos:
  120|   726k|void buf_incrwritepos(buffer* buf, unsigned int incr) {
  121|   726k|	if (incr > BUF_MAX_INCR || buf->pos + incr > buf->size) {
  ------------------
  |  |   34|  1.45M|#define BUF_MAX_INCR 1000000000
  ------------------
  |  Branch (121:6): [True: 0, False: 726k]
  |  Branch (121:29): [True: 0, False: 726k]
  ------------------
  122|      0|		dropbear_exit("Bad buf_incrwritepos");
  123|      0|	}
  124|   726k|	buf->pos += incr;
  125|   726k|	if (buf->pos > buf->len) {
  ------------------
  |  Branch (125:6): [True: 535k, False: 191k]
  ------------------
  126|   535k|		buf->len = buf->pos;
  127|   535k|	}
  128|   726k|}
buf_incrpos:
  131|   672k|void buf_incrpos(buffer* buf, unsigned int incr) {
  132|   672k|	if (incr > BUF_MAX_INCR 
  ------------------
  |  |   34|  1.34M|#define BUF_MAX_INCR 1000000000
  ------------------
  |  Branch (132:6): [True: 17, False: 672k]
  ------------------
  133|   672k|		|| (buf->pos + incr) > buf->len) {
  ------------------
  |  Branch (133:6): [True: 111, False: 672k]
  ------------------
  134|    128|		dropbear_exit("Bad buf_incrpos");
  135|    128|	}
  136|   672k|	buf->pos += incr;
  137|   672k|}
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|   126k|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|   126k|	if (buf->pos >= buf->len) {
  ------------------
  |  Branch (152:6): [True: 3, False: 126k]
  ------------------
  153|      3|		dropbear_exit("Bad buf_getbyte");
  154|      3|	}
  155|   126k|	return buf->data[buf->pos++];
  156|   126k|}
buf_getbool:
  159|  6.87k|unsigned char buf_getbool(buffer* buf) {
  160|       |
  161|  6.87k|	unsigned char b;
  162|  6.87k|	b = buf_getbyte(buf);
  163|  6.87k|	if (b != 0)
  ------------------
  |  Branch (163:6): [True: 535, False: 6.34k]
  ------------------
  164|    535|		b = 1;
  165|  6.87k|	return b;
  166|  6.87k|}
buf_putbyte:
  169|   200k|void buf_putbyte(buffer* buf, unsigned char val) {
  170|       |
  171|   200k|	if (buf->pos >= buf->len) {
  ------------------
  |  Branch (171:6): [True: 165k, False: 35.3k]
  ------------------
  172|   165k|		buf_incrlen(buf, 1);
  173|   165k|	}
  174|   200k|	buf->data[buf->pos] = val;
  175|   200k|	buf->pos++;
  176|   200k|}
buf_getptr:
  180|   834k|unsigned char* buf_getptr(const buffer* buf, unsigned int len) {
  181|       |
  182|   834k|	if (len > BUF_MAX_INCR || buf->pos + len > buf->len) {
  ------------------
  |  |   34|  1.66M|#define BUF_MAX_INCR 1000000000
  ------------------
  |  Branch (182:6): [True: 9, False: 833k]
  |  Branch (182:28): [True: 230, False: 833k]
  ------------------
  183|    239|		dropbear_exit("Bad buf_getptr");
  184|    239|	}
  185|   833k|	return &buf->data[buf->pos];
  186|   834k|}
buf_getwriteptr:
  190|   797k|unsigned char* buf_getwriteptr(const buffer* buf, unsigned int len) {
  191|       |
  192|   797k|	if (len > BUF_MAX_INCR || buf->pos + len > buf->size) {
  ------------------
  |  |   34|  1.59M|#define BUF_MAX_INCR 1000000000
  ------------------
  |  Branch (192:6): [True: 0, False: 797k]
  |  Branch (192:28): [True: 0, False: 797k]
  ------------------
  193|      0|		dropbear_exit("Bad buf_getwriteptr");
  194|      0|	}
  195|   797k|	return &buf->data[buf->pos];
  196|   797k|}
buf_getstring:
  201|  70.2k|char* buf_getstring(buffer* buf, unsigned int *retlen) {
  202|       |
  203|  70.2k|	unsigned int len;
  204|  70.2k|	char* ret;
  205|  70.2k|	void* src = NULL;
  206|  70.2k|	len = buf_getint(buf);
  207|  70.2k|	if (len > MAX_STRING_LEN) {
  ------------------
  |  |  253|  70.2k|#define MAX_STRING_LEN (MAX(MAX_CMD_LEN, 2400)) /* Sun SSH needs 2400 for algos,
  ------------------
  |  Branch (207:6): [True: 61, False: 70.2k]
  |  Branch (207:12): [True: 70.2k, Folded]
  ------------------
  208|     61|		dropbear_exit("String too long");
  209|     61|	}
  210|       |
  211|  70.2k|	if (retlen != NULL) {
  ------------------
  |  Branch (211:6): [True: 70.1k, False: 40]
  ------------------
  212|  70.1k|		*retlen = len;
  213|  70.1k|	}
  214|  70.2k|	src = buf_getptr(buf, len);
  215|  70.2k|	ret = m_malloc(len+1);
  216|  70.2k|	memcpy(ret, src, len);
  217|  70.2k|	buf_incrpos(buf, len);
  218|  70.2k|	ret[len] = '\0';
  219|       |
  220|  70.2k|	return ret;
  221|  70.2k|}
buf_getstringbuf:
  246|  4.65k|buffer * buf_getstringbuf(buffer *buf) {
  247|  4.65k|	return buf_getstringbuf_int(buf, 0);
  248|  4.65k|}
buf_eatstring:
  266|  13.1k|void buf_eatstring(buffer *buf) {
  267|       |
  268|  13.1k|	buf_incrpos( buf, buf_getint(buf) );
  269|  13.1k|}
buf_getint:
  272|   139k|unsigned int buf_getint(buffer* buf) {
  273|   139k|	unsigned int ret;
  274|       |
  275|   139k|	LOAD32H(ret, buf_getptr(buf, 4));
  ------------------
  |  |   66|   139k|#define LOAD32H(x, y)                           \
  |  |   67|   139k|do { XMEMCPY (&(x), (y), 4);                    \
  |  |  ------------------
  |  |  |  |   39|   139k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |   68|   139k|      (x) = __builtin_bswap32 ((x)); } while(0)
  |  |  ------------------
  |  |  |  Branch (68:46): [Folded, False: 139k]
  |  |  ------------------
  ------------------
  276|   139k|	buf_incrpos(buf, 4);
  277|   139k|	return ret;
  278|   139k|}
buf_putint:
  281|   235k|void buf_putint(buffer* buf, int unsigned val) {
  282|       |
  283|   235k|	STORE32H(val, buf_getwriteptr(buf, 4));
  ------------------
  |  |   62|   235k|#define STORE32H(x, y)                          \
  |  |   63|   235k|do { ulong32 __t = __builtin_bswap32 ((x));     \
  |  |   64|   235k|      XMEMCPY ((y), &__t, 4); } while(0)
  |  |  ------------------
  |  |  |  |   39|   235k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (64:39): [Folded, False: 235k]
  |  |  ------------------
  ------------------
  284|   235k|	buf_incrwritepos(buf, 4);
  285|       |
  286|   235k|}
buf_putstring:
  289|  43.1k|void buf_putstring(buffer* buf, const char* str, unsigned int len) {
  290|       |	
  291|  43.1k|	buf_putint(buf, len);
  292|  43.1k|	buf_putbytes(buf, (const unsigned char*)str, len);
  293|       |
  294|  43.1k|}
buf_putbufstring:
  297|    962|void buf_putbufstring(buffer *buf, const buffer* buf_str) {
  298|    962|	buf_putstring(buf, (const char*)buf_str->data, buf_str->len);
  299|    962|}
buf_putbytes:
  303|   255k|void buf_putbytes(buffer *buf, const unsigned char *bytes, unsigned int len) {
  304|   255k|	memcpy(buf_getwriteptr(buf, len), bytes, len);
  305|   255k|	buf_incrwritepos(buf, len);
  306|   255k|}
buf_putmpint:
  311|  6.16k|void buf_putmpint(buffer* buf, const mp_int * mp) {
  312|  6.16k|	size_t written;
  313|  6.16k|	unsigned int len, pad = 0;
  314|  6.16k|	TRACE2(("enter buf_putmpint"))
  315|       |
  316|  6.16k|	dropbear_assert(mp != NULL);
  ------------------
  |  |   84|  6.16k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (84:37): [True: 0, False: 6.16k]
  |  |  |  Branch (84:93): [Folded, False: 6.16k]
  |  |  ------------------
  ------------------
  317|       |
  318|  6.16k|	if (mp_isneg(mp)) {
  ------------------
  |  |  295|  6.16k|#define mp_isneg(a)  (((a)->sign != MP_ZPOS) ? MP_YES : MP_NO)
  |  |  ------------------
  |  |  |  |  151|  6.16k|#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|  6.16k|#define MP_NO         0
  |  |  ------------------
  |  |  |  Branch (295:22): [True: 0, False: 6.16k]
  |  |  |  Branch (295:23): [True: 0, False: 6.16k]
  |  |  ------------------
  ------------------
  319|      0|		dropbear_exit("negative bignum");
  320|      0|	}
  321|       |
  322|       |	/* zero check */
  323|  6.16k|	if (mp_iszero(mp)) {
  ------------------
  |  |  292|  6.16k|#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|  6.16k|#define MP_NO         0
  |  |  ------------------
  |  |  |  Branch (292:22): [True: 0, False: 6.16k]
  |  |  |  Branch (292:23): [True: 0, False: 6.16k]
  |  |  ------------------
  ------------------
  324|      0|		len = 0;
  325|  6.16k|	} else {
  326|       |		/* SSH spec requires padding for mpints with the MSB set, this code
  327|       |		 * implements it */
  328|  6.16k|		len = mp_count_bits(mp);
  329|       |		/* if the top bit of MSB is set, we need to pad */
  330|  6.16k|		pad = (len%8 == 0) ? 1 : 0;
  ------------------
  |  Branch (330:9): [True: 6.16k, False: 0]
  ------------------
  331|  6.16k|		len = len / 8 + 1; /* don't worry about rounding, we need it for
  332|       |							  padding anyway when len%8 == 0 */
  333|       |
  334|  6.16k|	}
  335|       |
  336|       |	/* store the length */
  337|  6.16k|	buf_putint(buf, len);
  338|       |	
  339|       |	/* store the actual value */
  340|  6.16k|	if (len > 0) {
  ------------------
  |  Branch (340:6): [True: 6.16k, False: 0]
  ------------------
  341|  6.16k|		if (pad) {
  ------------------
  |  Branch (341:7): [True: 6.16k, False: 0]
  ------------------
  342|  6.16k|			buf_putbyte(buf, 0x00);
  343|  6.16k|		}
  344|  6.16k|		if (mp_to_ubin(mp, buf_getwriteptr(buf, len-pad), len-pad, &written) != MP_OKAY) {
  ------------------
  |  |  161|  6.16k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (344:7): [True: 0, False: 6.16k]
  ------------------
  345|      0|			dropbear_exit("mpint error");
  346|      0|		}
  347|  6.16k|		buf_incrwritepos(buf, written);
  348|  6.16k|	}
  349|       |
  350|  6.16k|	TRACE2(("leave buf_putmpint"))
  351|  6.16k|}
buf_getmpint:
  356|  1.76k|int buf_getmpint(buffer* buf, mp_int* mp) {
  357|       |
  358|  1.76k|	unsigned int len;
  359|  1.76k|	len = buf_getint(buf);
  360|       |	
  361|  1.76k|	if (len == 0) {
  ------------------
  |  Branch (361:6): [True: 1.56k, False: 203]
  ------------------
  362|  1.56k|		mp_zero(mp);
  363|  1.56k|		return DROPBEAR_SUCCESS;
  ------------------
  |  |  111|  1.56k|#define DROPBEAR_SUCCESS 0
  ------------------
  364|  1.56k|	}
  365|       |
  366|    203|	if (len > BUF_MAX_MPINT) {
  ------------------
  |  |   38|    203|#define BUF_MAX_MPINT (8240 / 8)
  ------------------
  |  Branch (366:6): [True: 48, False: 155]
  ------------------
  367|     48|		return DROPBEAR_FAILURE;
  ------------------
  |  |  112|     48|#define DROPBEAR_FAILURE -1
  ------------------
  368|     48|	}
  369|       |
  370|       |	/* check for negative */
  371|    155|	if (*buf_getptr(buf, 1) & (1 << (CHAR_BIT-1))) {
  ------------------
  |  Branch (371:6): [True: 12, False: 143]
  ------------------
  372|     12|		return DROPBEAR_FAILURE;
  ------------------
  |  |  112|     12|#define DROPBEAR_FAILURE -1
  ------------------
  373|     12|	}
  374|       |
  375|    143|	if (mp_from_ubin(mp, buf_getptr(buf, len), len) != MP_OKAY) {
  ------------------
  |  |  161|    143|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (375:6): [True: 0, False: 143]
  ------------------
  376|      0|		return DROPBEAR_FAILURE;
  ------------------
  |  |  112|      0|#define DROPBEAR_FAILURE -1
  ------------------
  377|      0|	}
  378|       |
  379|    143|	buf_incrpos(buf, len);
  380|    143|	return DROPBEAR_SUCCESS;
  ------------------
  |  |  111|    143|#define DROPBEAR_SUCCESS 0
  ------------------
  381|    143|}
buffer.c:buf_getstringbuf_int:
  224|  4.65k|static buffer * buf_getstringbuf_int(buffer *buf, int incllen) {
  225|  4.65k|	buffer *ret = NULL;
  226|  4.65k|	unsigned int len = buf_getint(buf);
  227|  4.65k|	int extra = 0;
  228|  4.65k|	if (len > MAX_STRING_LEN) {
  ------------------
  |  |  253|  4.65k|#define MAX_STRING_LEN (MAX(MAX_CMD_LEN, 2400)) /* Sun SSH needs 2400 for algos,
  ------------------
  |  Branch (228:6): [True: 36, False: 4.61k]
  |  Branch (228:12): [True: 4.64k, Folded]
  ------------------
  229|     36|		dropbear_exit("String too long");
  230|     36|	}
  231|  4.61k|	if (incllen) {
  ------------------
  |  Branch (231:6): [True: 0, False: 4.61k]
  ------------------
  232|      0|		extra = 4;
  233|      0|	}
  234|  4.61k|	ret = buf_new(len+extra);
  235|  4.61k|	if (incllen) {
  ------------------
  |  Branch (235:6): [True: 0, False: 4.61k]
  ------------------
  236|      0|		buf_putint(ret, len);
  237|      0|	}
  238|  4.61k|	memcpy(buf_getwriteptr(ret, len), buf_getptr(buf, len), len);
  239|  4.61k|	buf_incrpos(buf, len);
  240|  4.61k|	buf_incrlen(ret, len);
  241|  4.61k|	buf_setpos(ret, 0);
  242|  4.61k|	return ret;
  243|  4.65k|}

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

buf_put_algolist_all:
  361|  61.4k|void buf_put_algolist_all(buffer * buf, const algo_type localalgos[], int useall) {
  362|  61.4k|	unsigned int i, len;
  363|  61.4k|	unsigned int donefirst = 0;
  364|  61.4k|	unsigned int startpos;
  365|       |
  366|  61.4k|	startpos = buf->pos;
  367|       |	/* Placeholder for length */
  368|  61.4k|	buf_putint(buf, 0); 
  369|   307k|	for (i = 0; localalgos[i].name != NULL; i++) {
  ------------------
  |  Branch (369:14): [True: 246k, False: 61.4k]
  ------------------
  370|   246k|		if (localalgos[i].usable || useall) {
  ------------------
  |  Branch (370:7): [True: 175k, False: 71.1k]
  |  Branch (370:31): [True: 736, False: 70.3k]
  ------------------
  371|   175k|			if (donefirst) {
  ------------------
  |  Branch (371:8): [True: 114k, False: 61.4k]
  ------------------
  372|   114k|				buf_putbyte(buf, ',');
  373|   114k|			}
  374|   175k|			donefirst = 1;
  375|   175k|			len = strlen(localalgos[i].name);
  376|   175k|			buf_putbytes(buf, (const unsigned char *) localalgos[i].name, len);
  377|   175k|		}
  378|   246k|	}
  379|       |	/* Fill out the length */
  380|  61.4k|	len = buf->pos - startpos - 4;
  381|  61.4k|	buf_setpos(buf, startpos);
  382|  61.4k|	buf_putint(buf, len);
  383|  61.4k|	TRACE(("algolist add %d '%.*s'", len, len, buf_getptr(buf, len)))
  384|  61.4k|	buf_incrwritepos(buf, len);
  385|  61.4k|}
buf_put_algolist:
  387|  61.3k|void buf_put_algolist(buffer * buf, const algo_type localalgos[]) {
  388|  61.3k|	buf_put_algolist_all(buf, localalgos, 0);
  389|  61.3k|}
buf_has_algo:
  433|  11.4k|int buf_has_algo(buffer *buf, const char *algo) {
  434|  11.4k|	unsigned char* algolist = NULL;
  435|  11.4k|	unsigned int orig_pos = buf->pos;
  436|  11.4k|	unsigned int len, remotecount, i;
  437|  11.4k|	const char *remotenames[MAX_PROPOSED_ALGO];
  438|  11.4k|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  112|  11.4k|#define DROPBEAR_FAILURE -1
  ------------------
  439|       |
  440|  11.4k|	algolist = buf_getstring(buf, &len);
  441|  11.4k|	remotecount = MAX_PROPOSED_ALGO;
  ------------------
  |  |  237|  11.4k|#define MAX_PROPOSED_ALGO 50
  ------------------
  442|  11.4k|	get_algolist(algolist, len, remotenames, &remotecount);
  443|  38.6k|	for (i = 0; i < remotecount; i++)
  ------------------
  |  Branch (443:14): [True: 27.6k, False: 10.9k]
  ------------------
  444|  27.6k|	{
  445|  27.6k|		if (strcmp(remotenames[i], algo) == 0) {
  ------------------
  |  Branch (445:7): [True: 479, False: 27.2k]
  ------------------
  446|    479|			ret = DROPBEAR_SUCCESS;
  ------------------
  |  |  111|    479|#define DROPBEAR_SUCCESS 0
  ------------------
  447|    479|			break;
  448|    479|		}
  449|  27.6k|	}
  450|  11.4k|	if (algolist) {
  ------------------
  |  Branch (450:6): [True: 11.3k, False: 63]
  ------------------
  451|       |		m_free(algolist);
  ------------------
  |  |   24|  11.3k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 11.3k]
  |  |  ------------------
  ------------------
  452|  11.3k|	}
  453|  11.4k|	buf_setpos(buf, orig_pos);
  454|  11.4k|	return ret;
  455|  11.4k|}
buf_match_algo:
  473|  53.7k|		int kexguess2, int *goodguess) {
  474|  53.7k|	char * algolist = NULL;
  475|  53.7k|	const char *remotenames[MAX_PROPOSED_ALGO], *localnames[MAX_PROPOSED_ALGO];
  476|  53.7k|	unsigned int len;
  477|  53.7k|	unsigned int remotecount, localcount, clicount, servcount, i, j;
  478|  53.7k|	algo_type * ret = NULL;
  479|  53.7k|	const char **clinames, **servnames;
  480|       |
  481|  53.7k|	if (goodguess) {
  ------------------
  |  Branch (481:6): [True: 13.7k, False: 40.0k]
  ------------------
  482|  13.7k|		*goodguess = 0;
  483|  13.7k|	}
  484|       |
  485|       |	/* get the comma-separated list from the buffer ie "algo1,algo2,algo3" */
  486|  53.7k|	algolist = buf_getstring(buf, &len);
  487|  53.7k|	DEBUG3(("buf_match_algo: %s", algolist))
  488|  53.7k|	remotecount = MAX_PROPOSED_ALGO;
  ------------------
  |  |  237|  53.7k|#define MAX_PROPOSED_ALGO 50
  ------------------
  489|  53.7k|	get_algolist(algolist, len, remotenames, &remotecount);
  490|       |
  491|   271k|	for (i = 0; localalgos[i].name != NULL; i++) {
  ------------------
  |  Branch (491:14): [True: 218k, False: 53.7k]
  ------------------
  492|   218k|		if (localalgos[i].usable) {
  ------------------
  |  Branch (492:7): [True: 151k, False: 66.8k]
  ------------------
  493|   151k|			localnames[i] = localalgos[i].name;
  494|   151k|		} else {
  495|  66.8k|			localnames[i] = NULL;
  496|  66.8k|		}
  497|   218k|	}
  498|  53.7k|	localcount = i;
  499|       |
  500|  53.7k|	if (IS_DROPBEAR_SERVER) {
  ------------------
  |  |  381|  53.7k|#define IS_DROPBEAR_SERVER (ses.isserver == 1)
  |  |  ------------------
  |  |  |  Branch (381:28): [True: 53.7k, False: 74]
  |  |  ------------------
  ------------------
  501|  53.7k|		clinames = remotenames;
  502|  53.7k|		clicount = remotecount;
  503|  53.7k|		servnames = localnames;
  504|  53.7k|		servcount = localcount;
  505|  53.7k|	} else {
  506|     74|		clinames = localnames;
  507|     74|		clicount = localcount;
  508|     74|		servnames = remotenames;
  509|     74|		servcount = remotecount;
  510|     74|	}
  511|       |
  512|       |	/* iterate and find the first match */
  513|  61.0k|	for (i = 0; i < clicount; i++) {
  ------------------
  |  Branch (513:14): [True: 59.0k, False: 1.96k]
  ------------------
  514|   230k|		for (j = 0; j < servcount; j++) {
  ------------------
  |  Branch (514:15): [True: 222k, False: 7.25k]
  ------------------
  515|   222k|			if (!(servnames[j] && clinames[i])) {
  ------------------
  |  Branch (515:10): [True: 141k, False: 81.0k]
  |  Branch (515:26): [True: 141k, False: 0]
  ------------------
  516|       |				/* unusable algos are NULL */
  517|  81.0k|				continue;
  518|  81.0k|			}
  519|   141k|			if (strcmp(servnames[j], clinames[i]) == 0) {
  ------------------
  |  Branch (519:8): [True: 51.8k, False: 90.1k]
  ------------------
  520|       |				/* set if it was a good guess */
  521|  51.8k|				if (goodguess != NULL) {
  ------------------
  |  Branch (521:9): [True: 13.4k, False: 38.3k]
  ------------------
  522|  13.4k|					if (kexguess2) {
  ------------------
  |  Branch (522:10): [True: 554, False: 12.9k]
  ------------------
  523|    554|						if (i == 0) {
  ------------------
  |  Branch (523:11): [True: 111, False: 443]
  ------------------
  524|    111|							*goodguess = 1;
  525|    111|						}
  526|  12.9k|					} else {
  527|  12.9k|						if (i == 0 && j == 0) {
  ------------------
  |  Branch (527:11): [True: 10.1k, False: 2.74k]
  |  Branch (527:21): [True: 4, False: 10.1k]
  ------------------
  528|      4|							*goodguess = 1;
  529|      4|						}
  530|  12.9k|					}
  531|  13.4k|				}
  532|       |				/* set the algo to return */
  533|  51.8k|				if (IS_DROPBEAR_SERVER) {
  ------------------
  |  |  381|  51.8k|#define IS_DROPBEAR_SERVER (ses.isserver == 1)
  |  |  ------------------
  |  |  |  Branch (381:28): [True: 51.8k, False: 0]
  |  |  ------------------
  ------------------
  534|  51.8k|					ret = &localalgos[j];
  535|  51.8k|				} else {
  536|      0|					ret = &localalgos[i];
  537|      0|				}
  538|  51.8k|				goto out;
  539|  51.8k|			}
  540|   141k|		}
  541|  59.0k|	}
  542|       |
  543|  53.7k|out:
  544|       |	m_free(algolist);
  ------------------
  |  |   24|  53.7k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 53.7k]
  |  |  ------------------
  ------------------
  545|  53.7k|	return ret;
  546|  53.7k|}
common-algo.c:void_start:
   52|  6.16k|			int UNUSED(keylen), int UNUSED(num_rounds), void* UNUSED(cipher_state)) {
   53|  6.16k|	return CRYPT_OK;
   54|  6.16k|}
common-algo.c:void_cipher:
   43|   102k|		unsigned long len, void* UNUSED(cipher_state)) {
   44|   102k|	if (in != out) {
  ------------------
  |  Branch (44:6): [True: 0, False: 102k]
  ------------------
   45|      0|		memmove(out, in, len);
   46|      0|	}
   47|   102k|	return CRYPT_OK;
   48|   102k|}
common-algo.c:dropbear_big_endian_ctr_start:
   93|  5.49k|		int num_rounds, symmetric_CTR *ctr) {
   94|  5.49k|	return ctr_start(cipher, IV, key, keylen, num_rounds, CTR_COUNTER_BIG_ENDIAN, ctr);
  ------------------
  |  |  860|  5.49k|#define CTR_COUNTER_BIG_ENDIAN       0x1000
  ------------------
   95|  5.49k|}
common-algo.c:get_algolist:
  396|  65.0k|				const char* *ret_list, unsigned int *ret_count) {
  397|  65.0k|	unsigned int max_count = *ret_count;
  398|  65.0k|	unsigned int i;
  399|       |
  400|  65.0k|	if (*ret_count == 0) {
  ------------------
  |  Branch (400:6): [True: 0, False: 65.0k]
  ------------------
  401|      0|		return;
  402|      0|	}
  403|  65.0k|	if (algolist_len > MAX_PROPOSED_ALGO*(MAX_NAME_LEN+1)) {
  ------------------
  |  |  237|  65.0k|#define MAX_PROPOSED_ALGO 50
  ------------------
              	if (algolist_len > MAX_PROPOSED_ALGO*(MAX_NAME_LEN+1)) {
  ------------------
  |  |  233|  65.0k|#define MAX_NAME_LEN 64 /* maximum length of a protocol name, isn't
  ------------------
  |  Branch (403:6): [True: 17, False: 65.0k]
  ------------------
  404|     17|		*ret_count = 0;
  405|     17|	}
  406|       |
  407|       |	/* ret_list will contain a list of the strings parsed out.
  408|       |	   We will have at least one string (even if it's just "") */
  409|  65.0k|	ret_list[0] = algolist;
  410|  65.0k|	*ret_count = 1;
  411|  1.27M|	for (i = 0; i < algolist_len; i++) {
  ------------------
  |  Branch (411:14): [True: 1.21M, False: 64.1k]
  ------------------
  412|  1.21M|		if (algolist[i] == '\0') {
  ------------------
  |  Branch (412:7): [True: 871, False: 1.21M]
  ------------------
  413|       |			/* someone is trying something strange */
  414|    871|			*ret_count = 0;
  415|    871|			return;
  416|    871|		}
  417|       |
  418|  1.21M|		if (algolist[i] == ',') {
  ------------------
  |  Branch (418:7): [True: 33.3k, False: 1.17M]
  ------------------
  419|  33.3k|			if (*ret_count >= max_count) {
  ------------------
  |  Branch (419:8): [True: 6, False: 33.3k]
  ------------------
  420|      6|				dropbear_exit("Too many remote algorithms");
  421|      0|				*ret_count = 0;
  422|      0|				return;
  423|      6|			}
  424|  33.3k|			algolist[i] = '\0';
  425|  33.3k|			ret_list[*ret_count] = &algolist[i+1];
  426|  33.3k|			(*ret_count)++;
  427|  33.3k|		}
  428|  1.21M|	}
  429|  65.0k|}

chaninitialise:
   70|  2.84k|void chaninitialise(const struct ChanType *chantypes[]) {
   71|       |
   72|       |	/* may as well create space for a single channel */
   73|  2.84k|	ses.channels = (struct Channel**)m_malloc(sizeof(struct Channel*));
   74|  2.84k|	ses.chansize = 1;
   75|  2.84k|	ses.channels[0] = NULL;
   76|  2.84k|	ses.chancount = 0;
   77|       |
   78|  2.84k|	ses.chantypes = chantypes;
   79|       |
   80|  2.84k|#if DROPBEAR_LISTENERS
   81|  2.84k|	listeners_initialise();
   82|  2.84k|#endif
   83|       |
   84|  2.84k|}
chancleanup:
   87|  2.84k|void chancleanup() {
   88|       |
   89|  2.84k|	unsigned int i;
   90|       |
   91|  2.84k|	TRACE(("enter chancleanup"))
   92|  5.68k|	for (i = 0; i < ses.chansize; i++) {
  ------------------
  |  Branch (92:14): [True: 2.84k, False: 2.84k]
  ------------------
   93|  2.84k|		if (ses.channels[i] != NULL) {
  ------------------
  |  Branch (93:7): [True: 0, False: 2.84k]
  ------------------
   94|      0|			TRACE(("channel %d closing", i))
   95|      0|			remove_channel(ses.channels[i]);
   96|      0|		}
   97|  2.84k|	}
   98|       |	m_free(ses.channels);
  ------------------
  |  |   24|  2.84k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 2.84k]
  |  |  ------------------
  ------------------
   99|  2.84k|	TRACE(("leave chancleanup"))
  100|  2.84k|}
channelio:
  199|   209k|void channelio(const fd_set *readfds, const fd_set *writefds) {
  200|       |
  201|       |	/* Listeners such as TCP, X11, agent-auth */
  202|   209k|	struct Channel *channel;
  203|   209k|	unsigned int i;
  204|       |
  205|       |	/* foreach channel */
  206|   419k|	for (i = 0; i < ses.chansize; i++) {
  ------------------
  |  Branch (206:14): [True: 209k, False: 209k]
  ------------------
  207|       |		/* Close checking only needs to occur for channels that had IO events */
  208|   209k|		int do_check_close = 0;
  209|       |
  210|   209k|		channel = ses.channels[i];
  211|   209k|		if (channel == NULL) {
  ------------------
  |  Branch (211:7): [True: 209k, False: 0]
  ------------------
  212|       |			/* only process in-use channels */
  213|   209k|			continue;
  214|   209k|		}
  215|       |
  216|       |		/* read data and send it over the wire */
  217|      0|		if (channel->readfd >= 0 && FD_ISSET(channel->readfd, readfds)) {
  ------------------
  |  Branch (217:7): [True: 0, False: 0]
  |  Branch (217:31): [True: 0, False: 0]
  ------------------
  218|      0|			TRACE(("send normal readfd"))
  219|      0|			send_msg_channel_data(channel, 0);
  220|      0|			do_check_close = 1;
  221|      0|		}
  222|       |
  223|       |		/* read stderr data and send it over the wire */
  224|      0|		if (ERRFD_IS_READ(channel) && channel->errfd >= 0 
  ------------------
  |  |   59|      0|#define ERRFD_IS_READ(channel) ((channel)->extrabuf == NULL)
  |  |  ------------------
  |  |  |  Branch (59:32): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (224:33): [True: 0, False: 0]
  ------------------
  225|      0|			&& FD_ISSET(channel->errfd, readfds)) {
  ------------------
  |  Branch (225:7): [True: 0, False: 0]
  ------------------
  226|      0|				TRACE(("send normal errfd"))
  227|      0|				send_msg_channel_data(channel, 1);
  228|      0|			do_check_close = 1;
  229|      0|		}
  230|       |
  231|       |		/* write to program/pipe stdin */
  232|      0|		if (channel->writefd >= 0 && FD_ISSET(channel->writefd, writefds)) {
  ------------------
  |  Branch (232:7): [True: 0, False: 0]
  |  Branch (232:32): [True: 0, False: 0]
  ------------------
  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|      0|		if (ERRFD_IS_WRITE(channel)
  ------------------
  |  |   60|      0|#define ERRFD_IS_WRITE(channel) (!ERRFD_IS_READ(channel))
  |  |  ------------------
  |  |  |  |   59|      0|#define ERRFD_IS_READ(channel) ((channel)->extrabuf == NULL)
  |  |  ------------------
  |  |  |  Branch (60:33): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  239|      0|				&& channel->errfd >= 0 && FD_ISSET(channel->errfd, writefds)) {
  ------------------
  |  Branch (239:8): [True: 0, False: 0]
  |  Branch (239:31): [True: 0, False: 0]
  ------------------
  240|      0|			writechannel(channel, channel->errfd, channel->extrabuf, NULL, NULL);
  241|      0|			do_check_close = 1;
  242|      0|		}
  243|       |
  244|      0|		if (ses.channel_signal_pending) {
  ------------------
  |  Branch (244:7): [True: 0, False: 0]
  ------------------
  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|      0|		if (do_check_close) {
  ------------------
  |  Branch (250:7): [True: 0, False: 0]
  ------------------
  251|      0|			check_close(channel);
  252|      0|		}
  253|      0|	}
  254|       |
  255|   209k|#if DROPBEAR_LISTENERS
  256|   209k|	handle_listeners(readfds);
  257|   209k|#endif
  258|   209k|}
setchannelfds:
  542|   212k|void setchannelfds(fd_set *readfds, fd_set *writefds, int allow_reads) {
  543|       |	
  544|   212k|	unsigned int i;
  545|   212k|	struct Channel * channel;
  546|       |	
  547|   424k|	for (i = 0; i < ses.chansize; i++) {
  ------------------
  |  Branch (547:14): [True: 212k, False: 212k]
  ------------------
  548|       |
  549|   212k|		channel = ses.channels[i];
  550|   212k|		if (channel == NULL) {
  ------------------
  |  Branch (550:7): [True: 212k, False: 0]
  ------------------
  551|   212k|			continue;
  552|   212k|		}
  553|       |
  554|       |		/* Stuff to put over the wire. 
  555|       |		Avoid queueing data to send if we're in the middle of a 
  556|       |		key re-exchange (!dataallowed), but still read from the 
  557|       |		FD if there's the possibility of "~."" to kill an 
  558|       |		interactive session (the read_mangler) */
  559|      0|		if (channel->transwindow > 0
  ------------------
  |  Branch (559:7): [True: 0, False: 0]
  ------------------
  560|      0|		   && ((ses.dataallowed && allow_reads) || channel->read_mangler)) {
  ------------------
  |  Branch (560:11): [True: 0, False: 0]
  |  Branch (560:30): [True: 0, False: 0]
  |  Branch (560:46): [True: 0, False: 0]
  ------------------
  561|       |
  562|      0|			if (channel->readfd >= 0) {
  ------------------
  |  Branch (562:8): [True: 0, False: 0]
  ------------------
  563|      0|				FD_SET(channel->readfd, readfds);
  564|      0|			}
  565|       |			
  566|      0|			if (ERRFD_IS_READ(channel) && channel->errfd >= 0) {
  ------------------
  |  |   59|      0|#define ERRFD_IS_READ(channel) ((channel)->extrabuf == NULL)
  |  |  ------------------
  |  |  |  Branch (59:32): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (566:34): [True: 0, False: 0]
  ------------------
  567|      0|					FD_SET(channel->errfd, readfds);
  568|      0|			}
  569|      0|		}
  570|       |
  571|       |		/* Stuff from the wire */
  572|      0|		if (channel->writefd >= 0 && cbuf_getused(channel->writebuf) > 0) {
  ------------------
  |  Branch (572:7): [True: 0, False: 0]
  |  Branch (572:32): [True: 0, False: 0]
  ------------------
  573|      0|				FD_SET(channel->writefd, writefds);
  574|      0|		}
  575|       |
  576|      0|		if (ERRFD_IS_WRITE(channel) && channel->errfd >= 0 
  ------------------
  |  |   60|      0|#define ERRFD_IS_WRITE(channel) (!ERRFD_IS_READ(channel))
  |  |  ------------------
  |  |  |  |   59|      0|#define ERRFD_IS_READ(channel) ((channel)->extrabuf == NULL)
  |  |  ------------------
  |  |  |  Branch (60:33): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (576:34): [True: 0, False: 0]
  ------------------
  577|      0|				&& cbuf_getused(channel->extrabuf) > 0) {
  ------------------
  |  Branch (577:8): [True: 0, False: 0]
  ------------------
  578|      0|				FD_SET(channel->errfd, writefds);
  579|      0|		}
  580|       |
  581|      0|	} /* foreach channel */
  582|       |
  583|   212k|#if DROPBEAR_LISTENERS
  584|   212k|	set_listener_fds(readfds);
  585|   212k|#endif
  586|       |
  587|   212k|}

send_msg_kexinit:
   51|  7.66k|void send_msg_kexinit() {
   52|       |
   53|  7.66k|	CHECKCLEARTOWRITE();
   54|  7.66k|	buf_putbyte(ses.writepayload, SSH_MSG_KEXINIT);
  ------------------
  |  |   36|  7.66k|#define SSH_MSG_KEXINIT                20
  ------------------
   55|       |
   56|       |	/* cookie */
   57|  7.66k|	genrandom(buf_getwriteptr(ses.writepayload, 16), 16);
   58|  7.66k|	buf_incrwritepos(ses.writepayload, 16);
   59|       |
   60|       |	/* kex algos */
   61|  7.66k|	buf_put_algolist(ses.writepayload, sshkex);
   62|       |
   63|       |	/* server_host_key_algorithms */
   64|  7.66k|	buf_put_algolist(ses.writepayload, sigalgs);
   65|       |
   66|       |	/* encryption_algorithms_client_to_server */
   67|  7.66k|	buf_put_algolist(ses.writepayload, sshciphers);
   68|       |
   69|       |	/* encryption_algorithms_server_to_client */
   70|  7.66k|	buf_put_algolist(ses.writepayload, sshciphers);
   71|       |
   72|       |	/* mac_algorithms_client_to_server */
   73|  7.66k|	buf_put_algolist(ses.writepayload, sshhashes);
   74|       |
   75|       |	/* mac_algorithms_server_to_client */
   76|  7.66k|	buf_put_algolist(ses.writepayload, sshhashes);
   77|       |
   78|       |
   79|       |	/* compression_algorithms_client_to_server */
   80|  7.66k|	buf_put_algolist(ses.writepayload, ses.compress_algos_c2s);
   81|       |
   82|       |	/* compression_algorithms_server_to_client */
   83|  7.66k|	buf_put_algolist(ses.writepayload, ses.compress_algos_s2c);
   84|       |
   85|       |	/* languages_client_to_server */
   86|  7.66k|	buf_putstring(ses.writepayload, "", 0);
   87|       |
   88|       |	/* languages_server_to_client */
   89|  7.66k|	buf_putstring(ses.writepayload, "", 0);
   90|       |
   91|       |	/* first_kex_packet_follows */
   92|  7.66k|	buf_putbyte(ses.writepayload, (ses.send_kex_first_guess != NULL));
   93|       |
   94|       |	/* reserved unit32 */
   95|  7.66k|	buf_putint(ses.writepayload, 0);
   96|       |
   97|       |	/* set up transmitted kex packet buffer for hashing. 
   98|       |	 * This is freed after the end of the kex */
   99|  7.66k|	ses.transkexinit = buf_newcopy(ses.writepayload);
  100|       |
  101|  7.66k|	encrypt_packet();
  102|  7.66k|	ses.dataallowed = 0; /* don't send other packets during kex */
  103|       |
  104|  7.66k|	ses.kexstate.sentkexinit = 1;
  105|       |
  106|  7.66k|	ses.newkeys = (struct key_context*)m_malloc(sizeof(struct key_context));
  107|       |
  108|  7.66k|	if (ses.send_kex_first_guess) {
  ------------------
  |  Branch (108:6): [True: 0, False: 7.66k]
  ------------------
  109|      0|		ses.newkeys->algo_kex = first_usable_algo(sshkex)->data;
  110|      0|		ses.newkeys->algo_signature = first_usable_algo(sigalgs)->val;
  111|      0|		ses.newkeys->algo_hostkey = signkey_type_from_signature(ses.newkeys->algo_signature);
  112|      0|		ses.send_kex_first_guess();
  113|      0|	}
  114|       |
  115|  7.66k|	TRACE(("DATAALLOWED=0"))
  116|  7.66k|	TRACE(("-> KEXINIT"))
  117|       |
  118|  7.66k|}
send_msg_newkeys:
  161|  6.16k|void send_msg_newkeys() {
  162|       |
  163|  6.16k|	TRACE(("enter send_msg_newkeys"))
  164|       |
  165|       |	/* generate the kexinit request */
  166|  6.16k|	CHECKCLEARTOWRITE();
  167|  6.16k|	buf_putbyte(ses.writepayload, SSH_MSG_NEWKEYS);
  ------------------
  |  |   37|  6.16k|#define SSH_MSG_NEWKEYS                21
  ------------------
  168|  6.16k|	encrypt_packet();
  169|       |
  170|       |	
  171|       |	/* set up our state */
  172|  6.16k|	ses.kexstate.sentnewkeys = 1;
  173|  6.16k|	if (ses.kexstate.donefirstkex) {
  ------------------
  |  Branch (173:6): [True: 4.63k, False: 1.53k]
  ------------------
  174|  4.63k|		ses.kexstate.donesecondkex = 1;
  175|  4.63k|	}
  176|  6.16k|	ses.kexstate.donefirstkex = 1;
  177|  6.16k|	ses.dataallowed = 1; /* we can send other packets again now */
  178|  6.16k|	gen_new_keys();
  179|  6.16k|	switch_keys();
  180|       |
  181|  6.16k|	if (ses.kexstate.strict_kex) {
  ------------------
  |  Branch (181:6): [True: 461, False: 5.70k]
  ------------------
  182|    461|		ses.transseq = 0;
  183|    461|	}
  184|       |
  185|  6.16k|	TRACE(("leave send_msg_newkeys"))
  186|  6.16k|}
recv_msg_newkeys:
  189|  5.80k|void recv_msg_newkeys() {
  190|       |
  191|  5.80k|	TRACE(("enter recv_msg_newkeys"))
  192|       |
  193|  5.80k|	ses.kexstate.recvnewkeys = 1;
  194|  5.80k|	switch_keys();
  195|       |
  196|  5.80k|	if (ses.kexstate.strict_kex) {
  ------------------
  |  Branch (196:6): [True: 444, False: 5.35k]
  ------------------
  197|    444|		ses.recvseq = 0;
  198|    444|	}
  199|  5.80k|	ses.kexstate.recvfirstnewkeys = 1;
  200|       |
  201|  5.80k|	TRACE(("leave recv_msg_newkeys"))
  202|  5.80k|}
kexfirstinitialise:
  230|  2.84k|void kexfirstinitialise() {
  231|  2.84k|	kex_setup_compress();
  232|  2.84k|	kexinitialise();
  233|  2.84k|}
recv_msg_kexinit:
  492|  7.08k|void recv_msg_kexinit() {
  493|       |	
  494|  7.08k|	unsigned int kexhashbuf_len = 0;
  495|  7.08k|	unsigned int remote_ident_len = 0;
  496|  7.08k|	unsigned int local_ident_len = 0;
  497|       |
  498|  7.08k|	TRACE(("<- KEXINIT"))
  499|  7.08k|	TRACE(("enter recv_msg_kexinit"))
  500|       |	
  501|  7.08k|	if (!ses.kexstate.sentkexinit) {
  ------------------
  |  Branch (501:6): [True: 4.82k, False: 2.25k]
  ------------------
  502|       |		/* we need to send a kex packet */
  503|  4.82k|		send_msg_kexinit();
  504|  4.82k|		TRACE(("continue recv_msg_kexinit: sent kexinit"))
  505|  4.82k|	}
  506|       |
  507|       |	/* "Once a party has sent a SSH_MSG_KEXINIT message ...
  508|       |	further SSH_MSG_KEXINIT messages MUST NOT be sent" */
  509|  7.08k|	if (ses.kexstate.recvkexinit) {
  ------------------
  |  Branch (509:6): [True: 0, False: 7.08k]
  ------------------
  510|      0|		dropbear_exit("Unexpected KEXINIT");
  511|      0|	}
  512|       |
  513|       |	/* start the kex hash */
  514|  7.08k|	local_ident_len = strlen(LOCAL_IDENT);
  ------------------
  |  |   14|  7.08k|#define LOCAL_IDENT "SSH-2.0-dropbear" IDENT_VERSION_PART
  |  |  ------------------
  |  |  |  |   12|  7.08k|#define IDENT_VERSION_PART "_" DROPBEAR_VERSION
  |  |  |  |  ------------------
  |  |  |  |  |  |    7|  7.08k|#define DROPBEAR_VERSION "2026.91"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  515|  7.08k|	remote_ident_len = strlen(ses.remoteident);
  516|       |
  517|  7.08k|	kexhashbuf_len = local_ident_len + remote_ident_len
  518|  7.08k|		+ ses.transkexinit->len + ses.payload->len
  519|  7.08k|		+ KEXHASHBUF_MAX_INTS;
  ------------------
  |  |  290|  7.08k|#define KEXHASHBUF_MAX_INTS (MAX_PUBKEY_SIZE + MAX_KEX_PARTS)
  |  |  ------------------
  |  |  |  |  261|  7.08k|#define MAX_PUBKEY_SIZE 600
  |  |  ------------------
  |  |               #define KEXHASHBUF_MAX_INTS (MAX_PUBKEY_SIZE + MAX_KEX_PARTS)
  |  |  ------------------
  |  |  |  |  274|  7.08k|#define MAX_KEX_PARTS (2*4 + 1184 + 1088 + 32*2 + 68)
  |  |  ------------------
  ------------------
  520|       |
  521|  7.08k|	ses.kexhashbuf = buf_new(kexhashbuf_len);
  522|       |
  523|  7.08k|	if (IS_DROPBEAR_CLIENT) {
  ------------------
  |  |  382|  7.08k|#define IS_DROPBEAR_CLIENT (ses.isserver == 0)
  |  |  ------------------
  |  |  |  Branch (382:28): [True: 0, False: 7.08k]
  |  |  ------------------
  ------------------
  524|       |
  525|       |		/* read the peer's choice of algos */
  526|      0|		read_kex_algos();
  527|       |
  528|       |		/* V_C, the client's version string (CR and NL excluded) */
  529|      0|		buf_putstring(ses.kexhashbuf, LOCAL_IDENT, local_ident_len);
  ------------------
  |  |   14|      0|#define LOCAL_IDENT "SSH-2.0-dropbear" IDENT_VERSION_PART
  |  |  ------------------
  |  |  |  |   12|      0|#define IDENT_VERSION_PART "_" DROPBEAR_VERSION
  |  |  |  |  ------------------
  |  |  |  |  |  |    7|      0|#define DROPBEAR_VERSION "2026.91"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  530|       |		/* V_S, the server's version string (CR and NL excluded) */
  531|      0|		buf_putstring(ses.kexhashbuf, ses.remoteident, remote_ident_len);
  532|       |
  533|       |		/* I_C, the payload of the client's SSH_MSG_KEXINIT */
  534|      0|		buf_putstring(ses.kexhashbuf,
  535|      0|			(const char*)ses.transkexinit->data, ses.transkexinit->len);
  536|       |		/* I_S, the payload of the server's SSH_MSG_KEXINIT */
  537|      0|		buf_setpos(ses.payload, ses.payload_beginning);
  538|      0|		buf_putstring(ses.kexhashbuf,
  539|      0|			(const char*)buf_getptr(ses.payload, ses.payload->len-ses.payload->pos),
  540|      0|			ses.payload->len-ses.payload->pos);
  541|      0|		ses.requirenext = SSH_MSG_KEXDH_REPLY;
  ------------------
  |  |   39|      0|#define SSH_MSG_KEXDH_REPLY            31
  ------------------
  542|  7.08k|	} else {
  543|       |		/* SERVER */
  544|       |
  545|       |		/* read the peer's choice of algos */
  546|  7.08k|		read_kex_algos();
  547|       |		/* V_C, the client's version string (CR and NL excluded) */
  548|  7.08k|		buf_putstring(ses.kexhashbuf, ses.remoteident, remote_ident_len);
  549|       |		/* V_S, the server's version string (CR and NL excluded) */
  550|  7.08k|		buf_putstring(ses.kexhashbuf, LOCAL_IDENT, local_ident_len);
  ------------------
  |  |   14|  7.08k|#define LOCAL_IDENT "SSH-2.0-dropbear" IDENT_VERSION_PART
  |  |  ------------------
  |  |  |  |   12|  7.08k|#define IDENT_VERSION_PART "_" DROPBEAR_VERSION
  |  |  |  |  ------------------
  |  |  |  |  |  |    7|  7.08k|#define DROPBEAR_VERSION "2026.91"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  551|       |
  552|       |		/* I_C, the payload of the client's SSH_MSG_KEXINIT */
  553|  7.08k|		buf_setpos(ses.payload, ses.payload_beginning);
  554|  7.08k|		buf_putstring(ses.kexhashbuf, 
  555|  7.08k|			(const char*)buf_getptr(ses.payload, ses.payload->len-ses.payload->pos),
  556|  7.08k|			ses.payload->len-ses.payload->pos);
  557|       |
  558|       |		/* I_S, the payload of the server's SSH_MSG_KEXINIT */
  559|  7.08k|		buf_putstring(ses.kexhashbuf,
  560|  7.08k|			(const char*)ses.transkexinit->data, ses.transkexinit->len);
  561|       |
  562|  7.08k|		ses.requirenext = SSH_MSG_KEXDH_INIT;
  ------------------
  |  |   38|  7.08k|#define SSH_MSG_KEXDH_INIT             30
  ------------------
  563|  7.08k|	}
  564|       |
  565|  7.08k|	buf_free(ses.transkexinit);
  566|  7.08k|	ses.transkexinit = NULL;
  567|       |	/* the rest of ses.kexhashbuf will be done after DH exchange */
  568|       |
  569|  7.08k|	ses.kexstate.recvkexinit = 1;
  570|       |
  571|  7.08k|	if (ses.kexstate.strict_kex && !ses.kexstate.donefirstkex && ses.recvseq != 1) {
  ------------------
  |  Branch (571:6): [True: 480, False: 6.60k]
  |  Branch (571:33): [True: 91, False: 389]
  |  Branch (571:63): [True: 7, False: 84]
  ------------------
  572|      7|		dropbear_exit("First packet wasn't kexinit");
  573|      7|	}
  574|       |
  575|  7.08k|	TRACE(("leave recv_msg_kexinit"))
  576|  7.08k|}
finish_kexhashbuf:
  579|  6.16k|void finish_kexhashbuf(void) {
  580|  6.16k|	hash_state hs;
  581|  6.16k|	const struct ltc_hash_descriptor *hash_desc = ses.newkeys->algo_kex->hash_desc;
  582|       |
  583|  6.16k|	hash_desc->init(&hs);
  584|  6.16k|	buf_setpos(ses.kexhashbuf, 0);
  585|  6.16k|	hash_desc->process(&hs, buf_getptr(ses.kexhashbuf, ses.kexhashbuf->len),
  586|  6.16k|			ses.kexhashbuf->len);
  587|  6.16k|	ses.hash = buf_new(hash_desc->hashsize);
  588|  6.16k|	hash_desc->done(&hs, buf_getwriteptr(ses.hash, hash_desc->hashsize));
  589|  6.16k|	buf_setlen(ses.hash, hash_desc->hashsize);
  590|       |
  591|       |#if defined(DEBUG_KEXHASH) && DEBUG_TRACE
  592|       |	if (!debug_trace) {
  593|       |		printhex("kexhashbuf", ses.kexhashbuf->data, ses.kexhashbuf->len);
  594|       |		printhex("kexhash", ses.hash->data, ses.hash->len);
  595|       |	}
  596|       |#endif
  597|       |
  598|  6.16k|	buf_burn_free(ses.kexhashbuf);
  599|  6.16k|	m_burn(&hs, sizeof(hash_state));
  600|  6.16k|	ses.kexhashbuf = NULL;
  601|       |	
  602|       |	/* first time around, we set the session_id to H */
  603|  6.16k|	if (ses.session_id == NULL) {
  ------------------
  |  Branch (603:6): [True: 1.53k, False: 4.63k]
  ------------------
  604|       |		/* create the session_id, this never needs freeing */
  605|  1.53k|		ses.session_id = buf_newcopy(ses.hash);
  606|  1.53k|	}
  607|  6.16k|}
common-kex.c:switch_keys:
  120|  11.9k|static void switch_keys() {
  121|  11.9k|	TRACE2(("enter switch_keys"))
  122|  11.9k|	if (!(ses.kexstate.sentkexinit && ses.kexstate.recvkexinit)) {
  ------------------
  |  Branch (122:8): [True: 11.9k, False: 7]
  |  Branch (122:36): [True: 11.9k, False: 0]
  ------------------
  123|      7|		dropbear_exit("Unexpected newkeys message");
  124|      7|	}
  125|       |
  126|  11.9k|	if (!ses.keys) {
  ------------------
  |  Branch (126:6): [True: 0, False: 11.9k]
  ------------------
  127|      0|		ses.keys = m_malloc(sizeof(*ses.newkeys));
  128|      0|	}
  129|  11.9k|	if (ses.kexstate.recvnewkeys && ses.newkeys->recv.valid) {
  ------------------
  |  Branch (129:6): [True: 5.79k, False: 6.16k]
  |  Branch (129:34): [True: 5.79k, False: 0]
  ------------------
  130|  5.79k|		TRACE(("switch_keys recv"))
  131|       |#ifndef DISABLE_ZLIB
  132|       |		gen_new_zstream_recv();
  133|       |#endif
  134|  5.79k|		ses.keys->recv = ses.newkeys->recv;
  135|  5.79k|		m_burn(&ses.newkeys->recv, sizeof(ses.newkeys->recv));
  136|  5.79k|		ses.newkeys->recv.valid = 0;
  137|  5.79k|	}
  138|  11.9k|	if (ses.kexstate.sentnewkeys && ses.newkeys->trans.valid) {
  ------------------
  |  Branch (138:6): [True: 11.9k, False: 0]
  |  Branch (138:34): [True: 6.16k, False: 5.79k]
  ------------------
  139|  6.16k|		TRACE(("switch_keys trans"))
  140|       |#ifndef DISABLE_ZLIB
  141|       |		gen_new_zstream_trans();
  142|       |#endif
  143|  6.16k|		ses.keys->trans = ses.newkeys->trans;
  144|  6.16k|		m_burn(&ses.newkeys->trans, sizeof(ses.newkeys->trans));
  145|  6.16k|		ses.newkeys->trans.valid = 0;
  146|  6.16k|	}
  147|  11.9k|	if (ses.kexstate.sentnewkeys && ses.kexstate.recvnewkeys)
  ------------------
  |  Branch (147:6): [True: 11.9k, False: 0]
  |  Branch (147:34): [True: 5.79k, False: 6.16k]
  ------------------
  148|  5.79k|	{
  149|  5.79k|		TRACE(("switch_keys done"))
  150|  5.79k|		ses.keys->algo_kex = ses.newkeys->algo_kex;
  151|  5.79k|		ses.keys->algo_hostkey = ses.newkeys->algo_hostkey;
  152|  5.79k|		ses.keys->algo_signature = ses.newkeys->algo_signature;
  153|  5.79k|		m_free(ses.newkeys);
  ------------------
  |  |   24|  5.79k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 5.79k]
  |  |  ------------------
  ------------------
  154|       |		ses.newkeys = NULL;
  155|  5.79k|		kexinitialise();
  156|  5.79k|	}
  157|  11.9k|	TRACE2(("leave switch_keys"))
  158|  11.9k|}
common-kex.c:kex_setup_compress:
  204|  2.84k|static void kex_setup_compress(void) {
  205|  2.84k|#ifdef DISABLE_ZLIB
  206|  2.84k|	ses.compress_algos_c2s = ssh_nocompress;
  207|  2.84k|	ses.compress_algos_s2c = ssh_nocompress;
  208|       |#else
  209|       |
  210|       |	if (!opts.compression) {
  211|       |		ses.compress_algos_c2s = ssh_nocompress;
  212|       |		ses.compress_algos_s2c = ssh_nocompress;
  213|       |		return;
  214|       |	}
  215|       |
  216|       |	if (IS_DROPBEAR_CLIENT) {
  217|       |		/* TODO: should c2s in dbclient be disabled?
  218|       |		 * Current Dropbear server disables it. Disabling it also
  219|       |		 * lets DROPBEAR_CLI_IMMEDIATE_AUTH work (see comment there) */
  220|       |		ses.compress_algos_c2s = ssh_compress;
  221|       |		ses.compress_algos_s2c = ssh_compress;
  222|       |	} else {
  223|       |		ses.compress_algos_c2s = ssh_nocompress;
  224|       |		ses.compress_algos_s2c = ssh_compress;
  225|       |	}
  226|       |#endif
  227|  2.84k|}
common-kex.c:kexinitialise:
  236|  8.63k|static void kexinitialise() {
  237|       |
  238|  8.63k|	TRACE(("kexinitialise()"))
  239|       |
  240|       |	/* sent/recv'd MSG_KEXINIT */
  241|  8.63k|	ses.kexstate.sentkexinit = 0;
  242|  8.63k|	ses.kexstate.recvkexinit = 0;
  243|       |
  244|       |	/* sent/recv'd MSG_NEWKEYS */
  245|  8.63k|	ses.kexstate.recvnewkeys = 0;
  246|  8.63k|	ses.kexstate.sentnewkeys = 0;
  247|       |
  248|       |	/* first_packet_follows */
  249|  8.63k|	ses.kexstate.them_firstfollows = 0;
  250|       |
  251|  8.63k|	ses.kexstate.datatrans = 0;
  252|  8.63k|	ses.kexstate.datarecv = 0;
  253|       |
  254|  8.63k|	ses.kexstate.our_first_follows_matches = 0;
  255|       |
  256|  8.63k|	ses.kexstate.lastkextime = monotonic_now();
  257|       |
  258|  8.63k|}
common-kex.c:gen_new_keys:
  299|  6.16k|static void gen_new_keys() {
  300|       |
  301|  6.16k|	unsigned char C2S_IV[MAX_IV_LEN];
  302|  6.16k|	unsigned char C2S_key[MAX_KEY_LEN];
  303|  6.16k|	unsigned char S2C_IV[MAX_IV_LEN];
  304|  6.16k|	unsigned char S2C_key[MAX_KEY_LEN];
  305|       |	/* unsigned char key[MAX_KEY_LEN]; */
  306|  6.16k|	unsigned char *trans_IV, *trans_key, *recv_IV, *recv_key;
  307|       |
  308|  6.16k|	hash_state hs;
  309|  6.16k|	const struct ltc_hash_descriptor *hash_desc = ses.newkeys->algo_kex->hash_desc;
  310|  6.16k|	char mactransletter, macrecvletter; /* Client or server specific */
  311|       |
  312|  6.16k|	TRACE(("enter gen_new_keys"))
  313|       |	/* the dh_K and hash are the start of all hashes, we make use of that */
  314|       |
  315|  6.16k|	hash_desc->init(&hs);
  316|  6.16k|	if (ses.dh_K) {
  ------------------
  |  Branch (316:6): [True: 6.16k, False: 0]
  ------------------
  317|  6.16k|		hash_process_mp(hash_desc, &hs, ses.dh_K);
  318|  6.16k|		mp_clear(ses.dh_K);
  319|  6.16k|		m_free(ses.dh_K);
  ------------------
  |  |   24|  6.16k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 6.16k]
  |  |  ------------------
  ------------------
  320|  6.16k|	}
  321|  6.16k|	if (ses.dh_K_bytes) {
  ------------------
  |  Branch (321:6): [True: 0, False: 6.16k]
  ------------------
  322|      0|	    hash_desc->process(&hs, ses.dh_K_bytes->data, ses.dh_K_bytes->len);
  323|      0|		buf_burn_free(ses.dh_K_bytes);
  324|      0|		ses.dh_K_bytes = NULL;
  325|      0|	}
  326|  6.16k|	hash_desc->process(&hs, ses.hash->data, ses.hash->len);
  327|  6.16k|	buf_burn_free(ses.hash);
  328|  6.16k|	ses.hash = NULL;
  329|       |
  330|  6.16k|	if (IS_DROPBEAR_CLIENT) {
  ------------------
  |  |  382|  6.16k|#define IS_DROPBEAR_CLIENT (ses.isserver == 0)
  |  |  ------------------
  |  |  |  Branch (382:28): [True: 0, False: 6.16k]
  |  |  ------------------
  ------------------
  331|      0|		trans_IV	= C2S_IV;
  332|      0|		recv_IV		= S2C_IV;
  333|      0|		trans_key	= C2S_key;
  334|      0|		recv_key	= S2C_key;
  335|      0|		mactransletter = 'E';
  336|      0|		macrecvletter = 'F';
  337|  6.16k|	} else {
  338|  6.16k|		trans_IV	= S2C_IV;
  339|  6.16k|		recv_IV		= C2S_IV;
  340|  6.16k|		trans_key	= S2C_key;
  341|  6.16k|		recv_key	= C2S_key;
  342|  6.16k|		mactransletter = 'F';
  343|  6.16k|		macrecvletter = 'E';
  344|  6.16k|	}
  345|       |
  346|  6.16k|	hashkeys(C2S_IV, sizeof(C2S_IV), &hs, 'A');
  347|  6.16k|	hashkeys(S2C_IV, sizeof(S2C_IV), &hs, 'B');
  348|  6.16k|	hashkeys(C2S_key, sizeof(C2S_key), &hs, 'C');
  349|  6.16k|	hashkeys(S2C_key, sizeof(S2C_key), &hs, 'D');
  350|       |
  351|  6.16k|	if (ses.newkeys->recv.algo_crypt->cipherdesc != NULL) {
  ------------------
  |  Branch (351:6): [True: 6.16k, False: 0]
  ------------------
  352|  6.16k|		int recv_cipher = -1;
  353|  6.16k|		if (ses.newkeys->recv.algo_crypt->cipherdesc->name != NULL) {
  ------------------
  |  Branch (353:7): [True: 5.30k, False: 860]
  ------------------
  354|  5.30k|			recv_cipher = find_cipher(ses.newkeys->recv.algo_crypt->cipherdesc->name);
  355|  5.30k|			if (recv_cipher < 0) {
  ------------------
  |  Branch (355:8): [True: 0, False: 5.30k]
  ------------------
  356|      0|				dropbear_exit("Crypto error");
  357|      0|			}
  358|  5.30k|		}
  359|  6.16k|		if (ses.newkeys->recv.crypt_mode->start(recv_cipher, 
  ------------------
  |  Branch (359:7): [True: 0, False: 6.16k]
  ------------------
  360|  6.16k|				recv_IV, recv_key, 
  361|  6.16k|				ses.newkeys->recv.algo_crypt->keysize, 0, 
  362|  6.16k|				&ses.newkeys->recv.cipher_state) != CRYPT_OK) {
  363|      0|			dropbear_exit("Crypto error");
  364|      0|		}
  365|  6.16k|	}
  366|       |
  367|  6.16k|	if (ses.newkeys->trans.algo_crypt->cipherdesc != NULL) {
  ------------------
  |  Branch (367:6): [True: 6.16k, False: 0]
  ------------------
  368|  6.16k|		int trans_cipher = -1;
  369|  6.16k|		if (ses.newkeys->trans.algo_crypt->cipherdesc->name != NULL) {
  ------------------
  |  Branch (369:7): [True: 5.49k, False: 675]
  ------------------
  370|  5.49k|			trans_cipher = find_cipher(ses.newkeys->trans.algo_crypt->cipherdesc->name);
  371|  5.49k|			if (trans_cipher < 0) {
  ------------------
  |  Branch (371:8): [True: 0, False: 5.49k]
  ------------------
  372|      0|				dropbear_exit("Crypto error");
  373|      0|			}
  374|  5.49k|		}
  375|  6.16k|		if (ses.newkeys->trans.crypt_mode->start(trans_cipher, 
  ------------------
  |  Branch (375:7): [True: 0, False: 6.16k]
  ------------------
  376|  6.16k|				trans_IV, trans_key, 
  377|  6.16k|				ses.newkeys->trans.algo_crypt->keysize, 0, 
  378|  6.16k|				&ses.newkeys->trans.cipher_state) != CRYPT_OK) {
  379|      0|			dropbear_exit("Crypto error");
  380|      0|		}
  381|  6.16k|	}
  382|       |
  383|  6.16k|	if (ses.newkeys->trans.algo_mac->hash_desc != NULL) {
  ------------------
  |  Branch (383:6): [True: 5.49k, False: 675]
  ------------------
  384|  5.49k|		hashkeys(ses.newkeys->trans.mackey, 
  385|  5.49k|				ses.newkeys->trans.algo_mac->keysize, &hs, mactransletter);
  386|  5.49k|		ses.newkeys->trans.hash_index = find_hash(ses.newkeys->trans.algo_mac->hash_desc->name);
  387|  5.49k|	}
  388|       |
  389|  6.16k|	if (ses.newkeys->recv.algo_mac->hash_desc != NULL) {
  ------------------
  |  Branch (389:6): [True: 0, False: 6.16k]
  ------------------
  390|      0|		hashkeys(ses.newkeys->recv.mackey, 
  391|      0|				ses.newkeys->recv.algo_mac->keysize, &hs, macrecvletter);
  392|      0|		ses.newkeys->recv.hash_index = find_hash(ses.newkeys->recv.algo_mac->hash_desc->name);
  393|      0|	}
  394|       |
  395|       |	/* Ready to switch over */
  396|  6.16k|	ses.newkeys->trans.valid = 1;
  397|  6.16k|	ses.newkeys->recv.valid = 1;
  398|       |
  399|  6.16k|	m_burn(C2S_IV, sizeof(C2S_IV));
  400|  6.16k|	m_burn(C2S_key, sizeof(C2S_key));
  401|  6.16k|	m_burn(S2C_IV, sizeof(S2C_IV));
  402|  6.16k|	m_burn(S2C_key, sizeof(S2C_key));
  403|  6.16k|	m_burn(&hs, sizeof(hash_state));
  404|       |
  405|  6.16k|	TRACE(("leave gen_new_keys"))
  406|  6.16k|}
common-kex.c:hashkeys:
  267|  30.1k|		const hash_state * hs, const unsigned char X) {
  268|       |
  269|  30.1k|	const struct ltc_hash_descriptor *hash_desc = ses.newkeys->algo_kex->hash_desc;
  270|  30.1k|	hash_state hs2;
  271|  30.1k|	unsigned int offset;
  272|  30.1k|	unsigned char tmpout[MAX_HASH_SIZE];
  273|       |
  274|  30.1k|	memcpy(&hs2, hs, sizeof(hash_state));
  275|  30.1k|	hash_desc->process(&hs2, &X, 1);
  276|  30.1k|	hash_desc->process(&hs2, ses.session_id->data, ses.session_id->len);
  277|  30.1k|	hash_desc->done(&hs2, tmpout);
  278|  30.1k|	memcpy(out, tmpout, MIN(hash_desc->hashsize, outlen));
  ------------------
  |  Branch (278:22): [True: 10.7k, False: 19.4k]
  ------------------
  279|  30.1k|	for (offset = hash_desc->hashsize; 
  280|  40.9k|			offset < outlen; 
  ------------------
  |  Branch (280:4): [True: 10.7k, False: 30.1k]
  ------------------
  281|  30.1k|			offset += hash_desc->hashsize)
  282|  10.7k|	{
  283|       |		/* need to extend */
  284|  10.7k|		memcpy(&hs2, hs, sizeof(hash_state));
  285|  10.7k|		hash_desc->process(&hs2, out, offset);
  286|  10.7k|		hash_desc->done(&hs2, tmpout);
  287|       |		memcpy(&out[offset], tmpout, MIN(outlen - offset, hash_desc->hashsize));
  ------------------
  |  Branch (287:32): [True: 812, False: 9.94k]
  ------------------
  288|  10.7k|	}
  289|  30.1k|	m_burn(&hs2, sizeof(hash_state));
  290|  30.1k|}
common-kex.c:read_kex_algos:
  611|  7.08k|static void read_kex_algos() {
  612|       |
  613|       |	/* for asymmetry */
  614|  7.08k|	algo_type * c2s_hash_algo = NULL;
  615|  7.08k|	algo_type * s2c_hash_algo = NULL;
  616|  7.08k|	algo_type * c2s_cipher_algo = NULL;
  617|  7.08k|	algo_type * s2c_cipher_algo = NULL;
  618|  7.08k|	algo_type * c2s_comp_algo = NULL;
  619|  7.08k|	algo_type * s2c_comp_algo = NULL;
  620|       |	/* the generic one */
  621|  7.08k|	algo_type * algo = NULL;
  622|       |
  623|       |	/* which algo couldn't match */
  624|  7.08k|	char * erralgo = NULL;
  625|       |
  626|  7.08k|	int goodguess = 0;
  627|  7.08k|	int allgood = 1; /* we AND this with each goodguess and see if its still
  628|       |						true after */
  629|  7.08k|	int kexguess2 = 0;
  630|       |
  631|  7.08k|	buf_incrpos(ses.payload, 16); /* start after the cookie */
  632|       |
  633|  7.08k|	memset(ses.newkeys, 0x0, sizeof(*ses.newkeys));
  634|       |
  635|       |	/* kex_algorithms */
  636|  7.08k|#if DROPBEAR_KEXGUESS2
  637|  7.08k|	if (buf_has_algo(ses.payload, KEXGUESS2_ALGO_NAME) == DROPBEAR_SUCCESS) {
  ------------------
  |  |  137|  7.08k|#define KEXGUESS2_ALGO_NAME "kexguess2@matt.ucc.asn.au"
  ------------------
              	if (buf_has_algo(ses.payload, KEXGUESS2_ALGO_NAME) == DROPBEAR_SUCCESS) {
  ------------------
  |  |  111|  7.08k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (637:6): [True: 283, False: 6.79k]
  ------------------
  638|    283|		kexguess2 = 1;
  639|    283|	}
  640|  7.08k|#endif
  641|       |
  642|  7.08k|#if DROPBEAR_EXT_INFO
  643|       |	/* Determine if SSH_MSG_EXT_INFO messages should be sent.
  644|       |	Should be done for the first key exchange. Only required on server side
  645|       |    for server-sig-algs */
  646|  7.08k|	if (IS_DROPBEAR_SERVER) {
  ------------------
  |  |  381|  7.08k|#define IS_DROPBEAR_SERVER (ses.isserver == 1)
  |  |  ------------------
  |  |  |  Branch (381:28): [True: 6.97k, False: 106]
  |  |  ------------------
  ------------------
  647|  6.97k|		if (!ses.kexstate.donefirstkex) {
  ------------------
  |  Branch (647:7): [True: 2.19k, False: 4.78k]
  ------------------
  648|  2.19k|			if (buf_has_algo(ses.payload, SSH_EXT_INFO_C) == DROPBEAR_SUCCESS) {
  ------------------
  |  |  100|  2.19k|#define SSH_EXT_INFO_C "ext-info-c"
  ------------------
              			if (buf_has_algo(ses.payload, SSH_EXT_INFO_C) == DROPBEAR_SUCCESS) {
  ------------------
  |  |  111|  2.19k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (648:8): [True: 102, False: 2.08k]
  ------------------
  649|    102|				ses.allow_ext_info = 1;
  650|    102|			}
  651|  2.19k|		}
  652|  6.97k|	}
  653|  7.08k|#endif
  654|       |
  655|  7.08k|	if (!ses.kexstate.donefirstkex) {
  ------------------
  |  Branch (655:6): [True: 2.19k, False: 4.89k]
  ------------------
  656|  2.19k|		const char* strict_name;
  657|  2.19k|		if (IS_DROPBEAR_CLIENT) {
  ------------------
  |  |  382|  2.19k|#define IS_DROPBEAR_CLIENT (ses.isserver == 0)
  |  |  ------------------
  |  |  |  Branch (382:28): [True: 0, False: 2.19k]
  |  |  ------------------
  ------------------
  658|      0|			strict_name = SSH_STRICT_KEX_S;
  ------------------
  |  |  104|      0|#define SSH_STRICT_KEX_S "kex-strict-s-v00@openssh.com"
  ------------------
  659|  2.19k|		} else {
  660|  2.19k|			strict_name = SSH_STRICT_KEX_C;
  ------------------
  |  |  105|  2.19k|#define SSH_STRICT_KEX_C "kex-strict-c-v00@openssh.com"
  ------------------
  661|  2.19k|		}
  662|  2.19k|		if (buf_has_algo(ses.payload, strict_name) == DROPBEAR_SUCCESS) {
  ------------------
  |  |  111|  2.19k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (662:7): [True: 94, False: 2.09k]
  ------------------
  663|     94|			ses.kexstate.strict_kex = 1;
  664|     94|		}
  665|  2.19k|	}
  666|       |
  667|  7.08k|	algo = buf_match_algo(ses.payload, sshkex, kexguess2, &goodguess);
  668|  7.08k|	allgood &= goodguess;
  669|  7.08k|	if (algo == NULL || algo->data == NULL) {
  ------------------
  |  Branch (669:6): [True: 312, False: 6.77k]
  |  Branch (669:22): [True: 9, False: 6.76k]
  ------------------
  670|       |		/* kexguess2, ext-info-c, ext-info-s should not match negotiation */
  671|    215|		erralgo = "kex";
  672|    215|		goto error;
  673|    215|	}
  674|  6.86k|	TRACE(("kexguess2 %d", kexguess2))
  675|  6.86k|	DEBUG3(("kex algo %s", algo->name))
  676|  6.86k|	ses.newkeys->algo_kex = algo->data;
  677|       |
  678|       |	/* server_host_key_algorithms */
  679|  6.86k|	algo = buf_match_algo(ses.payload, sigalgs, kexguess2, &goodguess);
  680|  6.86k|	allgood &= goodguess;
  681|  6.86k|	if (algo == NULL) {
  ------------------
  |  Branch (681:6): [True: 12, False: 6.85k]
  ------------------
  682|     12|		erralgo = "hostkey";
  683|     12|		goto error;
  684|     12|	}
  685|  6.85k|	DEBUG2(("hostkey algo %s", algo->name))
  686|  6.85k|	ses.newkeys->algo_signature = algo->val;
  687|  6.85k|	ses.newkeys->algo_hostkey = signkey_type_from_signature(ses.newkeys->algo_signature);
  688|       |
  689|       |	/* encryption_algorithms_client_to_server */
  690|  6.85k|	c2s_cipher_algo = buf_match_algo(ses.payload, sshciphers, 0, NULL);
  691|  6.85k|	if (c2s_cipher_algo == NULL) {
  ------------------
  |  Branch (691:6): [True: 10, False: 6.84k]
  ------------------
  692|     10|		erralgo = "enc c->s";
  693|     10|		goto error;
  694|     10|	}
  695|  6.84k|	DEBUG2(("enc  c2s is %s", c2s_cipher_algo->name))
  696|       |
  697|       |	/* encryption_algorithms_server_to_client */
  698|  6.84k|	s2c_cipher_algo = buf_match_algo(ses.payload, sshciphers, 0, NULL);
  699|  6.84k|	if (s2c_cipher_algo == NULL) {
  ------------------
  |  Branch (699:6): [True: 16, False: 6.82k]
  ------------------
  700|     16|		erralgo = "enc s->c";
  701|     16|		goto error;
  702|     16|	}
  703|  6.82k|	DEBUG2(("enc  s2c is %s", s2c_cipher_algo->name))
  704|       |
  705|       |	/* mac_algorithms_client_to_server */
  706|  6.82k|	c2s_hash_algo = buf_match_algo(ses.payload, sshhashes, 0, NULL);
  707|  6.82k|#if DROPBEAR_AEAD_MODE
  708|  6.82k|	if (((struct dropbear_cipher_mode*)c2s_cipher_algo->mode)->aead_crypt != NULL) {
  ------------------
  |  Branch (708:6): [True: 923, False: 5.90k]
  ------------------
  709|    923|		c2s_hash_algo = NULL;
  710|    923|	} else
  711|  5.90k|#endif
  712|  5.90k|	if (c2s_hash_algo == NULL) {
  ------------------
  |  Branch (712:6): [True: 3, False: 5.90k]
  ------------------
  713|      3|		erralgo = "mac c->s";
  714|      3|		goto error;
  715|      3|	}
  716|  6.82k|	DEBUG2(("hmac c2s is %s", c2s_hash_algo ? c2s_hash_algo->name : "<implicit>"))
  717|       |
  718|       |	/* mac_algorithms_server_to_client */
  719|  6.82k|	s2c_hash_algo = buf_match_algo(ses.payload, sshhashes, 0, NULL);
  720|  6.82k|#if DROPBEAR_AEAD_MODE
  721|  6.82k|	if (((struct dropbear_cipher_mode*)s2c_cipher_algo->mode)->aead_crypt != NULL) {
  ------------------
  |  Branch (721:6): [True: 720, False: 6.10k]
  ------------------
  722|    720|		s2c_hash_algo = NULL;
  723|    720|	} else
  724|  6.10k|#endif
  725|  6.10k|	if (s2c_hash_algo == NULL) {
  ------------------
  |  Branch (725:6): [True: 11, False: 6.09k]
  ------------------
  726|     11|		erralgo = "mac s->c";
  727|     11|		goto error;
  728|     11|	}
  729|  6.81k|	DEBUG2(("hmac s2c is %s", s2c_hash_algo ? s2c_hash_algo->name : "<implicit>"))
  730|       |
  731|       |	/* compression_algorithms_client_to_server */
  732|  6.81k|	c2s_comp_algo = buf_match_algo(ses.payload, ses.compress_algos_c2s, 0, NULL);
  733|  6.81k|	if (c2s_comp_algo == NULL) {
  ------------------
  |  Branch (733:6): [True: 8, False: 6.80k]
  ------------------
  734|      8|		erralgo = "comp c->s";
  735|      8|		goto error;
  736|      8|	}
  737|  6.80k|	DEBUG2(("comp c2s is %s", c2s_comp_algo->name))
  738|       |
  739|       |	/* compression_algorithms_server_to_client */
  740|  6.80k|	s2c_comp_algo = buf_match_algo(ses.payload, ses.compress_algos_s2c, 0, NULL);
  741|  6.80k|	if (s2c_comp_algo == NULL) {
  ------------------
  |  Branch (741:6): [True: 3, False: 6.80k]
  ------------------
  742|      3|		erralgo = "comp s->c";
  743|      3|		goto error;
  744|      3|	}
  745|  6.80k|	DEBUG2(("comp s2c is %s", s2c_comp_algo->name))
  746|       |
  747|       |	/* languages_client_to_server */
  748|  6.80k|	buf_eatstring(ses.payload);
  749|       |
  750|       |	/* languages_server_to_client */
  751|  6.80k|	buf_eatstring(ses.payload);
  752|       |
  753|       |	/* their first_kex_packet_follows */
  754|  6.80k|	if (buf_getbool(ses.payload)) {
  ------------------
  |  Branch (754:6): [True: 225, False: 6.57k]
  ------------------
  755|    225|		TRACE(("them kex firstfollows. allgood %d", allgood))
  756|    225|		ses.kexstate.them_firstfollows = 1;
  757|       |		/* if the guess wasn't good, we ignore the packet sent */
  758|    225|		if (!allgood) {
  ------------------
  |  Branch (758:7): [True: 198, False: 27]
  ------------------
  759|    198|			ses.ignorenext = 1;
  760|    198|		}
  761|    225|	}
  762|       |
  763|       |	/* Handle the asymmetry */
  764|  6.80k|	if (IS_DROPBEAR_CLIENT) {
  ------------------
  |  |  382|  6.80k|#define IS_DROPBEAR_CLIENT (ses.isserver == 0)
  |  |  ------------------
  |  |  |  Branch (382:28): [True: 0, False: 6.80k]
  |  |  ------------------
  ------------------
  765|      0|		ses.newkeys->recv.algo_crypt = 
  766|      0|			(struct dropbear_cipher*)s2c_cipher_algo->data;
  767|      0|		ses.newkeys->trans.algo_crypt = 
  768|      0|			(struct dropbear_cipher*)c2s_cipher_algo->data;
  769|      0|		ses.newkeys->recv.crypt_mode = 
  770|      0|			(struct dropbear_cipher_mode*)s2c_cipher_algo->mode;
  771|      0|		ses.newkeys->trans.crypt_mode =
  772|      0|			(struct dropbear_cipher_mode*)c2s_cipher_algo->mode;
  773|      0|		ses.newkeys->recv.algo_mac = 
  774|      0|#if DROPBEAR_AEAD_MODE
  775|      0|			s2c_hash_algo == NULL ? ses.newkeys->recv.crypt_mode->aead_mac :
  ------------------
  |  Branch (775:4): [True: 0, False: 0]
  ------------------
  776|      0|#endif
  777|      0|			(struct dropbear_hash*)s2c_hash_algo->data;
  778|      0|		ses.newkeys->trans.algo_mac = 
  779|      0|#if DROPBEAR_AEAD_MODE
  780|      0|			c2s_hash_algo == NULL ? ses.newkeys->trans.crypt_mode->aead_mac :
  ------------------
  |  Branch (780:4): [True: 0, False: 0]
  ------------------
  781|      0|#endif
  782|      0|			(struct dropbear_hash*)c2s_hash_algo->data;
  783|      0|		ses.newkeys->recv.algo_comp = s2c_comp_algo->val;
  784|      0|		ses.newkeys->trans.algo_comp = c2s_comp_algo->val;
  785|  6.80k|	} else {
  786|       |		/* SERVER */
  787|  6.80k|		ses.newkeys->recv.algo_crypt = 
  788|  6.80k|			(struct dropbear_cipher*)c2s_cipher_algo->data;
  789|  6.80k|		ses.newkeys->trans.algo_crypt = 
  790|  6.80k|			(struct dropbear_cipher*)s2c_cipher_algo->data;
  791|  6.80k|		ses.newkeys->recv.crypt_mode =
  792|  6.80k|			(struct dropbear_cipher_mode*)c2s_cipher_algo->mode;
  793|  6.80k|		ses.newkeys->trans.crypt_mode =
  794|  6.80k|			(struct dropbear_cipher_mode*)s2c_cipher_algo->mode;
  795|  6.80k|		ses.newkeys->recv.algo_mac = 
  796|  6.80k|#if DROPBEAR_AEAD_MODE
  797|  6.80k|			c2s_hash_algo == NULL ? ses.newkeys->recv.crypt_mode->aead_mac :
  ------------------
  |  Branch (797:4): [True: 899, False: 5.90k]
  ------------------
  798|  6.80k|#endif
  799|  6.80k|			(struct dropbear_hash*)c2s_hash_algo->data;
  800|  6.80k|		ses.newkeys->trans.algo_mac = 
  801|  6.80k|#if DROPBEAR_AEAD_MODE
  802|  6.80k|			s2c_hash_algo == NULL ? ses.newkeys->trans.crypt_mode->aead_mac :
  ------------------
  |  Branch (802:4): [True: 707, False: 6.09k]
  ------------------
  803|  6.80k|#endif
  804|  6.80k|			(struct dropbear_hash*)s2c_hash_algo->data;
  805|  6.80k|		ses.newkeys->recv.algo_comp = c2s_comp_algo->val;
  806|  6.80k|		ses.newkeys->trans.algo_comp = s2c_comp_algo->val;
  807|  6.80k|	}
  808|       |
  809|  6.80k|#if DROPBEAR_FUZZ
  810|  6.80k|	if (fuzz.fuzzing) {
  ------------------
  |  Branch (810:6): [True: 6.53k, False: 271]
  ------------------
  811|  6.53k|		fuzz_kex_fakealgos();
  812|  6.53k|	}
  813|  6.80k|#endif
  814|       |
  815|       |	/* reserved for future extensions */
  816|  6.80k|	buf_getint(ses.payload);
  817|       |
  818|  6.80k|	if (ses.send_kex_first_guess && allgood) {
  ------------------
  |  Branch (818:6): [True: 0, False: 6.80k]
  |  Branch (818:34): [True: 0, False: 0]
  ------------------
  819|      0|		TRACE(("our_first_follows_matches 1"))
  820|      0|		ses.kexstate.our_first_follows_matches = 1;
  821|      0|	}
  822|  6.80k|	return;
  823|       |
  824|    278|error:
  825|    278|	dropbear_exit("No matching algo %s", erralgo);
  826|  6.80k|}

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

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|       |#if DROPBEAR_SHA1_HMAC
   35|       |		&sha1_desc,
   36|       |#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|      4|	for (i = 0; reghashes[i] != NULL; i++) {
  ------------------
  |  Branch (56:14): [True: 3, False: 1]
  ------------------
   57|      3|		if (register_hash(reghashes[i]) == -1) {
  ------------------
  |  Branch (57:7): [True: 0, False: 3]
  ------------------
   58|      0|			dropbear_exit("Error registering crypto");
   59|      0|		}
   60|      3|	}
   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|   170k|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|       |	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|   170k|}

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

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

dropbear_close:
   95|  1.24k|void dropbear_close(const char* format, ...) {
   96|       |
   97|  1.24k|	va_list param;
   98|       |
   99|  1.24k|	va_start(param, format);
  100|  1.24k|	_dropbear_exit(EXIT_SUCCESS, format, param);
  101|  1.24k|	va_end(param);
  102|       |
  103|      0|}
dropbear_exit:
  105|  1.60k|void dropbear_exit(const char* format, ...) {
  106|       |
  107|  1.60k|	va_list param;
  108|       |
  109|  1.60k|	va_start(param, format);
  110|  1.60k|	_dropbear_exit(EXIT_FAILURE, format, param);
  111|  1.60k|	va_end(param);
  112|      0|}
dropbear_log:
  148|  3.32k|void dropbear_log(int priority, const char* format, ...) {
  149|       |
  150|  3.32k|	va_list param;
  151|       |
  152|  3.32k|	va_start(param, format);
  153|  3.32k|	_dropbear_log(priority, format, param);
  154|       |	va_end(param);
  155|  3.32k|}
m_close:
  565|  1.24k|void m_close(int fd) {
  566|  1.24k|	int val;
  567|       |
  568|  1.24k|	if (fd < 0) {
  ------------------
  |  Branch (568:6): [True: 0, False: 1.24k]
  ------------------
  569|      0|		return;
  570|      0|	}
  571|       |
  572|  1.24k|	do {
  573|  1.24k|		val = close(fd);
  ------------------
  |  |   56|  1.24k|#define close(fd) wrapfd_close(fd)
  ------------------
  574|  1.24k|	} while (val < 0 && errno == EINTR);
  ------------------
  |  Branch (574:11): [True: 0, False: 1.24k]
  |  Branch (574:22): [True: 0, False: 0]
  ------------------
  575|       |
  576|  1.24k|	if (val < 0 && errno != EBADF) {
  ------------------
  |  Branch (576:6): [True: 0, False: 1.24k]
  |  Branch (576:17): [True: 0, False: 0]
  ------------------
  577|       |		/* Linux says EIO can happen */
  578|       |		dropbear_exit("Error closing fd %d, %s", fd, strerror(errno));
  579|      0|	}
  580|  1.24k|}
setnonblocking:
  582|  5.68k|void setnonblocking(int fd) {
  583|       |
  584|  5.68k|	int fl = 0;
  585|  5.68k|	TRACE(("setnonblocking: %d", fd))
  586|       |
  587|  5.68k|#if DROPBEAR_FUZZ
  588|  5.68k|	if (fuzz.fuzzing) {
  ------------------
  |  Branch (588:6): [True: 5.68k, False: 0]
  ------------------
  589|  5.68k|		return;
  590|  5.68k|	}
  591|      0|#endif
  592|      0|	fl = fcntl(fd, F_GETFL, 0);
  593|      0|	if (fl == -1) {
  ------------------
  |  Branch (593:6): [True: 0, False: 0]
  ------------------
  594|       |		/* F_GETFL shouldn't fail */
  595|      0|		dropbear_exit("Couldn't set nonblocking");
  596|      0|	}
  597|       |
  598|      0|	if (fcntl(fd, F_SETFL, fl | O_NONBLOCK) == -1) {
  ------------------
  |  Branch (598:6): [True: 0, False: 0]
  ------------------
  599|      0|		if (errno == ENODEV) {
  ------------------
  |  Branch (599:7): [True: 0, False: 0]
  ------------------
  600|       |			/* Some devices (like /dev/null redirected in)
  601|       |			 * can't be set to non-blocking */
  602|      0|			TRACE(("ignoring ENODEV for setnonblocking"))
  603|      0|		} else {
  604|      0|			dropbear_exit("Couldn't set nonblocking");
  605|      0|		}
  606|      0|	}
  607|      0|	TRACE(("leave setnonblocking"))
  608|      0|}
disallow_core:
  610|      1|void disallow_core() {
  611|      1|	struct rlimit lim = {0};
  612|      1|	if (getrlimit(RLIMIT_CORE, &lim) < 0) {
  ------------------
  |  Branch (612:6): [True: 0, False: 1]
  ------------------
  613|      0|		TRACE(("getrlimit(RLIMIT_CORE) failed"));
  614|      0|	}
  615|      1|	lim.rlim_cur = 0;
  616|      1|	if (setrlimit(RLIMIT_CORE, &lim) < 0) {
  ------------------
  |  Branch (616:6): [True: 0, False: 1]
  ------------------
  617|      0|		TRACE(("setrlimit(RLIMIT_CORE) failed"));
  618|      0|	}
  619|      1|}
expand_homedir_path_home:
  647|      1|char * expand_homedir_path_home(const char *inpath, const char *homedir) {
  648|      1|	if (strncmp(inpath, "~/", 2) == 0 && homedir) {
  ------------------
  |  Branch (648:6): [True: 0, False: 1]
  |  Branch (648:39): [True: 0, False: 0]
  ------------------
  649|      0|		size_t len = strlen(inpath)-2 + strlen(homedir) + 2;
  650|      0|		char *buf = m_malloc(len);
  651|      0|		snprintf(buf, len, "%s/%s", homedir, inpath+2);
  652|      0|		return buf;
  653|      0|	}
  654|       |	/* Fallback */
  655|      1|	return m_strdup(inpath);
  656|      1|}
expand_homedir_path:
  660|      1|char * expand_homedir_path(const char *inpath) {
  661|      1|	struct passwd *pw = NULL;
  662|      1|	char *homedir = getenv("HOME");
  663|       |
  664|      1|	if (!homedir) {
  ------------------
  |  Branch (664:6): [True: 0, False: 1]
  ------------------
  665|      0|		pw = getpwuid(getuid());
  ------------------
  |  |  109|      0|#define getpwuid(x) fuzz_getpwuid(x)
  ------------------
  666|      0|		if (pw) {
  ------------------
  |  Branch (666:7): [True: 0, False: 0]
  ------------------
  667|      0|			homedir = pw->pw_dir;
  668|      0|		}
  669|      0|	}
  670|      1|	return expand_homedir_path_home(inpath, homedir);
  671|      1|}
gettime_wrapper:
  686|   577k|void gettime_wrapper(struct timespec *now) {
  687|   577k|	struct timeval tv;
  688|   577k|#if DROPBEAR_FUZZ
  689|   577k|	if (fuzz.fuzzing) {
  ------------------
  |  Branch (689:6): [True: 577k, False: 0]
  ------------------
  690|       |		/* time stands still when fuzzing */
  691|   577k|		now->tv_sec = 5;
  692|   577k|		now->tv_nsec = 0;
  693|   577k|	}
  694|   577k|#endif
  695|       |
  696|   577k|#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
  697|       |	/* POSIX monotonic clock. Newer Linux, BSD, MacOSX >10.12 */
  698|   577k|	if (clock_gettime(CLOCK_MONOTONIC, now) == 0) {
  ------------------
  |  Branch (698:6): [True: 577k, False: 0]
  ------------------
  699|   577k|		return;
  700|   577k|	}
  701|      0|#endif
  702|       |
  703|      0|#if defined(__linux__) && defined(SYS_clock_gettime)
  704|      0|	{
  705|       |	/* Old linux toolchain - kernel might support it but not the build headers */
  706|       |	/* Also glibc <2.17 requires -lrt which we neglect to add */
  707|      0|	static int linux_monotonic_failed = 0;
  708|      0|	if (!linux_monotonic_failed) {
  ------------------
  |  Branch (708:6): [True: 0, False: 0]
  ------------------
  709|       |		/* CLOCK_MONOTONIC isn't in some headers */
  710|      0|		int clock_source_monotonic = 1; 
  711|      0|		if (syscall(SYS_clock_gettime, clock_source_monotonic, now) == 0) {
  ------------------
  |  Branch (711:7): [True: 0, False: 0]
  ------------------
  712|      0|			return;
  713|      0|		} else {
  714|       |			/* Don't try again */
  715|      0|			linux_monotonic_failed = 1;
  716|      0|		}
  717|      0|	}
  718|      0|	}
  719|      0|#endif /* linux fallback clock_gettime */
  720|       |
  721|       |#if defined(HAVE_MACH_ABSOLUTE_TIME)
  722|       |	{
  723|       |	/* OS X pre 10.12, see https://developer.apple.com/library/mac/qa/qa1398/_index.html */
  724|       |	static mach_timebase_info_data_t timebase_info;
  725|       |	uint64_t scaled_time;
  726|       |	if (timebase_info.denom == 0) {
  727|       |		mach_timebase_info(&timebase_info);
  728|       |	}
  729|       |	scaled_time = mach_absolute_time() * timebase_info.numer / timebase_info.denom;
  730|       |	now->tv_sec = scaled_time / 1000000000;
  731|       |	now->tv_nsec = scaled_time % 1000000000;
  732|       |	}
  733|       |#endif /* osx mach_absolute_time */
  734|       |
  735|       |	/* Fallback for everything else - this will sometimes go backwards */
  736|      0|	gettimeofday(&tv, NULL);
  737|      0|	now->tv_sec = tv.tv_sec;
  738|      0|	now->tv_nsec = 1000*(long)tv.tv_usec;
  739|      0|}
monotonic_now:
  742|   575k|time_t monotonic_now() {
  743|   575k|	struct timespec ts;
  744|   575k|	gettime_wrapper(&ts);
  745|   575k|	return ts.tv_sec;
  746|   575k|}

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;
  ------------------
  |  |  112|      1|#define DROPBEAR_FAILURE -1
  ------------------
   48|       |
   49|      1|	TRACE(("enter buf_get_dss_pub_key"))
   50|      1|	dropbear_assert(key != NULL);
  ------------------
  |  |   84|      1|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (84:37): [True: 0, False: 1]
  |  |  |  Branch (84:93): [Folded, False: 1]
  |  |  ------------------
  ------------------
   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" */
  ------------------
  |  |  115|      1|#define SSH_SIGNKEY_DSS_LEN 7
  ------------------
   55|      1|	if (buf_getmpint(buf, key->p) == DROPBEAR_FAILURE
  ------------------
  |  |  112|      2|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (55:6): [True: 0, False: 1]
  ------------------
   56|      1|	 || buf_getmpint(buf, key->q) == DROPBEAR_FAILURE
  ------------------
  |  |  112|      2|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (56:6): [True: 0, False: 1]
  ------------------
   57|      1|	 || buf_getmpint(buf, key->g) == DROPBEAR_FAILURE
  ------------------
  |  |  112|      2|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (57:6): [True: 0, False: 1]
  ------------------
   58|      1|	 || buf_getmpint(buf, key->y) == DROPBEAR_FAILURE) {
  ------------------
  |  |  112|      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;
  ------------------
  |  |  112|      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;
  ------------------
  |  |  112|      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;
  ------------------
  |  |  112|      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;
  ------------------
  |  |  112|      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;
  ------------------
  |  |  112|      0|#define DROPBEAR_FAILURE -1
  ------------------
   85|      0|		goto out;
   86|      0|	}
   87|       |
   88|      1|	ret = DROPBEAR_SUCCESS;
  ------------------
  |  |  111|      1|#define DROPBEAR_SUCCESS 0
  ------------------
   89|      1|	TRACE(("leave buf_get_dss_pub_key: success"))
   90|      1|out:
   91|      1|	if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  112|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (91:6): [True: 0, False: 1]
  ------------------
   92|       |		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;
  ------------------
  |  |  112|      1|#define DROPBEAR_FAILURE -1
  ------------------
  103|       |
  104|      1|	dropbear_assert(key != NULL);
  ------------------
  |  |   84|      1|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (84:37): [True: 0, False: 1]
  |  |  |  Branch (84:93): [Folded, False: 1]
  |  |  ------------------
  ------------------
  105|       |
  106|      1|	ret = buf_get_dss_pub_key(buf, key);
  107|      1|	if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  112|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (107:6): [True: 0, False: 1]
  ------------------
  108|      0|		return DROPBEAR_FAILURE;
  ------------------
  |  |  112|      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) {
  ------------------
  |  |  112|      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|       |	m_free(key);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 0]
  |  |  ------------------
  ------------------
  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|      5|		for (;dp->size > 0; dp++) {
  ------------------
  |  Branch (52:9): [True: 5, False: 0]
  ------------------
   53|      5|			if (dp->size == (*curve)->ltc_size) {
  ------------------
  |  Branch (53:8): [True: 3, False: 2]
  ------------------
   54|      3|				(*curve)->dp = dp;
   55|      3|				break;
   56|      3|			}
   57|      5|		}
   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|       |		(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;
  ------------------
  |  |  112|      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;
  ------------------
  |  |  111|      1|#define DROPBEAR_SUCCESS 0
  ------------------
  199|       |
  200|      1|	out:
  201|      1|	if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  112|      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, False: 0]
  |  |  ------------------
  ------------------
  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, False: 1]
  |  |  ------------------
  ------------------
  128|      1|	m_free(b);
  ------------------
  |  |   24|      1|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 1]
  |  |  ------------------
  ------------------
  129|      1|	m_free(t1);
  ------------------
  |  |   24|      1|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 1]
  |  |  ------------------
  ------------------
  130|       |	m_free(t2);
  ------------------
  |  |   24|      1|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 1]
  |  |  ------------------
  ------------------
  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|      3|		|| type == DROPBEAR_SIGNKEY_ECDSA_NISTP384
  ------------------
  |  Branch (13:6): [True: 0, False: 3]
  ------------------
   14|      3|		|| 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, False: 1]
  |  |  ------------------
  ------------------
  121|      1|	m_free(identifier);
  ------------------
  |  |   24|      1|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 1]
  |  |  ------------------
  ------------------
  122|      1|	if (q_buf) {
  ------------------
  |  Branch (122:6): [True: 1, False: 0]
  ------------------
  123|      1|		buf_free(q_buf);
  124|       |		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) {
  ------------------
  |  |  111|      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, False: 0]
  |  |  ------------------
  ------------------
  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);
  ------------------
  |  |   84|      1|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (84:37): [True: 0, False: 1]
  |  |  |  Branch (84:93): [Folded, False: 1]
  |  |  ------------------
  ------------------
   84|       |
   85|      1|	buf_incrpos(buf, 4+SSH_SIGNKEY_ED25519_LEN); /* int + "ssh-ed25519" */
  ------------------
  |  |  119|      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;
  ------------------
  |  |  112|      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;
  ------------------
  |  |  111|      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, False: 0]
  |  |  ------------------
  ------------------
  113|       |
  114|      0|	TRACE2(("leave ed25519_key_free"))
  115|      0|}

listeners_initialise:
   30|  2.84k|void listeners_initialise() {
   31|       |
   32|       |	/* just one slot to start with */
   33|  2.84k|	ses.listeners = (struct Listener**)m_malloc(sizeof(struct Listener*));
   34|  2.84k|	ses.listensize = 1;
   35|  2.84k|	ses.listeners[0] = NULL;
   36|       |
   37|  2.84k|}
set_listener_fds:
   39|   212k|void set_listener_fds(fd_set * readfds) {
   40|       |
   41|   212k|	unsigned int i, j;
   42|   212k|	struct Listener *listener;
   43|       |
   44|       |	/* check each in turn */
   45|   424k|	for (i = 0; i < ses.listensize; i++) {
  ------------------
  |  Branch (45:14): [True: 212k, False: 212k]
  ------------------
   46|   212k|		listener = ses.listeners[i];
   47|   212k|		if (listener != NULL) {
  ------------------
  |  Branch (47:7): [True: 0, False: 212k]
  ------------------
   48|      0|			for (j = 0; j < listener->nsocks; j++) {
  ------------------
  |  Branch (48:16): [True: 0, False: 0]
  ------------------
   49|       |				FD_SET(listener->socks[j], readfds);
   50|      0|			}
   51|      0|		}
   52|   212k|	}
   53|   212k|}
handle_listeners:
   56|   209k|void handle_listeners(const fd_set * readfds) {
   57|       |
   58|   209k|	unsigned int i, j;
   59|   209k|	struct Listener *listener;
   60|   209k|	int sock;
   61|       |
   62|       |	/* check each in turn */
   63|   419k|	for (i = 0; i < ses.listensize; i++) {
  ------------------
  |  Branch (63:14): [True: 209k, False: 209k]
  ------------------
   64|   209k|		listener = ses.listeners[i];
   65|   209k|		if (listener != NULL) {
  ------------------
  |  Branch (65:7): [True: 0, False: 209k]
  ------------------
   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)) {
  ------------------
  |  Branch (68:9): [True: 0, False: 0]
  ------------------
   69|      0|					listener->acceptor(listener, sock);
   70|      0|				}
   71|      0|			}
   72|      0|		}
   73|   209k|	}
   74|   209k|} /* Woo brace matching */
remove_all_listeners:
  166|  2.84k|void remove_all_listeners(void) {
  167|  2.84k|	unsigned int i;
  168|  5.68k|	for (i = 0; i < ses.listensize; i++) {
  ------------------
  |  Branch (168:14): [True: 2.84k, False: 2.84k]
  ------------------
  169|  2.84k|		if (ses.listeners[i]) {
  ------------------
  |  Branch (169:7): [True: 0, False: 2.84k]
  ------------------
  170|      0|			remove_listener(ses.listeners[i]);
  171|      0|		}
  172|  2.84k|	}
  173|       |	m_free(ses.listeners);
  ------------------
  |  |   24|  2.84k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 2.84k]
  |  |  ------------------
  ------------------
  174|  2.84k|}

remove_connect_pending:
  291|  2.84k|void remove_connect_pending() {
  292|  2.84k|	while (ses.conn_pending.first) {
  ------------------
  |  Branch (292:9): [True: 0, False: 2.84k]
  ------------------
  293|      0|		struct dropbear_progress_connection *c = ses.conn_pending.first->item;
  294|      0|		remove_connect(c, ses.conn_pending.first);
  295|      0|	}
  296|  2.84k|}
set_connect_fds:
  299|   212k|void set_connect_fds(fd_set *writefd) {
  300|   212k|	m_list_elem *iter;
  301|   212k|	iter = ses.conn_pending.first;
  302|   212k|	while (iter) {
  ------------------
  |  Branch (302:9): [True: 0, False: 212k]
  ------------------
  303|      0|		m_list_elem *next_iter = iter->next;
  304|      0|		struct dropbear_progress_connection *c = iter->item;
  305|       |		/* Set one going */
  306|      0|		while (c->res_iter && c->sock < 0) {
  ------------------
  |  Branch (306:10): [True: 0, False: 0]
  |  Branch (306:25): [True: 0, False: 0]
  ------------------
  307|      0|			connect_try_next(c);
  308|      0|		}
  309|      0|		if (c->sock >= 0) {
  ------------------
  |  Branch (309:7): [True: 0, False: 0]
  ------------------
  310|      0|			FD_SET(c->sock, writefd);
  311|      0|		} else {
  312|       |			/* Final failure */
  313|      0|			if (!c->errstring) {
  ------------------
  |  Branch (313:8): [True: 0, False: 0]
  ------------------
  314|      0|				c->errstring = m_strdup("unexpected failure");
  315|      0|			}
  316|      0|			c->cb(DROPBEAR_FAILURE, -1, c->cb_data, c->errstring);
  ------------------
  |  |  112|      0|#define DROPBEAR_FAILURE -1
  ------------------
  317|      0|			remove_connect(c, iter);
  318|      0|		}
  319|      0|		iter = next_iter;
  320|      0|	}
  321|   212k|}
handle_connect_fds:
  323|   209k|void handle_connect_fds(const fd_set *writefd) {
  324|   209k|	m_list_elem *iter;
  325|   209k|	for (iter = ses.conn_pending.first; iter; iter = iter->next) {
  ------------------
  |  Branch (325:38): [True: 0, False: 209k]
  ------------------
  326|      0|		int val;
  327|      0|		socklen_t vallen = sizeof(val);
  328|      0|		struct dropbear_progress_connection *c = iter->item;
  329|       |
  330|      0|		if (c->sock < 0 || !FD_ISSET(c->sock, writefd)) {
  ------------------
  |  Branch (330:7): [True: 0, False: 0]
  |  Branch (330:22): [True: 0, False: 0]
  ------------------
  331|      0|			continue;
  332|      0|		}
  333|       |
  334|      0|		TRACE(("handling %s port %s socket %d", c->remotehost, c->remoteport, c->sock));
  335|       |
  336|      0|		if (getsockopt(c->sock, SOL_SOCKET, SO_ERROR, &val, &vallen) != 0) {
  ------------------
  |  Branch (336:7): [True: 0, False: 0]
  ------------------
  337|      0|			TRACE(("handle_connect_fds getsockopt(%d) SO_ERROR failed: %s", c->sock, strerror(errno)))
  338|       |			/* This isn't expected to happen - Unix has surprises though, continue gracefully. */
  339|      0|			m_close(c->sock);
  340|      0|			c->sock = -1;
  341|      0|		} else if (val != 0) {
  ------------------
  |  Branch (341:14): [True: 0, False: 0]
  ------------------
  342|       |			/* Connect failed */
  343|      0|			TRACE(("connect to %s port %s failed.", c->remotehost, c->remoteport))
  344|      0|			m_close(c->sock);
  345|      0|			c->sock = -1;
  346|       |
  347|      0|			m_free(c->errstring);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 0]
  |  |  ------------------
  ------------------
  348|      0|			c->errstring = m_strdup(strerror(val));
  349|      0|		} else {
  350|       |			/* New connection has been established */
  351|      0|			c->cb(DROPBEAR_SUCCESS, c->sock, c->cb_data, NULL);
  ------------------
  |  |  111|      0|#define DROPBEAR_SUCCESS 0
  ------------------
  352|      0|			remove_connect(c, iter);
  353|      0|			TRACE(("leave handle_connect_fds - success"))
  354|       |			/* Must return here - remove_connect() invalidates iter */
  355|      0|			return; 
  356|      0|		}
  357|      0|	}
  358|   209k|}
packet_queue_to_iovec:
  364|  38.0k|void packet_queue_to_iovec(const struct Queue *queue, struct iovec *iov, unsigned int *iov_count) {
  365|  38.0k|	struct Link *l;
  366|  38.0k|	unsigned int i;
  367|  38.0k|	int len;
  368|  38.0k|	buffer *writebuf;
  369|       |
  370|       |#ifndef IOV_MAX
  371|       |	#if (defined(__CYGWIN__) || defined(__GNU__)) && !defined(UIO_MAXIOV)
  372|       |		#define IOV_MAX 1024
  373|       |	#elif defined(__sgi)
  374|       |		#define IOV_MAX 512 
  375|       |	#else 
  376|       |		#define IOV_MAX UIO_MAXIOV
  377|       |	#endif
  378|       |#endif
  379|       |
  380|  38.0k|	*iov_count = MIN(MIN(queue->count, IOV_MAX), *iov_count);
  ------------------
  |  Branch (380:15): [True: 38.0k, False: 0]
  |  Branch (380:15): [True: 38.0k, False: 0]
  |  Branch (380:15): [True: 38.0k, False: 0]
  ------------------
  381|       |
  382|  79.0k|	for (l = queue->head, i = 0; i < *iov_count; l = l->link, i++)
  ------------------
  |  Branch (382:31): [True: 41.0k, False: 38.0k]
  ------------------
  383|  41.0k|	{
  384|  41.0k|		writebuf = (buffer*)l->item;
  385|  41.0k|		len = writebuf->len - writebuf->pos;
  386|  41.0k|		dropbear_assert(len > 0);
  ------------------
  |  |   84|  41.0k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (84:37): [True: 0, False: 41.0k]
  |  |  |  Branch (84:93): [Folded, False: 41.0k]
  |  |  ------------------
  ------------------
  387|  41.0k|		TRACE2(("write_packet writev #%d len %d/%d", i,
  388|  41.0k|				len, writebuf->len))
  389|  41.0k|		iov[i].iov_base = buf_getptr(writebuf, len);
  390|  41.0k|		iov[i].iov_len = len;
  391|  41.0k|	}
  392|  38.0k|}
packet_queue_consume:
  394|  38.0k|void packet_queue_consume(struct Queue *queue, ssize_t written) {
  395|  38.0k|	buffer *writebuf;
  396|  38.0k|	int len;
  397|  76.1k|	while (written > 0) {
  ------------------
  |  Branch (397:9): [True: 38.0k, False: 38.0k]
  ------------------
  398|  38.0k|		writebuf = (buffer*)examine(queue);
  399|  38.0k|		len = writebuf->len - writebuf->pos;
  400|  38.0k|		if (len > written) {
  ------------------
  |  Branch (400:7): [True: 0, False: 38.0k]
  ------------------
  401|       |			/* partial buffer write */
  402|      0|			buf_incrpos(writebuf, written);
  403|      0|			written = 0;
  404|  38.0k|		} else {
  405|  38.0k|			written -= len;
  406|  38.0k|			dequeue(queue);
  407|  38.0k|			buf_free(writebuf);
  408|  38.0k|		}
  409|  38.0k|	}
  410|  38.0k|}
set_sock_priority:
  430|  2.84k|void set_sock_priority(int sock, enum dropbear_prio prio) {
  431|       |
  432|  2.84k|	int rc;
  433|  2.84k|	int val;
  434|       |
  435|  2.84k|#if DROPBEAR_FUZZ
  436|  2.84k|	if (fuzz.fuzzing) {
  ------------------
  |  Branch (436:6): [True: 2.84k, False: 0]
  ------------------
  437|  2.84k|		TRACE(("fuzzing skips set_sock_prio"))
  438|  2.84k|		return;
  439|  2.84k|	}
  440|      0|#endif
  441|       |	/* Don't log ENOTSOCK errors so that this can harmlessly be called
  442|       |	 * on a client '-J' proxy pipe */
  443|       |
  444|      0|	if (opts.disable_ip_tos == 0) {
  ------------------
  |  Branch (444:6): [True: 0, False: 0]
  ------------------
  445|      0|#ifdef IP_TOS
  446|       |	/* Set the DSCP field for outbound IP packet priority.
  447|       |	rfc4594 has some guidance to meanings.
  448|       |
  449|       |	We set AF21 as "Low-Latency" class for interactive (tty session,
  450|       |	also handshake/setup packets). Other traffic is left at the default.
  451|       |
  452|       |	OpenSSH at present uses AF21/CS1, rationale
  453|       |	https://cvsweb.openbsd.org/src/usr.bin/ssh/readconf.c#rev1.284
  454|       |
  455|       |	Old Dropbear/OpenSSH and Debian/Ubuntu OpenSSH (at Jan 2022) use
  456|       |	IPTOS_LOWDELAY/IPTOS_THROUGHPUT
  457|       |
  458|       |	DSCP constants are from Linux headers, applicable to other platforms
  459|       |	such as macos.
  460|       |	*/
  461|      0|	if (prio == DROPBEAR_PRIO_LOWDELAY) {
  ------------------
  |  Branch (461:6): [True: 0, False: 0]
  ------------------
  462|      0|		val = 0x48; /* IPTOS_DSCP_AF21 */
  463|      0|	} else {
  464|      0|		val = 0; /* default */
  465|      0|	}
  466|      0|#if defined(IPPROTO_IPV6) && defined(IPV6_TCLASS)
  467|      0|	rc = setsockopt(sock, IPPROTO_IPV6, IPV6_TCLASS, (void*)&val, sizeof(val));
  468|      0|	if (rc < 0 && errno != ENOTSOCK) {
  ------------------
  |  Branch (468:6): [True: 0, False: 0]
  |  Branch (468:16): [True: 0, False: 0]
  ------------------
  469|      0|		TRACE(("Couldn't set IPV6_TCLASS (%s)", strerror(errno)));
  470|      0|	}
  471|      0|#endif
  472|      0|	rc = setsockopt(sock, IPPROTO_IP, IP_TOS, (void*)&val, sizeof(val));
  473|      0|	if (rc < 0 && errno != ENOTSOCK) {
  ------------------
  |  Branch (473:6): [True: 0, False: 0]
  |  Branch (473:16): [True: 0, False: 0]
  ------------------
  474|      0|		TRACE(("Couldn't set IP_TOS (%s)", strerror(errno)));
  475|      0|	}
  476|      0|#endif /* IP_TOS */
  477|      0|	}
  478|       |
  479|      0|#ifdef HAVE_LINUX_PKT_SCHED_H
  480|       |	/* Set scheduling priority within the local Linux network stack */
  481|      0|	if (prio == DROPBEAR_PRIO_LOWDELAY) {
  ------------------
  |  Branch (481:6): [True: 0, False: 0]
  ------------------
  482|      0|		val = TC_PRIO_INTERACTIVE;
  483|      0|	} else {
  484|      0|		val = 0;
  485|      0|	}
  486|       |	/* linux specific, sets QoS class. see tc-prio(8) */
  487|      0|	rc = setsockopt(sock, SOL_SOCKET, SO_PRIORITY, (void*) &val, sizeof(val));
  488|      0|	if (rc < 0 && errno != ENOTSOCK) {
  ------------------
  |  Branch (488:6): [True: 0, False: 0]
  |  Branch (488:16): [True: 0, False: 0]
  ------------------
  489|      0|		TRACE(("Couldn't set SO_PRIORITY (%s)", strerror(errno)))
  490|      0|    }
  491|      0|#endif
  492|       |
  493|      0|}
get_socket_address:
  683|  5.68k|{
  684|  5.68k|	struct sockaddr_storage addr;
  685|  5.68k|	socklen_t addrlen;
  686|       |
  687|  5.68k|#if DROPBEAR_FUZZ
  688|  5.68k|	if (fuzz.fuzzing) {
  ------------------
  |  Branch (688:6): [True: 5.68k, False: 0]
  ------------------
  689|  5.68k|		fuzz_get_socket_address(fd, local_host, local_port, remote_host, remote_port, host_lookup);
  690|  5.68k|		return;
  691|  5.68k|	}
  692|      0|#endif
  693|       |	
  694|      0|	if (local_host || local_port) {
  ------------------
  |  Branch (694:6): [True: 0, False: 0]
  |  Branch (694:20): [True: 0, False: 0]
  ------------------
  695|      0|		addrlen = sizeof(addr);
  696|      0|		if (getsockname(fd, (struct sockaddr*)&addr, &addrlen) < 0) {
  ------------------
  |  Branch (696:7): [True: 0, False: 0]
  ------------------
  697|      0|			dropbear_exit("Failed socket address: %s", strerror(errno));
  698|      0|		}
  699|      0|		getaddrstring(&addr, local_host, local_port, host_lookup);		
  700|      0|	}
  701|      0|	if (remote_host || remote_port) {
  ------------------
  |  Branch (701:6): [True: 0, False: 0]
  |  Branch (701:21): [True: 0, False: 0]
  ------------------
  702|      0|		addrlen = sizeof(addr);
  703|      0|		if (getpeername(fd, (struct sockaddr*)&addr, &addrlen) < 0) {
  ------------------
  |  Branch (703:7): [True: 0, False: 0]
  ------------------
  704|      0|			dropbear_exit("Failed socket address: %s", strerror(errno));
  705|      0|		}
  706|      0|		getaddrstring(&addr, remote_host, remote_port, host_lookup);		
  707|      0|	}
  708|      0|}

write_packet:
   58|  38.0k|void write_packet() {
   59|       |
   60|  38.0k|	ssize_t written;
   61|  38.0k|#if defined(HAVE_WRITEV) && (defined(IOV_MAX) || defined(UIO_MAXIOV))
   62|       |	/* 50 is somewhat arbitrary */
   63|  38.0k|	unsigned int iov_count = 50;
   64|  38.0k|	struct iovec iov[50];
   65|       |#else
   66|       |	int len;
   67|       |	buffer* writebuf;
   68|       |#endif
   69|       |	
   70|  38.0k|	TRACE2(("enter write_packet"))
   71|  38.0k|	dropbear_assert(!isempty(&ses.writequeue));
  ------------------
  |  |   84|  38.0k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (84:37): [True: 0, False: 38.0k]
  |  |  |  Branch (84:93): [Folded, False: 38.0k]
  |  |  ------------------
  ------------------
   72|       |
   73|  38.0k|#if defined(HAVE_WRITEV) && (defined(IOV_MAX) || defined(UIO_MAXIOV))
   74|       |
   75|  38.0k|	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|  38.0k|#if DROPBEAR_FUZZ
   80|  38.0k|	if (fuzz.fuzzing) {
  ------------------
  |  Branch (80:6): [True: 38.0k, False: 0]
  ------------------
   81|       |		/* pretend to write one packet at a time */
   82|       |		/* TODO(fuzz): randomise amount written based on the fuzz input */
   83|  38.0k|		written = iov[0].iov_len;
   84|  38.0k|	}
   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|  38.0k|	packet_queue_consume(&ses.writequeue, written);
  100|  38.0k|	ses.writequeue_len -= written;
  101|       |
  102|  38.0k|	if (written == 0) {
  ------------------
  |  Branch (102:6): [True: 0, False: 38.0k]
  ------------------
  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|  38.0k|	TRACE2(("leave write_packet"))
  145|  38.0k|}
read_packet:
  150|   192k|void read_packet() {
  151|       |
  152|   192k|	int len;
  153|   192k|	unsigned int maxlen;
  154|   192k|	unsigned char blocksize;
  155|       |
  156|   192k|	TRACE2(("enter read_packet"))
  157|   192k|	blocksize = ses.keys->recv.algo_crypt->blocksize;
  158|       |	
  159|   192k|	if (ses.readbuf == NULL || ses.readbuf->len < blocksize) {
  ------------------
  |  Branch (159:6): [True: 43.5k, False: 148k]
  |  Branch (159:29): [True: 82.9k, False: 65.5k]
  ------------------
  160|   126k|		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|   126k|		ret = read_packet_init();
  166|       |
  167|   126k|		if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  112|   126k|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (167:7): [True: 82.9k, False: 43.5k]
  ------------------
  168|       |			/* didn't read enough to determine the length */
  169|  82.9k|			TRACE2(("leave read_packet: packetinit done"))
  170|  82.9k|			return;
  171|  82.9k|		}
  172|   126k|	}
  173|       |
  174|       |	/* Attempt to read the remainder of the packet, note that there
  175|       |	 * mightn't be any available (EAGAIN) */
  176|   109k|	maxlen = ses.readbuf->len - ses.readbuf->pos;
  177|   109k|	if (maxlen == 0) {
  ------------------
  |  Branch (177:6): [True: 21.3k, False: 87.7k]
  ------------------
  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|  21.3k|		len = 0;
  182|  87.7k|	} else {
  183|  87.7k|		len = read(ses.sock_in, buf_getptr(ses.readbuf, maxlen), maxlen);
  ------------------
  |  |   55|  87.7k|#define read(fd, buf, count) wrapfd_read(fd, buf, count)
  ------------------
  184|       |
  185|  87.7k|		if (len == 0) {
  ------------------
  |  Branch (185:7): [True: 128, False: 87.5k]
  ------------------
  186|    128|			ses.remoteclosed();
  187|    128|		}
  188|       |
  189|  87.7k|		if (len < 0) {
  ------------------
  |  Branch (189:7): [True: 109, False: 87.5k]
  ------------------
  190|    109|			if (errno == EINTR || errno == EAGAIN) {
  ------------------
  |  Branch (190:8): [True: 108, False: 1]
  |  Branch (190:26): [True: 0, False: 1]
  ------------------
  191|    108|				TRACE2(("leave read_packet: EINTR or EAGAIN"))
  192|    108|				return;
  193|    108|			} else {
  194|      1|				dropbear_exit("Error reading: %s", strerror(errno));
  195|      1|			}
  196|    109|		}
  197|       |
  198|  87.5k|		buf_incrpos(ses.readbuf, len);
  199|  87.5k|	}
  200|       |
  201|   108k|	if ((unsigned int)len == maxlen) {
  ------------------
  |  Branch (201:6): [True: 42.3k, False: 66.6k]
  ------------------
  202|       |		/* The whole packet has been read */
  203|  42.3k|		decrypt_packet();
  204|       |		/* The main select() loop process_packet() to
  205|       |		 * handle the packet contents... */
  206|  42.3k|	}
  207|   108k|	TRACE2(("leave read_packet"))
  208|   108k|}
decrypt_packet:
  298|  42.3k|void decrypt_packet() {
  299|       |
  300|  42.3k|	unsigned char blocksize;
  301|  42.3k|	unsigned char macsize;
  302|  42.3k|	unsigned int padlen;
  303|  42.3k|	unsigned int len;
  304|       |
  305|  42.3k|	TRACE2(("enter decrypt_packet"))
  306|  42.3k|	blocksize = ses.keys->recv.algo_crypt->blocksize;
  307|  42.3k|	macsize = ses.keys->recv.algo_mac->hashsize;
  308|       |
  309|  42.3k|	ses.kexstate.datarecv += ses.readbuf->len;
  310|       |
  311|  42.3k|#if DROPBEAR_AEAD_MODE
  312|  42.3k|	if (ses.keys->recv.crypt_mode->aead_crypt) {
  ------------------
  |  Branch (312:6): [True: 0, False: 42.3k]
  ------------------
  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|  42.3k|#endif
  328|  42.3k|	{
  329|       |		/* we've already decrypted the first blocksize in read_packet_init */
  330|  42.3k|		buf_setpos(ses.readbuf, blocksize);
  331|       |
  332|       |		/* decrypt it in-place */
  333|  42.3k|		len = ses.readbuf->len - macsize - ses.readbuf->pos;
  334|  42.3k|		if (ses.keys->recv.crypt_mode->decrypt(
  ------------------
  |  Branch (334:7): [True: 0, False: 42.3k]
  ------------------
  335|  42.3k|					buf_getptr(ses.readbuf, len), 
  336|  42.3k|					buf_getwriteptr(ses.readbuf, len),
  337|  42.3k|					len,
  338|  42.3k|					&ses.keys->recv.cipher_state) != CRYPT_OK) {
  339|      0|			dropbear_exit("Error decrypting");
  340|      0|		}
  341|  42.3k|		buf_incrpos(ses.readbuf, len);
  342|       |
  343|       |		/* check the hmac */
  344|  42.3k|		if (checkmac() != DROPBEAR_SUCCESS) {
  ------------------
  |  |  111|  42.3k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (344:7): [True: 0, False: 42.3k]
  ------------------
  345|      0|			dropbear_exit("Integrity error");
  346|      0|		}
  347|       |
  348|  42.3k|	}
  349|       |	
  350|  42.3k|#if DROPBEAR_FUZZ
  351|  42.3k|	fuzz_dump(ses.readbuf->data, ses.readbuf->len);
  352|  42.3k|#endif
  353|       |
  354|       |	/* get padding length */
  355|  42.3k|	buf_setpos(ses.readbuf, PACKET_PADDING_OFF);
  ------------------
  |  |   48|  42.3k|#define PACKET_PADDING_OFF 4
  ------------------
  356|  42.3k|	padlen = buf_getbyte(ses.readbuf);
  357|       |		
  358|       |	/* payload length */
  359|       |	/* - 4 - 1 is for LEN and PADLEN values */
  360|  42.3k|	len = ses.readbuf->len - padlen - 4 - 1 - macsize;
  361|  42.3k|	if ((len > RECV_MAX_PAYLOAD_LEN+ZLIB_COMPRESS_EXPANSION) || (len < 1)) {
  ------------------
  |  |  555|  42.3k|#define RECV_MAX_PAYLOAD_LEN 32768
  ------------------
              	if ((len > RECV_MAX_PAYLOAD_LEN+ZLIB_COMPRESS_EXPANSION) || (len < 1)) {
  ------------------
  |  |   50|  42.3k|#define ZLIB_COMPRESS_EXPANSION (((RECV_MAX_PAYLOAD_LEN/16384)+1)*5 + 6)
  |  |  ------------------
  |  |  |  |  555|  42.3k|#define RECV_MAX_PAYLOAD_LEN 32768
  |  |  ------------------
  ------------------
  |  Branch (361:6): [True: 12, False: 42.3k]
  |  Branch (361:62): [True: 1, False: 42.3k]
  ------------------
  362|     13|		dropbear_exit("Bad packet size %u", len);
  363|     13|	}
  364|       |
  365|  42.3k|	buf_setpos(ses.readbuf, PACKET_PAYLOAD_OFF);
  ------------------
  |  |   49|  42.3k|#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|  42.3k|	{
  377|  42.3k|		ses.payload = ses.readbuf;
  378|  42.3k|		ses.payload_beginning = ses.payload->pos;
  379|  42.3k|		buf_setlen(ses.payload, ses.payload->pos + len);
  380|  42.3k|	}
  381|  42.3k|	ses.readbuf = NULL;
  382|       |
  383|  42.3k|	ses.recvseq++;
  384|       |
  385|  42.3k|	TRACE2(("leave decrypt_packet"))
  386|  42.3k|}
maybe_flush_reply_queue:
  495|   209k|void maybe_flush_reply_queue() {
  496|   209k|	struct packetlist *tmp_item = NULL, *curr_item = NULL;
  497|   209k|	if (!ses.dataallowed)
  ------------------
  |  Branch (497:6): [True: 104k, False: 104k]
  ------------------
  498|   104k|	{
  499|   104k|		TRACE(("maybe_empty_reply_queue - no data allowed"))
  500|   104k|		return;
  501|   104k|	}
  502|       |		
  503|   104k|	for (curr_item = ses.reply_queue_head; curr_item; ) {
  ------------------
  |  Branch (503:41): [True: 0, False: 104k]
  ------------------
  504|      0|		CHECKCLEARTOWRITE();
  505|      0|		buf_putbytes(ses.writepayload,
  506|      0|			curr_item->payload->data, curr_item->payload->len);
  507|       |			
  508|      0|		buf_free(curr_item->payload);
  509|      0|		tmp_item = curr_item;
  510|      0|		curr_item = curr_item->next;
  511|      0|		m_free(tmp_item);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 0]
  |  |  ------------------
  ------------------
  512|      0|		encrypt_packet();
  513|      0|	}
  514|       |	ses.reply_queue_head = ses.reply_queue_tail = NULL;
  515|   104k|}
encrypt_packet:
  519|  35.3k|void encrypt_packet() {
  520|       |
  521|  35.3k|	unsigned char padlen;
  522|  35.3k|	unsigned char blocksize, mac_size;
  523|  35.3k|	buffer * writebuf; /* the packet which will go on the wire. This is 
  524|       |	                      encrypted in-place. */
  525|  35.3k|	unsigned char packet_type;
  526|  35.3k|	unsigned int len, encrypt_buf_size;
  527|  35.3k|	unsigned char mac_bytes[MAX_MAC_LEN];
  528|       |
  529|  35.3k|	time_t now;
  530|       |	
  531|  35.3k|	TRACE2(("enter encrypt_packet()"))
  532|       |
  533|  35.3k|	buf_setpos(ses.writepayload, 0);
  534|  35.3k|	packet_type = buf_getbyte(ses.writepayload);
  535|  35.3k|	buf_setpos(ses.writepayload, 0);
  536|       |
  537|  35.3k|	TRACE2(("encrypt_packet type is %d", packet_type))
  538|       |	
  539|  35.3k|	if ((!ses.dataallowed && !packet_is_okay_kex(packet_type))) {
  ------------------
  |  Branch (539:7): [True: 19.5k, False: 15.8k]
  |  Branch (539:27): [True: 0, False: 19.5k]
  ------------------
  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|      0|		enqueue_reply_packet();
  544|      0|		return;
  545|      0|	}
  546|       |		
  547|  35.3k|	blocksize = ses.keys->trans.algo_crypt->blocksize;
  548|  35.3k|	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|  35.3k|	encrypt_buf_size = (ses.writepayload->len+4+1) 
  554|  35.3k|		+ MAX(MIN_PACKET_LEN, blocksize) + 3
  ------------------
  |  Branch (554:5): [True: 21.2k, False: 14.1k]
  ------------------
  555|       |	/* add space for the MAC at the end */
  556|  35.3k|				+ 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|  35.3k|				+ 1;
  564|       |
  565|  35.3k|	writebuf = buf_new(encrypt_buf_size);
  566|  35.3k|	buf_setlen(writebuf, PACKET_PAYLOAD_OFF);
  ------------------
  |  |   49|  35.3k|#define PACKET_PAYLOAD_OFF 5
  ------------------
  567|  35.3k|	buf_setpos(writebuf, PACKET_PAYLOAD_OFF);
  ------------------
  |  |   49|  35.3k|#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|  35.3k|	{
  576|  35.3k|		memcpy(buf_getwriteptr(writebuf, ses.writepayload->len),
  577|  35.3k|				buf_getptr(ses.writepayload, ses.writepayload->len),
  578|  35.3k|				ses.writepayload->len);
  579|  35.3k|		buf_incrwritepos(writebuf, ses.writepayload->len);
  580|  35.3k|	}
  581|       |
  582|       |	/* finished with payload */
  583|  35.3k|	buf_setpos(ses.writepayload, 0);
  584|  35.3k|	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|  35.3k|	len = writebuf->len;
  590|  35.3k|#if DROPBEAR_AEAD_MODE
  591|  35.3k|	if (ses.keys->trans.crypt_mode->aead_crypt) {
  ------------------
  |  Branch (591:6): [True: 3.51k, False: 31.8k]
  ------------------
  592|  3.51k|		len -= 4;
  593|  3.51k|	}
  594|  35.3k|#endif
  595|  35.3k|	padlen = blocksize - len % blocksize;
  596|  35.3k|	if (padlen < 4) {
  ------------------
  |  Branch (596:6): [True: 11.2k, False: 24.1k]
  ------------------
  597|  11.2k|		padlen += blocksize;
  598|  11.2k|	}
  599|       |	/* check for min packet length */
  600|  35.3k|	if (writebuf->len + padlen < MIN_PACKET_LEN) {
  ------------------
  |  |  241|  35.3k|#define MIN_PACKET_LEN 16
  ------------------
  |  Branch (600:6): [True: 515, False: 34.8k]
  ------------------
  601|    515|		padlen += blocksize;
  602|    515|	}
  603|       |
  604|  35.3k|	buf_setpos(writebuf, 0);
  605|       |	/* packet length excluding the packetlength uint32 */
  606|  35.3k|	buf_putint(writebuf, writebuf->len + padlen - 4);
  607|       |
  608|       |	/* padding len */
  609|  35.3k|	buf_putbyte(writebuf, padlen);
  610|       |	/* actual padding */
  611|  35.3k|	buf_setpos(writebuf, writebuf->len);
  612|  35.3k|	buf_incrlen(writebuf, padlen);
  613|  35.3k|	genrandom(buf_getptr(writebuf, padlen), padlen);
  614|       |
  615|  35.3k|#if DROPBEAR_AEAD_MODE
  616|  35.3k|	if (ses.keys->trans.crypt_mode->aead_crypt) {
  ------------------
  |  Branch (616:6): [True: 3.51k, False: 31.8k]
  ------------------
  617|       |		/* do the actual encryption, in-place */
  618|  3.51k|		buf_setpos(writebuf, 0);
  619|       |		/* encrypt it in-place*/
  620|  3.51k|		len = writebuf->len;
  621|  3.51k|		buf_incrlen(writebuf, mac_size);
  622|  3.51k|		if (ses.keys->trans.crypt_mode->aead_crypt(ses.transseq,
  ------------------
  |  Branch (622:7): [True: 0, False: 3.51k]
  ------------------
  623|  3.51k|					buf_getptr(writebuf, len),
  624|  3.51k|					buf_getwriteptr(writebuf, len + mac_size),
  625|  3.51k|					len, mac_size,
  626|  3.51k|					&ses.keys->trans.cipher_state, LTC_ENCRYPT) != CRYPT_OK) {
  ------------------
  |  |   68|  3.51k|#define LTC_ENCRYPT 0
  ------------------
  627|      0|			dropbear_exit("Error encrypting");
  628|      0|		}
  629|  3.51k|		buf_incrpos(writebuf, len + mac_size);
  630|  3.51k|	} else
  631|  31.8k|#endif
  632|  31.8k|	{
  633|  31.8k|		make_mac(ses.transseq, &ses.keys->trans, writebuf, writebuf->len, mac_bytes);
  634|       |
  635|       |		/* do the actual encryption, in-place */
  636|  31.8k|		buf_setpos(writebuf, 0);
  637|       |		/* encrypt it in-place*/
  638|  31.8k|		len = writebuf->len;
  639|  31.8k|		if (ses.keys->trans.crypt_mode->encrypt(
  ------------------
  |  Branch (639:7): [True: 0, False: 31.8k]
  ------------------
  640|  31.8k|					buf_getptr(writebuf, len),
  641|  31.8k|					buf_getwriteptr(writebuf, len),
  642|  31.8k|					len,
  643|  31.8k|					&ses.keys->trans.cipher_state) != CRYPT_OK) {
  644|      0|			dropbear_exit("Error encrypting");
  645|      0|		}
  646|  31.8k|		buf_incrpos(writebuf, len);
  647|       |
  648|       |		/* stick the MAC on it */
  649|  31.8k|		buf_putbytes(writebuf, mac_bytes, mac_size);
  650|  31.8k|	}
  651|       |
  652|       |	/* Update counts */
  653|  35.3k|	ses.kexstate.datatrans += writebuf->len;
  654|       |
  655|  35.3k|	writebuf_enqueue(writebuf);
  656|       |
  657|       |	/* Update counts */
  658|  35.3k|	ses.transseq++;
  659|       |
  660|  35.3k|	now = monotonic_now();
  661|  35.3k|	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|  35.3k|	if (packet_type != SSH_MSG_REQUEST_FAILURE
  ------------------
  |  |   65|  70.7k|#define SSH_MSG_REQUEST_FAILURE                 82
  ------------------
  |  Branch (665:6): [True: 35.3k, False: 0]
  ------------------
  666|  35.3k|		&& packet_type != SSH_MSG_UNIMPLEMENTED
  ------------------
  |  |   31|  70.7k|#define SSH_MSG_UNIMPLEMENTED          3
  ------------------
  |  Branch (666:6): [True: 15.5k, False: 19.8k]
  ------------------
  667|  15.5k|		&& packet_type != SSH_MSG_IGNORE) {
  ------------------
  |  |   30|  15.5k|#define SSH_MSG_IGNORE                 2
  ------------------
  |  Branch (667:6): [True: 15.5k, False: 0]
  ------------------
  668|  15.5k|		ses.last_packet_time_idle = now;
  669|       |
  670|  15.5k|	}
  671|       |
  672|  35.3k|	TRACE2(("leave encrypt_packet()"))
  673|  35.3k|}
writebuf_enqueue:
  675|  38.2k|void writebuf_enqueue(buffer * writebuf) {
  676|       |	/* enqueue the packet for sending. It will get freed after transmission. */
  677|  38.2k|	buf_setpos(writebuf, 0);
  678|  38.2k|	enqueue(&ses.writequeue, (void*)writebuf);
  679|  38.2k|	ses.writequeue_len += writebuf->len;
  680|  38.2k|}
packet.c:read_packet_init:
  214|   126k|static int read_packet_init() {
  215|       |
  216|   126k|	unsigned int maxlen;
  217|   126k|	int slen;
  218|   126k|	unsigned int len, plen;
  219|   126k|	unsigned int blocksize;
  220|   126k|	unsigned int macsize;
  221|       |
  222|       |
  223|   126k|	blocksize = ses.keys->recv.algo_crypt->blocksize;
  224|   126k|	macsize = ses.keys->recv.algo_mac->hashsize;
  225|       |
  226|   126k|	if (ses.readbuf == NULL) {
  ------------------
  |  Branch (226:6): [True: 43.5k, False: 82.9k]
  ------------------
  227|       |		/* start of a new packet */
  228|  43.5k|		ses.readbuf = buf_new(INIT_READBUF);
  ------------------
  |  |   51|  43.5k|#define INIT_READBUF 128
  ------------------
  229|  43.5k|	}
  230|       |
  231|   126k|	maxlen = blocksize - ses.readbuf->pos;
  232|       |			
  233|       |	/* read the rest of the packet if possible */
  234|   126k|	slen = read(ses.sock_in, buf_getwriteptr(ses.readbuf, maxlen),
  ------------------
  |  |   55|   126k|#define read(fd, buf, count) wrapfd_read(fd, buf, count)
  ------------------
  235|   126k|			maxlen);
  236|   126k|	if (slen == 0) {
  ------------------
  |  Branch (236:6): [True: 982, False: 125k]
  ------------------
  237|    982|		ses.remoteclosed();
  238|    982|	}
  239|   126k|	if (slen < 0) {
  ------------------
  |  Branch (239:6): [True: 124, False: 126k]
  ------------------
  240|    124|		if (errno == EINTR || errno == EAGAIN) {
  ------------------
  |  Branch (240:7): [True: 118, False: 6]
  |  Branch (240:25): [True: 0, False: 6]
  ------------------
  241|    118|			TRACE2(("leave read_packet_init: EINTR"))
  242|    118|			return DROPBEAR_FAILURE;
  ------------------
  |  |  112|    118|#define DROPBEAR_FAILURE -1
  ------------------
  243|    118|		}
  244|      6|		dropbear_exit("Error reading: %s", strerror(errno));
  245|    124|	}
  246|       |
  247|   126k|	buf_incrwritepos(ses.readbuf, slen);
  248|       |
  249|   126k|	if ((unsigned int)slen != maxlen) {
  ------------------
  |  Branch (249:6): [True: 82.8k, False: 43.5k]
  ------------------
  250|       |		/* don't have enough bytes to determine length, get next time */
  251|  82.8k|		return DROPBEAR_FAILURE;
  ------------------
  |  |  112|  82.8k|#define DROPBEAR_FAILURE -1
  ------------------
  252|  82.8k|	}
  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|  43.5k|	buf_setpos(ses.readbuf, 0);
  257|  43.5k|#if DROPBEAR_AEAD_MODE
  258|  43.5k|	if (ses.keys->recv.crypt_mode->aead_crypt) {
  ------------------
  |  Branch (258:6): [True: 0, False: 43.5k]
  ------------------
  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|  43.5k|#endif
  268|  43.5k|	{
  269|  43.5k|		if (ses.keys->recv.crypt_mode->decrypt(buf_getptr(ses.readbuf, blocksize), 
  ------------------
  |  Branch (269:7): [True: 0, False: 43.5k]
  ------------------
  270|  43.5k|					buf_getwriteptr(ses.readbuf, blocksize),
  271|  43.5k|					blocksize,
  272|  43.5k|					&ses.keys->recv.cipher_state) != CRYPT_OK) {
  273|      0|			dropbear_exit("Error decrypting");
  274|      0|		}
  275|  43.5k|		plen = buf_getint(ses.readbuf) + 4;
  276|  43.5k|		len = plen + macsize;
  277|  43.5k|	}
  278|       |
  279|  43.5k|	TRACE2(("packet size is %u, block %u mac %u", len, blocksize, macsize))
  280|       |
  281|       |
  282|       |	/* check packet length */
  283|  43.5k|	if ((len > RECV_MAX_PACKET_LEN) ||
  ------------------
  |  |  243|  43.5k|#define RECV_MAX_PACKET_LEN (MAX(35000, ((RECV_MAX_PAYLOAD_LEN)+100)))
  ------------------
  |  Branch (283:6): [True: 1.02k, False: 42.4k]
  |  Branch (283:13): [True: 42.5k, Folded]
  ------------------
  284|  42.4k|		(plen < blocksize) ||
  ------------------
  |  Branch (284:3): [True: 4, False: 42.4k]
  ------------------
  285|  42.4k|		(plen % blocksize != 0)) {
  ------------------
  |  Branch (285:3): [True: 27, False: 42.4k]
  ------------------
  286|     73|		dropbear_exit("Integrity error (bad packet size %u)", len);
  287|     73|	}
  288|       |
  289|  43.4k|	if (len > ses.readbuf->size) {
  ------------------
  |  Branch (289:6): [True: 7.53k, False: 35.9k]
  ------------------
  290|  7.53k|		ses.readbuf = buf_resize(ses.readbuf, len);		
  291|  7.53k|	}
  292|  43.4k|	buf_setlen(ses.readbuf, len);
  293|  43.4k|	buf_setpos(ses.readbuf, blocksize);
  294|  43.4k|	return DROPBEAR_SUCCESS;
  ------------------
  |  |  111|  43.4k|#define DROPBEAR_SUCCESS 0
  ------------------
  295|  43.5k|}
packet.c:checkmac:
  390|  42.3k|static int checkmac() {
  391|       |
  392|  42.3k|	unsigned char mac_bytes[MAX_MAC_LEN];
  393|  42.3k|	unsigned int mac_size, contents_len;
  394|       |	
  395|  42.3k|	mac_size = ses.keys->recv.algo_mac->hashsize;
  396|  42.3k|	contents_len = ses.readbuf->len - mac_size;
  397|       |
  398|  42.3k|	buf_setpos(ses.readbuf, 0);
  399|  42.3k|	make_mac(ses.recvseq, &ses.keys->recv, ses.readbuf, contents_len, mac_bytes);
  400|       |
  401|  42.3k|#if DROPBEAR_FUZZ
  402|  42.3k|	if (fuzz.fuzzing) {
  ------------------
  |  Branch (402:6): [True: 42.3k, False: 0]
  ------------------
  403|       |	 	/* fail 1 in 2000 times to test error path. */
  404|  42.3k|		unsigned int value = 0;
  405|  42.3k|		if (mac_size > sizeof(value)) {
  ------------------
  |  Branch (405:7): [True: 0, False: 42.3k]
  ------------------
  406|      0|			memcpy(&value, mac_bytes, sizeof(value));
  407|      0|		}
  408|  42.3k|		if (value % 2000 == 99) {
  ------------------
  |  Branch (408:7): [True: 0, False: 42.3k]
  ------------------
  409|      0|			return DROPBEAR_FAILURE;
  ------------------
  |  |  112|      0|#define DROPBEAR_FAILURE -1
  ------------------
  410|      0|		}
  411|  42.3k|		return DROPBEAR_SUCCESS;
  ------------------
  |  |  111|  42.3k|#define DROPBEAR_SUCCESS 0
  ------------------
  412|  42.3k|	}
  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;
  ------------------
  |  |  112|      0|#define DROPBEAR_FAILURE -1
  ------------------
  419|      0|	} else {
  420|      0|		return DROPBEAR_SUCCESS;
  ------------------
  |  |  111|      0|#define DROPBEAR_SUCCESS 0
  ------------------
  421|      0|	}
  422|      0|}
packet.c:packet_is_okay_kex:
  464|  19.5k|static int packet_is_okay_kex(unsigned char type) {
  465|  19.5k|	if (type >= SSH_MSG_USERAUTH_REQUEST) {
  ------------------
  |  |   42|  19.5k|#define SSH_MSG_USERAUTH_REQUEST            50
  ------------------
  |  Branch (465:6): [True: 0, False: 19.5k]
  ------------------
  466|      0|		return 0;
  467|      0|	}
  468|  19.5k|	if (type == SSH_MSG_SERVICE_REQUEST || type == SSH_MSG_SERVICE_ACCEPT) {
  ------------------
  |  |   33|  39.1k|#define SSH_MSG_SERVICE_REQUEST        5
  ------------------
              	if (type == SSH_MSG_SERVICE_REQUEST || type == SSH_MSG_SERVICE_ACCEPT) {
  ------------------
  |  |   34|  19.5k|#define SSH_MSG_SERVICE_ACCEPT         6
  ------------------
  |  Branch (468:6): [True: 0, False: 19.5k]
  |  Branch (468:41): [True: 0, False: 19.5k]
  ------------------
  469|      0|		return 0;
  470|      0|	}
  471|  19.5k|	if (type == SSH_MSG_KEXINIT) {
  ------------------
  |  |   36|  19.5k|#define SSH_MSG_KEXINIT                20
  ------------------
  |  Branch (471:6): [True: 0, False: 19.5k]
  ------------------
  472|       |		/* XXX should this die horribly if !dataallowed ?? */
  473|      0|		return 0;
  474|      0|	}
  475|  19.5k|	return 1;
  476|  19.5k|}
packet.c:make_mac:
  687|  74.2k|		unsigned char *output_mac) {
  688|  74.2k|	unsigned char seqbuf[4];
  689|  74.2k|	unsigned long bufsize;
  690|  74.2k|	hmac_state hmac;
  691|       |
  692|  74.2k|	if (key_state->algo_mac->hashsize > 0) {
  ------------------
  |  Branch (692:6): [True: 14.1k, False: 60.0k]
  ------------------
  693|       |		/* calculate the mac */
  694|  14.1k|		if (hmac_init(&hmac, 
  ------------------
  |  Branch (694:7): [True: 0, False: 14.1k]
  ------------------
  695|  14.1k|					key_state->hash_index,
  696|  14.1k|					key_state->mackey,
  697|  14.1k|					key_state->algo_mac->keysize) != CRYPT_OK) {
  698|      0|			dropbear_exit("HMAC error");
  699|      0|		}
  700|       |	
  701|       |		/* sequence number */
  702|  14.1k|		STORE32H(seqno, seqbuf);
  ------------------
  |  |   62|  14.1k|#define STORE32H(x, y)                          \
  |  |   63|  14.1k|do { ulong32 __t = __builtin_bswap32 ((x));     \
  |  |   64|  14.1k|      XMEMCPY ((y), &__t, 4); } while(0)
  |  |  ------------------
  |  |  |  |   39|  14.1k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (64:39): [Folded, False: 14.1k]
  |  |  ------------------
  ------------------
  703|  14.1k|		if (hmac_process(&hmac, seqbuf, 4) != CRYPT_OK) {
  ------------------
  |  Branch (703:7): [True: 0, False: 14.1k]
  ------------------
  704|      0|			dropbear_exit("HMAC error");
  705|      0|		}
  706|       |	
  707|       |		/* the actual contents */
  708|  14.1k|		buf_setpos(clear_buf, 0);
  709|  14.1k|		if (hmac_process(&hmac, 
  ------------------
  |  Branch (709:7): [True: 0, False: 14.1k]
  ------------------
  710|  14.1k|					buf_getptr(clear_buf, clear_len),
  711|  14.1k|					clear_len) != CRYPT_OK) {
  712|      0|			dropbear_exit("HMAC error");
  713|      0|		}
  714|       |	
  715|  14.1k|		bufsize = MAX_MAC_LEN;
  ------------------
  |  |  147|  14.1k|#define MAX_MAC_LEN 32
  ------------------
  716|  14.1k|		if (hmac_done(&hmac, output_mac, &bufsize) != CRYPT_OK) {
  ------------------
  |  Branch (716:7): [True: 0, False: 14.1k]
  ------------------
  717|      0|			dropbear_exit("HMAC error");
  718|      0|		}
  719|  14.1k|	}
  720|  74.2k|	TRACE2(("leave writemac"))
  721|  74.2k|}

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

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

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;
  ------------------
  |  |  112|      1|#define DROPBEAR_FAILURE -1
  ------------------
   56|      1|	TRACE(("enter buf_get_rsa_pub_key"))
   57|      1|	dropbear_assert(key != NULL);
  ------------------
  |  |   84|      1|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (84:37): [True: 0, False: 1]
  |  |  |  Branch (84:93): [Folded, False: 1]
  |  |  ------------------
  ------------------
   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" */
  ------------------
  |  |  117|      1|#define SSH_SIGNKEY_RSA_LEN 7
  ------------------
   64|       |
   65|      1|	if (buf_getmpint(buf, key->e) == DROPBEAR_FAILURE
  ------------------
  |  |  112|      2|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (65:6): [True: 0, False: 1]
  ------------------
   66|      1|	 || buf_getmpint(buf, key->n) == DROPBEAR_FAILURE) {
  ------------------
  |  |  112|      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) {
  ------------------
  |  |   69|      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;
  ------------------
  |  |  111|      1|#define DROPBEAR_SUCCESS 0
  ------------------
   84|      1|out:
   85|      1|	if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  112|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (85:6): [True: 0, False: 1]
  ------------------
   86|       |		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;
  ------------------
  |  |  112|      1|#define DROPBEAR_FAILURE -1
  ------------------
   96|       |
   97|      1|	TRACE(("enter buf_get_rsa_priv_key"))
   98|      1|	dropbear_assert(key != NULL);
  ------------------
  |  |   84|      1|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (84:37): [True: 0, False: 1]
  |  |  |  Branch (84:93): [Folded, False: 1]
  |  |  ------------------
  ------------------
   99|       |
  100|      1|	if (buf_get_rsa_pub_key(buf, key) == DROPBEAR_FAILURE) {
  ------------------
  |  |  112|      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;
  ------------------
  |  |  112|      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) {
  ------------------
  |  |  112|      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|       |		/* Keys without p or q are prior to Dropbear 0.33 from 2003. */
  117|      0|		dropbear_exit("RSA key format is ancient");
  118|      1|	} else {
  119|      1|		m_mp_alloc_init_multi(&key->p, &key->q, NULL);
  120|       |
  121|      1|		if (buf_getmpint(buf, key->p) == DROPBEAR_FAILURE) {
  ------------------
  |  |  112|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (121:7): [True: 0, False: 1]
  ------------------
  122|      0|			TRACE(("leave buf_get_rsa_priv_key: p: ret == DROPBEAR_FAILURE"))
  123|      0|			goto out;
  124|      0|		}
  125|       |
  126|      1|		if (buf_getmpint(buf, key->q) == DROPBEAR_FAILURE) {
  ------------------
  |  |  112|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (126:7): [True: 0, False: 1]
  ------------------
  127|      0|			TRACE(("leave buf_get_rsa_priv_key: q: ret == DROPBEAR_FAILURE"))
  128|      0|			goto out;
  129|      0|		}
  130|      1|	}
  131|       |
  132|      1|	ret = DROPBEAR_SUCCESS;
  ------------------
  |  |  111|      1|#define DROPBEAR_SUCCESS 0
  ------------------
  133|      1|out:
  134|      1|	if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  112|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (134:6): [True: 0, False: 1]
  ------------------
  135|       |		m_mp_free_multi(&key->d, &key->p, &key->q, NULL);
  136|      0|	}
  137|      1|	TRACE(("leave buf_get_rsa_priv_key"))
  138|      1|	return ret;
  139|      1|}
rsa_key_free:
  143|      1|void rsa_key_free(dropbear_rsa_key *key) {
  144|       |
  145|      1|	TRACE2(("enter rsa_key_free"))
  146|       |
  147|      1|	if (key == NULL) {
  ------------------
  |  Branch (147:6): [True: 1, False: 0]
  ------------------
  148|      1|		TRACE2(("leave rsa_key_free: key == NULL"))
  149|      1|		return;
  150|      1|	}
  151|      0|	m_mp_free_multi(&key->d, &key->e, &key->p, &key->q, &key->n, NULL);
  152|       |	m_free(key);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 0]
  |  |  ------------------
  ------------------
  153|      0|	TRACE2(("leave rsa_key_free"))
  154|      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|      7|enum signkey_type signkey_type_from_name(const char* name, unsigned int namelen) {
   87|      7|	int i;
   88|     40|	for (i = 0; i < DROPBEAR_SIGNKEY_NUM_NAMED; i++) {
  ------------------
  |  Branch (88:14): [True: 37, False: 3]
  ------------------
   89|     37|		const char *fixed_name = signkey_names[i];
   90|     37|		if (namelen == strlen(fixed_name)
  ------------------
  |  Branch (90:7): [True: 5, False: 32]
  ------------------
   91|      5|			&& 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, False: 4]
  ------------------
   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|     37|	}
  114|       |
  115|      3|	TRACE(("signkey_type_from_name unexpected key type."))
  116|       |
  117|      3|	return DROPBEAR_SIGNKEY_NONE;
  118|      7|}
signature_type_from_name:
  145|      3|enum signature_type signature_type_from_name(const char* name, unsigned int namelen) {
  146|      3|#if DROPBEAR_RSA
  147|      3|#if DROPBEAR_RSA_SHA256
  148|      3|	if (namelen == strlen(SSH_SIGNATURE_RSA_SHA256) 
  ------------------
  |  |  121|      3|#define SSH_SIGNATURE_RSA_SHA256 "rsa-sha2-256"
  ------------------
  |  Branch (148:6): [True: 0, False: 3]
  ------------------
  149|      0|		&& memcmp(name, SSH_SIGNATURE_RSA_SHA256, namelen) == 0) {
  ------------------
  |  |  121|      0|#define SSH_SIGNATURE_RSA_SHA256 "rsa-sha2-256"
  ------------------
  |  Branch (149:6): [True: 0, False: 0]
  ------------------
  150|      0|		return DROPBEAR_SIGNATURE_RSA_SHA256;
  151|      0|	}
  152|      3|#endif
  153|      3|#if DROPBEAR_RSA_SHA1
  154|      3|	if (namelen == strlen(SSH_SIGNKEY_RSA) 
  ------------------
  |  |  116|      3|#define SSH_SIGNKEY_RSA "ssh-rsa"
  ------------------
  |  Branch (154:6): [True: 0, False: 3]
  ------------------
  155|      0|		&& memcmp(name, SSH_SIGNKEY_RSA, namelen) == 0) {
  ------------------
  |  |  116|      0|#define SSH_SIGNKEY_RSA "ssh-rsa"
  ------------------
  |  Branch (155:6): [True: 0, False: 0]
  ------------------
  156|      0|		return DROPBEAR_SIGNATURE_RSA_SHA1;
  157|      0|	}
  158|      3|#endif
  159|      3|#endif /* DROPBEAR_RSA */
  160|      3|	return (enum signature_type)signkey_type_from_name(name, namelen);
  161|      3|}
signkey_type_from_signature:
  173|  6.72k|enum signkey_type signkey_type_from_signature(enum signature_type sigtype) {
  174|  6.72k|#if DROPBEAR_RSA
  175|  6.72k|#if DROPBEAR_RSA_SHA256
  176|  6.72k|	if (sigtype == DROPBEAR_SIGNATURE_RSA_SHA256) {
  ------------------
  |  Branch (176:6): [True: 2, False: 6.72k]
  ------------------
  177|      2|		return DROPBEAR_SIGNKEY_RSA;
  178|      2|	}
  179|  6.72k|#endif
  180|  6.72k|#if DROPBEAR_RSA_SHA1
  181|  6.72k|	if (sigtype == DROPBEAR_SIGNATURE_RSA_SHA1) {
  ------------------
  |  Branch (181:6): [True: 2, False: 6.72k]
  ------------------
  182|      2|		return DROPBEAR_SIGNKEY_RSA;
  183|      2|	}
  184|  6.72k|#endif
  185|  6.72k|#endif /* DROPBEAR_RSA */
  186|  6.72k|	assert((int)sigtype < (int)DROPBEAR_SIGNKEY_NUM_NAMED);
  ------------------
  |  Branch (186:2): [True: 0, False: 6.72k]
  |  Branch (186:2): [True: 6.72k, False: 0]
  ------------------
  187|  6.72k|	return (enum signkey_type)sigtype;
  188|  6.72k|}
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|       |			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;
  ------------------
  |  |  112|      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, False: 4]
  |  |  ------------------
  ------------------
  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;
  ------------------
  |  |  112|      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) {
  ------------------
  |  |  112|      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) {
  ------------------
  |  |  112|      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, False: 0]
  |  |  ------------------
  ------------------
  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;
  ------------------
  |  |  111|      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) {
  ------------------
  |  |  112|      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, False: 0]
  |  |  ------------------
  ------------------
  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|}

svr_authinitialise:
   42|  2.84k|void svr_authinitialise() {
   43|  2.84k|	memset(&ses.authstate, 0, sizeof(ses.authstate));
   44|  2.84k|#if DROPBEAR_SVR_PUBKEY_AUTH
   45|  2.84k|	ses.authstate.authtypes |= AUTH_TYPE_PUBKEY;
  ------------------
  |  |  103|  2.84k|#define AUTH_TYPE_PUBKEY    (1 << 1)
  ------------------
   46|  2.84k|#endif
   47|  2.84k|#if DROPBEAR_SVR_PASSWORD_AUTH || DROPBEAR_SVR_PAM_AUTH
   48|  2.84k|	if (!svr_opts.noauthpass) {
  ------------------
  |  Branch (48:6): [True: 2.84k, False: 0]
  ------------------
   49|  2.84k|		ses.authstate.authtypes |= AUTH_TYPE_PASSWORD;
  ------------------
  |  |  104|  2.84k|#define AUTH_TYPE_PASSWORD  (1 << 2)
  ------------------
   50|  2.84k|	}
   51|  2.84k|#endif
   52|  2.84k|}
recv_msg_userauth_request:
   73|  1.30k|void recv_msg_userauth_request() {
   74|       |
   75|  1.30k|	char *username = NULL, *servicename = NULL, *methodname = NULL;
   76|  1.30k|	unsigned int userlen, servicelen, methodlen;
   77|  1.30k|	int valid_user = 0;
   78|       |
   79|  1.30k|	TRACE(("enter recv_msg_userauth_request"))
   80|       |
   81|       |	/* for compensating failure delay */
   82|  1.30k|	gettime_wrapper(&ses.authstate.auth_starttime);
   83|       |
   84|       |	/* ignore packets if auth is already done */
   85|  1.30k|	if (ses.authstate.authdone == 1) {
  ------------------
  |  Branch (85:6): [True: 0, False: 1.30k]
  ------------------
   86|      0|		TRACE(("leave recv_msg_userauth_request: authdone already"))
   87|      0|		return;
   88|      0|	}
   89|       |
   90|       |	/* send the banner if it exists, it will only exist once */
   91|  1.30k|	if (svr_opts.banner) {
  ------------------
  |  Branch (91:6): [True: 0, False: 1.30k]
  ------------------
   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|  1.30k|	username = buf_getstring(ses.payload, &userlen);
   98|  1.30k|	servicename = buf_getstring(ses.payload, &servicelen);
   99|  1.30k|	methodname = buf_getstring(ses.payload, &methodlen);
  100|       |
  101|       |	/* only handle 'ssh-connection' currently */
  102|  1.30k|	if (!(servicelen == SSH_SERVICE_CONNECTION_LEN
  ------------------
  |  |  111|  2.60k|#define SSH_SERVICE_CONNECTION_LEN 14
  ------------------
  |  Branch (102:8): [True: 1.27k, False: 22]
  ------------------
  103|  1.27k|			&& (strncmp(servicename, SSH_SERVICE_CONNECTION,
  ------------------
  |  |  110|  1.27k|#define SSH_SERVICE_CONNECTION "ssh-connection"
  ------------------
  |  Branch (103:7): [True: 1.16k, False: 111]
  ------------------
  104|  1.27k|					SSH_SERVICE_CONNECTION_LEN) == 0))) {
  ------------------
  |  |  111|  1.27k|#define SSH_SERVICE_CONNECTION_LEN 14
  ------------------
  105|    123|		m_free(username);
  ------------------
  |  |   24|    123|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 123]
  |  |  ------------------
  ------------------
  106|    123|		m_free(servicename);
  ------------------
  |  |   24|    123|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 123]
  |  |  ------------------
  ------------------
  107|    123|		m_free(methodname);
  ------------------
  |  |   24|    123|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 123]
  |  |  ------------------
  ------------------
  108|    123|		dropbear_exit("unknown service in auth");
  109|    123|	}
  110|       |
  111|       |	/* check username is good before continuing. 
  112|       |	 * the 'incrfail' varies depending on the auth method to
  113|       |	 * avoid giving away which users exist on the system through
  114|       |	 * the time delay. */
  115|  1.17k|	if (checkusername(username, userlen) == DROPBEAR_SUCCESS) {
  ------------------
  |  |  111|  1.17k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (115:6): [True: 7, False: 1.17k]
  ------------------
  116|      7|		valid_user = 1;
  117|      7|	}
  118|       |
  119|       |	/* user wants to know what methods are supported */
  120|  1.17k|	if (methodlen == AUTH_METHOD_NONE_LEN &&
  ------------------
  |  |  108|  2.35k|#define AUTH_METHOD_NONE_LEN 4
  ------------------
  |  Branch (120:6): [True: 281, False: 896]
  ------------------
  121|    281|			strncmp(methodname, AUTH_METHOD_NONE,
  ------------------
  |  |  107|    281|#define AUTH_METHOD_NONE "none"
  ------------------
  |  Branch (121:4): [True: 173, False: 108]
  ------------------
  122|    281|				AUTH_METHOD_NONE_LEN) == 0) {
  ------------------
  |  |  108|    281|#define AUTH_METHOD_NONE_LEN 4
  ------------------
  123|    173|		TRACE(("recv_msg_userauth_request: 'none' request"))
  124|    173|		if (valid_user
  ------------------
  |  Branch (124:7): [True: 0, False: 173]
  ------------------
  125|      0|				&& svr_opts.allowblankpass
  ------------------
  |  Branch (125:8): [True: 0, False: 0]
  ------------------
  126|      0|				&& !svr_opts.noauthpass
  ------------------
  |  Branch (126:8): [True: 0, False: 0]
  ------------------
  127|      0|				&& !(svr_opts.norootpass && ses.authstate.pw_uid == 0) 
  ------------------
  |  Branch (127:10): [True: 0, False: 0]
  |  Branch (127:33): [True: 0, False: 0]
  ------------------
  128|      0|				&& ses.authstate.pw_passwd[0] == '\0') 
  ------------------
  |  Branch (128:8): [True: 0, False: 0]
  ------------------
  129|      0|		{
  130|      0|			dropbear_log(LOG_NOTICE, 
  131|      0|					"Auth succeeded with blank password for '%s' from %s",
  132|      0|					ses.authstate.pw_name,
  133|      0|					svr_ses.addrstring);
  134|      0|			send_msg_userauth_success();
  135|      0|			goto out;
  136|      0|		}
  137|    173|		else
  138|    173|		{
  139|       |			/* 'none' has no failure delay */
  140|    173|			send_msg_userauth_failure(0, 0);
  141|    173|			goto out;
  142|    173|		}
  143|    173|	}
  144|       |	
  145|  1.00k|#if DROPBEAR_SVR_PASSWORD_AUTH
  146|  1.00k|	if (!svr_opts.noauthpass &&
  ------------------
  |  Branch (146:6): [True: 868, False: 136]
  ------------------
  147|    868|			!(svr_opts.norootpass && ses.authstate.pw_uid == 0) ) {
  ------------------
  |  Branch (147:6): [True: 0, False: 868]
  |  Branch (147:29): [True: 0, False: 0]
  ------------------
  148|       |		/* user wants to try password auth */
  149|    868|		if (methodlen == AUTH_METHOD_PASSWORD_LEN &&
  ------------------
  |  |  112|  1.73k|#define AUTH_METHOD_PASSWORD_LEN 8
  ------------------
  |  Branch (149:7): [True: 189, False: 679]
  ------------------
  150|    189|				strncmp(methodname, AUTH_METHOD_PASSWORD,
  ------------------
  |  |  111|    189|#define AUTH_METHOD_PASSWORD "password"
  ------------------
  |  Branch (150:5): [True: 74, False: 115]
  ------------------
  151|    189|					AUTH_METHOD_PASSWORD_LEN) == 0) {
  ------------------
  |  |  112|    189|#define AUTH_METHOD_PASSWORD_LEN 8
  ------------------
  152|     74|			svr_auth_password(valid_user);
  153|     74|			goto out;
  154|     74|		}
  155|    868|	}
  156|    930|#endif
  157|       |
  158|       |#if DROPBEAR_SVR_PAM_AUTH
  159|       |	if (!svr_opts.noauthpass &&
  160|       |			!(svr_opts.norootpass && ses.authstate.pw_uid == 0) ) {
  161|       |		/* user wants to try password auth */
  162|       |		if (methodlen == AUTH_METHOD_PASSWORD_LEN &&
  163|       |				strncmp(methodname, AUTH_METHOD_PASSWORD,
  164|       |					AUTH_METHOD_PASSWORD_LEN) == 0) {
  165|       |			svr_auth_pam(valid_user);
  166|       |			goto out;
  167|       |		}
  168|       |	}
  169|       |#endif
  170|       |
  171|    930|#if DROPBEAR_SVR_PUBKEY_AUTH
  172|       |	/* user wants to try pubkey auth */
  173|    930|	if (methodlen == AUTH_METHOD_PUBKEY_LEN &&
  ------------------
  |  |  110|  1.86k|#define AUTH_METHOD_PUBKEY_LEN 9
  ------------------
  |  Branch (173:6): [True: 487, False: 443]
  ------------------
  174|    487|			strncmp(methodname, AUTH_METHOD_PUBKEY,
  ------------------
  |  |  109|    487|#define AUTH_METHOD_PUBKEY "publickey"
  ------------------
  |  Branch (174:4): [True: 267, False: 220]
  ------------------
  175|    487|				AUTH_METHOD_PUBKEY_LEN) == 0) {
  ------------------
  |  |  110|    487|#define AUTH_METHOD_PUBKEY_LEN 9
  ------------------
  176|    267|		svr_auth_pubkey(valid_user);
  177|    267|		goto out;
  178|    267|	}
  179|    663|#endif
  180|       |
  181|       |	/* nothing matched, we just fail with a delay */
  182|    663|	send_msg_userauth_failure(0, 1);
  183|       |
  184|    960|out:
  185|       |
  186|    960|	m_free(username);
  ------------------
  |  |   24|    960|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 960]
  |  |  ------------------
  ------------------
  187|    960|	m_free(servicename);
  ------------------
  |  |   24|    960|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 960]
  |  |  ------------------
  ------------------
  188|       |	m_free(methodname);
  ------------------
  |  |   24|    960|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 960]
  |  |  ------------------
  ------------------
  189|    960|}
send_msg_userauth_failure:
  348|    962|void send_msg_userauth_failure(int partial, int incrfail) {
  349|       |
  350|    962|	buffer *typebuf = NULL;
  351|       |
  352|    962|	TRACE(("enter send_msg_userauth_failure"))
  353|       |
  354|    962|	CHECKCLEARTOWRITE();
  355|       |	
  356|    962|	buf_putbyte(ses.writepayload, SSH_MSG_USERAUTH_FAILURE);
  ------------------
  |  |   43|    962|#define SSH_MSG_USERAUTH_FAILURE            51
  ------------------
  357|       |
  358|       |	/* put a list of allowed types */
  359|    962|	typebuf = buf_new(30); /* long enough for PUBKEY and PASSWORD */
  360|       |
  361|    962|	if (ses.authstate.authtypes & AUTH_TYPE_PUBKEY) {
  ------------------
  |  |  103|    962|#define AUTH_TYPE_PUBKEY    (1 << 1)
  ------------------
  |  Branch (361:6): [True: 962, False: 0]
  ------------------
  362|    962|		buf_putbytes(typebuf, (const unsigned char *)AUTH_METHOD_PUBKEY, AUTH_METHOD_PUBKEY_LEN);
  ------------------
  |  |  109|    962|#define AUTH_METHOD_PUBKEY "publickey"
  ------------------
              		buf_putbytes(typebuf, (const unsigned char *)AUTH_METHOD_PUBKEY, AUTH_METHOD_PUBKEY_LEN);
  ------------------
  |  |  110|    962|#define AUTH_METHOD_PUBKEY_LEN 9
  ------------------
  363|    962|		if (ses.authstate.authtypes & AUTH_TYPE_PASSWORD) {
  ------------------
  |  |  104|    962|#define AUTH_TYPE_PASSWORD  (1 << 2)
  ------------------
  |  Branch (363:7): [True: 962, False: 0]
  ------------------
  364|    962|			buf_putbyte(typebuf, ',');
  365|    962|		}
  366|    962|	}
  367|       |	
  368|    962|	if (ses.authstate.authtypes & AUTH_TYPE_PASSWORD) {
  ------------------
  |  |  104|    962|#define AUTH_TYPE_PASSWORD  (1 << 2)
  ------------------
  |  Branch (368:6): [True: 962, False: 0]
  ------------------
  369|    962|		buf_putbytes(typebuf, (const unsigned char *)AUTH_METHOD_PASSWORD, AUTH_METHOD_PASSWORD_LEN);
  ------------------
  |  |  111|    962|#define AUTH_METHOD_PASSWORD "password"
  ------------------
              		buf_putbytes(typebuf, (const unsigned char *)AUTH_METHOD_PASSWORD, AUTH_METHOD_PASSWORD_LEN);
  ------------------
  |  |  112|    962|#define AUTH_METHOD_PASSWORD_LEN 8
  ------------------
  370|    962|	}
  371|       |
  372|    962|	buf_putbufstring(ses.writepayload, typebuf);
  373|       |
  374|    962|	TRACE(("auth fail: methods %d, '%.*s'", ses.authstate.authtypes,
  375|    962|				typebuf->len, typebuf->data))
  376|       |
  377|    962|	buf_free(typebuf);
  378|       |
  379|    962|	buf_putbyte(ses.writepayload, partial ? 1 : 0);
  ------------------
  |  Branch (379:32): [True: 0, False: 962]
  ------------------
  380|    962|	encrypt_packet();
  381|       |
  382|    962|	if (incrfail) {
  ------------------
  |  Branch (382:6): [True: 597, False: 365]
  ------------------
  383|       |		/* The SSH_MSG_AUTH_FAILURE response is delayed to attempt to
  384|       |		avoid user enumeration and slow brute force attempts.
  385|       |		The delay is adjusted by the time already spent in processing
  386|       |		authentication (ses.authstate.auth_starttime timestamp). */
  387|       |
  388|       |		/* Desired total delay 300ms +-50ms (in nanoseconds).
  389|       |		Beware of integer overflow if increasing these values */
  390|    597|		const uint32_t mindelay = 250000000;
  391|    597|		const uint32_t vardelay = 100000000;
  392|    597|		uint32_t rand_delay;
  393|    597|		struct timespec delay;
  394|       |
  395|    597|		gettime_wrapper(&delay);
  396|    597|		delay.tv_sec -= ses.authstate.auth_starttime.tv_sec;
  397|    597|		delay.tv_nsec -= ses.authstate.auth_starttime.tv_nsec;
  398|       |
  399|       |		/* carry */
  400|    597|		if (delay.tv_nsec < 0) {
  ------------------
  |  Branch (400:7): [True: 0, False: 597]
  ------------------
  401|      0|			delay.tv_nsec += 1000000000;
  402|      0|			delay.tv_sec -= 1;
  403|      0|		}
  404|       |
  405|    597|		genrandom((unsigned char*)&rand_delay, sizeof(rand_delay));
  406|    597|		rand_delay = mindelay + (rand_delay % vardelay);
  407|       |
  408|    597|		if (delay.tv_sec == 0 && delay.tv_nsec <= rand_delay) {
  ------------------
  |  Branch (408:7): [True: 597, False: 0]
  |  Branch (408:28): [True: 597, False: 0]
  ------------------
  409|       |			/* Compensate for elapsed time */
  410|    597|			delay.tv_nsec = rand_delay - delay.tv_nsec;
  411|    597|		} else {
  412|       |			/* No time left or time went backwards, just delay anyway */
  413|      0|			delay.tv_sec = 0;
  414|      0|			delay.tv_nsec = rand_delay;
  415|      0|		}
  416|       |
  417|       |
  418|    597|#if DROPBEAR_FUZZ
  419|    597|		if (!fuzz.fuzzing)
  ------------------
  |  Branch (419:7): [True: 0, False: 597]
  ------------------
  420|      0|#endif
  421|      0|		{
  422|      0|			while (nanosleep(&delay, &delay) == -1 && errno == EINTR) { /* Go back to sleep */ }
  ------------------
  |  Branch (422:11): [True: 0, False: 0]
  |  Branch (422:46): [True: 0, False: 0]
  ------------------
  423|      0|		}
  424|       |
  425|    597|		ses.authstate.failcount++;
  426|    597|	}
  427|       |
  428|    962|	if (ses.authstate.failcount > svr_opts.maxauthtries) {
  ------------------
  |  Branch (428:6): [True: 2, False: 960]
  ------------------
  429|      2|		char * userstr;
  430|       |		/* XXX - send disconnect ? */
  431|      2|		TRACE(("Max auth tries reached, exiting"))
  432|       |
  433|      2|		if (ses.authstate.pw_name == NULL) {
  ------------------
  |  Branch (433:7): [True: 2, False: 0]
  ------------------
  434|      2|			userstr = "is invalid";
  435|      2|		} else {
  436|      0|			userstr = ses.authstate.pw_name;
  437|      0|		}
  438|      2|		dropbear_exit("Max auth tries reached - user '%s'",
  439|      2|				userstr);
  440|      2|	}
  441|       |	
  442|    962|	TRACE(("leave send_msg_userauth_failure"))
  443|    962|}
svr-auth.c:checkusername:
  229|  1.16k|static int checkusername(const char *username, unsigned int userlen) {
  230|       |
  231|  1.16k|	char* listshell = NULL;
  232|  1.16k|	char* usershell = NULL;
  233|  1.16k|	uid_t uid;
  234|       |
  235|  1.16k|	TRACE(("enter checkusername"))
  236|  1.16k|	if (userlen > MAX_USERNAME_LEN) {
  ------------------
  |  |  100|  1.16k|#define MAX_USERNAME_LEN 100 /* arbitrary for the moment */
  ------------------
  |  Branch (236:6): [True: 34, False: 1.13k]
  ------------------
  237|     34|		return DROPBEAR_FAILURE;
  ------------------
  |  |  112|     34|#define DROPBEAR_FAILURE -1
  ------------------
  238|     34|	}
  239|       |
  240|  1.13k|	if (strlen(username) != userlen) {
  ------------------
  |  Branch (240:6): [True: 7, False: 1.12k]
  ------------------
  241|      7|		dropbear_exit("Attempted username with a null byte");
  242|      7|	}
  243|       |
  244|  1.12k|	if (ses.authstate.username == NULL) {
  ------------------
  |  Branch (244:6): [True: 483, False: 643]
  ------------------
  245|       |		/* first request */
  246|    483|		fill_passwd(username);
  247|    483|		ses.authstate.username = m_strdup(username);
  248|    643|	} else {
  249|       |		/* check username hasn't changed */
  250|    643|		if (strcmp(username, ses.authstate.username) != 0) {
  ------------------
  |  Branch (250:7): [True: 119, False: 524]
  ------------------
  251|    119|			dropbear_exit("Client trying multiple usernames");
  252|    119|		}
  253|    643|	}
  254|       |
  255|       |	/* avoids cluttering logs with repeated failure messages from
  256|       |	consecutive authentication requests in a sesssion */
  257|  1.00k|	if (ses.authstate.checkusername_failed) {
  ------------------
  |  Branch (257:6): [True: 522, False: 485]
  ------------------
  258|    522|		TRACE(("checkusername: returning cached failure"))
  259|    522|		return DROPBEAR_FAILURE;
  ------------------
  |  |  112|    522|#define DROPBEAR_FAILURE -1
  ------------------
  260|    522|	}
  261|       |
  262|       |	/* check that user exists */
  263|    485|	if (!ses.authstate.pw_name) {
  ------------------
  |  Branch (263:6): [True: 478, False: 7]
  ------------------
  264|    478|		TRACE(("leave checkusername: user '%s' doesn't exist", username))
  265|    478|		dropbear_log(LOG_WARNING,
  266|    478|				"Login attempt for nonexistent user from %s",
  267|    478|				svr_ses.addrstring);
  268|    478|		ses.authstate.checkusername_failed = 1;
  269|    478|		return DROPBEAR_FAILURE;
  ------------------
  |  |  112|    478|#define DROPBEAR_FAILURE -1
  ------------------
  270|    478|	}
  271|       |
  272|       |	/* check if we are running as non-root, and login user is different from the server */
  273|      7|	uid = geteuid();
  274|      7|	if (!(DROPBEAR_SVR_MULTIUSER && uid == 0) && uid != ses.authstate.pw_uid) {
  ------------------
  |  |  393|     14|#define DROPBEAR_SVR_MULTIUSER 1
  |  |  ------------------
  |  |  |  Branch (393:32): [True: 7, Folded]
  |  |  ------------------
  ------------------
  |  Branch (274:34): [True: 7, False: 0]
  |  Branch (274:47): [True: 0, False: 0]
  ------------------
  275|      0|		TRACE(("running as nonroot, only server uid is allowed"))
  276|      0|		dropbear_log(LOG_WARNING,
  277|      0|				"Login attempt with wrong user %s from %s",
  278|      0|				ses.authstate.pw_name,
  279|      0|				svr_ses.addrstring);
  280|      0|		ses.authstate.checkusername_failed = 1;
  281|      0|		return DROPBEAR_FAILURE;
  ------------------
  |  |  112|      0|#define DROPBEAR_FAILURE -1
  ------------------
  282|      0|	}
  283|       |
  284|       |	/* check for non-root if desired */
  285|      7|	if (svr_opts.norootlogin && ses.authstate.pw_uid == 0) {
  ------------------
  |  Branch (285:6): [True: 0, False: 7]
  |  Branch (285:30): [True: 0, False: 0]
  ------------------
  286|      0|		TRACE(("leave checkusername: root login disabled"))
  287|      0|		dropbear_log(LOG_WARNING, "root login rejected");
  288|      0|		ses.authstate.checkusername_failed = 1;
  289|      0|		return DROPBEAR_FAILURE;
  ------------------
  |  |  112|      0|#define DROPBEAR_FAILURE -1
  ------------------
  290|      0|	}
  291|       |
  292|       |	/* check for login restricted to certain group if desired */
  293|      7|#ifdef HAVE_GETGROUPLIST
  294|      7|	if (svr_opts.restrict_group) {
  ------------------
  |  Branch (294:6): [True: 0, False: 7]
  ------------------
  295|      0|		if (check_group_membership(svr_opts.restrict_group_gid,
  ------------------
  |  Branch (295:7): [True: 0, False: 0]
  ------------------
  296|      0|				ses.authstate.pw_name, ses.authstate.pw_gid) == DROPBEAR_FAILURE) {
  ------------------
  |  |  112|      0|#define DROPBEAR_FAILURE -1
  ------------------
  297|      0|			dropbear_log(LOG_WARNING,
  298|      0|				"Logins are restricted to the group %s but user '%s' is not a member",
  299|      0|				svr_opts.restrict_group, ses.authstate.pw_name);
  300|      0|			ses.authstate.checkusername_failed = 1;
  301|      0|			return DROPBEAR_FAILURE;
  ------------------
  |  |  112|      0|#define DROPBEAR_FAILURE -1
  ------------------
  302|      0|		}
  303|      0|	}
  304|      7|#endif /* HAVE_GETGROUPLIST */
  305|       |
  306|      7|	TRACE(("shell is %s", ses.authstate.pw_shell))
  307|       |
  308|       |	/* check that the shell is set */
  309|      7|	usershell = ses.authstate.pw_shell;
  310|      7|	if (usershell[0] == '\0') {
  ------------------
  |  Branch (310:6): [True: 0, False: 7]
  ------------------
  311|       |		/* empty shell in /etc/passwd means /bin/sh according to passwd(5) */
  312|      0|		usershell = "/bin/sh";
  313|      0|	}
  314|       |
  315|       |	/* check the shell is valid. If /etc/shells doesn't exist, getusershell()
  316|       |	 * should return some standard shells like "/bin/sh" and "/bin/csh" (this
  317|       |	 * is platform-specific) */
  318|      7|	setusershell();
  319|      7|	while ((listshell = getusershell()) != NULL) {
  ------------------
  |  Branch (319:9): [True: 7, False: 0]
  ------------------
  320|      7|		TRACE(("test shell is '%s'", listshell))
  321|      7|		if (strcmp(listshell, usershell) == 0) {
  ------------------
  |  Branch (321:7): [True: 7, False: 0]
  ------------------
  322|       |			/* have a match */
  323|      7|			goto goodshell;
  324|      7|		}
  325|      7|	}
  326|       |	/* no matching shell */
  327|      0|	endusershell();
  328|      0|	TRACE(("no matching shell"))
  329|      0|	ses.authstate.checkusername_failed = 1;
  330|      0|	dropbear_log(LOG_WARNING, "User '%s' has invalid shell, rejected",
  331|      0|				ses.authstate.pw_name);
  332|      0|	return DROPBEAR_FAILURE;
  ------------------
  |  |  112|      0|#define DROPBEAR_FAILURE -1
  ------------------
  333|       |	
  334|      7|goodshell:
  335|      7|	endusershell();
  336|      7|	TRACE(("matching shell"))
  337|       |
  338|      7|	TRACE(("uid = %d", ses.authstate.pw_uid))
  339|      7|	TRACE(("leave checkusername"))
  340|      7|	return DROPBEAR_SUCCESS;
  ------------------
  |  |  111|      7|#define DROPBEAR_SUCCESS 0
  ------------------
  341|      7|}

svr_auth_password:
   51|     74|void svr_auth_password(int valid_user) {
   52|       |	
   53|     74|	char * passwdcrypt = NULL; /* the crypt from /etc/passwd or /etc/shadow */
   54|     74|	char * testcrypt = NULL; /* crypt generated from the user's password sent */
   55|     74|	char * password = NULL;
   56|     74|	unsigned int passwordlen;
   57|     74|	unsigned int changepw;
   58|       |
   59|       |	/* check if client wants to change password */
   60|     74|	changepw = buf_getbool(ses.payload);
   61|     74|	if (changepw) {
  ------------------
  |  Branch (61:6): [True: 45, False: 29]
  ------------------
   62|       |		/* not implemented by this server */
   63|     45|		send_msg_userauth_failure(0, 1);
   64|     45|		return;
   65|     45|	}
   66|       |
   67|     29|	password = buf_getstring(ses.payload, &passwordlen);
   68|     29|	if (valid_user && passwordlen <= DROPBEAR_MAX_PASSWORD_LEN) {
  ------------------
  |  |  131|      0|#define DROPBEAR_MAX_PASSWORD_LEN 100
  ------------------
  |  Branch (68:6): [True: 0, False: 29]
  |  Branch (68:20): [True: 0, False: 0]
  ------------------
   69|       |		/* the first bytes of passwdcrypt are the salt */
   70|      0|		passwdcrypt = ses.authstate.pw_passwd;
   71|      0|		testcrypt = crypt(password, passwdcrypt);
   72|      0|	}
   73|     29|	m_burn(password, passwordlen);
   74|     29|	m_free(password);
  ------------------
  |  |   24|     29|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 29]
  |  |  ------------------
  ------------------
   75|       |
   76|       |	/* After we have got the payload contents we can exit if the username
   77|       |	is invalid. Invalid users have already been logged. */
   78|     29|	if (!valid_user) {
  ------------------
  |  Branch (78:6): [True: 25, False: 4]
  ------------------
   79|     25|		send_msg_userauth_failure(0, 1);
   80|     25|		return;
   81|     25|	}
   82|       |
   83|      4|	if (passwordlen > DROPBEAR_MAX_PASSWORD_LEN) {
  ------------------
  |  |  131|      4|#define DROPBEAR_MAX_PASSWORD_LEN 100
  ------------------
  |  Branch (83:6): [True: 0, False: 4]
  ------------------
   84|      0|		dropbear_log(LOG_WARNING,
   85|      0|				"Too-long password attempt for '%s' from %s",
   86|      0|				ses.authstate.pw_name,
   87|      0|				svr_ses.addrstring);
   88|      0|		send_msg_userauth_failure(0, 1);
   89|      0|		return;
   90|      0|	}
   91|       |
   92|      4|	if (testcrypt == NULL) {
  ------------------
  |  Branch (92:6): [True: 0, False: 4]
  ------------------
   93|       |		/* crypt() with an invalid salt like "!!" */
   94|      0|		dropbear_log(LOG_WARNING, "User account '%s' is locked",
   95|      0|				ses.authstate.pw_name);
   96|      0|		send_msg_userauth_failure(0, 1);
   97|      0|		return;
   98|      0|	}
   99|       |
  100|       |	/* check for empty password */
  101|      4|	if (passwdcrypt[0] == '\0') {
  ------------------
  |  Branch (101:6): [True: 0, False: 4]
  ------------------
  102|      0|		dropbear_log(LOG_WARNING, "User '%s' has blank password, rejected",
  103|      0|				ses.authstate.pw_name);
  104|      0|		send_msg_userauth_failure(0, 1);
  105|      0|		return;
  106|      0|	}
  107|       |
  108|      4|	if (constant_time_strcmp(testcrypt, passwdcrypt) == 0) {
  ------------------
  |  Branch (108:6): [True: 0, False: 4]
  ------------------
  109|      0|		if (svr_opts.multiauthmethod && (ses.authstate.authtypes & ~AUTH_TYPE_PASSWORD)) {
  ------------------
  |  |  104|      0|#define AUTH_TYPE_PASSWORD  (1 << 2)
  ------------------
  |  Branch (109:7): [True: 0, False: 0]
  |  Branch (109:35): [True: 0, False: 0]
  ------------------
  110|       |			/* successful password authentication, but extra auth required */
  111|      0|			dropbear_log(LOG_NOTICE,
  112|      0|					"Password auth succeeded for '%s' from %s, extra auth required",
  113|      0|					ses.authstate.pw_name,
  114|      0|					svr_ses.addrstring);
  115|      0|			ses.authstate.authtypes &= ~AUTH_TYPE_PASSWORD; /* password auth ok, delete the method flag */
  ------------------
  |  |  104|      0|#define AUTH_TYPE_PASSWORD  (1 << 2)
  ------------------
  116|      0|			send_msg_userauth_failure(1, 0);  /* Send partial success */
  117|      0|		} else {
  118|       |			/* successful authentication */
  119|      0|			dropbear_log(LOG_NOTICE, 
  120|      0|					"Password auth succeeded for '%s' from %s",
  121|      0|					ses.authstate.pw_name,
  122|      0|					svr_ses.addrstring);
  123|      0|			send_msg_userauth_success();
  124|      0|		}
  125|      4|	} else {
  126|       |		dropbear_log(LOG_WARNING,
  127|      4|				"Bad password attempt for '%s' from %s",
  128|      4|				ses.authstate.pw_name,
  129|      4|				svr_ses.addrstring);
  130|      4|		send_msg_userauth_failure(0, 1);
  131|      4|	}
  132|      4|}

svr_auth_pubkey:
   85|    267|void svr_auth_pubkey(int valid_user) {
   86|       |
   87|    267|	unsigned char testkey; /* whether we're just checking if a key is usable */
   88|    267|	char* sigalgo = NULL;
   89|    267|	unsigned int sigalgolen;
   90|    267|	const char* keyalgo;
   91|    267|	unsigned int keyalgolen;
   92|    267|	unsigned char* keyblob = NULL;
   93|    267|	unsigned int keybloblen;
   94|    267|	unsigned int sign_payload_length;
   95|    267|	buffer * signbuf = NULL;
   96|    267|	sign_key * key = NULL;
   97|    267|	char* fp = NULL;
   98|    267|	enum signature_type sigtype;
   99|    267|	enum signkey_type keytype;
  100|    267|	int auth_failure = 1;
  101|    267|	struct PubKeyOptions *pubkey_options = NULL;
  102|       |
  103|    267|	TRACE(("enter pubkeyauth"))
  104|       |
  105|       |	/* 0 indicates user just wants to check if key can be used, 1 is an
  106|       |	 * actual attempt*/
  107|    267|	testkey = (buf_getbool(ses.payload) == 0);
  108|       |
  109|    267|	sigalgo = buf_getstring(ses.payload, &sigalgolen);
  110|    267|	keybloblen = buf_getint(ses.payload);
  111|    267|	keyblob = buf_getptr(ses.payload, keybloblen);
  112|       |
  113|    267|	if (!valid_user) {
  ------------------
  |  Branch (113:6): [True: 189, False: 78]
  ------------------
  114|       |		/* Return failure once we have read the contents of the packet
  115|       |		required to validate a public key.
  116|       |		Avoids blind user enumeration though it isn't possible to prevent
  117|       |		testing for user existence if the public key is known */
  118|    189|		send_msg_userauth_failure(0, 0);
  119|    189|		goto out;
  120|    189|	}
  121|       |
  122|     78|	sigtype = signature_type_from_name(sigalgo, sigalgolen);
  123|     78|	if (sigtype == DROPBEAR_SIGNATURE_NONE) {
  ------------------
  |  Branch (123:6): [True: 3, False: 75]
  ------------------
  124|      3|		send_msg_userauth_failure(0, 0);
  125|      3|		goto out;
  126|      3|	}
  127|       |
  128|     75|	keytype = signkey_type_from_signature(sigtype);
  129|     75|	keyalgo = signkey_name_from_type(keytype, &keyalgolen);
  130|       |
  131|       |#if DROPBEAR_PLUGIN
  132|       |    if (svr_ses.plugin_instance != NULL) {
  133|       |        char *options_buf;
  134|       |        if (svr_ses.plugin_instance->checkpubkey(
  135|       |                    svr_ses.plugin_instance,
  136|       |                    &ses.plugin_session,
  137|       |                    keyalgo,
  138|       |                    keyalgolen,
  139|       |                    keyblob,
  140|       |                    keybloblen,
  141|       |                    ses.authstate.username) == DROPBEAR_SUCCESS) {
  142|       |            /* Success */
  143|       |            auth_failure = 0;
  144|       |
  145|       |            /* Options provided? */
  146|       |            options_buf = ses.plugin_session->get_options(ses.plugin_session);
  147|       |            if (options_buf) {
  148|       |                struct buf temp_buf = {
  149|       |                    .data = (unsigned char *)options_buf,
  150|       |                    .len = strlen(options_buf),
  151|       |                    .pos = 0,
  152|       |                    .size = 0
  153|       |                };
  154|       |                pubkey_options = svr_parse_pubkey_options(&temp_buf, 0, "plugin");
  155|       |                if (pubkey_options == NULL) {
  156|       |                    /* Fail immediately as the plugin provided wrong options */
  157|       |                    send_msg_userauth_failure(0, 0);
  158|       |                    goto out;
  159|       |                }
  160|       |            }
  161|       |        }
  162|       |    }
  163|       |#endif
  164|       |	/* check if the key is valid */
  165|     75|	if (auth_failure) {
  ------------------
  |  Branch (165:6): [True: 0, False: 75]
  ------------------
  166|      0|		int status = checkpubkey(keyalgo, keyalgolen, keyblob, keybloblen, &pubkey_options);
  167|      0|		auth_failure = (status != DROPBEAR_SUCCESS);
  ------------------
  |  |  111|      0|#define DROPBEAR_SUCCESS 0
  ------------------
  168|      0|	}
  169|       |
  170|     75|	if (auth_failure) {
  ------------------
  |  Branch (170:6): [True: 0, False: 75]
  ------------------
  171|       |		/* MAX_PUBKEY_QUERIES allows a greater limit of pubkey queries
  172|       |		 * than the standard maxauthtries.
  173|       |		 * Start counting failures (incrfail) only when it's reaching
  174|       |		 * the limit.
  175|       |		 */
  176|      0|		unsigned int free_query_limit =
  177|      0|			MAX(0, MAX_PUBKEY_QUERIES - (int)svr_opts.maxauthtries);
  ------------------
  |  Branch (177:4): [True: 0, False: 0]
  ------------------
  178|      0|		int incrfail = ses.authstate.serv_pubkey_query_count >= free_query_limit;
  179|      0|		send_msg_userauth_failure(0, incrfail);
  180|      0|		ses.authstate.serv_pubkey_query_count++;
  181|      0|		goto out;
  182|      0|	}
  183|       |
  184|       |	/* let them know that the key is ok to use */
  185|     75|	if (testkey) {
  ------------------
  |  Branch (185:6): [True: 0, False: 75]
  ------------------
  186|      0|		send_msg_userauth_pk_ok(sigalgo, sigalgolen, keyblob, keybloblen);
  187|      0|		goto out;
  188|      0|	}
  189|       |
  190|       |	/* now we can actually verify the signature */
  191|       |
  192|       |	/* get the key */
  193|     75|	key = new_sign_key();
  194|     75|	if (buf_get_pub_key(ses.payload, key, &keytype) == DROPBEAR_FAILURE) {
  ------------------
  |  |  112|     75|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (194:6): [True: 0, False: 75]
  ------------------
  195|      0|		send_msg_userauth_failure(0, 1);
  196|      0|		goto out;
  197|      0|	}
  198|       |
  199|     75|#if DROPBEAR_SK_ECDSA || DROPBEAR_SK_ED25519
  200|     75|	key->sk_flags_mask = SSH_SK_USER_PRESENCE_REQD;
  ------------------
  |  |  135|     75|#define SSH_SK_USER_PRESENCE_REQD       0x01
  ------------------
  201|     75|#if DROPBEAR_SVR_PUBKEY_OPTIONS_BUILT
  202|     75|	if (pubkey_options->no_touch_required_flag) {
  ------------------
  |  Branch (202:6): [True: 0, False: 75]
  ------------------
  203|      0|		key->sk_flags_mask &= ~SSH_SK_USER_PRESENCE_REQD;
  ------------------
  |  |  135|      0|#define SSH_SK_USER_PRESENCE_REQD       0x01
  ------------------
  204|      0|	}
  205|     75|	if (pubkey_options->verify_required_flag) {
  ------------------
  |  Branch (205:6): [True: 0, False: 75]
  ------------------
  206|      0|		key->sk_flags_mask |= SSH_SK_USER_VERIFICATION_REQD;
  ------------------
  |  |  136|      0|#define SSH_SK_USER_VERIFICATION_REQD   0x04
  ------------------
  207|      0|	}
  208|     75|#endif /* DROPBEAR_SVR_PUBKEY_OPTIONS_BUILT */
  209|     75|#endif
  210|       |
  211|       |	/* create the data which has been signed - this a string containing
  212|       |	 * session_id, concatenated with the payload packet up to the signature */
  213|     75|	assert(ses.payload_beginning <= ses.payload->pos);
  ------------------
  |  Branch (213:2): [True: 0, False: 75]
  |  Branch (213:2): [True: 0, False: 75]
  ------------------
  214|     75|	sign_payload_length = ses.payload->pos - ses.payload_beginning;
  215|      0|	signbuf = buf_new(ses.payload->pos + 4 + ses.session_id->len);
  216|      0|	buf_putbufstring(signbuf, ses.session_id);
  217|       |
  218|       |	/* The entire contents of the payload prior. */
  219|      0|	buf_setpos(ses.payload, ses.payload_beginning);
  220|      0|	buf_putbytes(signbuf,
  221|      0|		buf_getptr(ses.payload, sign_payload_length),
  222|      0|		sign_payload_length);
  223|      0|	buf_incrpos(ses.payload, sign_payload_length);
  224|       |
  225|      0|	buf_setpos(signbuf, 0);
  226|       |
  227|       |	/* ... and finally verify the signature */
  228|      0|	fp = sign_key_fingerprint(keyblob, keybloblen);
  229|      0|	if (buf_verify(ses.payload, key, sigtype, signbuf) == DROPBEAR_SUCCESS) {
  ------------------
  |  |  111|      0|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (229:6): [True: 0, False: 0]
  ------------------
  230|      0|		if (ses.authstate.pubkey_options == NULL) {
  ------------------
  |  Branch (230:7): [True: 0, False: 0]
  ------------------
  231|      0|			ses.authstate.pubkey_options = pubkey_options;
  232|      0|			pubkey_options = NULL;
  233|      0|		}
  234|      0|		if (svr_opts.multiauthmethod && (ses.authstate.authtypes & ~AUTH_TYPE_PUBKEY)) {
  ------------------
  |  |  103|      0|#define AUTH_TYPE_PUBKEY    (1 << 1)
  ------------------
  |  Branch (234:7): [True: 0, False: 0]
  |  Branch (234:35): [True: 0, False: 0]
  ------------------
  235|       |			/* successful pubkey authentication, but extra auth required */
  236|      0|			dropbear_log(LOG_NOTICE,
  237|      0|					"Pubkey auth succeeded for '%s' with %s key %s from %s, extra auth required",
  238|      0|					ses.authstate.pw_name,
  239|      0|					signkey_name_from_type(keytype, NULL), fp,
  240|      0|					svr_ses.addrstring);
  241|      0|			ses.authstate.authtypes &= ~AUTH_TYPE_PUBKEY; /* pubkey auth ok, delete the method flag */
  ------------------
  |  |  103|      0|#define AUTH_TYPE_PUBKEY    (1 << 1)
  ------------------
  242|      0|			send_msg_userauth_failure(1, 0); /* Send partial success */
  243|      0|		} else {
  244|       |			/* successful authentication */
  245|      0|			dropbear_log(LOG_NOTICE,
  246|      0|					"Pubkey auth succeeded for '%s' with %s key %s from %s",
  247|      0|					ses.authstate.pw_name,
  248|      0|					signkey_name_from_type(keytype, NULL), fp,
  249|      0|					svr_ses.addrstring);
  250|      0|			send_msg_userauth_success();
  251|      0|		}
  252|       |#if DROPBEAR_PLUGIN
  253|       |		if ((ses.plugin_session != NULL) && (svr_ses.plugin_instance->auth_success != NULL)) {
  254|       |		    /* Was authenticated through the external plugin. tell plugin that signature verification was ok */
  255|       |		    svr_ses.plugin_instance->auth_success(ses.plugin_session);
  256|       |		}
  257|       |#endif
  258|      0|	} else {
  259|      0|		dropbear_log(LOG_WARNING,
  260|      0|				"Pubkey auth bad signature for '%s' with key %s from %s",
  261|      0|				ses.authstate.pw_name, fp, svr_ses.addrstring);
  262|      0|		send_msg_userauth_failure(0, 1);
  263|      0|	}
  264|      0|	m_free(fp);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 0]
  |  |  ------------------
  ------------------
  265|       |
  266|    192|out:
  267|       |	/* cleanup stuff */
  268|    192|	if (signbuf) {
  ------------------
  |  Branch (268:6): [True: 0, False: 192]
  ------------------
  269|      0|		buf_free(signbuf);
  270|      0|	}
  271|    192|	if (sigalgo) {
  ------------------
  |  Branch (271:6): [True: 192, False: 0]
  ------------------
  272|    192|		m_free(sigalgo);
  ------------------
  |  |   24|    192|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 192]
  |  |  ------------------
  ------------------
  273|    192|	}
  274|    192|	if (key) {
  ------------------
  |  Branch (274:6): [True: 0, False: 192]
  ------------------
  275|      0|		sign_key_free(key);
  276|      0|		key = NULL;
  277|      0|	}
  278|    192|	if (pubkey_options) {
  ------------------
  |  Branch (278:6): [True: 0, False: 192]
  ------------------
  279|      0|		svr_pubkey_options_cleanup(pubkey_options);
  280|       |		pubkey_options = NULL;
  281|      0|	}
  282|    192|	TRACE(("leave pubkeyauth"))
  283|    192|}

svr_pubkey_options_cleanup:
  165|  2.84k|void svr_pubkey_options_cleanup(struct PubKeyOptions *pubkey_options) {
  166|  2.84k|	if (pubkey_options) {
  ------------------
  |  Branch (166:6): [True: 0, False: 2.84k]
  ------------------
  167|      0|		m_free(pubkey_options->forced_command);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 0]
  |  |  ------------------
  ------------------
  168|      0|		if (pubkey_options->permit_open_destinations) {
  ------------------
  |  Branch (168:7): [True: 0, False: 0]
  ------------------
  169|      0|			m_list_elem *iter = pubkey_options->permit_open_destinations->first;
  170|      0|			while (iter) {
  ------------------
  |  Branch (170:11): [True: 0, False: 0]
  ------------------
  171|      0|				struct PermitTCPFwdEntry *entry = (struct PermitTCPFwdEntry*)list_remove(iter);
  172|      0|				m_free(entry->host);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 0]
  |  |  ------------------
  ------------------
  173|      0|				m_free(entry);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 0]
  |  |  ------------------
  ------------------
  174|      0|				iter = pubkey_options->permit_open_destinations->first;
  175|      0|			}
  176|      0|			m_free(pubkey_options->permit_open_destinations);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 0]
  |  |  ------------------
  ------------------
  177|      0|		}
  178|      0|		if (pubkey_options->permit_listens) {
  ------------------
  |  Branch (178:7): [True: 0, False: 0]
  ------------------
  179|      0|			m_list_elem *iter = pubkey_options->permit_listens->first;
  180|      0|			while (iter) {
  ------------------
  |  Branch (180:11): [True: 0, False: 0]
  ------------------
  181|      0|				struct PermitTCPFwdEntry *entry = (struct PermitTCPFwdEntry*)list_remove(iter);
  182|      0|				m_free(entry->host);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 0]
  |  |  ------------------
  ------------------
  183|      0|				m_free(entry);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 0]
  |  |  ------------------
  ------------------
  184|      0|				iter = pubkey_options->permit_listens->first;
  185|      0|			}
  186|      0|			m_free(pubkey_options->permit_listens);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 0]
  |  |  ------------------
  ------------------
  187|      0|		}
  188|      0|		m_free(pubkey_options->info_env);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 0]
  |  |  ------------------
  ------------------
  189|       |		m_free(pubkey_options);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 0]
  |  |  ------------------
  ------------------
  190|      0|	}
  191|  2.84k|}

svr_chansess_checksignal:
   95|   209k|void svr_chansess_checksignal(void) {
   96|   209k|	int status;
   97|   209k|	pid_t pid;
   98|       |
   99|   209k|	if (!ses.channel_signal_pending) {
  ------------------
  |  Branch (99:6): [True: 209k, False: 0]
  ------------------
  100|   209k|		return;
  101|   209k|	}
  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)) {
  ------------------
  |  Branch (126:7): [True: 0, False: 0]
  ------------------
  127|      0|			ex->exitstatus = WEXITSTATUS(status);
  128|      0|		}
  129|      0|		if (WIFSIGNALED(status)) {
  ------------------
  |  Branch (129:7): [True: 0, False: 0]
  ------------------
  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:
 1073|  2.84k|void svr_chansessinitialise() {
 1074|       |
 1075|  2.84k|	struct sigaction sa_chld;
 1076|       |
 1077|       |	/* single child process intially */
 1078|  2.84k|	svr_ses.childpids = (struct ChildPid*)m_malloc(sizeof(struct ChildPid));
 1079|  2.84k|	svr_ses.childpids[0].pid = -1; /* unused */
 1080|  2.84k|	svr_ses.childpids[0].chansess = NULL;
 1081|  2.84k|	svr_ses.childpidsize = 1;
 1082|  2.84k|	svr_ses.lastexit.exitpid = -1; /* Nothing has exited yet */
 1083|  2.84k|	sa_chld.sa_handler = sesssigchild_handler;
 1084|  2.84k|	sa_chld.sa_flags = SA_NOCLDSTOP;
 1085|  2.84k|	sigemptyset(&sa_chld.sa_mask);
 1086|  2.84k|	if (sigaction(SIGCHLD, &sa_chld, NULL) < 0) {
  ------------------
  |  Branch (1086:6): [True: 0, False: 2.84k]
  ------------------
 1087|      0|		dropbear_exit("signal() error");
 1088|      0|	}
 1089|       |	
 1090|  2.84k|}

recv_msg_kexdh_init:
   49|  6.41k|void recv_msg_kexdh_init() {
   50|  6.41k|	DEF_MP_INT(dh_e);
  ------------------
  |  |   81|  6.41k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
   51|  6.41k|	buffer *q_c = NULL;
   52|       |
   53|  6.41k|	TRACE(("enter recv_msg_kexdh_init"))
   54|  6.41k|	if (!ses.kexstate.recvkexinit) {
  ------------------
  |  Branch (54:6): [True: 6, False: 6.40k]
  ------------------
   55|      6|		dropbear_exit("Premature kexdh_init message received");
   56|      6|	}
   57|       |
   58|  6.40k|	switch (ses.newkeys->algo_kex->mode) {
  ------------------
  |  Branch (58:10): [True: 6.40k, False: 0]
  ------------------
   59|      0|#if DROPBEAR_NORMAL_DH
   60|  1.75k|		case DROPBEAR_KEX_NORMAL_DH:
  ------------------
  |  Branch (60:3): [True: 1.75k, False: 4.64k]
  ------------------
   61|  1.75k|			m_mp_init(&dh_e);
   62|  1.75k|			if (buf_getmpint(ses.payload, &dh_e) != DROPBEAR_SUCCESS) {
  ------------------
  |  |  111|  1.75k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (62:8): [True: 60, False: 1.69k]
  ------------------
   63|     60|				dropbear_exit("Bad kex value");
   64|     60|			}
   65|  1.69k|			break;
   66|  1.69k|#endif
   67|  1.69k|#if DROPBEAR_ECDH
   68|  1.69k|		case DROPBEAR_KEX_ECDH:
  ------------------
  |  Branch (68:3): [True: 1.20k, False: 5.20k]
  ------------------
   69|  1.20k|#endif
   70|  1.20k|#if DROPBEAR_CURVE25519
   71|  4.54k|		case DROPBEAR_KEX_CURVE25519:
  ------------------
  |  Branch (71:3): [True: 3.34k, False: 3.05k]
  ------------------
   72|  4.54k|#endif
   73|  4.54k|#if DROPBEAR_PQHYBRID
   74|  4.64k|		case DROPBEAR_KEX_PQHYBRID:
  ------------------
  |  Branch (74:3): [True: 101, False: 6.30k]
  ------------------
   75|  4.64k|#endif
   76|  4.64k|#if DROPBEAR_ECDH || DROPBEAR_CURVE25519 || DROPBEAR_PQHYBRID
   77|  4.64k|			q_c = buf_getstringbuf(ses.payload);
   78|  4.64k|			break;
   79|  6.40k|#endif
   80|  6.40k|	}
   81|  6.24k|	if (ses.payload->pos != ses.payload->len) {
  ------------------
  |  Branch (81:6): [True: 78, False: 6.16k]
  ------------------
   82|     78|		dropbear_exit("Bad kex value");
   83|     78|	}
   84|       |
   85|  6.16k|	send_msg_kexdh_reply(&dh_e, q_c);
   86|       |
   87|  6.16k|	mp_clear(&dh_e);
   88|  6.16k|	if (q_c) {
  ------------------
  |  Branch (88:6): [True: 4.54k, False: 1.62k]
  ------------------
   89|  4.54k|		buf_free(q_c);
   90|  4.54k|		q_c = NULL;
   91|  4.54k|	}
   92|       |
   93|  6.16k|	send_msg_newkeys();
   94|       |
   95|  6.16k|#if DROPBEAR_EXT_INFO
   96|       |	/* Only send it following the first newkeys */
   97|  6.16k|	if (!ses.kexstate.donesecondkex && ses.allow_ext_info) {
  ------------------
  |  Branch (97:6): [True: 1.53k, False: 4.63k]
  |  Branch (97:37): [True: 92, False: 1.44k]
  ------------------
   98|     92|		send_msg_ext_info();
   99|     92|	}
  100|  6.16k|#endif
  101|       |
  102|  6.16k|	if (!ses.kexstate.donesecondkex) {
  ------------------
  |  Branch (102:6): [True: 1.53k, False: 4.63k]
  ------------------
  103|       |		/* Disable other signature types.
  104|       |		 * During future rekeying, privileges may have been dropped
  105|       |		 * so other keys won't be loadable.
  106|       |		 * This must occur after send_msg_ext_info() which uses the hostkey list */
  107|  1.53k|		disable_sig_except(ses.newkeys->algo_signature);
  108|  1.53k|	}
  109|       |
  110|  6.16k|	ses.requirenext = SSH_MSG_NEWKEYS;
  ------------------
  |  |   37|  6.16k|#define SSH_MSG_NEWKEYS                21
  ------------------
  111|  6.16k|	TRACE(("leave recv_msg_kexdh_init"))
  112|  6.16k|}
svr-kex.c:send_msg_kexdh_reply:
  200|  6.16k|static void send_msg_kexdh_reply(mp_int *dh_e, buffer *q_c) {
  201|  6.16k|	TRACE(("enter send_msg_kexdh_reply"))
  202|       |
  203|       |	/* we can start creating the kexdh_reply packet */
  204|  6.16k|	CHECKCLEARTOWRITE();
  205|       |
  206|  6.16k|#if DROPBEAR_DELAY_HOSTKEY
  207|  6.16k|	if (svr_opts.delay_hostkey)
  ------------------
  |  Branch (207:6): [True: 0, False: 6.16k]
  ------------------
  208|      0|	{
  209|      0|		svr_ensure_hostkey();
  210|      0|	}
  211|  6.16k|#endif
  212|       |
  213|  6.16k|#if DROPBEAR_FUZZ
  214|  6.16k|	if (fuzz.fuzzing && fuzz.skip_kexmaths) {
  ------------------
  |  Branch (214:6): [True: 6.16k, False: 0]
  |  Branch (214:22): [True: 6.16k, False: 0]
  ------------------
  215|  6.16k|		fuzz_fake_send_kexdh_reply();
  216|  6.16k|		return;
  217|  6.16k|	}
  218|      0|#endif
  219|       |
  220|      0|	buf_putbyte(ses.writepayload, SSH_MSG_KEXDH_REPLY);
  ------------------
  |  |   39|      0|#define SSH_MSG_KEXDH_REPLY            31
  ------------------
  221|      0|	buf_put_pub_key(ses.writepayload, svr_opts.hostkey,
  222|      0|			ses.newkeys->algo_hostkey);
  223|       |
  224|      0|	switch (ses.newkeys->algo_kex->mode) {
  ------------------
  |  Branch (224:10): [True: 0, False: 0]
  ------------------
  225|      0|#if DROPBEAR_NORMAL_DH
  226|      0|		case DROPBEAR_KEX_NORMAL_DH:
  ------------------
  |  Branch (226:3): [True: 0, False: 0]
  ------------------
  227|      0|			{
  228|      0|			struct kex_dh_param * dh_param = gen_kexdh_param();
  229|      0|			kexdh_comb_key(dh_param, dh_e, svr_opts.hostkey);
  230|       |
  231|       |			/* put f */
  232|      0|			buf_putmpint(ses.writepayload, &dh_param->pub);
  233|      0|			free_kexdh_param(dh_param);
  234|      0|			}
  235|      0|			break;
  236|      0|#endif
  237|      0|#if DROPBEAR_ECDH
  238|      0|		case DROPBEAR_KEX_ECDH:
  ------------------
  |  Branch (238:3): [True: 0, False: 0]
  ------------------
  239|      0|			{
  240|      0|			struct kex_ecdh_param *ecdh_param = gen_kexecdh_param();
  241|      0|			kexecdh_comb_key(ecdh_param, q_c, svr_opts.hostkey);
  242|       |
  243|      0|			buf_put_ecc_raw_pubkey_string(ses.writepayload, &ecdh_param->key);
  244|      0|			free_kexecdh_param(ecdh_param);
  245|      0|			}
  246|      0|			break;
  247|      0|#endif
  248|      0|#if DROPBEAR_CURVE25519
  249|      0|		case DROPBEAR_KEX_CURVE25519:
  ------------------
  |  Branch (249:3): [True: 0, False: 0]
  ------------------
  250|      0|			{
  251|      0|			struct kex_curve25519_param *param = gen_kexcurve25519_param();
  252|      0|			kexcurve25519_comb_key(param, q_c, svr_opts.hostkey);
  253|       |
  254|      0|			buf_putstring(ses.writepayload, param->pub, CURVE25519_LEN);
  ------------------
  |  |  122|      0|#define CURVE25519_LEN 32
  ------------------
  255|      0|			free_kexcurve25519_param(param);
  256|      0|			}
  257|      0|			break;
  258|      0|#endif
  259|      0|#if DROPBEAR_PQHYBRID
  260|      0|		case DROPBEAR_KEX_PQHYBRID:
  ------------------
  |  Branch (260:3): [True: 0, False: 0]
  ------------------
  261|      0|			{
  262|      0|			struct kex_pqhybrid_param *param = gen_kexpqhybrid_param();
  263|      0|			kexpqhybrid_comb_key(param, q_c, svr_opts.hostkey);
  264|       |
  265|      0|			buf_putbufstring(ses.writepayload, param->concat_public);
  266|      0|			free_kexpqhybrid_param(param);
  267|      0|			}
  268|      0|			break;
  269|      0|#endif
  270|      0|	}
  271|       |
  272|       |	/* calc the signature */
  273|      0|	buf_put_sign(ses.writepayload, svr_opts.hostkey, 
  274|      0|			ses.newkeys->algo_signature, ses.hash);
  275|       |
  276|       |	/* the SSH_MSG_KEXDH_REPLY is done */
  277|      0|	encrypt_packet();
  278|       |
  279|      0|	TRACE(("leave send_msg_kexdh_reply"))
  280|      0|}
svr-kex.c:send_msg_ext_info:
  284|     92|static void send_msg_ext_info(void) {
  285|     92|	TRACE(("enter send_msg_ext_info"))
  286|       |
  287|     92|	buf_putbyte(ses.writepayload, SSH_MSG_EXT_INFO);
  ------------------
  |  |   35|     92|#define SSH_MSG_EXT_INFO               7
  ------------------
  288|       |	/* nr-extensions */
  289|     92|	buf_putint(ses.writepayload, 1);
  290|       |
  291|     92|	buf_putstring(ses.writepayload, SSH_SERVER_SIG_ALGS, strlen(SSH_SERVER_SIG_ALGS));
  ------------------
  |  |  101|     92|#define SSH_SERVER_SIG_ALGS "server-sig-algs"
  ------------------
              	buf_putstring(ses.writepayload, SSH_SERVER_SIG_ALGS, strlen(SSH_SERVER_SIG_ALGS));
  ------------------
  |  |  101|     92|#define SSH_SERVER_SIG_ALGS "server-sig-algs"
  ------------------
  292|     92|	buf_put_algolist_all(ses.writepayload, sigalgs, 1);
  293|       |	
  294|     92|	encrypt_packet();
  295|       |
  296|     92|	TRACE(("leave send_msg_ext_info"))
  297|     92|}

svr_getopts:
  147|      1|void svr_getopts(int argc, char ** argv) {
  148|       |
  149|      1|	unsigned int i, j;
  150|      1|	char ** next = NULL;
  151|      1|	int nextisport = 0;
  152|      1|	char* recv_window_arg = NULL;
  153|      1|	char* keepalive_arg = NULL;
  154|      1|	char* idle_timeout_arg = NULL;
  155|      1|	char* max_duration_arg = NULL;
  156|      1|	char* maxauthtries_arg = NULL;
  157|      1|	char* reexec_fd_arg = NULL;
  158|      1|	char* keyfile = NULL;
  159|      1|	char *algo_print_arg = NULL;
  160|      1|	char c;
  161|       |#if DROPBEAR_PLUGIN
  162|       |        char* pubkey_plugin = NULL;
  163|       |#endif
  164|       |
  165|       |
  166|       |	/* see printhelp() for options */
  167|      1|	svr_opts.bannerfile = NULL;
  168|      1|	svr_opts.banner = NULL;
  169|      1|	svr_opts.forced_command = NULL;
  170|      1|	svr_opts.forkbg = 1;
  171|      1|	svr_opts.norootlogin = 0;
  172|      1|#ifdef HAVE_GETGROUPLIST
  173|      1|	svr_opts.restrict_group = NULL;
  174|      1|	svr_opts.restrict_group_gid = 0;
  175|      1|#endif
  176|      1|	svr_opts.noauthpass = 0;
  177|      1|	svr_opts.norootpass = 0;
  178|      1|	svr_opts.allowblankpass = 0;
  179|      1|	svr_opts.multiauthmethod = 0;
  180|      1|	svr_opts.maxauthtries = MAX_AUTH_TRIES;
  ------------------
  |  |  463|      1|#define MAX_AUTH_TRIES 10
  ------------------
  181|      1|	svr_opts.inetdmode = 0;
  182|      1|	svr_opts.portcount = 0;
  183|      1|	svr_opts.hostkey = NULL;
  184|      1|	svr_opts.delay_hostkey = 0;
  185|      1|	svr_opts.pidfile = expand_homedir_path(DROPBEAR_PIDFILE);
  ------------------
  |  |  507|      1|#define DROPBEAR_PIDFILE "/var/run/dropbear.pid"
  ------------------
  186|      1|	svr_opts.authorized_keys_dir = "~/.ssh";
  187|      1|#if DROPBEAR_SVR_LOCALANYFWD
  188|      1|	svr_opts.nolocaltcp = 0;
  189|      1|#endif
  190|      1|#if DROPBEAR_SVR_REMOTEANYFWD
  191|      1|	svr_opts.noremotefwd = 0;
  192|      1|#endif
  193|       |#if DROPBEAR_PLUGIN
  194|       |        svr_opts.pubkey_plugin = NULL;
  195|       |        svr_opts.pubkey_plugin_options = NULL;
  196|       |#endif
  197|      1|	svr_opts.pass_on_env = 0;
  198|      1|	svr_opts.reexec_childpipe = -1;
  199|       |
  200|       |#ifndef DISABLE_ZLIB
  201|       |	opts.compression = 1;
  202|       |#endif 
  203|       |
  204|       |	/* not yet
  205|       |	opts.ipv4 = 1;
  206|       |	opts.ipv6 = 1;
  207|       |	*/
  208|      1|#if DO_MOTD
  209|      1|	svr_opts.domotd = 1;
  210|      1|#endif
  211|      1|#ifndef DISABLE_SYSLOG
  212|      1|	opts.usingsyslog = 1;
  213|      1|#endif
  214|      1|	opts.recv_window = DEFAULT_RECV_WINDOW;
  ------------------
  |  |  550|      1|#define DEFAULT_RECV_WINDOW 24576
  ------------------
  215|      1|	opts.keepalive_secs = DEFAULT_KEEPALIVE;
  ------------------
  |  |  566|      1|#define DEFAULT_KEEPALIVE 0
  ------------------
  216|      1|	opts.idle_timeout_secs = DEFAULT_IDLE_TIMEOUT;
  ------------------
  |  |  579|      1|#define DEFAULT_IDLE_TIMEOUT 0
  ------------------
  217|      1|	opts.max_duration_secs = DEFAULT_MAX_DURATION;
  ------------------
  |  |  585|      1|#define DEFAULT_MAX_DURATION 0
  ------------------
  218|       |
  219|      1|#if DROPBEAR_SVR_REMOTETCPFWD
  220|      1|	opts.listen_fwd_all = 0;
  221|      1|#endif
  222|      1|	opts.disable_ip_tos = 0;
  223|       |
  224|      2|	for (i = 1; i < (unsigned int)argc; i++) {
  ------------------
  |  Branch (224:14): [True: 1, False: 1]
  ------------------
  225|      1|		if (argv[i][0] != '-' || argv[i][1] == '\0')
  ------------------
  |  Branch (225:7): [True: 0, False: 1]
  |  Branch (225:28): [True: 0, False: 1]
  ------------------
  226|      0|			dropbear_exit("Invalid argument: %s", argv[i]);
  227|       |
  228|      2|		for (j = 1; (c = argv[i][j]) != '\0' && !next && !nextisport; j++) {
  ------------------
  |  Branch (228:15): [True: 1, False: 1]
  |  Branch (228:43): [True: 1, False: 0]
  |  Branch (228:52): [True: 1, False: 0]
  ------------------
  229|      1|			switch (c) {
  230|      0|				case 'b':
  ------------------
  |  Branch (230:5): [True: 0, False: 1]
  ------------------
  231|      0|					next = &svr_opts.bannerfile;
  232|      0|					break;
  233|      0|				case 'c':
  ------------------
  |  Branch (233:5): [True: 0, False: 1]
  ------------------
  234|      0|					next = &svr_opts.forced_command;
  235|      0|					break;
  236|      0|				case 'd':
  ------------------
  |  Branch (236:5): [True: 0, False: 1]
  ------------------
  237|      0|				case 'r':
  ------------------
  |  Branch (237:5): [True: 0, False: 1]
  ------------------
  238|      0|					next = &keyfile;
  239|      0|					break;
  240|      0|#if DROPBEAR_SVR_PUBKEY_AUTH
  241|      0|				case 'D':
  ------------------
  |  Branch (241:5): [True: 0, False: 1]
  ------------------
  242|      0|					next = &svr_opts.authorized_keys_dir;
  243|      0|					break;
  244|      0|#endif
  245|      0|				case 'R':
  ------------------
  |  Branch (245:5): [True: 0, False: 1]
  ------------------
  246|      0|					svr_opts.delay_hostkey = 1;
  247|      0|					break;
  248|      0|				case 'F':
  ------------------
  |  Branch (248:5): [True: 0, False: 1]
  ------------------
  249|      0|					svr_opts.forkbg = 0;
  250|      0|					break;
  251|      0|#ifndef DISABLE_SYSLOG
  252|      1|				case 'E':
  ------------------
  |  Branch (252:5): [True: 1, False: 0]
  ------------------
  253|      1|					opts.usingsyslog = 0;
  254|      1|					break;
  255|      0|#endif
  256|      0|				case 'e':
  ------------------
  |  Branch (256:5): [True: 0, False: 1]
  ------------------
  257|      0|					svr_opts.pass_on_env = 1;
  258|      0|					break;
  259|       |
  260|      0|#if DROPBEAR_SVR_LOCALANYFWD
  261|      0|				case 'j':
  ------------------
  |  Branch (261:5): [True: 0, False: 1]
  ------------------
  262|      0|					svr_opts.nolocaltcp = 1;
  263|      0|					break;
  264|       |#else
  265|       |				case 'j':
  266|       |					/* Ignore the flag */
  267|       |					break;
  268|       |#endif
  269|      0|#if DROPBEAR_SVR_REMOTEANYFWD
  270|      0|				case 'k':
  ------------------
  |  Branch (270:5): [True: 0, False: 1]
  ------------------
  271|      0|					svr_opts.noremotefwd = 1;
  272|      0|					break;
  273|       |#else
  274|       |				case 'k':
  275|       |					/* Ignore the flag */
  276|       |					break;
  277|       |#endif
  278|      0|#if DROPBEAR_SVR_REMOTETCPFWD
  279|      0|				case 'a':
  ------------------
  |  Branch (279:5): [True: 0, False: 1]
  ------------------
  280|      0|					opts.listen_fwd_all = 1;
  281|      0|					break;
  282|      0|#endif
  283|      0|#if INETD_MODE
  284|      0|				case 'i':
  ------------------
  |  Branch (284:5): [True: 0, False: 1]
  ------------------
  285|      0|					svr_opts.inetdmode = 1;
  286|      0|					break;
  287|      0|#endif
  288|      0|#if DROPBEAR_DO_REEXEC && NON_INETD_MODE
  289|       |				/* For internal use by re-exec */
  290|      0|				case '2':
  ------------------
  |  Branch (290:5): [True: 0, False: 1]
  ------------------
  291|      0|					next = &reexec_fd_arg;
  292|      0|					break;
  293|      0|#endif
  294|      0|				case 'p':
  ------------------
  |  Branch (294:5): [True: 0, False: 1]
  ------------------
  295|      0|					nextisport = 1;
  296|      0|					break;
  297|      0|				case 'P':
  ------------------
  |  Branch (297:5): [True: 0, False: 1]
  ------------------
  298|      0|					next = &svr_opts.pidfile;
  299|      0|					break;
  300|      0|#ifdef SO_BINDTODEVICE
  301|      0|				case 'l':
  ------------------
  |  Branch (301:5): [True: 0, False: 1]
  ------------------
  302|      0|					next = &svr_opts.interface;
  303|      0|					break;
  304|      0|#endif
  305|      0|#if DO_MOTD
  306|       |				/* motd is displayed by default, -m turns it off */
  307|      0|				case 'm':
  ------------------
  |  Branch (307:5): [True: 0, False: 1]
  ------------------
  308|      0|					svr_opts.domotd = 0;
  309|      0|					break;
  310|       |#else
  311|       |				case 'm':
  312|       |					break;
  313|       |#endif
  314|      0|				case 'w':
  ------------------
  |  Branch (314:5): [True: 0, False: 1]
  ------------------
  315|      0|					svr_opts.norootlogin = 1;
  316|      0|					break;
  317|      0|#ifdef HAVE_GETGROUPLIST
  318|      0|				case 'G':
  ------------------
  |  Branch (318:5): [True: 0, False: 1]
  ------------------
  319|      0|					next = &svr_opts.restrict_group;
  320|      0|					break;
  321|      0|#endif
  322|      0|				case 'W':
  ------------------
  |  Branch (322:5): [True: 0, False: 1]
  ------------------
  323|      0|					next = &recv_window_arg;
  324|      0|					break;
  325|      0|				case 'K':
  ------------------
  |  Branch (325:5): [True: 0, False: 1]
  ------------------
  326|      0|					next = &keepalive_arg;
  327|      0|					break;
  328|      0|				case 'I':
  ------------------
  |  Branch (328:5): [True: 0, False: 1]
  ------------------
  329|      0|					next = &idle_timeout_arg;
  330|      0|					break;
  331|      0|				case 'M':
  ------------------
  |  Branch (331:5): [True: 0, False: 1]
  ------------------
  332|      0|					next = &max_duration_arg;
  333|      0|					break;
  334|      0|				case 'T':
  ------------------
  |  Branch (334:5): [True: 0, False: 1]
  ------------------
  335|      0|					next = &maxauthtries_arg;
  336|      0|					break;
  337|      0|#if DROPBEAR_SVR_PASSWORD_AUTH || DROPBEAR_SVR_PAM_AUTH
  338|      0|				case 's':
  ------------------
  |  Branch (338:5): [True: 0, False: 1]
  ------------------
  339|      0|					svr_opts.noauthpass = 1;
  340|      0|					break;
  341|      0|				case 'g':
  ------------------
  |  Branch (341:5): [True: 0, False: 1]
  ------------------
  342|      0|					svr_opts.norootpass = 1;
  343|      0|					break;
  344|      0|				case 'B':
  ------------------
  |  Branch (344:5): [True: 0, False: 1]
  ------------------
  345|      0|					svr_opts.allowblankpass = 1;
  346|      0|					break;
  347|      0|				case 't':
  ------------------
  |  Branch (347:5): [True: 0, False: 1]
  ------------------
  348|      0|					svr_opts.multiauthmethod = 1;
  349|      0|					break;
  350|       |#else
  351|       |				case 's':
  352|       |				case 'g':
  353|       |					break;
  354|       |#endif
  355|      0|				case 'Q':
  ------------------
  |  Branch (355:5): [True: 0, False: 1]
  ------------------
  356|      0|					next = &algo_print_arg;
  357|      0|					break;
  358|      0|				case 'h':
  ------------------
  |  Branch (358:5): [True: 0, False: 1]
  ------------------
  359|      0|					printhelp(argv[0]);
  360|      0|					exit(EXIT_SUCCESS);
  361|      0|					break;
  362|      0|				case 'u':
  ------------------
  |  Branch (362:5): [True: 0, False: 1]
  ------------------
  363|       |					/* backwards compatibility with old urandom option */
  364|      0|					break;
  365|       |#if DROPBEAR_PLUGIN
  366|       |                                case 'A':
  367|       |                                        next = &pubkey_plugin;
  368|       |                                        break;
  369|       |#endif
  370|       |#if DEBUG_TRACE
  371|       |				case 'v':
  372|       |					debug_trace++;
  373|       |					break;
  374|       |#endif
  375|      0|				case 'V':
  ------------------
  |  Branch (375:5): [True: 0, False: 1]
  ------------------
  376|      0|					print_version();
  377|      0|					exit(EXIT_SUCCESS);
  378|      0|					break;
  379|      0|				case 'z':
  ------------------
  |  Branch (379:5): [True: 0, False: 1]
  ------------------
  380|      0|					opts.disable_ip_tos = 1;
  381|      0|					break;
  382|      0|				default:
  ------------------
  |  Branch (382:5): [True: 0, False: 1]
  ------------------
  383|      0|					fprintf(stderr, "Invalid option -%c\n", c);
  ------------------
  |  |  100|      0|#define stderr (fuzz.fake_stderr)
  ------------------
  384|      0|					printhelp(argv[0]);
  385|      0|					exit(EXIT_FAILURE);
  386|      0|					break;
  387|      1|			}
  388|      1|		}
  389|       |
  390|      1|		if (!next && !nextisport)
  ------------------
  |  Branch (390:7): [True: 1, False: 0]
  |  Branch (390:16): [True: 1, False: 0]
  ------------------
  391|      1|			continue;
  392|       |
  393|      0|		if (c == '\0') {
  ------------------
  |  Branch (393:7): [True: 0, False: 0]
  ------------------
  394|      0|			i++;
  395|      0|			j = 0;
  396|      0|			if (!argv[i]) {
  ------------------
  |  Branch (396:8): [True: 0, False: 0]
  ------------------
  397|      0|				dropbear_exit("Missing argument");
  398|      0|			}
  399|      0|		}
  400|       |
  401|      0|		if (nextisport) {
  ------------------
  |  Branch (401:7): [True: 0, False: 0]
  ------------------
  402|      0|			addportandaddress(&argv[i][j]);
  403|      0|			nextisport = 0;
  404|      0|		} else if (next) {
  ------------------
  |  Branch (404:14): [True: 0, False: 0]
  ------------------
  405|      0|			*next = &argv[i][j];
  406|      0|			if (*next == NULL) {
  ------------------
  |  Branch (406:8): [True: 0, False: 0]
  ------------------
  407|      0|				dropbear_exit("Invalid null argument");
  408|      0|			}
  409|      0|			next = NULL;
  410|       |
  411|      0|			if (keyfile) {
  ------------------
  |  Branch (411:8): [True: 0, False: 0]
  ------------------
  412|      0|				addhostkey(keyfile);
  413|      0|				keyfile = NULL;
  414|      0|			}
  415|      0|		}
  416|      0|	}
  417|       |
  418|       |	/* Set up listening ports */
  419|      1|	if (svr_opts.portcount == 0) {
  ------------------
  |  Branch (419:6): [True: 1, False: 0]
  ------------------
  420|      1|		svr_opts.ports[0] = m_strdup(DROPBEAR_DEFPORT);
  ------------------
  |  |   25|      1|#define DROPBEAR_DEFPORT "22"
  ------------------
  421|      1|		svr_opts.addresses[0] = m_strdup(DROPBEAR_DEFADDRESS);
  ------------------
  |  |   30|      1|#define DROPBEAR_DEFADDRESS ""
  ------------------
  422|      1|		svr_opts.portcount = 1;
  423|      1|	}
  424|       |
  425|      1|	if (svr_opts.bannerfile) {
  ------------------
  |  Branch (425:6): [True: 0, False: 1]
  ------------------
  426|      0|		load_banner();
  427|      0|	}
  428|       |
  429|      1|#ifdef HAVE_GETGROUPLIST
  430|      1|	if (svr_opts.restrict_group) {
  ------------------
  |  Branch (430:6): [True: 0, False: 1]
  ------------------
  431|      0|		struct group *restrictedgroup = getgrnam(svr_opts.restrict_group);
  432|       |
  433|      0|		if (restrictedgroup){
  ------------------
  |  Branch (433:7): [True: 0, False: 0]
  ------------------
  434|      0|			svr_opts.restrict_group_gid = restrictedgroup->gr_gid;
  435|      0|		} else {
  436|      0|			dropbear_exit("Cannot restrict logins to group '%s' as the group does not exist", svr_opts.restrict_group);
  437|      0|		}
  438|      0|	}
  439|      1|#endif
  440|       |
  441|      1|	if (recv_window_arg) {
  ------------------
  |  Branch (441:6): [True: 0, False: 1]
  ------------------
  442|      0|		parse_recv_window(recv_window_arg);
  443|      0|	}
  444|       |
  445|      1|	if (maxauthtries_arg) {
  ------------------
  |  Branch (445:6): [True: 0, False: 1]
  ------------------
  446|      0|		unsigned int val = 0;
  447|      0|		if (m_str_to_uint(maxauthtries_arg, &val) == DROPBEAR_FAILURE) {
  ------------------
  |  |  112|      0|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (447:7): [True: 0, False: 0]
  ------------------
  448|      0|			dropbear_exit("Bad maxauthtries '%s'", maxauthtries_arg);
  449|      0|		}
  450|      0|		svr_opts.maxauthtries = val;
  451|      0|	}
  452|       |
  453|       |
  454|      1|	if (keepalive_arg) {
  ------------------
  |  Branch (454:6): [True: 0, False: 1]
  ------------------
  455|      0|		unsigned int val;
  456|      0|		if (m_str_to_uint(keepalive_arg, &val) == DROPBEAR_FAILURE) {
  ------------------
  |  |  112|      0|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (456:7): [True: 0, False: 0]
  ------------------
  457|      0|			dropbear_exit("Bad keepalive '%s'", keepalive_arg);
  458|      0|		}
  459|      0|		opts.keepalive_secs = val;
  460|      0|	}
  461|       |
  462|      1|	if (idle_timeout_arg) {
  ------------------
  |  Branch (462:6): [True: 0, False: 1]
  ------------------
  463|      0|		unsigned int val;
  464|      0|		if (m_str_to_uint(idle_timeout_arg, &val) == DROPBEAR_FAILURE) {
  ------------------
  |  |  112|      0|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (464:7): [True: 0, False: 0]
  ------------------
  465|      0|			dropbear_exit("Bad idle_timeout '%s'", idle_timeout_arg);
  466|      0|		}
  467|      0|		opts.idle_timeout_secs = val;
  468|      0|	}
  469|       |
  470|      1|	if (max_duration_arg) {
  ------------------
  |  Branch (470:6): [True: 0, False: 1]
  ------------------
  471|      0|		unsigned int val;
  472|      0|		if (m_str_to_uint(max_duration_arg, &val) == DROPBEAR_FAILURE) {
  ------------------
  |  |  112|      0|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (472:7): [True: 0, False: 0]
  ------------------
  473|      0|			dropbear_exit("Bad max_duration '%s'", max_duration_arg);
  474|      0|		}
  475|      0|		opts.max_duration_secs = val;
  476|      0|	}
  477|       |
  478|      1|	if (svr_opts.forced_command) {
  ------------------
  |  Branch (478:6): [True: 0, False: 1]
  ------------------
  479|      0|		dropbear_log(LOG_INFO, "Forced command set to '%s'", svr_opts.forced_command);
  480|      0|	}
  481|       |
  482|      1|	if (svr_opts.interface) {
  ------------------
  |  Branch (482:6): [True: 0, False: 1]
  ------------------
  483|      0|		dropbear_log(LOG_INFO, "Binding to interface '%s'", svr_opts.interface);
  484|      0|	}
  485|       |
  486|      1|	if (reexec_fd_arg) {
  ------------------
  |  Branch (486:6): [True: 0, False: 1]
  ------------------
  487|      0|		if (m_str_to_uint(reexec_fd_arg, &svr_opts.reexec_childpipe) == DROPBEAR_FAILURE
  ------------------
  |  |  112|      0|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (487:7): [True: 0, False: 0]
  ------------------
  488|      0|			|| svr_opts.reexec_childpipe < 0) {
  ------------------
  |  Branch (488:7): [True: 0, False: 0]
  ------------------
  489|      0|			dropbear_exit("Bad -2");
  490|      0|		}
  491|      0|	}
  492|       |
  493|      1|	if (svr_opts.multiauthmethod && svr_opts.noauthpass) {
  ------------------
  |  Branch (493:6): [True: 0, False: 1]
  |  Branch (493:34): [True: 0, False: 0]
  ------------------
  494|      0|		dropbear_exit("-t and -s are incompatible");
  495|      0|	}
  496|       |
  497|      1|	if (strlen(svr_opts.authorized_keys_dir) == 0) {
  ------------------
  |  Branch (497:6): [True: 0, False: 1]
  ------------------
  498|      0|		dropbear_exit("Bad -D");
  499|      0|	}
  500|       |
  501|       |#if DROPBEAR_PLUGIN
  502|       |	if (pubkey_plugin) {
  503|       |		svr_opts.pubkey_plugin = m_strdup(pubkey_plugin);
  504|       |		char *args = strchr(svr_opts.pubkey_plugin, ',');
  505|       |		if (args) {
  506|       |			*args='\0';
  507|       |			++args;
  508|       |		}
  509|       |		svr_opts.pubkey_plugin_options = args;
  510|       |	}
  511|       |#endif
  512|      1|	if (algo_print_arg) {
  ------------------
  |  Branch (512:6): [True: 0, False: 1]
  ------------------
  513|      0|		print_algos(algo_print_arg);
  514|       |		/* No return */
  515|      0|	}
  516|      1|}
disable_sig_except:
  560|  1.53k|void disable_sig_except(enum signature_type allow_type) {
  561|  1.53k|	int i;
  562|  1.53k|	TRACE(("Disabling other sigs except %d", allow_type));
  563|  15.3k|	for (i = 0; sigalgs[i].name != NULL; i++) {
  ------------------
  |  Branch (563:14): [True: 13.8k, False: 1.53k]
  ------------------
  564|  13.8k|		enum signature_type sig_type = sigalgs[i].val;
  565|  13.8k|		if (sig_type != allow_type) {
  ------------------
  |  Branch (565:7): [True: 12.2k, False: 1.53k]
  ------------------
  566|  12.2k|			sigalgs[i].usable = 0;
  567|  12.2k|		}
  568|  13.8k|	}
  569|  1.53k|}

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

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

