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|  3.35k|int fuzz_set_input(const uint8_t *Data, size_t Size) {
   58|       |
   59|  3.35k|    fuzz.input->data = (unsigned char*)Data;
   60|  3.35k|    fuzz.input->size = Size;
   61|  3.35k|    fuzz.input->len = Size;
   62|  3.35k|    fuzz.input->pos = 0;
   63|       |
   64|  3.35k|    memset(&ses, 0x0, sizeof(ses));
   65|  3.35k|    memset(&svr_ses, 0x0, sizeof(svr_ses));
   66|  3.35k|    memset(&cli_ses, 0x0, sizeof(cli_ses));
   67|  3.35k|    wrapfd_setup(fuzz.input);
   68|       |    // printhex("input", fuzz.input->data, fuzz.input->len);
   69|       |
   70|  3.35k|    fuzz_seed(fuzz.input->data, MIN(fuzz.input->len, 16));
  ------------------
  |  Branch (70:33): [True: 265, False: 3.09k]
  ------------------
   71|       |
   72|  3.35k|    return DROPBEAR_SUCCESS;
  ------------------
  |  |  111|  3.35k|#define DROPBEAR_SUCCESS 0
  ------------------
   73|  3.35k|}
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|  3.35k|void fuzz_svr_hook_preloop() {
  106|  3.35k|    if (fuzz.svr_postauth) {
  ------------------
  |  Branch (106:9): [True: 0, False: 3.35k]
  ------------------
  107|      0|        ses.authstate.authdone = 1;
  108|      0|        fill_passwd("root");
  109|      0|    }
  110|  3.35k|}
fuzz_kex_fakealgos:
  197|  9.09k|void fuzz_kex_fakealgos(void) {
  198|  9.09k|    ses.newkeys->recv.crypt_mode = &dropbear_mode_none;
  199|  9.09k|    ses.newkeys->recv.algo_mac = &dropbear_nohash;
  200|  9.09k|}
fuzz_get_socket_address:
  203|  6.71k|                        char **remote_host, char **remote_port, int UNUSED(host_lookup)) {
  204|  6.71k|    if (local_host) {
  ------------------
  |  Branch (204:9): [True: 0, False: 6.71k]
  ------------------
  205|      0|        *local_host = m_strdup("fuzzlocalhost");
  206|      0|    }
  207|  6.71k|    if (local_port) {
  ------------------
  |  Branch (207:9): [True: 0, False: 6.71k]
  ------------------
  208|      0|        *local_port = m_strdup("1234");
  209|      0|    }
  210|  6.71k|    if (remote_host) {
  ------------------
  |  Branch (210:9): [True: 6.71k, False: 0]
  ------------------
  211|  6.71k|        *remote_host = m_strdup("fuzzremotehost");
  212|  6.71k|    }
  213|  6.71k|    if (remote_port) {
  ------------------
  |  Branch (213:9): [True: 3.35k, False: 3.35k]
  ------------------
  214|  3.35k|        *remote_port = m_strdup("9876");
  215|  3.35k|    }
  216|  6.71k|}
fuzz_run_server:
  264|  3.35k|int fuzz_run_server(const uint8_t *Data, size_t Size, int skip_kexmaths, int postauth) {
  265|  3.35k|    static int once = 0;
  266|  3.35k|    if (!once) {
  ------------------
  |  Branch (266:9): [True: 1, False: 3.35k]
  ------------------
  267|      1|        fuzz_svr_setup();
  268|      1|        fuzz.skip_kexmaths = skip_kexmaths;
  269|      1|        once = 1;
  270|      1|    }
  271|       |
  272|  3.35k|    fuzz.svr_postauth = postauth;
  273|       |
  274|  3.35k|    if (fuzz_set_input(Data, Size) == DROPBEAR_FAILURE) {
  ------------------
  |  |  112|  3.35k|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (274:9): [True: 0, False: 3.35k]
  ------------------
  275|      0|        return 0;
  276|      0|    }
  277|       |
  278|  3.35k|    uint32_t wrapseed;
  279|  3.35k|    genrandom((void*)&wrapseed, sizeof(wrapseed));
  280|  3.35k|    wrapfd_setseed(wrapseed);
  281|       |
  282|  3.35k|    int fakesock = wrapfd_new_fuzzinput();
  283|       |
  284|  3.35k|    m_malloc_set_epoch(1);
  285|  3.35k|    fuzz.do_jmp = 1;
  286|  3.35k|    if (setjmp(fuzz.jmp) == 0) {
  ------------------
  |  Branch (286:9): [True: 3.35k, False: 0]
  ------------------
  287|  3.35k|        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|  3.35k|}
fuzz_dump:
  345|   110k|void fuzz_dump(const unsigned char* data, size_t len) {
  346|   110k|    if (fuzz.dumping) {
  ------------------
  |  Branch (346:9): [True: 0, False: 110k]
  ------------------
  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|   110k|}
fuzz_getpwnam:
  373|    271|struct passwd* fuzz_getpwnam(const char *login) {
  374|    271|    if (!fuzz.fuzzing) {
  ------------------
  |  Branch (374:9): [True: 0, False: 271]
  ------------------
  375|      0|        return getpwnam(login);
  376|      0|    }
  377|    271|    if (strcmp(login, pwd_other.pw_name) == 0) {
  ------------------
  |  Branch (377:9): [True: 0, False: 271]
  ------------------
  378|      0|        return &pwd_other;
  379|      0|    }
  380|    271|    if (strcmp(login, pwd_root.pw_name) == 0) {
  ------------------
  |  Branch (380:9): [True: 2, False: 269]
  ------------------
  381|      2|        return &pwd_root;
  382|      2|    }
  383|    269|    return NULL;
  384|    271|}
fuzz-common.c:fuzz_dropbear_log:
   84|  3.74k|static void fuzz_dropbear_log(int UNUSED(priority), const char* UNUSED(format), va_list UNUSED(param)) {
   85|       |    /* No print */
   86|  3.74k|}
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|  3.35k|void wrapfd_setup(buffer *buf) {
   33|  3.35k|	TRACE(("wrapfd_setup"))
   34|       |
   35|       |	// clean old ones
   36|  3.35k|	int i;
   37|  26.8k|	for (i = 0; i <= wrapfd_maxfd; i++) {
  ------------------
  |  Branch (37:14): [True: 23.4k, False: 3.35k]
  ------------------
   38|  23.4k|		if (wrap_fds[i].mode != UNUSED) {
  ------------------
  |  Branch (38:7): [True: 2.04k, False: 21.4k]
  ------------------
   39|  2.04k|			wrapfd_remove(i);
   40|  2.04k|		}
   41|  23.4k|	}
   42|  3.35k|	wrapfd_maxfd = -1;
   43|       |
   44|  3.35k|	memset(rand_state, 0x0, sizeof(rand_state));
   45|  3.35k|	wrapfd_setseed(50);
   46|  3.35k|	input_buf = buf;
   47|  3.35k|}
wrapfd_setseed:
   49|  6.71k|void wrapfd_setseed(uint32_t seed) {
   50|  6.71k|	memcpy(rand_state, &seed, sizeof(seed));
   51|  6.71k|	nrand48(rand_state);
   52|  6.71k|}
wrapfd_new_fuzzinput:
   54|  3.35k|int wrapfd_new_fuzzinput() {
   55|  3.35k|	if (devnull_fd == -1) {
  ------------------
  |  Branch (55:6): [True: 1, False: 3.35k]
  ------------------
   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|  3.35k|	int fd = dup(devnull_fd);
   61|  3.35k|	assert(fd != -1);
  ------------------
  |  Branch (61:2): [True: 0, False: 3.35k]
  |  Branch (61:2): [True: 3.35k, False: 0]
  ------------------
   62|  3.35k|	assert(wrap_fds[fd].mode == UNUSED);
  ------------------
  |  Branch (62:2): [True: 0, False: 3.35k]
  |  Branch (62:2): [True: 3.35k, False: 0]
  ------------------
   63|  3.35k|	wrap_fds[fd].mode = COMMONBUF;
   64|  3.35k|	wrap_fds[fd].closein = 0;
   65|  3.35k|	wrap_fds[fd].closeout = 0;
   66|  3.35k|	wrapfd_maxfd = MAX(fd, wrapfd_maxfd);
  ------------------
  |  Branch (66:17): [True: 3.35k, False: 0]
  ------------------
   67|       |
   68|  3.35k|	return fd;
   69|  3.35k|}
wrapfd_close:
  105|  1.31k|int wrapfd_close(int fd) {
  106|  1.31k|	if (fd >= 0 && fd <= IOWRAP_MAXFD && wrap_fds[fd].mode != UNUSED) {
  ------------------
  |  |    9|  2.62k|#define IOWRAP_MAXFD (FD_SETSIZE-1)
  ------------------
  |  Branch (106:6): [True: 1.31k, False: 0]
  |  Branch (106:17): [True: 1.31k, False: 0]
  |  Branch (106:39): [True: 1.31k, False: 0]
  ------------------
  107|  1.31k|		wrapfd_remove(fd);
  108|  1.31k|		return 0;
  109|  1.31k|	} else {
  110|      0|		return close(fd);
  111|      0|	}
  112|  1.31k|}
wrapfd_read:
  114|   332k|int wrapfd_read(int fd, void *out, size_t count) {
  115|   332k|	size_t maxread;
  116|       |
  117|   332k|	if (!fuzz.wrapfds) {
  ------------------
  |  Branch (117:6): [True: 0, False: 332k]
  ------------------
  118|      0|		return read(fd, out, count);
  119|      0|	}
  120|       |
  121|   332k|	if (fd < 0 || fd > IOWRAP_MAXFD || wrap_fds[fd].mode == UNUSED) {
  ------------------
  |  |    9|   664k|#define IOWRAP_MAXFD (FD_SETSIZE-1)
  ------------------
  |  Branch (121:6): [True: 0, False: 332k]
  |  Branch (121:16): [True: 0, False: 332k]
  |  Branch (121:37): [True: 0, False: 332k]
  ------------------
  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|   332k|	assert(count != 0);
  ------------------
  |  Branch (128:2): [True: 0, False: 332k]
  |  Branch (128:2): [True: 332k, False: 0]
  ------------------
  129|       |
  130|   332k|	if (wrap_fds[fd].closein || erand48(rand_state) < CHANCE_CLOSE) {
  ------------------
  |  Branch (130:6): [True: 0, False: 332k]
  |  Branch (130:30): [True: 9, False: 332k]
  ------------------
  131|      9|		wrap_fds[fd].closein = 1;
  132|      9|		errno = ECONNRESET;
  133|      9|		return -1;
  134|      9|	}
  135|       |
  136|   332k|	if (erand48(rand_state) < CHANCE_INTR) {
  ------------------
  |  Branch (136:6): [True: 427, False: 331k]
  ------------------
  137|    427|		errno = EINTR;
  138|    427|		return -1;
  139|    427|	}
  140|       |
  141|   331k|	if (input_buf && wrap_fds[fd].mode == COMMONBUF) {
  ------------------
  |  Branch (141:6): [True: 331k, False: 0]
  |  Branch (141:19): [True: 331k, False: 0]
  ------------------
  142|   331k|		maxread = MIN(input_buf->len - input_buf->pos, count);
  ------------------
  |  Branch (142:13): [True: 1.97k, False: 329k]
  ------------------
  143|       |		/* returns 0 if buf is EOF, as intended */
  144|   331k|		if (maxread > 0) {
  ------------------
  |  Branch (144:7): [True: 330k, False: 1.26k]
  ------------------
  145|   330k|			maxread = nrand48(rand_state) % maxread + 1;
  146|   330k|		}
  147|   331k|		memcpy(out, buf_getptr(input_buf, maxread), maxread);
  148|   331k|		buf_incrpos(input_buf, maxread);
  149|   331k|		return maxread;
  150|   331k|	}
  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|   331k|}
wrapfd_select:
  196|   327k|	fd_set *exceptfds, struct timeval *timeout) {
  197|   327k|	int i, nset, sel;
  198|   327k|	int ret = 0;
  199|   327k|	int fdlist[IOWRAP_MAXFD+1];
  200|       |
  201|   327k|	if (!fuzz.wrapfds) {
  ------------------
  |  Branch (201:6): [True: 0, False: 327k]
  ------------------
  202|      0|		return select(nfds, readfds, writefds, exceptfds, timeout);
  203|      0|	}
  204|       |
  205|   327k|	assert(nfds <= IOWRAP_MAXFD+1);
  ------------------
  |  Branch (205:2): [True: 0, False: 327k]
  |  Branch (205:2): [True: 327k, False: 0]
  ------------------
  206|       |
  207|   327k|	if (erand48(rand_state) < CHANCE_INTR) {
  ------------------
  |  Branch (207:6): [True: 457, False: 326k]
  ------------------
  208|    457|		errno = EINTR;
  209|    457|		return -1;
  210|    457|	}
  211|       |
  212|       |	/* read */
  213|   326k|	if (readfds != NULL && erand48(rand_state) < CHANCE_READ1) {
  ------------------
  |  Branch (213:6): [True: 326k, False: 0]
  |  Branch (213:25): [True: 306k, False: 19.7k]
  ------------------
  214|  2.45M|		for (i = 0, nset = 0; i < nfds; i++) {
  ------------------
  |  Branch (214:25): [True: 2.14M, False: 306k]
  ------------------
  215|  2.14M|			if (FD_ISSET(i, readfds)) {
  ------------------
  |  Branch (215:8): [True: 300k, False: 1.84M]
  ------------------
  216|   300k|				assert(wrap_fds[i].mode != UNUSED);
  ------------------
  |  Branch (216:5): [True: 0, False: 300k]
  |  Branch (216:5): [True: 300k, False: 0]
  ------------------
  217|   300k|				fdlist[nset] = i;
  218|   300k|				nset++;
  219|   300k|			}
  220|  2.14M|		}
  221|   306k|		DROPBEAR_FD_ZERO(readfds);
  ------------------
  |  |  106|   306k|#define DROPBEAR_FD_ZERO(fds) FD_ZERO(fds)
  ------------------
  |  Branch (221:3): [Folded, False: 306k]
  ------------------
  222|       |
  223|   306k|		if (nset > 0) {
  ------------------
  |  Branch (223:7): [True: 300k, False: 6.53k]
  ------------------
  224|       |			/* set one */
  225|   300k|			sel = fdlist[nrand48(rand_state) % nset];
  226|   300k|			FD_SET(sel, readfds);
  227|   300k|			ret++;
  228|       |
  229|   300k|			if (erand48(rand_state) < CHANCE_READ2) {
  ------------------
  |  Branch (229:8): [True: 149k, False: 151k]
  ------------------
  230|   149k|				sel = fdlist[nrand48(rand_state) % nset];
  231|   149k|				if (!FD_ISSET(sel, readfds)) {
  ------------------
  |  Branch (231:9): [True: 0, False: 149k]
  ------------------
  232|      0|					FD_SET(sel, readfds);
  233|      0|					ret++;
  234|      0|				}
  235|   149k|			}
  236|   300k|		}
  237|   306k|	}
  238|       |
  239|       |	/* write */
  240|   326k|	if (writefds != NULL && erand48(rand_state) < CHANCE_WRITE1) {
  ------------------
  |  Branch (240:6): [True: 263k, False: 62.8k]
  |  Branch (240:26): [True: 254k, False: 9.67k]
  ------------------
  241|  2.03M|		for (i = 0, nset = 0; i < nfds; i++) {
  ------------------
  |  Branch (241:25): [True: 1.77M, False: 254k]
  ------------------
  242|  1.77M|			if (FD_ISSET(i, writefds)) {
  ------------------
  |  Branch (242:8): [True: 14.8k, False: 1.76M]
  ------------------
  243|  14.8k|				assert(wrap_fds[i].mode != UNUSED);
  ------------------
  |  Branch (243:5): [True: 0, False: 14.8k]
  |  Branch (243:5): [True: 14.8k, False: 0]
  ------------------
  244|  14.8k|				fdlist[nset] = i;
  245|  14.8k|				nset++;
  246|  14.8k|			}
  247|  1.77M|		}
  248|   254k|		DROPBEAR_FD_ZERO(writefds);
  ------------------
  |  |  106|   254k|#define DROPBEAR_FD_ZERO(fds) FD_ZERO(fds)
  ------------------
  |  Branch (248:3): [Folded, False: 254k]
  ------------------
  249|       |
  250|       |		/* set one */
  251|   254k|		if (nset > 0) {
  ------------------
  |  Branch (251:7): [True: 14.8k, False: 239k]
  ------------------
  252|  14.8k|			sel = fdlist[nrand48(rand_state) % nset];
  253|  14.8k|			FD_SET(sel, writefds);
  254|  14.8k|			ret++;
  255|       |
  256|  14.8k|			if (erand48(rand_state) < CHANCE_WRITE2) {
  ------------------
  |  Branch (256:8): [True: 4.88k, False: 9.94k]
  ------------------
  257|  4.88k|				sel = fdlist[nrand48(rand_state) % nset];
  258|  4.88k|				if (!FD_ISSET(sel, writefds)) {
  ------------------
  |  Branch (258:9): [True: 0, False: 4.88k]
  ------------------
  259|      0|					FD_SET(sel, writefds);
  260|      0|					ret++;
  261|      0|				}
  262|  4.88k|			}
  263|  14.8k|		}
  264|   254k|	}
  265|   326k|	return ret;
  266|   326k|}
fuzz-wrapfd.c:wrapfd_remove:
   96|  3.35k|static void wrapfd_remove(int fd) {
   97|  3.35k|	TRACE(("wrapfd_remove %d", fd))
   98|  3.35k|	assert(fd >= 0);
  ------------------
  |  Branch (98:2): [True: 0, False: 3.35k]
  |  Branch (98:2): [True: 3.35k, False: 0]
  ------------------
   99|  3.35k|	assert(fd <= IOWRAP_MAXFD);
  ------------------
  |  Branch (99:2): [True: 0, False: 3.35k]
  |  Branch (99:2): [True: 3.35k, False: 0]
  ------------------
  100|  3.35k|	assert(wrap_fds[fd].mode != UNUSED);
  ------------------
  |  Branch (100:2): [True: 0, False: 3.35k]
  |  Branch (100:2): [True: 3.35k, False: 0]
  ------------------
  101|  3.35k|	wrap_fds[fd].mode = UNUSED;
  102|  3.35k|	close(fd);
  103|  3.35k|}

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

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

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

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

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

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

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

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

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

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

ltm_desc.c:init:
   58|   907k|{
   59|   907k|   int err;
   60|       |
   61|   907k|   LTC_ARGCHK(a != NULL);
  ------------------
  |  |   32|   907k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 907k]
  |  |  |  Branch (32:87): [Folded, False: 907k]
  |  |  ------------------
  ------------------
   62|       |
   63|   907k|   if ((err = init_mpi(a)) != CRYPT_OK) {
  ------------------
  |  Branch (63:8): [True: 0, False: 907k]
  ------------------
   64|      0|      return err;
   65|      0|   }
   66|   907k|   if ((err = mpi_to_ltc_error(mp_init(*a))) != CRYPT_OK) {
  ------------------
  |  Branch (66:8): [True: 0, False: 907k]
  ------------------
   67|      0|      XFREE(*a);
  ------------------
  |  |   17|      0|#define XFREE m_free_direct
  ------------------
   68|      0|   }
   69|   907k|   return err;
   70|   907k|}
ltm_desc.c:init_mpi:
   46|   907k|{
   47|   907k|   LTC_ARGCHK(a != NULL);
  ------------------
  |  |   32|   907k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 907k]
  |  |  |  Branch (32:87): [Folded, False: 907k]
  |  |  ------------------
  ------------------
   48|       |
   49|   907k|   *a = XCALLOC(1, sizeof(mp_int));
  ------------------
  |  |   19|   907k|#define XCALLOC m_calloc
  ------------------
   50|   907k|   if (*a == NULL) {
  ------------------
  |  Branch (50:8): [True: 0, False: 907k]
  ------------------
   51|      0|      return CRYPT_MEM;
   52|   907k|   } else {
   53|   907k|      return CRYPT_OK;
   54|   907k|   }
   55|   907k|}
ltm_desc.c:mpi_to_ltc_error:
   34|  12.2M|{
   35|  12.2M|   size_t x;
   36|       |
   37|  12.2M|   for (x = 0; x < sizeof(mpi_to_ltc_codes)/sizeof(mpi_to_ltc_codes[0]); x++) {
  ------------------
  |  Branch (37:16): [True: 12.2M, False: 0]
  ------------------
   38|  12.2M|       if (err == mpi_to_ltc_codes[x].mpi_code) {
  ------------------
  |  Branch (38:12): [True: 12.2M, False: 0]
  ------------------
   39|  12.2M|          return mpi_to_ltc_codes[x].ltc_code;
   40|  12.2M|       }
   41|  12.2M|   }
   42|      0|   return CRYPT_ERROR;
   43|  12.2M|}
ltm_desc.c:deinit:
   73|   906k|{
   74|   906k|   LTC_ARGCHKVD(a != NULL);
  ------------------
  |  |   33|   906k|#define LTC_ARGCHKVD(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (33:34): [True: 0, False: 906k]
  |  |  |  Branch (33:89): [Folded, False: 906k]
  |  |  ------------------
  ------------------
   75|   906k|   mp_clear(a);
   76|   906k|   XFREE(a);
  ------------------
  |  |   17|   906k|#define XFREE m_free_direct
  ------------------
   77|   906k|}
ltm_desc.c:copy:
   87|   799k|{
   88|   799k|   LTC_ARGCHK(a != NULL);
  ------------------
  |  |   32|   799k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 799k]
  |  |  |  Branch (32:87): [Folded, False: 799k]
  |  |  ------------------
  ------------------
   89|   799k|   LTC_ARGCHK(b != NULL);
  ------------------
  |  |   32|   799k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 799k]
  |  |  |  Branch (32:87): [Folded, False: 799k]
  |  |  ------------------
  ------------------
   90|   799k|   return mpi_to_ltc_error(mp_copy(a, b));
   91|   799k|}
ltm_desc.c:set_int:
  104|    558|{
  105|    558|   LTC_ARGCHK(a != NULL);
  ------------------
  |  |   32|    558|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 558]
  |  |  |  Branch (32:87): [Folded, False: 558]
  |  |  ------------------
  ------------------
  106|    558|   mp_set_u32(a, b);
  107|    558|   return CRYPT_OK;
  108|    558|}
ltm_desc.c:get_digit:
  117|   259k|{
  118|   259k|   mp_int *A;
  119|   259k|   LTC_ARGCHK(a != NULL);
  ------------------
  |  |   32|   259k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 259k]
  |  |  |  Branch (32:87): [Folded, False: 259k]
  |  |  ------------------
  ------------------
  120|   259k|   A = a;
  121|   259k|   return (n >= A->used || n < 0) ? 0 : A->dp[n];
  ------------------
  |  Branch (121:12): [True: 0, False: 259k]
  |  Branch (121:28): [True: 0, False: 259k]
  ------------------
  122|   259k|}
ltm_desc.c:get_digit_count:
  125|   257k|{
  126|   257k|   mp_int *A;
  127|   257k|   LTC_ARGCHK(a != NULL);
  ------------------
  |  |   32|   257k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 257k]
  |  |  |  Branch (32:87): [Folded, False: 257k]
  |  |  ------------------
  ------------------
  128|   257k|   A = a;
  129|   257k|   return A->used;
  130|   257k|}
ltm_desc.c:compare:
  133|  1.28M|{
  134|  1.28M|   LTC_ARGCHK(a != NULL);
  ------------------
  |  |   32|  1.28M|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 1.28M]
  |  |  |  Branch (32:87): [Folded, False: 1.28M]
  |  |  ------------------
  ------------------
  135|  1.28M|   LTC_ARGCHK(b != NULL);
  ------------------
  |  |   32|  1.28M|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 1.28M]
  |  |  |  Branch (32:87): [Folded, False: 1.28M]
  |  |  ------------------
  ------------------
  136|  1.28M|   switch (mp_cmp(a, b)) {
  137|   649k|      case MP_LT: return LTC_MP_LT;
  ------------------
  |  |  154|   649k|#define MP_LT        -1   /* less than */
  ------------------
                    case MP_LT: return LTC_MP_LT;
  ------------------
  |  |   12|   649k|#define LTC_MP_LT   -1
  ------------------
  |  Branch (137:7): [True: 649k, False: 638k]
  ------------------
  138|      0|      case MP_EQ: return LTC_MP_EQ;
  ------------------
  |  |  155|      0|#define MP_EQ         0   /* equal to */
  ------------------
                    case MP_EQ: return LTC_MP_EQ;
  ------------------
  |  |   13|      0|#define LTC_MP_EQ    0
  ------------------
  |  Branch (138:7): [True: 0, False: 1.28M]
  ------------------
  139|   638k|      case MP_GT: return LTC_MP_GT;
  ------------------
  |  |  156|   638k|#define MP_GT         1   /* greater than */
  ------------------
                    case MP_GT: return LTC_MP_GT;
  ------------------
  |  |   14|   638k|#define LTC_MP_GT    1
  ------------------
  |  Branch (139:7): [True: 638k, False: 649k]
  ------------------
  140|      0|      default:    return 0;
  ------------------
  |  Branch (140:7): [True: 0, False: 1.28M]
  ------------------
  141|  1.28M|   }
  142|  1.28M|}
ltm_desc.c:compare_d:
  145|  1.41M|{
  146|  1.41M|   LTC_ARGCHK(a != NULL);
  ------------------
  |  |   32|  1.41M|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 1.41M]
  |  |  |  Branch (32:87): [Folded, False: 1.41M]
  |  |  ------------------
  ------------------
  147|  1.41M|   switch (mp_cmp_d(a, b)) {
  148|   704k|      case MP_LT: return LTC_MP_LT;
  ------------------
  |  |  154|   704k|#define MP_LT        -1   /* less than */
  ------------------
                    case MP_LT: return LTC_MP_LT;
  ------------------
  |  |   12|   704k|#define LTC_MP_LT   -1
  ------------------
  |  Branch (148:7): [True: 704k, False: 711k]
  ------------------
  149|      0|      case MP_EQ: return LTC_MP_EQ;
  ------------------
  |  |  155|      0|#define MP_EQ         0   /* equal to */
  ------------------
                    case MP_EQ: return LTC_MP_EQ;
  ------------------
  |  |   13|      0|#define LTC_MP_EQ    0
  ------------------
  |  Branch (149:7): [True: 0, False: 1.41M]
  ------------------
  150|   711k|      case MP_GT: return LTC_MP_GT;
  ------------------
  |  |  156|   711k|#define MP_GT         1   /* greater than */
  ------------------
                    case MP_GT: return LTC_MP_GT;
  ------------------
  |  |   14|   711k|#define LTC_MP_GT    1
  ------------------
  |  Branch (150:7): [True: 711k, False: 704k]
  ------------------
  151|      0|      default:    return 0;
  ------------------
  |  Branch (151:7): [True: 0, False: 1.41M]
  ------------------
  152|  1.41M|   }
  153|  1.41M|}
ltm_desc.c:read_radix:
  178|  1.11k|{
  179|  1.11k|   LTC_ARGCHK(a != NULL);
  ------------------
  |  |   32|  1.11k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 1.11k]
  |  |  |  Branch (32:87): [Folded, False: 1.11k]
  |  |  ------------------
  ------------------
  180|  1.11k|   LTC_ARGCHK(b != NULL);
  ------------------
  |  |   32|  1.11k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 1.11k]
  |  |  |  Branch (32:87): [Folded, False: 1.11k]
  |  |  ------------------
  ------------------
  181|  1.11k|   return mpi_to_ltc_error(mp_read_radix(a, b, radix));
  182|  1.11k|}
ltm_desc.c:unsigned_read:
  209|    279|{
  210|    279|   LTC_ARGCHK(a != NULL);
  ------------------
  |  |   32|    279|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 279]
  |  |  |  Branch (32:87): [Folded, False: 279]
  |  |  ------------------
  ------------------
  211|    279|   LTC_ARGCHK(b != NULL);
  ------------------
  |  |   32|    279|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 279]
  |  |  |  Branch (32:87): [Folded, False: 279]
  |  |  ------------------
  ------------------
  212|    279|   return mpi_to_ltc_error(mp_from_ubin(a, b, (size_t)len));
  213|    279|}
ltm_desc.c:add:
  217|  1.98M|{
  218|  1.98M|   LTC_ARGCHK(a != NULL);
  ------------------
  |  |   32|  1.98M|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 1.98M]
  |  |  |  Branch (32:87): [Folded, False: 1.98M]
  |  |  ------------------
  ------------------
  219|  1.98M|   LTC_ARGCHK(b != NULL);
  ------------------
  |  |   32|  1.98M|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 1.98M]
  |  |  |  Branch (32:87): [Folded, False: 1.98M]
  |  |  ------------------
  ------------------
  220|  1.98M|   LTC_ARGCHK(c != NULL);
  ------------------
  |  |   32|  1.98M|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 1.98M]
  |  |  |  Branch (32:87): [Folded, False: 1.98M]
  |  |  ------------------
  ------------------
  221|  1.98M|   return mpi_to_ltc_error(mp_add(a, b, c));
  222|  1.98M|}
ltm_desc.c:sub:
  233|  2.11M|{
  234|  2.11M|   LTC_ARGCHK(a != NULL);
  ------------------
  |  |   32|  2.11M|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 2.11M]
  |  |  |  Branch (32:87): [Folded, False: 2.11M]
  |  |  ------------------
  ------------------
  235|  2.11M|   LTC_ARGCHK(b != NULL);
  ------------------
  |  |   32|  2.11M|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 2.11M]
  |  |  |  Branch (32:87): [Folded, False: 2.11M]
  |  |  ------------------
  ------------------
  236|  2.11M|   LTC_ARGCHK(c != NULL);
  ------------------
  |  |   32|  2.11M|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 2.11M]
  |  |  |  Branch (32:87): [Folded, False: 2.11M]
  |  |  ------------------
  ------------------
  237|  2.11M|   return mpi_to_ltc_error(mp_sub(a, b, c));
  238|  2.11M|}
ltm_desc.c:mul:
  249|  2.06M|{
  250|  2.06M|   LTC_ARGCHK(a != NULL);
  ------------------
  |  |   32|  2.06M|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 2.06M]
  |  |  |  Branch (32:87): [Folded, False: 2.06M]
  |  |  ------------------
  ------------------
  251|  2.06M|   LTC_ARGCHK(b != NULL);
  ------------------
  |  |   32|  2.06M|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 2.06M]
  |  |  |  Branch (32:87): [Folded, False: 2.06M]
  |  |  ------------------
  ------------------
  252|  2.06M|   LTC_ARGCHK(c != NULL);
  ------------------
  |  |   32|  2.06M|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 2.06M]
  |  |  |  Branch (32:87): [Folded, False: 2.06M]
  |  |  ------------------
  ------------------
  253|  2.06M|   return mpi_to_ltc_error(mp_mul(a, b, c));
  254|  2.06M|}
ltm_desc.c:sqr:
  265|  1.03M|{
  266|  1.03M|   LTC_ARGCHK(a != NULL);
  ------------------
  |  |   32|  1.03M|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 1.03M]
  |  |  |  Branch (32:87): [Folded, False: 1.03M]
  |  |  ------------------
  ------------------
  267|  1.03M|   LTC_ARGCHK(b != NULL);
  ------------------
  |  |   32|  1.03M|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 1.03M]
  |  |  |  Branch (32:87): [Folded, False: 1.03M]
  |  |  ------------------
  ------------------
  268|  1.03M|   return mpi_to_ltc_error(mp_sqr(a, b));
  269|  1.03M|}
ltm_desc.c:divide:
  273|    711|{
  274|    711|   LTC_ARGCHK(a != NULL);
  ------------------
  |  |   32|    711|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 711]
  |  |  |  Branch (32:87): [Folded, False: 711]
  |  |  ------------------
  ------------------
  275|    711|   LTC_ARGCHK(b != NULL);
  ------------------
  |  |   32|    711|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 711]
  |  |  |  Branch (32:87): [Folded, False: 711]
  |  |  ------------------
  ------------------
  276|    711|   return mpi_to_ltc_error(mp_div(a, b, c, d));
  277|    711|}
ltm_desc.c:div_2:
  280|   257k|{
  281|   257k|   LTC_ARGCHK(a != NULL);
  ------------------
  |  |   32|   257k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 257k]
  |  |  |  Branch (32:87): [Folded, False: 257k]
  |  |  ------------------
  ------------------
  282|   257k|   LTC_ARGCHK(b != NULL);
  ------------------
  |  |   32|   257k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 257k]
  |  |  |  Branch (32:87): [Folded, False: 257k]
  |  |  ------------------
  ------------------
  283|   257k|   return mpi_to_ltc_error(mp_div_2(a, b));
  284|   257k|}
ltm_desc.c:mulmod:
  339|    837|{
  340|    837|   LTC_ARGCHK(a != NULL);
  ------------------
  |  |   32|    837|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 837]
  |  |  |  Branch (32:87): [Folded, False: 837]
  |  |  ------------------
  ------------------
  341|    837|   LTC_ARGCHK(b != NULL);
  ------------------
  |  |   32|    837|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 837]
  |  |  |  Branch (32:87): [Folded, False: 837]
  |  |  ------------------
  ------------------
  342|    837|   LTC_ARGCHK(c != NULL);
  ------------------
  |  |   32|    837|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 837]
  |  |  |  Branch (32:87): [Folded, False: 837]
  |  |  ------------------
  ------------------
  343|    837|   LTC_ARGCHK(d != NULL);
  ------------------
  |  |   32|    837|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 837]
  |  |  |  Branch (32:87): [Folded, False: 837]
  |  |  ------------------
  ------------------
  344|    837|   return mpi_to_ltc_error(mp_mulmod(a,b,c,d));
  345|    837|}
ltm_desc.c:invmod:
  357|    279|{
  358|    279|   LTC_ARGCHK(a != NULL);
  ------------------
  |  |   32|    279|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 279]
  |  |  |  Branch (32:87): [Folded, False: 279]
  |  |  ------------------
  ------------------
  359|    279|   LTC_ARGCHK(b != NULL);
  ------------------
  |  |   32|    279|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 279]
  |  |  |  Branch (32:87): [Folded, False: 279]
  |  |  ------------------
  ------------------
  360|    279|   LTC_ARGCHK(c != NULL);
  ------------------
  |  |   32|    279|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 279]
  |  |  |  Branch (32:87): [Folded, False: 279]
  |  |  ------------------
  ------------------
  361|    279|   return mpi_to_ltc_error(mp_invmod(a, b, c));
  362|    279|}
ltm_desc.c:montgomery_setup:
  366|    279|{
  367|    279|   int err;
  368|    279|   LTC_ARGCHK(a != NULL);
  ------------------
  |  |   32|    279|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 279]
  |  |  |  Branch (32:87): [Folded, False: 279]
  |  |  ------------------
  ------------------
  369|    279|   LTC_ARGCHK(b != NULL);
  ------------------
  |  |   32|    279|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 279]
  |  |  |  Branch (32:87): [Folded, False: 279]
  |  |  ------------------
  ------------------
  370|    279|   *b = XCALLOC(1, sizeof(mp_digit));
  ------------------
  |  |   19|    279|#define XCALLOC m_calloc
  ------------------
  371|    279|   if (*b == NULL) {
  ------------------
  |  Branch (371:8): [True: 0, False: 279]
  ------------------
  372|      0|      return CRYPT_MEM;
  373|      0|   }
  374|    279|   if ((err = mpi_to_ltc_error(mp_montgomery_setup(a, (mp_digit *)*b))) != CRYPT_OK) {
  ------------------
  |  Branch (374:8): [True: 0, False: 279]
  ------------------
  375|      0|      XFREE(*b);
  ------------------
  |  |   17|      0|#define XFREE m_free_direct
  ------------------
  376|      0|   }
  377|    279|   return err;
  378|    279|}
ltm_desc.c:montgomery_normalization:
  382|    279|{
  383|    279|   LTC_ARGCHK(a != NULL);
  ------------------
  |  |   32|    279|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 279]
  |  |  |  Branch (32:87): [Folded, False: 279]
  |  |  ------------------
  ------------------
  384|    279|   LTC_ARGCHK(b != NULL);
  ------------------
  |  |   32|    279|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 279]
  |  |  |  Branch (32:87): [Folded, False: 279]
  |  |  ------------------
  ------------------
  385|    279|   return mpi_to_ltc_error(mp_montgomery_calc_normalization(a, b));
  386|    279|}
ltm_desc.c:montgomery_reduce:
  390|  3.09M|{
  391|  3.09M|   LTC_ARGCHK(a != NULL);
  ------------------
  |  |   32|  3.09M|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 3.09M]
  |  |  |  Branch (32:87): [Folded, False: 3.09M]
  |  |  ------------------
  ------------------
  392|  3.09M|   LTC_ARGCHK(b != NULL);
  ------------------
  |  |   32|  3.09M|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 3.09M]
  |  |  |  Branch (32:87): [Folded, False: 3.09M]
  |  |  ------------------
  ------------------
  393|  3.09M|   LTC_ARGCHK(c != NULL);
  ------------------
  |  |   32|  3.09M|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 3.09M]
  |  |  |  Branch (32:87): [Folded, False: 3.09M]
  |  |  ------------------
  ------------------
  394|  3.09M|   return mpi_to_ltc_error(mp_montgomery_reduce(a, b, *((mp_digit *)c)));
  395|  3.09M|}
ltm_desc.c:montgomery_deinit:
  399|    279|{
  400|    279|   XFREE(a);
  ------------------
  |  |   17|    279|#define XFREE m_free_direct
  ------------------
  401|    279|}

ltc_init_multi:
   15|   259k|{
   16|   259k|   void    **cur = a;
   17|   259k|   int       np  = 0;
   18|   259k|   va_list   args;
   19|       |
   20|   259k|   va_start(args, a);
   21|  1.16M|   while (cur != NULL) {
  ------------------
  |  Branch (21:11): [True: 907k, False: 259k]
  ------------------
   22|   907k|       if (mp_init(cur) != CRYPT_OK) {
  ------------------
  |  |  516|   907k|#define mp_init(a)                   ltc_mp.init(a)
  ------------------
  |  Branch (22:12): [True: 0, False: 907k]
  ------------------
   23|       |          /* failed */
   24|      0|          va_list clean_list;
   25|       |
   26|      0|          va_start(clean_list, a);
   27|      0|          cur = a;
   28|      0|          while (np--) {
  ------------------
  |  Branch (28:18): [True: 0, False: 0]
  ------------------
   29|      0|              mp_clear(*cur);
  ------------------
  |  |  518|      0|#define mp_clear(a)                  ltc_mp.deinit(a)
  ------------------
   30|      0|              cur = va_arg(clean_list, void**);
   31|      0|          }
   32|      0|          va_end(clean_list);
   33|      0|          va_end(args);
   34|      0|          return CRYPT_MEM;
   35|      0|       }
   36|   907k|       ++np;
   37|   907k|       cur = va_arg(args, void**);
   38|   907k|   }
   39|   259k|   va_end(args);
   40|   259k|   return CRYPT_OK;
   41|   259k|}
ltc_deinit_multi:
   44|   259k|{
   45|   259k|   void     *cur = a;
   46|   259k|   va_list   args;
   47|       |
   48|   259k|   va_start(args, a);
   49|  1.16M|   while (cur != NULL) {
  ------------------
  |  Branch (49:11): [True: 906k, False: 259k]
  ------------------
   50|   906k|       mp_clear(cur);
  ------------------
  |  |  518|   906k|#define mp_clear(a)                  ltc_mp.deinit(a)
  ------------------
   51|   906k|       cur = va_arg(args, void *);
   52|   906k|   }
   53|       |   va_end(args);
   54|   259k|}

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

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

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

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

prng_is_valid:
   22|    279|{
   23|    279|   LTC_MUTEX_LOCK(&ltc_prng_mutex);
   24|    279|   if (idx < 0 || idx >= TAB_SIZE || prng_descriptor[idx].name == NULL) {
  ------------------
  |  |   14|    558|#define TAB_SIZE      5
  ------------------
  |  Branch (24:8): [True: 0, False: 279]
  |  Branch (24:19): [True: 0, False: 279]
  |  Branch (24:38): [True: 0, False: 279]
  ------------------
   25|      0|      LTC_MUTEX_UNLOCK(&ltc_prng_mutex);
   26|      0|      return CRYPT_INVALID_PRNG;
   27|      0|   }
   28|    279|   LTC_MUTEX_UNLOCK(&ltc_prng_mutex);
   29|    279|   return CRYPT_OK;
   30|    279|}

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|  24.3k|{
   24|  24.3k|   m_burn((void*)out, outlen);
   25|  24.3k|}

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

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

ecc_make_key_ex:
   49|    279|{
   50|    279|   int            err;
   51|    279|   ecc_point     *base;
   52|    279|   void          *prime, *order;
   53|    279|   unsigned char *buf;
   54|    279|   int            keysize;
   55|       |
   56|    279|   LTC_ARGCHK(key         != NULL);
  ------------------
  |  |   32|    279|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 279]
  |  |  |  Branch (32:87): [Folded, False: 279]
  |  |  ------------------
  ------------------
   57|    279|   LTC_ARGCHK(ltc_mp.name != NULL);
  ------------------
  |  |   32|    279|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 279]
  |  |  |  Branch (32:87): [Folded, False: 279]
  |  |  ------------------
  ------------------
   58|    279|   LTC_ARGCHK(dp          != NULL);
  ------------------
  |  |   32|    279|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 279]
  |  |  |  Branch (32:87): [Folded, False: 279]
  |  |  ------------------
  ------------------
   59|       |
   60|       |   /* good prng? */
   61|    279|   if ((err = prng_is_valid(wprng)) != CRYPT_OK) {
  ------------------
  |  Branch (61:8): [True: 0, False: 279]
  ------------------
   62|      0|      return err;
   63|      0|   }
   64|       |
   65|    279|   key->idx = -1;
   66|    279|   key->dp  = dp;
   67|    279|   keysize  = dp->size;
   68|       |
   69|       |   /* allocate ram */
   70|    279|   base = NULL;
   71|    279|   buf  = XMALLOC(ECC_MAXSIZE);
  ------------------
  |  |   16|    279|#define XMALLOC m_malloc
  ------------------
                 buf  = XMALLOC(ECC_MAXSIZE);
  ------------------
  |  |  249|    279|#define ECC_MAXSIZE  66
  ------------------
   72|    279|   if (buf == NULL) {
  ------------------
  |  Branch (72:8): [True: 0, False: 279]
  ------------------
   73|      0|      return CRYPT_MEM;
   74|      0|   }
   75|       |
   76|       |   /* make up random string */
   77|    279|   if (prng_descriptor[wprng].read(buf, (unsigned long)keysize, prng) != (unsigned long)keysize) {
  ------------------
  |  Branch (77:8): [True: 0, False: 279]
  ------------------
   78|      0|      err = CRYPT_ERROR_READPRNG;
   79|      0|      goto ERR_BUF;
   80|      0|   }
   81|       |
   82|       |   /* setup the key variables */
   83|    279|   if ((err = mp_init_multi(&key->pubkey.x, &key->pubkey.y, &key->pubkey.z, &key->k, &prime, &order, NULL)) != CRYPT_OK) {
  ------------------
  |  |  517|    279|#define mp_init_multi                ltc_init_multi
  ------------------
  |  Branch (83:8): [True: 0, False: 279]
  ------------------
   84|      0|      goto ERR_BUF;
   85|      0|   }
   86|    279|   base = ltc_ecc_new_point();
   87|    279|   if (base == NULL) {
  ------------------
  |  Branch (87:8): [True: 0, False: 279]
  ------------------
   88|      0|      err = CRYPT_MEM;
   89|      0|      goto errkey;
   90|      0|   }
   91|       |
   92|       |   /* read in the specs for this key */
   93|    279|   if ((err = mp_read_radix(prime,   (char *)key->dp->prime, 16)) != CRYPT_OK)                  { goto errkey; }
  ------------------
  |  |  537|    279|#define mp_read_radix(a, b, c)       ltc_mp.read_radix(a, b, c)
  ------------------
  |  Branch (93:8): [True: 0, False: 279]
  ------------------
   94|    279|   if ((err = mp_read_radix(order,   (char *)key->dp->order, 16)) != CRYPT_OK)                  { goto errkey; }
  ------------------
  |  |  537|    279|#define mp_read_radix(a, b, c)       ltc_mp.read_radix(a, b, c)
  ------------------
  |  Branch (94:8): [True: 0, False: 279]
  ------------------
   95|    279|   if ((err = mp_read_radix(base->x, (char *)key->dp->Gx, 16)) != CRYPT_OK)                     { goto errkey; }
  ------------------
  |  |  537|    279|#define mp_read_radix(a, b, c)       ltc_mp.read_radix(a, b, c)
  ------------------
  |  Branch (95:8): [True: 0, False: 279]
  ------------------
   96|    279|   if ((err = mp_read_radix(base->y, (char *)key->dp->Gy, 16)) != CRYPT_OK)                     { goto errkey; }
  ------------------
  |  |  537|    279|#define mp_read_radix(a, b, c)       ltc_mp.read_radix(a, b, c)
  ------------------
  |  Branch (96:8): [True: 0, False: 279]
  ------------------
   97|    279|   if ((err = mp_set(base->z, 1)) != CRYPT_OK)                                                  { goto errkey; }
  ------------------
  |  |  526|    279|#define mp_set(a, b)                 ltc_mp.set_int(a, b)
  ------------------
  |  Branch (97:8): [True: 0, False: 279]
  ------------------
   98|    279|   if ((err = mp_read_unsigned_bin(key->k, (unsigned char *)buf, keysize)) != CRYPT_OK)         { goto errkey; }
  ------------------
  |  |  541|    279|#define mp_read_unsigned_bin(a, b, c) ltc_mp.unsigned_read(a, b, c)
  ------------------
  |  Branch (98:8): [True: 0, False: 279]
  ------------------
   99|       |
  100|       |   /* the key should be smaller than the order of base point */
  101|    279|   if (mp_cmp(key->k, order) != LTC_MP_LT) {
  ------------------
  |  |  531|    279|#define mp_cmp(a, b)                 ltc_mp.compare(a, b)
  ------------------
                 if (mp_cmp(key->k, order) != LTC_MP_LT) {
  ------------------
  |  |   12|    279|#define LTC_MP_LT   -1
  ------------------
  |  Branch (101:8): [True: 153, False: 126]
  ------------------
  102|    153|       if((err = mp_mod(key->k, order, key->k)) != CRYPT_OK)                                    { goto errkey; }
  ------------------
  |  |  552|    153|#define mp_mod(a, b, c)              ltc_mp.mpdiv(a, b, NULL, c)
  ------------------
  |  Branch (102:11): [True: 0, False: 153]
  ------------------
  103|    153|   }
  104|       |   /* make the public key */
  105|    279|   if ((err = ltc_mp.ecc_ptmul(key->k, base, &key->pubkey, prime, 1)) != CRYPT_OK)              { goto errkey; }
  ------------------
  |  Branch (105:8): [True: 0, False: 279]
  ------------------
  106|    279|   key->type = PK_PRIVATE;
  107|       |
  108|       |   /* free up ram */
  109|    279|   err = CRYPT_OK;
  110|    279|   goto cleanup;
  111|      0|errkey:
  112|      0|   mp_clear_multi(key->pubkey.x, key->pubkey.y, key->pubkey.z, key->k, NULL);
  ------------------
  |  |  519|      0|#define mp_clear_multi               ltc_deinit_multi
  ------------------
  113|    279|cleanup:
  114|    279|   ltc_ecc_del_point(base);
  115|    279|   mp_clear_multi(prime, order, NULL);
  ------------------
  |  |  519|    279|#define mp_clear_multi               ltc_deinit_multi
  ------------------
  116|    279|ERR_BUF:
  117|       |#ifdef LTC_CLEAN_STACK
  118|       |   zeromem(buf, ECC_MAXSIZE);
  119|       |#endif
  120|    279|   XFREE(buf);
  ------------------
  |  |   17|    279|#define XFREE m_free_direct
  ------------------
  121|    279|   return err;
  122|    279|}

ltc_ecc_map:
   32|    279|{
   33|    279|   void *t1, *t2;
   34|    279|   int   err;
   35|       |
   36|    279|   LTC_ARGCHK(P       != NULL);
  ------------------
  |  |   32|    279|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 279]
  |  |  |  Branch (32:87): [Folded, False: 279]
  |  |  ------------------
  ------------------
   37|    279|   LTC_ARGCHK(modulus != NULL);
  ------------------
  |  |   32|    279|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 279]
  |  |  |  Branch (32:87): [Folded, False: 279]
  |  |  ------------------
  ------------------
   38|    279|   LTC_ARGCHK(mp      != NULL);
  ------------------
  |  |   32|    279|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 279]
  |  |  |  Branch (32:87): [Folded, False: 279]
  |  |  ------------------
  ------------------
   39|       |
   40|    279|   if ((err = mp_init_multi(&t1, &t2, NULL)) != CRYPT_OK) {
  ------------------
  |  |  517|    279|#define mp_init_multi                ltc_init_multi
  ------------------
  |  Branch (40:8): [True: 0, False: 279]
  ------------------
   41|      0|      return err;
   42|      0|   }
   43|       |
   44|       |   /* first map z back to normal */
   45|    279|   if ((err = mp_montgomery_reduce(P->z, modulus, mp)) != CRYPT_OK)           { goto done; }
  ------------------
  |  |  565|    279|#define mp_montgomery_reduce(a, b, c)   ltc_mp.montgomery_reduce(a, b, c)
  ------------------
  |  Branch (45:8): [True: 0, False: 279]
  ------------------
   46|       |
   47|       |   /* get 1/z */
   48|    279|   if ((err = mp_invmod(P->z, modulus, t1)) != CRYPT_OK)                      { goto done; }
  ------------------
  |  |  561|    279|#define mp_invmod(a, b, c)           ltc_mp.invmod(a, b, c)
  ------------------
  |  Branch (48:8): [True: 0, False: 279]
  ------------------
   49|       |
   50|       |   /* get 1/z^2 and 1/z^3 */
   51|    279|   if ((err = mp_sqr(t1, t2)) != CRYPT_OK)                                    { goto done; }
  ------------------
  |  |  549|    279|#define mp_sqr(a, b)                 ltc_mp.sqr(a, b)
  ------------------
  |  Branch (51:8): [True: 0, False: 279]
  ------------------
   52|    279|   if ((err = mp_mod(t2, modulus, t2)) != CRYPT_OK)                           { goto done; }
  ------------------
  |  |  552|    279|#define mp_mod(a, b, c)              ltc_mp.mpdiv(a, b, NULL, c)
  ------------------
  |  Branch (52:8): [True: 0, False: 279]
  ------------------
   53|    279|   if ((err = mp_mul(t1, t2, t1)) != CRYPT_OK)                                { goto done; }
  ------------------
  |  |  547|    279|#define mp_mul(a, b, c)              ltc_mp.mul(a, b, c)
  ------------------
  |  Branch (53:8): [True: 0, False: 279]
  ------------------
   54|    279|   if ((err = mp_mod(t1, modulus, t1)) != CRYPT_OK)                           { goto done; }
  ------------------
  |  |  552|    279|#define mp_mod(a, b, c)              ltc_mp.mpdiv(a, b, NULL, c)
  ------------------
  |  Branch (54:8): [True: 0, False: 279]
  ------------------
   55|       |
   56|       |   /* multiply against x/y */
   57|    279|   if ((err = mp_mul(P->x, t2, P->x)) != CRYPT_OK)                            { goto done; }
  ------------------
  |  |  547|    279|#define mp_mul(a, b, c)              ltc_mp.mul(a, b, c)
  ------------------
  |  Branch (57:8): [True: 0, False: 279]
  ------------------
   58|    279|   if ((err = mp_montgomery_reduce(P->x, modulus, mp)) != CRYPT_OK)           { goto done; }
  ------------------
  |  |  565|    279|#define mp_montgomery_reduce(a, b, c)   ltc_mp.montgomery_reduce(a, b, c)
  ------------------
  |  Branch (58:8): [True: 0, False: 279]
  ------------------
   59|    279|   if ((err = mp_mul(P->y, t1, P->y)) != CRYPT_OK)                            { goto done; }
  ------------------
  |  |  547|    279|#define mp_mul(a, b, c)              ltc_mp.mul(a, b, c)
  ------------------
  |  Branch (59:8): [True: 0, False: 279]
  ------------------
   60|    279|   if ((err = mp_montgomery_reduce(P->y, modulus, mp)) != CRYPT_OK)           { goto done; }
  ------------------
  |  |  565|    279|#define mp_montgomery_reduce(a, b, c)   ltc_mp.montgomery_reduce(a, b, c)
  ------------------
  |  Branch (60:8): [True: 0, False: 279]
  ------------------
   61|    279|   if ((err = mp_set(P->z, 1)) != CRYPT_OK)                                   { goto done; }
  ------------------
  |  |  526|    279|#define mp_set(a, b)                 ltc_mp.set_int(a, b)
  ------------------
  |  Branch (61:8): [True: 0, False: 279]
  ------------------
   62|       |
   63|    279|   err = CRYPT_OK;
   64|    279|done:
   65|    279|   mp_clear_multi(t1, t2, NULL);
  ------------------
  |  |  519|    279|#define mp_clear_multi               ltc_deinit_multi
  ------------------
   66|    279|   return err;
   67|    279|}

ltc_ecc_mulmod:
   36|    279|{
   37|    279|   ecc_point *tG, *M[3];
   38|    279|   int        i, j, err;
   39|    279|   void       *mu, *mp;
   40|    279|   ltc_mp_digit buf;
   41|    279|   int        bitcnt, mode, digidx;
   42|       |
   43|    279|   LTC_ARGCHK(k       != NULL);
  ------------------
  |  |   32|    279|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 279]
  |  |  |  Branch (32:87): [Folded, False: 279]
  |  |  ------------------
  ------------------
   44|    279|   LTC_ARGCHK(G       != NULL);
  ------------------
  |  |   32|    279|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 279]
  |  |  |  Branch (32:87): [Folded, False: 279]
  |  |  ------------------
  ------------------
   45|    279|   LTC_ARGCHK(R       != NULL);
  ------------------
  |  |   32|    279|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 279]
  |  |  |  Branch (32:87): [Folded, False: 279]
  |  |  ------------------
  ------------------
   46|    279|   LTC_ARGCHK(modulus != NULL);
  ------------------
  |  |   32|    279|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 279]
  |  |  |  Branch (32:87): [Folded, False: 279]
  |  |  ------------------
  ------------------
   47|       |
   48|       |   /* init montgomery reduction */
   49|    279|   if ((err = mp_montgomery_setup(modulus, &mp)) != CRYPT_OK) {
  ------------------
  |  |  563|    279|#define mp_montgomery_setup(a, b)    ltc_mp.montgomery_setup(a, b)
  ------------------
  |  Branch (49:8): [True: 0, False: 279]
  ------------------
   50|      0|      return err;
   51|      0|   }
   52|    279|   if ((err = mp_init(&mu)) != CRYPT_OK) {
  ------------------
  |  |  516|    279|#define mp_init(a)                   ltc_mp.init(a)
  ------------------
  |  Branch (52:8): [True: 0, False: 279]
  ------------------
   53|      0|      mp_montgomery_free(mp);
  ------------------
  |  |  566|      0|#define mp_montgomery_free(a)        ltc_mp.montgomery_deinit(a)
  ------------------
   54|      0|      return err;
   55|      0|   }
   56|    279|   if ((err = mp_montgomery_normalization(mu, modulus)) != CRYPT_OK) {
  ------------------
  |  |  564|    279|#define mp_montgomery_normalization(a, b) ltc_mp.montgomery_normalization(a, b)
  ------------------
  |  Branch (56:8): [True: 0, False: 279]
  ------------------
   57|      0|      mp_clear(mu);
  ------------------
  |  |  518|      0|#define mp_clear(a)                  ltc_mp.deinit(a)
  ------------------
   58|      0|      mp_montgomery_free(mp);
  ------------------
  |  |  566|      0|#define mp_montgomery_free(a)        ltc_mp.montgomery_deinit(a)
  ------------------
   59|      0|      return err;
   60|      0|   }
   61|       |
   62|       |   /* alloc ram for window temps */
   63|  1.11k|   for (i = 0; i < 3; i++) {
  ------------------
  |  Branch (63:16): [True: 837, False: 279]
  ------------------
   64|    837|      M[i] = ltc_ecc_new_point();
   65|    837|      if (M[i] == NULL) {
  ------------------
  |  Branch (65:11): [True: 0, False: 837]
  ------------------
   66|      0|         for (j = 0; j < i; j++) {
  ------------------
  |  Branch (66:22): [True: 0, False: 0]
  ------------------
   67|      0|             ltc_ecc_del_point(M[j]);
   68|      0|         }
   69|      0|         mp_clear(mu);
  ------------------
  |  |  518|      0|#define mp_clear(a)                  ltc_mp.deinit(a)
  ------------------
   70|      0|         mp_montgomery_free(mp);
  ------------------
  |  |  566|      0|#define mp_montgomery_free(a)        ltc_mp.montgomery_deinit(a)
  ------------------
   71|      0|         return CRYPT_MEM;
   72|      0|      }
   73|    837|   }
   74|       |
   75|       |   /* make a copy of G incase R==G */
   76|    279|   tG = ltc_ecc_new_point();
   77|    279|   if (tG == NULL)                                                                   { err = CRYPT_MEM; goto done; }
  ------------------
  |  Branch (77:8): [True: 0, False: 279]
  ------------------
   78|       |
   79|       |   /* tG = G  and convert to montgomery */
   80|    279|   if ((err = mp_mulmod(G->x, mu, modulus, tG->x)) != CRYPT_OK)                      { goto done; }
  ------------------
  |  |  559|    279|#define mp_mulmod(a, b, c, d)        ltc_mp.mulmod(a, b, c, d)
  ------------------
  |  Branch (80:8): [True: 0, False: 279]
  ------------------
   81|    279|   if ((err = mp_mulmod(G->y, mu, modulus, tG->y)) != CRYPT_OK)                      { goto done; }
  ------------------
  |  |  559|    279|#define mp_mulmod(a, b, c, d)        ltc_mp.mulmod(a, b, c, d)
  ------------------
  |  Branch (81:8): [True: 0, False: 279]
  ------------------
   82|    279|   if ((err = mp_mulmod(G->z, mu, modulus, tG->z)) != CRYPT_OK)                      { goto done; }
  ------------------
  |  |  559|    279|#define mp_mulmod(a, b, c, d)        ltc_mp.mulmod(a, b, c, d)
  ------------------
  |  Branch (82:8): [True: 0, False: 279]
  ------------------
   83|    279|   mp_clear(mu);
  ------------------
  |  |  518|    279|#define mp_clear(a)                  ltc_mp.deinit(a)
  ------------------
   84|    279|   mu = NULL;
   85|       |
   86|       |   /* calc the M tab */
   87|       |   /* M[0] == G */
   88|    279|   if ((err = mp_copy(tG->x, M[0]->x)) != CRYPT_OK)                                  { goto done; }
  ------------------
  |  |  524|    279|#define mp_copy(a, b)                ltc_mp.copy(a, b)
  ------------------
  |  Branch (88:8): [True: 0, False: 279]
  ------------------
   89|    279|   if ((err = mp_copy(tG->y, M[0]->y)) != CRYPT_OK)                                  { goto done; }
  ------------------
  |  |  524|    279|#define mp_copy(a, b)                ltc_mp.copy(a, b)
  ------------------
  |  Branch (89:8): [True: 0, False: 279]
  ------------------
   90|    279|   if ((err = mp_copy(tG->z, M[0]->z)) != CRYPT_OK)                                  { goto done; }
  ------------------
  |  |  524|    279|#define mp_copy(a, b)                ltc_mp.copy(a, b)
  ------------------
  |  Branch (90:8): [True: 0, False: 279]
  ------------------
   91|       |   /* M[1] == 2G */
   92|    279|   if ((err = ltc_mp.ecc_ptdbl(tG, M[1], modulus, mp)) != CRYPT_OK)                  { goto done; }
  ------------------
  |  Branch (92:8): [True: 0, False: 279]
  ------------------
   93|       |
   94|       |   /* setup sliding window */
   95|    279|   mode   = 0;
   96|    279|   bitcnt = 1;
   97|    279|   buf    = 0;
   98|    279|   digidx = mp_get_digit_count(k) - 1;
  ------------------
  |  |  530|    279|#define mp_get_digit_count(a)        ltc_mp.get_digit_count(a)
  ------------------
   99|       |
  100|       |   /* perform ops */
  101|   128k|   for (;;) {
  102|       |     /* grab next digit as required */
  103|   128k|      if (--bitcnt == 0) {
  ------------------
  |  Branch (103:11): [True: 2.42k, False: 126k]
  ------------------
  104|  2.42k|         if (digidx == -1) {
  ------------------
  |  Branch (104:14): [True: 279, False: 2.14k]
  ------------------
  105|    279|            break;
  106|    279|         }
  107|  2.14k|         buf    = mp_get_digit(k, digidx);
  ------------------
  |  |  529|  2.14k|#define mp_get_digit(a, n)           ltc_mp.get_digit(a, n)
  ------------------
  108|  2.14k|         bitcnt = (int) MP_DIGIT_BIT;
  ------------------
  |  |  513|  2.14k|#define MP_DIGIT_BIT                 ltc_mp.bits_per_digit
  ------------------
  109|  2.14k|         --digidx;
  110|  2.14k|      }
  111|       |
  112|       |      /* grab the next msb from the ltiplicand */
  113|   128k|      i = (buf >> (MP_DIGIT_BIT - 1)) & 1;
  ------------------
  |  |  513|   128k|#define MP_DIGIT_BIT                 ltc_mp.bits_per_digit
  ------------------
  114|   128k|      buf <<= 1;
  115|       |
  116|   128k|      if (mode == 0 && i == 0) {
  ------------------
  |  Branch (116:11): [True: 8.50k, False: 120k]
  |  Branch (116:24): [True: 8.22k, False: 279]
  ------------------
  117|       |         /* dummy operations */
  118|  8.22k|         if ((err = ltc_mp.ecc_ptadd(M[0], M[1], M[2], modulus, mp)) != CRYPT_OK)    { goto done; }
  ------------------
  |  Branch (118:14): [True: 0, False: 8.22k]
  ------------------
  119|  8.22k|         if ((err = ltc_mp.ecc_ptdbl(M[1], M[2], modulus, mp)) != CRYPT_OK)          { goto done; }
  ------------------
  |  Branch (119:14): [True: 0, False: 8.22k]
  ------------------
  120|  8.22k|         continue;
  121|  8.22k|      }
  122|       |
  123|   120k|      if (mode == 0 && i == 1) {
  ------------------
  |  Branch (123:11): [True: 279, False: 120k]
  |  Branch (123:24): [True: 279, False: 0]
  ------------------
  124|    279|         mode = 1;
  125|       |         /* dummy operations */
  126|    279|         if ((err = ltc_mp.ecc_ptadd(M[0], M[1], M[2], modulus, mp)) != CRYPT_OK)    { goto done; }
  ------------------
  |  Branch (126:14): [True: 0, False: 279]
  ------------------
  127|    279|         if ((err = ltc_mp.ecc_ptdbl(M[1], M[2], modulus, mp)) != CRYPT_OK)          { goto done; }
  ------------------
  |  Branch (127:14): [True: 0, False: 279]
  ------------------
  128|    279|         continue;
  129|    279|      }
  130|       |
  131|   120k|      if ((err = ltc_mp.ecc_ptadd(M[0], M[1], M[i^1], modulus, mp)) != CRYPT_OK)     { goto done; }
  ------------------
  |  Branch (131:11): [True: 0, False: 120k]
  ------------------
  132|   120k|      if ((err = ltc_mp.ecc_ptdbl(M[i], M[i], modulus, mp)) != CRYPT_OK)             { goto done; }
  ------------------
  |  Branch (132:11): [True: 0, False: 120k]
  ------------------
  133|   120k|   }
  134|       |
  135|       |   /* copy result out */
  136|    279|   if ((err = mp_copy(M[0]->x, R->x)) != CRYPT_OK)                                   { goto done; }
  ------------------
  |  |  524|    279|#define mp_copy(a, b)                ltc_mp.copy(a, b)
  ------------------
  |  Branch (136:8): [True: 0, False: 279]
  ------------------
  137|    279|   if ((err = mp_copy(M[0]->y, R->y)) != CRYPT_OK)                                   { goto done; }
  ------------------
  |  |  524|    279|#define mp_copy(a, b)                ltc_mp.copy(a, b)
  ------------------
  |  Branch (137:8): [True: 0, False: 279]
  ------------------
  138|    279|   if ((err = mp_copy(M[0]->z, R->z)) != CRYPT_OK)                                   { goto done; }
  ------------------
  |  |  524|    279|#define mp_copy(a, b)                ltc_mp.copy(a, b)
  ------------------
  |  Branch (138:8): [True: 0, False: 279]
  ------------------
  139|       |
  140|       |   /* map R back from projective space */
  141|    279|   if (map) {
  ------------------
  |  Branch (141:8): [True: 279, False: 0]
  ------------------
  142|    279|      err = ltc_ecc_map(R, modulus, mp);
  143|    279|   } else {
  144|      0|      err = CRYPT_OK;
  145|      0|   }
  146|    279|done:
  147|    279|   if (mu != NULL) {
  ------------------
  |  Branch (147:8): [True: 0, False: 279]
  ------------------
  148|      0|      mp_clear(mu);
  ------------------
  |  |  518|      0|#define mp_clear(a)                  ltc_mp.deinit(a)
  ------------------
  149|      0|   }
  150|    279|   mp_montgomery_free(mp);
  ------------------
  |  |  566|    279|#define mp_montgomery_free(a)        ltc_mp.montgomery_deinit(a)
  ------------------
  151|    279|   ltc_ecc_del_point(tG);
  152|  1.11k|   for (i = 0; i < 3; i++) {
  ------------------
  |  Branch (152:16): [True: 837, False: 279]
  ------------------
  153|    837|       ltc_ecc_del_point(M[i]);
  154|    837|   }
  155|    279|   return err;
  156|    279|}

ltc_ecc_new_point:
   29|  1.39k|{
   30|  1.39k|   ecc_point *p;
   31|  1.39k|   p = XCALLOC(1, sizeof(*p));
  ------------------
  |  |   19|  1.39k|#define XCALLOC m_calloc
  ------------------
   32|  1.39k|   if (p == NULL) {
  ------------------
  |  Branch (32:8): [True: 0, False: 1.39k]
  ------------------
   33|      0|      return NULL;
   34|      0|   }
   35|  1.39k|   if (mp_init_multi(&p->x, &p->y, &p->z, NULL) != CRYPT_OK) {
  ------------------
  |  |  517|  1.39k|#define mp_init_multi                ltc_init_multi
  ------------------
  |  Branch (35:8): [True: 0, False: 1.39k]
  ------------------
   36|      0|      XFREE(p);
  ------------------
  |  |   17|      0|#define XFREE m_free_direct
  ------------------
   37|      0|      return NULL;
   38|      0|   }
   39|  1.39k|   return p;
   40|  1.39k|}
ltc_ecc_del_point:
   46|  1.39k|{
   47|       |   /* prevents free'ing null arguments */
   48|  1.39k|   if (p != NULL) {
  ------------------
  |  Branch (48:8): [True: 1.39k, False: 0]
  ------------------
   49|  1.39k|      mp_clear_multi(p->x, p->y, p->z, NULL); /* note: p->z may be NULL but that's ok with this function anyways */
  ------------------
  |  |  519|  1.39k|#define mp_clear_multi               ltc_deinit_multi
  ------------------
   50|  1.39k|      XFREE(p);
  ------------------
  |  |   17|  1.39k|#define XFREE m_free_direct
  ------------------
   51|  1.39k|   }
   52|  1.39k|}

ltc_ecc_projective_add_point:
   34|   128k|{
   35|   128k|   void  *t1, *t2, *x, *y, *z;
   36|   128k|   int    err;
   37|       |
   38|   128k|   LTC_ARGCHK(P       != NULL);
  ------------------
  |  |   32|   128k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 128k]
  |  |  |  Branch (32:87): [Folded, False: 128k]
  |  |  ------------------
  ------------------
   39|   128k|   LTC_ARGCHK(Q       != NULL);
  ------------------
  |  |   32|   128k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 128k]
  |  |  |  Branch (32:87): [Folded, False: 128k]
  |  |  ------------------
  ------------------
   40|   128k|   LTC_ARGCHK(R       != NULL);
  ------------------
  |  |   32|   128k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 128k]
  |  |  |  Branch (32:87): [Folded, False: 128k]
  |  |  ------------------
  ------------------
   41|   128k|   LTC_ARGCHK(modulus != NULL);
  ------------------
  |  |   32|   128k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 128k]
  |  |  |  Branch (32:87): [Folded, False: 128k]
  |  |  ------------------
  ------------------
   42|   128k|   LTC_ARGCHK(mp      != NULL);
  ------------------
  |  |   32|   128k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 128k]
  |  |  |  Branch (32:87): [Folded, False: 128k]
  |  |  ------------------
  ------------------
   43|       |
   44|   128k|   if ((err = mp_init_multi(&t1, &t2, &x, &y, &z, NULL)) != CRYPT_OK) {
  ------------------
  |  |  517|   128k|#define mp_init_multi                ltc_init_multi
  ------------------
  |  Branch (44:8): [True: 0, False: 128k]
  ------------------
   45|      0|      return err;
   46|      0|   }
   47|       |
   48|       |   /* should we dbl instead? */
   49|   128k|   if ((err = mp_sub(modulus, Q->y, t1)) != CRYPT_OK)                          { goto done; }
  ------------------
  |  |  545|   128k|#define mp_sub(a, b, c)              ltc_mp.sub(a, b, c)
  ------------------
  |  Branch (49:8): [True: 0, False: 128k]
  ------------------
   50|       |
   51|   128k|   if ( (mp_cmp(P->x, Q->x) == LTC_MP_EQ) &&
  ------------------
  |  |  531|   128k|#define mp_cmp(a, b)                 ltc_mp.compare(a, b)
  ------------------
                 if ( (mp_cmp(P->x, Q->x) == LTC_MP_EQ) &&
  ------------------
  |  |   13|   128k|#define LTC_MP_EQ    0
  ------------------
  |  Branch (51:9): [True: 0, False: 128k]
  ------------------
   52|      0|        (Q->z != NULL && mp_cmp(P->z, Q->z) == LTC_MP_EQ) &&
  ------------------
  |  |  531|      0|#define mp_cmp(a, b)                 ltc_mp.compare(a, b)
  ------------------
                      (Q->z != NULL && mp_cmp(P->z, Q->z) == LTC_MP_EQ) &&
  ------------------
  |  |   13|      0|#define LTC_MP_EQ    0
  ------------------
  |  Branch (52:10): [True: 0, False: 0]
  |  Branch (52:26): [True: 0, False: 0]
  ------------------
   53|      0|        (mp_cmp(P->y, Q->y) == LTC_MP_EQ || mp_cmp(P->y, t1) == LTC_MP_EQ)) {
  ------------------
  |  |  531|      0|#define mp_cmp(a, b)                 ltc_mp.compare(a, b)
  ------------------
                      (mp_cmp(P->y, Q->y) == LTC_MP_EQ || mp_cmp(P->y, t1) == LTC_MP_EQ)) {
  ------------------
  |  |   13|      0|#define LTC_MP_EQ    0
  ------------------
                      (mp_cmp(P->y, Q->y) == LTC_MP_EQ || mp_cmp(P->y, t1) == LTC_MP_EQ)) {
  ------------------
  |  |  531|      0|#define mp_cmp(a, b)                 ltc_mp.compare(a, b)
  ------------------
                      (mp_cmp(P->y, Q->y) == LTC_MP_EQ || mp_cmp(P->y, t1) == LTC_MP_EQ)) {
  ------------------
  |  |   13|      0|#define LTC_MP_EQ    0
  ------------------
  |  Branch (53:10): [True: 0, False: 0]
  |  Branch (53:45): [True: 0, False: 0]
  ------------------
   54|      0|        mp_clear_multi(t1, t2, x, y, z, NULL);
  ------------------
  |  |  519|      0|#define mp_clear_multi               ltc_deinit_multi
  ------------------
   55|      0|        return ltc_ecc_projective_dbl_point(P, R, modulus, mp);
   56|      0|   }
   57|       |
   58|   128k|   if ((err = mp_copy(P->x, x)) != CRYPT_OK)                                   { goto done; }
  ------------------
  |  |  524|   128k|#define mp_copy(a, b)                ltc_mp.copy(a, b)
  ------------------
  |  Branch (58:8): [True: 0, False: 128k]
  ------------------
   59|   128k|   if ((err = mp_copy(P->y, y)) != CRYPT_OK)                                   { goto done; }
  ------------------
  |  |  524|   128k|#define mp_copy(a, b)                ltc_mp.copy(a, b)
  ------------------
  |  Branch (59:8): [True: 0, False: 128k]
  ------------------
   60|   128k|   if ((err = mp_copy(P->z, z)) != CRYPT_OK)                                   { goto done; }
  ------------------
  |  |  524|   128k|#define mp_copy(a, b)                ltc_mp.copy(a, b)
  ------------------
  |  Branch (60:8): [True: 0, False: 128k]
  ------------------
   61|       |
   62|       |   /* if Z is one then these are no-operations */
   63|   128k|   if (Q->z != NULL) {
  ------------------
  |  Branch (63:8): [True: 128k, False: 0]
  ------------------
   64|       |      /* T1 = Z' * Z' */
   65|   128k|      if ((err = mp_sqr(Q->z, t1)) != CRYPT_OK)                                { goto done; }
  ------------------
  |  |  549|   128k|#define mp_sqr(a, b)                 ltc_mp.sqr(a, b)
  ------------------
  |  Branch (65:11): [True: 0, False: 128k]
  ------------------
   66|   128k|      if ((err = mp_montgomery_reduce(t1, modulus, mp)) != CRYPT_OK)           { goto done; }
  ------------------
  |  |  565|   128k|#define mp_montgomery_reduce(a, b, c)   ltc_mp.montgomery_reduce(a, b, c)
  ------------------
  |  Branch (66:11): [True: 0, False: 128k]
  ------------------
   67|       |      /* X = X * T1 */
   68|   128k|      if ((err = mp_mul(t1, x, x)) != CRYPT_OK)                                { goto done; }
  ------------------
  |  |  547|   128k|#define mp_mul(a, b, c)              ltc_mp.mul(a, b, c)
  ------------------
  |  Branch (68:11): [True: 0, False: 128k]
  ------------------
   69|   128k|      if ((err = mp_montgomery_reduce(x, modulus, mp)) != CRYPT_OK)            { goto done; }
  ------------------
  |  |  565|   128k|#define mp_montgomery_reduce(a, b, c)   ltc_mp.montgomery_reduce(a, b, c)
  ------------------
  |  Branch (69:11): [True: 0, False: 128k]
  ------------------
   70|       |      /* T1 = Z' * T1 */
   71|   128k|      if ((err = mp_mul(Q->z, t1, t1)) != CRYPT_OK)                            { goto done; }
  ------------------
  |  |  547|   128k|#define mp_mul(a, b, c)              ltc_mp.mul(a, b, c)
  ------------------
  |  Branch (71:11): [True: 0, False: 128k]
  ------------------
   72|   128k|      if ((err = mp_montgomery_reduce(t1, modulus, mp)) != CRYPT_OK)           { goto done; }
  ------------------
  |  |  565|   128k|#define mp_montgomery_reduce(a, b, c)   ltc_mp.montgomery_reduce(a, b, c)
  ------------------
  |  Branch (72:11): [True: 0, False: 128k]
  ------------------
   73|       |      /* Y = Y * T1 */
   74|   128k|      if ((err = mp_mul(t1, y, y)) != CRYPT_OK)                                { goto done; }
  ------------------
  |  |  547|   128k|#define mp_mul(a, b, c)              ltc_mp.mul(a, b, c)
  ------------------
  |  Branch (74:11): [True: 0, False: 128k]
  ------------------
   75|   128k|      if ((err = mp_montgomery_reduce(y, modulus, mp)) != CRYPT_OK)            { goto done; }
  ------------------
  |  |  565|   128k|#define mp_montgomery_reduce(a, b, c)   ltc_mp.montgomery_reduce(a, b, c)
  ------------------
  |  Branch (75:11): [True: 0, False: 128k]
  ------------------
   76|   128k|   }
   77|       |
   78|       |   /* T1 = Z*Z */
   79|   128k|   if ((err = mp_sqr(z, t1)) != CRYPT_OK)                                      { goto done; }
  ------------------
  |  |  549|   128k|#define mp_sqr(a, b)                 ltc_mp.sqr(a, b)
  ------------------
  |  Branch (79:8): [True: 0, False: 128k]
  ------------------
   80|   128k|   if ((err = mp_montgomery_reduce(t1, modulus, mp)) != CRYPT_OK)              { goto done; }
  ------------------
  |  |  565|   128k|#define mp_montgomery_reduce(a, b, c)   ltc_mp.montgomery_reduce(a, b, c)
  ------------------
  |  Branch (80:8): [True: 0, False: 128k]
  ------------------
   81|       |   /* T2 = X' * T1 */
   82|   128k|   if ((err = mp_mul(Q->x, t1, t2)) != CRYPT_OK)                               { goto done; }
  ------------------
  |  |  547|   128k|#define mp_mul(a, b, c)              ltc_mp.mul(a, b, c)
  ------------------
  |  Branch (82:8): [True: 0, False: 128k]
  ------------------
   83|   128k|   if ((err = mp_montgomery_reduce(t2, modulus, mp)) != CRYPT_OK)              { goto done; }
  ------------------
  |  |  565|   128k|#define mp_montgomery_reduce(a, b, c)   ltc_mp.montgomery_reduce(a, b, c)
  ------------------
  |  Branch (83:8): [True: 0, False: 128k]
  ------------------
   84|       |   /* T1 = Z * T1 */
   85|   128k|   if ((err = mp_mul(z, t1, t1)) != CRYPT_OK)                                  { goto done; }
  ------------------
  |  |  547|   128k|#define mp_mul(a, b, c)              ltc_mp.mul(a, b, c)
  ------------------
  |  Branch (85:8): [True: 0, False: 128k]
  ------------------
   86|   128k|   if ((err = mp_montgomery_reduce(t1, modulus, mp)) != CRYPT_OK)              { goto done; }
  ------------------
  |  |  565|   128k|#define mp_montgomery_reduce(a, b, c)   ltc_mp.montgomery_reduce(a, b, c)
  ------------------
  |  Branch (86:8): [True: 0, False: 128k]
  ------------------
   87|       |   /* T1 = Y' * T1 */
   88|   128k|   if ((err = mp_mul(Q->y, t1, t1)) != CRYPT_OK)                               { goto done; }
  ------------------
  |  |  547|   128k|#define mp_mul(a, b, c)              ltc_mp.mul(a, b, c)
  ------------------
  |  Branch (88:8): [True: 0, False: 128k]
  ------------------
   89|   128k|   if ((err = mp_montgomery_reduce(t1, modulus, mp)) != CRYPT_OK)              { goto done; }
  ------------------
  |  |  565|   128k|#define mp_montgomery_reduce(a, b, c)   ltc_mp.montgomery_reduce(a, b, c)
  ------------------
  |  Branch (89:8): [True: 0, False: 128k]
  ------------------
   90|       |
   91|       |   /* Y = Y - T1 */
   92|   128k|   if ((err = mp_sub(y, t1, y)) != CRYPT_OK)                                   { goto done; }
  ------------------
  |  |  545|   128k|#define mp_sub(a, b, c)              ltc_mp.sub(a, b, c)
  ------------------
  |  Branch (92:8): [True: 0, False: 128k]
  ------------------
   93|   128k|   if (mp_cmp_d(y, 0) == LTC_MP_LT) {
  ------------------
  |  |  532|   128k|#define mp_cmp_d(a, b)               ltc_mp.compare_d(a, b)
  ------------------
                 if (mp_cmp_d(y, 0) == LTC_MP_LT) {
  ------------------
  |  |   12|   128k|#define LTC_MP_LT   -1
  ------------------
  |  Branch (93:8): [True: 60.3k, False: 68.3k]
  ------------------
   94|  60.3k|      if ((err = mp_add(y, modulus, y)) != CRYPT_OK)                           { goto done; }
  ------------------
  |  |  543|  60.3k|#define mp_add(a, b, c)              ltc_mp.add(a, b, c)
  ------------------
  |  Branch (94:11): [True: 0, False: 60.3k]
  ------------------
   95|  60.3k|   }
   96|       |   /* T1 = 2T1 */
   97|   128k|   if ((err = mp_add(t1, t1, t1)) != CRYPT_OK)                                 { goto done; }
  ------------------
  |  |  543|   128k|#define mp_add(a, b, c)              ltc_mp.add(a, b, c)
  ------------------
  |  Branch (97:8): [True: 0, False: 128k]
  ------------------
   98|   128k|   if (mp_cmp(t1, modulus) != LTC_MP_LT) {
  ------------------
  |  |  531|   128k|#define mp_cmp(a, b)                 ltc_mp.compare(a, b)
  ------------------
                 if (mp_cmp(t1, modulus) != LTC_MP_LT) {
  ------------------
  |  |   12|   128k|#define LTC_MP_LT   -1
  ------------------
  |  Branch (98:8): [True: 63.2k, False: 65.3k]
  ------------------
   99|  63.2k|      if ((err = mp_sub(t1, modulus, t1)) != CRYPT_OK)                         { goto done; }
  ------------------
  |  |  545|  63.2k|#define mp_sub(a, b, c)              ltc_mp.sub(a, b, c)
  ------------------
  |  Branch (99:11): [True: 0, False: 63.2k]
  ------------------
  100|  63.2k|   }
  101|       |   /* T1 = Y + T1 */
  102|   128k|   if ((err = mp_add(t1, y, t1)) != CRYPT_OK)                                  { goto done; }
  ------------------
  |  |  543|   128k|#define mp_add(a, b, c)              ltc_mp.add(a, b, c)
  ------------------
  |  Branch (102:8): [True: 0, False: 128k]
  ------------------
  103|   128k|   if (mp_cmp(t1, modulus) != LTC_MP_LT) {
  ------------------
  |  |  531|   128k|#define mp_cmp(a, b)                 ltc_mp.compare(a, b)
  ------------------
                 if (mp_cmp(t1, modulus) != LTC_MP_LT) {
  ------------------
  |  |   12|   128k|#define LTC_MP_LT   -1
  ------------------
  |  Branch (103:8): [True: 62.9k, False: 65.7k]
  ------------------
  104|  62.9k|      if ((err = mp_sub(t1, modulus, t1)) != CRYPT_OK)                         { goto done; }
  ------------------
  |  |  545|  62.9k|#define mp_sub(a, b, c)              ltc_mp.sub(a, b, c)
  ------------------
  |  Branch (104:11): [True: 0, False: 62.9k]
  ------------------
  105|  62.9k|   }
  106|       |   /* X = X - T2 */
  107|   128k|   if ((err = mp_sub(x, t2, x)) != CRYPT_OK)                                   { goto done; }
  ------------------
  |  |  545|   128k|#define mp_sub(a, b, c)              ltc_mp.sub(a, b, c)
  ------------------
  |  Branch (107:8): [True: 0, False: 128k]
  ------------------
  108|   128k|   if (mp_cmp_d(x, 0) == LTC_MP_LT) {
  ------------------
  |  |  532|   128k|#define mp_cmp_d(a, b)               ltc_mp.compare_d(a, b)
  ------------------
                 if (mp_cmp_d(x, 0) == LTC_MP_LT) {
  ------------------
  |  |   12|   128k|#define LTC_MP_LT   -1
  ------------------
  |  Branch (108:8): [True: 68.4k, False: 60.1k]
  ------------------
  109|  68.4k|      if ((err = mp_add(x, modulus, x)) != CRYPT_OK)                           { goto done; }
  ------------------
  |  |  543|  68.4k|#define mp_add(a, b, c)              ltc_mp.add(a, b, c)
  ------------------
  |  Branch (109:11): [True: 0, False: 68.4k]
  ------------------
  110|  68.4k|   }
  111|       |   /* T2 = 2T2 */
  112|   128k|   if ((err = mp_add(t2, t2, t2)) != CRYPT_OK)                                 { goto done; }
  ------------------
  |  |  543|   128k|#define mp_add(a, b, c)              ltc_mp.add(a, b, c)
  ------------------
  |  Branch (112:8): [True: 0, False: 128k]
  ------------------
  113|   128k|   if (mp_cmp(t2, modulus) != LTC_MP_LT) {
  ------------------
  |  |  531|   128k|#define mp_cmp(a, b)                 ltc_mp.compare(a, b)
  ------------------
                 if (mp_cmp(t2, modulus) != LTC_MP_LT) {
  ------------------
  |  |   12|   128k|#define LTC_MP_LT   -1
  ------------------
  |  Branch (113:8): [True: 62.2k, False: 66.3k]
  ------------------
  114|  62.2k|      if ((err = mp_sub(t2, modulus, t2)) != CRYPT_OK)                         { goto done; }
  ------------------
  |  |  545|  62.2k|#define mp_sub(a, b, c)              ltc_mp.sub(a, b, c)
  ------------------
  |  Branch (114:11): [True: 0, False: 62.2k]
  ------------------
  115|  62.2k|   }
  116|       |   /* T2 = X + T2 */
  117|   128k|   if ((err = mp_add(t2, x, t2)) != CRYPT_OK)                                  { goto done; }
  ------------------
  |  |  543|   128k|#define mp_add(a, b, c)              ltc_mp.add(a, b, c)
  ------------------
  |  Branch (117:8): [True: 0, False: 128k]
  ------------------
  118|   128k|   if (mp_cmp(t2, modulus) != LTC_MP_LT) {
  ------------------
  |  |  531|   128k|#define mp_cmp(a, b)                 ltc_mp.compare(a, b)
  ------------------
                 if (mp_cmp(t2, modulus) != LTC_MP_LT) {
  ------------------
  |  |   12|   128k|#define LTC_MP_LT   -1
  ------------------
  |  Branch (118:8): [True: 66.0k, False: 62.6k]
  ------------------
  119|  66.0k|      if ((err = mp_sub(t2, modulus, t2)) != CRYPT_OK)                         { goto done; }
  ------------------
  |  |  545|  66.0k|#define mp_sub(a, b, c)              ltc_mp.sub(a, b, c)
  ------------------
  |  Branch (119:11): [True: 0, False: 66.0k]
  ------------------
  120|  66.0k|   }
  121|       |
  122|       |   /* if Z' != 1 */
  123|   128k|   if (Q->z != NULL) {
  ------------------
  |  Branch (123:8): [True: 128k, False: 0]
  ------------------
  124|       |      /* Z = Z * Z' */
  125|   128k|      if ((err = mp_mul(z, Q->z, z)) != CRYPT_OK)                              { goto done; }
  ------------------
  |  |  547|   128k|#define mp_mul(a, b, c)              ltc_mp.mul(a, b, c)
  ------------------
  |  Branch (125:11): [True: 0, False: 128k]
  ------------------
  126|   128k|      if ((err = mp_montgomery_reduce(z, modulus, mp)) != CRYPT_OK)            { goto done; }
  ------------------
  |  |  565|   128k|#define mp_montgomery_reduce(a, b, c)   ltc_mp.montgomery_reduce(a, b, c)
  ------------------
  |  Branch (126:11): [True: 0, False: 128k]
  ------------------
  127|   128k|   }
  128|       |
  129|       |   /* Z = Z * X */
  130|   128k|   if ((err = mp_mul(z, x, z)) != CRYPT_OK)                                    { goto done; }
  ------------------
  |  |  547|   128k|#define mp_mul(a, b, c)              ltc_mp.mul(a, b, c)
  ------------------
  |  Branch (130:8): [True: 0, False: 128k]
  ------------------
  131|   128k|   if ((err = mp_montgomery_reduce(z, modulus, mp)) != CRYPT_OK)               { goto done; }
  ------------------
  |  |  565|   128k|#define mp_montgomery_reduce(a, b, c)   ltc_mp.montgomery_reduce(a, b, c)
  ------------------
  |  Branch (131:8): [True: 0, False: 128k]
  ------------------
  132|       |
  133|       |   /* T1 = T1 * X  */
  134|   128k|   if ((err = mp_mul(t1, x, t1)) != CRYPT_OK)                                  { goto done; }
  ------------------
  |  |  547|   128k|#define mp_mul(a, b, c)              ltc_mp.mul(a, b, c)
  ------------------
  |  Branch (134:8): [True: 0, False: 128k]
  ------------------
  135|   128k|   if ((err = mp_montgomery_reduce(t1, modulus, mp)) != CRYPT_OK)              { goto done; }
  ------------------
  |  |  565|   128k|#define mp_montgomery_reduce(a, b, c)   ltc_mp.montgomery_reduce(a, b, c)
  ------------------
  |  Branch (135:8): [True: 0, False: 128k]
  ------------------
  136|       |   /* X = X * X */
  137|   128k|   if ((err = mp_sqr(x, x)) != CRYPT_OK)                                       { goto done; }
  ------------------
  |  |  549|   128k|#define mp_sqr(a, b)                 ltc_mp.sqr(a, b)
  ------------------
  |  Branch (137:8): [True: 0, False: 128k]
  ------------------
  138|   128k|   if ((err = mp_montgomery_reduce(x, modulus, mp)) != CRYPT_OK)               { goto done; }
  ------------------
  |  |  565|   128k|#define mp_montgomery_reduce(a, b, c)   ltc_mp.montgomery_reduce(a, b, c)
  ------------------
  |  Branch (138:8): [True: 0, False: 128k]
  ------------------
  139|       |   /* T2 = T2 * x */
  140|   128k|   if ((err = mp_mul(t2, x, t2)) != CRYPT_OK)                                  { goto done; }
  ------------------
  |  |  547|   128k|#define mp_mul(a, b, c)              ltc_mp.mul(a, b, c)
  ------------------
  |  Branch (140:8): [True: 0, False: 128k]
  ------------------
  141|   128k|   if ((err = mp_montgomery_reduce(t2, modulus, mp)) != CRYPT_OK)              { goto done; }
  ------------------
  |  |  565|   128k|#define mp_montgomery_reduce(a, b, c)   ltc_mp.montgomery_reduce(a, b, c)
  ------------------
  |  Branch (141:8): [True: 0, False: 128k]
  ------------------
  142|       |   /* T1 = T1 * X  */
  143|   128k|   if ((err = mp_mul(t1, x, t1)) != CRYPT_OK)                                  { goto done; }
  ------------------
  |  |  547|   128k|#define mp_mul(a, b, c)              ltc_mp.mul(a, b, c)
  ------------------
  |  Branch (143:8): [True: 0, False: 128k]
  ------------------
  144|   128k|   if ((err = mp_montgomery_reduce(t1, modulus, mp)) != CRYPT_OK)              { goto done; }
  ------------------
  |  |  565|   128k|#define mp_montgomery_reduce(a, b, c)   ltc_mp.montgomery_reduce(a, b, c)
  ------------------
  |  Branch (144:8): [True: 0, False: 128k]
  ------------------
  145|       |
  146|       |   /* X = Y*Y */
  147|   128k|   if ((err = mp_sqr(y, x)) != CRYPT_OK)                                       { goto done; }
  ------------------
  |  |  549|   128k|#define mp_sqr(a, b)                 ltc_mp.sqr(a, b)
  ------------------
  |  Branch (147:8): [True: 0, False: 128k]
  ------------------
  148|   128k|   if ((err = mp_montgomery_reduce(x, modulus, mp)) != CRYPT_OK)               { goto done; }
  ------------------
  |  |  565|   128k|#define mp_montgomery_reduce(a, b, c)   ltc_mp.montgomery_reduce(a, b, c)
  ------------------
  |  Branch (148:8): [True: 0, False: 128k]
  ------------------
  149|       |   /* X = X - T2 */
  150|   128k|   if ((err = mp_sub(x, t2, x)) != CRYPT_OK)                                   { goto done; }
  ------------------
  |  |  545|   128k|#define mp_sub(a, b, c)              ltc_mp.sub(a, b, c)
  ------------------
  |  Branch (150:8): [True: 0, False: 128k]
  ------------------
  151|   128k|   if (mp_cmp_d(x, 0) == LTC_MP_LT) {
  ------------------
  |  |  532|   128k|#define mp_cmp_d(a, b)               ltc_mp.compare_d(a, b)
  ------------------
                 if (mp_cmp_d(x, 0) == LTC_MP_LT) {
  ------------------
  |  |   12|   128k|#define LTC_MP_LT   -1
  ------------------
  |  Branch (151:8): [True: 63.7k, False: 64.9k]
  ------------------
  152|  63.7k|      if ((err = mp_add(x, modulus, x)) != CRYPT_OK)                           { goto done; }
  ------------------
  |  |  543|  63.7k|#define mp_add(a, b, c)              ltc_mp.add(a, b, c)
  ------------------
  |  Branch (152:11): [True: 0, False: 63.7k]
  ------------------
  153|  63.7k|   }
  154|       |
  155|       |   /* T2 = T2 - X */
  156|   128k|   if ((err = mp_sub(t2, x, t2)) != CRYPT_OK)                                  { goto done; }
  ------------------
  |  |  545|   128k|#define mp_sub(a, b, c)              ltc_mp.sub(a, b, c)
  ------------------
  |  Branch (156:8): [True: 0, False: 128k]
  ------------------
  157|   128k|   if (mp_cmp_d(t2, 0) == LTC_MP_LT) {
  ------------------
  |  |  532|   128k|#define mp_cmp_d(a, b)               ltc_mp.compare_d(a, b)
  ------------------
                 if (mp_cmp_d(t2, 0) == LTC_MP_LT) {
  ------------------
  |  |   12|   128k|#define LTC_MP_LT   -1
  ------------------
  |  Branch (157:8): [True: 66.1k, False: 62.5k]
  ------------------
  158|  66.1k|      if ((err = mp_add(t2, modulus, t2)) != CRYPT_OK)                         { goto done; }
  ------------------
  |  |  543|  66.1k|#define mp_add(a, b, c)              ltc_mp.add(a, b, c)
  ------------------
  |  Branch (158:11): [True: 0, False: 66.1k]
  ------------------
  159|  66.1k|   }
  160|       |   /* T2 = T2 - X */
  161|   128k|   if ((err = mp_sub(t2, x, t2)) != CRYPT_OK)                                  { goto done; }
  ------------------
  |  |  545|   128k|#define mp_sub(a, b, c)              ltc_mp.sub(a, b, c)
  ------------------
  |  Branch (161:8): [True: 0, False: 128k]
  ------------------
  162|   128k|   if (mp_cmp_d(t2, 0) == LTC_MP_LT) {
  ------------------
  |  |  532|   128k|#define mp_cmp_d(a, b)               ltc_mp.compare_d(a, b)
  ------------------
                 if (mp_cmp_d(t2, 0) == LTC_MP_LT) {
  ------------------
  |  |   12|   128k|#define LTC_MP_LT   -1
  ------------------
  |  Branch (162:8): [True: 63.3k, False: 65.2k]
  ------------------
  163|  63.3k|      if ((err = mp_add(t2, modulus, t2)) != CRYPT_OK)                         { goto done; }
  ------------------
  |  |  543|  63.3k|#define mp_add(a, b, c)              ltc_mp.add(a, b, c)
  ------------------
  |  Branch (163:11): [True: 0, False: 63.3k]
  ------------------
  164|  63.3k|   }
  165|       |   /* T2 = T2 * Y */
  166|   128k|   if ((err = mp_mul(t2, y, t2)) != CRYPT_OK)                                  { goto done; }
  ------------------
  |  |  547|   128k|#define mp_mul(a, b, c)              ltc_mp.mul(a, b, c)
  ------------------
  |  Branch (166:8): [True: 0, False: 128k]
  ------------------
  167|   128k|   if ((err = mp_montgomery_reduce(t2, modulus, mp)) != CRYPT_OK)              { goto done; }
  ------------------
  |  |  565|   128k|#define mp_montgomery_reduce(a, b, c)   ltc_mp.montgomery_reduce(a, b, c)
  ------------------
  |  Branch (167:8): [True: 0, False: 128k]
  ------------------
  168|       |   /* Y = T2 - T1 */
  169|   128k|   if ((err = mp_sub(t2, t1, y)) != CRYPT_OK)                                  { goto done; }
  ------------------
  |  |  545|   128k|#define mp_sub(a, b, c)              ltc_mp.sub(a, b, c)
  ------------------
  |  Branch (169:8): [True: 0, False: 128k]
  ------------------
  170|   128k|   if (mp_cmp_d(y, 0) == LTC_MP_LT) {
  ------------------
  |  |  532|   128k|#define mp_cmp_d(a, b)               ltc_mp.compare_d(a, b)
  ------------------
                 if (mp_cmp_d(y, 0) == LTC_MP_LT) {
  ------------------
  |  |   12|   128k|#define LTC_MP_LT   -1
  ------------------
  |  Branch (170:8): [True: 66.1k, False: 62.4k]
  ------------------
  171|  66.1k|      if ((err = mp_add(y, modulus, y)) != CRYPT_OK)                           { goto done; }
  ------------------
  |  |  543|  66.1k|#define mp_add(a, b, c)              ltc_mp.add(a, b, c)
  ------------------
  |  Branch (171:11): [True: 0, False: 66.1k]
  ------------------
  172|  66.1k|   }
  173|       |   /* Y = Y/2 */
  174|   128k|   if (mp_isodd(y)) {
  ------------------
  |  |  572|   128k|#define mp_isodd(a)                  (mp_get_digit_count(a) > 0 ? (mp_get_digit(a, 0) & 1 ? LTC_MP_YES : LTC_MP_NO) : LTC_MP_NO)
  |  |  ------------------
  |  |  |  |  530|   128k|#define mp_get_digit_count(a)        ltc_mp.get_digit_count(a)
  |  |  ------------------
  |  |               #define mp_isodd(a)                  (mp_get_digit_count(a) > 0 ? (mp_get_digit(a, 0) & 1 ? LTC_MP_YES : LTC_MP_NO) : LTC_MP_NO)
  |  |  ------------------
  |  |  |  |  529|   128k|#define mp_get_digit(a, n)           ltc_mp.get_digit(a, n)
  |  |  ------------------
  |  |               #define mp_isodd(a)                  (mp_get_digit_count(a) > 0 ? (mp_get_digit(a, 0) & 1 ? LTC_MP_YES : LTC_MP_NO) : LTC_MP_NO)
  |  |  ------------------
  |  |  |  |   17|  65.6k|#define LTC_MP_YES   1
  |  |  ------------------
  |  |               #define mp_isodd(a)                  (mp_get_digit_count(a) > 0 ? (mp_get_digit(a, 0) & 1 ? LTC_MP_YES : LTC_MP_NO) : LTC_MP_NO)
  |  |  ------------------
  |  |  |  |   16|  63.0k|#define LTC_MP_NO    0
  |  |  ------------------
  |  |               #define mp_isodd(a)                  (mp_get_digit_count(a) > 0 ? (mp_get_digit(a, 0) & 1 ? LTC_MP_YES : LTC_MP_NO) : LTC_MP_NO)
  |  |  ------------------
  |  |  |  |   16|      0|#define LTC_MP_NO    0
  |  |  ------------------
  |  |  |  Branch (572:38): [True: 65.6k, False: 63.0k]
  |  |  |  Branch (572:39): [True: 128k, False: 0]
  |  |  |  Branch (572:68): [True: 65.6k, False: 63.0k]
  |  |  ------------------
  ------------------
  175|  65.6k|      if ((err = mp_add(y, modulus, y)) != CRYPT_OK)                           { goto done; }
  ------------------
  |  |  543|  65.6k|#define mp_add(a, b, c)              ltc_mp.add(a, b, c)
  ------------------
  |  Branch (175:11): [True: 0, False: 65.6k]
  ------------------
  176|  65.6k|   }
  177|   128k|   if ((err = mp_div_2(y, y)) != CRYPT_OK)                                     { goto done; }
  ------------------
  |  |  551|   128k|#define mp_div_2(a, b)               ltc_mp.div_2(a, b)
  ------------------
  |  Branch (177:8): [True: 0, False: 128k]
  ------------------
  178|       |
  179|   128k|   if ((err = mp_copy(x, R->x)) != CRYPT_OK)                                   { goto done; }
  ------------------
  |  |  524|   128k|#define mp_copy(a, b)                ltc_mp.copy(a, b)
  ------------------
  |  Branch (179:8): [True: 0, False: 128k]
  ------------------
  180|   128k|   if ((err = mp_copy(y, R->y)) != CRYPT_OK)                                   { goto done; }
  ------------------
  |  |  524|   128k|#define mp_copy(a, b)                ltc_mp.copy(a, b)
  ------------------
  |  Branch (180:8): [True: 0, False: 128k]
  ------------------
  181|   128k|   if ((err = mp_copy(z, R->z)) != CRYPT_OK)                                   { goto done; }
  ------------------
  |  |  524|   128k|#define mp_copy(a, b)                ltc_mp.copy(a, b)
  ------------------
  |  Branch (181:8): [True: 0, False: 128k]
  ------------------
  182|       |
  183|   128k|   err = CRYPT_OK;
  184|   128k|done:
  185|   128k|   mp_clear_multi(t1, t2, x, y, z, NULL);
  ------------------
  |  |  519|   128k|#define mp_clear_multi               ltc_deinit_multi
  ------------------
  186|   128k|   return err;
  187|   128k|}

ltc_ecc_projective_dbl_point:
   33|   128k|{
   34|   128k|   void *t1, *t2;
   35|   128k|   int   err;
   36|       |
   37|   128k|   LTC_ARGCHK(P       != NULL);
  ------------------
  |  |   32|   128k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 128k]
  |  |  |  Branch (32:87): [Folded, False: 128k]
  |  |  ------------------
  ------------------
   38|   128k|   LTC_ARGCHK(R       != NULL);
  ------------------
  |  |   32|   128k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 128k]
  |  |  |  Branch (32:87): [Folded, False: 128k]
  |  |  ------------------
  ------------------
   39|   128k|   LTC_ARGCHK(modulus != NULL);
  ------------------
  |  |   32|   128k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 128k]
  |  |  |  Branch (32:87): [Folded, False: 128k]
  |  |  ------------------
  ------------------
   40|   128k|   LTC_ARGCHK(mp      != NULL);
  ------------------
  |  |   32|   128k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 128k]
  |  |  |  Branch (32:87): [Folded, False: 128k]
  |  |  ------------------
  ------------------
   41|       |
   42|   128k|   if ((err = mp_init_multi(&t1, &t2, NULL)) != CRYPT_OK) {
  ------------------
  |  |  517|   128k|#define mp_init_multi                ltc_init_multi
  ------------------
  |  Branch (42:8): [True: 0, False: 128k]
  ------------------
   43|      0|      return err;
   44|      0|   }
   45|       |
   46|   128k|   if (P != R) {
  ------------------
  |  Branch (46:8): [True: 8.78k, False: 120k]
  ------------------
   47|  8.78k|      if ((err = mp_copy(P->x, R->x)) != CRYPT_OK)                                { goto done; }
  ------------------
  |  |  524|  8.78k|#define mp_copy(a, b)                ltc_mp.copy(a, b)
  ------------------
  |  Branch (47:11): [True: 0, False: 8.78k]
  ------------------
   48|  8.78k|      if ((err = mp_copy(P->y, R->y)) != CRYPT_OK)                                { goto done; }
  ------------------
  |  |  524|  8.78k|#define mp_copy(a, b)                ltc_mp.copy(a, b)
  ------------------
  |  Branch (48:11): [True: 0, False: 8.78k]
  ------------------
   49|  8.78k|      if ((err = mp_copy(P->z, R->z)) != CRYPT_OK)                                { goto done; }
  ------------------
  |  |  524|  8.78k|#define mp_copy(a, b)                ltc_mp.copy(a, b)
  ------------------
  |  Branch (49:11): [True: 0, False: 8.78k]
  ------------------
   50|  8.78k|   }
   51|       |
   52|       |   /* t1 = Z * Z */
   53|   128k|   if ((err = mp_sqr(R->z, t1)) != CRYPT_OK)                                      { goto done; }
  ------------------
  |  |  549|   128k|#define mp_sqr(a, b)                 ltc_mp.sqr(a, b)
  ------------------
  |  Branch (53:8): [True: 0, False: 128k]
  ------------------
   54|   128k|   if ((err = mp_montgomery_reduce(t1, modulus, mp)) != CRYPT_OK)                 { goto done; }
  ------------------
  |  |  565|   128k|#define mp_montgomery_reduce(a, b, c)   ltc_mp.montgomery_reduce(a, b, c)
  ------------------
  |  Branch (54:8): [True: 0, False: 128k]
  ------------------
   55|       |   /* Z = Y * Z */
   56|   128k|   if ((err = mp_mul(R->z, R->y, R->z)) != CRYPT_OK)                              { goto done; }
  ------------------
  |  |  547|   128k|#define mp_mul(a, b, c)              ltc_mp.mul(a, b, c)
  ------------------
  |  Branch (56:8): [True: 0, False: 128k]
  ------------------
   57|   128k|   if ((err = mp_montgomery_reduce(R->z, modulus, mp)) != CRYPT_OK)               { goto done; }
  ------------------
  |  |  565|   128k|#define mp_montgomery_reduce(a, b, c)   ltc_mp.montgomery_reduce(a, b, c)
  ------------------
  |  Branch (57:8): [True: 0, False: 128k]
  ------------------
   58|       |   /* Z = 2Z */
   59|   128k|   if ((err = mp_add(R->z, R->z, R->z)) != CRYPT_OK)                              { goto done; }
  ------------------
  |  |  543|   128k|#define mp_add(a, b, c)              ltc_mp.add(a, b, c)
  ------------------
  |  Branch (59:8): [True: 0, False: 128k]
  ------------------
   60|   128k|   if (mp_cmp(R->z, modulus) != LTC_MP_LT) {
  ------------------
  |  |  531|   128k|#define mp_cmp(a, b)                 ltc_mp.compare(a, b)
  ------------------
                 if (mp_cmp(R->z, modulus) != LTC_MP_LT) {
  ------------------
  |  |   12|   128k|#define LTC_MP_LT   -1
  ------------------
  |  Branch (60:8): [True: 65.6k, False: 63.2k]
  ------------------
   61|  65.6k|      if ((err = mp_sub(R->z, modulus, R->z)) != CRYPT_OK)                        { goto done; }
  ------------------
  |  |  545|  65.6k|#define mp_sub(a, b, c)              ltc_mp.sub(a, b, c)
  ------------------
  |  Branch (61:11): [True: 0, False: 65.6k]
  ------------------
   62|  65.6k|   }
   63|       |
   64|       |   /* T2 = X - T1 */
   65|   128k|   if ((err = mp_sub(R->x, t1, t2)) != CRYPT_OK)                                  { goto done; }
  ------------------
  |  |  545|   128k|#define mp_sub(a, b, c)              ltc_mp.sub(a, b, c)
  ------------------
  |  Branch (65:8): [True: 0, False: 128k]
  ------------------
   66|   128k|   if (mp_cmp_d(t2, 0) == LTC_MP_LT) {
  ------------------
  |  |  532|   128k|#define mp_cmp_d(a, b)               ltc_mp.compare_d(a, b)
  ------------------
                 if (mp_cmp_d(t2, 0) == LTC_MP_LT) {
  ------------------
  |  |   12|   128k|#define LTC_MP_LT   -1
  ------------------
  |  Branch (66:8): [True: 62.5k, False: 66.4k]
  ------------------
   67|  62.5k|      if ((err = mp_add(t2, modulus, t2)) != CRYPT_OK)                            { goto done; }
  ------------------
  |  |  543|  62.5k|#define mp_add(a, b, c)              ltc_mp.add(a, b, c)
  ------------------
  |  Branch (67:11): [True: 0, False: 62.5k]
  ------------------
   68|  62.5k|   }
   69|       |   /* T1 = X + T1 */
   70|   128k|   if ((err = mp_add(t1, R->x, t1)) != CRYPT_OK)                                  { goto done; }
  ------------------
  |  |  543|   128k|#define mp_add(a, b, c)              ltc_mp.add(a, b, c)
  ------------------
  |  Branch (70:8): [True: 0, False: 128k]
  ------------------
   71|   128k|   if (mp_cmp(t1, modulus) != LTC_MP_LT) {
  ------------------
  |  |  531|   128k|#define mp_cmp(a, b)                 ltc_mp.compare(a, b)
  ------------------
                 if (mp_cmp(t1, modulus) != LTC_MP_LT) {
  ------------------
  |  |   12|   128k|#define LTC_MP_LT   -1
  ------------------
  |  Branch (71:8): [True: 62.7k, False: 66.2k]
  ------------------
   72|  62.7k|      if ((err = mp_sub(t1, modulus, t1)) != CRYPT_OK)                            { goto done; }
  ------------------
  |  |  545|  62.7k|#define mp_sub(a, b, c)              ltc_mp.sub(a, b, c)
  ------------------
  |  Branch (72:11): [True: 0, False: 62.7k]
  ------------------
   73|  62.7k|   }
   74|       |   /* T2 = T1 * T2 */
   75|   128k|   if ((err = mp_mul(t1, t2, t2)) != CRYPT_OK)                                    { goto done; }
  ------------------
  |  |  547|   128k|#define mp_mul(a, b, c)              ltc_mp.mul(a, b, c)
  ------------------
  |  Branch (75:8): [True: 0, False: 128k]
  ------------------
   76|   128k|   if ((err = mp_montgomery_reduce(t2, modulus, mp)) != CRYPT_OK)                 { goto done; }
  ------------------
  |  |  565|   128k|#define mp_montgomery_reduce(a, b, c)   ltc_mp.montgomery_reduce(a, b, c)
  ------------------
  |  Branch (76:8): [True: 0, False: 128k]
  ------------------
   77|       |   /* T1 = 2T2 */
   78|   128k|   if ((err = mp_add(t2, t2, t1)) != CRYPT_OK)                                    { goto done; }
  ------------------
  |  |  543|   128k|#define mp_add(a, b, c)              ltc_mp.add(a, b, c)
  ------------------
  |  Branch (78:8): [True: 0, False: 128k]
  ------------------
   79|   128k|   if (mp_cmp(t1, modulus) != LTC_MP_LT) {
  ------------------
  |  |  531|   128k|#define mp_cmp(a, b)                 ltc_mp.compare(a, b)
  ------------------
                 if (mp_cmp(t1, modulus) != LTC_MP_LT) {
  ------------------
  |  |   12|   128k|#define LTC_MP_LT   -1
  ------------------
  |  Branch (79:8): [True: 63.7k, False: 65.1k]
  ------------------
   80|  63.7k|      if ((err = mp_sub(t1, modulus, t1)) != CRYPT_OK)                            { goto done; }
  ------------------
  |  |  545|  63.7k|#define mp_sub(a, b, c)              ltc_mp.sub(a, b, c)
  ------------------
  |  Branch (80:11): [True: 0, False: 63.7k]
  ------------------
   81|  63.7k|   }
   82|       |   /* T1 = T1 + T2 */
   83|   128k|   if ((err = mp_add(t1, t2, t1)) != CRYPT_OK)                                    { goto done; }
  ------------------
  |  |  543|   128k|#define mp_add(a, b, c)              ltc_mp.add(a, b, c)
  ------------------
  |  Branch (83:8): [True: 0, False: 128k]
  ------------------
   84|   128k|   if (mp_cmp(t1, modulus) != LTC_MP_LT) {
  ------------------
  |  |  531|   128k|#define mp_cmp(a, b)                 ltc_mp.compare(a, b)
  ------------------
                 if (mp_cmp(t1, modulus) != LTC_MP_LT) {
  ------------------
  |  |   12|   128k|#define LTC_MP_LT   -1
  ------------------
  |  Branch (84:8): [True: 63.0k, False: 65.9k]
  ------------------
   85|  63.0k|      if ((err = mp_sub(t1, modulus, t1)) != CRYPT_OK)                            { goto done; }
  ------------------
  |  |  545|  63.0k|#define mp_sub(a, b, c)              ltc_mp.sub(a, b, c)
  ------------------
  |  Branch (85:11): [True: 0, False: 63.0k]
  ------------------
   86|  63.0k|   }
   87|       |
   88|       |   /* Y = 2Y */
   89|   128k|   if ((err = mp_add(R->y, R->y, R->y)) != CRYPT_OK)                              { goto done; }
  ------------------
  |  |  543|   128k|#define mp_add(a, b, c)              ltc_mp.add(a, b, c)
  ------------------
  |  Branch (89:8): [True: 0, False: 128k]
  ------------------
   90|   128k|   if (mp_cmp(R->y, modulus) != LTC_MP_LT) {
  ------------------
  |  |  531|   128k|#define mp_cmp(a, b)                 ltc_mp.compare(a, b)
  ------------------
                 if (mp_cmp(R->y, modulus) != LTC_MP_LT) {
  ------------------
  |  |   12|   128k|#define LTC_MP_LT   -1
  ------------------
  |  Branch (90:8): [True: 63.7k, False: 65.1k]
  ------------------
   91|  63.7k|      if ((err = mp_sub(R->y, modulus, R->y)) != CRYPT_OK)                        { goto done; }
  ------------------
  |  |  545|  63.7k|#define mp_sub(a, b, c)              ltc_mp.sub(a, b, c)
  ------------------
  |  Branch (91:11): [True: 0, False: 63.7k]
  ------------------
   92|  63.7k|   }
   93|       |   /* Y = Y * Y */
   94|   128k|   if ((err = mp_sqr(R->y, R->y)) != CRYPT_OK)                                    { goto done; }
  ------------------
  |  |  549|   128k|#define mp_sqr(a, b)                 ltc_mp.sqr(a, b)
  ------------------
  |  Branch (94:8): [True: 0, False: 128k]
  ------------------
   95|   128k|   if ((err = mp_montgomery_reduce(R->y, modulus, mp)) != CRYPT_OK)               { goto done; }
  ------------------
  |  |  565|   128k|#define mp_montgomery_reduce(a, b, c)   ltc_mp.montgomery_reduce(a, b, c)
  ------------------
  |  Branch (95:8): [True: 0, False: 128k]
  ------------------
   96|       |   /* T2 = Y * Y */
   97|   128k|   if ((err = mp_sqr(R->y, t2)) != CRYPT_OK)                                      { goto done; }
  ------------------
  |  |  549|   128k|#define mp_sqr(a, b)                 ltc_mp.sqr(a, b)
  ------------------
  |  Branch (97:8): [True: 0, False: 128k]
  ------------------
   98|   128k|   if ((err = mp_montgomery_reduce(t2, modulus, mp)) != CRYPT_OK)                 { goto done; }
  ------------------
  |  |  565|   128k|#define mp_montgomery_reduce(a, b, c)   ltc_mp.montgomery_reduce(a, b, c)
  ------------------
  |  Branch (98:8): [True: 0, False: 128k]
  ------------------
   99|       |   /* T2 = T2/2 */
  100|   128k|   if (mp_isodd(t2)) {
  ------------------
  |  |  572|   128k|#define mp_isodd(a)                  (mp_get_digit_count(a) > 0 ? (mp_get_digit(a, 0) & 1 ? LTC_MP_YES : LTC_MP_NO) : LTC_MP_NO)
  |  |  ------------------
  |  |  |  |  530|   128k|#define mp_get_digit_count(a)        ltc_mp.get_digit_count(a)
  |  |  ------------------
  |  |               #define mp_isodd(a)                  (mp_get_digit_count(a) > 0 ? (mp_get_digit(a, 0) & 1 ? LTC_MP_YES : LTC_MP_NO) : LTC_MP_NO)
  |  |  ------------------
  |  |  |  |  529|   128k|#define mp_get_digit(a, n)           ltc_mp.get_digit(a, n)
  |  |  ------------------
  |  |               #define mp_isodd(a)                  (mp_get_digit_count(a) > 0 ? (mp_get_digit(a, 0) & 1 ? LTC_MP_YES : LTC_MP_NO) : LTC_MP_NO)
  |  |  ------------------
  |  |  |  |   17|  60.5k|#define LTC_MP_YES   1
  |  |  ------------------
  |  |               #define mp_isodd(a)                  (mp_get_digit_count(a) > 0 ? (mp_get_digit(a, 0) & 1 ? LTC_MP_YES : LTC_MP_NO) : LTC_MP_NO)
  |  |  ------------------
  |  |  |  |   16|  68.4k|#define LTC_MP_NO    0
  |  |  ------------------
  |  |               #define mp_isodd(a)                  (mp_get_digit_count(a) > 0 ? (mp_get_digit(a, 0) & 1 ? LTC_MP_YES : LTC_MP_NO) : LTC_MP_NO)
  |  |  ------------------
  |  |  |  |   16|      0|#define LTC_MP_NO    0
  |  |  ------------------
  |  |  |  Branch (572:38): [True: 60.5k, False: 68.4k]
  |  |  |  Branch (572:39): [True: 128k, False: 0]
  |  |  |  Branch (572:68): [True: 60.5k, False: 68.4k]
  |  |  ------------------
  ------------------
  101|  60.5k|      if ((err = mp_add(t2, modulus, t2)) != CRYPT_OK)                            { goto done; }
  ------------------
  |  |  543|  60.5k|#define mp_add(a, b, c)              ltc_mp.add(a, b, c)
  ------------------
  |  Branch (101:11): [True: 0, False: 60.5k]
  ------------------
  102|  60.5k|   }
  103|   128k|   if ((err = mp_div_2(t2, t2)) != CRYPT_OK)                                      { goto done; }
  ------------------
  |  |  551|   128k|#define mp_div_2(a, b)               ltc_mp.div_2(a, b)
  ------------------
  |  Branch (103:8): [True: 0, False: 128k]
  ------------------
  104|       |   /* Y = Y * X */
  105|   128k|   if ((err = mp_mul(R->y, R->x, R->y)) != CRYPT_OK)                              { goto done; }
  ------------------
  |  |  547|   128k|#define mp_mul(a, b, c)              ltc_mp.mul(a, b, c)
  ------------------
  |  Branch (105:8): [True: 0, False: 128k]
  ------------------
  106|   128k|   if ((err = mp_montgomery_reduce(R->y, modulus, mp)) != CRYPT_OK)               { goto done; }
  ------------------
  |  |  565|   128k|#define mp_montgomery_reduce(a, b, c)   ltc_mp.montgomery_reduce(a, b, c)
  ------------------
  |  Branch (106:8): [True: 0, False: 128k]
  ------------------
  107|       |
  108|       |   /* X  = T1 * T1 */
  109|   128k|   if ((err = mp_sqr(t1, R->x)) != CRYPT_OK)                                      { goto done; }
  ------------------
  |  |  549|   128k|#define mp_sqr(a, b)                 ltc_mp.sqr(a, b)
  ------------------
  |  Branch (109:8): [True: 0, False: 128k]
  ------------------
  110|   128k|   if ((err = mp_montgomery_reduce(R->x, modulus, mp)) != CRYPT_OK)               { goto done; }
  ------------------
  |  |  565|   128k|#define mp_montgomery_reduce(a, b, c)   ltc_mp.montgomery_reduce(a, b, c)
  ------------------
  |  Branch (110:8): [True: 0, False: 128k]
  ------------------
  111|       |   /* X = X - Y */
  112|   128k|   if ((err = mp_sub(R->x, R->y, R->x)) != CRYPT_OK)                              { goto done; }
  ------------------
  |  |  545|   128k|#define mp_sub(a, b, c)              ltc_mp.sub(a, b, c)
  ------------------
  |  Branch (112:8): [True: 0, False: 128k]
  ------------------
  113|   128k|   if (mp_cmp_d(R->x, 0) == LTC_MP_LT) {
  ------------------
  |  |  532|   128k|#define mp_cmp_d(a, b)               ltc_mp.compare_d(a, b)
  ------------------
                 if (mp_cmp_d(R->x, 0) == LTC_MP_LT) {
  ------------------
  |  |   12|   128k|#define LTC_MP_LT   -1
  ------------------
  |  Branch (113:8): [True: 62.4k, False: 66.4k]
  ------------------
  114|  62.4k|      if ((err = mp_add(R->x, modulus, R->x)) != CRYPT_OK)                        { goto done; }
  ------------------
  |  |  543|  62.4k|#define mp_add(a, b, c)              ltc_mp.add(a, b, c)
  ------------------
  |  Branch (114:11): [True: 0, False: 62.4k]
  ------------------
  115|  62.4k|   }
  116|       |   /* X = X - Y */
  117|   128k|   if ((err = mp_sub(R->x, R->y, R->x)) != CRYPT_OK)                              { goto done; }
  ------------------
  |  |  545|   128k|#define mp_sub(a, b, c)              ltc_mp.sub(a, b, c)
  ------------------
  |  Branch (117:8): [True: 0, False: 128k]
  ------------------
  118|   128k|   if (mp_cmp_d(R->x, 0) == LTC_MP_LT) {
  ------------------
  |  |  532|   128k|#define mp_cmp_d(a, b)               ltc_mp.compare_d(a, b)
  ------------------
                 if (mp_cmp_d(R->x, 0) == LTC_MP_LT) {
  ------------------
  |  |   12|   128k|#define LTC_MP_LT   -1
  ------------------
  |  Branch (118:8): [True: 62.4k, False: 66.5k]
  ------------------
  119|  62.4k|      if ((err = mp_add(R->x, modulus, R->x)) != CRYPT_OK)                        { goto done; }
  ------------------
  |  |  543|  62.4k|#define mp_add(a, b, c)              ltc_mp.add(a, b, c)
  ------------------
  |  Branch (119:11): [True: 0, False: 62.4k]
  ------------------
  120|  62.4k|   }
  121|       |
  122|       |   /* Y = Y - X */
  123|   128k|   if ((err = mp_sub(R->y, R->x, R->y)) != CRYPT_OK)                              { goto done; }
  ------------------
  |  |  545|   128k|#define mp_sub(a, b, c)              ltc_mp.sub(a, b, c)
  ------------------
  |  Branch (123:8): [True: 0, False: 128k]
  ------------------
  124|   128k|   if (mp_cmp_d(R->y, 0) == LTC_MP_LT) {
  ------------------
  |  |  532|   128k|#define mp_cmp_d(a, b)               ltc_mp.compare_d(a, b)
  ------------------
                 if (mp_cmp_d(R->y, 0) == LTC_MP_LT) {
  ------------------
  |  |   12|   128k|#define LTC_MP_LT   -1
  ------------------
  |  Branch (124:8): [True: 66.2k, False: 62.6k]
  ------------------
  125|  66.2k|      if ((err = mp_add(R->y, modulus, R->y)) != CRYPT_OK)                        { goto done; }
  ------------------
  |  |  543|  66.2k|#define mp_add(a, b, c)              ltc_mp.add(a, b, c)
  ------------------
  |  Branch (125:11): [True: 0, False: 66.2k]
  ------------------
  126|  66.2k|   }
  127|       |   /* Y = Y * T1 */
  128|   128k|   if ((err = mp_mul(R->y, t1, R->y)) != CRYPT_OK)                                { goto done; }
  ------------------
  |  |  547|   128k|#define mp_mul(a, b, c)              ltc_mp.mul(a, b, c)
  ------------------
  |  Branch (128:8): [True: 0, False: 128k]
  ------------------
  129|   128k|   if ((err = mp_montgomery_reduce(R->y, modulus, mp)) != CRYPT_OK)               { goto done; }
  ------------------
  |  |  565|   128k|#define mp_montgomery_reduce(a, b, c)   ltc_mp.montgomery_reduce(a, b, c)
  ------------------
  |  Branch (129:8): [True: 0, False: 128k]
  ------------------
  130|       |   /* Y = Y - T2 */
  131|   128k|   if ((err = mp_sub(R->y, t2, R->y)) != CRYPT_OK)                                { goto done; }
  ------------------
  |  |  545|   128k|#define mp_sub(a, b, c)              ltc_mp.sub(a, b, c)
  ------------------
  |  Branch (131:8): [True: 0, False: 128k]
  ------------------
  132|   128k|   if (mp_cmp_d(R->y, 0) == LTC_MP_LT) {
  ------------------
  |  |  532|   128k|#define mp_cmp_d(a, b)               ltc_mp.compare_d(a, b)
  ------------------
                 if (mp_cmp_d(R->y, 0) == LTC_MP_LT) {
  ------------------
  |  |   12|   128k|#define LTC_MP_LT   -1
  ------------------
  |  Branch (132:8): [True: 62.8k, False: 66.1k]
  ------------------
  133|  62.8k|      if ((err = mp_add(R->y, modulus, R->y)) != CRYPT_OK)                        { goto done; }
  ------------------
  |  |  543|  62.8k|#define mp_add(a, b, c)              ltc_mp.add(a, b, c)
  ------------------
  |  Branch (133:11): [True: 0, False: 62.8k]
  ------------------
  134|  62.8k|   }
  135|       |
  136|   128k|   err = CRYPT_OK;
  137|   128k|done:
  138|   128k|   mp_clear_multi(t1, t2, NULL);
  ------------------
  |  |  519|   128k|#define mp_clear_multi               ltc_deinit_multi
  ------------------
  139|   128k|   return err;
  140|   128k|}

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

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

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

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

mp_2expt:
   12|  30.9k|{
   13|  30.9k|   mp_err    err;
   14|       |
   15|  30.9k|   if (b < 0) {
  ------------------
  |  Branch (15:8): [True: 0, False: 30.9k]
  ------------------
   16|      0|      return MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
   17|      0|   }
   18|       |
   19|       |   /* zero a as per default */
   20|  30.9k|   mp_zero(a);
   21|       |
   22|       |   /* grow a to accomodate the single bit */
   23|  30.9k|   if ((err = mp_grow(a, (b / MP_DIGIT_BIT) + 1)) != MP_OKAY) {
  ------------------
  |  |   82|  30.9k|#   define MP_DIGIT_BIT 60
  ------------------
                 if ((err = mp_grow(a, (b / MP_DIGIT_BIT) + 1)) != MP_OKAY) {
  ------------------
  |  |  161|  30.9k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (23:8): [True: 0, False: 30.9k]
  ------------------
   24|      0|      return err;
   25|      0|   }
   26|       |
   27|       |   /* set the used count of where the bit will go */
   28|  30.9k|   a->used = (b / MP_DIGIT_BIT) + 1;
  ------------------
  |  |   82|  30.9k|#   define MP_DIGIT_BIT 60
  ------------------
   29|       |
   30|       |   /* put the single bit in its place */
   31|  30.9k|   a->dp[b / MP_DIGIT_BIT] = (mp_digit)1 << (mp_digit)(b % MP_DIGIT_BIT);
  ------------------
  |  |   82|  30.9k|#   define MP_DIGIT_BIT 60
  ------------------
                 a->dp[b / MP_DIGIT_BIT] = (mp_digit)1 << (mp_digit)(b % MP_DIGIT_BIT);
  ------------------
  |  |   82|  30.9k|#   define MP_DIGIT_BIT 60
  ------------------
   32|       |
   33|  30.9k|   return MP_OKAY;
  ------------------
  |  |  161|  30.9k|#define MP_OKAY       0   /* no error */
  ------------------
   34|  30.9k|}

mp_add:
    8|  2.00M|{
    9|  2.00M|   mp_sign sa, sb;
   10|  2.00M|   mp_err err;
   11|       |
   12|       |   /* get sign of both inputs */
   13|  2.00M|   sa = a->sign;
   14|  2.00M|   sb = b->sign;
   15|       |
   16|       |   /* handle two cases, not four */
   17|  2.00M|   if (sa == sb) {
  ------------------
  |  Branch (17:8): [True: 1.29M, False: 712k]
  ------------------
   18|       |      /* both positive or both negative */
   19|       |      /* add their magnitudes, copy the sign */
   20|  1.29M|      c->sign = sa;
   21|  1.29M|      err = s_mp_add(a, b, c);
   22|  1.29M|   } 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|   712k|      if (mp_cmp_mag(a, b) == MP_LT) {
  ------------------
  |  |  154|   712k|#define MP_LT        -1   /* less than */
  ------------------
  |  Branch (27:11): [True: 712k, False: 57]
  ------------------
   28|   712k|         c->sign = sb;
   29|   712k|         err = s_mp_sub(b, a, c);
   30|   712k|      } else {
   31|     57|         c->sign = sa;
   32|     57|         err = s_mp_sub(a, b, c);
   33|     57|      }
   34|   712k|   }
   35|  2.00M|   return err;
   36|  2.00M|}

mp_add_d:
    8|   129k|{
    9|   129k|   mp_err     err;
   10|   129k|   int ix, oldused;
   11|   129k|   mp_digit *tmpa, *tmpc;
   12|       |
   13|       |   /* grow c as required */
   14|   129k|   if (c->alloc < (a->used + 1)) {
  ------------------
  |  Branch (14:8): [True: 8.39k, False: 121k]
  ------------------
   15|  8.39k|      if ((err = mp_grow(c, a->used + 1)) != MP_OKAY) {
  ------------------
  |  |  161|  8.39k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (15:11): [True: 0, False: 8.39k]
  ------------------
   16|      0|         return err;
   17|      0|      }
   18|  8.39k|   }
   19|       |
   20|       |   /* if a is negative and |a| >= b, call c = |a| - b */
   21|   129k|   if ((a->sign == MP_NEG) && ((a->used > 1) || (a->dp[0] >= b))) {
  ------------------
  |  |  152|   129k|#define MP_NEG        1   /* negative */
  ------------------
  |  Branch (21:8): [True: 0, False: 129k]
  |  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|   129k|   oldused = c->used;
   40|       |
   41|       |   /* source alias */
   42|   129k|   tmpa    = a->dp;
   43|       |
   44|       |   /* destination alias */
   45|   129k|   tmpc    = c->dp;
   46|       |
   47|       |   /* if a is positive */
   48|   129k|   if (a->sign == MP_ZPOS) {
  ------------------
  |  |  151|   129k|#define MP_ZPOS       0   /* positive integer */
  ------------------
  |  Branch (48:8): [True: 129k, False: 0]
  ------------------
   49|       |      /* add digits, mu is carry */
   50|   129k|      mp_digit mu = b;
   51|   950k|      for (ix = 0; ix < a->used; ix++) {
  ------------------
  |  Branch (51:20): [True: 821k, False: 129k]
  ------------------
   52|   821k|         *tmpc   = *tmpa++ + mu;
   53|   821k|         mu      = *tmpc >> MP_DIGIT_BIT;
  ------------------
  |  |   82|   821k|#   define MP_DIGIT_BIT 60
  ------------------
   54|   821k|         *tmpc++ &= MP_MASK;
  ------------------
  |  |  106|   821k|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|   821k|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
   55|   821k|      }
   56|       |      /* set final carry */
   57|   129k|      ix++;
   58|   129k|      *tmpc++  = mu;
   59|       |
   60|       |      /* setup size */
   61|   129k|      c->used = a->used + 1;
   62|   129k|   } 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|   129k|   c->sign = MP_ZPOS;
  ------------------
  |  |  151|   129k|#define MP_ZPOS       0   /* positive integer */
  ------------------
   81|       |
   82|       |   /* now zero to oldused */
   83|   129k|   MP_ZERO_DIGITS(tmpc, oldused - ix);
  ------------------
  |  |   89|   129k|#  define MP_ZERO_DIGITS(mem, digits)                   \
  |  |   90|   129k|do {                                                    \
  |  |   91|   129k|   int zd_ = (digits);                                  \
  |  |   92|   129k|   mp_digit* zm_ = (mem);                               \
  |  |   93|   129k|   while (zd_-- > 0) {                                  \
  |  |  ------------------
  |  |  |  Branch (93:11): [True: 0, False: 129k]
  |  |  ------------------
  |  |   94|      0|      *zm_++ = 0;                                       \
  |  |   95|      0|   }                                                    \
  |  |   96|   129k|} while (0)
  |  |  ------------------
  |  |  |  Branch (96:10): [Folded, False: 129k]
  |  |  ------------------
  ------------------
   84|   129k|   mp_clamp(c);
   85|       |
   86|   129k|   return MP_OKAY;
  ------------------
  |  |  161|   129k|#define MP_OKAY       0   /* no error */
  ------------------
   87|   129k|}

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

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

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

mp_cmp:
    8|  13.5M|{
    9|       |   /* compare based on sign */
   10|  13.5M|   if (a->sign != b->sign) {
  ------------------
  |  Branch (10:8): [True: 0, False: 13.5M]
  ------------------
   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|  13.5M|   if (a->sign == MP_NEG) {
  ------------------
  |  |  152|  13.5M|#define MP_NEG        1   /* negative */
  ------------------
  |  Branch (19:8): [True: 0, False: 13.5M]
  ------------------
   20|       |      /* if negative compare opposite direction */
   21|      0|      return mp_cmp_mag(b, a);
   22|  13.5M|   } else {
   23|  13.5M|      return mp_cmp_mag(a, b);
   24|  13.5M|   }
   25|  13.5M|}

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

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

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

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

mp_div:
   87|  57.6k|{
   88|  57.6k|   mp_int  q, x, y, t1, t2;
   89|  57.6k|   int     n, t, i, norm;
   90|  57.6k|   mp_sign neg;
   91|  57.6k|   mp_err  err;
   92|       |
   93|       |   /* is divisor zero ? */
   94|  57.6k|   if (MP_IS_ZERO(b)) {
  ------------------
  |  |  163|  57.6k|#define MP_IS_ZERO(a) ((a)->used == 0)
  |  |  ------------------
  |  |  |  Branch (163:23): [True: 0, False: 57.6k]
  |  |  ------------------
  ------------------
   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|  57.6k|   if (mp_cmp_mag(a, b) == MP_LT) {
  ------------------
  |  |  154|  57.6k|#define MP_LT        -1   /* less than */
  ------------------
  |  Branch (99:8): [True: 16.9k, False: 40.6k]
  ------------------
  100|  16.9k|      if (d != NULL) {
  ------------------
  |  Branch (100:11): [True: 16.9k, False: 0]
  ------------------
  101|  16.9k|         err = mp_copy(a, d);
  102|  16.9k|      } else {
  103|      0|         err = MP_OKAY;
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
  104|      0|      }
  105|  16.9k|      if (c != NULL) {
  ------------------
  |  Branch (105:11): [True: 0, False: 16.9k]
  ------------------
  106|      0|         mp_zero(c);
  107|      0|      }
  108|  16.9k|      return err;
  109|  16.9k|   }
  110|       |
  111|  40.6k|   if ((err = mp_init_size(&q, a->used + 2)) != MP_OKAY) {
  ------------------
  |  |  161|  40.6k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (111:8): [True: 0, False: 40.6k]
  ------------------
  112|      0|      return err;
  113|      0|   }
  114|  40.6k|   q.used = a->used + 2;
  115|       |
  116|  40.6k|   if ((err = mp_init(&t1)) != MP_OKAY)                           goto LBL_Q;
  ------------------
  |  |  161|  40.6k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (116:8): [True: 0, False: 40.6k]
  ------------------
  117|       |
  118|  40.6k|   if ((err = mp_init(&t2)) != MP_OKAY)                           goto LBL_T1;
  ------------------
  |  |  161|  40.6k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (118:8): [True: 0, False: 40.6k]
  ------------------
  119|       |
  120|  40.6k|   if ((err = mp_init_copy(&x, a)) != MP_OKAY)                    goto LBL_T2;
  ------------------
  |  |  161|  40.6k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (120:8): [True: 0, False: 40.6k]
  ------------------
  121|       |
  122|  40.6k|   if ((err = mp_init_copy(&y, b)) != MP_OKAY)                    goto LBL_X;
  ------------------
  |  |  161|  40.6k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (122:8): [True: 0, False: 40.6k]
  ------------------
  123|       |
  124|       |   /* fix the sign */
  125|  40.6k|   neg = (a->sign == b->sign) ? MP_ZPOS : MP_NEG;
  ------------------
  |  |  151|  40.6k|#define MP_ZPOS       0   /* positive integer */
  ------------------
                 neg = (a->sign == b->sign) ? MP_ZPOS : MP_NEG;
  ------------------
  |  |  152|  40.6k|#define MP_NEG        1   /* negative */
  ------------------
  |  Branch (125:10): [True: 40.6k, False: 0]
  ------------------
  126|  40.6k|   x.sign = y.sign = MP_ZPOS;
  ------------------
  |  |  151|  40.6k|#define MP_ZPOS       0   /* positive integer */
  ------------------
  127|       |
  128|       |   /* normalize both x and y, ensure that y >= b/2, [b == 2**MP_DIGIT_BIT] */
  129|  40.6k|   norm = mp_count_bits(&y) % MP_DIGIT_BIT;
  ------------------
  |  |   82|  40.6k|#   define MP_DIGIT_BIT 60
  ------------------
  130|  40.6k|   if (norm < (MP_DIGIT_BIT - 1)) {
  ------------------
  |  |   82|  40.6k|#   define MP_DIGIT_BIT 60
  ------------------
  |  Branch (130:8): [True: 40.6k, False: 0]
  ------------------
  131|  40.6k|      norm = (MP_DIGIT_BIT - 1) - norm;
  ------------------
  |  |   82|  40.6k|#   define MP_DIGIT_BIT 60
  ------------------
  132|  40.6k|      if ((err = mp_mul_2d(&x, norm, &x)) != MP_OKAY)             goto LBL_Y;
  ------------------
  |  |  161|  40.6k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (132:11): [True: 0, False: 40.6k]
  ------------------
  133|  40.6k|      if ((err = mp_mul_2d(&y, norm, &y)) != MP_OKAY)             goto LBL_Y;
  ------------------
  |  |  161|  40.6k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (133:11): [True: 0, False: 40.6k]
  ------------------
  134|  40.6k|   } 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|  40.6k|   n = x.used - 1;
  140|  40.6k|   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|  40.6k|   if ((err = mp_lshd(&y, n - t)) != MP_OKAY)                     goto LBL_Y;
  ------------------
  |  |  161|  40.6k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (144:8): [True: 0, False: 40.6k]
  ------------------
  145|       |
  146|  44.7k|   while (mp_cmp(&x, &y) != MP_LT) {
  ------------------
  |  |  154|  44.7k|#define MP_LT        -1   /* less than */
  ------------------
  |  Branch (146:11): [True: 4.06k, False: 40.6k]
  ------------------
  147|  4.06k|      ++(q.dp[n - t]);
  148|  4.06k|      if ((err = mp_sub(&x, &y, &x)) != MP_OKAY)                  goto LBL_Y;
  ------------------
  |  |  161|  4.06k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (148:11): [True: 0, False: 4.06k]
  ------------------
  149|  4.06k|   }
  150|       |
  151|       |   /* reset y by shifting it back down */
  152|  40.6k|   mp_rshd(&y, n - t);
  153|       |
  154|       |   /* step 3. for i from n down to (t + 1) */
  155|  1.22M|   for (i = n; i >= (t + 1); i--) {
  ------------------
  |  Branch (155:16): [True: 1.18M, False: 40.6k]
  ------------------
  156|  1.18M|      if (i > x.used) {
  ------------------
  |  Branch (156:11): [True: 0, False: 1.18M]
  ------------------
  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|  1.18M|      if (x.dp[i] == y.dp[t]) {
  ------------------
  |  Branch (162:11): [True: 0, False: 1.18M]
  ------------------
  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|  1.18M|      } else {
  165|  1.18M|         mp_word tmp;
  166|  1.18M|         tmp = (mp_word)x.dp[i] << (mp_word)MP_DIGIT_BIT;
  ------------------
  |  |   82|  1.18M|#   define MP_DIGIT_BIT 60
  ------------------
  167|  1.18M|         tmp |= (mp_word)x.dp[i - 1];
  168|  1.18M|         tmp /= (mp_word)y.dp[t];
  169|  1.18M|         if (tmp > (mp_word)MP_MASK) {
  ------------------
  |  |  106|  1.18M|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|  1.18M|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
  |  Branch (169:14): [True: 0, False: 1.18M]
  ------------------
  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|  1.18M|         q.dp[(i - t) - 1] = (mp_digit)(tmp & (mp_word)MP_MASK);
  ------------------
  |  |  106|  1.18M|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|  1.18M|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
  173|  1.18M|      }
  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|  1.18M|      q.dp[(i - t) - 1] = (q.dp[(i - t) - 1] + 1uL) & (mp_digit)MP_MASK;
  ------------------
  |  |  106|  1.18M|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|  1.18M|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
  181|  2.51M|      do {
  182|  2.51M|         q.dp[(i - t) - 1] = (q.dp[(i - t) - 1] - 1uL) & (mp_digit)MP_MASK;
  ------------------
  |  |  106|  2.51M|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|  2.51M|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
  183|       |
  184|       |         /* find left hand */
  185|  2.51M|         mp_zero(&t1);
  186|  2.51M|         t1.dp[0] = ((t - 1) < 0) ? 0u : y.dp[t - 1];
  ------------------
  |  Branch (186:21): [True: 0, False: 2.51M]
  ------------------
  187|  2.51M|         t1.dp[1] = y.dp[t];
  188|  2.51M|         t1.used = 2;
  189|  2.51M|         if ((err = mp_mul_d(&t1, q.dp[(i - t) - 1], &t1)) != MP_OKAY) goto LBL_Y;
  ------------------
  |  |  161|  2.51M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (189:14): [True: 0, False: 2.51M]
  ------------------
  190|       |
  191|       |         /* find right hand */
  192|  2.51M|         t2.dp[0] = ((i - 2) < 0) ? 0u : x.dp[i - 2];
  ------------------
  |  Branch (192:21): [True: 0, False: 2.51M]
  ------------------
  193|  2.51M|         t2.dp[1] = x.dp[i - 1]; /* i >= 1 always holds */
  194|  2.51M|         t2.dp[2] = x.dp[i];
  195|  2.51M|         t2.used = 3;
  196|  2.51M|      } while (mp_cmp_mag(&t1, &t2) == MP_GT);
  ------------------
  |  |  156|  2.51M|#define MP_GT         1   /* greater than */
  ------------------
  |  Branch (196:16): [True: 1.32M, False: 1.18M]
  ------------------
  197|       |
  198|       |      /* step 3.3 x = x - q{i-t-1} * y * b**{i-t-1} */
  199|  1.18M|      if ((err = mp_mul_d(&y, q.dp[(i - t) - 1], &t1)) != MP_OKAY) goto LBL_Y;
  ------------------
  |  |  161|  1.18M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (199:11): [True: 0, False: 1.18M]
  ------------------
  200|       |
  201|  1.18M|      if ((err = mp_lshd(&t1, (i - t) - 1)) != MP_OKAY)           goto LBL_Y;
  ------------------
  |  |  161|  1.18M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (201:11): [True: 0, False: 1.18M]
  ------------------
  202|       |
  203|  1.18M|      if ((err = mp_sub(&x, &t1, &x)) != MP_OKAY)                 goto LBL_Y;
  ------------------
  |  |  161|  1.18M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (203:11): [True: 0, False: 1.18M]
  ------------------
  204|       |
  205|       |      /* if x < 0 then { x = x + y*b**{i-t-1}; q{i-t-1} -= 1; } */
  206|  1.18M|      if (x.sign == MP_NEG) {
  ------------------
  |  |  152|  1.18M|#define MP_NEG        1   /* negative */
  ------------------
  |  Branch (206:11): [True: 0, False: 1.18M]
  ------------------
  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|  1.18M|   }
  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|  40.6k|   x.sign = (x.used == 0) ? MP_ZPOS : a->sign;
  ------------------
  |  |  151|      0|#define MP_ZPOS       0   /* positive integer */
  ------------------
  |  Branch (220:13): [True: 0, False: 40.6k]
  ------------------
  221|       |
  222|  40.6k|   if (c != NULL) {
  ------------------
  |  Branch (222:8): [True: 0, False: 40.6k]
  ------------------
  223|      0|      mp_clamp(&q);
  224|      0|      mp_exch(&q, c);
  225|      0|      c->sign = neg;
  226|      0|   }
  227|       |
  228|  40.6k|   if (d != NULL) {
  ------------------
  |  Branch (228:8): [True: 40.6k, False: 0]
  ------------------
  229|  40.6k|      if ((err = mp_div_2d(&x, norm, &x, NULL)) != MP_OKAY)       goto LBL_Y;
  ------------------
  |  |  161|  40.6k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (229:11): [True: 0, False: 40.6k]
  ------------------
  230|  40.6k|      mp_exch(&x, d);
  231|  40.6k|   }
  232|       |
  233|  40.6k|   err = MP_OKAY;
  ------------------
  |  |  161|  40.6k|#define MP_OKAY       0   /* no error */
  ------------------
  234|       |
  235|  40.6k|LBL_Y:
  236|  40.6k|   mp_clear(&y);
  237|  40.6k|LBL_X:
  238|  40.6k|   mp_clear(&x);
  239|  40.6k|LBL_T2:
  240|  40.6k|   mp_clear(&t2);
  241|  40.6k|LBL_T1:
  242|  40.6k|   mp_clear(&t1);
  243|  40.6k|LBL_Q:
  244|  40.6k|   mp_clear(&q);
  245|  40.6k|   return err;
  246|  40.6k|}

mp_div_2:
    8|  49.2M|{
    9|  49.2M|   int     x, oldused;
   10|  49.2M|   mp_digit r, rr, *tmpa, *tmpb;
   11|  49.2M|   mp_err err;
   12|       |
   13|       |   /* copy */
   14|  49.2M|   if (b->alloc < a->used) {
  ------------------
  |  Branch (14:8): [True: 6.94k, False: 49.2M]
  ------------------
   15|  6.94k|      if ((err = mp_grow(b, a->used)) != MP_OKAY) {
  ------------------
  |  |  161|  6.94k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (15:11): [True: 0, False: 6.94k]
  ------------------
   16|      0|         return err;
   17|      0|      }
   18|  6.94k|   }
   19|       |
   20|  49.2M|   oldused = b->used;
   21|  49.2M|   b->used = a->used;
   22|       |
   23|       |   /* source alias */
   24|  49.2M|   tmpa = a->dp + b->used - 1;
   25|       |
   26|       |   /* dest alias */
   27|  49.2M|   tmpb = b->dp + b->used - 1;
   28|       |
   29|       |   /* carry */
   30|  49.2M|   r = 0;
   31|  1.33G|   for (x = b->used - 1; x >= 0; x--) {
  ------------------
  |  Branch (31:26): [True: 1.28G, False: 49.2M]
  ------------------
   32|       |      /* get the carry for the next iteration */
   33|  1.28G|      rr = *tmpa & 1u;
   34|       |
   35|       |      /* shift the current digit, add in carry and store */
   36|  1.28G|      *tmpb-- = (*tmpa-- >> 1) | (r << (MP_DIGIT_BIT - 1));
  ------------------
  |  |   82|  1.28G|#   define MP_DIGIT_BIT 60
  ------------------
   37|       |
   38|       |      /* forward carry to next iteration */
   39|  1.28G|      r = rr;
   40|  1.28G|   }
   41|       |
   42|       |   /* zero excess digits */
   43|  49.2M|   MP_ZERO_DIGITS(b->dp + b->used, oldused - b->used);
  ------------------
  |  |   89|  49.2M|#  define MP_ZERO_DIGITS(mem, digits)                   \
  |  |   90|  49.2M|do {                                                    \
  |  |   91|  49.2M|   int zd_ = (digits);                                  \
  |  |   92|  49.2M|   mp_digit* zm_ = (mem);                               \
  |  |   93|  49.2M|   while (zd_-- > 0) {                                  \
  |  |  ------------------
  |  |  |  Branch (93:11): [True: 0, False: 49.2M]
  |  |  ------------------
  |  |   94|      0|      *zm_++ = 0;                                       \
  |  |   95|      0|   }                                                    \
  |  |   96|  49.2M|} while (0)
  |  |  ------------------
  |  |  |  Branch (96:10): [Folded, False: 49.2M]
  |  |  ------------------
  ------------------
   44|       |
   45|  49.2M|   b->sign = a->sign;
   46|  49.2M|   mp_clamp(b);
   47|  49.2M|   return MP_OKAY;
  ------------------
  |  |  161|  49.2M|#define MP_OKAY       0   /* no error */
  ------------------
   48|  49.2M|}

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

mp_dr_is_modulus:
    8|  30.6k|{
    9|  30.6k|   int ix;
   10|       |
   11|       |   /* must be at least two digits */
   12|  30.6k|   if (a->used < 2) {
  ------------------
  |  Branch (12:8): [True: 0, False: 30.6k]
  ------------------
   13|      0|      return MP_NO;
  ------------------
  |  |  159|      0|#define MP_NO         0
  ------------------
   14|      0|   }
   15|       |
   16|       |   /* must be of the form b**k - a [a <= b] so all
   17|       |    * but the first digit must be equal to -1 (mod b).
   18|       |    */
   19|  30.6k|   for (ix = 1; ix < a->used; ix++) {
  ------------------
  |  Branch (19:17): [True: 30.6k, False: 0]
  ------------------
   20|  30.6k|      if (a->dp[ix] != MP_MASK) {
  ------------------
  |  |  106|  30.6k|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|  30.6k|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
  |  Branch (20:11): [True: 30.6k, False: 0]
  ------------------
   21|  30.6k|         return MP_NO;
  ------------------
  |  |  159|  30.6k|#define MP_NO         0
  ------------------
   22|  30.6k|      }
   23|  30.6k|   }
   24|      0|   return MP_YES;
  ------------------
  |  |  158|      0|#define MP_YES        1
  ------------------
   25|  30.6k|}

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

mp_exptmod:
   12|  30.6k|{
   13|  30.6k|   int dr;
   14|       |
   15|       |   /* modulus P must be positive */
   16|  30.6k|   if (P->sign == MP_NEG) {
  ------------------
  |  |  152|  30.6k|#define MP_NEG        1   /* negative */
  ------------------
  |  Branch (16:8): [True: 0, False: 30.6k]
  ------------------
   17|      0|      return MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
   18|      0|   }
   19|       |
   20|       |   /* if exponent X is negative we have to recurse */
   21|  30.6k|   if (X->sign == MP_NEG) {
  ------------------
  |  |  152|  30.6k|#define MP_NEG        1   /* negative */
  ------------------
  |  Branch (21:8): [True: 0, False: 30.6k]
  ------------------
   22|      0|      mp_int tmpG, tmpX;
   23|      0|      mp_err err;
   24|       |
   25|      0|      if (!MP_HAS(MP_INVMOD)) {
  ------------------
  |  |  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 (25:11): [Folded, False: 0]
  ------------------
   26|      0|         return MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
   27|      0|      }
   28|       |
   29|      0|      if ((err = mp_init_multi(&tmpG, &tmpX, NULL)) != MP_OKAY) {
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (29:11): [True: 0, False: 0]
  ------------------
   30|      0|         return err;
   31|      0|      }
   32|       |
   33|       |      /* first compute 1/G mod P */
   34|      0|      if ((err = mp_invmod(G, P, &tmpG)) != MP_OKAY) {
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (34:11): [True: 0, False: 0]
  ------------------
   35|      0|         goto LBL_ERR;
   36|      0|      }
   37|       |
   38|       |      /* now get |X| */
   39|      0|      if ((err = mp_abs(X, &tmpX)) != MP_OKAY) {
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (39:11): [True: 0, False: 0]
  ------------------
   40|      0|         goto LBL_ERR;
   41|      0|      }
   42|       |
   43|       |      /* and now compute (1/G)**|X| instead of G**X [X < 0] */
   44|      0|      err = mp_exptmod(&tmpG, &tmpX, P, Y);
   45|      0|LBL_ERR:
   46|      0|      mp_clear_multi(&tmpG, &tmpX, NULL);
   47|      0|      return err;
   48|      0|   }
   49|       |
   50|       |   /* modified diminished radix reduction */
   51|  30.6k|   if (MP_HAS(MP_REDUCE_IS_2K_L) && MP_HAS(MP_REDUCE_2K_L) && MP_HAS(S_MP_EXPTMOD) &&
  ------------------
  |  |  150|  61.2k|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|  30.6k|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|  30.6k|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [True: 0, Folded]
  |  |  ------------------
  ------------------
                 if (MP_HAS(MP_REDUCE_IS_2K_L) && MP_HAS(MP_REDUCE_2K_L) && MP_HAS(S_MP_EXPTMOD) &&
  ------------------
  |  |  150|  30.6k|#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]
  |  |  ------------------
  ------------------
                 if (MP_HAS(MP_REDUCE_IS_2K_L) && MP_HAS(MP_REDUCE_2K_L) && MP_HAS(S_MP_EXPTMOD) &&
  ------------------
  |  |  150|  30.6k|#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]
  |  |  ------------------
  ------------------
   52|  30.6k|       (mp_reduce_is_2k_l(P) == MP_YES)) {
  ------------------
  |  |  158|  30.6k|#define MP_YES        1
  ------------------
  |  Branch (52:8): [True: 0, False: 30.6k]
  ------------------
   53|      0|      return s_mp_exptmod(G, X, P, Y, 1);
   54|      0|   }
   55|       |
   56|       |   /* is it a DR modulus? default to no */
   57|  30.6k|   dr = (MP_HAS(MP_DR_IS_MODULUS) && (mp_dr_is_modulus(P) == MP_YES)) ? 1 : 0;
  ------------------
  |  |  150|  61.2k|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|  30.6k|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|  30.6k|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [True: 30.6k, Folded]
  |  |  ------------------
  ------------------
                 dr = (MP_HAS(MP_DR_IS_MODULUS) && (mp_dr_is_modulus(P) == MP_YES)) ? 1 : 0;
  ------------------
  |  |  158|  30.6k|#define MP_YES        1
  ------------------
  |  Branch (57:38): [True: 0, False: 30.6k]
  ------------------
   58|       |
   59|       |   /* if not, is it a unrestricted DR modulus? */
   60|  30.6k|   if (MP_HAS(MP_REDUCE_IS_2K) && (dr == 0)) {
  ------------------
  |  |  150|  61.2k|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|  30.6k|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|  30.6k|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [True: 30.6k, Folded]
  |  |  ------------------
  ------------------
  |  Branch (60:35): [True: 30.6k, False: 0]
  ------------------
   61|  30.6k|      dr = (mp_reduce_is_2k(P) == MP_YES) ? 2 : 0;
  ------------------
  |  |  158|  30.6k|#define MP_YES        1
  ------------------
  |  Branch (61:12): [True: 0, False: 30.6k]
  ------------------
   62|  30.6k|   }
   63|       |
   64|       |   /* if the modulus is odd or dr != 0 use the montgomery method */
   65|  30.6k|   if (MP_HAS(S_MP_EXPTMOD_FAST) && (MP_IS_ODD(P) || (dr != 0))) {
  ------------------
  |  |  150|  61.2k|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|  30.6k|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|  30.6k|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [True: 30.6k, Folded]
  |  |  ------------------
  ------------------
                 if (MP_HAS(S_MP_EXPTMOD_FAST) && (MP_IS_ODD(P) || (dr != 0))) {
  ------------------
  |  |  165|  61.2k|#define MP_IS_ODD(a)  (((a)->used > 0) && (((a)->dp[0] & 1u) == 1u))
  |  |  ------------------
  |  |  |  Branch (165:24): [True: 30.6k, False: 0]
  |  |  |  Branch (165:43): [True: 30.6k, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (65:54): [True: 0, False: 0]
  ------------------
   66|  30.6k|      return s_mp_exptmod_fast(G, X, P, Y, dr);
   67|  30.6k|   } else if (MP_HAS(S_MP_EXPTMOD)) {
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
   68|       |      /* otherwise use the generic Barrett reduction technique */
   69|      0|      return s_mp_exptmod(G, X, P, Y, 0);
   70|      0|   } else {
   71|       |      /* no exptmod for evens */
   72|      0|      return MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
   73|      0|   }
   74|  30.6k|}

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

mp_grow:
    8|  2.03M|{
    9|  2.03M|   int     i;
   10|  2.03M|   mp_digit *tmp;
   11|       |
   12|  2.03M|   if (size < 0) {
  ------------------
  |  Branch (12:8): [True: 0, False: 2.03M]
  ------------------
   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|  2.03M|   if (a->alloc < size) {
  ------------------
  |  Branch (17:8): [True: 2.00M, False: 30.9k]
  ------------------
   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|  2.00M|      tmp = (mp_digit *) MP_REALLOC(a->dp,
  ------------------
  |  | 1325|  2.00M|#define MP_REALLOC   m_realloc_ltm
  ------------------
   25|  2.00M|                                    (size_t)a->alloc * sizeof(mp_digit),
   26|  2.00M|                                    (size_t)size * sizeof(mp_digit));
   27|  2.00M|      if (tmp == NULL) {
  ------------------
  |  Branch (27:11): [True: 0, False: 2.00M]
  ------------------
   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|  2.00M|      a->dp = tmp;
   34|       |
   35|       |      /* zero excess digits */
   36|  2.00M|      i        = a->alloc;
   37|  2.00M|      a->alloc = size;
   38|  2.00M|      MP_ZERO_DIGITS(a->dp + i, a->alloc - i);
  ------------------
  |  |   89|  2.00M|#  define MP_ZERO_DIGITS(mem, digits)                   \
  |  |   90|  2.00M|do {                                                    \
  |  |   91|  2.00M|   int zd_ = (digits);                                  \
  |  |   92|  2.00M|   mp_digit* zm_ = (mem);                               \
  |  |   93|  57.7M|   while (zd_-- > 0) {                                  \
  |  |  ------------------
  |  |  |  Branch (93:11): [True: 55.7M, False: 2.00M]
  |  |  ------------------
  |  |   94|  55.7M|      *zm_++ = 0;                                       \
  |  |   95|  55.7M|   }                                                    \
  |  |   96|  2.00M|} while (0)
  |  |  ------------------
  |  |  |  Branch (96:10): [Folded, False: 2.00M]
  |  |  ------------------
  ------------------
   39|  2.00M|   }
   40|  2.03M|   return MP_OKAY;
  ------------------
  |  |  161|  2.03M|#define MP_OKAY       0   /* no error */
  ------------------
   41|  2.03M|}

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

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

mp_init_multi:
    9|  8.67k|{
   10|  8.67k|   mp_err err = MP_OKAY;      /* Assume ok until proven otherwise */
  ------------------
  |  |  161|  8.67k|#define MP_OKAY       0   /* no error */
  ------------------
   11|  8.67k|   int n = 0;                 /* Number of ok inits */
   12|  8.67k|   mp_int *cur_arg = mp;
   13|  8.67k|   va_list args;
   14|       |
   15|  8.67k|   va_start(args, mp);        /* init args to next argument from caller */
   16|  60.7k|   while (cur_arg != NULL) {
  ------------------
  |  Branch (16:11): [True: 52.0k, False: 8.67k]
  ------------------
   17|  52.0k|      if (mp_init(cur_arg) != MP_OKAY) {
  ------------------
  |  |  161|  52.0k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (17:11): [True: 0, False: 52.0k]
  ------------------
   18|       |         /* Oops - error! Back-track and mp_clear what we already
   19|       |            succeeded in init-ing, then return error.
   20|       |         */
   21|      0|         va_list clean_args;
   22|       |
   23|       |         /* now start cleaning up */
   24|      0|         cur_arg = mp;
   25|      0|         va_start(clean_args, mp);
   26|      0|         while (n-- != 0) {
  ------------------
  |  Branch (26:17): [True: 0, False: 0]
  ------------------
   27|      0|            mp_clear(cur_arg);
   28|      0|            cur_arg = va_arg(clean_args, mp_int *);
   29|      0|         }
   30|      0|         va_end(clean_args);
   31|      0|         err = MP_MEM;
  ------------------
  |  |  163|      0|#define MP_MEM        -2  /* out of mem */
  ------------------
   32|      0|         break;
   33|      0|      }
   34|  52.0k|      n++;
   35|  52.0k|      cur_arg = va_arg(args, mp_int *);
   36|  52.0k|   }
   37|       |   va_end(args);
   38|  8.67k|   return err;                /* Assumed ok, if error flagged above. */
   39|  8.67k|}

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

mp_invmod:
    8|  8.67k|{
    9|       |   /* b cannot be negative and has to be >1 */
   10|  8.67k|   if ((b->sign == MP_NEG) || (mp_cmp_d(b, 1uL) != MP_GT)) {
  ------------------
  |  |  152|  8.67k|#define MP_NEG        1   /* negative */
  ------------------
                 if ((b->sign == MP_NEG) || (mp_cmp_d(b, 1uL) != MP_GT)) {
  ------------------
  |  |  156|  8.67k|#define MP_GT         1   /* greater than */
  ------------------
  |  Branch (10:8): [True: 0, False: 8.67k]
  |  Branch (10:31): [True: 0, False: 8.67k]
  ------------------
   11|      0|      return MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
   12|      0|   }
   13|       |
   14|       |   /* if the modulus is odd we can use a faster routine instead */
   15|  8.67k|   if (MP_HAS(S_MP_INVMOD_FAST) && MP_IS_ODD(b)) {
  ------------------
  |  |  150|  17.3k|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|  8.67k|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|  8.67k|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [True: 8.67k, Folded]
  |  |  ------------------
  ------------------
                 if (MP_HAS(S_MP_INVMOD_FAST) && MP_IS_ODD(b)) {
  ------------------
  |  |  165|  8.67k|#define MP_IS_ODD(a)  (((a)->used > 0) && (((a)->dp[0] & 1u) == 1u))
  |  |  ------------------
  |  |  |  Branch (165:24): [True: 8.67k, False: 0]
  |  |  |  Branch (165:43): [True: 8.67k, False: 0]
  |  |  ------------------
  ------------------
   16|  8.67k|      return s_mp_invmod_fast(a, b, c);
   17|  8.67k|   }
   18|       |
   19|      0|   return MP_HAS(S_MP_INVMOD_SLOW)
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
   20|      0|          ? s_mp_invmod_slow(a, b, c)
   21|      0|          : MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
   22|  8.67k|}

mp_lshd:
    8|  1.22M|{
    9|  1.22M|   int x;
   10|  1.22M|   mp_err err;
   11|  1.22M|   mp_digit *top, *bottom;
   12|       |
   13|       |   /* if its less than zero return */
   14|  1.22M|   if (b <= 0) {
  ------------------
  |  Branch (14:8): [True: 40.6k, False: 1.18M]
  ------------------
   15|  40.6k|      return MP_OKAY;
  ------------------
  |  |  161|  40.6k|#define MP_OKAY       0   /* no error */
  ------------------
   16|  40.6k|   }
   17|       |   /* no need to shift 0 around */
   18|  1.18M|   if (MP_IS_ZERO(a)) {
  ------------------
  |  |  163|  1.18M|#define MP_IS_ZERO(a) ((a)->used == 0)
  |  |  ------------------
  |  |  |  Branch (163:23): [True: 0, False: 1.18M]
  |  |  ------------------
  ------------------
   19|      0|      return MP_OKAY;
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
   20|      0|   }
   21|       |
   22|       |   /* grow to fit the new digits */
   23|  1.18M|   if (a->alloc < (a->used + b)) {
  ------------------
  |  Branch (23:8): [True: 73.3k, False: 1.11M]
  ------------------
   24|  73.3k|      if ((err = mp_grow(a, a->used + b)) != MP_OKAY) {
  ------------------
  |  |  161|  73.3k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (24:11): [True: 0, False: 73.3k]
  ------------------
   25|      0|         return err;
   26|      0|      }
   27|  73.3k|   }
   28|       |
   29|       |   /* increment the used by the shift amount then copy upwards */
   30|  1.18M|   a->used += b;
   31|       |
   32|       |   /* top */
   33|  1.18M|   top = a->dp + a->used - 1;
   34|       |
   35|       |   /* base */
   36|  1.18M|   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|  43.7M|   for (x = a->used - 1; x >= b; x--) {
  ------------------
  |  Branch (42:26): [True: 42.5M, False: 1.18M]
  ------------------
   43|  42.5M|      *top-- = *bottom--;
   44|  42.5M|   }
   45|       |
   46|       |   /* zero the lower digits */
   47|  1.18M|   MP_ZERO_DIGITS(a->dp, b);
  ------------------
  |  |   89|  1.18M|#  define MP_ZERO_DIGITS(mem, digits)                   \
  |  |   90|  1.18M|do {                                                    \
  |  |   91|  1.18M|   int zd_ = (digits);                                  \
  |  |   92|  1.18M|   mp_digit* zm_ = (mem);                               \
  |  |   93|  22.1M|   while (zd_-- > 0) {                                  \
  |  |  ------------------
  |  |  |  Branch (93:11): [True: 20.9M, False: 1.18M]
  |  |  ------------------
  |  |   94|  20.9M|      *zm_++ = 0;                                       \
  |  |   95|  20.9M|   }                                                    \
  |  |   96|  1.18M|} while (0)
  |  |  ------------------
  |  |  |  Branch (96:10): [Folded, False: 1.18M]
  |  |  ------------------
  ------------------
   48|       |
   49|  1.18M|   return MP_OKAY;
  ------------------
  |  |  161|  1.18M|#define MP_OKAY       0   /* no error */
  ------------------
   50|  1.18M|}

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

mp_montgomery_calc_normalization:
   13|  30.9k|{
   14|  30.9k|   int    x, bits;
   15|  30.9k|   mp_err err;
   16|       |
   17|       |   /* how many bits of last digit does b use */
   18|  30.9k|   bits = mp_count_bits(b) % MP_DIGIT_BIT;
  ------------------
  |  |   82|  30.9k|#   define MP_DIGIT_BIT 60
  ------------------
   19|       |
   20|  30.9k|   if (b->used > 1) {
  ------------------
  |  Branch (20:8): [True: 30.9k, False: 0]
  ------------------
   21|  30.9k|      if ((err = mp_2expt(a, ((b->used - 1) * MP_DIGIT_BIT) + bits - 1)) != MP_OKAY) {
  ------------------
  |  |   82|  30.9k|#   define MP_DIGIT_BIT 60
  ------------------
                    if ((err = mp_2expt(a, ((b->used - 1) * MP_DIGIT_BIT) + bits - 1)) != MP_OKAY) {
  ------------------
  |  |  161|  30.9k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (21:11): [True: 0, False: 30.9k]
  ------------------
   22|      0|         return err;
   23|      0|      }
   24|  30.9k|   } else {
   25|      0|      mp_set(a, 1uL);
   26|      0|      bits = 1;
   27|      0|   }
   28|       |
   29|       |
   30|       |   /* now compute C = A * B mod b */
   31|  1.66M|   for (x = bits - 1; x < (int)MP_DIGIT_BIT; x++) {
  ------------------
  |  |   82|  1.66M|#   define MP_DIGIT_BIT 60
  ------------------
  |  Branch (31:23): [True: 1.63M, False: 30.9k]
  ------------------
   32|  1.63M|      if ((err = mp_mul_2(a, a)) != MP_OKAY) {
  ------------------
  |  |  161|  1.63M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (32:11): [True: 0, False: 1.63M]
  ------------------
   33|      0|         return err;
   34|      0|      }
   35|  1.63M|      if (mp_cmp_mag(a, b) != MP_LT) {
  ------------------
  |  |  154|  1.63M|#define MP_LT        -1   /* less than */
  ------------------
  |  Branch (35:11): [True: 417k, False: 1.21M]
  ------------------
   36|   417k|         if ((err = s_mp_sub(a, b, a)) != MP_OKAY) {
  ------------------
  |  |  161|   417k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (36:14): [True: 0, False: 417k]
  ------------------
   37|      0|            return err;
   38|      0|         }
   39|   417k|      }
   40|  1.63M|   }
   41|       |
   42|  30.9k|   return MP_OKAY;
  ------------------
  |  |  161|  30.9k|#define MP_OKAY       0   /* no error */
  ------------------
   43|  30.9k|}

mp_montgomery_reduce:
    8|  3.09M|{
    9|  3.09M|   int      ix, digs;
   10|  3.09M|   mp_err   err;
   11|  3.09M|   mp_digit mu;
   12|       |
   13|       |   /* can the fast reduction [comba] method be used?
   14|       |    *
   15|       |    * Note that unlike in mul you're safely allowed *less*
   16|       |    * than the available columns [255 per default] since carries
   17|       |    * are fixed up in the inner loop.
   18|       |    */
   19|  3.09M|   digs = (n->used * 2) + 1;
   20|  3.09M|   if ((digs < MP_WARRAY) &&
  ------------------
  |  |  172|  3.09M|#define MP_WARRAY PRIVATE_MP_WARRAY
  |  |  ------------------
  |  |  |  |  203|  3.09M|#define PRIVATE_MP_WARRAY (int)(1uLL << (((CHAR_BIT * sizeof(private_mp_word)) - (2 * MP_DIGIT_BIT)) + 1))
  |  |  |  |  ------------------
  |  |  |  |  |  |   82|  3.09M|#   define MP_DIGIT_BIT 60
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (20:8): [True: 3.09M, False: 0]
  ------------------
   21|  3.09M|       (x->used <= MP_WARRAY) &&
  ------------------
  |  |  172|  3.09M|#define MP_WARRAY PRIVATE_MP_WARRAY
  |  |  ------------------
  |  |  |  |  203|  3.09M|#define PRIVATE_MP_WARRAY (int)(1uLL << (((CHAR_BIT * sizeof(private_mp_word)) - (2 * MP_DIGIT_BIT)) + 1))
  |  |  |  |  ------------------
  |  |  |  |  |  |   82|  3.09M|#   define MP_DIGIT_BIT 60
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (21:8): [True: 3.09M, False: 0]
  ------------------
   22|  3.09M|       (n->used < MP_MAXFAST)) {
  ------------------
  |  |  168|  3.09M|#define MP_MAXFAST              (int)(1uL << (MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT)))
  |  |  ------------------
  |  |  |  |  167|  3.09M|#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|  3.09M|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
  |  Branch (22:8): [True: 3.09M, False: 0]
  ------------------
   23|  3.09M|      return s_mp_montgomery_reduce_fast(x, n, rho);
   24|  3.09M|   }
   25|       |
   26|       |   /* grow the input as required */
   27|      0|   if (x->alloc < digs) {
  ------------------
  |  Branch (27:8): [True: 0, False: 0]
  ------------------
   28|      0|      if ((err = mp_grow(x, digs)) != 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|      0|   x->used = digs;
   33|       |
   34|      0|   for (ix = 0; ix < n->used; ix++) {
  ------------------
  |  Branch (34:17): [True: 0, False: 0]
  ------------------
   35|       |      /* mu = ai * rho mod b
   36|       |       *
   37|       |       * The value of rho must be precalculated via
   38|       |       * montgomery_setup() such that
   39|       |       * it equals -1/n0 mod b this allows the
   40|       |       * following inner loop to reduce the
   41|       |       * input one digit at a time
   42|       |       */
   43|      0|      mu = (mp_digit)(((mp_word)x->dp[ix] * (mp_word)rho) & 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
  |  |  ------------------
  ------------------
   44|       |
   45|       |      /* a = a + mu * m * b**i */
   46|      0|      {
   47|      0|         int iy;
   48|      0|         mp_digit *tmpn, *tmpx, u;
   49|      0|         mp_word r;
   50|       |
   51|       |         /* alias for digits of the modulus */
   52|      0|         tmpn = n->dp;
   53|       |
   54|       |         /* alias for the digits of x [the input] */
   55|      0|         tmpx = x->dp + ix;
   56|       |
   57|       |         /* set the carry to zero */
   58|      0|         u = 0;
   59|       |
   60|       |         /* Multiply and add in place */
   61|      0|         for (iy = 0; iy < n->used; iy++) {
  ------------------
  |  Branch (61:23): [True: 0, False: 0]
  ------------------
   62|       |            /* compute product and sum */
   63|      0|            r       = ((mp_word)mu * (mp_word)*tmpn++) +
   64|      0|                      (mp_word)u + (mp_word)*tmpx;
   65|       |
   66|       |            /* get carry */
   67|      0|            u       = (mp_digit)(r >> (mp_word)MP_DIGIT_BIT);
  ------------------
  |  |   82|      0|#   define MP_DIGIT_BIT 60
  ------------------
   68|       |
   69|       |            /* fix digit */
   70|      0|            *tmpx++ = (mp_digit)(r & (mp_word)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
  |  |  ------------------
  ------------------
   71|      0|         }
   72|       |         /* At this point the ix'th digit of x should be zero */
   73|       |
   74|       |
   75|       |         /* propagate carries upwards as required*/
   76|      0|         while (u != 0u) {
  ------------------
  |  Branch (76:17): [True: 0, False: 0]
  ------------------
   77|      0|            *tmpx   += u;
   78|      0|            u        = *tmpx >> MP_DIGIT_BIT;
  ------------------
  |  |   82|      0|#   define MP_DIGIT_BIT 60
  ------------------
   79|      0|            *tmpx++ &= 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
  |  |  ------------------
  ------------------
   80|      0|         }
   81|      0|      }
   82|      0|   }
   83|       |
   84|       |   /* at this point the n.used'th least
   85|       |    * significant digits of x are all zero
   86|       |    * which means we can shift x to the
   87|       |    * right by n.used digits and the
   88|       |    * residue is unchanged.
   89|       |    */
   90|       |
   91|       |   /* x = x/b**n.used */
   92|      0|   mp_clamp(x);
   93|      0|   mp_rshd(x, n->used);
   94|       |
   95|       |   /* if x >= n then x = x - n */
   96|      0|   if (mp_cmp_mag(x, n) != MP_LT) {
  ------------------
  |  |  154|      0|#define MP_LT        -1   /* less than */
  ------------------
  |  Branch (96:8): [True: 0, False: 0]
  ------------------
   97|      0|      return s_mp_sub(x, n, x);
   98|      0|   }
   99|       |
  100|      0|   return MP_OKAY;
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
  101|      0|}

mp_montgomery_setup:
    8|  30.9k|{
    9|  30.9k|   mp_digit x, b;
   10|       |
   11|       |   /* fast inversion mod 2**k
   12|       |    *
   13|       |    * Based on the fact that
   14|       |    *
   15|       |    * XA = 1 (mod 2**n)  =>  (X(2-XA)) A = 1 (mod 2**2n)
   16|       |    *                    =>  2*X*A - X*X*A*A = 1
   17|       |    *                    =>  2*(1) - (1)     = 1
   18|       |    */
   19|  30.9k|   b = n->dp[0];
   20|       |
   21|  30.9k|   if ((b & 1u) == 0u) {
  ------------------
  |  Branch (21:8): [True: 0, False: 30.9k]
  ------------------
   22|      0|      return MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
   23|      0|   }
   24|       |
   25|  30.9k|   x = (((b + 2u) & 4u) << 1) + b; /* here x*a==1 mod 2**4 */
   26|  30.9k|   x *= 2u - (b * x);              /* here x*a==1 mod 2**8 */
   27|  30.9k|#if !defined(MP_8BIT)
   28|  30.9k|   x *= 2u - (b * x);              /* here x*a==1 mod 2**16 */
   29|  30.9k|#endif
   30|  30.9k|#if defined(MP_64BIT) || !(defined(MP_8BIT) || defined(MP_16BIT))
   31|  30.9k|   x *= 2u - (b * x);              /* here x*a==1 mod 2**32 */
   32|  30.9k|#endif
   33|  30.9k|#ifdef MP_64BIT
   34|  30.9k|   x *= 2u - (b * x);              /* here x*a==1 mod 2**64 */
   35|  30.9k|#endif
   36|       |
   37|       |   /* rho = -1/m mod b */
   38|  30.9k|   *rho = (mp_digit)(((mp_word)1 << (mp_word)MP_DIGIT_BIT) - x) & MP_MASK;
  ------------------
  |  |   82|  30.9k|#   define MP_DIGIT_BIT 60
  ------------------
                 *rho = (mp_digit)(((mp_word)1 << (mp_word)MP_DIGIT_BIT) - x) & MP_MASK;
  ------------------
  |  |  106|  30.9k|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|  30.9k|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
   39|       |
   40|  30.9k|   return MP_OKAY;
  ------------------
  |  |  161|  30.9k|#define MP_OKAY       0   /* no error */
  ------------------
   41|  30.9k|}

mp_mul:
    8|  9.34M|{
    9|  9.34M|   mp_err err;
   10|  9.34M|   int min_len = MP_MIN(a->used, b->used),
  ------------------
  |  |  156|  9.34M|#define MP_MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (156:23): [True: 86.0k, False: 9.25M]
  |  |  ------------------
  ------------------
   11|  9.34M|       max_len = MP_MAX(a->used, b->used),
  ------------------
  |  |  157|  9.34M|#define MP_MAX(x, y) (((x) > (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (157:23): [True: 513k, False: 8.83M]
  |  |  ------------------
  ------------------
   12|  9.34M|       digs = a->used + b->used + 1;
   13|  9.34M|   mp_sign neg = (a->sign == b->sign) ? MP_ZPOS : MP_NEG;
  ------------------
  |  |  151|  9.34M|#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: 9.34M, False: 0]
  ------------------
   14|       |
   15|  9.34M|   if (MP_HAS(S_MP_BALANCE_MUL) &&
  ------------------
  |  |  150|  18.6M|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|  9.34M|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|  9.34M|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [True: 9.34M, 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|  9.34M|       (min_len >= MP_KARATSUBA_MUL_CUTOFF) &&
  ------------------
  |  |  121|  9.34M|#  define MP_KARATSUBA_MUL_CUTOFF KARATSUBA_MUL_CUTOFF
  ------------------
  |  Branch (23:8): [True: 0, False: 9.34M]
  ------------------
   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|  9.34M|   } else if (MP_HAS(S_MP_TOOM_MUL) &&
  ------------------
  |  |  150|  18.6M|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|  9.34M|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|  9.34M|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [Folded, False: 9.34M]
  |  |  ------------------
  ------------------
   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|  9.34M|   } else if (MP_HAS(S_MP_KARATSUBA_MUL) &&
  ------------------
  |  |  150|  18.6M|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|  9.34M|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|  9.34M|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [Folded, False: 9.34M]
  |  |  ------------------
  ------------------
   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|  9.34M|   } else if (MP_HAS(S_MP_MUL_DIGS_FAST) &&
  ------------------
  |  |  150|  18.6M|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|  9.34M|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|  9.34M|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [True: 9.34M, 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|  9.34M|              (digs < MP_WARRAY) &&
  ------------------
  |  |  172|  9.34M|#define MP_WARRAY PRIVATE_MP_WARRAY
  |  |  ------------------
  |  |  |  |  203|  9.34M|#define PRIVATE_MP_WARRAY (int)(1uLL << (((CHAR_BIT * sizeof(private_mp_word)) - (2 * MP_DIGIT_BIT)) + 1))
  |  |  |  |  ------------------
  |  |  |  |  |  |   82|  9.34M|#   define MP_DIGIT_BIT 60
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (41:15): [True: 9.34M, False: 0]
  ------------------
   42|  9.34M|              (min_len <= MP_MAXFAST)) {
  ------------------
  |  |  168|  9.34M|#define MP_MAXFAST              (int)(1uL << (MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT)))
  |  |  ------------------
  |  |  |  |  167|  9.34M|#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|  9.34M|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
  |  Branch (42:15): [True: 9.34M, False: 0]
  ------------------
   43|  9.34M|      err = s_mp_mul_digs_fast(a, b, c, digs);
   44|  9.34M|   } 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|  9.34M|   c->sign = (c->used > 0) ? neg : MP_ZPOS;
  ------------------
  |  |  151|  9.34M|#define MP_ZPOS       0   /* positive integer */
  ------------------
  |  Branch (49:14): [True: 9.34M, False: 0]
  ------------------
   50|  9.34M|   return err;
   51|  9.34M|}

mp_mul_2:
    8|  1.63M|{
    9|  1.63M|   int     x, oldused;
   10|  1.63M|   mp_err err;
   11|       |
   12|       |   /* grow to accomodate result */
   13|  1.63M|   if (b->alloc < (a->used + 1)) {
  ------------------
  |  Branch (13:8): [True: 0, False: 1.63M]
  ------------------
   14|      0|      if ((err = mp_grow(b, a->used + 1)) != MP_OKAY) {
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (14:11): [True: 0, False: 0]
  ------------------
   15|      0|         return err;
   16|      0|      }
   17|      0|   }
   18|       |
   19|  1.63M|   oldused = b->used;
   20|  1.63M|   b->used = a->used;
   21|       |
   22|  1.63M|   {
   23|  1.63M|      mp_digit r, rr, *tmpa, *tmpb;
   24|       |
   25|       |      /* alias for source */
   26|  1.63M|      tmpa = a->dp;
   27|       |
   28|       |      /* alias for dest */
   29|  1.63M|      tmpb = b->dp;
   30|       |
   31|       |      /* carry */
   32|  1.63M|      r = 0;
   33|  57.7M|      for (x = 0; x < a->used; x++) {
  ------------------
  |  Branch (33:19): [True: 56.1M, False: 1.63M]
  ------------------
   34|       |
   35|       |         /* get what will be the *next* carry bit from the
   36|       |          * MSB of the current digit
   37|       |          */
   38|  56.1M|         rr = *tmpa >> (mp_digit)(MP_DIGIT_BIT - 1);
  ------------------
  |  |   82|  56.1M|#   define MP_DIGIT_BIT 60
  ------------------
   39|       |
   40|       |         /* now shift up this digit, add in the carry [from the previous] */
   41|  56.1M|         *tmpb++ = ((*tmpa++ << 1uL) | r) & MP_MASK;
  ------------------
  |  |  106|  56.1M|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|  56.1M|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
   42|       |
   43|       |         /* copy the carry that would be from the source
   44|       |          * digit into the next iteration
   45|       |          */
   46|  56.1M|         r = rr;
   47|  56.1M|      }
   48|       |
   49|       |      /* new leading digit? */
   50|  1.63M|      if (r != 0u) {
  ------------------
  |  Branch (50:11): [True: 60, False: 1.63M]
  ------------------
   51|       |         /* add a MSB which is always 1 at this point */
   52|     60|         *tmpb = 1;
   53|     60|         ++(b->used);
   54|     60|      }
   55|       |
   56|       |      /* now zero any excess digits on the destination
   57|       |       * that we didn't write to
   58|       |       */
   59|  1.63M|      MP_ZERO_DIGITS(b->dp + b->used, oldused - b->used);
  ------------------
  |  |   89|  1.63M|#  define MP_ZERO_DIGITS(mem, digits)                   \
  |  |   90|  1.63M|do {                                                    \
  |  |   91|  1.63M|   int zd_ = (digits);                                  \
  |  |   92|  1.63M|   mp_digit* zm_ = (mem);                               \
  |  |   93|  1.63M|   while (zd_-- > 0) {                                  \
  |  |  ------------------
  |  |  |  Branch (93:11): [True: 0, False: 1.63M]
  |  |  ------------------
  |  |   94|      0|      *zm_++ = 0;                                       \
  |  |   95|      0|   }                                                    \
  |  |   96|  1.63M|} while (0)
  |  |  ------------------
  |  |  |  Branch (96:10): [Folded, False: 1.63M]
  |  |  ------------------
  ------------------
   60|  1.63M|   }
   61|  1.63M|   b->sign = a->sign;
   62|  1.63M|   return MP_OKAY;
  ------------------
  |  |  161|  1.63M|#define MP_OKAY       0   /* no error */
  ------------------
   63|  1.63M|}

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

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

mp_mulmod:
    8|  48.2k|{
    9|  48.2k|   mp_err err;
   10|  48.2k|   mp_int t;
   11|       |
   12|  48.2k|   if ((err = mp_init_size(&t, c->used)) != MP_OKAY) {
  ------------------
  |  |  161|  48.2k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (12:8): [True: 0, False: 48.2k]
  ------------------
   13|      0|      return err;
   14|      0|   }
   15|       |
   16|  48.2k|   if ((err = mp_mul(a, b, &t)) != MP_OKAY) {
  ------------------
  |  |  161|  48.2k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (16:8): [True: 0, False: 48.2k]
  ------------------
   17|      0|      goto LBL_ERR;
   18|      0|   }
   19|  48.2k|   err = mp_mod(&t, c, d);
   20|       |
   21|  48.2k|LBL_ERR:
   22|  48.2k|   mp_clear(&t);
   23|  48.2k|   return err;
   24|  48.2k|}

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|  1.11k|{
   11|  1.11k|   mp_err   err;
   12|  1.11k|   int      y;
   13|  1.11k|   mp_sign  neg;
   14|  1.11k|   unsigned pos;
   15|  1.11k|   char     ch;
   16|       |
   17|       |   /* zero the digit bignum */
   18|  1.11k|   mp_zero(a);
   19|       |
   20|       |   /* make sure the radix is ok */
   21|  1.11k|   if ((radix < 2) || (radix > 64)) {
  ------------------
  |  Branch (21:8): [True: 0, False: 1.11k]
  |  Branch (21:23): [True: 0, False: 1.11k]
  ------------------
   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|  1.11k|   if (*str == '-') {
  ------------------
  |  Branch (28:8): [True: 0, False: 1.11k]
  ------------------
   29|      0|      ++str;
   30|      0|      neg = MP_NEG;
  ------------------
  |  |  152|      0|#define MP_NEG        1   /* negative */
  ------------------
   31|  1.11k|   } else {
   32|  1.11k|      neg = MP_ZPOS;
  ------------------
  |  |  151|  1.11k|#define MP_ZPOS       0   /* positive integer */
  ------------------
   33|  1.11k|   }
   34|       |
   35|       |   /* set the integer to the default of zero */
   36|  1.11k|   mp_zero(a);
   37|       |
   38|       |   /* process each digit of the string */
   39|   122k|   while (*str != '\0') {
  ------------------
  |  Branch (39:11): [True: 121k, False: 1.11k]
  ------------------
   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|   121k|      ch = (radix <= 36) ? (char)MP_TOUPPER((int)*str) : *str;
  ------------------
  |  |    6|   121k|#define MP_TOUPPER(c) ((((c) >= 'a') && ((c) <= 'z')) ? (((c) + 'A') - 'a') : (c))
  |  |  ------------------
  |  |  |  Branch (6:25): [True: 0, False: 121k]
  |  |  |  Branch (6:41): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (44:12): [True: 121k, False: 0]
  ------------------
   45|   121k|      pos = (unsigned)(ch - '(');
   46|   121k|      if (mp_s_rmap_reverse_sz < pos) {
  ------------------
  |  Branch (46:11): [True: 0, False: 121k]
  ------------------
   47|      0|         break;
   48|      0|      }
   49|   121k|      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|   121k|      if ((y == 0xff) || (y >= radix)) {
  ------------------
  |  Branch (55:11): [True: 0, False: 121k]
  |  Branch (55:26): [True: 0, False: 121k]
  ------------------
   56|      0|         break;
   57|      0|      }
   58|   121k|      if ((err = mp_mul_d(a, (mp_digit)radix, a)) != MP_OKAY) {
  ------------------
  |  |  161|   121k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (58:11): [True: 0, False: 121k]
  ------------------
   59|      0|         return err;
   60|      0|      }
   61|   121k|      if ((err = mp_add_d(a, (mp_digit)y, a)) != MP_OKAY) {
  ------------------
  |  |  161|   121k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (61:11): [True: 0, False: 121k]
  ------------------
   62|      0|         return err;
   63|      0|      }
   64|   121k|      ++str;
   65|   121k|   }
   66|       |
   67|       |   /* if an illegal character was found, fail. */
   68|  1.11k|   if (!((*str == '\0') || (*str == '\r') || (*str == '\n'))) {
  ------------------
  |  Branch (68:10): [True: 1.11k, 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|  1.11k|   if (!MP_IS_ZERO(a)) {
  ------------------
  |  |  163|  1.11k|#define MP_IS_ZERO(a) ((a)->used == 0)
  ------------------
  |  Branch (74:8): [True: 1.11k, False: 0]
  ------------------
   75|  1.11k|      a->sign = neg;
   76|  1.11k|   }
   77|  1.11k|   return MP_OKAY;
  ------------------
  |  |  161|  1.11k|#define MP_OKAY       0   /* no error */
  ------------------
   78|  1.11k|}

mp_reduce_is_2k:
    8|  30.6k|{
    9|  30.6k|   int ix, iy, iw;
   10|  30.6k|   mp_digit iz;
   11|       |
   12|  30.6k|   if (a->used == 0) {
  ------------------
  |  Branch (12:8): [True: 0, False: 30.6k]
  ------------------
   13|      0|      return MP_NO;
  ------------------
  |  |  159|      0|#define MP_NO         0
  ------------------
   14|  30.6k|   } else if (a->used == 1) {
  ------------------
  |  Branch (14:15): [True: 0, False: 30.6k]
  ------------------
   15|      0|      return MP_YES;
  ------------------
  |  |  158|      0|#define MP_YES        1
  ------------------
   16|  30.6k|   } else if (a->used > 1) {
  ------------------
  |  Branch (16:15): [True: 30.6k, False: 0]
  ------------------
   17|  30.6k|      iy = mp_count_bits(a);
   18|  30.6k|      iz = 1;
   19|  30.6k|      iw = 1;
   20|       |
   21|       |      /* Test every bit from the second digit up, must be 1 */
   22|   186k|      for (ix = MP_DIGIT_BIT; ix < iy; ix++) {
  ------------------
  |  |   82|  30.6k|#   define MP_DIGIT_BIT 60
  ------------------
  |  Branch (22:31): [True: 186k, False: 0]
  ------------------
   23|   186k|         if ((a->dp[iw] & iz) == 0u) {
  ------------------
  |  Branch (23:14): [True: 30.6k, False: 156k]
  ------------------
   24|  30.6k|            return MP_NO;
  ------------------
  |  |  159|  30.6k|#define MP_NO         0
  ------------------
   25|  30.6k|         }
   26|   156k|         iz <<= 1;
   27|   156k|         if (iz > MP_DIGIT_MAX) {
  ------------------
  |  |  107|   156k|#define MP_DIGIT_MAX     MP_MASK
  |  |  ------------------
  |  |  |  |  106|   156k|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  |  |  ------------------
  |  |  |  |  |  |   82|   156k|#   define MP_DIGIT_BIT 60
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (27:14): [True: 0, False: 156k]
  ------------------
   28|      0|            ++iw;
   29|      0|            iz = 1;
   30|      0|         }
   31|   156k|      }
   32|      0|      return MP_YES;
  ------------------
  |  |  158|      0|#define MP_YES        1
  ------------------
   33|  30.6k|   } else {
   34|      0|      return MP_YES;
  ------------------
  |  |  158|      0|#define MP_YES        1
  ------------------
   35|      0|   }
   36|  30.6k|}

mp_reduce_is_2k_l:
    8|  30.6k|{
    9|  30.6k|   int ix, iy;
   10|       |
   11|  30.6k|   if (a->used == 0) {
  ------------------
  |  Branch (11:8): [True: 0, False: 30.6k]
  ------------------
   12|      0|      return MP_NO;
  ------------------
  |  |  159|      0|#define MP_NO         0
  ------------------
   13|  30.6k|   } else if (a->used == 1) {
  ------------------
  |  Branch (13:15): [True: 0, False: 30.6k]
  ------------------
   14|      0|      return MP_YES;
  ------------------
  |  |  158|      0|#define MP_YES        1
  ------------------
   15|  30.6k|   } else if (a->used > 1) {
  ------------------
  |  Branch (15:15): [True: 30.6k, False: 0]
  ------------------
   16|       |      /* if more than half of the digits are -1 we're sold */
   17|  1.10M|      for (iy = ix = 0; ix < a->used; ix++) {
  ------------------
  |  Branch (17:25): [True: 1.07M, False: 30.6k]
  ------------------
   18|  1.07M|         if (a->dp[ix] == MP_DIGIT_MAX) {
  ------------------
  |  |  107|  1.07M|#define MP_DIGIT_MAX     MP_MASK
  |  |  ------------------
  |  |  |  |  106|  1.07M|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  |  |  ------------------
  |  |  |  |  |  |   82|  1.07M|#   define MP_DIGIT_BIT 60
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (18:14): [True: 13.8k, False: 1.05M]
  ------------------
   19|  13.8k|            ++iy;
   20|  13.8k|         }
   21|  1.07M|      }
   22|  30.6k|      return (iy >= (a->used/2)) ? MP_YES : MP_NO;
  ------------------
  |  |  158|      0|#define MP_YES        1
  ------------------
                    return (iy >= (a->used/2)) ? MP_YES : MP_NO;
  ------------------
  |  |  159|  30.6k|#define MP_NO         0
  ------------------
  |  Branch (22:14): [True: 0, False: 30.6k]
  ------------------
   23|  30.6k|   } else {
   24|      0|      return MP_NO;
  ------------------
  |  |  159|      0|#define MP_NO         0
  ------------------
   25|      0|   }
   26|  30.6k|}

mp_rshd:
    8|  40.6k|{
    9|  40.6k|   int     x;
   10|  40.6k|   mp_digit *bottom, *top;
   11|       |
   12|       |   /* if b <= 0 then ignore it */
   13|  40.6k|   if (b <= 0) {
  ------------------
  |  Branch (13:8): [True: 3.02k, False: 37.6k]
  ------------------
   14|  3.02k|      return;
   15|  3.02k|   }
   16|       |
   17|       |   /* if b > used then simply zero it and return */
   18|  37.6k|   if (a->used <= b) {
  ------------------
  |  Branch (18:8): [True: 0, False: 37.6k]
  ------------------
   19|      0|      mp_zero(a);
   20|      0|      return;
   21|      0|   }
   22|       |
   23|       |   /* shift the digits down */
   24|       |
   25|       |   /* bottom */
   26|  37.6k|   bottom = a->dp;
   27|       |
   28|       |   /* top [offset into digits] */
   29|  37.6k|   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|  1.32M|   for (x = 0; x < (a->used - b); x++) {
  ------------------
  |  Branch (41:16): [True: 1.28M, False: 37.6k]
  ------------------
   42|  1.28M|      *bottom++ = *top++;
   43|  1.28M|   }
   44|       |
   45|       |   /* zero the top digits */
   46|  37.6k|   MP_ZERO_DIGITS(bottom, a->used - x);
  ------------------
  |  |   89|  37.6k|#  define MP_ZERO_DIGITS(mem, digits)                   \
  |  |   90|  37.6k|do {                                                    \
  |  |   91|  37.6k|   int zd_ = (digits);                                  \
  |  |   92|  37.6k|   mp_digit* zm_ = (mem);                               \
  |  |   93|  1.22M|   while (zd_-- > 0) {                                  \
  |  |  ------------------
  |  |  |  Branch (93:11): [True: 1.18M, False: 37.6k]
  |  |  ------------------
  |  |   94|  1.18M|      *zm_++ = 0;                                       \
  |  |   95|  1.18M|   }                                                    \
  |  |   96|  37.6k|} while (0)
  |  |  ------------------
  |  |  |  Branch (96:10): [Folded, False: 37.6k]
  |  |  ------------------
  ------------------
   47|       |
   48|       |   /* remove excess digits */
   49|  37.6k|   a->used -= b;
   50|  37.6k|}

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

mp_sqr:
    8|  47.3M|{
    9|  47.3M|   mp_err err;
   10|  47.3M|   if (MP_HAS(S_MP_TOOM_SQR) && /* use Toom-Cook? */
  ------------------
  |  |  150|  94.7M|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|  47.3M|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|  47.3M|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [Folded, False: 47.3M]
  |  |  ------------------
  ------------------
   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|  47.3M|   } else if (MP_HAS(S_MP_KARATSUBA_SQR) &&  /* Karatsuba? */
  ------------------
  |  |  150|  94.7M|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|  47.3M|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|  47.3M|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [Folded, False: 47.3M]
  |  |  ------------------
  ------------------
   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|  47.3M|   } else if (MP_HAS(S_MP_SQR_FAST) && /* can we use the fast comba multiplier? */
  ------------------
  |  |  150|  94.7M|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|  47.3M|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|  47.3M|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [True: 47.3M, Folded]
  |  |  ------------------
  ------------------
   17|  47.3M|              (((a->used * 2) + 1) < MP_WARRAY) &&
  ------------------
  |  |  172|  47.3M|#define MP_WARRAY PRIVATE_MP_WARRAY
  |  |  ------------------
  |  |  |  |  203|  47.3M|#define PRIVATE_MP_WARRAY (int)(1uLL << (((CHAR_BIT * sizeof(private_mp_word)) - (2 * MP_DIGIT_BIT)) + 1))
  |  |  |  |  ------------------
  |  |  |  |  |  |   82|  47.3M|#   define MP_DIGIT_BIT 60
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (17:15): [True: 47.3M, False: 0]
  ------------------
   18|  47.3M|              (a->used < (MP_MAXFAST / 2))) {
  ------------------
  |  |  168|  47.3M|#define MP_MAXFAST              (int)(1uL << (MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT)))
  |  |  ------------------
  |  |  |  |  167|  47.3M|#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|  47.3M|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
  |  Branch (18:15): [True: 47.3M, False: 0]
  ------------------
   19|  47.3M|      err = s_mp_sqr_fast(a, b);
   20|  47.3M|   } 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|  47.3M|   b->sign = MP_ZPOS;
  ------------------
  |  |  151|  47.3M|#define MP_ZPOS       0   /* positive integer */
  ------------------
   26|  47.3M|   return err;
   27|  47.3M|}

mp_sub:
    8|  40.0M|{
    9|  40.0M|   mp_sign sa = a->sign, sb = b->sign;
   10|  40.0M|   mp_err err;
   11|       |
   12|  40.0M|   if (sa != sb) {
  ------------------
  |  Branch (12:8): [True: 11.9M, False: 28.1M]
  ------------------
   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|  11.9M|      c->sign = sa;
   18|  11.9M|      err = s_mp_add(a, b, c);
   19|  28.1M|   } 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|  28.1M|      if (mp_cmp_mag(a, b) != MP_LT) {
  ------------------
  |  |  154|  28.1M|#define MP_LT        -1   /* less than */
  ------------------
  |  Branch (24:11): [True: 19.1M, False: 8.98M]
  ------------------
   25|       |         /* Copy the sign from the first */
   26|  19.1M|         c->sign = sa;
   27|       |         /* The first has a larger or equal magnitude */
   28|  19.1M|         err = s_mp_sub(a, b, c);
   29|  19.1M|      } else {
   30|       |         /* The result has the *opposite* sign from */
   31|       |         /* the first number. */
   32|  8.98M|         c->sign = (sa == MP_ZPOS) ? MP_NEG : MP_ZPOS;
  ------------------
  |  |  151|  8.98M|#define MP_ZPOS       0   /* positive integer */
  ------------------
                       c->sign = (sa == MP_ZPOS) ? MP_NEG : MP_ZPOS;
  ------------------
  |  |  152|  4.85M|#define MP_NEG        1   /* negative */
  ------------------
                       c->sign = (sa == MP_ZPOS) ? MP_NEG : MP_ZPOS;
  ------------------
  |  |  151|  13.1M|#define MP_ZPOS       0   /* positive integer */
  ------------------
  |  Branch (32:20): [True: 4.85M, False: 4.13M]
  ------------------
   33|       |         /* The second has a larger magnitude */
   34|  8.98M|         err = s_mp_sub(b, a, c);
   35|  8.98M|      }
   36|  28.1M|   }
   37|  40.0M|   return err;
   38|  40.0M|}

mp_sub_d:
    8|  13.8k|{
    9|  13.8k|   mp_digit *tmpa, *tmpc;
   10|  13.8k|   mp_err    err;
   11|  13.8k|   int       ix, oldused;
   12|       |
   13|       |   /* grow c as required */
   14|  13.8k|   if (c->alloc < (a->used + 1)) {
  ------------------
  |  Branch (14:8): [True: 13.8k, False: 0]
  ------------------
   15|  13.8k|      if ((err = mp_grow(c, a->used + 1)) != MP_OKAY) {
  ------------------
  |  |  161|  13.8k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (15:11): [True: 0, False: 13.8k]
  ------------------
   16|      0|         return err;
   17|      0|      }
   18|  13.8k|   }
   19|       |
   20|       |   /* if a is negative just do an unsigned
   21|       |    * addition [with fudged signs]
   22|       |    */
   23|  13.8k|   if (a->sign == MP_NEG) {
  ------------------
  |  |  152|  13.8k|#define MP_NEG        1   /* negative */
  ------------------
  |  Branch (23:8): [True: 0, False: 13.8k]
  ------------------
   24|      0|      mp_int a_ = *a;
   25|      0|      a_.sign = MP_ZPOS;
  ------------------
  |  |  151|      0|#define MP_ZPOS       0   /* positive integer */
  ------------------
   26|      0|      err     = mp_add_d(&a_, b, c);
   27|      0|      c->sign = MP_NEG;
  ------------------
  |  |  152|      0|#define MP_NEG        1   /* negative */
  ------------------
   28|       |
   29|       |      /* clamp */
   30|      0|      mp_clamp(c);
   31|       |
   32|      0|      return err;
   33|      0|   }
   34|       |
   35|       |   /* setup regs */
   36|  13.8k|   oldused = c->used;
   37|  13.8k|   tmpa    = a->dp;
   38|  13.8k|   tmpc    = c->dp;
   39|       |
   40|       |   /* if a <= b simply fix the single digit */
   41|  13.8k|   if (((a->used == 1) && (a->dp[0] <= b)) || (a->used == 0)) {
  ------------------
  |  Branch (41:9): [True: 0, False: 13.8k]
  |  Branch (41:27): [True: 0, False: 0]
  |  Branch (41:47): [True: 0, False: 13.8k]
  ------------------
   42|      0|      if (a->used == 1) {
  ------------------
  |  Branch (42:11): [True: 0, False: 0]
  ------------------
   43|      0|         *tmpc++ = b - *tmpa;
   44|      0|      } else {
   45|      0|         *tmpc++ = b;
   46|      0|      }
   47|      0|      ix      = 1;
   48|       |
   49|       |      /* negative/1digit */
   50|      0|      c->sign = MP_NEG;
  ------------------
  |  |  152|      0|#define MP_NEG        1   /* negative */
  ------------------
   51|      0|      c->used = 1;
   52|  13.8k|   } else {
   53|  13.8k|      mp_digit mu = b;
   54|       |
   55|       |      /* positive/size */
   56|  13.8k|      c->sign = MP_ZPOS;
  ------------------
  |  |  151|  13.8k|#define MP_ZPOS       0   /* positive integer */
  ------------------
   57|  13.8k|      c->used = a->used;
   58|       |
   59|       |      /* subtract digits, mu is carry */
   60|   500k|      for (ix = 0; ix < a->used; ix++) {
  ------------------
  |  Branch (60:20): [True: 486k, False: 13.8k]
  ------------------
   61|   486k|         *tmpc    = *tmpa++ - mu;
   62|   486k|         mu       = *tmpc >> (MP_SIZEOF_BITS(mp_digit) - 1u);
  ------------------
  |  |  167|   486k|#define MP_SIZEOF_BITS(type)    ((size_t)CHAR_BIT * sizeof(type))
  ------------------
   63|   486k|         *tmpc++ &= MP_MASK;
  ------------------
  |  |  106|   486k|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|   486k|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
   64|   486k|      }
   65|  13.8k|   }
   66|       |
   67|       |   /* zero excess digits */
   68|  13.8k|   MP_ZERO_DIGITS(tmpc, oldused - ix);
  ------------------
  |  |   89|  13.8k|#  define MP_ZERO_DIGITS(mem, digits)                   \
  |  |   90|  13.8k|do {                                                    \
  |  |   91|  13.8k|   int zd_ = (digits);                                  \
  |  |   92|  13.8k|   mp_digit* zm_ = (mem);                               \
  |  |   93|  13.8k|   while (zd_-- > 0) {                                  \
  |  |  ------------------
  |  |  |  Branch (93:11): [True: 0, False: 13.8k]
  |  |  ------------------
  |  |   94|      0|      *zm_++ = 0;                                       \
  |  |   95|      0|   }                                                    \
  |  |   96|  13.8k|} while (0)
  |  |  ------------------
  |  |  |  Branch (96:10): [Folded, False: 13.8k]
  |  |  ------------------
  ------------------
   69|       |
   70|  13.8k|   mp_clamp(c);
   71|  13.8k|   return MP_OKAY;
  ------------------
  |  |  161|  13.8k|#define MP_OKAY       0   /* no error */
  ------------------
   72|  13.8k|}

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

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

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

s_mp_add:
    8|  13.2M|{
    9|  13.2M|   const mp_int *x;
   10|  13.2M|   mp_err err;
   11|  13.2M|   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|  13.2M|   if (a->used > b->used) {
  ------------------
  |  Branch (16:8): [True: 52.3k, False: 13.1M]
  ------------------
   17|  52.3k|      min = b->used;
   18|  52.3k|      max = a->used;
   19|  52.3k|      x = a;
   20|  13.1M|   } else {
   21|  13.1M|      min = a->used;
   22|  13.1M|      max = b->used;
   23|  13.1M|      x = b;
   24|  13.1M|   }
   25|       |
   26|       |   /* init result */
   27|  13.2M|   if (c->alloc < (max + 1)) {
  ------------------
  |  Branch (27:8): [True: 25.1k, False: 13.1M]
  ------------------
   28|  25.1k|      if ((err = mp_grow(c, max + 1)) != MP_OKAY) {
  ------------------
  |  |  161|  25.1k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (28:11): [True: 0, False: 25.1k]
  ------------------
   29|      0|         return err;
   30|      0|      }
   31|  25.1k|   }
   32|       |
   33|       |   /* get old used digit count and set new one */
   34|  13.2M|   olduse = c->used;
   35|  13.2M|   c->used = max + 1;
   36|       |
   37|  13.2M|   {
   38|  13.2M|      mp_digit u, *tmpa, *tmpb, *tmpc;
   39|  13.2M|      int i;
   40|       |
   41|       |      /* alias for digit pointers */
   42|       |
   43|       |      /* first input */
   44|  13.2M|      tmpa = a->dp;
   45|       |
   46|       |      /* second input */
   47|  13.2M|      tmpb = b->dp;
   48|       |
   49|       |      /* destination */
   50|  13.2M|      tmpc = c->dp;
   51|       |
   52|       |      /* zero the carry */
   53|  13.2M|      u = 0;
   54|   437M|      for (i = 0; i < min; i++) {
  ------------------
  |  Branch (54:19): [True: 424M, False: 13.2M]
  ------------------
   55|       |         /* Compute the sum at one digit, T[i] = A[i] + B[i] + U */
   56|   424M|         *tmpc = *tmpa++ + *tmpb++ + u;
   57|       |
   58|       |         /* U = carry bit of T[i] */
   59|   424M|         u = *tmpc >> (mp_digit)MP_DIGIT_BIT;
  ------------------
  |  |   82|   424M|#   define MP_DIGIT_BIT 60
  ------------------
   60|       |
   61|       |         /* take away carry bit from T[i] */
   62|   424M|         *tmpc++ &= MP_MASK;
  ------------------
  |  |  106|   424M|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|   424M|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
   63|   424M|      }
   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|  13.2M|      if (min != max) {
  ------------------
  |  Branch (68:11): [True: 177k, False: 13.0M]
  ------------------
   69|   842k|         for (; i < max; i++) {
  ------------------
  |  Branch (69:17): [True: 665k, False: 177k]
  ------------------
   70|       |            /* T[i] = X[i] + U */
   71|   665k|            *tmpc = x->dp[i] + u;
   72|       |
   73|       |            /* U = carry bit of T[i] */
   74|   665k|            u = *tmpc >> (mp_digit)MP_DIGIT_BIT;
  ------------------
  |  |   82|   665k|#   define MP_DIGIT_BIT 60
  ------------------
   75|       |
   76|       |            /* take away carry bit from T[i] */
   77|   665k|            *tmpc++ &= MP_MASK;
  ------------------
  |  |  106|   665k|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|   665k|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
   78|   665k|         }
   79|   177k|      }
   80|       |
   81|       |      /* add carry */
   82|  13.2M|      *tmpc++ = u;
   83|       |
   84|       |      /* clear digits above oldused */
   85|  13.2M|      MP_ZERO_DIGITS(tmpc, olduse - c->used);
  ------------------
  |  |   89|  13.2M|#  define MP_ZERO_DIGITS(mem, digits)                   \
  |  |   90|  13.2M|do {                                                    \
  |  |   91|  13.2M|   int zd_ = (digits);                                  \
  |  |   92|  13.2M|   mp_digit* zm_ = (mem);                               \
  |  |   93|  13.2M|   while (zd_-- > 0) {                                  \
  |  |  ------------------
  |  |  |  Branch (93:11): [True: 0, False: 13.2M]
  |  |  ------------------
  |  |   94|      0|      *zm_++ = 0;                                       \
  |  |   95|      0|   }                                                    \
  |  |   96|  13.2M|} while (0)
  |  |  ------------------
  |  |  |  Branch (96:10): [Folded, False: 13.2M]
  |  |  ------------------
  ------------------
   86|  13.2M|   }
   87|       |
   88|  13.2M|   mp_clamp(c);
   89|  13.2M|   return MP_OKAY;
  ------------------
  |  |  161|  13.2M|#define MP_OKAY       0   /* no error */
  ------------------
   90|  13.2M|}

s_mp_exptmod_fast:
   23|  30.6k|{
   24|  30.6k|   mp_int  M[TAB_SIZE], res;
   25|  30.6k|   mp_digit buf, mp;
   26|  30.6k|   int     bitbuf, bitcpy, bitcnt, mode, digidx, x, y, winsize;
   27|  30.6k|   mp_err   err;
   28|       |
   29|       |   /* use a pointer to the reduction algorithm.  This allows us to use
   30|       |    * one of many reduction algorithms without modding the guts of
   31|       |    * the code with if statements everywhere.
   32|       |    */
   33|  30.6k|   mp_err(*redux)(mp_int *x, const mp_int *n, mp_digit rho);
   34|       |
   35|       |   /* find window size */
   36|  30.6k|   x = mp_count_bits(X);
   37|  30.6k|   if (x <= 7) {
  ------------------
  |  Branch (37:8): [True: 0, False: 30.6k]
  ------------------
   38|      0|      winsize = 2;
   39|  30.6k|   } else if (x <= 36) {
  ------------------
  |  Branch (39:15): [True: 8.39k, False: 22.2k]
  ------------------
   40|  8.39k|      winsize = 3;
   41|  22.2k|   } else if (x <= 140) {
  ------------------
  |  Branch (41:15): [True: 0, False: 22.2k]
  ------------------
   42|      0|      winsize = 4;
   43|  22.2k|   } else if (x <= 450) {
  ------------------
  |  Branch (43:15): [True: 0, False: 22.2k]
  ------------------
   44|      0|      winsize = 5;
   45|  22.2k|   } else if (x <= 1303) {
  ------------------
  |  Branch (45:15): [True: 0, False: 22.2k]
  ------------------
   46|      0|      winsize = 6;
   47|  22.2k|   } else if (x <= 3529) {
  ------------------
  |  Branch (47:15): [True: 22.2k, False: 0]
  ------------------
   48|  22.2k|      winsize = 7;
   49|  22.2k|   } else {
   50|      0|      winsize = 8;
   51|      0|   }
   52|       |
   53|  30.6k|   winsize = MAX_WINSIZE ? MP_MIN(MAX_WINSIZE, winsize) : winsize;
  ------------------
  |  |   19|  30.6k|#   define MAX_WINSIZE 0
  |  |  ------------------
  |  |  |  Branch (19:24): [Folded, False: 30.6k]
  |  |  ------------------
  ------------------
                 winsize = MAX_WINSIZE ? MP_MIN(MAX_WINSIZE, winsize) : winsize;
  ------------------
  |  |  156|      0|#define MP_MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (156:23): [True: 0, False: 0]
  |  |  ------------------
  ------------------
   54|       |
   55|       |   /* init M array */
   56|       |   /* init first cell */
   57|  30.6k|   if ((err = mp_init_size(&M[1], P->alloc)) != MP_OKAY) {
  ------------------
  |  |  161|  30.6k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (57:8): [True: 0, False: 30.6k]
  ------------------
   58|      0|      return err;
   59|      0|   }
   60|       |
   61|       |   /* now init the second half of the array */
   62|  1.48M|   for (x = 1<<(winsize-1); x < (1 << winsize); x++) {
  ------------------
  |  Branch (62:29): [True: 1.45M, False: 30.6k]
  ------------------
   63|  1.45M|      if ((err = mp_init_size(&M[x], P->alloc)) != MP_OKAY) {
  ------------------
  |  |  161|  1.45M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (63:11): [True: 0, False: 1.45M]
  ------------------
   64|      0|         for (y = 1<<(winsize-1); y < x; y++) {
  ------------------
  |  Branch (64:35): [True: 0, False: 0]
  ------------------
   65|      0|            mp_clear(&M[y]);
   66|      0|         }
   67|      0|         mp_clear(&M[1]);
   68|      0|         return err;
   69|      0|      }
   70|  1.45M|   }
   71|       |
   72|       |   /* determine and setup reduction code */
   73|  30.6k|   if (redmode == 0) {
  ------------------
  |  Branch (73:8): [True: 30.6k, False: 0]
  ------------------
   74|  30.6k|      if (MP_HAS(MP_MONTGOMERY_SETUP)) {
  ------------------
  |  |  150|  30.6k|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|  30.6k|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|  30.6k|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [True: 30.6k, Folded]
  |  |  ------------------
  ------------------
   75|       |         /* now setup montgomery  */
   76|  30.6k|         if ((err = mp_montgomery_setup(P, &mp)) != MP_OKAY)      goto LBL_M;
  ------------------
  |  |  161|  30.6k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (76:14): [True: 0, False: 30.6k]
  ------------------
   77|  30.6k|      } else {
   78|      0|         err = MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
   79|      0|         goto LBL_M;
   80|      0|      }
   81|       |
   82|       |      /* automatically pick the comba one if available (saves quite a few calls/ifs) */
   83|  30.6k|      if (MP_HAS(S_MP_MONTGOMERY_REDUCE_FAST) &&
  ------------------
  |  |  150|  61.2k|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|  30.6k|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|  30.6k|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [True: 30.6k, Folded]
  |  |  ------------------
  ------------------
   84|  30.6k|          (((P->used * 2) + 1) < MP_WARRAY) &&
  ------------------
  |  |  172|  30.6k|#define MP_WARRAY PRIVATE_MP_WARRAY
  |  |  ------------------
  |  |  |  |  203|  30.6k|#define PRIVATE_MP_WARRAY (int)(1uLL << (((CHAR_BIT * sizeof(private_mp_word)) - (2 * MP_DIGIT_BIT)) + 1))
  |  |  |  |  ------------------
  |  |  |  |  |  |   82|  30.6k|#   define MP_DIGIT_BIT 60
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (84:11): [True: 30.6k, False: 0]
  ------------------
   85|  30.6k|          (P->used < MP_MAXFAST)) {
  ------------------
  |  |  168|  30.6k|#define MP_MAXFAST              (int)(1uL << (MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT)))
  |  |  ------------------
  |  |  |  |  167|  30.6k|#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|  30.6k|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
  |  Branch (85:11): [True: 30.6k, False: 0]
  ------------------
   86|  30.6k|         redux = s_mp_montgomery_reduce_fast;
   87|  30.6k|      } else if (MP_HAS(MP_MONTGOMERY_REDUCE)) {
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
   88|       |         /* use slower baseline Montgomery method */
   89|      0|         redux = mp_montgomery_reduce;
   90|      0|      } else {
   91|      0|         err = MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
   92|      0|         goto LBL_M;
   93|      0|      }
   94|  30.6k|   } else if (redmode == 1) {
  ------------------
  |  Branch (94:15): [True: 0, False: 0]
  ------------------
   95|      0|      if (MP_HAS(MP_DR_SETUP) && MP_HAS(MP_DR_REDUCE)) {
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
                    if (MP_HAS(MP_DR_SETUP) && MP_HAS(MP_DR_REDUCE)) {
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
   96|       |         /* setup DR reduction for moduli of the form B**k - b */
   97|      0|         mp_dr_setup(P, &mp);
   98|      0|         redux = mp_dr_reduce;
   99|      0|      } else {
  100|      0|         err = MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
  101|      0|         goto LBL_M;
  102|      0|      }
  103|      0|   } else if (MP_HAS(MP_REDUCE_2K_SETUP) && MP_HAS(MP_REDUCE_2K)) {
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
                 } else if (MP_HAS(MP_REDUCE_2K_SETUP) && MP_HAS(MP_REDUCE_2K)) {
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  104|       |      /* setup DR reduction for moduli of the form 2**k - b */
  105|      0|      if ((err = mp_reduce_2k_setup(P, &mp)) != MP_OKAY)          goto LBL_M;
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (105:11): [True: 0, False: 0]
  ------------------
  106|      0|      redux = mp_reduce_2k;
  107|      0|   } else {
  108|      0|      err = MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
  109|      0|      goto LBL_M;
  110|      0|   }
  111|       |
  112|       |   /* setup result */
  113|  30.6k|   if ((err = mp_init_size(&res, P->alloc)) != MP_OKAY)           goto LBL_M;
  ------------------
  |  |  161|  30.6k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (113:8): [True: 0, False: 30.6k]
  ------------------
  114|       |
  115|       |   /* create M table
  116|       |    *
  117|       |
  118|       |    *
  119|       |    * The first half of the table is not computed though accept for M[0] and M[1]
  120|       |    */
  121|       |
  122|  30.6k|   if (redmode == 0) {
  ------------------
  |  Branch (122:8): [True: 30.6k, False: 0]
  ------------------
  123|  30.6k|      if (MP_HAS(MP_MONTGOMERY_CALC_NORMALIZATION)) {
  ------------------
  |  |  150|  30.6k|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|  30.6k|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|  30.6k|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [True: 30.6k, Folded]
  |  |  ------------------
  ------------------
  124|       |         /* now we need R mod m */
  125|  30.6k|         if ((err = mp_montgomery_calc_normalization(&res, P)) != MP_OKAY) goto LBL_RES;
  ------------------
  |  |  161|  30.6k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (125:14): [True: 0, False: 30.6k]
  ------------------
  126|       |
  127|       |         /* now set M[1] to G * R mod m */
  128|  30.6k|         if ((err = mp_mulmod(G, &res, P, &M[1])) != MP_OKAY)     goto LBL_RES;
  ------------------
  |  |  161|  30.6k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (128:14): [True: 0, False: 30.6k]
  ------------------
  129|  30.6k|      } else {
  130|      0|         err = MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
  131|      0|         goto LBL_RES;
  132|      0|      }
  133|  30.6k|   } else {
  134|      0|      mp_set(&res, 1uL);
  135|      0|      if ((err = mp_mod(G, P, &M[1])) != MP_OKAY)                 goto LBL_RES;
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (135:11): [True: 0, False: 0]
  ------------------
  136|      0|   }
  137|       |
  138|       |   /* compute the value at M[1<<(winsize-1)] by squaring M[1] (winsize-1) times */
  139|  30.6k|   if ((err = mp_copy(&M[1], &M[(size_t)1 << (winsize - 1)])) != MP_OKAY) goto LBL_RES;
  ------------------
  |  |  161|  30.6k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (139:8): [True: 0, False: 30.6k]
  ------------------
  140|       |
  141|   180k|   for (x = 0; x < (winsize - 1); x++) {
  ------------------
  |  Branch (141:16): [True: 150k, False: 30.6k]
  ------------------
  142|   150k|      if ((err = mp_sqr(&M[(size_t)1 << (winsize - 1)], &M[(size_t)1 << (winsize - 1)])) != MP_OKAY) goto LBL_RES;
  ------------------
  |  |  161|   150k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (142:11): [True: 0, False: 150k]
  ------------------
  143|   150k|      if ((err = redux(&M[(size_t)1 << (winsize - 1)], P, mp)) != MP_OKAY) goto LBL_RES;
  ------------------
  |  |  161|   150k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (143:11): [True: 0, False: 150k]
  ------------------
  144|   150k|   }
  145|       |
  146|       |   /* create upper table */
  147|  1.45M|   for (x = (1 << (winsize - 1)) + 1; x < (1 << winsize); x++) {
  ------------------
  |  Branch (147:39): [True: 1.42M, False: 30.6k]
  ------------------
  148|  1.42M|      if ((err = mp_mul(&M[x - 1], &M[1], &M[x])) != MP_OKAY)     goto LBL_RES;
  ------------------
  |  |  161|  1.42M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (148:11): [True: 0, False: 1.42M]
  ------------------
  149|  1.42M|      if ((err = redux(&M[x], P, mp)) != MP_OKAY)                 goto LBL_RES;
  ------------------
  |  |  161|  1.42M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (149:11): [True: 0, False: 1.42M]
  ------------------
  150|  1.42M|   }
  151|       |
  152|       |   /* set initial mode and bit cnt */
  153|  30.6k|   mode   = 0;
  154|  30.6k|   bitcnt = 1;
  155|  30.6k|   buf    = 0;
  156|  30.6k|   digidx = X->used - 1;
  157|  30.6k|   bitcpy = 0;
  158|  30.6k|   bitbuf = 0;
  159|       |
  160|  47.7M|   for (;;) {
  161|       |      /* grab next digit as required */
  162|  47.7M|      if (--bitcnt == 0) {
  ------------------
  |  Branch (162:11): [True: 825k, False: 46.9M]
  ------------------
  163|       |         /* if digidx == -1 we are out of digits so break */
  164|   825k|         if (digidx == -1) {
  ------------------
  |  Branch (164:14): [True: 30.6k, False: 795k]
  ------------------
  165|  30.6k|            break;
  166|  30.6k|         }
  167|       |         /* read next digit and reset bitcnt */
  168|   795k|         buf    = X->dp[digidx--];
  169|   795k|         bitcnt = (int)MP_DIGIT_BIT;
  ------------------
  |  |   82|   795k|#   define MP_DIGIT_BIT 60
  ------------------
  170|   795k|      }
  171|       |
  172|       |      /* grab the next msb from the exponent */
  173|  47.7M|      y     = (mp_digit)(buf >> (MP_DIGIT_BIT - 1)) & 1uL;
  ------------------
  |  |   82|  47.7M|#   define MP_DIGIT_BIT 60
  ------------------
  174|  47.7M|      buf <<= (mp_digit)1;
  175|       |
  176|       |      /* if the bit is zero and mode == 0 then we ignore it
  177|       |       * These represent the leading zero bits before the first 1 bit
  178|       |       * in the exponent.  Technically this opt is not required but it
  179|       |       * does lower the # of trivial squaring/reductions used
  180|       |       */
  181|  47.7M|      if ((mode == 0) && (y == 0)) {
  ------------------
  |  Branch (181:11): [True: 1.55M, False: 46.1M]
  |  Branch (181:26): [True: 1.52M, False: 30.6k]
  ------------------
  182|  1.52M|         continue;
  183|  1.52M|      }
  184|       |
  185|       |      /* if the bit is zero and mode == 1 then we square */
  186|  46.1M|      if ((mode == 1) && (y == 0)) {
  ------------------
  |  Branch (186:11): [True: 11.6M, False: 34.5M]
  |  Branch (186:26): [True: 5.87M, False: 5.74M]
  ------------------
  187|  5.87M|         if ((err = mp_sqr(&res, &res)) != MP_OKAY)               goto LBL_RES;
  ------------------
  |  |  161|  5.87M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (187:14): [True: 0, False: 5.87M]
  ------------------
  188|  5.87M|         if ((err = redux(&res, P, mp)) != MP_OKAY)               goto LBL_RES;
  ------------------
  |  |  161|  5.87M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (188:14): [True: 0, False: 5.87M]
  ------------------
  189|  5.87M|         continue;
  190|  5.87M|      }
  191|       |
  192|       |      /* else we add it to the window */
  193|  40.2M|      bitbuf |= (y << (winsize - ++bitcpy));
  194|  40.2M|      mode    = 2;
  195|       |
  196|  40.2M|      if (bitcpy == winsize) {
  ------------------
  |  Branch (196:11): [True: 5.75M, False: 34.5M]
  ------------------
  197|       |         /* ok window is filled so square as required and multiply  */
  198|       |         /* square first */
  199|  45.9M|         for (x = 0; x < winsize; x++) {
  ------------------
  |  Branch (199:22): [True: 40.2M, False: 5.75M]
  ------------------
  200|  40.2M|            if ((err = mp_sqr(&res, &res)) != MP_OKAY)            goto LBL_RES;
  ------------------
  |  |  161|  40.2M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (200:17): [True: 0, False: 40.2M]
  ------------------
  201|  40.2M|            if ((err = redux(&res, P, mp)) != MP_OKAY)            goto LBL_RES;
  ------------------
  |  |  161|  40.2M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (201:17): [True: 0, False: 40.2M]
  ------------------
  202|  40.2M|         }
  203|       |
  204|       |         /* then multiply */
  205|  5.75M|         if ((err = mp_mul(&res, &M[bitbuf], &res)) != MP_OKAY)   goto LBL_RES;
  ------------------
  |  |  161|  5.75M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (205:14): [True: 0, False: 5.75M]
  ------------------
  206|  5.75M|         if ((err = redux(&res, P, mp)) != MP_OKAY)               goto LBL_RES;
  ------------------
  |  |  161|  5.75M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (206:14): [True: 0, False: 5.75M]
  ------------------
  207|       |
  208|       |         /* empty window and reset */
  209|  5.75M|         bitcpy = 0;
  210|  5.75M|         bitbuf = 0;
  211|  5.75M|         mode   = 1;
  212|  5.75M|      }
  213|  40.2M|   }
  214|       |
  215|       |   /* if bits remain then square/multiply */
  216|  30.6k|   if ((mode == 2) && (bitcpy > 0)) {
  ------------------
  |  Branch (216:8): [True: 23.7k, False: 6.90k]
  |  Branch (216:23): [True: 23.7k, False: 0]
  ------------------
  217|       |      /* square then multiply if the bit is set */
  218|  84.3k|      for (x = 0; x < bitcpy; x++) {
  ------------------
  |  Branch (218:19): [True: 60.6k, False: 23.7k]
  ------------------
  219|  60.6k|         if ((err = mp_sqr(&res, &res)) != MP_OKAY)               goto LBL_RES;
  ------------------
  |  |  161|  60.6k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (219:14): [True: 0, False: 60.6k]
  ------------------
  220|  60.6k|         if ((err = redux(&res, P, mp)) != MP_OKAY)               goto LBL_RES;
  ------------------
  |  |  161|  60.6k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (220:14): [True: 0, False: 60.6k]
  ------------------
  221|       |
  222|       |         /* get next bit of the window */
  223|  60.6k|         bitbuf <<= 1;
  224|  60.6k|         if ((bitbuf & (1 << winsize)) != 0) {
  ------------------
  |  Branch (224:14): [True: 47.7k, False: 12.9k]
  ------------------
  225|       |            /* then multiply */
  226|  47.7k|            if ((err = mp_mul(&res, &M[1], &res)) != MP_OKAY)     goto LBL_RES;
  ------------------
  |  |  161|  47.7k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (226:17): [True: 0, False: 47.7k]
  ------------------
  227|  47.7k|            if ((err = redux(&res, P, mp)) != MP_OKAY)            goto LBL_RES;
  ------------------
  |  |  161|  47.7k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (227:17): [True: 0, False: 47.7k]
  ------------------
  228|  47.7k|         }
  229|  60.6k|      }
  230|  23.7k|   }
  231|       |
  232|  30.6k|   if (redmode == 0) {
  ------------------
  |  Branch (232:8): [True: 30.6k, False: 0]
  ------------------
  233|       |      /* fixup result if Montgomery reduction is used
  234|       |       * recall that any value in a Montgomery system is
  235|       |       * actually multiplied by R mod n.  So we have
  236|       |       * to reduce one more time to cancel out the factor
  237|       |       * of R.
  238|       |       */
  239|  30.6k|      if ((err = redux(&res, P, mp)) != MP_OKAY)                  goto LBL_RES;
  ------------------
  |  |  161|  30.6k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (239:11): [True: 0, False: 30.6k]
  ------------------
  240|  30.6k|   }
  241|       |
  242|       |   /* swap res with Y */
  243|  30.6k|   mp_exch(&res, Y);
  244|  30.6k|   err = MP_OKAY;
  ------------------
  |  |  161|  30.6k|#define MP_OKAY       0   /* no error */
  ------------------
  245|  30.6k|LBL_RES:
  246|  30.6k|   mp_clear(&res);
  247|  30.6k|LBL_M:
  248|  30.6k|   mp_clear(&M[1]);
  249|  1.48M|   for (x = 1<<(winsize-1); x < (1 << winsize); x++) {
  ------------------
  |  Branch (249:29): [True: 1.45M, False: 30.6k]
  ------------------
  250|  1.45M|      mp_clear(&M[x]);
  251|  1.45M|   }
  252|  30.6k|   return err;
  253|  30.6k|}

s_mp_invmod_fast:
   13|  8.67k|{
   14|  8.67k|   mp_int  x, y, u, v, B, D;
   15|  8.67k|   mp_sign neg;
   16|  8.67k|   mp_err  err;
   17|       |
   18|       |   /* 2. [modified] b must be odd   */
   19|  8.67k|   if (MP_IS_EVEN(b)) {
  ------------------
  |  |  164|  8.67k|#define MP_IS_EVEN(a) (((a)->used == 0) || (((a)->dp[0] & 1u) == 0u))
  |  |  ------------------
  |  |  |  Branch (164:24): [True: 0, False: 8.67k]
  |  |  |  Branch (164:44): [True: 0, False: 8.67k]
  |  |  ------------------
  ------------------
   20|      0|      return MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
   21|      0|   }
   22|       |
   23|       |   /* init all our temps */
   24|  8.67k|   if ((err = mp_init_multi(&x, &y, &u, &v, &B, &D, NULL)) != MP_OKAY) {
  ------------------
  |  |  161|  8.67k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (24:8): [True: 0, False: 8.67k]
  ------------------
   25|      0|      return err;
   26|      0|   }
   27|       |
   28|       |   /* x == modulus, y == value to invert */
   29|  8.67k|   if ((err = mp_copy(b, &x)) != MP_OKAY)                         goto LBL_ERR;
  ------------------
  |  |  161|  8.67k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (29:8): [True: 0, False: 8.67k]
  ------------------
   30|       |
   31|       |   /* we need y = |a| */
   32|  8.67k|   if ((err = mp_mod(a, b, &y)) != MP_OKAY)                       goto LBL_ERR;
  ------------------
  |  |  161|  8.67k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (32:8): [True: 0, False: 8.67k]
  ------------------
   33|       |
   34|       |   /* if one of x,y is zero return an error! */
   35|  8.67k|   if (MP_IS_ZERO(&x) || MP_IS_ZERO(&y)) {
  ------------------
  |  |  163|  17.3k|#define MP_IS_ZERO(a) ((a)->used == 0)
  |  |  ------------------
  |  |  |  Branch (163:23): [True: 0, False: 8.67k]
  |  |  ------------------
  ------------------
                 if (MP_IS_ZERO(&x) || MP_IS_ZERO(&y)) {
  ------------------
  |  |  163|  8.67k|#define MP_IS_ZERO(a) ((a)->used == 0)
  |  |  ------------------
  |  |  |  Branch (163:23): [True: 0, False: 8.67k]
  |  |  ------------------
  ------------------
   36|      0|      err = MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
   37|      0|      goto LBL_ERR;
   38|      0|   }
   39|       |
   40|       |   /* 3. u=x, v=y, A=1, B=0, C=0,D=1 */
   41|  8.67k|   if ((err = mp_copy(&x, &u)) != MP_OKAY)                        goto LBL_ERR;
  ------------------
  |  |  161|  8.67k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (41:8): [True: 0, False: 8.67k]
  ------------------
   42|  8.67k|   if ((err = mp_copy(&y, &v)) != MP_OKAY)                        goto LBL_ERR;
  ------------------
  |  |  161|  8.67k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (42:8): [True: 0, False: 8.67k]
  ------------------
   43|  8.67k|   mp_set(&D, 1uL);
   44|       |
   45|  12.1M|top:
   46|       |   /* 4.  while u is even do */
   47|  24.4M|   while (MP_IS_EVEN(&u)) {
  ------------------
  |  |  164|  24.4M|#define MP_IS_EVEN(a) (((a)->used == 0) || (((a)->dp[0] & 1u) == 0u))
  |  |  ------------------
  |  |  |  Branch (164:24): [True: 0, False: 24.4M]
  |  |  |  Branch (164:44): [True: 12.2M, False: 12.1M]
  |  |  ------------------
  ------------------
   48|       |      /* 4.1 u = u/2 */
   49|  12.2M|      if ((err = mp_div_2(&u, &u)) != MP_OKAY)                    goto LBL_ERR;
  ------------------
  |  |  161|  12.2M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (49:11): [True: 0, False: 12.2M]
  ------------------
   50|       |
   51|       |      /* 4.2 if B is odd then */
   52|  12.2M|      if (MP_IS_ODD(&B)) {
  ------------------
  |  |  165|  12.2M|#define MP_IS_ODD(a)  (((a)->used > 0) && (((a)->dp[0] & 1u) == 1u))
  |  |  ------------------
  |  |  |  Branch (165:24): [True: 12.2M, False: 0]
  |  |  |  Branch (165:43): [True: 6.12M, False: 6.14M]
  |  |  ------------------
  ------------------
   53|  6.12M|         if ((err = mp_sub(&B, &x, &B)) != MP_OKAY)               goto LBL_ERR;
  ------------------
  |  |  161|  6.12M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (53:14): [True: 0, False: 6.12M]
  ------------------
   54|  6.12M|      }
   55|       |      /* B = B/2 */
   56|  12.2M|      if ((err = mp_div_2(&B, &B)) != MP_OKAY)                    goto LBL_ERR;
  ------------------
  |  |  161|  12.2M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (56:11): [True: 0, False: 12.2M]
  ------------------
   57|  12.2M|   }
   58|       |
   59|       |   /* 5.  while v is even do */
   60|  24.4M|   while (MP_IS_EVEN(&v)) {
  ------------------
  |  |  164|  24.4M|#define MP_IS_EVEN(a) (((a)->used == 0) || (((a)->dp[0] & 1u) == 0u))
  |  |  ------------------
  |  |  |  Branch (164:24): [True: 0, False: 24.4M]
  |  |  |  Branch (164:44): [True: 12.2M, False: 12.1M]
  |  |  ------------------
  ------------------
   61|       |      /* 5.1 v = v/2 */
   62|  12.2M|      if ((err = mp_div_2(&v, &v)) != MP_OKAY)                    goto LBL_ERR;
  ------------------
  |  |  161|  12.2M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (62:11): [True: 0, False: 12.2M]
  ------------------
   63|       |
   64|       |      /* 5.2 if D is odd then */
   65|  12.2M|      if (MP_IS_ODD(&D)) {
  ------------------
  |  |  165|  12.2M|#define MP_IS_ODD(a)  (((a)->used > 0) && (((a)->dp[0] & 1u) == 1u))
  |  |  ------------------
  |  |  |  Branch (165:24): [True: 12.2M, False: 0]
  |  |  |  Branch (165:43): [True: 6.17M, False: 6.07M]
  |  |  ------------------
  ------------------
   66|       |         /* D = (D-x)/2 */
   67|  6.17M|         if ((err = mp_sub(&D, &x, &D)) != MP_OKAY)               goto LBL_ERR;
  ------------------
  |  |  161|  6.17M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (67:14): [True: 0, False: 6.17M]
  ------------------
   68|  6.17M|      }
   69|       |      /* D = D/2 */
   70|  12.2M|      if ((err = mp_div_2(&D, &D)) != MP_OKAY)                    goto LBL_ERR;
  ------------------
  |  |  161|  12.2M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (70:11): [True: 0, False: 12.2M]
  ------------------
   71|  12.2M|   }
   72|       |
   73|       |   /* 6.  if u >= v then */
   74|  12.1M|   if (mp_cmp(&u, &v) != MP_LT) {
  ------------------
  |  |  154|  12.1M|#define MP_LT        -1   /* less than */
  ------------------
  |  Branch (74:8): [True: 6.09M, False: 6.10M]
  ------------------
   75|       |      /* u = u - v, B = B - D */
   76|  6.09M|      if ((err = mp_sub(&u, &v, &u)) != MP_OKAY)                  goto LBL_ERR;
  ------------------
  |  |  161|  6.09M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (76:11): [True: 0, False: 6.09M]
  ------------------
   77|       |
   78|  6.09M|      if ((err = mp_sub(&B, &D, &B)) != MP_OKAY)                  goto LBL_ERR;
  ------------------
  |  |  161|  6.09M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (78:11): [True: 0, False: 6.09M]
  ------------------
   79|  6.10M|   } else {
   80|       |      /* v - v - u, D = D - B */
   81|  6.10M|      if ((err = mp_sub(&v, &u, &v)) != MP_OKAY)                  goto LBL_ERR;
  ------------------
  |  |  161|  6.10M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (81:11): [True: 0, False: 6.10M]
  ------------------
   82|       |
   83|  6.10M|      if ((err = mp_sub(&D, &B, &D)) != MP_OKAY)                  goto LBL_ERR;
  ------------------
  |  |  161|  6.10M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (83:11): [True: 0, False: 6.10M]
  ------------------
   84|  6.10M|   }
   85|       |
   86|       |   /* if not zero goto step 4 */
   87|  12.1M|   if (!MP_IS_ZERO(&u)) {
  ------------------
  |  |  163|  12.1M|#define MP_IS_ZERO(a) ((a)->used == 0)
  ------------------
  |  Branch (87:8): [True: 12.1M, False: 8.67k]
  ------------------
   88|  12.1M|      goto top;
   89|  12.1M|   }
   90|       |
   91|       |   /* now a = C, b = D, gcd == g*v */
   92|       |
   93|       |   /* if v != 1 then there is no inverse */
   94|  8.67k|   if (mp_cmp_d(&v, 1uL) != MP_EQ) {
  ------------------
  |  |  155|  8.67k|#define MP_EQ         0   /* equal to */
  ------------------
  |  Branch (94:8): [True: 0, False: 8.67k]
  ------------------
   95|      0|      err = MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
   96|      0|      goto LBL_ERR;
   97|      0|   }
   98|       |
   99|       |   /* b is now the inverse */
  100|  8.67k|   neg = a->sign;
  101|  16.1k|   while (D.sign == MP_NEG) {
  ------------------
  |  |  152|  16.1k|#define MP_NEG        1   /* negative */
  ------------------
  |  Branch (101:11): [True: 7.52k, False: 8.67k]
  ------------------
  102|  7.52k|      if ((err = mp_add(&D, b, &D)) != MP_OKAY)                   goto LBL_ERR;
  ------------------
  |  |  161|  7.52k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (102:11): [True: 0, False: 7.52k]
  ------------------
  103|  7.52k|   }
  104|       |
  105|       |   /* too big */
  106|  8.67k|   while (mp_cmp_mag(&D, b) != MP_LT) {
  ------------------
  |  |  154|  8.67k|#define MP_LT        -1   /* less than */
  ------------------
  |  Branch (106:11): [True: 1, False: 8.67k]
  ------------------
  107|      1|      if ((err = mp_sub(&D, b, &D)) != MP_OKAY)                   goto LBL_ERR;
  ------------------
  |  |  161|      1|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (107:11): [True: 0, False: 1]
  ------------------
  108|      1|   }
  109|       |
  110|  8.67k|   mp_exch(&D, c);
  111|  8.67k|   c->sign = neg;
  112|  8.67k|   err = MP_OKAY;
  ------------------
  |  |  161|  8.67k|#define MP_OKAY       0   /* no error */
  ------------------
  113|       |
  114|  8.67k|LBL_ERR:
  115|       |   mp_clear_multi(&x, &y, &u, &v, &B, &D, NULL);
  116|  8.67k|   return err;
  117|  8.67k|}

s_mp_montgomery_reduce_fast:
   15|  56.6M|{
   16|  56.6M|   int     ix, olduse;
   17|  56.6M|   mp_err  err;
   18|  56.6M|   mp_word W[MP_WARRAY];
   19|       |
   20|  56.6M|   if (x->used > MP_WARRAY) {
  ------------------
  |  |  172|  56.6M|#define MP_WARRAY PRIVATE_MP_WARRAY
  |  |  ------------------
  |  |  |  |  203|  56.6M|#define PRIVATE_MP_WARRAY (int)(1uLL << (((CHAR_BIT * sizeof(private_mp_word)) - (2 * MP_DIGIT_BIT)) + 1))
  |  |  |  |  ------------------
  |  |  |  |  |  |   82|  56.6M|#   define MP_DIGIT_BIT 60
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (20:8): [True: 0, False: 56.6M]
  ------------------
   21|      0|      return MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
   22|      0|   }
   23|       |
   24|       |   /* get old used count */
   25|  56.6M|   olduse = x->used;
   26|       |
   27|       |   /* grow a as required */
   28|  56.6M|   if (x->alloc < (n->used + 1)) {
  ------------------
  |  Branch (28:8): [True: 0, False: 56.6M]
  ------------------
   29|      0|      if ((err = mp_grow(x, n->used + 1)) != MP_OKAY) {
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (29:11): [True: 0, False: 0]
  ------------------
   30|      0|         return err;
   31|      0|      }
   32|      0|   }
   33|       |
   34|       |   /* first we have to get the digits of the input into
   35|       |    * an array of double precision words W[...]
   36|       |    */
   37|  56.6M|   {
   38|  56.6M|      mp_word *_W;
   39|  56.6M|      mp_digit *tmpx;
   40|       |
   41|       |      /* alias for the W[] array */
   42|  56.6M|      _W   = W;
   43|       |
   44|       |      /* alias for the digits of  x*/
   45|  56.6M|      tmpx = x->dp;
   46|       |
   47|       |      /* copy the digits of a into W[0..a->used-1] */
   48|  3.80G|      for (ix = 0; ix < x->used; ix++) {
  ------------------
  |  Branch (48:20): [True: 3.74G, False: 56.6M]
  ------------------
   49|  3.74G|         *_W++ = *tmpx++;
   50|  3.74G|      }
   51|       |
   52|       |      /* zero the high words of W[a->used..m->used*2] */
   53|  56.6M|      if (ix < ((n->used * 2) + 1)) {
  ------------------
  |  Branch (53:11): [True: 56.6M, False: 0]
  ------------------
   54|  56.6M|         MP_ZERO_BUFFER(_W, sizeof(mp_word) * (size_t)(((n->used * 2) + 1) - ix));
  ------------------
  |  |   81|  56.6M|#  define MP_ZERO_BUFFER(mem, size)                     \
  |  |   82|  56.6M|do {                                                    \
  |  |   83|  56.6M|   size_t zs_ = (size);                                 \
  |  |   84|  56.6M|   char* zm_ = (char*)(mem);                            \
  |  |   85|  1.86G|   while (zs_-- > 0u) {                                 \
  |  |  ------------------
  |  |  |  Branch (85:11): [True: 1.80G, False: 56.6M]
  |  |  ------------------
  |  |   86|  1.80G|      *zm_++ = '\0';                                    \
  |  |   87|  1.80G|   }                                                    \
  |  |   88|  56.6M|} while (0)
  |  |  ------------------
  |  |  |  Branch (88:10): [Folded, False: 56.6M]
  |  |  ------------------
  ------------------
   55|  56.6M|      }
   56|  56.6M|   }
   57|       |
   58|       |   /* now we proceed to zero successive digits
   59|       |    * from the least significant upwards
   60|       |    */
   61|  1.95G|   for (ix = 0; ix < n->used; ix++) {
  ------------------
  |  Branch (61:17): [True: 1.90G, False: 56.6M]
  ------------------
   62|       |      /* mu = ai * m' mod b
   63|       |       *
   64|       |       * We avoid a double precision multiplication (which isn't required)
   65|       |       * by casting the value down to a mp_digit.  Note this requires
   66|       |       * that W[ix-1] have  the carry cleared (see after the inner loop)
   67|       |       */
   68|  1.90G|      mp_digit mu;
   69|  1.90G|      mu = ((W[ix] & MP_MASK) * rho) & MP_MASK;
  ------------------
  |  |  106|  1.90G|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|  1.90G|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
                    mu = ((W[ix] & MP_MASK) * rho) & MP_MASK;
  ------------------
  |  |  106|  1.90G|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|  1.90G|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
   70|       |
   71|       |      /* a = a + mu * m * b**i
   72|       |       *
   73|       |       * This is computed in place and on the fly.  The multiplication
   74|       |       * by b**i is handled by offseting which columns the results
   75|       |       * are added to.
   76|       |       *
   77|       |       * Note the comba method normally doesn't handle carries in the
   78|       |       * inner loop In this case we fix the carry from the previous
   79|       |       * column since the Montgomery reduction requires digits of the
   80|       |       * result (so far) [see above] to work.  This is
   81|       |       * handled by fixing up one carry after the inner loop.  The
   82|       |       * carry fixups are done in order so after these loops the
   83|       |       * first m->used words of W[] have the carries fixed
   84|       |       */
   85|  1.90G|      {
   86|  1.90G|         int iy;
   87|  1.90G|         mp_digit *tmpn;
   88|  1.90G|         mp_word *_W;
   89|       |
   90|       |         /* alias for the digits of the modulus */
   91|  1.90G|         tmpn = n->dp;
   92|       |
   93|       |         /* Alias for the columns set by an offset of ix */
   94|  1.90G|         _W = W + ix;
   95|       |
   96|       |         /* inner loop */
   97|  67.7G|         for (iy = 0; iy < n->used; iy++) {
  ------------------
  |  Branch (97:23): [True: 65.8G, False: 1.90G]
  ------------------
   98|  65.8G|            *_W++ += (mp_word)mu * (mp_word)*tmpn++;
   99|  65.8G|         }
  100|  1.90G|      }
  101|       |
  102|       |      /* now fix carry for next digit, W[ix+1] */
  103|  1.90G|      W[ix + 1] += W[ix] >> (mp_word)MP_DIGIT_BIT;
  ------------------
  |  |   82|  1.90G|#   define MP_DIGIT_BIT 60
  ------------------
  104|  1.90G|   }
  105|       |
  106|       |   /* now we have to propagate the carries and
  107|       |    * shift the words downward [all those least
  108|       |    * significant digits we zeroed].
  109|       |    */
  110|  56.6M|   {
  111|  56.6M|      mp_digit *tmpx;
  112|  56.6M|      mp_word *_W, *_W1;
  113|       |
  114|       |      /* nox fix rest of carries */
  115|       |
  116|       |      /* alias for current word */
  117|  56.6M|      _W1 = W + ix;
  118|       |
  119|       |      /* alias for next word, where the carry goes */
  120|  56.6M|      _W = W + ++ix;
  121|       |
  122|  1.95G|      for (; ix < ((n->used * 2) + 1); ix++) {
  ------------------
  |  Branch (122:14): [True: 1.90G, False: 56.6M]
  ------------------
  123|  1.90G|         *_W++ += *_W1++ >> (mp_word)MP_DIGIT_BIT;
  ------------------
  |  |   82|  1.90G|#   define MP_DIGIT_BIT 60
  ------------------
  124|  1.90G|      }
  125|       |
  126|       |      /* copy out, A = A/b**n
  127|       |       *
  128|       |       * The result is A/b**n but instead of converting from an
  129|       |       * array of mp_word to mp_digit than calling mp_rshd
  130|       |       * we just copy them in the right order
  131|       |       */
  132|       |
  133|       |      /* alias for destination word */
  134|  56.6M|      tmpx = x->dp;
  135|       |
  136|       |      /* alias for shifted double precision result */
  137|  56.6M|      _W = W + n->used;
  138|       |
  139|  2.01G|      for (ix = 0; ix < (n->used + 1); ix++) {
  ------------------
  |  Branch (139:20): [True: 1.95G, False: 56.6M]
  ------------------
  140|  1.95G|         *tmpx++ = *_W++ & (mp_word)MP_MASK;
  ------------------
  |  |  106|  1.95G|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|  1.95G|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
  141|  1.95G|      }
  142|       |
  143|       |      /* zero oldused digits, if the input a was larger than
  144|       |       * m->used+1 we'll have to clear the digits
  145|       |       */
  146|  56.6M|      MP_ZERO_DIGITS(tmpx, olduse - ix);
  ------------------
  |  |   89|  56.6M|#  define MP_ZERO_DIGITS(mem, digits)                   \
  |  |   90|  56.6M|do {                                                    \
  |  |   91|  56.6M|   int zd_ = (digits);                                  \
  |  |   92|  56.6M|   mp_digit* zm_ = (mem);                               \
  |  |   93|  1.84G|   while (zd_-- > 0) {                                  \
  |  |  ------------------
  |  |  |  Branch (93:11): [True: 1.78G, False: 56.6M]
  |  |  ------------------
  |  |   94|  1.78G|      *zm_++ = 0;                                       \
  |  |   95|  1.78G|   }                                                    \
  |  |   96|  56.6M|} while (0)
  |  |  ------------------
  |  |  |  Branch (96:10): [Folded, False: 56.6M]
  |  |  ------------------
  ------------------
  147|  56.6M|   }
  148|       |
  149|       |   /* set the max used and clamp */
  150|  56.6M|   x->used = n->used + 1;
  151|  56.6M|   mp_clamp(x);
  152|       |
  153|       |   /* if A >= m then A = A - m */
  154|  56.6M|   if (mp_cmp_mag(x, n) != MP_LT) {
  ------------------
  |  |  154|  56.6M|#define MP_LT        -1   /* less than */
  ------------------
  |  Branch (154:8): [True: 3, False: 56.6M]
  ------------------
  155|      3|      return s_mp_sub(x, n, x);
  156|      3|   }
  157|  56.6M|   return MP_OKAY;
  ------------------
  |  |  161|  56.6M|#define MP_OKAY       0   /* no error */
  ------------------
  158|  56.6M|}

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

s_mp_sqr_fast:
   17|  47.3M|{
   18|  47.3M|   int       olduse, pa, ix, iz;
   19|  47.3M|   mp_digit  W[MP_WARRAY], *tmpx;
   20|  47.3M|   mp_word   W1;
   21|  47.3M|   mp_err    err;
   22|       |
   23|       |   /* grow the destination as required */
   24|  47.3M|   pa = a->used + a->used;
   25|  47.3M|   if (b->alloc < pa) {
  ------------------
  |  Branch (25:8): [True: 68.7k, False: 47.2M]
  ------------------
   26|  68.7k|      if ((err = mp_grow(b, pa)) != MP_OKAY) {
  ------------------
  |  |  161|  68.7k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (26:11): [True: 0, False: 68.7k]
  ------------------
   27|      0|         return err;
   28|      0|      }
   29|  68.7k|   }
   30|       |
   31|       |   /* number of output digits to produce */
   32|  47.3M|   W1 = 0;
   33|  3.30G|   for (ix = 0; ix < pa; ix++) {
  ------------------
  |  Branch (33:17): [True: 3.25G, False: 47.3M]
  ------------------
   34|  3.25G|      int      tx, ty, iy;
   35|  3.25G|      mp_word  _W;
   36|  3.25G|      mp_digit *tmpy;
   37|       |
   38|       |      /* clear counter */
   39|  3.25G|      _W = 0;
   40|       |
   41|       |      /* get offsets into the two bignums */
   42|  3.25G|      ty = MP_MIN(a->used-1, ix);
  ------------------
  |  |  156|  3.25G|#define MP_MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (156:23): [True: 1.62G, False: 1.62G]
  |  |  ------------------
  ------------------
   43|  3.25G|      tx = ix - ty;
   44|       |
   45|       |      /* setup temp aliases */
   46|  3.25G|      tmpx = a->dp + tx;
   47|  3.25G|      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|  3.25G|      iy = MP_MIN(a->used-tx, ty+1);
  ------------------
  |  |  156|  3.25G|#define MP_MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (156:23): [True: 1.62G, False: 1.62G]
  |  |  ------------------
  ------------------
   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|  3.25G|      iy = MP_MIN(iy, ((ty-tx)+1)>>1);
  ------------------
  |  |  156|  3.25G|#define MP_MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (156:23): [True: 0, False: 3.25G]
  |  |  ------------------
  ------------------
   59|       |
   60|       |      /* execute loop */
   61|  30.8G|      for (iz = 0; iz < iy; iz++) {
  ------------------
  |  Branch (61:20): [True: 27.5G, False: 3.25G]
  ------------------
   62|  27.5G|         _W += (mp_word)*tmpx++ * (mp_word)*tmpy--;
   63|  27.5G|      }
   64|       |
   65|       |      /* double the inner product and add carry */
   66|  3.25G|      _W = _W + _W + W1;
   67|       |
   68|       |      /* even columns have the square term in them */
   69|  3.25G|      if (((unsigned)ix & 1u) == 0u) {
  ------------------
  |  Branch (69:11): [True: 1.62G, False: 1.62G]
  ------------------
   70|  1.62G|         _W += (mp_word)a->dp[ix>>1] * (mp_word)a->dp[ix>>1];
   71|  1.62G|      }
   72|       |
   73|       |      /* store it */
   74|  3.25G|      W[ix] = (mp_digit)_W & MP_MASK;
  ------------------
  |  |  106|  3.25G|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|  3.25G|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
   75|       |
   76|       |      /* make next carry */
   77|  3.25G|      W1 = _W >> (mp_word)MP_DIGIT_BIT;
  ------------------
  |  |   82|  3.25G|#   define MP_DIGIT_BIT 60
  ------------------
   78|  3.25G|   }
   79|       |
   80|       |   /* setup dest */
   81|  47.3M|   olduse  = b->used;
   82|  47.3M|   b->used = a->used+a->used;
   83|       |
   84|  47.3M|   {
   85|  47.3M|      mp_digit *tmpb;
   86|  47.3M|      tmpb = b->dp;
   87|  3.30G|      for (ix = 0; ix < pa; ix++) {
  ------------------
  |  Branch (87:20): [True: 3.25G, False: 47.3M]
  ------------------
   88|  3.25G|         *tmpb++ = W[ix] & MP_MASK;
  ------------------
  |  |  106|  3.25G|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|  3.25G|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
   89|  3.25G|      }
   90|       |
   91|       |      /* clear unused digits [that existed in the old copy of c] */
   92|  47.3M|      MP_ZERO_DIGITS(tmpb, olduse - ix);
  ------------------
  |  |   89|  47.3M|#  define MP_ZERO_DIGITS(mem, digits)                   \
  |  |   90|  47.3M|do {                                                    \
  |  |   91|  47.3M|   int zd_ = (digits);                                  \
  |  |   92|  47.3M|   mp_digit* zm_ = (mem);                               \
  |  |   93|  47.3M|   while (zd_-- > 0) {                                  \
  |  |  ------------------
  |  |  |  Branch (93:11): [True: 27.0k, False: 47.3M]
  |  |  ------------------
  |  |   94|  27.0k|      *zm_++ = 0;                                       \
  |  |   95|  27.0k|   }                                                    \
  |  |   96|  47.3M|} while (0)
  |  |  ------------------
  |  |  |  Branch (96:10): [Folded, False: 47.3M]
  |  |  ------------------
  ------------------
   93|  47.3M|   }
   94|  47.3M|   mp_clamp(b);
   95|  47.3M|   return MP_OKAY;
  ------------------
  |  |  161|  47.3M|#define MP_OKAY       0   /* no error */
  ------------------
   96|  47.3M|}

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

m_mp_init:
   31|  7.07k|void m_mp_init(mp_int *mp) {
   32|       |
   33|  7.07k|	if (mp_init(mp) != MP_OKAY) {
  ------------------
  |  |  161|  7.07k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (33:6): [True: 0, False: 7.07k]
  ------------------
   34|      0|		dropbear_exit("Mem alloc error");
   35|      0|	}
   36|  7.07k|}
m_mp_init_multi:
   41|  22.2k|{
   42|  22.2k|	mp_int* cur_arg = mp;
   43|  22.2k|	va_list args;
   44|       |
   45|  22.2k|	va_start(args, mp);        /* init args to next argument from caller */
   46|   146k|	while (cur_arg != NULL) {
  ------------------
  |  Branch (46:9): [True: 124k, False: 22.2k]
  ------------------
   47|   124k|		if (mp_init(cur_arg) != MP_OKAY) {
  ------------------
  |  |  161|   124k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (47:7): [True: 0, False: 124k]
  ------------------
   48|      0|			dropbear_exit("Mem alloc error");
   49|      0|		}
   50|   124k|		cur_arg = va_arg(args, mp_int*);
   51|   124k|	}
   52|  22.2k|	va_end(args);
   53|  22.2k|}
m_mp_alloc_init_multi:
   56|  8.40k|{
   57|  8.40k|	mp_int** cur_arg = mp;
   58|  8.40k|	va_list args;
   59|       |
   60|  8.40k|	va_start(args, mp);        /* init args to next argument from caller */
   61|  16.8k|	while (cur_arg != NULL) {
  ------------------
  |  Branch (61:9): [True: 8.41k, False: 8.40k]
  ------------------
   62|  8.41k|		*cur_arg = m_malloc(sizeof(mp_int));
   63|  8.41k|		if (mp_init(*cur_arg) != MP_OKAY) {
  ------------------
  |  |  161|  8.41k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (63:7): [True: 0, False: 8.41k]
  ------------------
   64|      0|			dropbear_exit("Mem alloc error");
   65|      0|		}
   66|  8.41k|		cur_arg = va_arg(args, mp_int**);
   67|  8.41k|	}
   68|  8.40k|	va_end(args);
   69|  8.40k|}
bytes_to_mp:
   87|  51.4k|void bytes_to_mp(mp_int *mp, const unsigned char* bytes, unsigned int len) {
   88|       |
   89|  51.4k|	if (mp_from_ubin(mp, (unsigned char*)bytes, len) != MP_OKAY) {
  ------------------
  |  |  161|  51.4k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (89:6): [True: 0, False: 51.4k]
  ------------------
   90|      0|		dropbear_exit("Mem alloc error");
   91|      0|	}
   92|  51.4k|}
hash_process_mp:
   96|  8.39k|				hash_state *hs, const mp_int *mp) {
   97|  8.39k|	buffer * buf;
   98|       |
   99|  8.39k|	buf = buf_new(512 + 20); /* max buffer is a 4096 bit key, 
  100|       |								plus header + some leeway*/
  101|  8.39k|	buf_putmpint(buf, mp);
  102|  8.39k|	hash_desc->process(hs, buf->data, buf->len);
  103|  8.39k|	buf_burn_free(buf);
  104|  8.39k|}
m_mp_burn:
  106|  41.9k|void m_mp_burn(mp_int *mp) {
  107|  41.9k|	m_burn(mp->dp, mp->alloc * sizeof(*mp->dp));
  108|  41.9k|	mp->used = 0;
  109|  41.9k|}

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

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

buf_put_algolist_all:
  361|  82.6k|void buf_put_algolist_all(buffer * buf, const algo_type localalgos[], int useall) {
  362|  82.6k|	unsigned int i, len;
  363|  82.6k|	unsigned int donefirst = 0;
  364|  82.6k|	unsigned int startpos;
  365|       |
  366|  82.6k|	startpos = buf->pos;
  367|       |	/* Placeholder for length */
  368|  82.6k|	buf_putint(buf, 0); 
  369|   413k|	for (i = 0; localalgos[i].name != NULL; i++) {
  ------------------
  |  Branch (369:14): [True: 331k, False: 82.6k]
  ------------------
  370|   331k|		if (localalgos[i].usable || useall) {
  ------------------
  |  Branch (370:7): [True: 234k, False: 96.8k]
  |  Branch (370:31): [True: 768, False: 96.1k]
  ------------------
  371|   235k|			if (donefirst) {
  ------------------
  |  Branch (371:8): [True: 152k, False: 82.6k]
  ------------------
  372|   152k|				buf_putbyte(buf, ',');
  373|   152k|			}
  374|   235k|			donefirst = 1;
  375|   235k|			len = strlen(localalgos[i].name);
  376|   235k|			buf_putbytes(buf, (const unsigned char *) localalgos[i].name, len);
  377|   235k|		}
  378|   331k|	}
  379|       |	/* Fill out the length */
  380|  82.6k|	len = buf->pos - startpos - 4;
  381|  82.6k|	buf_setpos(buf, startpos);
  382|  82.6k|	buf_putint(buf, len);
  383|  82.6k|	TRACE(("algolist add %d '%.*s'", len, len, buf_getptr(buf, len)))
  384|  82.6k|	buf_incrwritepos(buf, len);
  385|  82.6k|}
buf_put_algolist:
  387|  82.6k|void buf_put_algolist(buffer * buf, const algo_type localalgos[]) {
  388|  82.6k|	buf_put_algolist_all(buf, localalgos, 0);
  389|  82.6k|}
buf_has_algo:
  433|  15.1k|int buf_has_algo(buffer *buf, const char *algo) {
  434|  15.1k|	unsigned char* algolist = NULL;
  435|  15.1k|	unsigned int orig_pos = buf->pos;
  436|  15.1k|	unsigned int len, remotecount, i;
  437|  15.1k|	const char *remotenames[MAX_PROPOSED_ALGO];
  438|  15.1k|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  112|  15.1k|#define DROPBEAR_FAILURE -1
  ------------------
  439|       |
  440|  15.1k|	algolist = buf_getstring(buf, &len);
  441|  15.1k|	remotecount = MAX_PROPOSED_ALGO;
  ------------------
  |  |  237|  15.1k|#define MAX_PROPOSED_ALGO 50
  ------------------
  442|  15.1k|	get_algolist(algolist, len, remotenames, &remotecount);
  443|  79.7k|	for (i = 0; i < remotecount; i++)
  ------------------
  |  Branch (443:14): [True: 64.8k, False: 14.8k]
  ------------------
  444|  64.8k|	{
  445|  64.8k|		if (strcmp(remotenames[i], algo) == 0) {
  ------------------
  |  Branch (445:7): [True: 283, False: 64.5k]
  ------------------
  446|    283|			ret = DROPBEAR_SUCCESS;
  ------------------
  |  |  111|    283|#define DROPBEAR_SUCCESS 0
  ------------------
  447|    283|			break;
  448|    283|		}
  449|  64.8k|	}
  450|  15.1k|	if (algolist) {
  ------------------
  |  Branch (450:6): [True: 15.0k, False: 82]
  ------------------
  451|       |		m_free(algolist);
  ------------------
  |  |   24|  15.0k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 15.0k]
  |  |  ------------------
  ------------------
  452|  15.0k|	}
  453|  15.1k|	buf_setpos(buf, orig_pos);
  454|  15.1k|	return ret;
  455|  15.1k|}
buf_match_algo:
  473|  74.5k|		int kexguess2, int *goodguess) {
  474|  74.5k|	char * algolist = NULL;
  475|  74.5k|	const char *remotenames[MAX_PROPOSED_ALGO], *localnames[MAX_PROPOSED_ALGO];
  476|  74.5k|	unsigned int len;
  477|  74.5k|	unsigned int remotecount, localcount, clicount, servcount, i, j;
  478|  74.5k|	algo_type * ret = NULL;
  479|  74.5k|	const char **clinames, **servnames;
  480|       |
  481|  74.5k|	if (goodguess) {
  ------------------
  |  Branch (481:6): [True: 19.0k, False: 55.5k]
  ------------------
  482|  19.0k|		*goodguess = 0;
  483|  19.0k|	}
  484|       |
  485|       |	/* get the comma-separated list from the buffer ie "algo1,algo2,algo3" */
  486|  74.5k|	algolist = buf_getstring(buf, &len);
  487|  74.5k|	DEBUG3(("buf_match_algo: %s", algolist))
  488|  74.5k|	remotecount = MAX_PROPOSED_ALGO;
  ------------------
  |  |  237|  74.5k|#define MAX_PROPOSED_ALGO 50
  ------------------
  489|  74.5k|	get_algolist(algolist, len, remotenames, &remotecount);
  490|       |
  491|   376k|	for (i = 0; localalgos[i].name != NULL; i++) {
  ------------------
  |  Branch (491:14): [True: 302k, False: 74.5k]
  ------------------
  492|   302k|		if (localalgos[i].usable) {
  ------------------
  |  Branch (492:7): [True: 209k, False: 92.8k]
  ------------------
  493|   209k|			localnames[i] = localalgos[i].name;
  494|   209k|		} else {
  495|  92.8k|			localnames[i] = NULL;
  496|  92.8k|		}
  497|   302k|	}
  498|  74.5k|	localcount = i;
  499|       |
  500|  74.5k|	if (IS_DROPBEAR_SERVER) {
  ------------------
  |  |  381|  74.5k|#define IS_DROPBEAR_SERVER (ses.isserver == 1)
  |  |  ------------------
  |  |  |  Branch (381:28): [True: 74.4k, False: 55]
  |  |  ------------------
  ------------------
  501|  74.4k|		clinames = remotenames;
  502|  74.4k|		clicount = remotecount;
  503|  74.4k|		servnames = localnames;
  504|  74.4k|		servcount = localcount;
  505|  74.4k|	} else {
  506|     55|		clinames = localnames;
  507|     55|		clicount = localcount;
  508|     55|		servnames = remotenames;
  509|     55|		servcount = remotecount;
  510|     55|	}
  511|       |
  512|       |	/* iterate and find the first match */
  513|  86.3k|	for (i = 0; i < clicount; i++) {
  ------------------
  |  Branch (513:14): [True: 84.8k, False: 1.53k]
  ------------------
  514|   335k|		for (j = 0; j < servcount; j++) {
  ------------------
  |  Branch (514:15): [True: 323k, False: 11.8k]
  ------------------
  515|   323k|			if (!(servnames[j] && clinames[i])) {
  ------------------
  |  Branch (515:10): [True: 241k, False: 81.8k]
  |  Branch (515:26): [True: 241k, False: 0]
  ------------------
  516|       |				/* unusable algos are NULL */
  517|  81.8k|				continue;
  518|  81.8k|			}
  519|   241k|			if (strcmp(servnames[j], clinames[i]) == 0) {
  ------------------
  |  Branch (519:8): [True: 72.9k, False: 168k]
  ------------------
  520|       |				/* set if it was a good guess */
  521|  72.9k|				if (goodguess != NULL) {
  ------------------
  |  Branch (521:9): [True: 18.6k, False: 54.2k]
  ------------------
  522|  18.6k|					if (kexguess2) {
  ------------------
  |  Branch (522:10): [True: 238, False: 18.4k]
  ------------------
  523|    238|						if (i == 0) {
  ------------------
  |  Branch (523:11): [True: 180, False: 58]
  ------------------
  524|    180|							*goodguess = 1;
  525|    180|						}
  526|  18.4k|					} else {
  527|  18.4k|						if (i == 0 && j == 0) {
  ------------------
  |  Branch (527:11): [True: 16.7k, False: 1.67k]
  |  Branch (527:21): [True: 4, False: 16.7k]
  ------------------
  528|      4|							*goodguess = 1;
  529|      4|						}
  530|  18.4k|					}
  531|  18.6k|				}
  532|       |				/* set the algo to return */
  533|  72.9k|				if (IS_DROPBEAR_SERVER) {
  ------------------
  |  |  381|  72.9k|#define IS_DROPBEAR_SERVER (ses.isserver == 1)
  |  |  ------------------
  |  |  |  Branch (381:28): [True: 72.9k, False: 0]
  |  |  ------------------
  ------------------
  534|  72.9k|					ret = &localalgos[j];
  535|  72.9k|				} else {
  536|      0|					ret = &localalgos[i];
  537|      0|				}
  538|  72.9k|				goto out;
  539|  72.9k|			}
  540|   241k|		}
  541|  84.8k|	}
  542|       |
  543|  74.4k|out:
  544|       |	m_free(algolist);
  ------------------
  |  |   24|  74.4k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 74.4k]
  |  |  ------------------
  ------------------
  545|  74.4k|	return ret;
  546|  74.5k|}
common-algo.c:void_start:
   52|  8.39k|			int UNUSED(keylen), int UNUSED(num_rounds), void* UNUSED(cipher_state)) {
   53|  8.39k|	return CRYPT_OK;
   54|  8.39k|}
common-algo.c:void_cipher:
   43|   117k|		unsigned long len, void* UNUSED(cipher_state)) {
   44|   117k|	if (in != out) {
  ------------------
  |  Branch (44:6): [True: 0, False: 117k]
  ------------------
   45|      0|		memmove(out, in, len);
   46|      0|	}
   47|   117k|	return CRYPT_OK;
   48|   117k|}
common-algo.c:dropbear_big_endian_ctr_start:
   93|  7.97k|		int num_rounds, symmetric_CTR *ctr) {
   94|  7.97k|	return ctr_start(cipher, IV, key, keylen, num_rounds, CTR_COUNTER_BIG_ENDIAN, ctr);
  ------------------
  |  |  860|  7.97k|#define CTR_COUNTER_BIG_ENDIAN       0x1000
  ------------------
   95|  7.97k|}
common-algo.c:get_algolist:
  396|  89.5k|				const char* *ret_list, unsigned int *ret_count) {
  397|  89.5k|	unsigned int max_count = *ret_count;
  398|  89.5k|	unsigned int i;
  399|       |
  400|  89.5k|	if (*ret_count == 0) {
  ------------------
  |  Branch (400:6): [True: 0, False: 89.5k]
  ------------------
  401|      0|		return;
  402|      0|	}
  403|  89.5k|	if (algolist_len > MAX_PROPOSED_ALGO*(MAX_NAME_LEN+1)) {
  ------------------
  |  |  237|  89.5k|#define MAX_PROPOSED_ALGO 50
  ------------------
              	if (algolist_len > MAX_PROPOSED_ALGO*(MAX_NAME_LEN+1)) {
  ------------------
  |  |  233|  89.5k|#define MAX_NAME_LEN 64 /* maximum length of a protocol name, isn't
  ------------------
  |  Branch (403:6): [True: 8, False: 89.5k]
  ------------------
  404|      8|		*ret_count = 0;
  405|      8|	}
  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|  89.5k|	ret_list[0] = algolist;
  410|  89.5k|	*ret_count = 1;
  411|  1.94M|	for (i = 0; i < algolist_len; i++) {
  ------------------
  |  Branch (411:14): [True: 1.85M, False: 88.7k]
  ------------------
  412|  1.85M|		if (algolist[i] == '\0') {
  ------------------
  |  Branch (412:7): [True: 719, False: 1.85M]
  ------------------
  413|       |			/* someone is trying something strange */
  414|    719|			*ret_count = 0;
  415|    719|			return;
  416|    719|		}
  417|       |
  418|  1.85M|		if (algolist[i] == ',') {
  ------------------
  |  Branch (418:7): [True: 87.1k, False: 1.76M]
  ------------------
  419|  87.1k|			if (*ret_count >= max_count) {
  ------------------
  |  Branch (419:8): [True: 6, False: 87.1k]
  ------------------
  420|      6|				dropbear_exit("Too many remote algorithms");
  421|      0|				*ret_count = 0;
  422|      0|				return;
  423|      6|			}
  424|  87.1k|			algolist[i] = '\0';
  425|  87.1k|			ret_list[*ret_count] = &algolist[i+1];
  426|  87.1k|			(*ret_count)++;
  427|  87.1k|		}
  428|  1.85M|	}
  429|  89.5k|}

chaninitialise:
   70|  3.35k|void chaninitialise(const struct ChanType *chantypes[]) {
   71|       |
   72|       |	/* may as well create space for a single channel */
   73|  3.35k|	ses.channels = (struct Channel**)m_malloc(sizeof(struct Channel*));
   74|  3.35k|	ses.chansize = 1;
   75|  3.35k|	ses.channels[0] = NULL;
   76|  3.35k|	ses.chancount = 0;
   77|       |
   78|  3.35k|	ses.chantypes = chantypes;
   79|       |
   80|  3.35k|#if DROPBEAR_LISTENERS
   81|  3.35k|	listeners_initialise();
   82|  3.35k|#endif
   83|       |
   84|  3.35k|}
chancleanup:
   87|  3.35k|void chancleanup() {
   88|       |
   89|  3.35k|	unsigned int i;
   90|       |
   91|  3.35k|	TRACE(("enter chancleanup"))
   92|  6.71k|	for (i = 0; i < ses.chansize; i++) {
  ------------------
  |  Branch (92:14): [True: 3.35k, False: 3.35k]
  ------------------
   93|  3.35k|		if (ses.channels[i] != NULL) {
  ------------------
  |  Branch (93:7): [True: 0, False: 3.35k]
  ------------------
   94|      0|			TRACE(("channel %d closing", i))
   95|      0|			remove_channel(ses.channels[i]);
   96|      0|		}
   97|  3.35k|	}
   98|       |	m_free(ses.channels);
  ------------------
  |  |   24|  3.35k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 3.35k]
  |  |  ------------------
  ------------------
   99|  3.35k|	TRACE(("leave chancleanup"))
  100|  3.35k|}
channelio:
  199|   260k|void channelio(const fd_set *readfds, const fd_set *writefds) {
  200|       |
  201|       |	/* Listeners such as TCP, X11, agent-auth */
  202|   260k|	struct Channel *channel;
  203|   260k|	unsigned int i;
  204|       |
  205|       |	/* foreach channel */
  206|   521k|	for (i = 0; i < ses.chansize; i++) {
  ------------------
  |  Branch (206:14): [True: 260k, False: 260k]
  ------------------
  207|       |		/* Close checking only needs to occur for channels that had IO events */
  208|   260k|		int do_check_close = 0;
  209|       |
  210|   260k|		channel = ses.channels[i];
  211|   260k|		if (channel == NULL) {
  ------------------
  |  Branch (211:7): [True: 260k, False: 0]
  ------------------
  212|       |			/* only process in-use channels */
  213|   260k|			continue;
  214|   260k|		}
  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|   260k|#if DROPBEAR_LISTENERS
  256|   260k|	handle_listeners(readfds);
  257|   260k|#endif
  258|   260k|}
setchannelfds:
  542|   264k|void setchannelfds(fd_set *readfds, fd_set *writefds, int allow_reads) {
  543|       |	
  544|   264k|	unsigned int i;
  545|   264k|	struct Channel * channel;
  546|       |	
  547|   528k|	for (i = 0; i < ses.chansize; i++) {
  ------------------
  |  Branch (547:14): [True: 264k, False: 264k]
  ------------------
  548|       |
  549|   264k|		channel = ses.channels[i];
  550|   264k|		if (channel == NULL) {
  ------------------
  |  Branch (550:7): [True: 264k, False: 0]
  ------------------
  551|   264k|			continue;
  552|   264k|		}
  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|   264k|#if DROPBEAR_LISTENERS
  584|   264k|	set_listener_fds(readfds);
  585|   264k|#endif
  586|       |
  587|   264k|}

send_msg_kexinit:
   51|  10.3k|void send_msg_kexinit() {
   52|       |
   53|  10.3k|	CHECKCLEARTOWRITE();
   54|  10.3k|	buf_putbyte(ses.writepayload, SSH_MSG_KEXINIT);
  ------------------
  |  |   36|  10.3k|#define SSH_MSG_KEXINIT                20
  ------------------
   55|       |
   56|       |	/* cookie */
   57|  10.3k|	genrandom(buf_getwriteptr(ses.writepayload, 16), 16);
   58|  10.3k|	buf_incrwritepos(ses.writepayload, 16);
   59|       |
   60|       |	/* kex algos */
   61|  10.3k|	buf_put_algolist(ses.writepayload, sshkex);
   62|       |
   63|       |	/* server_host_key_algorithms */
   64|  10.3k|	buf_put_algolist(ses.writepayload, sigalgs);
   65|       |
   66|       |	/* encryption_algorithms_client_to_server */
   67|  10.3k|	buf_put_algolist(ses.writepayload, sshciphers);
   68|       |
   69|       |	/* encryption_algorithms_server_to_client */
   70|  10.3k|	buf_put_algolist(ses.writepayload, sshciphers);
   71|       |
   72|       |	/* mac_algorithms_client_to_server */
   73|  10.3k|	buf_put_algolist(ses.writepayload, sshhashes);
   74|       |
   75|       |	/* mac_algorithms_server_to_client */
   76|  10.3k|	buf_put_algolist(ses.writepayload, sshhashes);
   77|       |
   78|       |
   79|       |	/* compression_algorithms_client_to_server */
   80|  10.3k|	buf_put_algolist(ses.writepayload, ses.compress_algos_c2s);
   81|       |
   82|       |	/* compression_algorithms_server_to_client */
   83|  10.3k|	buf_put_algolist(ses.writepayload, ses.compress_algos_s2c);
   84|       |
   85|       |	/* languages_client_to_server */
   86|  10.3k|	buf_putstring(ses.writepayload, "", 0);
   87|       |
   88|       |	/* languages_server_to_client */
   89|  10.3k|	buf_putstring(ses.writepayload, "", 0);
   90|       |
   91|       |	/* first_kex_packet_follows */
   92|  10.3k|	buf_putbyte(ses.writepayload, (ses.send_kex_first_guess != NULL));
   93|       |
   94|       |	/* reserved unit32 */
   95|  10.3k|	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|  10.3k|	ses.transkexinit = buf_newcopy(ses.writepayload);
  100|       |
  101|  10.3k|	encrypt_packet();
  102|  10.3k|	ses.dataallowed = 0; /* don't send other packets during kex */
  103|       |
  104|  10.3k|	ses.kexstate.sentkexinit = 1;
  105|       |
  106|  10.3k|	ses.newkeys = (struct key_context*)m_malloc(sizeof(struct key_context));
  107|       |
  108|  10.3k|	if (ses.send_kex_first_guess) {
  ------------------
  |  Branch (108:6): [True: 0, False: 10.3k]
  ------------------
  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|  10.3k|	TRACE(("DATAALLOWED=0"))
  116|  10.3k|	TRACE(("-> KEXINIT"))
  117|       |
  118|  10.3k|}
send_msg_newkeys:
  161|  8.39k|void send_msg_newkeys() {
  162|       |
  163|  8.39k|	TRACE(("enter send_msg_newkeys"))
  164|       |
  165|       |	/* generate the kexinit request */
  166|  8.39k|	CHECKCLEARTOWRITE();
  167|  8.39k|	buf_putbyte(ses.writepayload, SSH_MSG_NEWKEYS);
  ------------------
  |  |   37|  8.39k|#define SSH_MSG_NEWKEYS                21
  ------------------
  168|  8.39k|	encrypt_packet();
  169|       |
  170|       |	
  171|       |	/* set up our state */
  172|  8.39k|	ses.kexstate.sentnewkeys = 1;
  173|  8.39k|	if (ses.kexstate.donefirstkex) {
  ------------------
  |  Branch (173:6): [True: 6.69k, False: 1.69k]
  ------------------
  174|  6.69k|		ses.kexstate.donesecondkex = 1;
  175|  6.69k|	}
  176|  8.39k|	ses.kexstate.donefirstkex = 1;
  177|  8.39k|	ses.dataallowed = 1; /* we can send other packets again now */
  178|  8.39k|	gen_new_keys();
  179|  8.39k|	switch_keys();
  180|       |
  181|  8.39k|	if (ses.kexstate.strict_kex) {
  ------------------
  |  Branch (181:6): [True: 125, False: 8.27k]
  ------------------
  182|    125|		ses.transseq = 0;
  183|    125|	}
  184|       |
  185|  8.39k|	TRACE(("leave send_msg_newkeys"))
  186|  8.39k|}
recv_msg_newkeys:
  189|  7.73k|void recv_msg_newkeys() {
  190|       |
  191|  7.73k|	TRACE(("enter recv_msg_newkeys"))
  192|       |
  193|  7.73k|	ses.kexstate.recvnewkeys = 1;
  194|  7.73k|	switch_keys();
  195|       |
  196|  7.73k|	if (ses.kexstate.strict_kex) {
  ------------------
  |  Branch (196:6): [True: 119, False: 7.61k]
  ------------------
  197|    119|		ses.recvseq = 0;
  198|    119|	}
  199|  7.73k|	ses.kexstate.recvfirstnewkeys = 1;
  200|       |
  201|  7.73k|	TRACE(("leave recv_msg_newkeys"))
  202|  7.73k|}
kexfirstinitialise:
  230|  3.35k|void kexfirstinitialise() {
  231|  3.35k|	kex_setup_compress();
  232|  3.35k|	kexinitialise();
  233|  3.35k|}
recv_msg_kexinit:
  492|  9.74k|void recv_msg_kexinit() {
  493|       |	
  494|  9.74k|	unsigned int kexhashbuf_len = 0;
  495|  9.74k|	unsigned int remote_ident_len = 0;
  496|  9.74k|	unsigned int local_ident_len = 0;
  497|       |
  498|  9.74k|	TRACE(("<- KEXINIT"))
  499|  9.74k|	TRACE(("enter recv_msg_kexinit"))
  500|       |	
  501|  9.74k|	if (!ses.kexstate.sentkexinit) {
  ------------------
  |  Branch (501:6): [True: 6.96k, False: 2.77k]
  ------------------
  502|       |		/* we need to send a kex packet */
  503|  6.96k|		send_msg_kexinit();
  504|  6.96k|		TRACE(("continue recv_msg_kexinit: sent kexinit"))
  505|  6.96k|	}
  506|       |
  507|       |	/* "Once a party has sent a SSH_MSG_KEXINIT message ...
  508|       |	further SSH_MSG_KEXINIT messages MUST NOT be sent" */
  509|  9.74k|	if (ses.kexstate.recvkexinit) {
  ------------------
  |  Branch (509:6): [True: 0, False: 9.74k]
  ------------------
  510|      0|		dropbear_exit("Unexpected KEXINIT");
  511|      0|	}
  512|       |
  513|       |	/* start the kex hash */
  514|  9.74k|	local_ident_len = strlen(LOCAL_IDENT);
  ------------------
  |  |   14|  9.74k|#define LOCAL_IDENT "SSH-2.0-dropbear" IDENT_VERSION_PART
  |  |  ------------------
  |  |  |  |   12|  9.74k|#define IDENT_VERSION_PART "_" DROPBEAR_VERSION
  |  |  |  |  ------------------
  |  |  |  |  |  |    7|  9.74k|#define DROPBEAR_VERSION "2026.91"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  515|  9.74k|	remote_ident_len = strlen(ses.remoteident);
  516|       |
  517|  9.74k|	kexhashbuf_len = local_ident_len + remote_ident_len
  518|  9.74k|		+ ses.transkexinit->len + ses.payload->len
  519|  9.74k|		+ KEXHASHBUF_MAX_INTS;
  ------------------
  |  |  290|  9.74k|#define KEXHASHBUF_MAX_INTS (MAX_PUBKEY_SIZE + MAX_KEX_PARTS)
  |  |  ------------------
  |  |  |  |  261|  9.74k|#define MAX_PUBKEY_SIZE 600
  |  |  ------------------
  |  |               #define KEXHASHBUF_MAX_INTS (MAX_PUBKEY_SIZE + MAX_KEX_PARTS)
  |  |  ------------------
  |  |  |  |  274|  9.74k|#define MAX_KEX_PARTS (2*4 + 1184 + 1088 + 32*2 + 68)
  |  |  ------------------
  ------------------
  520|       |
  521|  9.74k|	ses.kexhashbuf = buf_new(kexhashbuf_len);
  522|       |
  523|  9.74k|	if (IS_DROPBEAR_CLIENT) {
  ------------------
  |  |  382|  9.74k|#define IS_DROPBEAR_CLIENT (ses.isserver == 0)
  |  |  ------------------
  |  |  |  Branch (382:28): [True: 0, False: 9.74k]
  |  |  ------------------
  ------------------
  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|  9.74k|	} else {
  543|       |		/* SERVER */
  544|       |
  545|       |		/* read the peer's choice of algos */
  546|  9.74k|		read_kex_algos();
  547|       |		/* V_C, the client's version string (CR and NL excluded) */
  548|  9.74k|		buf_putstring(ses.kexhashbuf, ses.remoteident, remote_ident_len);
  549|       |		/* V_S, the server's version string (CR and NL excluded) */
  550|  9.74k|		buf_putstring(ses.kexhashbuf, LOCAL_IDENT, local_ident_len);
  ------------------
  |  |   14|  9.74k|#define LOCAL_IDENT "SSH-2.0-dropbear" IDENT_VERSION_PART
  |  |  ------------------
  |  |  |  |   12|  9.74k|#define IDENT_VERSION_PART "_" DROPBEAR_VERSION
  |  |  |  |  ------------------
  |  |  |  |  |  |    7|  9.74k|#define DROPBEAR_VERSION "2026.91"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  551|       |
  552|       |		/* I_C, the payload of the client's SSH_MSG_KEXINIT */
  553|  9.74k|		buf_setpos(ses.payload, ses.payload_beginning);
  554|  9.74k|		buf_putstring(ses.kexhashbuf, 
  555|  9.74k|			(const char*)buf_getptr(ses.payload, ses.payload->len-ses.payload->pos),
  556|  9.74k|			ses.payload->len-ses.payload->pos);
  557|       |
  558|       |		/* I_S, the payload of the server's SSH_MSG_KEXINIT */
  559|  9.74k|		buf_putstring(ses.kexhashbuf,
  560|  9.74k|			(const char*)ses.transkexinit->data, ses.transkexinit->len);
  561|       |
  562|  9.74k|		ses.requirenext = SSH_MSG_KEXDH_INIT;
  ------------------
  |  |   38|  9.74k|#define SSH_MSG_KEXDH_INIT             30
  ------------------
  563|  9.74k|	}
  564|       |
  565|  9.74k|	buf_free(ses.transkexinit);
  566|  9.74k|	ses.transkexinit = NULL;
  567|       |	/* the rest of ses.kexhashbuf will be done after DH exchange */
  568|       |
  569|  9.74k|	ses.kexstate.recvkexinit = 1;
  570|       |
  571|  9.74k|	if (ses.kexstate.strict_kex && !ses.kexstate.donefirstkex && ses.recvseq != 1) {
  ------------------
  |  Branch (571:6): [True: 148, False: 9.59k]
  |  Branch (571:33): [True: 41, False: 107]
  |  Branch (571:63): [True: 8, False: 33]
  ------------------
  572|      8|		dropbear_exit("First packet wasn't kexinit");
  573|      8|	}
  574|       |
  575|  9.74k|	TRACE(("leave recv_msg_kexinit"))
  576|  9.74k|}
finish_kexhashbuf:
  579|  8.39k|void finish_kexhashbuf(void) {
  580|  8.39k|	hash_state hs;
  581|  8.39k|	const struct ltc_hash_descriptor *hash_desc = ses.newkeys->algo_kex->hash_desc;
  582|       |
  583|  8.39k|	hash_desc->init(&hs);
  584|  8.39k|	buf_setpos(ses.kexhashbuf, 0);
  585|  8.39k|	hash_desc->process(&hs, buf_getptr(ses.kexhashbuf, ses.kexhashbuf->len),
  586|  8.39k|			ses.kexhashbuf->len);
  587|  8.39k|	ses.hash = buf_new(hash_desc->hashsize);
  588|  8.39k|	hash_desc->done(&hs, buf_getwriteptr(ses.hash, hash_desc->hashsize));
  589|  8.39k|	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|  8.39k|	buf_burn_free(ses.kexhashbuf);
  599|  8.39k|	m_burn(&hs, sizeof(hash_state));
  600|  8.39k|	ses.kexhashbuf = NULL;
  601|       |	
  602|       |	/* first time around, we set the session_id to H */
  603|  8.39k|	if (ses.session_id == NULL) {
  ------------------
  |  Branch (603:6): [True: 1.69k, False: 6.69k]
  ------------------
  604|       |		/* create the session_id, this never needs freeing */
  605|  1.69k|		ses.session_id = buf_newcopy(ses.hash);
  606|  1.69k|	}
  607|  8.39k|}
common-kex.c:switch_keys:
  120|  16.1k|static void switch_keys() {
  121|  16.1k|	TRACE2(("enter switch_keys"))
  122|  16.1k|	if (!(ses.kexstate.sentkexinit && ses.kexstate.recvkexinit)) {
  ------------------
  |  Branch (122:8): [True: 16.1k, False: 16]
  |  Branch (122:36): [True: 16.1k, False: 0]
  ------------------
  123|     16|		dropbear_exit("Unexpected newkeys message");
  124|     16|	}
  125|       |
  126|  16.1k|	if (!ses.keys) {
  ------------------
  |  Branch (126:6): [True: 0, False: 16.1k]
  ------------------
  127|      0|		ses.keys = m_malloc(sizeof(*ses.newkeys));
  128|      0|	}
  129|  16.1k|	if (ses.kexstate.recvnewkeys && ses.newkeys->recv.valid) {
  ------------------
  |  Branch (129:6): [True: 7.71k, False: 8.39k]
  |  Branch (129:34): [True: 7.71k, False: 0]
  ------------------
  130|  7.71k|		TRACE(("switch_keys recv"))
  131|       |#ifndef DISABLE_ZLIB
  132|       |		gen_new_zstream_recv();
  133|       |#endif
  134|  7.71k|		ses.keys->recv = ses.newkeys->recv;
  135|  7.71k|		m_burn(&ses.newkeys->recv, sizeof(ses.newkeys->recv));
  136|  7.71k|		ses.newkeys->recv.valid = 0;
  137|  7.71k|	}
  138|  16.1k|	if (ses.kexstate.sentnewkeys && ses.newkeys->trans.valid) {
  ------------------
  |  Branch (138:6): [True: 16.1k, False: 0]
  |  Branch (138:34): [True: 8.39k, False: 7.71k]
  ------------------
  139|  8.39k|		TRACE(("switch_keys trans"))
  140|       |#ifndef DISABLE_ZLIB
  141|       |		gen_new_zstream_trans();
  142|       |#endif
  143|  8.39k|		ses.keys->trans = ses.newkeys->trans;
  144|  8.39k|		m_burn(&ses.newkeys->trans, sizeof(ses.newkeys->trans));
  145|  8.39k|		ses.newkeys->trans.valid = 0;
  146|  8.39k|	}
  147|  16.1k|	if (ses.kexstate.sentnewkeys && ses.kexstate.recvnewkeys)
  ------------------
  |  Branch (147:6): [True: 16.1k, False: 0]
  |  Branch (147:34): [True: 7.71k, False: 8.39k]
  ------------------
  148|  7.71k|	{
  149|  7.71k|		TRACE(("switch_keys done"))
  150|  7.71k|		ses.keys->algo_kex = ses.newkeys->algo_kex;
  151|  7.71k|		ses.keys->algo_hostkey = ses.newkeys->algo_hostkey;
  152|  7.71k|		ses.keys->algo_signature = ses.newkeys->algo_signature;
  153|  7.71k|		m_free(ses.newkeys);
  ------------------
  |  |   24|  7.71k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 7.71k]
  |  |  ------------------
  ------------------
  154|       |		ses.newkeys = NULL;
  155|  7.71k|		kexinitialise();
  156|  7.71k|	}
  157|  16.1k|	TRACE2(("leave switch_keys"))
  158|  16.1k|}
common-kex.c:kex_setup_compress:
  204|  3.35k|static void kex_setup_compress(void) {
  205|  3.35k|#ifdef DISABLE_ZLIB
  206|  3.35k|	ses.compress_algos_c2s = ssh_nocompress;
  207|  3.35k|	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|  3.35k|}
common-kex.c:kexinitialise:
  236|  11.0k|static void kexinitialise() {
  237|       |
  238|  11.0k|	TRACE(("kexinitialise()"))
  239|       |
  240|       |	/* sent/recv'd MSG_KEXINIT */
  241|  11.0k|	ses.kexstate.sentkexinit = 0;
  242|  11.0k|	ses.kexstate.recvkexinit = 0;
  243|       |
  244|       |	/* sent/recv'd MSG_NEWKEYS */
  245|  11.0k|	ses.kexstate.recvnewkeys = 0;
  246|  11.0k|	ses.kexstate.sentnewkeys = 0;
  247|       |
  248|       |	/* first_packet_follows */
  249|  11.0k|	ses.kexstate.them_firstfollows = 0;
  250|       |
  251|  11.0k|	ses.kexstate.datatrans = 0;
  252|  11.0k|	ses.kexstate.datarecv = 0;
  253|       |
  254|  11.0k|	ses.kexstate.our_first_follows_matches = 0;
  255|       |
  256|  11.0k|	ses.kexstate.lastkextime = monotonic_now();
  257|       |
  258|  11.0k|}
common-kex.c:gen_new_keys:
  299|  8.39k|static void gen_new_keys() {
  300|       |
  301|  8.39k|	unsigned char C2S_IV[MAX_IV_LEN];
  302|  8.39k|	unsigned char C2S_key[MAX_KEY_LEN];
  303|  8.39k|	unsigned char S2C_IV[MAX_IV_LEN];
  304|  8.39k|	unsigned char S2C_key[MAX_KEY_LEN];
  305|       |	/* unsigned char key[MAX_KEY_LEN]; */
  306|  8.39k|	unsigned char *trans_IV, *trans_key, *recv_IV, *recv_key;
  307|       |
  308|  8.39k|	hash_state hs;
  309|  8.39k|	const struct ltc_hash_descriptor *hash_desc = ses.newkeys->algo_kex->hash_desc;
  310|  8.39k|	char mactransletter, macrecvletter; /* Client or server specific */
  311|       |
  312|  8.39k|	TRACE(("enter gen_new_keys"))
  313|       |	/* the dh_K and hash are the start of all hashes, we make use of that */
  314|       |
  315|  8.39k|	hash_desc->init(&hs);
  316|  8.39k|	if (ses.dh_K) {
  ------------------
  |  Branch (316:6): [True: 8.39k, False: 0]
  ------------------
  317|  8.39k|		hash_process_mp(hash_desc, &hs, ses.dh_K);
  318|  8.39k|		mp_clear(ses.dh_K);
  319|  8.39k|		m_free(ses.dh_K);
  ------------------
  |  |   24|  8.39k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 8.39k]
  |  |  ------------------
  ------------------
  320|  8.39k|	}
  321|  8.39k|	if (ses.dh_K_bytes) {
  ------------------
  |  Branch (321:6): [True: 0, False: 8.39k]
  ------------------
  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|  8.39k|	hash_desc->process(&hs, ses.hash->data, ses.hash->len);
  327|  8.39k|	buf_burn_free(ses.hash);
  328|  8.39k|	ses.hash = NULL;
  329|       |
  330|  8.39k|	if (IS_DROPBEAR_CLIENT) {
  ------------------
  |  |  382|  8.39k|#define IS_DROPBEAR_CLIENT (ses.isserver == 0)
  |  |  ------------------
  |  |  |  Branch (382:28): [True: 0, False: 8.39k]
  |  |  ------------------
  ------------------
  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|  8.39k|	} else {
  338|  8.39k|		trans_IV	= S2C_IV;
  339|  8.39k|		recv_IV		= C2S_IV;
  340|  8.39k|		trans_key	= S2C_key;
  341|  8.39k|		recv_key	= C2S_key;
  342|  8.39k|		mactransletter = 'F';
  343|  8.39k|		macrecvletter = 'E';
  344|  8.39k|	}
  345|       |
  346|  8.39k|	hashkeys(C2S_IV, sizeof(C2S_IV), &hs, 'A');
  347|  8.39k|	hashkeys(S2C_IV, sizeof(S2C_IV), &hs, 'B');
  348|  8.39k|	hashkeys(C2S_key, sizeof(C2S_key), &hs, 'C');
  349|  8.39k|	hashkeys(S2C_key, sizeof(S2C_key), &hs, 'D');
  350|       |
  351|  8.39k|	if (ses.newkeys->recv.algo_crypt->cipherdesc != NULL) {
  ------------------
  |  Branch (351:6): [True: 8.39k, False: 0]
  ------------------
  352|  8.39k|		int recv_cipher = -1;
  353|  8.39k|		if (ses.newkeys->recv.algo_crypt->cipherdesc->name != NULL) {
  ------------------
  |  Branch (353:7): [True: 7.81k, False: 579]
  ------------------
  354|  7.81k|			recv_cipher = find_cipher(ses.newkeys->recv.algo_crypt->cipherdesc->name);
  355|  7.81k|			if (recv_cipher < 0) {
  ------------------
  |  Branch (355:8): [True: 0, False: 7.81k]
  ------------------
  356|      0|				dropbear_exit("Crypto error");
  357|      0|			}
  358|  7.81k|		}
  359|  8.39k|		if (ses.newkeys->recv.crypt_mode->start(recv_cipher, 
  ------------------
  |  Branch (359:7): [True: 0, False: 8.39k]
  ------------------
  360|  8.39k|				recv_IV, recv_key, 
  361|  8.39k|				ses.newkeys->recv.algo_crypt->keysize, 0, 
  362|  8.39k|				&ses.newkeys->recv.cipher_state) != CRYPT_OK) {
  363|      0|			dropbear_exit("Crypto error");
  364|      0|		}
  365|  8.39k|	}
  366|       |
  367|  8.39k|	if (ses.newkeys->trans.algo_crypt->cipherdesc != NULL) {
  ------------------
  |  Branch (367:6): [True: 8.39k, False: 0]
  ------------------
  368|  8.39k|		int trans_cipher = -1;
  369|  8.39k|		if (ses.newkeys->trans.algo_crypt->cipherdesc->name != NULL) {
  ------------------
  |  Branch (369:7): [True: 7.97k, False: 419]
  ------------------
  370|  7.97k|			trans_cipher = find_cipher(ses.newkeys->trans.algo_crypt->cipherdesc->name);
  371|  7.97k|			if (trans_cipher < 0) {
  ------------------
  |  Branch (371:8): [True: 0, False: 7.97k]
  ------------------
  372|      0|				dropbear_exit("Crypto error");
  373|      0|			}
  374|  7.97k|		}
  375|  8.39k|		if (ses.newkeys->trans.crypt_mode->start(trans_cipher, 
  ------------------
  |  Branch (375:7): [True: 0, False: 8.39k]
  ------------------
  376|  8.39k|				trans_IV, trans_key, 
  377|  8.39k|				ses.newkeys->trans.algo_crypt->keysize, 0, 
  378|  8.39k|				&ses.newkeys->trans.cipher_state) != CRYPT_OK) {
  379|      0|			dropbear_exit("Crypto error");
  380|      0|		}
  381|  8.39k|	}
  382|       |
  383|  8.39k|	if (ses.newkeys->trans.algo_mac->hash_desc != NULL) {
  ------------------
  |  Branch (383:6): [True: 7.97k, False: 419]
  ------------------
  384|  7.97k|		hashkeys(ses.newkeys->trans.mackey, 
  385|  7.97k|				ses.newkeys->trans.algo_mac->keysize, &hs, mactransletter);
  386|  7.97k|		ses.newkeys->trans.hash_index = find_hash(ses.newkeys->trans.algo_mac->hash_desc->name);
  387|  7.97k|	}
  388|       |
  389|  8.39k|	if (ses.newkeys->recv.algo_mac->hash_desc != NULL) {
  ------------------
  |  Branch (389:6): [True: 0, False: 8.39k]
  ------------------
  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|  8.39k|	ses.newkeys->trans.valid = 1;
  397|  8.39k|	ses.newkeys->recv.valid = 1;
  398|       |
  399|  8.39k|	m_burn(C2S_IV, sizeof(C2S_IV));
  400|  8.39k|	m_burn(C2S_key, sizeof(C2S_key));
  401|  8.39k|	m_burn(S2C_IV, sizeof(S2C_IV));
  402|  8.39k|	m_burn(S2C_key, sizeof(S2C_key));
  403|  8.39k|	m_burn(&hs, sizeof(hash_state));
  404|       |
  405|  8.39k|	TRACE(("leave gen_new_keys"))
  406|  8.39k|}
common-kex.c:hashkeys:
  267|  41.5k|		const hash_state * hs, const unsigned char X) {
  268|       |
  269|  41.5k|	const struct ltc_hash_descriptor *hash_desc = ses.newkeys->algo_kex->hash_desc;
  270|  41.5k|	hash_state hs2;
  271|  41.5k|	unsigned int offset;
  272|  41.5k|	unsigned char tmpout[MAX_HASH_SIZE];
  273|       |
  274|  41.5k|	memcpy(&hs2, hs, sizeof(hash_state));
  275|  41.5k|	hash_desc->process(&hs2, &X, 1);
  276|  41.5k|	hash_desc->process(&hs2, ses.session_id->data, ses.session_id->len);
  277|  41.5k|	hash_desc->done(&hs2, tmpout);
  278|  41.5k|	memcpy(out, tmpout, MIN(hash_desc->hashsize, outlen));
  ------------------
  |  Branch (278:22): [True: 16.7k, False: 24.7k]
  ------------------
  279|  41.5k|	for (offset = hash_desc->hashsize; 
  280|  58.3k|			offset < outlen; 
  ------------------
  |  Branch (280:4): [True: 16.7k, False: 41.5k]
  ------------------
  281|  41.5k|			offset += hash_desc->hashsize)
  282|  16.7k|	{
  283|       |		/* need to extend */
  284|  16.7k|		memcpy(&hs2, hs, sizeof(hash_state));
  285|  16.7k|		hash_desc->process(&hs2, out, offset);
  286|  16.7k|		hash_desc->done(&hs2, tmpout);
  287|       |		memcpy(&out[offset], tmpout, MIN(outlen - offset, hash_desc->hashsize));
  ------------------
  |  Branch (287:32): [True: 0, False: 16.7k]
  ------------------
  288|  16.7k|	}
  289|  41.5k|	m_burn(&hs2, sizeof(hash_state));
  290|  41.5k|}
common-kex.c:read_kex_algos:
  611|  9.74k|static void read_kex_algos() {
  612|       |
  613|       |	/* for asymmetry */
  614|  9.74k|	algo_type * c2s_hash_algo = NULL;
  615|  9.74k|	algo_type * s2c_hash_algo = NULL;
  616|  9.74k|	algo_type * c2s_cipher_algo = NULL;
  617|  9.74k|	algo_type * s2c_cipher_algo = NULL;
  618|  9.74k|	algo_type * c2s_comp_algo = NULL;
  619|  9.74k|	algo_type * s2c_comp_algo = NULL;
  620|       |	/* the generic one */
  621|  9.74k|	algo_type * algo = NULL;
  622|       |
  623|       |	/* which algo couldn't match */
  624|  9.74k|	char * erralgo = NULL;
  625|       |
  626|  9.74k|	int goodguess = 0;
  627|  9.74k|	int allgood = 1; /* we AND this with each goodguess and see if its still
  628|       |						true after */
  629|  9.74k|	int kexguess2 = 0;
  630|       |
  631|  9.74k|	buf_incrpos(ses.payload, 16); /* start after the cookie */
  632|       |
  633|  9.74k|	memset(ses.newkeys, 0x0, sizeof(*ses.newkeys));
  634|       |
  635|       |	/* kex_algorithms */
  636|  9.74k|#if DROPBEAR_KEXGUESS2
  637|  9.74k|	if (buf_has_algo(ses.payload, KEXGUESS2_ALGO_NAME) == DROPBEAR_SUCCESS) {
  ------------------
  |  |  137|  9.74k|#define KEXGUESS2_ALGO_NAME "kexguess2@matt.ucc.asn.au"
  ------------------
              	if (buf_has_algo(ses.payload, KEXGUESS2_ALGO_NAME) == DROPBEAR_SUCCESS) {
  ------------------
  |  |  111|  9.74k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (637:6): [True: 121, False: 9.62k]
  ------------------
  638|    121|		kexguess2 = 1;
  639|    121|	}
  640|  9.74k|#endif
  641|       |
  642|  9.74k|#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|  9.74k|	if (IS_DROPBEAR_SERVER) {
  ------------------
  |  |  381|  9.74k|#define IS_DROPBEAR_SERVER (ses.isserver == 1)
  |  |  ------------------
  |  |  |  Branch (381:28): [True: 9.64k, False: 97]
  |  |  ------------------
  ------------------
  647|  9.64k|		if (!ses.kexstate.donefirstkex) {
  ------------------
  |  Branch (647:7): [True: 2.69k, False: 6.94k]
  ------------------
  648|  2.69k|			if (buf_has_algo(ses.payload, SSH_EXT_INFO_C) == DROPBEAR_SUCCESS) {
  ------------------
  |  |  100|  2.69k|#define SSH_EXT_INFO_C "ext-info-c"
  ------------------
              			if (buf_has_algo(ses.payload, SSH_EXT_INFO_C) == DROPBEAR_SUCCESS) {
  ------------------
  |  |  111|  2.69k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (648:8): [True: 116, False: 2.58k]
  ------------------
  649|    116|				ses.allow_ext_info = 1;
  650|    116|			}
  651|  2.69k|		}
  652|  9.64k|	}
  653|  9.74k|#endif
  654|       |
  655|  9.74k|	if (!ses.kexstate.donefirstkex) {
  ------------------
  |  Branch (655:6): [True: 2.69k, False: 7.04k]
  ------------------
  656|  2.69k|		const char* strict_name;
  657|  2.69k|		if (IS_DROPBEAR_CLIENT) {
  ------------------
  |  |  382|  2.69k|#define IS_DROPBEAR_CLIENT (ses.isserver == 0)
  |  |  ------------------
  |  |  |  Branch (382:28): [True: 0, False: 2.69k]
  |  |  ------------------
  ------------------
  658|      0|			strict_name = SSH_STRICT_KEX_S;
  ------------------
  |  |  104|      0|#define SSH_STRICT_KEX_S "kex-strict-s-v00@openssh.com"
  ------------------
  659|  2.69k|		} else {
  660|  2.69k|			strict_name = SSH_STRICT_KEX_C;
  ------------------
  |  |  105|  2.69k|#define SSH_STRICT_KEX_C "kex-strict-c-v00@openssh.com"
  ------------------
  661|  2.69k|		}
  662|  2.69k|		if (buf_has_algo(ses.payload, strict_name) == DROPBEAR_SUCCESS) {
  ------------------
  |  |  111|  2.69k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (662:7): [True: 46, False: 2.65k]
  ------------------
  663|     46|			ses.kexstate.strict_kex = 1;
  664|     46|		}
  665|  2.69k|	}
  666|       |
  667|  9.74k|	algo = buf_match_algo(ses.payload, sshkex, kexguess2, &goodguess);
  668|  9.74k|	allgood &= goodguess;
  669|  9.74k|	if (algo == NULL || algo->data == NULL) {
  ------------------
  |  Branch (669:6): [True: 359, False: 9.38k]
  |  Branch (669:22): [True: 4, False: 9.38k]
  ------------------
  670|       |		/* kexguess2, ext-info-c, ext-info-s should not match negotiation */
  671|    266|		erralgo = "kex";
  672|    266|		goto error;
  673|    266|	}
  674|  9.47k|	TRACE(("kexguess2 %d", kexguess2))
  675|  9.47k|	DEBUG3(("kex algo %s", algo->name))
  676|  9.47k|	ses.newkeys->algo_kex = algo->data;
  677|       |
  678|       |	/* server_host_key_algorithms */
  679|  9.47k|	algo = buf_match_algo(ses.payload, sigalgs, kexguess2, &goodguess);
  680|  9.47k|	allgood &= goodguess;
  681|  9.47k|	if (algo == NULL) {
  ------------------
  |  Branch (681:6): [True: 54, False: 9.42k]
  ------------------
  682|     54|		erralgo = "hostkey";
  683|     54|		goto error;
  684|     54|	}
  685|  9.42k|	DEBUG2(("hostkey algo %s", algo->name))
  686|  9.42k|	ses.newkeys->algo_signature = algo->val;
  687|  9.42k|	ses.newkeys->algo_hostkey = signkey_type_from_signature(ses.newkeys->algo_signature);
  688|       |
  689|       |	/* encryption_algorithms_client_to_server */
  690|  9.42k|	c2s_cipher_algo = buf_match_algo(ses.payload, sshciphers, 0, NULL);
  691|  9.42k|	if (c2s_cipher_algo == NULL) {
  ------------------
  |  Branch (691:6): [True: 19, False: 9.40k]
  ------------------
  692|     19|		erralgo = "enc c->s";
  693|     19|		goto error;
  694|     19|	}
  695|  9.40k|	DEBUG2(("enc  c2s is %s", c2s_cipher_algo->name))
  696|       |
  697|       |	/* encryption_algorithms_server_to_client */
  698|  9.40k|	s2c_cipher_algo = buf_match_algo(ses.payload, sshciphers, 0, NULL);
  699|  9.40k|	if (s2c_cipher_algo == NULL) {
  ------------------
  |  Branch (699:6): [True: 12, False: 9.39k]
  ------------------
  700|     12|		erralgo = "enc s->c";
  701|     12|		goto error;
  702|     12|	}
  703|  9.39k|	DEBUG2(("enc  s2c is %s", s2c_cipher_algo->name))
  704|       |
  705|       |	/* mac_algorithms_client_to_server */
  706|  9.39k|	c2s_hash_algo = buf_match_algo(ses.payload, sshhashes, 0, NULL);
  707|  9.39k|#if DROPBEAR_AEAD_MODE
  708|  9.39k|	if (((struct dropbear_cipher_mode*)c2s_cipher_algo->mode)->aead_crypt != NULL) {
  ------------------
  |  Branch (708:6): [True: 644, False: 8.74k]
  ------------------
  709|    644|		c2s_hash_algo = NULL;
  710|    644|	} else
  711|  8.74k|#endif
  712|  8.74k|	if (c2s_hash_algo == NULL) {
  ------------------
  |  Branch (712:6): [True: 9, False: 8.74k]
  ------------------
  713|      9|		erralgo = "mac c->s";
  714|      9|		goto error;
  715|      9|	}
  716|  9.38k|	DEBUG2(("hmac c2s is %s", c2s_hash_algo ? c2s_hash_algo->name : "<implicit>"))
  717|       |
  718|       |	/* mac_algorithms_server_to_client */
  719|  9.38k|	s2c_hash_algo = buf_match_algo(ses.payload, sshhashes, 0, NULL);
  720|  9.38k|#if DROPBEAR_AEAD_MODE
  721|  9.38k|	if (((struct dropbear_cipher_mode*)s2c_cipher_algo->mode)->aead_crypt != NULL) {
  ------------------
  |  Branch (721:6): [True: 452, False: 8.93k]
  ------------------
  722|    452|		s2c_hash_algo = NULL;
  723|    452|	} else
  724|  8.93k|#endif
  725|  8.93k|	if (s2c_hash_algo == NULL) {
  ------------------
  |  Branch (725:6): [True: 18, False: 8.91k]
  ------------------
  726|     18|		erralgo = "mac s->c";
  727|     18|		goto error;
  728|     18|	}
  729|  9.36k|	DEBUG2(("hmac s2c is %s", s2c_hash_algo ? s2c_hash_algo->name : "<implicit>"))
  730|       |
  731|       |	/* compression_algorithms_client_to_server */
  732|  9.36k|	c2s_comp_algo = buf_match_algo(ses.payload, ses.compress_algos_c2s, 0, NULL);
  733|  9.36k|	if (c2s_comp_algo == NULL) {
  ------------------
  |  Branch (733:6): [True: 7, False: 9.35k]
  ------------------
  734|      7|		erralgo = "comp c->s";
  735|      7|		goto error;
  736|      7|	}
  737|  9.35k|	DEBUG2(("comp c2s is %s", c2s_comp_algo->name))
  738|       |
  739|       |	/* compression_algorithms_server_to_client */
  740|  9.35k|	s2c_comp_algo = buf_match_algo(ses.payload, ses.compress_algos_s2c, 0, NULL);
  741|  9.35k|	if (s2c_comp_algo == NULL) {
  ------------------
  |  Branch (741:6): [True: 5, False: 9.35k]
  ------------------
  742|      5|		erralgo = "comp s->c";
  743|      5|		goto error;
  744|      5|	}
  745|  9.35k|	DEBUG2(("comp s2c is %s", s2c_comp_algo->name))
  746|       |
  747|       |	/* languages_client_to_server */
  748|  9.35k|	buf_eatstring(ses.payload);
  749|       |
  750|       |	/* languages_server_to_client */
  751|  9.35k|	buf_eatstring(ses.payload);
  752|       |
  753|       |	/* their first_kex_packet_follows */
  754|  9.35k|	if (buf_getbool(ses.payload)) {
  ------------------
  |  Branch (754:6): [True: 542, False: 8.81k]
  ------------------
  755|    542|		TRACE(("them kex firstfollows. allgood %d", allgood))
  756|    542|		ses.kexstate.them_firstfollows = 1;
  757|       |		/* if the guess wasn't good, we ignore the packet sent */
  758|    542|		if (!allgood) {
  ------------------
  |  Branch (758:7): [True: 481, False: 61]
  ------------------
  759|    481|			ses.ignorenext = 1;
  760|    481|		}
  761|    542|	}
  762|       |
  763|       |	/* Handle the asymmetry */
  764|  9.35k|	if (IS_DROPBEAR_CLIENT) {
  ------------------
  |  |  382|  9.35k|#define IS_DROPBEAR_CLIENT (ses.isserver == 0)
  |  |  ------------------
  |  |  |  Branch (382:28): [True: 0, False: 9.35k]
  |  |  ------------------
  ------------------
  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|  9.35k|	} else {
  786|       |		/* SERVER */
  787|  9.35k|		ses.newkeys->recv.algo_crypt = 
  788|  9.35k|			(struct dropbear_cipher*)c2s_cipher_algo->data;
  789|  9.35k|		ses.newkeys->trans.algo_crypt = 
  790|  9.35k|			(struct dropbear_cipher*)s2c_cipher_algo->data;
  791|  9.35k|		ses.newkeys->recv.crypt_mode =
  792|  9.35k|			(struct dropbear_cipher_mode*)c2s_cipher_algo->mode;
  793|  9.35k|		ses.newkeys->trans.crypt_mode =
  794|  9.35k|			(struct dropbear_cipher_mode*)s2c_cipher_algo->mode;
  795|  9.35k|		ses.newkeys->recv.algo_mac = 
  796|  9.35k|#if DROPBEAR_AEAD_MODE
  797|  9.35k|			c2s_hash_algo == NULL ? ses.newkeys->recv.crypt_mode->aead_mac :
  ------------------
  |  Branch (797:4): [True: 621, False: 8.73k]
  ------------------
  798|  9.35k|#endif
  799|  9.35k|			(struct dropbear_hash*)c2s_hash_algo->data;
  800|  9.35k|		ses.newkeys->trans.algo_mac = 
  801|  9.35k|#if DROPBEAR_AEAD_MODE
  802|  9.35k|			s2c_hash_algo == NULL ? ses.newkeys->trans.crypt_mode->aead_mac :
  ------------------
  |  Branch (802:4): [True: 445, False: 8.90k]
  ------------------
  803|  9.35k|#endif
  804|  9.35k|			(struct dropbear_hash*)s2c_hash_algo->data;
  805|  9.35k|		ses.newkeys->recv.algo_comp = c2s_comp_algo->val;
  806|  9.35k|		ses.newkeys->trans.algo_comp = s2c_comp_algo->val;
  807|  9.35k|	}
  808|       |
  809|  9.35k|#if DROPBEAR_FUZZ
  810|  9.35k|	if (fuzz.fuzzing) {
  ------------------
  |  Branch (810:6): [True: 9.09k, False: 263]
  ------------------
  811|  9.09k|		fuzz_kex_fakealgos();
  812|  9.09k|	}
  813|  9.35k|#endif
  814|       |
  815|       |	/* reserved for future extensions */
  816|  9.35k|	buf_getint(ses.payload);
  817|       |
  818|  9.35k|	if (ses.send_kex_first_guess && allgood) {
  ------------------
  |  Branch (818:6): [True: 0, False: 9.35k]
  |  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|  9.35k|	return;
  823|       |
  824|    390|error:
  825|    390|	dropbear_exit("No matching algo %s", erralgo);
  826|  9.35k|}

common_session_init:
   47|  3.35k|void common_session_init(int sock_in, int sock_out) {
   48|  3.35k|	time_t now;
   49|       |
   50|       |#if DEBUG_TRACE
   51|       |	debug_start_net();
   52|       |#endif
   53|       |
   54|  3.35k|	TRACE(("enter session_init"))
   55|       |
   56|  3.35k|	ses.sock_in = sock_in;
   57|  3.35k|	ses.sock_out = sock_out;
   58|  3.35k|	ses.maxfd = MAX(sock_in, sock_out);
  ------------------
  |  Branch (58:14): [True: 0, False: 3.35k]
  ------------------
   59|       |
   60|  3.35k|	if (sock_in >= 0) {
  ------------------
  |  Branch (60:6): [True: 3.35k, False: 0]
  ------------------
   61|  3.35k|		setnonblocking(sock_in);
   62|  3.35k|	}
   63|  3.35k|	if (sock_out >= 0) {
  ------------------
  |  Branch (63:6): [True: 3.35k, False: 0]
  ------------------
   64|  3.35k|		setnonblocking(sock_out);
   65|  3.35k|	}
   66|       |
   67|  3.35k|	ses.socket_prio = DROPBEAR_PRIO_NORMAL;
   68|       |	/* Sets it to lowdelay */
   69|  3.35k|	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|  3.35k|	now = monotonic_now();
   85|  3.35k|	ses.connect_time = now;
   86|  3.35k|	ses.last_packet_time_keepalive_recv = now;
   87|  3.35k|	ses.last_packet_time_idle = now;
   88|  3.35k|	ses.last_packet_time_any_sent = 0;
   89|  3.35k|	ses.last_packet_time_keepalive_sent = 0;
   90|       |	
   91|  3.35k|#if DROPBEAR_FUZZ
   92|  3.35k|	if (!fuzz.fuzzing)
  ------------------
  |  Branch (92:6): [True: 0, False: 3.35k]
  ------------------
   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|  3.35k|	ses.writepayload = buf_new(TRANS_MAX_PAYLOAD_LEN);
  ------------------
  |  |  560|  3.35k|#define TRANS_MAX_PAYLOAD_LEN 16384
  ------------------
  105|  3.35k|	ses.transseq = 0;
  106|       |
  107|  3.35k|	ses.readbuf = NULL;
  108|  3.35k|	ses.payload = NULL;
  109|  3.35k|	ses.recvseq = 0;
  110|       |
  111|  3.35k|	initqueue(&ses.writequeue);
  112|       |
  113|  3.35k|	ses.requirenext = SSH_MSG_KEXINIT;
  ------------------
  |  |   36|  3.35k|#define SSH_MSG_KEXINIT                20
  ------------------
  114|  3.35k|	ses.dataallowed = 1; /* we can send data until we actually 
  115|       |							send the SSH_MSG_KEXINIT */
  116|  3.35k|	ses.ignorenext = 0;
  117|  3.35k|	ses.lastpacket = 0;
  118|  3.35k|	ses.reply_queue_head = NULL;
  119|  3.35k|	ses.reply_queue_tail = NULL;
  120|       |
  121|       |	/* set all the algos to none */
  122|  3.35k|	ses.keys = (struct key_context*)m_malloc(sizeof(struct key_context));
  123|  3.35k|	ses.newkeys = NULL;
  124|  3.35k|	ses.keys->recv.algo_crypt = &dropbear_nocipher;
  125|  3.35k|	ses.keys->trans.algo_crypt = &dropbear_nocipher;
  126|  3.35k|	ses.keys->recv.crypt_mode = &dropbear_mode_none;
  127|  3.35k|	ses.keys->trans.crypt_mode = &dropbear_mode_none;
  128|       |	
  129|  3.35k|	ses.keys->recv.algo_mac = &dropbear_nohash;
  130|  3.35k|	ses.keys->trans.algo_mac = &dropbear_nohash;
  131|       |
  132|  3.35k|	ses.keys->algo_kex = NULL;
  133|  3.35k|	ses.keys->algo_hostkey = -1;
  134|  3.35k|	ses.keys->recv.algo_comp = DROPBEAR_COMP_NONE;
  135|  3.35k|	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|  3.35k|	ses.session_id = NULL;
  144|  3.35k|	ses.kexhashbuf = NULL;
  145|  3.35k|	ses.transkexinit = NULL;
  146|  3.35k|	ses.dh_K = NULL;
  147|  3.35k|	ses.remoteident = NULL;
  148|       |
  149|  3.35k|	ses.chantypes = NULL;
  150|       |
  151|  3.35k|	ses.allowprivport = 0;
  152|       |
  153|       |#if DROPBEAR_PLUGIN
  154|       |        ses.plugin_session = NULL;
  155|       |#endif
  156|       |
  157|  3.35k|	TRACE(("leave session_init"))
  158|  3.35k|}
session_loop:
  160|  3.35k|void session_loop(void(*loophandler)(void)) {
  161|       |
  162|  3.35k|	fd_set readfd, writefd;
  163|  3.35k|	struct timeval timeout;
  164|  3.35k|	int val;
  165|       |
  166|       |	/* main loop, select()s for all sockets in use */
  167|   264k|	for(;;) {
  168|   264k|		const int writequeue_has_space = (ses.writequeue_len <= 2*TRANS_MAX_PAYLOAD_LEN);
  ------------------
  |  |  560|   264k|#define TRANS_MAX_PAYLOAD_LEN 16384
  ------------------
  169|       |
  170|   264k|		timeout.tv_sec = select_timeout();
  171|   264k|		timeout.tv_usec = 0;
  172|   264k|		DROPBEAR_FD_ZERO(&writefd);
  ------------------
  |  |  106|   264k|#define DROPBEAR_FD_ZERO(fds) FD_ZERO(fds)
  ------------------
  |  Branch (172:3): [Folded, False: 264k]
  ------------------
  173|   264k|		DROPBEAR_FD_ZERO(&readfd);
  ------------------
  |  |  106|   264k|#define DROPBEAR_FD_ZERO(fds) FD_ZERO(fds)
  ------------------
  |  Branch (173:3): [Folded, False: 264k]
  ------------------
  174|       |
  175|   264k|		dropbear_assert(ses.payload == NULL);
  ------------------
  |  |   84|   264k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (84:37): [True: 0, False: 264k]
  |  |  |  Branch (84:93): [Folded, False: 264k]
  |  |  ------------------
  ------------------
  176|       |
  177|       |		/* We get woken up when signal handlers write to this pipe.
  178|       |		   SIGCHLD in svr-chansession is the only one currently. */
  179|   264k|#if DROPBEAR_FUZZ
  180|   264k|		if (!fuzz.fuzzing) 
  ------------------
  |  Branch (180:7): [True: 0, False: 264k]
  ------------------
  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|   264k|		setchannelfds(&readfd, &writefd, writequeue_has_space);
  188|       |
  189|       |		/* Pending connections to test */
  190|   264k|		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|   264k|		if (ses.sock_in != -1 
  ------------------
  |  Branch (198:7): [True: 264k, False: 0]
  ------------------
  199|   264k|			&& (ses.remoteident || isempty(&ses.writequeue)) 
  ------------------
  |  Branch (199:8): [True: 253k, False: 10.1k]
  |  Branch (199:27): [True: 3.48k, False: 6.71k]
  ------------------
  200|   257k|			&& writequeue_has_space) {
  ------------------
  |  Branch (200:7): [True: 257k, False: 0]
  ------------------
  201|   257k|			FD_SET(ses.sock_in, &readfd);
  202|   257k|		}
  203|       |
  204|       |		/* Ordering is important, this test must occur after any other function
  205|       |		might have queued packets (such as connection handlers) */
  206|   264k|		if (ses.sock_out != -1 && !isempty(&ses.writequeue)) {
  ------------------
  |  Branch (206:7): [True: 264k, False: 0]
  |  Branch (206:29): [True: 15.1k, False: 248k]
  ------------------
  207|  15.1k|			FD_SET(ses.sock_out, &writefd);
  208|  15.1k|		}
  209|       |
  210|   264k|		val = select(ses.maxfd+1, &readfd, &writefd, NULL, &timeout);
  ------------------
  |  |   53|   264k|        wrapfd_select(nfds, readfds, writefds, exceptfds, timeout)
  ------------------
  211|       |
  212|   264k|		if (ses.exitflag) {
  ------------------
  |  Branch (212:7): [True: 0, False: 264k]
  ------------------
  213|      0|			dropbear_exit("Terminated by signal");
  214|      0|		}
  215|       |		
  216|   264k|		if (val < 0 && errno != EINTR) {
  ------------------
  |  Branch (216:7): [True: 373, False: 263k]
  |  Branch (216:18): [True: 0, False: 373]
  ------------------
  217|      0|			dropbear_exit("Error in select");
  218|      0|		}
  219|       |
  220|   264k|		if (val <= 0) {
  ------------------
  |  Branch (220:7): [True: 13.6k, False: 250k]
  ------------------
  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|  13.6k|			DROPBEAR_FD_ZERO(&writefd);
  ------------------
  |  |  106|  13.6k|#define DROPBEAR_FD_ZERO(fds) FD_ZERO(fds)
  ------------------
  |  Branch (225:4): [Folded, False: 13.6k]
  ------------------
  226|  13.6k|			DROPBEAR_FD_ZERO(&readfd);
  ------------------
  |  |  106|  13.6k|#define DROPBEAR_FD_ZERO(fds) FD_ZERO(fds)
  ------------------
  |  Branch (226:4): [Folded, False: 13.6k]
  ------------------
  227|  13.6k|		}
  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|   264k|		ses.channel_signal_pending = 0;
  233|   264k|		if (FD_ISSET(ses.signal_pipe[0], &readfd)) {
  ------------------
  |  Branch (233:7): [True: 0, False: 264k]
  ------------------
  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|   264k|		checktimeouts();
  242|       |
  243|       |		/* process session socket's incoming data */
  244|   264k|		if (ses.sock_in != -1) {
  ------------------
  |  Branch (244:7): [True: 264k, False: 0]
  ------------------
  245|   264k|			if (FD_ISSET(ses.sock_in, &readfd)) {
  ------------------
  |  Branch (245:8): [True: 243k, False: 20.2k]
  ------------------
  246|   243k|				if (!ses.remoteident) {
  ------------------
  |  Branch (246:9): [True: 3.35k, False: 240k]
  ------------------
  247|       |					/* blocking read of the version string */
  248|  3.35k|					read_session_identification();
  249|   240k|				} else {
  250|   240k|					read_packet();
  251|   240k|				}
  252|   243k|			}
  253|       |			
  254|       |			/* Process the decrypted packet. After this, the read buffer
  255|       |			 * will be ready for a new packet */
  256|   264k|			if (ses.payload != NULL) {
  ------------------
  |  Branch (256:8): [True: 48.3k, False: 215k]
  ------------------
  257|  48.3k|				process_packet();
  258|  48.3k|			}
  259|   264k|		}
  260|       |
  261|       |		/* if required, flush out any queued reply packets that
  262|       |		were being held up during a KEX */
  263|   264k|		maybe_flush_reply_queue();
  264|       |
  265|   264k|		handle_connect_fds(&writefd);
  266|       |
  267|       |		/* loop handler prior to channelio, in case the server loophandler closes
  268|       |		channels on process exit */
  269|   264k|		loophandler();
  270|       |
  271|       |		/* process pipes etc for the channels, ses.dataallowed == 0
  272|       |		 * during rekeying ) */
  273|   264k|		channelio(&readfd, &writefd);
  274|       |
  275|       |		/* process session socket's outgoing data */
  276|   264k|		if (ses.sock_out != -1) {
  ------------------
  |  Branch (276:7): [True: 260k, False: 3.35k]
  ------------------
  277|   260k|			if (!isempty(&ses.writequeue)) {
  ------------------
  |  Branch (277:8): [True: 49.8k, False: 210k]
  ------------------
  278|  49.8k|				write_packet();
  279|  49.8k|			}
  280|   260k|		}
  281|       |
  282|   264k|	} /* for(;;) */
  283|       |	
  284|       |	/* Not reached */
  285|  3.35k|}
session_cleanup:
  296|  3.35k|void session_cleanup() {
  297|       |	
  298|  3.35k|	TRACE(("enter session_cleanup"))
  299|       |	
  300|       |	/* we can't cleanup if we don't know the session state */
  301|  3.35k|	if (!ses.init_done) {
  ------------------
  |  Branch (301:6): [True: 0, False: 3.35k]
  ------------------
  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|  3.35k|	chancleanup();
  310|       |
  311|  3.35k|	if (ses.extra_session_cleanup) {
  ------------------
  |  Branch (311:6): [True: 3.35k, False: 0]
  ------------------
  312|  3.35k|		ses.extra_session_cleanup();
  313|  3.35k|	}
  314|       |
  315|       |	/* After these are freed most functions will fail */
  316|  3.35k|#if DROPBEAR_CLEANUP
  317|       |	/* listeners call cleanup functions, this should occur before
  318|       |	other session state is freed. */
  319|  3.35k|	remove_all_listeners();
  320|       |
  321|  3.35k|	remove_connect_pending();
  322|       |
  323|  4.00k|	while (!isempty(&ses.writequeue)) {
  ------------------
  |  Branch (323:9): [True: 646, False: 3.35k]
  ------------------
  324|    646|		buf_free(dequeue(&ses.writequeue));
  325|    646|	}
  326|       |
  327|  3.35k|	m_free(ses.newkeys);
  ------------------
  |  |   24|  3.35k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 3.35k]
  |  |  ------------------
  ------------------
  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|  3.35k|	m_free(ses.remoteident);
  ------------------
  |  |   24|  3.35k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 3.35k]
  |  |  ------------------
  ------------------
  344|  3.35k|	m_free(ses.authstate.pw_dir);
  ------------------
  |  |   24|  3.35k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 3.35k]
  |  |  ------------------
  ------------------
  345|  3.35k|	m_free(ses.authstate.pw_name);
  ------------------
  |  |   24|  3.35k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 3.35k]
  |  |  ------------------
  ------------------
  346|  3.35k|	m_free(ses.authstate.pw_shell);
  ------------------
  |  |   24|  3.35k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 3.35k]
  |  |  ------------------
  ------------------
  347|  3.35k|	m_free(ses.authstate.pw_passwd);
  ------------------
  |  |   24|  3.35k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 3.35k]
  |  |  ------------------
  ------------------
  348|  3.35k|	m_free(ses.authstate.username);
  ------------------
  |  |   24|  3.35k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 3.35k]
  |  |  ------------------
  ------------------
  349|  3.35k|#endif
  350|       |
  351|  3.35k|	cleanup_buf(&ses.session_id);
  352|  3.35k|	cleanup_buf(&ses.hash);
  353|  3.35k|	cleanup_buf(&ses.payload);
  354|  3.35k|	cleanup_buf(&ses.readbuf);
  355|  3.35k|	cleanup_buf(&ses.writepayload);
  356|  3.35k|	cleanup_buf(&ses.kexhashbuf);
  357|  3.35k|	cleanup_buf(&ses.transkexinit);
  358|  3.35k|	if (ses.dh_K) {
  ------------------
  |  Branch (358:6): [True: 0, False: 3.35k]
  ------------------
  359|      0|		mp_clear(ses.dh_K);
  360|      0|	}
  361|  3.35k|	m_free(ses.dh_K);
  ------------------
  |  |   24|  3.35k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 3.35k]
  |  |  ------------------
  ------------------
  362|  3.35k|	if (ses.dh_K_bytes) {
  ------------------
  |  Branch (362:6): [True: 0, False: 3.35k]
  ------------------
  363|      0|		buf_burn_free(ses.dh_K_bytes);
  364|      0|	}
  365|       |
  366|  3.35k|	m_burn(ses.keys, sizeof(struct key_context));
  367|  3.35k|	m_free(ses.keys);
  ------------------
  |  |   24|  3.35k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 3.35k]
  |  |  ------------------
  ------------------
  368|       |
  369|  3.35k|	TRACE(("leave session_cleanup"))
  370|  3.35k|}
send_session_identification:
  372|  3.35k|void send_session_identification() {
  373|  3.35k|	buffer *writebuf = buf_new(strlen(LOCAL_IDENT "\r\n") + 1);
  ------------------
  |  |   14|  3.35k|#define LOCAL_IDENT "SSH-2.0-dropbear" IDENT_VERSION_PART
  ------------------
  374|  3.35k|	buf_putbytes(writebuf, (const unsigned char *) LOCAL_IDENT "\r\n", strlen(LOCAL_IDENT "\r\n"));
  ------------------
  |  |   14|  3.35k|#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|  3.35k|#define LOCAL_IDENT "SSH-2.0-dropbear" IDENT_VERSION_PART
  ------------------
  375|  3.35k|	writebuf_enqueue(writebuf);
  376|  3.35k|}
fill_passwd:
  655|    271|void fill_passwd(const char* username) {
  656|    271|	struct passwd *pw = NULL;
  657|    271|	if (ses.authstate.pw_name)
  ------------------
  |  Branch (657:6): [True: 0, False: 271]
  ------------------
  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|    271|	if (ses.authstate.pw_dir)
  ------------------
  |  Branch (659:6): [True: 0, False: 271]
  ------------------
  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|    271|	if (ses.authstate.pw_shell)
  ------------------
  |  Branch (661:6): [True: 0, False: 271]
  ------------------
  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|    271|	if (ses.authstate.pw_passwd)
  ------------------
  |  Branch (663:6): [True: 0, False: 271]
  ------------------
  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|    271|	pw = getpwnam(username);
  ------------------
  |  |  108|    271|#define getpwnam(x) fuzz_getpwnam(x)
  ------------------
  667|    271|	if (!pw) {
  ------------------
  |  Branch (667:6): [True: 269, False: 2]
  ------------------
  668|    269|		return;
  669|    269|	}
  670|      2|	ses.authstate.pw_uid = pw->pw_uid;
  671|      2|	ses.authstate.pw_gid = pw->pw_gid;
  672|      2|	ses.authstate.pw_name = m_strdup(pw->pw_name);
  673|      2|	ses.authstate.pw_dir = m_strdup(pw->pw_dir);
  674|      2|	ses.authstate.pw_shell = m_strdup(pw->pw_shell);
  675|      2|	{
  676|      2|		char *passwd_crypt = pw->pw_passwd;
  677|      2|#ifdef HAVE_SHADOW_H
  678|       |		/* "x" for the passwd crypt indicates shadow should be used */
  679|      2|		if (pw->pw_passwd && strcmp(pw->pw_passwd, "x") == 0) {
  ------------------
  |  Branch (679:7): [True: 2, False: 0]
  |  Branch (679:24): [True: 0, False: 2]
  ------------------
  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|      2|#endif
  690|      2|		if (!passwd_crypt) {
  ------------------
  |  Branch (690:7): [True: 0, False: 2]
  ------------------
  691|       |			/* android supposedly returns NULL */
  692|      0|			passwd_crypt = "!!";
  693|      0|		}
  694|      2|		ses.authstate.pw_passwd = m_strdup(passwd_crypt);
  695|      2|	}
  696|      2|}
update_channel_prio:
  699|  3.35k|void update_channel_prio() {
  700|  3.35k|	enum dropbear_prio new_prio;
  701|  3.35k|	int any = 0;
  702|  3.35k|	unsigned int i;
  703|       |
  704|  3.35k|	TRACE(("update_channel_prio"))
  705|       |
  706|  3.35k|	if (ses.sock_out < 0) {
  ------------------
  |  Branch (706:6): [True: 0, False: 3.35k]
  ------------------
  707|      0|		TRACE(("leave update_channel_prio: no socket"))
  708|      0|		return;
  709|      0|	}
  710|       |
  711|  3.35k|	new_prio = DROPBEAR_PRIO_NORMAL;
  712|  3.35k|	for (i = 0; i < ses.chansize; i++) {
  ------------------
  |  Branch (712:14): [True: 0, False: 3.35k]
  ------------------
  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|  3.35k|	if (any == 0) {
  ------------------
  |  Branch (724:6): [True: 3.35k, False: 0]
  ------------------
  725|       |		/* lowdelay during setup */
  726|  3.35k|		TRACE(("update_channel_prio: not any"))
  727|  3.35k|		new_prio = DROPBEAR_PRIO_LOWDELAY;
  728|  3.35k|	}
  729|       |
  730|  3.35k|	if (new_prio != ses.socket_prio) {
  ------------------
  |  Branch (730:6): [True: 3.35k, False: 0]
  ------------------
  731|  3.35k|		TRACE(("Dropbear priority transitioning %d -> %d", ses.socket_prio, new_prio))
  732|  3.35k|		set_sock_priority(ses.sock_out, new_prio);
  733|  3.35k|		ses.socket_prio = new_prio;
  734|  3.35k|	}
  735|  3.35k|}
common-session.c:cleanup_buf:
  287|  23.4k|static void cleanup_buf(buffer **buf) {
  288|  23.4k|	if (!*buf) {
  ------------------
  |  Branch (288:6): [True: 12.6k, False: 10.8k]
  ------------------
  289|  12.6k|		return;
  290|  12.6k|	}
  291|  10.8k|	buf_burn_free(*buf);
  292|       |	*buf = NULL;
  293|  10.8k|}
common-session.c:read_session_identification:
  378|  3.35k|static void read_session_identification() {
  379|       |	/* max length of 255 chars */
  380|  3.35k|	char linebuf[256];
  381|  3.35k|	int len = 0;
  382|  3.35k|	char done = 0;
  383|  3.35k|	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|  3.48k|	for (i = IS_DROPBEAR_CLIENT ? 50 : 1; i > 0; i--) {
  ------------------
  |  |  382|  3.35k|#define IS_DROPBEAR_CLIENT (ses.isserver == 0)
  |  |  ------------------
  |  |  |  Branch (382:28): [True: 0, False: 3.35k]
  |  |  ------------------
  ------------------
  |  Branch (388:40): [True: 3.35k, False: 124]
  ------------------
  389|  3.35k|		len = ident_readln(ses.sock_in, linebuf, sizeof(linebuf));
  390|       |
  391|  3.35k|		if (len < 0 && errno != EINTR) {
  ------------------
  |  Branch (391:7): [True: 86, False: 3.27k]
  |  Branch (391:18): [True: 7, False: 79]
  ------------------
  392|       |			/* It failed */
  393|      7|			break;
  394|      7|		}
  395|       |
  396|  3.34k|		if (len >= 4 && memcmp(linebuf, "SSH-", 4) == 0) {
  ------------------
  |  Branch (396:7): [True: 3.26k, False: 84]
  |  Branch (396:19): [True: 3.22k, False: 40]
  ------------------
  397|       |			/* start of line matches */
  398|  3.22k|			done = 1;
  399|  3.22k|			break;
  400|  3.22k|		}
  401|  3.34k|	}
  402|       |
  403|  3.35k|	if (!done) {
  ------------------
  |  Branch (403:6): [True: 131, False: 3.22k]
  ------------------
  404|    131|		TRACE(("error reading remote ident: %s\n", strerror(errno)))
  405|    131|		ses.remoteclosed();
  406|  3.22k|	} else {
  407|       |		/* linebuf is already null terminated */
  408|  3.22k|		ses.remoteident = m_malloc(len);
  409|  3.22k|		memcpy(ses.remoteident, linebuf, len);
  410|  3.22k|	}
  411|       |
  412|       |	/* Shall assume that 2.x will be backwards compatible. */
  413|  3.35k|	if (strncmp(ses.remoteident, "SSH-2.", 6) != 0
  ------------------
  |  Branch (413:6): [True: 61, False: 3.29k]
  ------------------
  414|     61|			&& strncmp(ses.remoteident, "SSH-1.99-", 9) != 0) {
  ------------------
  |  Branch (414:7): [True: 60, False: 1]
  ------------------
  415|     60|		dropbear_exit("Incompatible remote version '%s'", ses.remoteident);
  416|     60|	}
  417|       |
  418|  3.35k|	DEBUG1(("remoteident: %s", ses.remoteident))
  419|       |
  420|  3.35k|}
common-session.c:ident_readln:
  424|  3.35k|static int ident_readln(int fd, char* buf, int count) {
  425|       |	
  426|  3.35k|	char in;
  427|  3.35k|	int pos = 0;
  428|  3.35k|	int num = 0;
  429|  3.35k|	fd_set fds;
  430|  3.35k|	struct timeval timeout;
  431|       |
  432|  3.35k|	TRACE(("enter ident_readln"))
  433|       |
  434|  3.35k|	if (count < 1) {
  ------------------
  |  Branch (434:6): [True: 0, False: 3.35k]
  ------------------
  435|      0|		return -1;
  436|      0|	}
  437|       |
  438|  3.35k|	DROPBEAR_FD_ZERO(&fds);
  ------------------
  |  |  106|  3.35k|#define DROPBEAR_FD_ZERO(fds) FD_ZERO(fds)
  ------------------
  |  Branch (438:2): [Folded, False: 3.35k]
  ------------------
  439|       |
  440|       |	/* select since it's a non-blocking fd */
  441|       |	
  442|       |	/* leave space to null-terminate */
  443|  62.9k|	while (pos < count-1) {
  ------------------
  |  Branch (443:9): [True: 62.9k, False: 1]
  ------------------
  444|       |
  445|  62.9k|		FD_SET(fd, &fds);
  446|       |
  447|  62.9k|		timeout.tv_sec = 1;
  448|  62.9k|		timeout.tv_usec = 0;
  449|  62.9k|		if (select(fd+1, &fds, NULL, NULL, &timeout) < 0) {
  ------------------
  |  |   53|  62.9k|        wrapfd_select(nfds, readfds, writefds, exceptfds, timeout)
  ------------------
  |  Branch (449:7): [True: 84, False: 62.8k]
  ------------------
  450|     84|			if (errno == EINTR) {
  ------------------
  |  Branch (450:8): [True: 84, False: 0]
  ------------------
  451|     84|				continue;
  452|     84|			}
  453|      0|			TRACE(("leave ident_readln: select error"))
  454|      0|			return -1;
  455|     84|		}
  456|       |
  457|  62.8k|		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|  62.8k|		if (FD_ISSET(fd, &fds)) {
  ------------------
  |  Branch (462:7): [True: 62.8k, False: 0]
  ------------------
  463|  62.8k|			num = read(fd, &in, 1);
  ------------------
  |  |   55|  62.8k|#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|  62.8k|			if (num < 0) {
  ------------------
  |  Branch (466:8): [True: 138, False: 62.7k]
  ------------------
  467|       |				/* error */
  468|    138|				if (errno == EINTR) {
  ------------------
  |  Branch (468:9): [True: 136, False: 2]
  ------------------
  469|    136|					continue; /* not a real error */
  470|    136|				}
  471|      2|				TRACE(("leave ident_readln: read error"))
  472|      2|				return -1;
  473|    138|			}
  474|  62.7k|			if (num == 0) {
  ------------------
  |  Branch (474:8): [True: 84, False: 62.6k]
  ------------------
  475|       |				/* EOF */
  476|     84|				TRACE(("leave ident_readln: EOF"))
  477|     84|				return -1;
  478|     84|			}
  479|       |
  480|  62.6k|#if DROPBEAR_FUZZ
  481|  62.6k|			fuzz_dump(&in, 1);
  482|  62.6k|#endif
  483|       |
  484|  62.6k|			if (in == '\n') {
  ------------------
  |  Branch (484:8): [True: 3.26k, False: 59.3k]
  ------------------
  485|       |				/* end of ident string */
  486|  3.26k|				break;
  487|  3.26k|			}
  488|       |			/* we don't want to include '\r's */
  489|  59.3k|			if (in != '\r') {
  ------------------
  |  Branch (489:8): [True: 47.5k, False: 11.8k]
  ------------------
  490|  47.5k|				buf[pos] = in;
  491|  47.5k|				pos++;
  492|  47.5k|			}
  493|  59.3k|		}
  494|  62.8k|	}
  495|       |
  496|  3.27k|	buf[pos] = '\0';
  497|  3.27k|	TRACE(("leave ident_readln: return %d", pos+1))
  498|  3.27k|	return pos+1;
  499|  3.35k|}
common-session.c:checktimeouts:
  545|   326k|static void checktimeouts() {
  546|       |
  547|   326k|	time_t now;
  548|   326k|	now = monotonic_now();
  549|       |
  550|   326k|	if (IS_DROPBEAR_SERVER && ses.authstate.authdone != 1
  ------------------
  |  |  381|   653k|#define IS_DROPBEAR_SERVER (ses.isserver == 1)
  |  |  ------------------
  |  |  |  Branch (381:28): [True: 326k, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (550:28): [True: 326k, False: 0]
  ------------------
  551|   326k|		&& elapsed(now, ses.connect_time) >= AUTH_TIMEOUT) {
  ------------------
  |  |   35|   326k|#define AUTH_TIMEOUT 300 /* we choose 5 minutes */
  ------------------
  |  Branch (551:6): [True: 0, False: 326k]
  ------------------
  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|   326k|	if (ses.remoteident == NULL) {
  ------------------
  |  Branch (556:6): [True: 73.0k, False: 253k]
  ------------------
  557|  73.0k|		return;
  558|  73.0k|	}
  559|       |
  560|   253k|	if (!ses.kexstate.sentkexinit
  ------------------
  |  Branch (560:6): [True: 69.1k, False: 184k]
  ------------------
  561|  69.1k|			&& (elapsed(now, ses.kexstate.lastkextime) >= KEX_REKEY_TIMEOUT
  ------------------
  |  |   28|   138k|#define KEX_REKEY_TIMEOUT (3600 * 8)
  ------------------
  |  Branch (561:8): [True: 0, False: 69.1k]
  ------------------
  562|  69.1k|			|| ses.kexstate.datarecv+ses.kexstate.datatrans >= KEX_REKEY_DATA
  ------------------
  |  |   31|   138k|#define KEX_REKEY_DATA (1<<30) /* 2^30 == 1GB, this value must be < INT_MAX */
  ------------------
  |  Branch (562:7): [True: 0, False: 69.1k]
  ------------------
  563|  69.1k|			|| ses.kexstate.needrekey)) {
  ------------------
  |  Branch (563:7): [True: 0, False: 69.1k]
  ------------------
  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|   253k|	if (opts.keepalive_secs > 0 && ses.authstate.authdone) {
  ------------------
  |  Branch (569:6): [True: 0, False: 253k]
  |  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|   253k|	if (opts.idle_timeout_secs > 0
  ------------------
  |  Branch (591:6): [True: 0, False: 253k]
  ------------------
  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|   253k|	if (opts.max_duration_secs > 0
  ------------------
  |  Branch (596:6): [True: 0, False: 253k]
  ------------------
  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|   253k|}
common-session.c:elapsed:
  535|  1.72M|static long elapsed(time_t now, time_t prev) {
  536|  1.72M|	time_t del = now - prev;
  537|  1.72M|	if (del > LONG_MAX) {
  ------------------
  |  Branch (537:6): [True: 0, False: 1.72M]
  ------------------
  538|      0|		return LONG_MAX;
  539|      0|	}
  540|  1.72M|	return (long)del;
  541|  1.72M|}
common-session.c:select_timeout:
  613|   264k|static long select_timeout() {
  614|       |	/* determine the minimum timeout that might be required, so
  615|       |	as to avoid waking when unneccessary */
  616|   264k|	long timeout = KEX_REKEY_TIMEOUT;
  ------------------
  |  |   28|   264k|#define KEX_REKEY_TIMEOUT (3600 * 8)
  ------------------
  617|   264k|	time_t now = monotonic_now();
  618|       |
  619|   264k|	if (!ses.kexstate.sentkexinit) {
  ------------------
  |  Branch (619:6): [True: 69.1k, False: 194k]
  ------------------
  620|  69.1k|		update_timeout(KEX_REKEY_TIMEOUT, now, ses.kexstate.lastkextime, &timeout);
  ------------------
  |  |   28|  69.1k|#define KEX_REKEY_TIMEOUT (3600 * 8)
  ------------------
  621|  69.1k|	}
  622|   264k|	if (ses.kexstate.needrekey) {
  ------------------
  |  Branch (622:6): [True: 0, False: 264k]
  ------------------
  623|      0|		timeout = 0;
  624|      0|	}
  625|       |
  626|   264k|	if (ses.authstate.authdone != 1 && IS_DROPBEAR_SERVER) {
  ------------------
  |  |  381|   264k|#define IS_DROPBEAR_SERVER (ses.isserver == 1)
  |  |  ------------------
  |  |  |  Branch (381:28): [True: 264k, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (626:6): [True: 264k, False: 0]
  ------------------
  627|       |		/* AUTH_TIMEOUT is only relevant before authdone */
  628|   264k|		update_timeout(AUTH_TIMEOUT, now, ses.connect_time, &timeout);
  ------------------
  |  |   35|   264k|#define AUTH_TIMEOUT 300 /* we choose 5 minutes */
  ------------------
  629|   264k|	}
  630|       |
  631|   264k|	if (ses.authstate.authdone) {
  ------------------
  |  Branch (631:6): [True: 0, False: 264k]
  ------------------
  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|   264k|	update_timeout(opts.idle_timeout_secs, now, ses.last_packet_time_idle,
  638|   264k|		&timeout);
  639|       |
  640|   264k|	update_timeout(opts.max_duration_secs, now, ses.connect_time,
  641|   264k|		&timeout);
  642|       |
  643|       |	/* clamp negative timeouts to zero - event has already triggered */
  644|       |	return MAX(timeout, 0);
  ------------------
  |  Branch (644:9): [True: 264k, False: 0]
  ------------------
  645|   264k|}
common-session.c:update_timeout:
  602|   861k|static void update_timeout(long limit, time_t now, time_t last_event, long * timeout) {
  603|   861k|	TRACE2(("update_timeout limit %ld, now %llu, last %llu, timeout %ld",
  604|   861k|		limit,
  605|   861k|		(unsigned long long)now,
  606|   861k|		(unsigned long long)last_event, *timeout))
  607|   861k|	if (last_event > 0 && limit > 0) {
  ------------------
  |  Branch (607:6): [True: 861k, False: 0]
  |  Branch (607:24): [True: 333k, False: 528k]
  ------------------
  608|       |		*timeout = MIN(*timeout, MAX(0, limit - elapsed(now, last_event)));
  ------------------
  |  Branch (608:14): [True: 0, False: 333k]
  |  Branch (608:14): [True: 0, False: 333k]
  |  Branch (608:14): [True: 0, False: 333k]
  ------------------
  609|   333k|		TRACE2(("new timeout %ld", *timeout))
  610|   333k|	}
  611|   861k|}

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

dropbear_curve25519_scalarmult:
  214|  3.01k|{
  215|  3.01k|  u8 z[32];
  216|  3.01k|  i64 x[80],r,i;
  217|  3.01k|  gf a,b,c,d,e,f;
  218|  93.5k|  FOR(i,31) z[i]=n[i];
  ------------------
  |  |   34|  96.5k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 93.5k, False: 3.01k]
  |  |  ------------------
  ------------------
  219|  3.01k|  z[31]=(n[31]&127)|64;
  220|  3.01k|  z[0]&=248;
  221|  3.01k|  unpack25519(x,p);
  222|  48.2k|  FOR(i,16) {
  ------------------
  |  |   34|  51.3k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 48.2k, False: 3.01k]
  |  |  ------------------
  ------------------
  223|  48.2k|    b[i]=x[i];
  224|  48.2k|    d[i]=a[i]=c[i]=0;
  225|  48.2k|  }
  226|  3.01k|  a[0]=d[0]=1;
  227|   772k|  for(i=254;i>=0;--i) {
  ------------------
  |  Branch (227:13): [True: 769k, False: 3.01k]
  ------------------
  228|   769k|    r=(z[i>>3]>>(i&7))&1;
  229|   769k|    sel25519(a,b,r);
  230|   769k|    sel25519(c,d,r);
  231|   769k|    A(e,a,c);
  232|   769k|    Z(a,a,c);
  233|   769k|    A(c,b,d);
  234|   769k|    Z(b,b,d);
  235|   769k|    S(d,e);
  236|   769k|    S(f,a);
  237|   769k|    M(a,c,a);
  238|   769k|    M(c,b,e);
  239|   769k|    A(e,a,c);
  240|   769k|    Z(a,a,c);
  241|   769k|    S(b,a);
  242|   769k|    Z(c,d,f);
  243|   769k|    M(a,c,_121665);
  244|   769k|    A(a,a,d);
  245|   769k|    M(c,c,a);
  246|   769k|    M(a,d,f);
  247|   769k|    M(d,b,x);
  248|   769k|    S(b,e);
  249|   769k|    sel25519(a,b,r);
  250|   769k|    sel25519(c,d,r);
  251|   769k|  }
  252|  48.2k|  FOR(i,16) {
  ------------------
  |  |   34|  51.3k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 48.2k, False: 3.01k]
  |  |  ------------------
  ------------------
  253|  48.2k|    x[i+16]=a[i];
  254|  48.2k|    x[i+32]=c[i];
  255|  48.2k|    x[i+48]=b[i];
  256|  48.2k|    x[i+64]=d[i];
  257|  48.2k|  }
  258|  3.01k|  inv25519(x+32,x+32);
  259|  3.01k|  M(x+16,x+16,x+32);
  260|  3.01k|  pack25519(q,x+16);
  261|  3.01k|}
curve25519.c:unpack25519:
  152|  3.01k|{
  153|  3.01k|  int i;
  154|  48.2k|  FOR(i,16) o[i]=n[2*i]+((i64)n[2*i+1]<<8);
  ------------------
  |  |   34|  51.3k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 48.2k, False: 3.01k]
  |  |  ------------------
  ------------------
  155|  3.01k|  o[15]&=0x7fff;
  156|  3.01k|}
curve25519.c:sel25519:
   98|  3.08M|{
   99|  3.08M|  i64 t,i,c=~(b-1);
  100|  49.3M|  FOR(i,16) {
  ------------------
  |  |   34|  52.4M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 49.3M, False: 3.08M]
  |  |  ------------------
  ------------------
  101|  49.3M|    t= c&(p[i]^q[i]);
  102|  49.3M|    p[i]^=t;
  103|  49.3M|    q[i]^=t;
  104|  49.3M|  }
  105|  3.08M|}
curve25519.c:A:
  159|  3.07M|{
  160|  3.07M|  int i;
  161|  49.2M|  FOR(i,16) o[i]=a[i]+b[i];
  ------------------
  |  |   34|  52.3M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 49.2M, False: 3.07M]
  |  |  ------------------
  ------------------
  162|  3.07M|}
curve25519.c:Z:
  165|  3.07M|{
  166|  3.07M|  int i;
  167|  49.2M|  FOR(i,16) o[i]=a[i]-b[i];
  ------------------
  |  |   34|  52.3M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 49.2M, False: 3.07M]
  |  |  ------------------
  ------------------
  168|  3.07M|}
curve25519.c:S:
  182|  3.84M|{
  183|  3.84M|  M(o,a,a);
  184|  3.84M|}
curve25519.c:M:
  171|  9.22M|{
  172|  9.22M|  i64 i,j,t[31];
  173|   286M|  FOR(i,31) t[i]=0;
  ------------------
  |  |   34|   295M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 286M, False: 9.22M]
  |  |  ------------------
  ------------------
  174|  2.36G|  FOR(i,16) FOR(j,16) t[i+j]+=a[i]*b[j];
  ------------------
  |  |   34|   156M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 147M, False: 9.22M]
  |  |  ------------------
  ------------------
                FOR(i,16) FOR(j,16) t[i+j]+=a[i]*b[j];
  ------------------
  |  |   34|  2.50G|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 2.36G, False: 147M]
  |  |  ------------------
  ------------------
  175|   138M|  FOR(i,15) t[i]+=38*t[i+16];
  ------------------
  |  |   34|   147M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 138M, False: 9.22M]
  |  |  ------------------
  ------------------
  176|   147M|  FOR(i,16) o[i]=t[i];
  ------------------
  |  |   34|   156M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 147M, False: 9.22M]
  |  |  ------------------
  ------------------
  177|  9.22M|  car25519(o);
  178|  9.22M|  car25519(o);
  179|  9.22M|}
curve25519.c:car25519:
   86|  18.4M|{
   87|  18.4M|  int i;
   88|  18.4M|  i64 c;
   89|   295M|  FOR(i,16) {
  ------------------
  |  |   34|   313M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 295M, False: 18.4M]
  |  |  ------------------
  ------------------
   90|   295M|    o[i]+=(1LL<<16);
   91|   295M|    c=o[i]>>16;
   92|   295M|    o[(i+1)*(i<15)]+=c-1+37*(c-1)*(i==15);
   93|   295M|    o[i]-=((u64)c)<<16;
   94|   295M|  }
   95|  18.4M|}
curve25519.c:inv25519:
  187|  3.01k|{
  188|  3.01k|  gf c;
  189|  3.01k|  int a;
  190|  48.2k|  FOR(a,16) c[a]=i[a];
  ------------------
  |  |   34|  51.3k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 48.2k, False: 3.01k]
  |  |  ------------------
  ------------------
  191|   769k|  for(a=253;a>=0;a--) {
  ------------------
  |  Branch (191:13): [True: 766k, False: 3.01k]
  ------------------
  192|   766k|    S(c,c);
  193|   766k|    if(a!=2&&a!=4) M(c,c,i);
  ------------------
  |  Branch (193:8): [True: 763k, False: 3.01k]
  |  Branch (193:14): [True: 760k, False: 3.01k]
  ------------------
  194|   766k|  }
  195|  48.2k|  FOR(a,16) o[a]=c[a];
  ------------------
  |  |   34|  51.3k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 48.2k, False: 3.01k]
  |  |  ------------------
  ------------------
  196|  3.01k|}
curve25519.c:pack25519:
  108|  3.01k|{
  109|  3.01k|  int i,j,b;
  110|  3.01k|  gf m,t;
  111|  48.2k|  FOR(i,16) t[i]=n[i];
  ------------------
  |  |   34|  51.3k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 48.2k, False: 3.01k]
  |  |  ------------------
  ------------------
  112|  3.01k|  car25519(t);
  113|  3.01k|  car25519(t);
  114|  3.01k|  car25519(t);
  115|  6.03k|  FOR(j,2) {
  ------------------
  |  |   34|  9.05k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 6.03k, False: 3.01k]
  |  |  ------------------
  ------------------
  116|  6.03k|    m[0]=t[0]-0xffed;
  117|  90.5k|    for(i=1;i<15;i++) {
  ------------------
  |  Branch (117:13): [True: 84.5k, False: 6.03k]
  ------------------
  118|  84.5k|      m[i]=t[i]-0xffff-((m[i-1]>>16)&1);
  119|  84.5k|      m[i-1]&=0xffff;
  120|  84.5k|    }
  121|  6.03k|    m[15]=t[15]-0x7fff-((m[14]>>16)&1);
  122|  6.03k|    b=(m[15]>>16)&1;
  123|  6.03k|    m[14]&=0xffff;
  124|  6.03k|    sel25519(t,m,1-b);
  125|  6.03k|  }
  126|  48.2k|  FOR(i,16) {
  ------------------
  |  |   34|  51.3k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 48.2k, False: 3.01k]
  |  |  ------------------
  ------------------
  127|  48.2k|    o[2*i]=t[i]&0xff;
  128|  48.2k|    o[2*i+1]=t[i]>>8;
  129|  48.2k|  }
  130|  3.01k|}

m_burn:
    5|   331k|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|   331k|}

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

fuzz_seed:
  153|  3.35k|void fuzz_seed(const unsigned char* dat, unsigned int len) {
  154|  3.35k|	hash_state hs;
  155|  3.35k|	sha256_init(&hs);
  156|  3.35k|	sha256_process(&hs, "fuzzfuzzfuzz", strlen("fuzzfuzzfuzz"));
  157|  3.35k|	sha256_process(&hs, dat, len);
  158|  3.35k|	sha256_done(&hs, hashpool);
  159|  3.35k|	counter = 0;
  160|  3.35k|	donerandinit = 1;
  161|  3.35k|}
genrandom:
  313|  90.6k|void genrandom(unsigned char* buf, unsigned int len) {
  314|       |
  315|  90.6k|	hash_state hs;
  316|  90.6k|	unsigned char hash[SHA256_HASH_SIZE];
  317|  90.6k|	unsigned int copylen;
  318|       |
  319|  90.6k|	if (!donerandinit) {
  ------------------
  |  Branch (319:6): [True: 0, False: 90.6k]
  ------------------
  320|      0|		dropbear_exit("seedrandom not done");
  321|      0|	}
  322|       |
  323|   316k|	while (len > 0) {
  ------------------
  |  Branch (323:9): [True: 225k, False: 90.6k]
  ------------------
  324|   225k|		sha256_init(&hs);
  325|   225k|		sha256_process(&hs, (void*)hashpool, sizeof(hashpool));
  326|   225k|		sha256_process(&hs, (void*)&counter, sizeof(counter));
  327|   225k|		sha256_done(&hs, hash);
  328|       |
  329|   225k|		counter++;
  330|   225k|		if (counter > MAX_COUNTER) {
  ------------------
  |  |   35|   225k|#define MAX_COUNTER (1<<30)
  ------------------
  |  Branch (330:7): [True: 0, False: 225k]
  ------------------
  331|      0|			seedrandom();
  332|      0|		}
  333|       |
  334|       |		copylen = MIN(len, SHA256_HASH_SIZE);
  ------------------
  |  Branch (334:13): [True: 69.7k, False: 155k]
  ------------------
  335|   225k|		memcpy(buf, hash, copylen);
  336|   225k|		len -= copylen;
  337|   225k|		buf += copylen;
  338|   225k|	}
  339|  90.6k|	m_burn(hash, sizeof(hash));
  340|  90.6k|}
gen_random_mpint:
  347|  23.7k|void gen_random_mpint(const mp_int *max, mp_int *rand) {
  348|       |
  349|  23.7k|	unsigned char *randbuf = NULL;
  350|  23.7k|	unsigned int len = 0;
  351|  23.7k|	const unsigned char masks[] = {0xff, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f};
  352|       |
  353|  23.7k|	const int size_bits = mp_count_bits(max);
  354|       |
  355|  23.7k|	len = size_bits / 8;
  356|  23.7k|	if ((size_bits % 8) != 0) {
  ------------------
  |  Branch (356:6): [True: 6.94k, False: 16.7k]
  ------------------
  357|  6.94k|		len += 1;
  358|  6.94k|	}
  359|       |
  360|  23.7k|	randbuf = (unsigned char*)m_malloc(len);
  361|  27.6k|	do {
  362|  27.6k|		genrandom(randbuf, len);
  363|       |		/* Mask out the unrequired bits - mp_read_unsigned_bin expects
  364|       |		 * MSB first.*/
  365|  27.6k|		randbuf[0] &= masks[size_bits % 8];
  366|       |
  367|  27.6k|		bytes_to_mp(rand, randbuf, len);
  368|       |
  369|       |		/* keep regenerating until we get one satisfying
  370|       |		 * 0 < rand < max    */
  371|  27.6k|	} while (!(mp_cmp(rand, max) == MP_LT && mp_cmp_d(rand, 0) == MP_GT));
  ------------------
  |  |  154|  55.2k|#define MP_LT        -1   /* less than */
  ------------------
              	} while (!(mp_cmp(rand, max) == MP_LT && mp_cmp_d(rand, 0) == MP_GT));
  ------------------
  |  |  156|  23.7k|#define MP_GT         1   /* greater than */
  ------------------
  |  Branch (371:13): [True: 23.7k, False: 3.91k]
  |  Branch (371:43): [True: 23.7k, False: 0]
  ------------------
  372|  23.7k|	m_burn(randbuf, len);
  373|       |	m_free(randbuf);
  ------------------
  |  |   24|  23.7k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 23.7k]
  |  |  ------------------
  ------------------
  374|  23.7k|}

dropbear_close:
   95|  1.31k|void dropbear_close(const char* format, ...) {
   96|       |
   97|  1.31k|	va_list param;
   98|       |
   99|  1.31k|	va_start(param, format);
  100|  1.31k|	_dropbear_exit(EXIT_SUCCESS, format, param);
  101|  1.31k|	va_end(param);
  102|       |
  103|      0|}
dropbear_exit:
  105|  2.04k|void dropbear_exit(const char* format, ...) {
  106|       |
  107|  2.04k|	va_list param;
  108|       |
  109|  2.04k|	va_start(param, format);
  110|  2.04k|	_dropbear_exit(EXIT_FAILURE, format, param);
  111|  2.04k|	va_end(param);
  112|      0|}
dropbear_log:
  148|  3.74k|void dropbear_log(int priority, const char* format, ...) {
  149|       |
  150|  3.74k|	va_list param;
  151|       |
  152|  3.74k|	va_start(param, format);
  153|  3.74k|	_dropbear_log(priority, format, param);
  154|       |	va_end(param);
  155|  3.74k|}
m_close:
  565|  1.31k|void m_close(int fd) {
  566|  1.31k|	int val;
  567|       |
  568|  1.31k|	if (fd < 0) {
  ------------------
  |  Branch (568:6): [True: 0, False: 1.31k]
  ------------------
  569|      0|		return;
  570|      0|	}
  571|       |
  572|  1.31k|	do {
  573|  1.31k|		val = close(fd);
  ------------------
  |  |   56|  1.31k|#define close(fd) wrapfd_close(fd)
  ------------------
  574|  1.31k|	} while (val < 0 && errno == EINTR);
  ------------------
  |  Branch (574:11): [True: 0, False: 1.31k]
  |  Branch (574:22): [True: 0, False: 0]
  ------------------
  575|       |
  576|  1.31k|	if (val < 0 && errno != EBADF) {
  ------------------
  |  Branch (576:6): [True: 0, False: 1.31k]
  |  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.31k|}
setnonblocking:
  582|  6.71k|void setnonblocking(int fd) {
  583|       |
  584|  6.71k|	int fl = 0;
  585|  6.71k|	TRACE(("setnonblocking: %d", fd))
  586|       |
  587|  6.71k|#if DROPBEAR_FUZZ
  588|  6.71k|	if (fuzz.fuzzing) {
  ------------------
  |  Branch (588:6): [True: 6.71k, False: 0]
  ------------------
  589|  6.71k|		return;
  590|  6.71k|	}
  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|}
constant_time_memcmp:
  674|  1.50k|{
  675|  1.50k|	const char *xa = a, *xb = b;
  676|  1.50k|	uint8_t c = 0;
  677|  1.50k|	size_t i;
  678|  49.5k|	for (i = 0; i < n; i++)
  ------------------
  |  Branch (678:14): [True: 48.0k, False: 1.50k]
  ------------------
  679|  48.0k|	{
  680|  48.0k|		c |= (xa[i] ^ xb[i]);
  681|  48.0k|	}
  682|  1.50k|	return c;
  683|  1.50k|}
gettime_wrapper:
  686|   701k|void gettime_wrapper(struct timespec *now) {
  687|   701k|	struct timeval tv;
  688|   701k|#if DROPBEAR_FUZZ
  689|   701k|	if (fuzz.fuzzing) {
  ------------------
  |  Branch (689:6): [True: 701k, False: 0]
  ------------------
  690|       |		/* time stands still when fuzzing */
  691|   701k|		now->tv_sec = 5;
  692|   701k|		now->tv_nsec = 0;
  693|   701k|	}
  694|   701k|#endif
  695|       |
  696|   701k|#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
  697|       |	/* POSIX monotonic clock. Newer Linux, BSD, MacOSX >10.12 */
  698|   701k|	if (clock_gettime(CLOCK_MONOTONIC, now) == 0) {
  ------------------
  |  Branch (698:6): [True: 701k, False: 0]
  ------------------
  699|   701k|		return;
  700|   701k|	}
  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|   700k|time_t monotonic_now() {
  743|   700k|	struct timespec ts;
  744|   700k|	gettime_wrapper(&ts);
  745|   700k|	return ts.tv_sec;
  746|   700k|}

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|    280|ecc_key * buf_get_ecc_raw_pubkey(buffer *buf, const struct dropbear_ecc_curve *curve) {
  148|    280|	ecc_key *key = NULL;
  149|    280|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  112|    280|#define DROPBEAR_FAILURE -1
  ------------------
  150|    280|	const unsigned int size = curve->dp->size;
  151|    280|	unsigned char first;
  152|       |
  153|    280|	TRACE(("enter buf_get_ecc_raw_pubkey"))
  154|       |
  155|    280|	buf_setpos(buf, 0);
  156|    280|	first = buf_getbyte(buf);
  157|    280|	if (first == 2 || first == 3) {
  ------------------
  |  Branch (157:6): [True: 39, False: 241]
  |  Branch (157:20): [True: 83, False: 158]
  ------------------
  158|    119|		dropbear_log(LOG_WARNING, "Dropbear doesn't support ECC point compression");
  159|    119|		return NULL;
  160|    119|	}
  161|    161|	if (first != 4 || buf->len != 1+2*size) {
  ------------------
  |  Branch (161:6): [True: 131, False: 30]
  |  Branch (161:20): [True: 29, False: 1]
  ------------------
  162|    157|		TRACE(("leave, wrong size"))
  163|    157|		return NULL;
  164|    157|	}
  165|       |
  166|      4|	key = new_ecc_key();
  167|      4|	key->dp = curve->dp;
  168|       |
  169|      4|	if (mp_from_ubin(key->pubkey.x, buf_getptr(buf, size), size) != MP_OKAY) {
  ------------------
  |  |  161|      4|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (169:6): [True: 0, False: 4]
  ------------------
  170|      0|		TRACE(("failed to read x"))
  171|      0|		goto out;
  172|      0|	}
  173|      4|	buf_incrpos(buf, size);
  174|       |
  175|      4|	if (mp_from_ubin(key->pubkey.y, buf_getptr(buf, size), size) != MP_OKAY) {
  ------------------
  |  |  161|      4|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (175:6): [True: 0, False: 4]
  ------------------
  176|      0|		TRACE(("failed to read y"))
  177|      0|		goto out;
  178|      0|	}
  179|      4|	buf_incrpos(buf, size);
  180|       |
  181|      4|	mp_set(key->pubkey.z, 1);
  182|       |
  183|      4|	if (ecc_is_point(key) != CRYPT_OK) {
  ------------------
  |  Branch (183:6): [True: 0, False: 4]
  ------------------
  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|      4|	if (mp_cmp_d(key->pubkey.x, 0) == LTC_MP_EQ) {
  ------------------
  |  |   13|      4|#define LTC_MP_EQ    0
  ------------------
  |  Branch (189:6): [True: 0, False: 4]
  ------------------
  190|      0|		TRACE(("failed, x == 0"))
  191|      0|		goto out;
  192|      0|	}
  193|      4|	if (mp_cmp_d(key->pubkey.y, 0) == LTC_MP_EQ) {
  ------------------
  |  |   13|      4|#define LTC_MP_EQ    0
  ------------------
  |  Branch (193:6): [True: 0, False: 4]
  ------------------
  194|      0|		TRACE(("failed, y == 0"))
  195|      0|		goto out;
  196|      0|	}
  197|       |
  198|      4|	ret = DROPBEAR_SUCCESS;
  ------------------
  |  |  111|      4|#define DROPBEAR_SUCCESS 0
  ------------------
  199|       |
  200|      4|	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|      4|}
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|  25.5k|{
   12|  25.5k|	return type == DROPBEAR_SIGNKEY_ECDSA_NISTP256
  ------------------
  |  Branch (12:9): [True: 1, False: 25.5k]
  ------------------
   13|  25.5k|		|| type == DROPBEAR_SIGNKEY_ECDSA_NISTP384
  ------------------
  |  Branch (13:6): [True: 0, False: 25.5k]
  ------------------
   14|  25.5k|		|| type == DROPBEAR_SIGNKEY_ECDSA_NISTP521;
  ------------------
  |  Branch (14:6): [True: 0, False: 25.5k]
  ------------------
   15|  25.5k|}
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|}

gen_kexdh_param:
   21|  6.94k|struct kex_dh_param *gen_kexdh_param() {
   22|  6.94k|    struct kex_dh_param *param = NULL;
   23|       |
   24|  6.94k|    DEF_MP_INT(dh_p);
  ------------------
  |  |   81|  6.94k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
   25|  6.94k|    DEF_MP_INT(dh_q);
  ------------------
  |  |   81|  6.94k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
   26|  6.94k|    DEF_MP_INT(dh_g);
  ------------------
  |  |   81|  6.94k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
   27|       |
   28|  6.94k|    TRACE(("enter gen_kexdh_vals"))
   29|       |
   30|  6.94k|    param = m_malloc(sizeof(*param));
   31|  6.94k|    m_mp_init_multi(&param->pub, &param->priv, &dh_g, &dh_p, &dh_q, NULL);
   32|       |
   33|       |    /* read the prime and generator*/
   34|  6.94k|    load_dh_p(&dh_p);
   35|       |    
   36|  6.94k|    mp_set_ul(&dh_g, DH_G_VAL);
   37|       |
   38|       |    /* calculate q = (p-1)/2 */
   39|       |    /* dh_priv is just a temp var here */
   40|  6.94k|    if (mp_sub_d(&dh_p, 1, &param->priv) != MP_OKAY) { 
  ------------------
  |  |  161|  6.94k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (40:9): [True: 0, False: 6.94k]
  ------------------
   41|      0|        dropbear_exit("Diffie-Hellman error");
   42|      0|    }
   43|  6.94k|    if (mp_div_2(&param->priv, &dh_q) != MP_OKAY) {
  ------------------
  |  |  161|  6.94k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (43:9): [True: 0, False: 6.94k]
  ------------------
   44|      0|        dropbear_exit("Diffie-Hellman error");
   45|      0|    }
   46|       |
   47|       |    /* Generate a private portion 0 < dh_priv < dh_q */
   48|  6.94k|    gen_random_mpint(&dh_q, &param->priv);
   49|       |
   50|       |    /* f = g^y mod p */
   51|  6.94k|    if (mp_exptmod(&dh_g, &param->priv, &dh_p, &param->pub) != MP_OKAY) {
  ------------------
  |  |  161|  6.94k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (51:9): [True: 0, False: 6.94k]
  ------------------
   52|      0|        dropbear_exit("Diffie-Hellman error");
   53|      0|    }
   54|  6.94k|    mp_clear_multi(&dh_g, &dh_p, &dh_q, NULL);
   55|  6.94k|    return param;
   56|  6.94k|}
free_kexdh_param:
   59|  6.89k|{
   60|  6.89k|    mp_clear_multi(&param->pub, &param->priv, NULL);
   61|       |    m_free(param);
  ------------------
  |  |   24|  6.89k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 6.89k]
  |  |  ------------------
  ------------------
   62|  6.89k|}
kexdh_comb_key:
   69|  6.94k|        sign_key *hostkey) {
   70|       |
   71|  6.94k|    DEF_MP_INT(dh_p);
  ------------------
  |  |   81|  6.94k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
   72|  6.94k|    DEF_MP_INT(dh_p_min1);
  ------------------
  |  |   81|  6.94k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
   73|  6.94k|    mp_int *dh_e = NULL, *dh_f = NULL;
   74|       |
   75|  6.94k|    m_mp_init_multi(&dh_p, &dh_p_min1, NULL);
   76|  6.94k|    load_dh_p(&dh_p);
   77|       |
   78|  6.94k|    if (mp_sub_d(&dh_p, 1, &dh_p_min1) != MP_OKAY) { 
  ------------------
  |  |  161|  6.94k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (78:9): [True: 0, False: 6.94k]
  ------------------
   79|      0|        dropbear_exit("Diffie-Hellman error");
   80|      0|    }
   81|       |
   82|       |    /* Check that dh_pub_them (dh_e or dh_f) is in the range [2, p-2] */
   83|  6.94k|    if (mp_cmp(dh_pub_them, &dh_p_min1) != MP_LT 
  ------------------
  |  |  154|  13.8k|#define MP_LT        -1   /* less than */
  ------------------
  |  Branch (83:9): [True: 3, False: 6.94k]
  ------------------
   84|  6.94k|            || mp_cmp_d(dh_pub_them, 1) != MP_GT) {
  ------------------
  |  |  156|  6.94k|#define MP_GT         1   /* greater than */
  ------------------
  |  Branch (84:16): [True: 48, False: 6.89k]
  ------------------
   85|     51|        dropbear_exit("Diffie-Hellman error");
   86|     51|    }
   87|       |    
   88|       |    /* K = e^y mod p = f^x mod p */
   89|  6.89k|    m_mp_alloc_init_multi(&ses.dh_K, NULL);
   90|  6.89k|    if (mp_exptmod(dh_pub_them, &param->priv, &dh_p, ses.dh_K) != MP_OKAY) {
  ------------------
  |  |  161|  6.89k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (90:9): [True: 0, False: 6.89k]
  ------------------
   91|      0|        dropbear_exit("Diffie-Hellman error");
   92|      0|    }
   93|       |
   94|       |    /* clear no longer needed vars */
   95|  6.89k|    mp_clear_multi(&dh_p, &dh_p_min1, NULL);
   96|       |
   97|       |    /* From here on, the code needs to work with the _same_ vars on each side,
   98|       |     * not vice-versaing for client/server */
   99|  6.89k|    if (IS_DROPBEAR_CLIENT) {
  ------------------
  |  |  382|  6.89k|#define IS_DROPBEAR_CLIENT (ses.isserver == 0)
  |  |  ------------------
  |  |  |  Branch (382:28): [True: 0, False: 6.89k]
  |  |  ------------------
  ------------------
  100|      0|        dh_e = &param->pub;
  101|      0|        dh_f = dh_pub_them;
  102|  6.89k|    } else {
  103|  6.89k|        dh_e = dh_pub_them;
  104|  6.89k|        dh_f = &param->pub;
  105|  6.89k|    } 
  106|       |
  107|       |    /* Create the remainder of the hash buffer, to generate the exchange hash */
  108|       |    /* K_S, the host key */
  109|  6.89k|    buf_put_pub_key(ses.kexhashbuf, hostkey, ses.newkeys->algo_hostkey);
  110|       |    /* e, exchange value sent by the client */
  111|  6.89k|    buf_putmpint(ses.kexhashbuf, dh_e);
  112|       |    /* f, exchange value sent by the server */
  113|  6.89k|    buf_putmpint(ses.kexhashbuf, dh_f);
  114|       |    /* K, the shared secret */
  115|  6.89k|    buf_putmpint(ses.kexhashbuf, ses.dh_K);
  116|       |
  117|       |    /* calculate the hash H to sign */
  118|  6.89k|    finish_kexhashbuf();
  119|  6.89k|}
kex-dh.c:load_dh_p:
   13|  13.8k|{
   14|  13.8k|    bytes_to_mp(dh_p, ses.newkeys->algo_kex->dh_p_bytes, 
   15|  13.8k|        ses.newkeys->algo_kex->dh_p_len);
   16|  13.8k|}

gen_kexecdh_param:
   11|    279|struct kex_ecdh_param *gen_kexecdh_param() {
   12|    279|    struct kex_ecdh_param *param = m_malloc(sizeof(*param));
   13|    279|    const struct dropbear_ecc_curve *curve = ses.newkeys->algo_kex->details;
   14|    279|    if (ecc_make_key_ex(NULL, dropbear_ltc_prng, 
  ------------------
  |  Branch (14:9): [True: 0, False: 279]
  ------------------
   15|    279|        &param->key, curve->dp) != CRYPT_OK) {
   16|      0|        dropbear_exit("ECC error");
   17|      0|    }
   18|    279|    return param;
   19|    279|}
kexecdh_comb_key:
   27|    279|        sign_key *hostkey) {
   28|    279|    const struct dropbear_ecc_curve *curve
   29|    279|        = ses.newkeys->algo_kex->details;
   30|       |    /* public keys from client and server */
   31|    279|    ecc_key *Q_C, *Q_S, *Q_them;
   32|       |
   33|    279|    Q_them = buf_get_ecc_raw_pubkey(pub_them, curve);
   34|    279|    if (Q_them == NULL) {
  ------------------
  |  Branch (34:9): [True: 276, False: 3]
  ------------------
   35|    276|        dropbear_exit("ECC error");
   36|    276|    }
   37|       |
   38|      3|    ses.dh_K = dropbear_ecc_shared_secret(Q_them, &param->key);
   39|       |
   40|       |    /* Create the remainder of the hash buffer, to generate the exchange hash
   41|       |       See RFC5656 section 4 page 7 */
   42|      3|    if (IS_DROPBEAR_CLIENT) {
  ------------------
  |  |  382|      3|#define IS_DROPBEAR_CLIENT (ses.isserver == 0)
  |  |  ------------------
  |  |  |  Branch (382:28): [True: 0, False: 3]
  |  |  ------------------
  ------------------
   43|      0|        Q_C = &param->key;
   44|      0|        Q_S = Q_them;
   45|      3|    } else {
   46|      3|        Q_C = Q_them;
   47|      3|        Q_S = &param->key;
   48|      3|    } 
   49|       |
   50|       |    /* K_S, the host key */
   51|      3|    buf_put_pub_key(ses.kexhashbuf, hostkey, ses.newkeys->algo_hostkey);
   52|       |    /* Q_C, client's ephemeral public key octet string */
   53|      3|    buf_put_ecc_raw_pubkey_string(ses.kexhashbuf, Q_C);
   54|       |    /* Q_S, server's ephemeral public key octet string */
   55|      3|    buf_put_ecc_raw_pubkey_string(ses.kexhashbuf, Q_S);
   56|       |    /* K, the shared secret */
   57|      3|    buf_putmpint(ses.kexhashbuf, ses.dh_K);
   58|       |
   59|      3|    ecc_free(Q_them);
   60|      3|    m_free(Q_them);
  ------------------
  |  |   24|      3|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 3]
  |  |  ------------------
  ------------------
   61|       |
   62|       |    /* calculate the hash H to sign */
   63|      3|    finish_kexhashbuf();
   64|      3|}

gen_kexpqhybrid_param:
   13|      2|struct kex_pqhybrid_param *gen_kexpqhybrid_param() {
   14|      2|    struct kex_pqhybrid_param *param = m_malloc(sizeof(*param));
   15|      2|    const struct dropbear_kem_desc *kem = ses.newkeys->algo_kex->details;
   16|       |
   17|      2|    param->curve25519 = gen_kexcurve25519_param();
   18|       |
   19|      2|    if (IS_DROPBEAR_CLIENT) {
  ------------------
  |  |  382|      2|#define IS_DROPBEAR_CLIENT (ses.isserver == 0)
  |  |  ------------------
  |  |  |  Branch (382:28): [True: 0, False: 2]
  |  |  ------------------
  ------------------
   20|      0|        param->kem_cli_secret = buf_new(kem->secret_len);
   21|      0|        param->concat_public = buf_new(kem->public_len + CURVE25519_LEN);
  ------------------
  |  |  122|      0|#define CURVE25519_LEN 32
  ------------------
   22|      0|        kem->kem_gen(
   23|      0|            buf_getwriteptr(param->concat_public, kem->public_len),
   24|      0|            buf_getwriteptr(param->kem_cli_secret, kem->secret_len));
   25|      0|        buf_incrwritepos(param->concat_public, kem->public_len);
   26|      0|        buf_incrwritepos(param->kem_cli_secret, kem->secret_len);
   27|      0|        buf_setpos(param->kem_cli_secret, 0);
   28|       |        /* Append the curve25519 parameter */
   29|      0|        buf_putbytes(param->concat_public, param->curve25519->pub, CURVE25519_LEN);
  ------------------
  |  |  122|      0|#define CURVE25519_LEN 32
  ------------------
   30|      0|    }
   31|       |
   32|      2|    return param;
   33|      2|}
kexpqhybrid_comb_key:
   46|      2|    buffer *buf_pub, sign_key *hostkey) {
   47|       |
   48|      2|    const struct dropbear_kem_desc *kem = ses.newkeys->algo_kex->details;
   49|      2|    const struct ltc_hash_descriptor *hash_desc
   50|      2|        = ses.newkeys->algo_kex->hash_desc;
   51|       |
   52|       |    /* Either public key (from client) or ciphertext (from server) */
   53|      2|    unsigned char *remote_pub_kem = NULL;
   54|      2|    buffer *pub_25519 = NULL;
   55|      2|    buffer *k_out = NULL;
   56|      2|    unsigned int remote_len;
   57|      2|    hash_state hs;
   58|      2|    const buffer * Q_C = NULL;
   59|      2|    const buffer * Q_S = NULL;
   60|       |
   61|       |    /* Extract input parts from the remote peer */
   62|      2|    if (IS_DROPBEAR_CLIENT) {
  ------------------
  |  |  382|      2|#define IS_DROPBEAR_CLIENT (ses.isserver == 0)
  |  |  ------------------
  |  |  |  Branch (382:28): [True: 0, False: 2]
  |  |  ------------------
  ------------------
   63|       |        /* S_REPLY = S_CT2 || S_PK1 */
   64|      0|        remote_len = kem->ciphertext_len;
   65|      2|    } else {
   66|       |        /* C_INIT = C_PK2 || C_PK1 */
   67|      2|        remote_len = kem->public_len;
   68|      2|    }
   69|      2|    remote_pub_kem = buf_getptr(buf_pub, remote_len);
   70|      2|    buf_incrpos(buf_pub, remote_len);
   71|      2|    pub_25519 = buf_getptrcopy(buf_pub, CURVE25519_LEN);
  ------------------
  |  |  122|      2|#define CURVE25519_LEN 32
  ------------------
   72|      2|    buf_incrpos(buf_pub, CURVE25519_LEN);
  ------------------
  |  |  122|      2|#define CURVE25519_LEN 32
  ------------------
   73|       |    /* Check all is consumed */
   74|      2|    if (buf_pub->pos != buf_pub->len) {
  ------------------
  |  Branch (74:9): [True: 0, False: 2]
  ------------------
   75|      0|        dropbear_exit("Bad sntrup");
   76|      0|    }
   77|       |
   78|       |    /* k_out = K_PQ || K_CL */
   79|      2|    k_out = buf_new(kem->output_len + CURVE25519_LEN);
  ------------------
  |  |  122|      2|#define CURVE25519_LEN 32
  ------------------
   80|       |
   81|       |    /* Derive pq kem part (K_PQ) */
   82|      2|    if (IS_DROPBEAR_CLIENT) {
  ------------------
  |  |  382|      2|#define IS_DROPBEAR_CLIENT (ses.isserver == 0)
  |  |  ------------------
  |  |  |  Branch (382:28): [True: 0, False: 2]
  |  |  ------------------
  ------------------
   83|      0|        kem->kem_dec(
   84|      0|            buf_getwriteptr(k_out, kem->output_len),
   85|      0|            remote_pub_kem,
   86|      0|            buf_getptr(param->kem_cli_secret, kem->secret_len));
   87|      0|        buf_burn_free(param->kem_cli_secret);
   88|      0|        param->kem_cli_secret = NULL;
   89|      2|    } else {
   90|       |        /* Server returns ciphertext */
   91|      2|        assert(param->concat_public == NULL);
  ------------------
  |  Branch (91:9): [True: 0, False: 2]
  |  Branch (91:9): [True: 0, False: 2]
  ------------------
   92|      2|        param->concat_public = buf_new(kem->ciphertext_len + CURVE25519_LEN);
  ------------------
  |  |  122|      0|#define CURVE25519_LEN 32
  ------------------
   93|      0|        kem->kem_enc(
   94|      0|            buf_getwriteptr(param->concat_public, kem->ciphertext_len),
   95|      0|            buf_getwriteptr(k_out, kem->output_len),
   96|      0|            remote_pub_kem);
   97|      0|        buf_incrwritepos(param->concat_public, kem->ciphertext_len);
   98|       |        /* Append the curve25519 parameter */
   99|      0|        buf_putbytes(param->concat_public, param->curve25519->pub, CURVE25519_LEN);
  ------------------
  |  |  122|      0|#define CURVE25519_LEN 32
  ------------------
  100|      0|    }
  101|      2|    buf_incrwritepos(k_out, kem->output_len);
  102|       |
  103|       |    /* Derive ec part (K_CL) */
  104|      0|    kexcurve25519_derive(param->curve25519, pub_25519,
  105|      0|        buf_getwriteptr(k_out, CURVE25519_LEN));
  ------------------
  |  |  122|      0|#define CURVE25519_LEN 32
  ------------------
  106|      0|    buf_incrwritepos(k_out, CURVE25519_LEN);
  ------------------
  |  |  122|      0|#define CURVE25519_LEN 32
  ------------------
  107|       |
  108|       |    /* dh_K_bytes = HASH(k_out)
  109|       |       dh_K_bytes is a SSH string with length prefix, since
  110|       |       that is what needs to be hashed in gen_new_keys() */
  111|      0|    ses.dh_K_bytes = buf_new(4 + hash_desc->hashsize);
  112|      0|    buf_putint(ses.dh_K_bytes, hash_desc->hashsize);
  113|      0|    hash_desc->init(&hs);
  114|      0|    hash_desc->process(&hs, k_out->data, k_out->len);
  115|      0|    hash_desc->done(&hs, buf_getwriteptr(ses.dh_K_bytes, hash_desc->hashsize));
  116|      0|    m_burn(&hs, sizeof(hash_state));
  117|      0|    buf_incrwritepos(ses.dh_K_bytes, hash_desc->hashsize);
  118|       |
  119|       |    /* Create the remainder of the hash buffer */
  120|      0|    if (IS_DROPBEAR_CLIENT) {
  ------------------
  |  |  382|      0|#define IS_DROPBEAR_CLIENT (ses.isserver == 0)
  |  |  ------------------
  |  |  |  Branch (382:28): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  121|      0|        Q_C = param->concat_public;
  122|      0|        Q_S = buf_pub;
  123|      0|    } else {
  124|      0|        Q_S = param->concat_public;
  125|      0|        Q_C = buf_pub;
  126|      0|    }
  127|       |
  128|       |    /* K_S, the host key */
  129|      0|    buf_put_pub_key(ses.kexhashbuf, hostkey, ses.newkeys->algo_hostkey);
  130|      0|    buf_putbufstring(ses.kexhashbuf, Q_C);
  131|      0|    buf_putbufstring(ses.kexhashbuf, Q_S);
  132|       |    /* K, the shared secret */
  133|      0|    buf_putbytes(ses.kexhashbuf, ses.dh_K_bytes->data, ses.dh_K_bytes->len);
  134|       |
  135|       |    /* calculate the hash H to sign */
  136|      0|    finish_kexhashbuf();
  137|       |
  138|      0|    buf_burn_free(k_out);
  139|      0|    buf_free(pub_25519);
  140|      0|}

gen_kexcurve25519_param:
   14|  1.51k|struct kex_curve25519_param *gen_kexcurve25519_param() {
   15|       |    /* Per http://cr.yp.to/ecdh.html */
   16|  1.51k|    struct kex_curve25519_param *param = m_malloc(sizeof(*param));
   17|  1.51k|    const unsigned char basepoint[32] = {9};
   18|       |
   19|  1.51k|    genrandom(param->priv, CURVE25519_LEN);
  ------------------
  |  |  122|  1.51k|#define CURVE25519_LEN 32
  ------------------
   20|  1.51k|    dropbear_curve25519_scalarmult(param->pub, param->priv, basepoint);
   21|       |
   22|  1.51k|    return param;
   23|  1.51k|}
free_kexcurve25519_param:
   25|  1.50k|void free_kexcurve25519_param(struct kex_curve25519_param *param) {
   26|  1.50k|    m_burn(param->priv, CURVE25519_LEN);
  ------------------
  |  |  122|  1.50k|#define CURVE25519_LEN 32
  ------------------
   27|       |    m_free(param);
  ------------------
  |  |   24|  1.50k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 1.50k]
  |  |  ------------------
  ------------------
   28|  1.50k|}
kexcurve25519_derive:
   32|  1.51k|    unsigned char *out) {
   33|  1.51k|    char zeroes[CURVE25519_LEN] = {0};
   34|  1.51k|    if (buf_pub_them->len != CURVE25519_LEN)
  ------------------
  |  |  122|  1.51k|#define CURVE25519_LEN 32
  ------------------
  |  Branch (34:9): [True: 12, False: 1.50k]
  ------------------
   35|     12|    {
   36|     12|        dropbear_exit("Bad curve25519");
   37|     12|    }
   38|       |
   39|  1.50k|    dropbear_curve25519_scalarmult(out, param->priv, buf_pub_them->data);
   40|       |
   41|  1.50k|    if (constant_time_memcmp(zeroes, out, CURVE25519_LEN) == 0) {
  ------------------
  |  |  122|  1.50k|#define CURVE25519_LEN 32
  ------------------
  |  Branch (41:9): [True: 1, False: 1.50k]
  ------------------
   42|      1|        dropbear_exit("Bad curve25519");
   43|      1|    }
   44|  1.50k|}
kexcurve25519_comb_key:
   52|  1.51k|    sign_key *hostkey) {
   53|  1.51k|    unsigned char out[CURVE25519_LEN];
   54|  1.51k|    const unsigned char* Q_C = NULL;
   55|  1.51k|    const unsigned char* Q_S = NULL;
   56|       |
   57|  1.51k|    kexcurve25519_derive(param, buf_pub_them, out);
   58|       |
   59|  1.51k|    m_mp_alloc_init_multi(&ses.dh_K, NULL);
   60|  1.51k|    bytes_to_mp(ses.dh_K, out, CURVE25519_LEN);
  ------------------
  |  |  122|  1.51k|#define CURVE25519_LEN 32
  ------------------
   61|  1.51k|    m_burn(out, sizeof(out));
   62|       |
   63|       |    /* Create the remainder of the hash buffer, to generate the exchange hash.
   64|       |       See RFC5656 section 4 page 7 */
   65|  1.51k|    if (IS_DROPBEAR_CLIENT) {
  ------------------
  |  |  382|  1.51k|#define IS_DROPBEAR_CLIENT (ses.isserver == 0)
  |  |  ------------------
  |  |  |  Branch (382:28): [True: 0, False: 1.51k]
  |  |  ------------------
  ------------------
   66|      0|        Q_C = param->pub;
   67|      0|        Q_S = buf_pub_them->data;
   68|  1.51k|    } else {
   69|  1.51k|        Q_S = param->pub;
   70|  1.51k|        Q_C = buf_pub_them->data;
   71|  1.51k|    }
   72|       |
   73|       |    /* K_S, the host key */
   74|  1.51k|    buf_put_pub_key(ses.kexhashbuf, hostkey, ses.newkeys->algo_hostkey);
   75|       |    /* Q_C, client's ephemeral public key octet string */
   76|  1.51k|    buf_putstring(ses.kexhashbuf, (const char*)Q_C, CURVE25519_LEN);
  ------------------
  |  |  122|  1.51k|#define CURVE25519_LEN 32
  ------------------
   77|       |    /* Q_S, server's ephemeral public key octet string */
   78|  1.51k|    buf_putstring(ses.kexhashbuf, (const char*)Q_S, CURVE25519_LEN);
  ------------------
  |  |  122|  1.51k|#define CURVE25519_LEN 32
  ------------------
   79|       |    /* K, the shared secret */
   80|  1.51k|    buf_putmpint(ses.kexhashbuf, ses.dh_K);
   81|       |
   82|       |    /* calculate the hash H to sign */
   83|  1.51k|    finish_kexhashbuf();
   84|  1.51k|}

listeners_initialise:
   30|  3.35k|void listeners_initialise() {
   31|       |
   32|       |	/* just one slot to start with */
   33|  3.35k|	ses.listeners = (struct Listener**)m_malloc(sizeof(struct Listener*));
   34|  3.35k|	ses.listensize = 1;
   35|  3.35k|	ses.listeners[0] = NULL;
   36|       |
   37|  3.35k|}
set_listener_fds:
   39|   264k|void set_listener_fds(fd_set * readfds) {
   40|       |
   41|   264k|	unsigned int i, j;
   42|   264k|	struct Listener *listener;
   43|       |
   44|       |	/* check each in turn */
   45|   528k|	for (i = 0; i < ses.listensize; i++) {
  ------------------
  |  Branch (45:14): [True: 264k, False: 264k]
  ------------------
   46|   264k|		listener = ses.listeners[i];
   47|   264k|		if (listener != NULL) {
  ------------------
  |  Branch (47:7): [True: 0, False: 264k]
  ------------------
   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|   264k|	}
   53|   264k|}
handle_listeners:
   56|   260k|void handle_listeners(const fd_set * readfds) {
   57|       |
   58|   260k|	unsigned int i, j;
   59|   260k|	struct Listener *listener;
   60|   260k|	int sock;
   61|       |
   62|       |	/* check each in turn */
   63|   521k|	for (i = 0; i < ses.listensize; i++) {
  ------------------
  |  Branch (63:14): [True: 260k, False: 260k]
  ------------------
   64|   260k|		listener = ses.listeners[i];
   65|   260k|		if (listener != NULL) {
  ------------------
  |  Branch (65:7): [True: 0, False: 260k]
  ------------------
   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|   260k|	}
   74|   260k|} /* Woo brace matching */
remove_all_listeners:
  166|  3.35k|void remove_all_listeners(void) {
  167|  3.35k|	unsigned int i;
  168|  6.71k|	for (i = 0; i < ses.listensize; i++) {
  ------------------
  |  Branch (168:14): [True: 3.35k, False: 3.35k]
  ------------------
  169|  3.35k|		if (ses.listeners[i]) {
  ------------------
  |  Branch (169:7): [True: 0, False: 3.35k]
  ------------------
  170|      0|			remove_listener(ses.listeners[i]);
  171|      0|		}
  172|  3.35k|	}
  173|       |	m_free(ses.listeners);
  ------------------
  |  |   24|  3.35k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 3.35k]
  |  |  ------------------
  ------------------
  174|  3.35k|}

dropbear_prng_read:
   70|    279|{
   71|    279|   LTC_ARGCHK(out != NULL);
  ------------------
  |  |   32|    279|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 279]
  |  |  |  Branch (32:87): [Folded, False: 279]
  |  |  ------------------
  ------------------
   72|    279|   genrandom(out, outlen);
   73|    279|   return outlen;
   74|    279|}

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

process_packet:
   43|  48.3k|void process_packet() {
   44|       |
   45|  48.3k|	unsigned char type;
   46|  48.3k|	unsigned int i;
   47|  48.3k|	unsigned int first_strict_kex = ses.kexstate.strict_kex && !ses.kexstate.recvfirstnewkeys;
  ------------------
  |  Branch (47:34): [True: 535, False: 47.8k]
  |  Branch (47:61): [True: 81, False: 454]
  ------------------
   48|  48.3k|	time_t now;
   49|       |
   50|  48.3k|	TRACE2(("enter process_packet"))
   51|       |
   52|  48.3k|	type = buf_getbyte(ses.payload);
   53|  48.3k|	TRACE(("process_packet: packet type = %d,  len %d", type, ses.payload->len))
   54|       |
   55|  48.3k|	now = monotonic_now();
   56|  48.3k|	ses.last_packet_time_keepalive_recv = now;
   57|       |
   58|       |
   59|  48.3k|	if (type == SSH_MSG_DISCONNECT) {
  ------------------
  |  |   29|  48.3k|#define SSH_MSG_DISCONNECT             1
  ------------------
  |  Branch (59:6): [True: 2, False: 48.3k]
  ------------------
   60|       |		/* Allowed at any time */
   61|      2|		dropbear_close("Disconnect received");
   62|      2|	}
   63|       |
   64|       |	/* These packets may be received at any time,
   65|       |	   except during first kex with strict kex */
   66|  48.3k|	if (!first_strict_kex) {
  ------------------
  |  Branch (66:6): [True: 48.2k, False: 83]
  ------------------
   67|  48.2k|		switch(type) {
  ------------------
  |  Branch (67:10): [True: 1.06k, False: 47.2k]
  ------------------
   68|    180|			case SSH_MSG_IGNORE:
  ------------------
  |  |   30|    180|#define SSH_MSG_IGNORE                 2
  ------------------
  |  Branch (68:4): [True: 180, False: 48.0k]
  ------------------
   69|    180|				goto out;
   70|    786|			case SSH_MSG_DEBUG:
  ------------------
  |  |   32|    786|#define SSH_MSG_DEBUG                  4
  ------------------
  |  Branch (70:4): [True: 786, False: 47.4k]
  ------------------
   71|    786|				goto out;
   72|     98|			case SSH_MSG_UNIMPLEMENTED:
  ------------------
  |  |   31|     98|#define SSH_MSG_UNIMPLEMENTED          3
  ------------------
  |  Branch (72:4): [True: 98, False: 48.1k]
  ------------------
   73|     98|				TRACE(("SSH_MSG_UNIMPLEMENTED"))
   74|     98|				goto out;
   75|  48.2k|		}
   76|  48.2k|	}
   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|  47.2k|	if (!(type == SSH_MSG_GLOBAL_REQUEST 
  ------------------
  |  |   63|  94.5k|#define SSH_MSG_GLOBAL_REQUEST                  80
  ------------------
  |  Branch (82:8): [True: 4, False: 47.2k]
  ------------------
   83|  47.2k|		|| type == SSH_MSG_REQUEST_FAILURE
  ------------------
  |  |   65|  94.5k|#define SSH_MSG_REQUEST_FAILURE                 82
  ------------------
  |  Branch (83:6): [True: 1, False: 47.2k]
  ------------------
   84|  47.2k|		|| type == SSH_MSG_CHANNEL_FAILURE)) {
  ------------------
  |  |   76|  47.2k|#define SSH_MSG_CHANNEL_FAILURE                 100
  ------------------
  |  Branch (84:6): [True: 4, False: 47.2k]
  ------------------
   85|  47.2k|		ses.last_packet_time_idle = now;
   86|  47.2k|	}
   87|       |
   88|       |	/* This applies for KEX, where the spec says the next packet MUST be
   89|       |	 * NEWKEYS */
   90|  47.2k|	if (ses.requirenext != 0) {
  ------------------
  |  Branch (90:6): [True: 38.3k, False: 8.92k]
  ------------------
   91|  38.3k|		if (ses.requirenext == type)
  ------------------
  |  Branch (91:7): [True: 19.8k, False: 18.4k]
  ------------------
   92|  19.8k|		{
   93|       |			/* Got what we expected */
   94|  19.8k|			TRACE(("got expected packet %d during kexinit", type))
   95|  19.8k|		}
   96|  18.4k|		else
   97|  18.4k|		{
   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.4k|			if (type >= 1 && type <= 49
  ------------------
  |  Branch (101:8): [True: 18.4k, False: 16]
  |  Branch (101:21): [True: 18.4k, False: 37]
  ------------------
  102|  18.4k|				&& type != SSH_MSG_SERVICE_REQUEST
  ------------------
  |  |   33|  36.9k|#define SSH_MSG_SERVICE_REQUEST        5
  ------------------
  |  Branch (102:8): [True: 18.4k, False: 2]
  ------------------
  103|  18.4k|				&& type != SSH_MSG_SERVICE_ACCEPT
  ------------------
  |  |   34|  36.9k|#define SSH_MSG_SERVICE_ACCEPT         6
  ------------------
  |  Branch (103:8): [True: 18.4k, False: 1]
  ------------------
  104|  18.4k|				&& type != SSH_MSG_KEXINIT
  ------------------
  |  |   36|  36.9k|#define SSH_MSG_KEXINIT                20
  ------------------
  |  Branch (104:8): [True: 18.4k, False: 4]
  ------------------
  105|  18.4k|				&& !first_strict_kex)
  ------------------
  |  Branch (105:8): [True: 18.4k, False: 2]
  ------------------
  106|  18.4k|			{
  107|  18.4k|				TRACE(("unknown allowed packet during kexinit"))
  108|  18.4k|				recv_unimplemented();
  109|  18.4k|				goto out;
  110|  18.4k|			}
  111|     62|			else
  112|     62|			{
  113|     62|				TRACE(("disallowed packet during kexinit"))
  114|     62|				dropbear_exit("Unexpected packet type %d, expected %d", type,
  115|     62|						ses.requirenext);
  116|     62|			}
  117|  18.4k|		}
  118|  38.3k|	}
  119|       |
  120|       |	/* Check if we should ignore this packet. Used currently only for
  121|       |	 * KEX code, with first_kex_packet_follows */
  122|  28.8k|	if (ses.ignorenext) {
  ------------------
  |  Branch (122:6): [True: 425, False: 28.3k]
  ------------------
  123|    425|		TRACE(("Ignoring packet, type = %d", type))
  124|    425|		ses.ignorenext = 0;
  125|    425|		goto out;
  126|    425|	}
  127|       |
  128|       |	/* Only clear the flag after we have checked ignorenext */
  129|  28.3k|	if (ses.requirenext != 0 && ses.requirenext == type)
  ------------------
  |  Branch (129:6): [True: 19.4k, False: 8.92k]
  |  Branch (129:30): [True: 19.4k, False: 0]
  ------------------
  130|  19.4k|	{
  131|  19.4k|		ses.requirenext = 0;
  132|  19.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|  28.3k|	if ( !ses.authstate.authdone && type > MAX_UNAUTH_PACKET_TYPE ) {
  ------------------
  |  |   38|  28.3k|#define MAX_UNAUTH_PACKET_TYPE SSH_MSG_USERAUTH_PK_OK
  |  |  ------------------
  |  |  |  |   52|  28.3k|#define SSH_MSG_USERAUTH_PK_OK				60
  |  |  ------------------
  ------------------
  |  Branch (139:7): [True: 28.3k, False: 2]
  |  Branch (139:34): [True: 7, False: 28.3k]
  ------------------
  140|      7|		dropbear_exit("Received message %d before userauth", type);
  141|      7|	}
  142|       |
  143|   177k|	for (i = 0; ; i++) {
  144|   177k|		if (ses.packettypes[i].type == 0) {
  ------------------
  |  Branch (144:7): [True: 904, False: 176k]
  ------------------
  145|       |			/* end of list */
  146|    904|			break;
  147|    904|		}
  148|       |
  149|   176k|		if (ses.packettypes[i].type == type) {
  ------------------
  |  Branch (149:7): [True: 27.4k, False: 148k]
  ------------------
  150|  27.4k|			ses.packettypes[i].handler();
  151|  27.4k|			goto out;
  152|  27.4k|		}
  153|   176k|	}
  154|       |
  155|       |	
  156|       |	/* TODO do something more here? */
  157|    906|	TRACE(("preauth unknown packet"))
  158|    906|	recv_unimplemented();
  159|       |
  160|  46.5k|out:
  161|  46.5k|	ses.lastpacket = type;
  162|  46.5k|	buf_free(ses.payload);
  163|  46.5k|	ses.payload = NULL;
  164|       |
  165|  46.5k|	TRACE2(("leave process_packet"))
  166|  46.5k|}
process-packet.c:recv_unimplemented:
  174|  19.3k|static void recv_unimplemented() {
  175|       |
  176|  19.3k|	CHECKCLEARTOWRITE();
  177|       |
  178|  19.3k|	buf_putbyte(ses.writepayload, SSH_MSG_UNIMPLEMENTED);
  ------------------
  |  |   31|  19.3k|#define SSH_MSG_UNIMPLEMENTED          3
  ------------------
  179|       |	/* the decryption routine increments the sequence number, we must
  180|       |	 * decrement */
  181|  19.3k|	buf_putint(ses.writepayload, ses.recvseq - 1);
  182|       |
  183|  19.3k|	encrypt_packet();
  184|  19.3k|}

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

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|}
buf_put_rsa_pub_key:
  162|  17.1k|void buf_put_rsa_pub_key(buffer* buf, const dropbear_rsa_key *key) {
  163|       |
  164|  17.1k|	TRACE(("enter buf_put_rsa_pub_key"))
  165|  17.1k|	dropbear_assert(key != NULL);
  ------------------
  |  |   84|  17.1k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (84:37): [True: 0, False: 17.1k]
  |  |  |  Branch (84:93): [Folded, False: 17.1k]
  |  |  ------------------
  ------------------
  166|       |
  167|  17.1k|	buf_putstring(buf, SSH_SIGNKEY_RSA, SSH_SIGNKEY_RSA_LEN);
  ------------------
  |  |  116|  17.1k|#define SSH_SIGNKEY_RSA "ssh-rsa"
  ------------------
              	buf_putstring(buf, SSH_SIGNKEY_RSA, SSH_SIGNKEY_RSA_LEN);
  ------------------
  |  |  117|  17.1k|#define SSH_SIGNKEY_RSA_LEN 7
  ------------------
  168|  17.1k|	buf_putmpint(buf, key->e);
  169|  17.1k|	buf_putmpint(buf, key->n);
  170|       |
  171|  17.1k|	TRACE(("leave buf_put_rsa_pub_key"))
  172|       |
  173|  17.1k|}
buf_put_rsa_sign:
  257|  8.39k|		enum signature_type sigtype, const buffer *data_buf) {
  258|  8.39k|	const char *name = NULL;
  259|  8.39k|	unsigned int nsize, ssize, namelen = 0;
  260|  8.39k|	unsigned int i;
  261|  8.39k|	size_t written;
  262|  8.39k|	DEF_MP_INT(rsa_s);
  ------------------
  |  |   81|  8.39k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  263|  8.39k|	DEF_MP_INT(rsa_tmp1);
  ------------------
  |  |   81|  8.39k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  264|  8.39k|	DEF_MP_INT(rsa_tmp2);
  ------------------
  |  |   81|  8.39k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  265|  8.39k|	DEF_MP_INT(rsa_tmp3);
  ------------------
  |  |   81|  8.39k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  266|  8.39k|	DEF_MP_INT(rsa_phi_n);
  ------------------
  |  |   81|  8.39k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  267|  8.39k|	DEF_MP_INT(rsa_b_tmp);
  ------------------
  |  |   81|  8.39k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  268|  8.39k|	DEF_MP_INT(rsa_b_rand);
  ------------------
  |  |   81|  8.39k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  269|  8.39k|	DEF_MP_INT(rsa_b_phi);
  ------------------
  |  |   81|  8.39k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  270|  8.39k|	DEF_MP_INT(rsa_b_d);
  ------------------
  |  |   81|  8.39k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  271|       |	
  272|  8.39k|	TRACE(("enter buf_put_rsa_sign"))
  273|  8.39k|	dropbear_assert(key != NULL);
  ------------------
  |  |   84|  8.39k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (84:37): [True: 0, False: 8.39k]
  |  |  |  Branch (84:93): [Folded, False: 8.39k]
  |  |  ------------------
  ------------------
  274|       |
  275|  8.39k|	m_mp_init_multi(&rsa_s, &rsa_tmp1, &rsa_tmp2, &rsa_tmp3,
  276|  8.39k|		&rsa_phi_n, &rsa_b_tmp, &rsa_b_rand, &rsa_b_phi, &rsa_b_d,
  277|  8.39k|		NULL);
  278|       |
  279|  8.39k|	rsa_pad_em(key, data_buf, &rsa_tmp1, sigtype);
  280|       |
  281|       |	/* the actual signing of the padded data */
  282|       |
  283|  8.39k|#if DROPBEAR_RSA_BLINDING
  284|       |	/* https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-rsa-guidance-08 */
  285|       |
  286|       |	/* With base blinding, s = (r^(-1))((em)*r^e)^d mod n */
  287|       |
  288|       |	/* generate the r base blinding value */
  289|       |	/* rsa_tmp2 is r */
  290|  8.39k|	gen_random_mpint(key->n, &rsa_tmp2);
  291|       |
  292|       |	/* rsa_tmp1 is em */
  293|       |	/* em' = em * r^e mod n */
  294|       |	/* rsa_s used as a temp var*/
  295|  8.39k|	if (mp_exptmod(&rsa_tmp2, key->e, key->n, &rsa_s) != MP_OKAY) {
  ------------------
  |  |  161|  8.39k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (295:6): [True: 0, False: 8.39k]
  ------------------
  296|      0|		dropbear_exit("RSA error");
  297|      0|	}
  298|  8.39k|	if (mp_invmod(&rsa_tmp2, key->n, &rsa_tmp3) != MP_OKAY) {
  ------------------
  |  |  161|  8.39k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (298:6): [True: 0, False: 8.39k]
  ------------------
  299|      0|		dropbear_exit("RSA error");
  300|      0|	}
  301|  8.39k|	if (mp_mulmod(&rsa_tmp1, &rsa_s, key->n, &rsa_tmp2) != MP_OKAY) {
  ------------------
  |  |  161|  8.39k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (301:6): [True: 0, False: 8.39k]
  ------------------
  302|      0|		dropbear_exit("RSA error");
  303|      0|	}
  304|       |
  305|       |	/* exponent blinding, m = c^(d + b*phi(n)) mod n.
  306|       |	 * b is a 64-bit random value. */
  307|  8.39k|	mp_set_u64(&rsa_b_tmp, UINT64_MAX);
  308|  8.39k|	gen_random_mpint(&rsa_b_tmp, &rsa_b_rand);
  309|       |	/* phi(n) = phi(p*q) = phi(p) * phi(q) = (p-1)*(q-1) = n + 1 - p - q
  310|       |	 * since n = p*q, phi(prime) = prime-1. */
  311|  8.39k|	if (mp_add_d(key->n, 1, &rsa_phi_n) != MP_OKAY) {
  ------------------
  |  |  161|  8.39k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (311:6): [True: 0, False: 8.39k]
  ------------------
  312|      0|		dropbear_exit("RSA error");
  313|      0|	}
  314|       |	/* rsa_b_d as a temporary */
  315|  8.39k|	if (mp_sub(&rsa_phi_n, key->p, &rsa_b_d) != MP_OKAY) {
  ------------------
  |  |  161|  8.39k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (315:6): [True: 0, False: 8.39k]
  ------------------
  316|      0|		dropbear_exit("RSA error");
  317|      0|	}
  318|  8.39k|	if (mp_sub(&rsa_b_d, key->q, &rsa_phi_n) != MP_OKAY) {
  ------------------
  |  |  161|  8.39k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (318:6): [True: 0, False: 8.39k]
  ------------------
  319|      0|		dropbear_exit("RSA error");
  320|      0|	}
  321|       |
  322|       |	/* b*phi(n) */
  323|  8.39k|	if (mp_mul(&rsa_b_rand, &rsa_phi_n, &rsa_b_tmp) != MP_OKAY) {
  ------------------
  |  |  161|  8.39k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (323:6): [True: 0, False: 8.39k]
  ------------------
  324|      0|		dropbear_exit("RSA error");
  325|      0|	}
  326|       |	/* d + b*phi(n) */
  327|  8.39k|	if (mp_add(key->d, &rsa_b_tmp, &rsa_b_d) != MP_OKAY) {
  ------------------
  |  |  161|  8.39k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (327:6): [True: 0, False: 8.39k]
  ------------------
  328|      0|		dropbear_exit("RSA error");
  329|      0|	}
  330|       |
  331|       |	/* rsa_tmp2 is em' */
  332|       |	/* s' = (em')^d mod n */
  333|  8.39k|	if (mp_exptmod(&rsa_tmp2, &rsa_b_d, key->n, &rsa_tmp1) != MP_OKAY) {
  ------------------
  |  |  161|  8.39k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (333:6): [True: 0, False: 8.39k]
  ------------------
  334|      0|		dropbear_exit("RSA error");
  335|      0|	}
  336|       |
  337|  8.39k|	m_mp_burn(&rsa_phi_n);
  338|  8.39k|	m_mp_burn(&rsa_b_tmp);
  339|  8.39k|	m_mp_burn(&rsa_b_rand);
  340|  8.39k|	m_mp_burn(&rsa_b_phi);
  341|  8.39k|	m_mp_burn(&rsa_b_d);
  342|       |
  343|       |	/* rsa_tmp1 is s' */
  344|       |	/* rsa_tmp3 is r^(-1) mod n */
  345|       |	/* s = (s')r^(-1) mod n */
  346|  8.39k|	if (mp_mulmod(&rsa_tmp1, &rsa_tmp3, key->n, &rsa_s) != MP_OKAY) {
  ------------------
  |  |  161|  8.39k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (346:6): [True: 0, False: 8.39k]
  ------------------
  347|      0|		dropbear_exit("RSA error");
  348|      0|	}
  349|       |
  350|       |#else
  351|       |
  352|       |	/* s = em^d mod n */
  353|       |	/* rsa_tmp1 is em */
  354|       |	if (mp_exptmod(&rsa_tmp1, key->d, key->n, &rsa_s) != MP_OKAY) {
  355|       |		dropbear_exit("RSA error");
  356|       |	}
  357|       |
  358|       |#endif /* DROPBEAR_RSA_BLINDING */
  359|       |
  360|  8.39k|	mp_clear_multi(&rsa_tmp1, &rsa_tmp2, &rsa_tmp3,
  361|  8.39k|		&rsa_phi_n, &rsa_b_tmp, &rsa_b_rand, &rsa_b_phi, &rsa_b_d,
  362|  8.39k|		NULL);
  363|       |
  364|       |	/* create the signature to return */
  365|  8.39k|	name = signature_name_from_type(sigtype, &namelen);
  366|  8.39k|	buf_putstring(buf, name, namelen);
  367|       |
  368|  8.39k|	nsize = mp_ubin_size(key->n);
  369|       |
  370|       |	/* string rsa_signature_blob length */
  371|  8.39k|	buf_putint(buf, nsize);
  372|       |	/* pad out s to same length as n */
  373|  8.39k|	ssize = mp_ubin_size(&rsa_s);
  374|  8.39k|	dropbear_assert(ssize <= nsize);
  ------------------
  |  |   84|  8.39k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (84:37): [True: 0, False: 8.39k]
  |  |  |  Branch (84:93): [Folded, False: 8.39k]
  |  |  ------------------
  ------------------
  375|  8.44k|	for (i = 0; i < nsize-ssize; i++) {
  ------------------
  |  Branch (375:14): [True: 52, False: 8.39k]
  ------------------
  376|     52|		buf_putbyte(buf, 0x00);
  377|     52|	}
  378|       |
  379|  8.39k|	if (mp_to_ubin(&rsa_s, buf_getwriteptr(buf, ssize), ssize, &written) != MP_OKAY) {
  ------------------
  |  |  161|  8.39k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (379:6): [True: 0, False: 8.39k]
  ------------------
  380|      0|		dropbear_exit("RSA error");
  381|      0|	}
  382|  8.39k|	buf_incrwritepos(buf, written);
  383|  8.39k|	mp_clear(&rsa_s);
  384|       |
  385|       |#if defined(DEBUG_RSA) && DEBUG_TRACE
  386|       |	if (!debug_trace) {
  387|       |		printhex("RSA sig", buf->data, buf->len);
  388|       |	}
  389|       |#endif
  390|       |	
  391|       |
  392|  8.39k|	TRACE(("leave buf_put_rsa_sign"))
  393|  8.39k|}
rsa.c:rsa_pad_em:
  398|  8.39k|	const buffer *data_buf, mp_int * rsa_em, enum signature_type sigtype) {
  399|       |    /* EM = 0x00 || 0x01 || PS || 0x00 || T 
  400|       |	   PS is padding of 0xff to make EM the size of key->n
  401|       |
  402|       |	   T is the DER encoding of the hash alg (sha1 or sha256)
  403|       |	*/
  404|       |
  405|       |	/* From rfc8017 page 46 */
  406|  8.39k|#if DROPBEAR_RSA_SHA1
  407|  8.39k|	const unsigned char T_sha1[] =
  408|  8.39k|		{0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b,
  409|  8.39k|		 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14};
  410|  8.39k|#endif
  411|  8.39k|#if DROPBEAR_RSA_SHA256
  412|  8.39k|	const unsigned char T_sha256[] =
  413|  8.39k|		{0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01,
  414|  8.39k|		 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20};
  415|  8.39k|#endif
  416|       |
  417|  8.39k|    int Tlen = 0;
  418|  8.39k|    const unsigned char *T = NULL;
  419|  8.39k|	const struct ltc_hash_descriptor *hash_desc = NULL;
  420|  8.39k|	buffer * rsa_EM = NULL;
  421|  8.39k|	hash_state hs;
  422|  8.39k|	unsigned int nsize;
  423|       |
  424|  8.39k|	switch (sigtype) {
  425|      0|#if DROPBEAR_RSA_SHA1
  426|  8.39k|		case DROPBEAR_SIGNATURE_RSA_SHA1:
  ------------------
  |  Branch (426:3): [True: 8.39k, False: 0]
  ------------------
  427|  8.39k|			Tlen = sizeof(T_sha1);
  428|  8.39k|			T = T_sha1;
  429|  8.39k|			hash_desc = &sha1_desc;
  430|  8.39k|			break;
  431|      0|#endif
  432|      0|#if DROPBEAR_RSA_SHA256
  433|      0|		case DROPBEAR_SIGNATURE_RSA_SHA256:
  ------------------
  |  Branch (433:3): [True: 0, False: 8.39k]
  ------------------
  434|      0|			Tlen = sizeof(T_sha256);
  435|      0|			T = T_sha256;
  436|      0|			hash_desc = &sha256_desc;
  437|      0|			break;
  438|      0|#endif
  439|      0|		default:
  ------------------
  |  Branch (439:3): [True: 0, False: 8.39k]
  ------------------
  440|      0|			assert(0);
  ------------------
  |  Branch (440:4): [Folded, False: 0]
  |  Branch (440:4): [Folded, False: 0]
  ------------------
  441|  8.39k|	}
  442|       |	
  443|       |
  444|  8.39k|	nsize = mp_ubin_size(key->n);
  445|       |
  446|  8.39k|	rsa_EM = buf_new(nsize);
  447|       |	/* type byte */
  448|  8.39k|	buf_putbyte(rsa_EM, 0x00);
  449|  8.39k|	buf_putbyte(rsa_EM, 0x01);
  450|       |	/* Padding with PS 0xFF bytes */
  451|  1.83M|	while(rsa_EM->pos != rsa_EM->size - (1 + Tlen + hash_desc->hashsize)) {
  ------------------
  |  Branch (451:8): [True: 1.83M, False: 8.39k]
  ------------------
  452|  1.83M|		buf_putbyte(rsa_EM, 0xff);
  453|  1.83M|	}
  454|  8.39k|	buf_putbyte(rsa_EM, 0x00);
  455|       |	/* Magic ASN1 stuff */
  456|  8.39k|	buf_putbytes(rsa_EM, T, Tlen);
  457|       |
  458|       |	/* The hash of the data */
  459|  8.39k|	hash_desc->init(&hs);
  460|  8.39k|	hash_desc->process(&hs, data_buf->data, data_buf->len);
  461|  8.39k|	hash_desc->done(&hs, buf_getwriteptr(rsa_EM, hash_desc->hashsize));
  462|  8.39k|	buf_incrwritepos(rsa_EM, hash_desc->hashsize);
  463|       |
  464|  8.39k|	dropbear_assert(rsa_EM->pos == rsa_EM->size);
  ------------------
  |  |   84|  8.39k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (84:37): [True: 0, False: 8.39k]
  |  |  |  Branch (84:93): [Folded, False: 8.39k]
  |  |  ------------------
  ------------------
  465|       |
  466|       |	/* Create the mp_int from the encoded bytes */
  467|  8.39k|	buf_setpos(rsa_EM, 0);
  468|  8.39k|	bytes_to_mp(rsa_em, buf_getptr(rsa_EM, rsa_EM->size),
  469|  8.39k|			rsa_EM->size);
  470|  8.39k|	buf_free(rsa_EM);
  471|  8.39k|}

new_sign_key:
   62|      1|sign_key * new_sign_key() {
   63|       |
   64|      1|	sign_key * ret;
   65|       |
   66|      1|	ret = (sign_key*)m_malloc(sizeof(sign_key));
   67|      1|	ret->type = DROPBEAR_SIGNKEY_NONE;
   68|      1|	ret->source = SIGNKEY_SOURCE_INVALID;
   69|      1|	return ret;
   70|      1|}
signkey_type_from_name:
   86|      4|enum signkey_type signkey_type_from_name(const char* name, unsigned int namelen) {
   87|      4|	int i;
   88|     13|	for (i = 0; i < DROPBEAR_SIGNKEY_NUM_NAMED; i++) {
  ------------------
  |  Branch (88:14): [True: 13, False: 0]
  ------------------
   89|     13|		const char *fixed_name = signkey_names[i];
   90|     13|		if (namelen == strlen(fixed_name)
  ------------------
  |  Branch (90:7): [True: 5, False: 8]
  ------------------
   91|      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|     13|	}
  114|       |
  115|      0|	TRACE(("signkey_type_from_name unexpected key type."))
  116|       |
  117|      0|	return DROPBEAR_SIGNKEY_NONE;
  118|      4|}
signature_name_from_type:
  122|  8.39k|const char* signature_name_from_type(enum signature_type type, unsigned int *namelen) {
  123|  8.39k|#if DROPBEAR_RSA
  124|  8.39k|#if DROPBEAR_RSA_SHA256
  125|  8.39k|	if (type == DROPBEAR_SIGNATURE_RSA_SHA256) {
  ------------------
  |  Branch (125:6): [True: 0, False: 8.39k]
  ------------------
  126|      0|		if (namelen) {
  ------------------
  |  Branch (126:7): [True: 0, False: 0]
  ------------------
  127|      0|			*namelen = strlen(SSH_SIGNATURE_RSA_SHA256);
  ------------------
  |  |  121|      0|#define SSH_SIGNATURE_RSA_SHA256 "rsa-sha2-256"
  ------------------
  128|      0|		}
  129|      0|		return SSH_SIGNATURE_RSA_SHA256;
  ------------------
  |  |  121|      0|#define SSH_SIGNATURE_RSA_SHA256 "rsa-sha2-256"
  ------------------
  130|      0|	}
  131|  8.39k|#endif
  132|  8.39k|#if DROPBEAR_RSA_SHA1
  133|  8.39k|	if (type == DROPBEAR_SIGNATURE_RSA_SHA1) {
  ------------------
  |  Branch (133:6): [True: 8.39k, False: 0]
  ------------------
  134|  8.39k|		if (namelen) {
  ------------------
  |  Branch (134:7): [True: 8.39k, False: 0]
  ------------------
  135|  8.39k|			*namelen = strlen(SSH_SIGNKEY_RSA);
  ------------------
  |  |  116|  8.39k|#define SSH_SIGNKEY_RSA "ssh-rsa"
  ------------------
  136|  8.39k|		}
  137|  8.39k|		return SSH_SIGNKEY_RSA;
  ------------------
  |  |  116|  8.39k|#define SSH_SIGNKEY_RSA "ssh-rsa"
  ------------------
  138|  8.39k|	}
  139|      0|#endif
  140|      0|#endif /* DROPBEAR_RSA */
  141|      0|	return signkey_name_from_type((enum signkey_type)type, namelen);
  142|  8.39k|}
signkey_type_from_signature:
  173|  17.7k|enum signkey_type signkey_type_from_signature(enum signature_type sigtype) {
  174|  17.7k|#if DROPBEAR_RSA
  175|  17.7k|#if DROPBEAR_RSA_SHA256
  176|  17.7k|	if (sigtype == DROPBEAR_SIGNATURE_RSA_SHA256) {
  ------------------
  |  Branch (176:6): [True: 1, False: 17.7k]
  ------------------
  177|      1|		return DROPBEAR_SIGNKEY_RSA;
  178|      1|	}
  179|  17.7k|#endif
  180|  17.7k|#if DROPBEAR_RSA_SHA1
  181|  17.7k|	if (sigtype == DROPBEAR_SIGNATURE_RSA_SHA1) {
  ------------------
  |  Branch (181:6): [True: 17.6k, False: 85]
  ------------------
  182|  17.6k|		return DROPBEAR_SIGNKEY_RSA;
  183|  17.6k|	}
  184|     85|#endif
  185|     85|#endif /* DROPBEAR_RSA */
  186|  17.7k|	assert((int)sigtype < (int)DROPBEAR_SIGNKEY_NUM_NAMED);
  ------------------
  |  Branch (186:2): [True: 0, False: 85]
  |  Branch (186:2): [True: 85, False: 0]
  ------------------
  187|     85|	return (enum signkey_type)sigtype;
  188|     85|}
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|}
buf_put_pub_key:
  419|  17.1k|void buf_put_pub_key(buffer* buf, sign_key *key, enum signkey_type type) {
  420|       |
  421|  17.1k|	buffer *pubkeys;
  422|       |
  423|  17.1k|	TRACE2(("enter buf_put_pub_key"))
  424|  17.1k|	pubkeys = buf_new(MAX_PUBKEY_SIZE);
  ------------------
  |  |  261|  17.1k|#define MAX_PUBKEY_SIZE 600
  ------------------
  425|       |	
  426|  17.1k|#if DROPBEAR_DSS
  427|  17.1k|	if (type == DROPBEAR_SIGNKEY_DSS) {
  ------------------
  |  Branch (427:6): [True: 0, False: 17.1k]
  ------------------
  428|      0|		buf_put_dss_pub_key(pubkeys, key->dsskey);
  429|      0|	}
  430|  17.1k|#endif
  431|  17.1k|#if DROPBEAR_RSA
  432|  17.1k|	if (type == DROPBEAR_SIGNKEY_RSA) {
  ------------------
  |  Branch (432:6): [True: 17.1k, False: 0]
  ------------------
  433|  17.1k|		buf_put_rsa_pub_key(pubkeys, key->rsakey);
  434|  17.1k|	}
  435|  17.1k|#endif
  436|  17.1k|#if DROPBEAR_ECDSA
  437|  17.1k|	if (signkey_is_ecdsa(type)
  ------------------
  |  Branch (437:6): [True: 0, False: 17.1k]
  ------------------
  438|  17.1k|#if DROPBEAR_SK_ECDSA
  439|  17.1k|		|| type == DROPBEAR_SIGNKEY_SK_ECDSA_NISTP256
  ------------------
  |  Branch (439:6): [True: 0, False: 17.1k]
  ------------------
  440|  17.1k|#endif
  441|  17.1k|		) {
  442|      0|		ecc_key **eck = (ecc_key**)signkey_key_ptr(key, type);
  443|      0|		if (eck && *eck) {
  ------------------
  |  Branch (443:7): [True: 0, False: 0]
  |  Branch (443:14): [True: 0, False: 0]
  ------------------
  444|      0|			buf_put_ecdsa_pub_key(pubkeys, *eck);
  445|      0|		}
  446|      0|	}
  447|  17.1k|#endif
  448|  17.1k|#if DROPBEAR_ED25519
  449|  17.1k|	if (type == DROPBEAR_SIGNKEY_ED25519
  ------------------
  |  Branch (449:6): [True: 0, False: 17.1k]
  ------------------
  450|  17.1k|#if DROPBEAR_SK_ED25519
  451|  17.1k|		|| type == DROPBEAR_SIGNKEY_SK_ED25519
  ------------------
  |  Branch (451:6): [True: 0, False: 17.1k]
  ------------------
  452|  17.1k|#endif
  453|  17.1k|	) {
  454|      0|		buf_put_ed25519_pub_key(pubkeys, key->ed25519key);
  455|      0|	}
  456|  17.1k|#endif
  457|  17.1k|	if (pubkeys->len == 0) {
  ------------------
  |  Branch (457:6): [True: 0, False: 17.1k]
  ------------------
  458|      0|		dropbear_exit("Bad key types in buf_put_pub_key");
  459|      0|	}
  460|       |
  461|  17.1k|	buf_putbufstring(buf, pubkeys);
  462|  17.1k|	buf_free(pubkeys);
  463|  17.1k|	TRACE2(("leave buf_put_pub_key"))
  464|  17.1k|}
buf_put_sign:
  596|  8.39k|	const buffer *data_buf) {
  597|  8.39k|	buffer *sigblob = buf_new(MAX_PUBKEY_SIZE);
  ------------------
  |  |  261|  8.39k|#define MAX_PUBKEY_SIZE 600
  ------------------
  598|  8.39k|	enum signkey_type keytype = signkey_type_from_signature(sigtype);
  599|       |
  600|       |#if DEBUG_TRACE > DROPBEAR_VERBOSE_LEVEL
  601|       |	{
  602|       |		const char* signame = signature_name_from_type(sigtype, NULL);
  603|       |		TRACE(("buf_put_sign type %d %s", sigtype, signame));
  604|       |	}
  605|       |#endif
  606|       |
  607|       |
  608|  8.39k|#if DROPBEAR_DSS
  609|  8.39k|	if (keytype == DROPBEAR_SIGNKEY_DSS) {
  ------------------
  |  Branch (609:6): [True: 0, False: 8.39k]
  ------------------
  610|      0|		buf_put_dss_sign(sigblob, key->dsskey, data_buf);
  611|      0|	}
  612|  8.39k|#endif
  613|  8.39k|#if DROPBEAR_RSA
  614|  8.39k|	if (keytype == DROPBEAR_SIGNKEY_RSA) {
  ------------------
  |  Branch (614:6): [True: 8.39k, False: 0]
  ------------------
  615|  8.39k|		buf_put_rsa_sign(sigblob, key->rsakey, sigtype, data_buf);
  616|  8.39k|	}
  617|  8.39k|#endif
  618|  8.39k|#if DROPBEAR_ECDSA
  619|  8.39k|	if (signkey_is_ecdsa(keytype)) {
  ------------------
  |  Branch (619:6): [True: 0, False: 8.39k]
  ------------------
  620|      0|		ecc_key **eck = (ecc_key**)signkey_key_ptr(key, keytype);
  621|      0|		if (eck && *eck) {
  ------------------
  |  Branch (621:7): [True: 0, False: 0]
  |  Branch (621:14): [True: 0, False: 0]
  ------------------
  622|      0|			buf_put_ecdsa_sign(sigblob, *eck, data_buf);
  623|      0|		}
  624|      0|	}
  625|  8.39k|#endif
  626|  8.39k|#if DROPBEAR_ED25519
  627|  8.39k|	if (keytype == DROPBEAR_SIGNKEY_ED25519) {
  ------------------
  |  Branch (627:6): [True: 0, False: 8.39k]
  ------------------
  628|      0|		buf_put_ed25519_sign(sigblob, key->ed25519key, data_buf);
  629|      0|	}
  630|  8.39k|#endif
  631|  8.39k|	if (sigblob->len == 0) {
  ------------------
  |  Branch (631:6): [True: 0, False: 8.39k]
  ------------------
  632|      0|		dropbear_exit("Non-matching signing type");
  633|      0|	}
  634|  8.39k|	buf_putbufstring(buf, sigblob);
  635|  8.39k|	buf_free(sigblob);
  636|       |
  637|  8.39k|}

svr_authinitialise:
   42|  3.35k|void svr_authinitialise() {
   43|  3.35k|	memset(&ses.authstate, 0, sizeof(ses.authstate));
   44|  3.35k|#if DROPBEAR_SVR_PUBKEY_AUTH
   45|  3.35k|	ses.authstate.authtypes |= AUTH_TYPE_PUBKEY;
  ------------------
  |  |  103|  3.35k|#define AUTH_TYPE_PUBKEY    (1 << 1)
  ------------------
   46|  3.35k|#endif
   47|  3.35k|#if DROPBEAR_SVR_PASSWORD_AUTH || DROPBEAR_SVR_PAM_AUTH
   48|  3.35k|	if (!svr_opts.noauthpass) {
  ------------------
  |  Branch (48:6): [True: 3.35k, False: 0]
  ------------------
   49|  3.35k|		ses.authstate.authtypes |= AUTH_TYPE_PASSWORD;
  ------------------
  |  |  104|  3.35k|#define AUTH_TYPE_PASSWORD  (1 << 2)
  ------------------
   50|  3.35k|	}
   51|  3.35k|#endif
   52|  3.35k|}
recv_msg_userauth_request:
   73|    645|void recv_msg_userauth_request() {
   74|       |
   75|    645|	char *username = NULL, *servicename = NULL, *methodname = NULL;
   76|    645|	unsigned int userlen, servicelen, methodlen;
   77|    645|	int valid_user = 0;
   78|       |
   79|    645|	TRACE(("enter recv_msg_userauth_request"))
   80|       |
   81|       |	/* for compensating failure delay */
   82|    645|	gettime_wrapper(&ses.authstate.auth_starttime);
   83|       |
   84|       |	/* ignore packets if auth is already done */
   85|    645|	if (ses.authstate.authdone == 1) {
  ------------------
  |  Branch (85:6): [True: 0, False: 645]
  ------------------
   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|    645|	if (svr_opts.banner) {
  ------------------
  |  Branch (91:6): [True: 0, False: 645]
  ------------------
   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|    645|	username = buf_getstring(ses.payload, &userlen);
   98|    645|	servicename = buf_getstring(ses.payload, &servicelen);
   99|    645|	methodname = buf_getstring(ses.payload, &methodlen);
  100|       |
  101|       |	/* only handle 'ssh-connection' currently */
  102|    645|	if (!(servicelen == SSH_SERVICE_CONNECTION_LEN
  ------------------
  |  |  111|  1.29k|#define SSH_SERVICE_CONNECTION_LEN 14
  ------------------
  |  Branch (102:8): [True: 616, False: 29]
  ------------------
  103|    616|			&& (strncmp(servicename, SSH_SERVICE_CONNECTION,
  ------------------
  |  |  110|    616|#define SSH_SERVICE_CONNECTION "ssh-connection"
  ------------------
  |  Branch (103:7): [True: 485, False: 131]
  ------------------
  104|    616|					SSH_SERVICE_CONNECTION_LEN) == 0))) {
  ------------------
  |  |  111|    616|#define SSH_SERVICE_CONNECTION_LEN 14
  ------------------
  105|    140|		m_free(username);
  ------------------
  |  |   24|    140|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 140]
  |  |  ------------------
  ------------------
  106|    140|		m_free(servicename);
  ------------------
  |  |   24|    140|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 140]
  |  |  ------------------
  ------------------
  107|    140|		m_free(methodname);
  ------------------
  |  |   24|    140|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 140]
  |  |  ------------------
  ------------------
  108|    140|		dropbear_exit("unknown service in auth");
  109|    140|	}
  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|    505|	if (checkusername(username, userlen) == DROPBEAR_SUCCESS) {
  ------------------
  |  |  111|    505|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (115:6): [True: 2, False: 503]
  ------------------
  116|      2|		valid_user = 1;
  117|      2|	}
  118|       |
  119|       |	/* user wants to know what methods are supported */
  120|    505|	if (methodlen == AUTH_METHOD_NONE_LEN &&
  ------------------
  |  |  108|  1.01k|#define AUTH_METHOD_NONE_LEN 4
  ------------------
  |  Branch (120:6): [True: 80, False: 425]
  ------------------
  121|     80|			strncmp(methodname, AUTH_METHOD_NONE,
  ------------------
  |  |  107|     80|#define AUTH_METHOD_NONE "none"
  ------------------
  |  Branch (121:4): [True: 11, False: 69]
  ------------------
  122|     80|				AUTH_METHOD_NONE_LEN) == 0) {
  ------------------
  |  |  108|     80|#define AUTH_METHOD_NONE_LEN 4
  ------------------
  123|     11|		TRACE(("recv_msg_userauth_request: 'none' request"))
  124|     11|		if (valid_user
  ------------------
  |  Branch (124:7): [True: 0, False: 11]
  ------------------
  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|     11|		else
  138|     11|		{
  139|       |			/* 'none' has no failure delay */
  140|     11|			send_msg_userauth_failure(0, 0);
  141|     11|			goto out;
  142|     11|		}
  143|     11|	}
  144|       |	
  145|    494|#if DROPBEAR_SVR_PASSWORD_AUTH
  146|    494|	if (!svr_opts.noauthpass &&
  ------------------
  |  Branch (146:6): [True: 437, False: 57]
  ------------------
  147|    437|			!(svr_opts.norootpass && ses.authstate.pw_uid == 0) ) {
  ------------------
  |  Branch (147:6): [True: 0, False: 437]
  |  Branch (147:29): [True: 0, False: 0]
  ------------------
  148|       |		/* user wants to try password auth */
  149|    437|		if (methodlen == AUTH_METHOD_PASSWORD_LEN &&
  ------------------
  |  |  112|    874|#define AUTH_METHOD_PASSWORD_LEN 8
  ------------------
  |  Branch (149:7): [True: 184, False: 253]
  ------------------
  150|    184|				strncmp(methodname, AUTH_METHOD_PASSWORD,
  ------------------
  |  |  111|    184|#define AUTH_METHOD_PASSWORD "password"
  ------------------
  |  Branch (150:5): [True: 42, False: 142]
  ------------------
  151|    184|					AUTH_METHOD_PASSWORD_LEN) == 0) {
  ------------------
  |  |  112|    184|#define AUTH_METHOD_PASSWORD_LEN 8
  ------------------
  152|     42|			svr_auth_password(valid_user);
  153|     42|			goto out;
  154|     42|		}
  155|    437|	}
  156|    452|#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|    452|#if DROPBEAR_SVR_PUBKEY_AUTH
  172|       |	/* user wants to try pubkey auth */
  173|    452|	if (methodlen == AUTH_METHOD_PUBKEY_LEN &&
  ------------------
  |  |  110|    904|#define AUTH_METHOD_PUBKEY_LEN 9
  ------------------
  |  Branch (173:6): [True: 143, False: 309]
  ------------------
  174|    143|			strncmp(methodname, AUTH_METHOD_PUBKEY,
  ------------------
  |  |  109|    143|#define AUTH_METHOD_PUBKEY "publickey"
  ------------------
  |  Branch (174:4): [True: 61, False: 82]
  ------------------
  175|    143|				AUTH_METHOD_PUBKEY_LEN) == 0) {
  ------------------
  |  |  110|    143|#define AUTH_METHOD_PUBKEY_LEN 9
  ------------------
  176|     61|		svr_auth_pubkey(valid_user);
  177|     61|		goto out;
  178|     61|	}
  179|    391|#endif
  180|       |
  181|       |	/* nothing matched, we just fail with a delay */
  182|    391|	send_msg_userauth_failure(0, 1);
  183|       |
  184|    427|out:
  185|       |
  186|    427|	m_free(username);
  ------------------
  |  |   24|    427|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 427]
  |  |  ------------------
  ------------------
  187|    427|	m_free(servicename);
  ------------------
  |  |   24|    427|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 427]
  |  |  ------------------
  ------------------
  188|       |	m_free(methodname);
  ------------------
  |  |   24|    427|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 427]
  |  |  ------------------
  ------------------
  189|    427|}
send_msg_userauth_failure:
  348|    428|void send_msg_userauth_failure(int partial, int incrfail) {
  349|       |
  350|    428|	buffer *typebuf = NULL;
  351|       |
  352|    428|	TRACE(("enter send_msg_userauth_failure"))
  353|       |
  354|    428|	CHECKCLEARTOWRITE();
  355|       |	
  356|    428|	buf_putbyte(ses.writepayload, SSH_MSG_USERAUTH_FAILURE);
  ------------------
  |  |   43|    428|#define SSH_MSG_USERAUTH_FAILURE            51
  ------------------
  357|       |
  358|       |	/* put a list of allowed types */
  359|    428|	typebuf = buf_new(30); /* long enough for PUBKEY and PASSWORD */
  360|       |
  361|    428|	if (ses.authstate.authtypes & AUTH_TYPE_PUBKEY) {
  ------------------
  |  |  103|    428|#define AUTH_TYPE_PUBKEY    (1 << 1)
  ------------------
  |  Branch (361:6): [True: 428, False: 0]
  ------------------
  362|    428|		buf_putbytes(typebuf, (const unsigned char *)AUTH_METHOD_PUBKEY, AUTH_METHOD_PUBKEY_LEN);
  ------------------
  |  |  109|    428|#define AUTH_METHOD_PUBKEY "publickey"
  ------------------
              		buf_putbytes(typebuf, (const unsigned char *)AUTH_METHOD_PUBKEY, AUTH_METHOD_PUBKEY_LEN);
  ------------------
  |  |  110|    428|#define AUTH_METHOD_PUBKEY_LEN 9
  ------------------
  363|    428|		if (ses.authstate.authtypes & AUTH_TYPE_PASSWORD) {
  ------------------
  |  |  104|    428|#define AUTH_TYPE_PASSWORD  (1 << 2)
  ------------------
  |  Branch (363:7): [True: 428, False: 0]
  ------------------
  364|    428|			buf_putbyte(typebuf, ',');
  365|    428|		}
  366|    428|	}
  367|       |	
  368|    428|	if (ses.authstate.authtypes & AUTH_TYPE_PASSWORD) {
  ------------------
  |  |  104|    428|#define AUTH_TYPE_PASSWORD  (1 << 2)
  ------------------
  |  Branch (368:6): [True: 428, False: 0]
  ------------------
  369|    428|		buf_putbytes(typebuf, (const unsigned char *)AUTH_METHOD_PASSWORD, AUTH_METHOD_PASSWORD_LEN);
  ------------------
  |  |  111|    428|#define AUTH_METHOD_PASSWORD "password"
  ------------------
              		buf_putbytes(typebuf, (const unsigned char *)AUTH_METHOD_PASSWORD, AUTH_METHOD_PASSWORD_LEN);
  ------------------
  |  |  112|    428|#define AUTH_METHOD_PASSWORD_LEN 8
  ------------------
  370|    428|	}
  371|       |
  372|    428|	buf_putbufstring(ses.writepayload, typebuf);
  373|       |
  374|    428|	TRACE(("auth fail: methods %d, '%.*s'", ses.authstate.authtypes,
  375|    428|				typebuf->len, typebuf->data))
  376|       |
  377|    428|	buf_free(typebuf);
  378|       |
  379|    428|	buf_putbyte(ses.writepayload, partial ? 1 : 0);
  ------------------
  |  Branch (379:32): [True: 0, False: 428]
  ------------------
  380|    428|	encrypt_packet();
  381|       |
  382|    428|	if (incrfail) {
  ------------------
  |  Branch (382:6): [True: 374, False: 54]
  ------------------
  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|    374|		const uint32_t mindelay = 250000000;
  391|    374|		const uint32_t vardelay = 100000000;
  392|    374|		uint32_t rand_delay;
  393|    374|		struct timespec delay;
  394|       |
  395|    374|		gettime_wrapper(&delay);
  396|    374|		delay.tv_sec -= ses.authstate.auth_starttime.tv_sec;
  397|    374|		delay.tv_nsec -= ses.authstate.auth_starttime.tv_nsec;
  398|       |
  399|       |		/* carry */
  400|    374|		if (delay.tv_nsec < 0) {
  ------------------
  |  Branch (400:7): [True: 0, False: 374]
  ------------------
  401|      0|			delay.tv_nsec += 1000000000;
  402|      0|			delay.tv_sec -= 1;
  403|      0|		}
  404|       |
  405|    374|		genrandom((unsigned char*)&rand_delay, sizeof(rand_delay));
  406|    374|		rand_delay = mindelay + (rand_delay % vardelay);
  407|       |
  408|    374|		if (delay.tv_sec == 0 && delay.tv_nsec <= rand_delay) {
  ------------------
  |  Branch (408:7): [True: 374, False: 0]
  |  Branch (408:28): [True: 374, False: 0]
  ------------------
  409|       |			/* Compensate for elapsed time */
  410|    374|			delay.tv_nsec = rand_delay - delay.tv_nsec;
  411|    374|		} 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|    374|#if DROPBEAR_FUZZ
  419|    374|		if (!fuzz.fuzzing)
  ------------------
  |  Branch (419:7): [True: 0, False: 374]
  ------------------
  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|    374|		ses.authstate.failcount++;
  426|    374|	}
  427|       |
  428|    428|	if (ses.authstate.failcount > svr_opts.maxauthtries) {
  ------------------
  |  Branch (428:6): [True: 1, False: 427]
  ------------------
  429|      1|		char * userstr;
  430|       |		/* XXX - send disconnect ? */
  431|      1|		TRACE(("Max auth tries reached, exiting"))
  432|       |
  433|      1|		if (ses.authstate.pw_name == NULL) {
  ------------------
  |  Branch (433:7): [True: 1, False: 0]
  ------------------
  434|      1|			userstr = "is invalid";
  435|      1|		} else {
  436|      0|			userstr = ses.authstate.pw_name;
  437|      0|		}
  438|      1|		dropbear_exit("Max auth tries reached - user '%s'",
  439|      1|				userstr);
  440|      1|	}
  441|       |	
  442|    428|	TRACE(("leave send_msg_userauth_failure"))
  443|    428|}
svr-auth.c:checkusername:
  229|    485|static int checkusername(const char *username, unsigned int userlen) {
  230|       |
  231|    485|	char* listshell = NULL;
  232|    485|	char* usershell = NULL;
  233|    485|	uid_t uid;
  234|       |
  235|    485|	TRACE(("enter checkusername"))
  236|    485|	if (userlen > MAX_USERNAME_LEN) {
  ------------------
  |  |  100|    485|#define MAX_USERNAME_LEN 100 /* arbitrary for the moment */
  ------------------
  |  Branch (236:6): [True: 0, False: 485]
  ------------------
  237|      0|		return DROPBEAR_FAILURE;
  ------------------
  |  |  112|      0|#define DROPBEAR_FAILURE -1
  ------------------
  238|      0|	}
  239|       |
  240|    485|	if (strlen(username) != userlen) {
  ------------------
  |  Branch (240:6): [True: 5, False: 480]
  ------------------
  241|      5|		dropbear_exit("Attempted username with a null byte");
  242|      5|	}
  243|       |
  244|    480|	if (ses.authstate.username == NULL) {
  ------------------
  |  Branch (244:6): [True: 271, False: 209]
  ------------------
  245|       |		/* first request */
  246|    271|		fill_passwd(username);
  247|    271|		ses.authstate.username = m_strdup(username);
  248|    271|	} else {
  249|       |		/* check username hasn't changed */
  250|    209|		if (strcmp(username, ses.authstate.username) != 0) {
  ------------------
  |  Branch (250:7): [True: 32, False: 177]
  ------------------
  251|     32|			dropbear_exit("Client trying multiple usernames");
  252|     32|		}
  253|    209|	}
  254|       |
  255|       |	/* avoids cluttering logs with repeated failure messages from
  256|       |	consecutive authentication requests in a sesssion */
  257|    448|	if (ses.authstate.checkusername_failed) {
  ------------------
  |  Branch (257:6): [True: 177, False: 271]
  ------------------
  258|    177|		TRACE(("checkusername: returning cached failure"))
  259|    177|		return DROPBEAR_FAILURE;
  ------------------
  |  |  112|    177|#define DROPBEAR_FAILURE -1
  ------------------
  260|    177|	}
  261|       |
  262|       |	/* check that user exists */
  263|    271|	if (!ses.authstate.pw_name) {
  ------------------
  |  Branch (263:6): [True: 269, False: 2]
  ------------------
  264|    269|		TRACE(("leave checkusername: user '%s' doesn't exist", username))
  265|    269|		dropbear_log(LOG_WARNING,
  266|    269|				"Login attempt for nonexistent user from %s",
  267|    269|				svr_ses.addrstring);
  268|    269|		ses.authstate.checkusername_failed = 1;
  269|    269|		return DROPBEAR_FAILURE;
  ------------------
  |  |  112|    269|#define DROPBEAR_FAILURE -1
  ------------------
  270|    269|	}
  271|       |
  272|       |	/* check if we are running as non-root, and login user is different from the server */
  273|      2|	uid = geteuid();
  274|      2|	if (!(DROPBEAR_SVR_MULTIUSER && uid == 0) && uid != ses.authstate.pw_uid) {
  ------------------
  |  |  393|      4|#define DROPBEAR_SVR_MULTIUSER 1
  |  |  ------------------
  |  |  |  Branch (393:32): [True: 2, Folded]
  |  |  ------------------
  ------------------
  |  Branch (274:34): [True: 2, 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|      2|	if (svr_opts.norootlogin && ses.authstate.pw_uid == 0) {
  ------------------
  |  Branch (285:6): [True: 0, False: 2]
  |  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|      2|#ifdef HAVE_GETGROUPLIST
  294|      2|	if (svr_opts.restrict_group) {
  ------------------
  |  Branch (294:6): [True: 0, False: 2]
  ------------------
  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|      2|#endif /* HAVE_GETGROUPLIST */
  305|       |
  306|      2|	TRACE(("shell is %s", ses.authstate.pw_shell))
  307|       |
  308|       |	/* check that the shell is set */
  309|      2|	usershell = ses.authstate.pw_shell;
  310|      2|	if (usershell[0] == '\0') {
  ------------------
  |  Branch (310:6): [True: 0, False: 2]
  ------------------
  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|      2|	setusershell();
  319|      2|	while ((listshell = getusershell()) != NULL) {
  ------------------
  |  Branch (319:9): [True: 2, False: 0]
  ------------------
  320|      2|		TRACE(("test shell is '%s'", listshell))
  321|      2|		if (strcmp(listshell, usershell) == 0) {
  ------------------
  |  Branch (321:7): [True: 2, False: 0]
  ------------------
  322|       |			/* have a match */
  323|      2|			goto goodshell;
  324|      2|		}
  325|      2|	}
  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|      2|goodshell:
  335|      2|	endusershell();
  336|      2|	TRACE(("matching shell"))
  337|       |
  338|      2|	TRACE(("uid = %d", ses.authstate.pw_uid))
  339|      2|	TRACE(("leave checkusername"))
  340|      2|	return DROPBEAR_SUCCESS;
  ------------------
  |  |  111|      2|#define DROPBEAR_SUCCESS 0
  ------------------
  341|      2|}

svr_auth_password:
   51|     42|void svr_auth_password(int valid_user) {
   52|       |	
   53|     42|	char * passwdcrypt = NULL; /* the crypt from /etc/passwd or /etc/shadow */
   54|     42|	char * testcrypt = NULL; /* crypt generated from the user's password sent */
   55|     42|	char * password = NULL;
   56|     42|	unsigned int passwordlen;
   57|     42|	unsigned int changepw;
   58|       |
   59|       |	/* check if client wants to change password */
   60|     42|	changepw = buf_getbool(ses.payload);
   61|     42|	if (changepw) {
  ------------------
  |  Branch (61:6): [True: 21, False: 21]
  ------------------
   62|       |		/* not implemented by this server */
   63|     21|		send_msg_userauth_failure(0, 1);
   64|     21|		return;
   65|     21|	}
   66|       |
   67|     21|	password = buf_getstring(ses.payload, &passwordlen);
   68|     21|	if (valid_user && passwordlen <= DROPBEAR_MAX_PASSWORD_LEN) {
  ------------------
  |  |  131|      0|#define DROPBEAR_MAX_PASSWORD_LEN 100
  ------------------
  |  Branch (68:6): [True: 0, False: 21]
  |  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|     21|	m_burn(password, passwordlen);
   74|     21|	m_free(password);
  ------------------
  |  |   24|     21|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 21]
  |  |  ------------------
  ------------------
   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|     21|	if (!valid_user) {
  ------------------
  |  Branch (78:6): [True: 19, False: 2]
  ------------------
   79|     19|		send_msg_userauth_failure(0, 1);
   80|     19|		return;
   81|     19|	}
   82|       |
   83|      2|	if (passwordlen > DROPBEAR_MAX_PASSWORD_LEN) {
  ------------------
  |  |  131|      2|#define DROPBEAR_MAX_PASSWORD_LEN 100
  ------------------
  |  Branch (83:6): [True: 0, False: 2]
  ------------------
   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|      2|	if (testcrypt == NULL) {
  ------------------
  |  Branch (92:6): [True: 0, False: 2]
  ------------------
   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|      2|	if (passwdcrypt[0] == '\0') {
  ------------------
  |  Branch (101:6): [True: 0, False: 2]
  ------------------
  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|      2|	if (constant_time_strcmp(testcrypt, passwdcrypt) == 0) {
  ------------------
  |  Branch (108:6): [True: 0, False: 2]
  ------------------
  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|      2|	} else {
  126|       |		dropbear_log(LOG_WARNING,
  127|      2|				"Bad password attempt for '%s' from %s",
  128|      2|				ses.authstate.pw_name,
  129|      2|				svr_ses.addrstring);
  130|      2|		send_msg_userauth_failure(0, 1);
  131|      2|	}
  132|      2|}

svr_auth_pubkey:
   85|     61|void svr_auth_pubkey(int valid_user) {
   86|       |
   87|     61|	unsigned char testkey; /* whether we're just checking if a key is usable */
   88|     61|	char* sigalgo = NULL;
   89|     61|	unsigned int sigalgolen;
   90|     61|	const char* keyalgo;
   91|     61|	unsigned int keyalgolen;
   92|     61|	unsigned char* keyblob = NULL;
   93|     61|	unsigned int keybloblen;
   94|     61|	unsigned int sign_payload_length;
   95|     61|	buffer * signbuf = NULL;
   96|     61|	sign_key * key = NULL;
   97|     61|	char* fp = NULL;
   98|     61|	enum signature_type sigtype;
   99|     61|	enum signkey_type keytype;
  100|     61|	int auth_failure = 1;
  101|     61|	struct PubKeyOptions *pubkey_options = NULL;
  102|       |
  103|     61|	TRACE(("enter pubkeyauth"))
  104|       |
  105|       |	/* 0 indicates user just wants to check if key can be used, 1 is an
  106|       |	 * actual attempt*/
  107|     61|	testkey = (buf_getbool(ses.payload) == 0);
  108|       |
  109|     61|	sigalgo = buf_getstring(ses.payload, &sigalgolen);
  110|     61|	keybloblen = buf_getint(ses.payload);
  111|     61|	keyblob = buf_getptr(ses.payload, keybloblen);
  112|       |
  113|     61|	if (!valid_user) {
  ------------------
  |  Branch (113:6): [True: 43, False: 18]
  ------------------
  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|     43|		send_msg_userauth_failure(0, 0);
  119|     43|		goto out;
  120|     43|	}
  121|       |
  122|     18|	sigtype = signature_type_from_name(sigalgo, sigalgolen);
  123|     18|	if (sigtype == DROPBEAR_SIGNATURE_NONE) {
  ------------------
  |  Branch (123:6): [True: 0, False: 18]
  ------------------
  124|      0|		send_msg_userauth_failure(0, 0);
  125|      0|		goto out;
  126|      0|	}
  127|       |
  128|     18|	keytype = signkey_type_from_signature(sigtype);
  129|     18|	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|     18|	if (auth_failure) {
  ------------------
  |  Branch (165:6): [True: 0, False: 18]
  ------------------
  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|     18|	if (auth_failure) {
  ------------------
  |  Branch (170:6): [True: 0, False: 18]
  ------------------
  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|     18|	if (testkey) {
  ------------------
  |  Branch (185:6): [True: 0, False: 18]
  ------------------
  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|     18|	key = new_sign_key();
  194|     18|	if (buf_get_pub_key(ses.payload, key, &keytype) == DROPBEAR_FAILURE) {
  ------------------
  |  |  112|     18|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (194:6): [True: 0, False: 18]
  ------------------
  195|      0|		send_msg_userauth_failure(0, 1);
  196|      0|		goto out;
  197|      0|	}
  198|       |
  199|     18|#if DROPBEAR_SK_ECDSA || DROPBEAR_SK_ED25519
  200|     18|	key->sk_flags_mask = SSH_SK_USER_PRESENCE_REQD;
  ------------------
  |  |  135|     18|#define SSH_SK_USER_PRESENCE_REQD       0x01
  ------------------
  201|     18|#if DROPBEAR_SVR_PUBKEY_OPTIONS_BUILT
  202|     18|	if (pubkey_options->no_touch_required_flag) {
  ------------------
  |  Branch (202:6): [True: 0, False: 18]
  ------------------
  203|      0|		key->sk_flags_mask &= ~SSH_SK_USER_PRESENCE_REQD;
  ------------------
  |  |  135|      0|#define SSH_SK_USER_PRESENCE_REQD       0x01
  ------------------
  204|      0|	}
  205|     18|	if (pubkey_options->verify_required_flag) {
  ------------------
  |  Branch (205:6): [True: 0, False: 18]
  ------------------
  206|      0|		key->sk_flags_mask |= SSH_SK_USER_VERIFICATION_REQD;
  ------------------
  |  |  136|      0|#define SSH_SK_USER_VERIFICATION_REQD   0x04
  ------------------
  207|      0|	}
  208|     18|#endif /* DROPBEAR_SVR_PUBKEY_OPTIONS_BUILT */
  209|     18|#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|     18|	assert(ses.payload_beginning <= ses.payload->pos);
  ------------------
  |  Branch (213:2): [True: 0, False: 18]
  |  Branch (213:2): [True: 0, False: 18]
  ------------------
  214|     18|	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|     43|out:
  267|       |	/* cleanup stuff */
  268|     43|	if (signbuf) {
  ------------------
  |  Branch (268:6): [True: 0, False: 43]
  ------------------
  269|      0|		buf_free(signbuf);
  270|      0|	}
  271|     43|	if (sigalgo) {
  ------------------
  |  Branch (271:6): [True: 43, False: 0]
  ------------------
  272|     43|		m_free(sigalgo);
  ------------------
  |  |   24|     43|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 43]
  |  |  ------------------
  ------------------
  273|     43|	}
  274|     43|	if (key) {
  ------------------
  |  Branch (274:6): [True: 0, False: 43]
  ------------------
  275|      0|		sign_key_free(key);
  276|      0|		key = NULL;
  277|      0|	}
  278|     43|	if (pubkey_options) {
  ------------------
  |  Branch (278:6): [True: 0, False: 43]
  ------------------
  279|      0|		svr_pubkey_options_cleanup(pubkey_options);
  280|       |		pubkey_options = NULL;
  281|      0|	}
  282|     43|	TRACE(("leave pubkeyauth"))
  283|     43|}

svr_pubkey_options_cleanup:
  165|  3.35k|void svr_pubkey_options_cleanup(struct PubKeyOptions *pubkey_options) {
  166|  3.35k|	if (pubkey_options) {
  ------------------
  |  Branch (166:6): [True: 0, False: 3.35k]
  ------------------
  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|  3.35k|}

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

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

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.69k|void disable_sig_except(enum signature_type allow_type) {
  561|  1.69k|	int i;
  562|  1.69k|	TRACE(("Disabling other sigs except %d", allow_type));
  563|  16.9k|	for (i = 0; sigalgs[i].name != NULL; i++) {
  ------------------
  |  Branch (563:14): [True: 15.2k, False: 1.69k]
  ------------------
  564|  15.2k|		enum signature_type sig_type = sigalgs[i].val;
  565|  15.2k|		if (sig_type != allow_type) {
  ------------------
  |  Branch (565:7): [True: 13.5k, False: 1.69k]
  ------------------
  566|  13.5k|			sigalgs[i].usable = 0;
  567|  13.5k|		}
  568|  15.2k|	}
  569|  1.69k|}

recv_msg_service_request:
   37|    361|void recv_msg_service_request() {
   38|       |
   39|    361|	char * name;
   40|    361|	unsigned int len;
   41|       |
   42|    361|	TRACE(("enter recv_msg_service_request"))
   43|       |
   44|    361|	name = buf_getstring(ses.payload, &len);
   45|       |
   46|       |	/* ssh-userauth */
   47|    361|	if (len == SSH_SERVICE_USERAUTH_LEN && 
  ------------------
  |  |  109|    722|#define SSH_SERVICE_USERAUTH_LEN 12
  ------------------
  |  Branch (47:6): [True: 219, False: 142]
  ------------------
   48|    219|			strncmp(SSH_SERVICE_USERAUTH, name, len) == 0) {
  ------------------
  |  |  108|    219|#define SSH_SERVICE_USERAUTH "ssh-userauth"
  ------------------
  |  Branch (48:4): [True: 153, False: 66]
  ------------------
   49|       |
   50|    153|		send_msg_service_accept(name, len);
   51|    153|		m_free(name);
  ------------------
  |  |   24|    153|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 153]
  |  |  ------------------
  ------------------
   52|    153|		TRACE(("leave recv_msg_service_request: done ssh-userauth"))
   53|    153|		return;
   54|    153|	}
   55|       |
   56|       |	/* ssh-connection */
   57|    208|	if (len == SSH_SERVICE_CONNECTION_LEN &&
  ------------------
  |  |  111|    416|#define SSH_SERVICE_CONNECTION_LEN 14
  ------------------
  |  Branch (57:6): [True: 126, False: 82]
  ------------------
   58|    126|			(strncmp(SSH_SERVICE_CONNECTION, name, len) == 0)) {
  ------------------
  |  |  110|    126|#define SSH_SERVICE_CONNECTION "ssh-connection"
  ------------------
  |  Branch (58:4): [True: 1, False: 125]
  ------------------
   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|    207|	m_free(name);
  ------------------
  |  |   24|    207|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 207]
  |  |  ------------------
  ------------------
   70|       |	/* TODO this should be a MSG_DISCONNECT */
   71|    207|	dropbear_exit("Unrecognised SSH_MSG_SERVICE_REQUEST");
   72|       |
   73|       |
   74|    208|}
svr-service.c:send_msg_service_accept:
   76|    153|static void send_msg_service_accept(const char *name, int len) {
   77|       |
   78|    153|	TRACE(("accepting service %s", name))
   79|       |
   80|    153|	CHECKCLEARTOWRITE();
   81|       |
   82|    153|	buf_putbyte(ses.writepayload, SSH_MSG_SERVICE_ACCEPT);
  ------------------
  |  |   34|    153|#define SSH_MSG_SERVICE_ACCEPT         6
  ------------------
   83|    153|	buf_putstring(ses.writepayload, name, len);
   84|       |
   85|    153|	encrypt_packet();
   86|       |
   87|    153|}

svr_session:
  108|  3.35k|void svr_session(int sock, int childpipe) {
  109|  3.35k|	char *host, *port;
  110|  3.35k|	size_t len;
  111|       |
  112|  3.35k|	common_session_init(sock, sock);
  113|       |
  114|       |	/* Initialise server specific parts of the session */
  115|  3.35k|	svr_ses.childpipe = childpipe;
  116|       |#if DROPBEAR_VFORK
  117|       |	svr_ses.server_pid = getpid();
  118|       |#endif
  119|       |
  120|       |	/* for logging the remote address */
  121|  3.35k|	get_socket_address(ses.sock_in, NULL, NULL, &host, &port, 0);
  122|  3.35k|	len = strlen(host) + strlen(port) + 2;
  123|  3.35k|	svr_ses.addrstring = m_malloc(len);
  124|  3.35k|	snprintf(svr_ses.addrstring, len, "%s:%s", host, port);
  125|  3.35k|	m_free(host);
  ------------------
  |  |   24|  3.35k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 3.35k]
  |  |  ------------------
  ------------------
  126|  3.35k|	m_free(port);
  ------------------
  |  |   24|  3.35k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 3.35k]
  |  |  ------------------
  ------------------
  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|  3.35k|	svr_authinitialise();
  174|  3.35k|	chaninitialise(svr_chantypes);
  175|  3.35k|	svr_chansessinitialise();
  176|  3.35k|	svr_algos_initialise();
  177|       |
  178|  3.35k|	get_socket_address(ses.sock_in, NULL, NULL, 
  179|  3.35k|			&svr_ses.remotehost, NULL, 1);
  180|       |
  181|       |	/* set up messages etc */
  182|  3.35k|	ses.remoteclosed = svr_remoteclosed;
  183|  3.35k|	ses.extra_session_cleanup = svr_session_cleanup;
  184|       |
  185|       |	/* packet handlers */
  186|  3.35k|	ses.packettypes = svr_packettypes;
  187|       |
  188|  3.35k|	ses.isserver = 1;
  189|       |
  190|       |	/* We're ready to go now */
  191|  3.35k|	ses.init_done = 1;
  192|       |
  193|       |	/* exchange identification, version etc */
  194|  3.35k|	send_session_identification();
  195|       |	
  196|  3.35k|	kexfirstinitialise(); /* initialise the kex state */
  197|       |
  198|       |	/* start off with key exchange */
  199|  3.35k|	send_msg_kexinit();
  200|       |
  201|  3.35k|#if DROPBEAR_FUZZ
  202|  3.35k|    if (fuzz.fuzzing) {
  ------------------
  |  Branch (202:9): [True: 3.35k, False: 0]
  ------------------
  203|  3.35k|        fuzz_svr_hook_preloop();
  204|  3.35k|    }
  205|  3.35k|#endif
  206|       |
  207|       |	/* Run the main for-loop. */
  208|  3.35k|	session_loop(svr_chansess_checksignal);
  209|       |
  210|       |	/* Not reached */
  211|       |
  212|  3.35k|}
svr_dropbear_exit:
  215|  3.35k|void svr_dropbear_exit(int exitcode, const char* format, va_list param) {
  216|  3.35k|	char exitmsg[150];
  217|  3.35k|	char fullmsg[300];
  218|  3.35k|	char fromaddr[60];
  219|  3.35k|	int i;
  220|  3.35k|	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|  3.35k|	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|  3.35k|	fromaddr[0] = '\0';
  237|  3.35k|	if (svr_ses.addrstring) {
  ------------------
  |  Branch (237:6): [True: 3.35k, False: 0]
  ------------------
  238|  3.35k|	    snprintf(fromaddr, sizeof(fromaddr), " from <%s>", svr_ses.addrstring);
  239|  3.35k|    }
  240|       |
  241|       |	/* Add the prefix depending on session/auth state */
  242|  3.35k|	if (!ses.init_done) {
  ------------------
  |  Branch (242:6): [True: 0, False: 3.35k]
  ------------------
  243|       |		/* before session init */
  244|      0|		snprintf(fullmsg, sizeof(fullmsg), "Early exit%s: %s", fromaddr, exitmsg);
  245|  3.35k|	} else if (ses.authstate.authdone) {
  ------------------
  |  Branch (245:13): [True: 0, False: 3.35k]
  ------------------
  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|  3.35k|	} else if (ses.authstate.pw_name) {
  ------------------
  |  Branch (250:13): [True: 2, False: 3.35k]
  ------------------
  251|       |		/* we have a potential user */
  252|      2|		snprintf(fullmsg, sizeof(fullmsg), 
  253|      2|				"Exit before auth%s: (user '%s', %u fails): %s",
  254|      2|				fromaddr, ses.authstate.pw_name, ses.authstate.failcount, exitmsg);
  255|      2|		add_delay = 1;
  256|  3.35k|	} else {
  257|       |		/* before userauth */
  258|  3.35k|		snprintf(fullmsg, sizeof(fullmsg), "Exit before auth%s: %s", fromaddr, exitmsg);
  259|  3.35k|		add_delay = 1;
  260|  3.35k|	}
  261|       |
  262|  3.35k|	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|  3.35k|	if ((add_delay != 0) && (UNAUTH_CLOSE_DELAY > 0)) {
  ------------------
  |  |  499|  3.35k|#define UNAUTH_CLOSE_DELAY 0
  ------------------
  |  Branch (276:6): [True: 3.35k, False: 0]
  |  Branch (276:26): [Folded, False: 3.35k]
  ------------------
  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|  3.35k|	{
  288|       |		/* must be after we've done with username etc */
  289|  3.35k|		session_cleanup();
  290|  3.35k|	}
  291|       |
  292|  3.35k|#if DROPBEAR_FUZZ
  293|       |	/* longjmp before cleaning up svr_opts */
  294|  3.35k|    if (fuzz.do_jmp) {
  ------------------
  |  Branch (294:9): [True: 3.35k, False: 0]
  ------------------
  295|  3.35k|        longjmp(fuzz.jmp, 1);
  296|  3.35k|    }
  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|  3.35k|}
svr-session.c:svr_session_cleanup:
   86|  3.35k|svr_session_cleanup(void) {
   87|  3.35k|	svr_pubkey_options_cleanup(ses.authstate.pubkey_options);
   88|  3.35k|	ses.authstate.pubkey_options = NULL;
   89|       |
   90|  3.35k|	m_free(svr_ses.addrstring);
  ------------------
  |  |   24|  3.35k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 3.35k]
  |  |  ------------------
  ------------------
   91|  3.35k|	m_free(svr_ses.remotehost);
  ------------------
  |  |   24|  3.35k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 3.35k]
  |  |  ------------------
  ------------------
   92|  3.35k|	m_free(svr_ses.childpids);
  ------------------
  |  |   24|  3.35k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 3.35k]
  |  |  ------------------
  ------------------
   93|  3.35k|	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|  3.35k|}
svr-session.c:svr_remoteclosed:
  351|  1.31k|static void svr_remoteclosed() {
  352|       |
  353|  1.31k|	m_close(ses.sock_in);
  354|  1.31k|	if (ses.sock_in != ses.sock_out) {
  ------------------
  |  Branch (354:6): [True: 0, False: 1.31k]
  ------------------
  355|      0|		m_close(ses.sock_out);
  356|      0|	}
  357|  1.31k|	ses.sock_in = -1;
  358|  1.31k|	ses.sock_out = -1;
  359|  1.31k|	dropbear_close("Exited normally");
  360|       |
  361|  1.31k|}
svr-session.c:svr_algos_initialise:
  363|  3.35k|static void svr_algos_initialise(void) {
  364|  3.35k|	algo_type *algo;
  365|  46.9k|	for (algo = sshkex; algo->name; algo++) {
  ------------------
  |  Branch (365:22): [True: 43.6k, False: 3.35k]
  ------------------
  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|  43.6k|#if DROPBEAR_EXT_INFO
  372|  43.6k|		if (strcmp(algo->name, SSH_EXT_INFO_C) == 0) {
  ------------------
  |  |  100|  43.6k|#define SSH_EXT_INFO_C "ext-info-c"
  ------------------
  |  Branch (372:7): [True: 3.35k, False: 40.2k]
  ------------------
  373|  3.35k|			algo->usable = 0;
  374|  3.35k|		}
  375|  43.6k|#endif
  376|  43.6k|		if (strcmp(algo->name, SSH_STRICT_KEX_C) == 0) {
  ------------------
  |  |  105|  43.6k|#define SSH_STRICT_KEX_C "kex-strict-c-v00@openssh.com"
  ------------------
  |  Branch (376:7): [True: 3.35k, False: 40.2k]
  ------------------
  377|  3.35k|			algo->usable = 0;
  378|  3.35k|		}
  379|  43.6k|	}
  380|  3.35k|}

