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

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

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

sha1_init:
  164|  8.94k|{
  165|  8.94k|   LTC_ARGCHK(md != NULL);
  ------------------
  |  |   32|  8.94k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 8.94k]
  |  |  |  Branch (32:87): [Folded, False: 8.94k]
  |  |  ------------------
  ------------------
  166|  8.94k|   md->sha1.state[0] = 0x67452301UL;
  167|  8.94k|   md->sha1.state[1] = 0xefcdab89UL;
  168|  8.94k|   md->sha1.state[2] = 0x98badcfeUL;
  169|  8.94k|   md->sha1.state[3] = 0x10325476UL;
  170|  8.94k|   md->sha1.state[4] = 0xc3d2e1f0UL;
  171|  8.94k|   md->sha1.curlen = 0;
  172|  8.94k|   md->sha1.length = 0;
  173|  8.94k|   return CRYPT_OK;
  174|  8.94k|}
sha1_done:
  192|  8.94k|{
  193|  8.94k|    int i;
  194|       |
  195|  8.94k|    LTC_ARGCHK(md  != NULL);
  ------------------
  |  |   32|  8.94k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 8.94k]
  |  |  |  Branch (32:87): [Folded, False: 8.94k]
  |  |  ------------------
  ------------------
  196|  8.94k|    LTC_ARGCHK(out != NULL);
  ------------------
  |  |   32|  8.94k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 8.94k]
  |  |  |  Branch (32:87): [Folded, False: 8.94k]
  |  |  ------------------
  ------------------
  197|       |
  198|  8.94k|    if (md->sha1.curlen >= sizeof(md->sha1.buf)) {
  ------------------
  |  Branch (198:9): [True: 0, False: 8.94k]
  ------------------
  199|      0|       return CRYPT_INVALID_ARG;
  200|      0|    }
  201|       |
  202|       |    /* increase the length of the message */
  203|  8.94k|    md->sha1.length += md->sha1.curlen * 8;
  204|       |
  205|       |    /* append the '1' bit */
  206|  8.94k|    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.94k|    if (md->sha1.curlen > 56) {
  ------------------
  |  Branch (212:9): [True: 0, False: 8.94k]
  ------------------
  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|   214k|    while (md->sha1.curlen < 56) {
  ------------------
  |  Branch (221:12): [True: 205k, False: 8.94k]
  ------------------
  222|   205k|        md->sha1.buf[md->sha1.curlen++] = (unsigned char)0;
  223|   205k|    }
  224|       |
  225|       |    /* store length */
  226|  8.94k|    STORE64H(md->sha1.length, md->sha1.buf+56);
  ------------------
  |  |  101|  8.94k|#define STORE64H(x, y)                          \
  |  |  102|  8.94k|do { ulong64 __t = __builtin_bswap64 ((x));     \
  |  |  103|  8.94k|      XMEMCPY ((y), &__t, 8); } while(0)
  |  |  ------------------
  |  |  |  |   39|  8.94k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (103:39): [Folded, False: 8.94k]
  |  |  ------------------
  ------------------
  227|  8.94k|    sha1_compress(md, md->sha1.buf);
  228|       |
  229|       |    /* copy output */
  230|  53.6k|    for (i = 0; i < 5; i++) {
  ------------------
  |  Branch (230:17): [True: 44.7k, False: 8.94k]
  ------------------
  231|  44.7k|        STORE32H(md->sha1.state[i], out+(4*i));
  ------------------
  |  |   62|  44.7k|#define STORE32H(x, y)                          \
  |  |   63|  44.7k|do { ulong32 __t = __builtin_bswap32 ((x));     \
  |  |   64|  44.7k|      XMEMCPY ((y), &__t, 4); } while(0)
  |  |  ------------------
  |  |  |  |   39|  44.7k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (64:39): [Folded, False: 44.7k]
  |  |  ------------------
  ------------------
  232|  44.7k|    }
  233|       |#ifdef LTC_CLEAN_STACK
  234|       |    zeromem(md, sizeof(hash_state));
  235|       |#endif
  236|  8.94k|    return CRYPT_OK;
  237|  8.94k|}
sha1.c:sha1_compress:
   47|  8.94k|{
   48|  8.94k|    ulong32 a,b,c,d,e,W[80],i;
   49|  8.94k|#ifdef LTC_SMALL_CODE
   50|  8.94k|    ulong32 t;
   51|  8.94k|#endif
   52|       |
   53|       |    /* copy the state into 512-bits into W[0..15] */
   54|   152k|    for (i = 0; i < 16; i++) {
  ------------------
  |  Branch (54:17): [True: 143k, False: 8.94k]
  ------------------
   55|   143k|        LOAD32H(W[i], buf + (4*i));
  ------------------
  |  |   66|   143k|#define LOAD32H(x, y)                           \
  |  |   67|   143k|do { XMEMCPY (&(x), (y), 4);                    \
  |  |  ------------------
  |  |  |  |   39|   143k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |   68|   143k|      (x) = __builtin_bswap32 ((x)); } while(0)
  |  |  ------------------
  |  |  |  Branch (68:46): [Folded, False: 143k]
  |  |  ------------------
  ------------------
   56|   143k|    }
   57|       |
   58|       |    /* copy state */
   59|  8.94k|    a = md->sha1.state[0];
   60|  8.94k|    b = md->sha1.state[1];
   61|  8.94k|    c = md->sha1.state[2];
   62|  8.94k|    d = md->sha1.state[3];
   63|  8.94k|    e = md->sha1.state[4];
   64|       |
   65|       |    /* expand it */
   66|   581k|    for (i = 16; i < 80; i++) {
  ------------------
  |  Branch (66:18): [True: 572k, False: 8.94k]
  ------------------
   67|   572k|        W[i] = ROL(W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16], 1);
   68|   572k|    }
   69|       |
   70|       |    /* compress */
   71|       |    /* round one */
   72|  8.94k|    #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.94k|    #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.94k|    #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.94k|    #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.94k|#ifdef LTC_SMALL_CODE
   78|       |
   79|   187k|    for (i = 0; i < 20; ) {
  ------------------
  |  Branch (79:17): [True: 178k, False: 8.94k]
  ------------------
   80|   178k|       FF0(a,b,c,d,e,i++); t = e; e = d; d = c; c = b; b = a; a = t;
  ------------------
  |  |   72|   178k|    #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|   178k|#define ROLc(word,i) ({ \
  |  |  |  |  276|   178k|   ulong32 __ROLc_tmp = (word); \
  |  |  |  |  277|   178k|   __asm__ ("roll %2, %0" : \
  |  |  |  |  278|   178k|            "=r" (__ROLc_tmp) : \
  |  |  |  |  279|   178k|            "0" (__ROLc_tmp), \
  |  |  |  |  280|   178k|            "I" (i)); \
  |  |  |  |  281|   178k|            __ROLc_tmp; \
  |  |  |  |  282|   178k|   })
  |  |  ------------------
  |  |                   #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|   178k|#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|   178k|#define ROLc(word,i) ({ \
  |  |  |  |  276|   178k|   ulong32 __ROLc_tmp = (word); \
  |  |  |  |  277|   178k|   __asm__ ("roll %2, %0" : \
  |  |  |  |  278|   178k|            "=r" (__ROLc_tmp) : \
  |  |  |  |  279|   178k|            "0" (__ROLc_tmp), \
  |  |  |  |  280|   178k|            "I" (i)); \
  |  |  |  |  281|   178k|            __ROLc_tmp; \
  |  |  |  |  282|   178k|   })
  |  |  ------------------
  ------------------
   81|   178k|    }
   82|       |
   83|   187k|    for (; i < 40; ) {
  ------------------
  |  Branch (83:12): [True: 178k, False: 8.94k]
  ------------------
   84|   178k|       FF1(a,b,c,d,e,i++); t = e; e = d; d = c; c = b; b = a; a = t;
  ------------------
  |  |   73|   178k|    #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|   178k|#define ROLc(word,i) ({ \
  |  |  |  |  276|   178k|   ulong32 __ROLc_tmp = (word); \
  |  |  |  |  277|   178k|   __asm__ ("roll %2, %0" : \
  |  |  |  |  278|   178k|            "=r" (__ROLc_tmp) : \
  |  |  |  |  279|   178k|            "0" (__ROLc_tmp), \
  |  |  |  |  280|   178k|            "I" (i)); \
  |  |  |  |  281|   178k|            __ROLc_tmp; \
  |  |  |  |  282|   178k|   })
  |  |  ------------------
  |  |                   #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|   178k|#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|   178k|#define ROLc(word,i) ({ \
  |  |  |  |  276|   178k|   ulong32 __ROLc_tmp = (word); \
  |  |  |  |  277|   178k|   __asm__ ("roll %2, %0" : \
  |  |  |  |  278|   178k|            "=r" (__ROLc_tmp) : \
  |  |  |  |  279|   178k|            "0" (__ROLc_tmp), \
  |  |  |  |  280|   178k|            "I" (i)); \
  |  |  |  |  281|   178k|            __ROLc_tmp; \
  |  |  |  |  282|   178k|   })
  |  |  ------------------
  ------------------
   85|   178k|    }
   86|       |
   87|   187k|    for (; i < 60; ) {
  ------------------
  |  Branch (87:12): [True: 178k, False: 8.94k]
  ------------------
   88|   178k|       FF2(a,b,c,d,e,i++); t = e; e = d; d = c; c = b; b = a; a = t;
  ------------------
  |  |   74|   178k|    #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|   178k|#define ROLc(word,i) ({ \
  |  |  |  |  276|   178k|   ulong32 __ROLc_tmp = (word); \
  |  |  |  |  277|   178k|   __asm__ ("roll %2, %0" : \
  |  |  |  |  278|   178k|            "=r" (__ROLc_tmp) : \
  |  |  |  |  279|   178k|            "0" (__ROLc_tmp), \
  |  |  |  |  280|   178k|            "I" (i)); \
  |  |  |  |  281|   178k|            __ROLc_tmp; \
  |  |  |  |  282|   178k|   })
  |  |  ------------------
  |  |                   #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|   178k|#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|   178k|#define ROLc(word,i) ({ \
  |  |  |  |  276|   178k|   ulong32 __ROLc_tmp = (word); \
  |  |  |  |  277|   178k|   __asm__ ("roll %2, %0" : \
  |  |  |  |  278|   178k|            "=r" (__ROLc_tmp) : \
  |  |  |  |  279|   178k|            "0" (__ROLc_tmp), \
  |  |  |  |  280|   178k|            "I" (i)); \
  |  |  |  |  281|   178k|            __ROLc_tmp; \
  |  |  |  |  282|   178k|   })
  |  |  ------------------
  ------------------
   89|   178k|    }
   90|       |
   91|   187k|    for (; i < 80; ) {
  ------------------
  |  Branch (91:12): [True: 178k, False: 8.94k]
  ------------------
   92|   178k|       FF3(a,b,c,d,e,i++); t = e; e = d; d = c; c = b; b = a; a = t;
  ------------------
  |  |   75|   178k|    #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|   178k|#define ROLc(word,i) ({ \
  |  |  |  |  276|   178k|   ulong32 __ROLc_tmp = (word); \
  |  |  |  |  277|   178k|   __asm__ ("roll %2, %0" : \
  |  |  |  |  278|   178k|            "=r" (__ROLc_tmp) : \
  |  |  |  |  279|   178k|            "0" (__ROLc_tmp), \
  |  |  |  |  280|   178k|            "I" (i)); \
  |  |  |  |  281|   178k|            __ROLc_tmp; \
  |  |  |  |  282|   178k|   })
  |  |  ------------------
  |  |                   #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|   178k|#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|   178k|#define ROLc(word,i) ({ \
  |  |  |  |  276|   178k|   ulong32 __ROLc_tmp = (word); \
  |  |  |  |  277|   178k|   __asm__ ("roll %2, %0" : \
  |  |  |  |  278|   178k|            "=r" (__ROLc_tmp) : \
  |  |  |  |  279|   178k|            "0" (__ROLc_tmp), \
  |  |  |  |  280|   178k|            "I" (i)); \
  |  |  |  |  281|   178k|            __ROLc_tmp; \
  |  |  |  |  282|   178k|   })
  |  |  ------------------
  ------------------
   93|   178k|    }
   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.94k|    #undef FF0
  134|  8.94k|    #undef FF1
  135|  8.94k|    #undef FF2
  136|  8.94k|    #undef FF3
  137|       |
  138|       |    /* store */
  139|  8.94k|    md->sha1.state[0] = md->sha1.state[0] + a;
  140|  8.94k|    md->sha1.state[1] = md->sha1.state[1] + b;
  141|  8.94k|    md->sha1.state[2] = md->sha1.state[2] + c;
  142|  8.94k|    md->sha1.state[3] = md->sha1.state[3] + d;
  143|  8.94k|    md->sha1.state[4] = md->sha1.state[4] + e;
  144|       |
  145|  8.94k|    return CRYPT_OK;
  146|  8.94k|}

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

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

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

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

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

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

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

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

ltc_init_multi:
   15|   257k|{
   16|   257k|   void    **cur = a;
   17|   257k|   int       np  = 0;
   18|   257k|   va_list   args;
   19|       |
   20|   257k|   va_start(args, a);
   21|  1.15M|   while (cur != NULL) {
  ------------------
  |  Branch (21:11): [True: 899k, False: 257k]
  ------------------
   22|   899k|       if (mp_init(cur) != CRYPT_OK) {
  ------------------
  |  |  516|   899k|#define mp_init(a)                   ltc_mp.init(a)
  ------------------
  |  Branch (22:12): [True: 0, False: 899k]
  ------------------
   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|   899k|       ++np;
   37|   899k|       cur = va_arg(args, void**);
   38|   899k|   }
   39|   257k|   va_end(args);
   40|   257k|   return CRYPT_OK;
   41|   257k|}
ltc_deinit_multi:
   44|   257k|{
   45|   257k|   void     *cur = a;
   46|   257k|   va_list   args;
   47|       |
   48|   257k|   va_start(args, a);
   49|  1.15M|   while (cur != NULL) {
  ------------------
  |  Branch (49:11): [True: 898k, False: 257k]
  ------------------
   50|   898k|       mp_clear(cur);
  ------------------
  |  |  518|   898k|#define mp_clear(a)                  ltc_mp.deinit(a)
  ------------------
   51|   898k|       cur = va_arg(args, void *);
   52|   898k|   }
   53|       |   va_end(args);
   54|   257k|}

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

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

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

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

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

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

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

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

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

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

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

ltc_ecc_new_point:
   29|  1.38k|{
   30|  1.38k|   ecc_point *p;
   31|  1.38k|   p = XCALLOC(1, sizeof(*p));
  ------------------
  |  |   19|  1.38k|#define XCALLOC m_calloc
  ------------------
   32|  1.38k|   if (p == NULL) {
  ------------------
  |  Branch (32:8): [True: 0, False: 1.38k]
  ------------------
   33|      0|      return NULL;
   34|      0|   }
   35|  1.38k|   if (mp_init_multi(&p->x, &p->y, &p->z, NULL) != CRYPT_OK) {
  ------------------
  |  |  517|  1.38k|#define mp_init_multi                ltc_init_multi
  ------------------
  |  Branch (35:8): [True: 0, False: 1.38k]
  ------------------
   36|      0|      XFREE(p);
  ------------------
  |  |   17|      0|#define XFREE m_free_direct
  ------------------
   37|      0|      return NULL;
   38|      0|   }
   39|  1.38k|   return p;
   40|  1.38k|}
ltc_ecc_del_point:
   46|  1.38k|{
   47|       |   /* prevents free'ing null arguments */
   48|  1.38k|   if (p != NULL) {
  ------------------
  |  Branch (48:8): [True: 1.38k, False: 0]
  ------------------
   49|  1.38k|      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.38k|#define mp_clear_multi               ltc_deinit_multi
  ------------------
   50|  1.38k|      XFREE(p);
  ------------------
  |  |   17|  1.38k|#define XFREE m_free_direct
  ------------------
   51|  1.38k|   }
   52|  1.38k|}

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

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

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

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

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

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

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

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

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.94k, False: 120k]
  ------------------
   15|  8.94k|      if ((err = mp_grow(c, a->used + 1)) != MP_OKAY) {
  ------------------
  |  |  161|  8.94k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (15:11): [True: 0, False: 8.94k]
  ------------------
   16|      0|         return err;
   17|      0|      }
   18|  8.94k|   }
   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|   966k|      for (ix = 0; ix < a->used; ix++) {
  ------------------
  |  Branch (51:20): [True: 836k, False: 129k]
  ------------------
   52|   836k|         *tmpc   = *tmpa++ + mu;
   53|   836k|         mu      = *tmpc >> MP_DIGIT_BIT;
  ------------------
  |  |   82|   836k|#   define MP_DIGIT_BIT 60
  ------------------
   54|   836k|         *tmpc++ &= MP_MASK;
  ------------------
  |  |  106|   836k|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|   836k|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
   55|   836k|      }
   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|   235M|{
   15|       |   /* decrease used while the most significant digit is
   16|       |    * zero.
   17|       |    */
   18|   369M|   while ((a->used > 0) && (a->dp[a->used - 1] == 0u)) {
  ------------------
  |  Branch (18:11): [True: 369M, False: 176k]
  |  Branch (18:28): [True: 134M, False: 234M]
  ------------------
   19|   134M|      --(a->used);
   20|   134M|   }
   21|       |
   22|       |   /* reset the sign flag if used == 0 */
   23|   235M|   if (a->used == 0) {
  ------------------
  |  Branch (23:8): [True: 176k, False: 234M]
  ------------------
   24|   176k|      a->sign = MP_ZPOS;
  ------------------
  |  |  151|   176k|#define MP_ZPOS       0   /* positive integer */
  ------------------
   25|   176k|   }
   26|   235M|}

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

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

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

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

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: 943k, False: 102M]
  ------------------
   14|   943k|      return MP_GT;
  ------------------
  |  |  156|   943k|#define MP_GT         1   /* greater than */
  ------------------
   15|   943k|   }
   16|       |
   17|   102M|   if (a->used < b->used) {
  ------------------
  |  Branch (17:8): [True: 1.43M, False: 101M]
  ------------------
   18|  1.43M|      return MP_LT;
  ------------------
  |  |  154|  1.43M|#define MP_LT        -1   /* less than */
  ------------------
   19|  1.43M|   }
   20|       |
   21|       |   /* alias for a */
   22|   101M|   tmpa = a->dp + (a->used - 1);
   23|       |
   24|       |   /* alias for b */
   25|   101M|   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: 25.0k]
  ------------------
   29|   104M|      if (*tmpa > *tmpb) {
  ------------------
  |  Branch (29:11): [True: 28.2M, False: 76.6M]
  ------------------
   30|  28.2M|         return MP_GT;
  ------------------
  |  |  156|  28.2M|#define MP_GT         1   /* greater than */
  ------------------
   31|  28.2M|      }
   32|       |
   33|  76.6M|      if (*tmpa < *tmpb) {
  ------------------
  |  Branch (33:11): [True: 72.9M, False: 3.65M]
  ------------------
   34|  72.9M|         return MP_LT;
  ------------------
  |  |  154|  72.9M|#define MP_LT        -1   /* less than */
  ------------------
   35|  72.9M|      }
   36|  76.6M|   }
   37|  25.0k|   return MP_EQ;
  ------------------
  |  |  155|  25.0k|#define MP_EQ         0   /* equal to */
  ------------------
   38|   101M|}

mp_copy:
    8|  14.6M|{
    9|  14.6M|   int n;
   10|  14.6M|   mp_digit *tmpa, *tmpb;
   11|  14.6M|   mp_err err;
   12|       |
   13|       |   /* if dst == src do nothing */
   14|  14.6M|   if (a == b) {
  ------------------
  |  Branch (14:8): [True: 13.6M, False: 1.03M]
  ------------------
   15|  13.6M|      return MP_OKAY;
  ------------------
  |  |  161|  13.6M|#define MP_OKAY       0   /* no error */
  ------------------
   16|  13.6M|   }
   17|       |
   18|       |   /* grow dest */
   19|  1.03M|   if (b->alloc < a->used) {
  ------------------
  |  Branch (19:8): [True: 26.8k, False: 1.00M]
  ------------------
   20|  26.8k|      if ((err = mp_grow(b, a->used)) != MP_OKAY) {
  ------------------
  |  |  161|  26.8k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (20:11): [True: 0, False: 26.8k]
  ------------------
   21|      0|         return err;
   22|      0|      }
   23|  26.8k|   }
   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.8M|   for (n = 0; n < a->used; n++) {
  ------------------
  |  Branch (35:16): [True: 14.8M, False: 1.03M]
  ------------------
   36|  14.8M|      *tmpb++ = *tmpa++;
   37|  14.8M|   }
   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: 4, False: 1.03M]
  |  |  ------------------
  |  |   94|      4|      *zm_++ = 0;                                       \
  |  |   95|      4|   }                                                    \
  |  |   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|   338k|{
    9|   338k|   int     r;
   10|   338k|   mp_digit q;
   11|       |
   12|       |   /* shortcut */
   13|   338k|   if (MP_IS_ZERO(a)) {
  ------------------
  |  |  163|   338k|#define MP_IS_ZERO(a) ((a)->used == 0)
  |  |  ------------------
  |  |  |  Branch (163:23): [True: 0, False: 338k]
  |  |  ------------------
  ------------------
   14|      0|      return 0;
   15|      0|   }
   16|       |
   17|       |   /* get number of digits and add that */
   18|   338k|   r = (a->used - 1) * MP_DIGIT_BIT;
  ------------------
  |  |   82|   338k|#   define MP_DIGIT_BIT 60
  ------------------
   19|       |
   20|       |   /* take the last digit and count the bits in it */
   21|   338k|   q = a->dp[a->used - 1];
   22|  3.62M|   while (q > 0u) {
  ------------------
  |  Branch (22:11): [True: 3.28M, False: 338k]
  ------------------
   23|  3.28M|      ++r;
   24|  3.28M|      q >>= 1u;
   25|  3.28M|   }
   26|   338k|   return r;
   27|   338k|}

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

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

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

mp_dr_is_modulus:
    8|  30.2k|{
    9|  30.2k|   int ix;
   10|       |
   11|       |   /* must be at least two digits */
   12|  30.2k|   if (a->used < 2) {
  ------------------
  |  Branch (12:8): [True: 0, False: 30.2k]
  ------------------
   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.2k|   for (ix = 1; ix < a->used; ix++) {
  ------------------
  |  Branch (19:17): [True: 30.2k, False: 0]
  ------------------
   20|  30.2k|      if (a->dp[ix] != MP_MASK) {
  ------------------
  |  |  106|  30.2k|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|  30.2k|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
  |  Branch (20:11): [True: 30.2k, False: 0]
  ------------------
   21|  30.2k|         return MP_NO;
  ------------------
  |  |  159|  30.2k|#define MP_NO         0
  ------------------
   22|  30.2k|      }
   23|  30.2k|   }
   24|      0|   return MP_YES;
  ------------------
  |  |  158|      0|#define MP_YES        1
  ------------------
   25|  30.2k|}

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

mp_exptmod:
   12|  30.2k|{
   13|  30.2k|   int dr;
   14|       |
   15|       |   /* modulus P must be positive */
   16|  30.2k|   if (P->sign == MP_NEG) {
  ------------------
  |  |  152|  30.2k|#define MP_NEG        1   /* negative */
  ------------------
  |  Branch (16:8): [True: 0, False: 30.2k]
  ------------------
   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.2k|   if (X->sign == MP_NEG) {
  ------------------
  |  |  152|  30.2k|#define MP_NEG        1   /* negative */
  ------------------
  |  Branch (21:8): [True: 0, False: 30.2k]
  ------------------
   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.2k|   if (MP_HAS(MP_REDUCE_IS_2K_L) && MP_HAS(MP_REDUCE_2K_L) && MP_HAS(S_MP_EXPTMOD) &&
  ------------------
  |  |  150|  60.5k|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|  30.2k|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|  30.2k|#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.2k|#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.2k|#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.2k|       (mp_reduce_is_2k_l(P) == MP_YES)) {
  ------------------
  |  |  158|  30.2k|#define MP_YES        1
  ------------------
  |  Branch (52:8): [True: 0, False: 30.2k]
  ------------------
   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.2k|   dr = (MP_HAS(MP_DR_IS_MODULUS) && (mp_dr_is_modulus(P) == MP_YES)) ? 1 : 0;
  ------------------
  |  |  150|  60.5k|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|  30.2k|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|  30.2k|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [True: 30.2k, Folded]
  |  |  ------------------
  ------------------
                 dr = (MP_HAS(MP_DR_IS_MODULUS) && (mp_dr_is_modulus(P) == MP_YES)) ? 1 : 0;
  ------------------
  |  |  158|  30.2k|#define MP_YES        1
  ------------------
  |  Branch (57:38): [True: 0, False: 30.2k]
  ------------------
   58|       |
   59|       |   /* if not, is it a unrestricted DR modulus? */
   60|  30.2k|   if (MP_HAS(MP_REDUCE_IS_2K) && (dr == 0)) {
  ------------------
  |  |  150|  60.5k|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|  30.2k|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|  30.2k|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [True: 30.2k, Folded]
  |  |  ------------------
  ------------------
  |  Branch (60:35): [True: 30.2k, False: 0]
  ------------------
   61|  30.2k|      dr = (mp_reduce_is_2k(P) == MP_YES) ? 2 : 0;
  ------------------
  |  |  158|  30.2k|#define MP_YES        1
  ------------------
  |  Branch (61:12): [True: 0, False: 30.2k]
  ------------------
   62|  30.2k|   }
   63|       |
   64|       |   /* if the modulus is odd or dr != 0 use the montgomery method */
   65|  30.2k|   if (MP_HAS(S_MP_EXPTMOD_FAST) && (MP_IS_ODD(P) || (dr != 0))) {
  ------------------
  |  |  150|  60.5k|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|  30.2k|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|  30.2k|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [True: 30.2k, Folded]
  |  |  ------------------
  ------------------
                 if (MP_HAS(S_MP_EXPTMOD_FAST) && (MP_IS_ODD(P) || (dr != 0))) {
  ------------------
  |  |  165|  60.5k|#define MP_IS_ODD(a)  (((a)->used > 0) && (((a)->dp[0] & 1u) == 1u))
  |  |  ------------------
  |  |  |  Branch (165:24): [True: 30.2k, False: 0]
  |  |  |  Branch (165:43): [True: 30.2k, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (65:54): [True: 0, False: 0]
  ------------------
   66|  30.2k|      return s_mp_exptmod_fast(G, X, P, Y, dr);
   67|  30.2k|   } 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.2k|}

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

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

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

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

mp_init_multi:
    9|  9.22k|{
   10|  9.22k|   mp_err err = MP_OKAY;      /* Assume ok until proven otherwise */
  ------------------
  |  |  161|  9.22k|#define MP_OKAY       0   /* no error */
  ------------------
   11|  9.22k|   int n = 0;                 /* Number of ok inits */
   12|  9.22k|   mp_int *cur_arg = mp;
   13|  9.22k|   va_list args;
   14|       |
   15|  9.22k|   va_start(args, mp);        /* init args to next argument from caller */
   16|  64.5k|   while (cur_arg != NULL) {
  ------------------
  |  Branch (16:11): [True: 55.3k, False: 9.22k]
  ------------------
   17|  55.3k|      if (mp_init(cur_arg) != MP_OKAY) {
  ------------------
  |  |  161|  55.3k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (17:11): [True: 0, False: 55.3k]
  ------------------
   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|  55.3k|      n++;
   35|  55.3k|      cur_arg = va_arg(args, mp_int *);
   36|  55.3k|   }
   37|       |   va_end(args);
   38|  9.22k|   return err;                /* Assumed ok, if error flagged above. */
   39|  9.22k|}

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

mp_invmod:
    8|  9.22k|{
    9|       |   /* b cannot be negative and has to be >1 */
   10|  9.22k|   if ((b->sign == MP_NEG) || (mp_cmp_d(b, 1uL) != MP_GT)) {
  ------------------
  |  |  152|  9.22k|#define MP_NEG        1   /* negative */
  ------------------
                 if ((b->sign == MP_NEG) || (mp_cmp_d(b, 1uL) != MP_GT)) {
  ------------------
  |  |  156|  9.22k|#define MP_GT         1   /* greater than */
  ------------------
  |  Branch (10:8): [True: 0, False: 9.22k]
  |  Branch (10:31): [True: 0, False: 9.22k]
  ------------------
   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|  9.22k|   if (MP_HAS(S_MP_INVMOD_FAST) && MP_IS_ODD(b)) {
  ------------------
  |  |  150|  18.4k|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|  9.22k|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|  9.22k|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [True: 9.22k, Folded]
  |  |  ------------------
  ------------------
                 if (MP_HAS(S_MP_INVMOD_FAST) && MP_IS_ODD(b)) {
  ------------------
  |  |  165|  9.22k|#define MP_IS_ODD(a)  (((a)->used > 0) && (((a)->dp[0] & 1u) == 1u))
  |  |  ------------------
  |  |  |  Branch (165:24): [True: 9.22k, False: 0]
  |  |  |  Branch (165:43): [True: 9.22k, False: 0]
  |  |  ------------------
  ------------------
   16|  9.22k|      return s_mp_invmod_fast(a, b, c);
   17|  9.22k|   }
   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|  9.22k|}

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

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

mp_montgomery_calc_normalization:
   13|  30.5k|{
   14|  30.5k|   int    x, bits;
   15|  30.5k|   mp_err err;
   16|       |
   17|       |   /* how many bits of last digit does b use */
   18|  30.5k|   bits = mp_count_bits(b) % MP_DIGIT_BIT;
  ------------------
  |  |   82|  30.5k|#   define MP_DIGIT_BIT 60
  ------------------
   19|       |
   20|  30.5k|   if (b->used > 1) {
  ------------------
  |  Branch (20:8): [True: 30.5k, False: 0]
  ------------------
   21|  30.5k|      if ((err = mp_2expt(a, ((b->used - 1) * MP_DIGIT_BIT) + bits - 1)) != MP_OKAY) {
  ------------------
  |  |   82|  30.5k|#   define MP_DIGIT_BIT 60
  ------------------
                    if ((err = mp_2expt(a, ((b->used - 1) * MP_DIGIT_BIT) + bits - 1)) != MP_OKAY) {
  ------------------
  |  |  161|  30.5k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (21:11): [True: 0, False: 30.5k]
  ------------------
   22|      0|         return err;
   23|      0|      }
   24|  30.5k|   } 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.64M|   for (x = bits - 1; x < (int)MP_DIGIT_BIT; x++) {
  ------------------
  |  |   82|  1.64M|#   define MP_DIGIT_BIT 60
  ------------------
  |  Branch (31:23): [True: 1.61M, False: 30.5k]
  ------------------
   32|  1.61M|      if ((err = mp_mul_2(a, a)) != MP_OKAY) {
  ------------------
  |  |  161|  1.61M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (32:11): [True: 0, False: 1.61M]
  ------------------
   33|      0|         return err;
   34|      0|      }
   35|  1.61M|      if (mp_cmp_mag(a, b) != MP_LT) {
  ------------------
  |  |  154|  1.61M|#define MP_LT        -1   /* less than */
  ------------------
  |  Branch (35:11): [True: 442k, False: 1.16M]
  ------------------
   36|   442k|         if ((err = s_mp_sub(a, b, a)) != MP_OKAY) {
  ------------------
  |  |  161|   442k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (36:14): [True: 0, False: 442k]
  ------------------
   37|      0|            return err;
   38|      0|         }
   39|   442k|      }
   40|  1.61M|   }
   41|       |
   42|  30.5k|   return MP_OKAY;
  ------------------
  |  |  161|  30.5k|#define MP_OKAY       0   /* no error */
  ------------------
   43|  30.5k|}

mp_montgomery_reduce:
    8|  3.06M|{
    9|  3.06M|   int      ix, digs;
   10|  3.06M|   mp_err   err;
   11|  3.06M|   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.06M|   digs = (n->used * 2) + 1;
   20|  3.06M|   if ((digs < MP_WARRAY) &&
  ------------------
  |  |  172|  3.06M|#define MP_WARRAY PRIVATE_MP_WARRAY
  |  |  ------------------
  |  |  |  |  203|  3.06M|#define PRIVATE_MP_WARRAY (int)(1uLL << (((CHAR_BIT * sizeof(private_mp_word)) - (2 * MP_DIGIT_BIT)) + 1))
  |  |  |  |  ------------------
  |  |  |  |  |  |   82|  3.06M|#   define MP_DIGIT_BIT 60
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (20:8): [True: 3.06M, False: 0]
  ------------------
   21|  3.06M|       (x->used <= MP_WARRAY) &&
  ------------------
  |  |  172|  3.06M|#define MP_WARRAY PRIVATE_MP_WARRAY
  |  |  ------------------
  |  |  |  |  203|  3.06M|#define PRIVATE_MP_WARRAY (int)(1uLL << (((CHAR_BIT * sizeof(private_mp_word)) - (2 * MP_DIGIT_BIT)) + 1))
  |  |  |  |  ------------------
  |  |  |  |  |  |   82|  3.06M|#   define MP_DIGIT_BIT 60
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (21:8): [True: 3.06M, False: 0]
  ------------------
   22|  3.06M|       (n->used < MP_MAXFAST)) {
  ------------------
  |  |  168|  3.06M|#define MP_MAXFAST              (int)(1uL << (MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT)))
  |  |  ------------------
  |  |  |  |  167|  3.06M|#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.06M|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
  |  Branch (22:8): [True: 3.06M, False: 0]
  ------------------
   23|  3.06M|      return s_mp_montgomery_reduce_fast(x, n, rho);
   24|  3.06M|   }
   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.5k|{
    9|  30.5k|   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.5k|   b = n->dp[0];
   20|       |
   21|  30.5k|   if ((b & 1u) == 0u) {
  ------------------
  |  Branch (21:8): [True: 0, False: 30.5k]
  ------------------
   22|      0|      return MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
   23|      0|   }
   24|       |
   25|  30.5k|   x = (((b + 2u) & 4u) << 1) + b; /* here x*a==1 mod 2**4 */
   26|  30.5k|   x *= 2u - (b * x);              /* here x*a==1 mod 2**8 */
   27|  30.5k|#if !defined(MP_8BIT)
   28|  30.5k|   x *= 2u - (b * x);              /* here x*a==1 mod 2**16 */
   29|  30.5k|#endif
   30|  30.5k|#if defined(MP_64BIT) || !(defined(MP_8BIT) || defined(MP_16BIT))
   31|  30.5k|   x *= 2u - (b * x);              /* here x*a==1 mod 2**32 */
   32|  30.5k|#endif
   33|  30.5k|#ifdef MP_64BIT
   34|  30.5k|   x *= 2u - (b * x);              /* here x*a==1 mod 2**64 */
   35|  30.5k|#endif
   36|       |
   37|       |   /* rho = -1/m mod b */
   38|  30.5k|   *rho = (mp_digit)(((mp_word)1 << (mp_word)MP_DIGIT_BIT) - x) & MP_MASK;
  ------------------
  |  |   82|  30.5k|#   define MP_DIGIT_BIT 60
  ------------------
                 *rho = (mp_digit)(((mp_word)1 << (mp_word)MP_DIGIT_BIT) - x) & MP_MASK;
  ------------------
  |  |  106|  30.5k|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|  30.5k|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
   39|       |
   40|  30.5k|   return MP_OKAY;
  ------------------
  |  |  161|  30.5k|#define MP_OKAY       0   /* no error */
  ------------------
   41|  30.5k|}

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

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

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

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

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

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

mp_reduce_is_2k:
    8|  30.2k|{
    9|  30.2k|   int ix, iy, iw;
   10|  30.2k|   mp_digit iz;
   11|       |
   12|  30.2k|   if (a->used == 0) {
  ------------------
  |  Branch (12:8): [True: 0, False: 30.2k]
  ------------------
   13|      0|      return MP_NO;
  ------------------
  |  |  159|      0|#define MP_NO         0
  ------------------
   14|  30.2k|   } else if (a->used == 1) {
  ------------------
  |  Branch (14:15): [True: 0, False: 30.2k]
  ------------------
   15|      0|      return MP_YES;
  ------------------
  |  |  158|      0|#define MP_YES        1
  ------------------
   16|  30.2k|   } else if (a->used > 1) {
  ------------------
  |  Branch (16:15): [True: 30.2k, False: 0]
  ------------------
   17|  30.2k|      iy = mp_count_bits(a);
   18|  30.2k|      iz = 1;
   19|  30.2k|      iw = 1;
   20|       |
   21|       |      /* Test every bit from the second digit up, must be 1 */
   22|   187k|      for (ix = MP_DIGIT_BIT; ix < iy; ix++) {
  ------------------
  |  |   82|  30.2k|#   define MP_DIGIT_BIT 60
  ------------------
  |  Branch (22:31): [True: 187k, False: 0]
  ------------------
   23|   187k|         if ((a->dp[iw] & iz) == 0u) {
  ------------------
  |  Branch (23:14): [True: 30.2k, False: 156k]
  ------------------
   24|  30.2k|            return MP_NO;
  ------------------
  |  |  159|  30.2k|#define MP_NO         0
  ------------------
   25|  30.2k|         }
   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.2k|   } else {
   34|      0|      return MP_YES;
  ------------------
  |  |  158|      0|#define MP_YES        1
  ------------------
   35|      0|   }
   36|  30.2k|}

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

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

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

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

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

mp_sub_d:
    8|  12.4k|{
    9|  12.4k|   mp_digit *tmpa, *tmpc;
   10|  12.4k|   mp_err    err;
   11|  12.4k|   int       ix, oldused;
   12|       |
   13|       |   /* grow c as required */
   14|  12.4k|   if (c->alloc < (a->used + 1)) {
  ------------------
  |  Branch (14:8): [True: 12.4k, False: 0]
  ------------------
   15|  12.4k|      if ((err = mp_grow(c, a->used + 1)) != MP_OKAY) {
  ------------------
  |  |  161|  12.4k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (15:11): [True: 0, False: 12.4k]
  ------------------
   16|      0|         return err;
   17|      0|      }
   18|  12.4k|   }
   19|       |
   20|       |   /* if a is negative just do an unsigned
   21|       |    * addition [with fudged signs]
   22|       |    */
   23|  12.4k|   if (a->sign == MP_NEG) {
  ------------------
  |  |  152|  12.4k|#define MP_NEG        1   /* negative */
  ------------------
  |  Branch (23:8): [True: 0, False: 12.4k]
  ------------------
   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|  12.4k|   oldused = c->used;
   37|  12.4k|   tmpa    = a->dp;
   38|  12.4k|   tmpc    = c->dp;
   39|       |
   40|       |   /* if a <= b simply fix the single digit */
   41|  12.4k|   if (((a->used == 1) && (a->dp[0] <= b)) || (a->used == 0)) {
  ------------------
  |  Branch (41:9): [True: 0, False: 12.4k]
  |  Branch (41:27): [True: 0, False: 0]
  |  Branch (41:47): [True: 0, False: 12.4k]
  ------------------
   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|  12.4k|   } else {
   53|  12.4k|      mp_digit mu = b;
   54|       |
   55|       |      /* positive/size */
   56|  12.4k|      c->sign = MP_ZPOS;
  ------------------
  |  |  151|  12.4k|#define MP_ZPOS       0   /* positive integer */
  ------------------
   57|  12.4k|      c->used = a->used;
   58|       |
   59|       |      /* subtract digits, mu is carry */
   60|   447k|      for (ix = 0; ix < a->used; ix++) {
  ------------------
  |  Branch (60:20): [True: 435k, False: 12.4k]
  ------------------
   61|   435k|         *tmpc    = *tmpa++ - mu;
   62|   435k|         mu       = *tmpc >> (MP_SIZEOF_BITS(mp_digit) - 1u);
  ------------------
  |  |  167|   435k|#define MP_SIZEOF_BITS(type)    ((size_t)CHAR_BIT * sizeof(type))
  ------------------
   63|   435k|         *tmpc++ &= MP_MASK;
  ------------------
  |  |  106|   435k|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|   435k|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
   64|   435k|      }
   65|  12.4k|   }
   66|       |
   67|       |   /* zero excess digits */
   68|  12.4k|   MP_ZERO_DIGITS(tmpc, oldused - ix);
  ------------------
  |  |   89|  12.4k|#  define MP_ZERO_DIGITS(mem, digits)                   \
  |  |   90|  12.4k|do {                                                    \
  |  |   91|  12.4k|   int zd_ = (digits);                                  \
  |  |   92|  12.4k|   mp_digit* zm_ = (mem);                               \
  |  |   93|  12.4k|   while (zd_-- > 0) {                                  \
  |  |  ------------------
  |  |  |  Branch (93:11): [True: 0, False: 12.4k]
  |  |  ------------------
  |  |   94|      0|      *zm_++ = 0;                                       \
  |  |   95|      0|   }                                                    \
  |  |   96|  12.4k|} while (0)
  |  |  ------------------
  |  |  |  Branch (96:10): [Folded, False: 12.4k]
  |  |  ------------------
  ------------------
   69|       |
   70|  12.4k|   mp_clamp(c);
   71|  12.4k|   return MP_OKAY;
  ------------------
  |  |  161|  12.4k|#define MP_OKAY       0   /* no error */
  ------------------
   72|  12.4k|}

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

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

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

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

s_mp_exptmod_fast:
   23|  30.2k|{
   24|  30.2k|   mp_int  M[TAB_SIZE], res;
   25|  30.2k|   mp_digit buf, mp;
   26|  30.2k|   int     bitbuf, bitcpy, bitcnt, mode, digidx, x, y, winsize;
   27|  30.2k|   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.2k|   mp_err(*redux)(mp_int *x, const mp_int *n, mp_digit rho);
   34|       |
   35|       |   /* find window size */
   36|  30.2k|   x = mp_count_bits(X);
   37|  30.2k|   if (x <= 7) {
  ------------------
  |  Branch (37:8): [True: 0, False: 30.2k]
  ------------------
   38|      0|      winsize = 2;
   39|  30.2k|   } else if (x <= 36) {
  ------------------
  |  Branch (39:15): [True: 8.94k, False: 21.3k]
  ------------------
   40|  8.94k|      winsize = 3;
   41|  21.3k|   } else if (x <= 140) {
  ------------------
  |  Branch (41:15): [True: 0, False: 21.3k]
  ------------------
   42|      0|      winsize = 4;
   43|  21.3k|   } else if (x <= 450) {
  ------------------
  |  Branch (43:15): [True: 0, False: 21.3k]
  ------------------
   44|      0|      winsize = 5;
   45|  21.3k|   } else if (x <= 1303) {
  ------------------
  |  Branch (45:15): [True: 0, False: 21.3k]
  ------------------
   46|      0|      winsize = 6;
   47|  21.3k|   } else if (x <= 3529) {
  ------------------
  |  Branch (47:15): [True: 21.3k, False: 0]
  ------------------
   48|  21.3k|      winsize = 7;
   49|  21.3k|   } else {
   50|      0|      winsize = 8;
   51|      0|   }
   52|       |
   53|  30.2k|   winsize = MAX_WINSIZE ? MP_MIN(MAX_WINSIZE, winsize) : winsize;
  ------------------
  |  |   19|  30.2k|#   define MAX_WINSIZE 0
  |  |  ------------------
  |  |  |  Branch (19:24): [Folded, False: 30.2k]
  |  |  ------------------
  ------------------
                 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.2k|   if ((err = mp_init_size(&M[1], P->alloc)) != MP_OKAY) {
  ------------------
  |  |  161|  30.2k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (57:8): [True: 0, False: 30.2k]
  ------------------
   58|      0|      return err;
   59|      0|   }
   60|       |
   61|       |   /* now init the second half of the array */
   62|  1.43M|   for (x = 1<<(winsize-1); x < (1 << winsize); x++) {
  ------------------
  |  Branch (62:29): [True: 1.40M, False: 30.2k]
  ------------------
   63|  1.40M|      if ((err = mp_init_size(&M[x], P->alloc)) != MP_OKAY) {
  ------------------
  |  |  161|  1.40M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (63:11): [True: 0, False: 1.40M]
  ------------------
   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.40M|   }
   71|       |
   72|       |   /* determine and setup reduction code */
   73|  30.2k|   if (redmode == 0) {
  ------------------
  |  Branch (73:8): [True: 30.2k, False: 0]
  ------------------
   74|  30.2k|      if (MP_HAS(MP_MONTGOMERY_SETUP)) {
  ------------------
  |  |  150|  30.2k|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|  30.2k|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|  30.2k|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [True: 30.2k, Folded]
  |  |  ------------------
  ------------------
   75|       |         /* now setup montgomery  */
   76|  30.2k|         if ((err = mp_montgomery_setup(P, &mp)) != MP_OKAY)      goto LBL_M;
  ------------------
  |  |  161|  30.2k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (76:14): [True: 0, False: 30.2k]
  ------------------
   77|  30.2k|      } 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.2k|      if (MP_HAS(S_MP_MONTGOMERY_REDUCE_FAST) &&
  ------------------
  |  |  150|  60.5k|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|  30.2k|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|  30.2k|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [True: 30.2k, Folded]
  |  |  ------------------
  ------------------
   84|  30.2k|          (((P->used * 2) + 1) < MP_WARRAY) &&
  ------------------
  |  |  172|  30.2k|#define MP_WARRAY PRIVATE_MP_WARRAY
  |  |  ------------------
  |  |  |  |  203|  30.2k|#define PRIVATE_MP_WARRAY (int)(1uLL << (((CHAR_BIT * sizeof(private_mp_word)) - (2 * MP_DIGIT_BIT)) + 1))
  |  |  |  |  ------------------
  |  |  |  |  |  |   82|  30.2k|#   define MP_DIGIT_BIT 60
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (84:11): [True: 30.2k, False: 0]
  ------------------
   85|  30.2k|          (P->used < MP_MAXFAST)) {
  ------------------
  |  |  168|  30.2k|#define MP_MAXFAST              (int)(1uL << (MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT)))
  |  |  ------------------
  |  |  |  |  167|  30.2k|#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.2k|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
  |  Branch (85:11): [True: 30.2k, False: 0]
  ------------------
   86|  30.2k|         redux = s_mp_montgomery_reduce_fast;
   87|  30.2k|      } 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.2k|   } 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.2k|   if ((err = mp_init_size(&res, P->alloc)) != MP_OKAY)           goto LBL_M;
  ------------------
  |  |  161|  30.2k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (113:8): [True: 0, False: 30.2k]
  ------------------
  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.2k|   if (redmode == 0) {
  ------------------
  |  Branch (122:8): [True: 30.2k, False: 0]
  ------------------
  123|  30.2k|      if (MP_HAS(MP_MONTGOMERY_CALC_NORMALIZATION)) {
  ------------------
  |  |  150|  30.2k|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|  30.2k|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|  30.2k|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [True: 30.2k, Folded]
  |  |  ------------------
  ------------------
  124|       |         /* now we need R mod m */
  125|  30.2k|         if ((err = mp_montgomery_calc_normalization(&res, P)) != MP_OKAY) goto LBL_RES;
  ------------------
  |  |  161|  30.2k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (125:14): [True: 0, False: 30.2k]
  ------------------
  126|       |
  127|       |         /* now set M[1] to G * R mod m */
  128|  30.2k|         if ((err = mp_mulmod(G, &res, P, &M[1])) != MP_OKAY)     goto LBL_RES;
  ------------------
  |  |  161|  30.2k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (128:14): [True: 0, False: 30.2k]
  ------------------
  129|  30.2k|      } else {
  130|      0|         err = MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
  131|      0|         goto LBL_RES;
  132|      0|      }
  133|  30.2k|   } 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.2k|   if ((err = mp_copy(&M[1], &M[(size_t)1 << (winsize - 1)])) != MP_OKAY) goto LBL_RES;
  ------------------
  |  |  161|  30.2k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (139:8): [True: 0, False: 30.2k]
  ------------------
  140|       |
  141|   176k|   for (x = 0; x < (winsize - 1); x++) {
  ------------------
  |  Branch (141:16): [True: 145k, False: 30.2k]
  ------------------
  142|   145k|      if ((err = mp_sqr(&M[(size_t)1 << (winsize - 1)], &M[(size_t)1 << (winsize - 1)])) != MP_OKAY) goto LBL_RES;
  ------------------
  |  |  161|   145k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (142:11): [True: 0, False: 145k]
  ------------------
  143|   145k|      if ((err = redux(&M[(size_t)1 << (winsize - 1)], P, mp)) != MP_OKAY) goto LBL_RES;
  ------------------
  |  |  161|   145k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (143:11): [True: 0, False: 145k]
  ------------------
  144|   145k|   }
  145|       |
  146|       |   /* create upper table */
  147|  1.40M|   for (x = (1 << (winsize - 1)) + 1; x < (1 << winsize); x++) {
  ------------------
  |  Branch (147:39): [True: 1.36M, False: 30.2k]
  ------------------
  148|  1.36M|      if ((err = mp_mul(&M[x - 1], &M[1], &M[x])) != MP_OKAY)     goto LBL_RES;
  ------------------
  |  |  161|  1.36M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (148:11): [True: 0, False: 1.36M]
  ------------------
  149|  1.36M|      if ((err = redux(&M[x], P, mp)) != MP_OKAY)                 goto LBL_RES;
  ------------------
  |  |  161|  1.36M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (149:11): [True: 0, False: 1.36M]
  ------------------
  150|  1.36M|   }
  151|       |
  152|       |   /* set initial mode and bit cnt */
  153|  30.2k|   mode   = 0;
  154|  30.2k|   bitcnt = 1;
  155|  30.2k|   buf    = 0;
  156|  30.2k|   digidx = X->used - 1;
  157|  30.2k|   bitcpy = 0;
  158|  30.2k|   bitbuf = 0;
  159|       |
  160|  45.8M|   for (;;) {
  161|       |      /* grab next digit as required */
  162|  45.8M|      if (--bitcnt == 0) {
  ------------------
  |  Branch (162:11): [True: 794k, False: 45.0M]
  ------------------
  163|       |         /* if digidx == -1 we are out of digits so break */
  164|   794k|         if (digidx == -1) {
  ------------------
  |  Branch (164:14): [True: 30.2k, False: 764k]
  ------------------
  165|  30.2k|            break;
  166|  30.2k|         }
  167|       |         /* read next digit and reset bitcnt */
  168|   764k|         buf    = X->dp[digidx--];
  169|   764k|         bitcnt = (int)MP_DIGIT_BIT;
  ------------------
  |  |   82|   764k|#   define MP_DIGIT_BIT 60
  ------------------
  170|   764k|      }
  171|       |
  172|       |      /* grab the next msb from the exponent */
  173|  45.8M|      y     = (mp_digit)(buf >> (MP_DIGIT_BIT - 1)) & 1uL;
  ------------------
  |  |   82|  45.8M|#   define MP_DIGIT_BIT 60
  ------------------
  174|  45.8M|      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|  45.8M|      if ((mode == 0) && (y == 0)) {
  ------------------
  |  Branch (181:11): [True: 1.52M, False: 44.3M]
  |  Branch (181:26): [True: 1.49M, False: 30.2k]
  ------------------
  182|  1.49M|         continue;
  183|  1.49M|      }
  184|       |
  185|       |      /* if the bit is zero and mode == 1 then we square */
  186|  44.3M|      if ((mode == 1) && (y == 0)) {
  ------------------
  |  Branch (186:11): [True: 11.1M, False: 33.1M]
  |  Branch (186:26): [True: 5.65M, False: 5.51M]
  ------------------
  187|  5.65M|         if ((err = mp_sqr(&res, &res)) != MP_OKAY)               goto LBL_RES;
  ------------------
  |  |  161|  5.65M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (187:14): [True: 0, False: 5.65M]
  ------------------
  188|  5.65M|         if ((err = redux(&res, P, mp)) != MP_OKAY)               goto LBL_RES;
  ------------------
  |  |  161|  5.65M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (188:14): [True: 0, False: 5.65M]
  ------------------
  189|  5.65M|         continue;
  190|  5.65M|      }
  191|       |
  192|       |      /* else we add it to the window */
  193|  38.6M|      bitbuf |= (y << (winsize - ++bitcpy));
  194|  38.6M|      mode    = 2;
  195|       |
  196|  38.6M|      if (bitcpy == winsize) {
  ------------------
  |  Branch (196:11): [True: 5.52M, False: 33.1M]
  ------------------
  197|       |         /* ok window is filled so square as required and multiply  */
  198|       |         /* square first */
  199|  44.1M|         for (x = 0; x < winsize; x++) {
  ------------------
  |  Branch (199:22): [True: 38.6M, False: 5.52M]
  ------------------
  200|  38.6M|            if ((err = mp_sqr(&res, &res)) != MP_OKAY)            goto LBL_RES;
  ------------------
  |  |  161|  38.6M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (200:17): [True: 0, False: 38.6M]
  ------------------
  201|  38.6M|            if ((err = redux(&res, P, mp)) != MP_OKAY)            goto LBL_RES;
  ------------------
  |  |  161|  38.6M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (201:17): [True: 0, False: 38.6M]
  ------------------
  202|  38.6M|         }
  203|       |
  204|       |         /* then multiply */
  205|  5.52M|         if ((err = mp_mul(&res, &M[bitbuf], &res)) != MP_OKAY)   goto LBL_RES;
  ------------------
  |  |  161|  5.52M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (205:14): [True: 0, False: 5.52M]
  ------------------
  206|  5.52M|         if ((err = redux(&res, P, mp)) != MP_OKAY)               goto LBL_RES;
  ------------------
  |  |  161|  5.52M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (206:14): [True: 0, False: 5.52M]
  ------------------
  207|       |
  208|       |         /* empty window and reset */
  209|  5.52M|         bitcpy = 0;
  210|  5.52M|         bitbuf = 0;
  211|  5.52M|         mode   = 1;
  212|  5.52M|      }
  213|  38.6M|   }
  214|       |
  215|       |   /* if bits remain then square/multiply */
  216|  30.2k|   if ((mode == 2) && (bitcpy > 0)) {
  ------------------
  |  Branch (216:8): [True: 23.4k, False: 6.85k]
  |  Branch (216:23): [True: 23.4k, False: 0]
  ------------------
  217|       |      /* square then multiply if the bit is set */
  218|  81.1k|      for (x = 0; x < bitcpy; x++) {
  ------------------
  |  Branch (218:19): [True: 57.6k, False: 23.4k]
  ------------------
  219|  57.6k|         if ((err = mp_sqr(&res, &res)) != MP_OKAY)               goto LBL_RES;
  ------------------
  |  |  161|  57.6k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (219:14): [True: 0, False: 57.6k]
  ------------------
  220|  57.6k|         if ((err = redux(&res, P, mp)) != MP_OKAY)               goto LBL_RES;
  ------------------
  |  |  161|  57.6k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (220:14): [True: 0, False: 57.6k]
  ------------------
  221|       |
  222|       |         /* get next bit of the window */
  223|  57.6k|         bitbuf <<= 1;
  224|  57.6k|         if ((bitbuf & (1 << winsize)) != 0) {
  ------------------
  |  Branch (224:14): [True: 46.4k, False: 11.2k]
  ------------------
  225|       |            /* then multiply */
  226|  46.4k|            if ((err = mp_mul(&res, &M[1], &res)) != MP_OKAY)     goto LBL_RES;
  ------------------
  |  |  161|  46.4k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (226:17): [True: 0, False: 46.4k]
  ------------------
  227|  46.4k|            if ((err = redux(&res, P, mp)) != MP_OKAY)            goto LBL_RES;
  ------------------
  |  |  161|  46.4k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (227:17): [True: 0, False: 46.4k]
  ------------------
  228|  46.4k|         }
  229|  57.6k|      }
  230|  23.4k|   }
  231|       |
  232|  30.2k|   if (redmode == 0) {
  ------------------
  |  Branch (232:8): [True: 30.2k, 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.2k|      if ((err = redux(&res, P, mp)) != MP_OKAY)                  goto LBL_RES;
  ------------------
  |  |  161|  30.2k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (239:11): [True: 0, False: 30.2k]
  ------------------
  240|  30.2k|   }
  241|       |
  242|       |   /* swap res with Y */
  243|  30.2k|   mp_exch(&res, Y);
  244|  30.2k|   err = MP_OKAY;
  ------------------
  |  |  161|  30.2k|#define MP_OKAY       0   /* no error */
  ------------------
  245|  30.2k|LBL_RES:
  246|  30.2k|   mp_clear(&res);
  247|  30.2k|LBL_M:
  248|  30.2k|   mp_clear(&M[1]);
  249|  1.43M|   for (x = 1<<(winsize-1); x < (1 << winsize); x++) {
  ------------------
  |  Branch (249:29): [True: 1.40M, False: 30.2k]
  ------------------
  250|  1.40M|      mp_clear(&M[x]);
  251|  1.40M|   }
  252|  30.2k|   return err;
  253|  30.2k|}

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

s_mp_montgomery_reduce_fast:
   15|  54.5M|{
   16|  54.5M|   int     ix, olduse;
   17|  54.5M|   mp_err  err;
   18|  54.5M|   mp_word W[MP_WARRAY];
   19|       |
   20|  54.5M|   if (x->used > MP_WARRAY) {
  ------------------
  |  |  172|  54.5M|#define MP_WARRAY PRIVATE_MP_WARRAY
  |  |  ------------------
  |  |  |  |  203|  54.5M|#define PRIVATE_MP_WARRAY (int)(1uLL << (((CHAR_BIT * sizeof(private_mp_word)) - (2 * MP_DIGIT_BIT)) + 1))
  |  |  |  |  ------------------
  |  |  |  |  |  |   82|  54.5M|#   define MP_DIGIT_BIT 60
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (20:8): [True: 0, False: 54.5M]
  ------------------
   21|      0|      return MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
   22|      0|   }
   23|       |
   24|       |   /* get old used count */
   25|  54.5M|   olduse = x->used;
   26|       |
   27|       |   /* grow a as required */
   28|  54.5M|   if (x->alloc < (n->used + 1)) {
  ------------------
  |  Branch (28:8): [True: 0, False: 54.5M]
  ------------------
   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|  54.5M|   {
   38|  54.5M|      mp_word *_W;
   39|  54.5M|      mp_digit *tmpx;
   40|       |
   41|       |      /* alias for the W[] array */
   42|  54.5M|      _W   = W;
   43|       |
   44|       |      /* alias for the digits of  x*/
   45|  54.5M|      tmpx = x->dp;
   46|       |
   47|       |      /* copy the digits of a into W[0..a->used-1] */
   48|  3.65G|      for (ix = 0; ix < x->used; ix++) {
  ------------------
  |  Branch (48:20): [True: 3.59G, False: 54.5M]
  ------------------
   49|  3.59G|         *_W++ = *tmpx++;
   50|  3.59G|      }
   51|       |
   52|       |      /* zero the high words of W[a->used..m->used*2] */
   53|  54.5M|      if (ix < ((n->used * 2) + 1)) {
  ------------------
  |  Branch (53:11): [True: 54.5M, False: 0]
  ------------------
   54|  54.5M|         MP_ZERO_BUFFER(_W, sizeof(mp_word) * (size_t)(((n->used * 2) + 1) - ix));
  ------------------
  |  |   81|  54.5M|#  define MP_ZERO_BUFFER(mem, size)                     \
  |  |   82|  54.5M|do {                                                    \
  |  |   83|  54.5M|   size_t zs_ = (size);                                 \
  |  |   84|  54.5M|   char* zm_ = (char*)(mem);                            \
  |  |   85|  1.79G|   while (zs_-- > 0u) {                                 \
  |  |  ------------------
  |  |  |  Branch (85:11): [True: 1.73G, False: 54.5M]
  |  |  ------------------
  |  |   86|  1.73G|      *zm_++ = '\0';                                    \
  |  |   87|  1.73G|   }                                                    \
  |  |   88|  54.5M|} while (0)
  |  |  ------------------
  |  |  |  Branch (88:10): [Folded, False: 54.5M]
  |  |  ------------------
  ------------------
   55|  54.5M|      }
   56|  54.5M|   }
   57|       |
   58|       |   /* now we proceed to zero successive digits
   59|       |    * from the least significant upwards
   60|       |    */
   61|  1.88G|   for (ix = 0; ix < n->used; ix++) {
  ------------------
  |  Branch (61:17): [True: 1.82G, False: 54.5M]
  ------------------
   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.82G|      mp_digit mu;
   69|  1.82G|      mu = ((W[ix] & MP_MASK) * rho) & MP_MASK;
  ------------------
  |  |  106|  1.82G|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|  1.82G|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
                    mu = ((W[ix] & MP_MASK) * rho) & MP_MASK;
  ------------------
  |  |  106|  1.82G|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|  1.82G|#   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.82G|      {
   86|  1.82G|         int iy;
   87|  1.82G|         mp_digit *tmpn;
   88|  1.82G|         mp_word *_W;
   89|       |
   90|       |         /* alias for the digits of the modulus */
   91|  1.82G|         tmpn = n->dp;
   92|       |
   93|       |         /* Alias for the columns set by an offset of ix */
   94|  1.82G|         _W = W + ix;
   95|       |
   96|       |         /* inner loop */
   97|  65.0G|         for (iy = 0; iy < n->used; iy++) {
  ------------------
  |  Branch (97:23): [True: 63.2G, False: 1.82G]
  ------------------
   98|  63.2G|            *_W++ += (mp_word)mu * (mp_word)*tmpn++;
   99|  63.2G|         }
  100|  1.82G|      }
  101|       |
  102|       |      /* now fix carry for next digit, W[ix+1] */
  103|  1.82G|      W[ix + 1] += W[ix] >> (mp_word)MP_DIGIT_BIT;
  ------------------
  |  |   82|  1.82G|#   define MP_DIGIT_BIT 60
  ------------------
  104|  1.82G|   }
  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|  54.5M|   {
  111|  54.5M|      mp_digit *tmpx;
  112|  54.5M|      mp_word *_W, *_W1;
  113|       |
  114|       |      /* nox fix rest of carries */
  115|       |
  116|       |      /* alias for current word */
  117|  54.5M|      _W1 = W + ix;
  118|       |
  119|       |      /* alias for next word, where the carry goes */
  120|  54.5M|      _W = W + ++ix;
  121|       |
  122|  1.88G|      for (; ix < ((n->used * 2) + 1); ix++) {
  ------------------
  |  Branch (122:14): [True: 1.82G, False: 54.5M]
  ------------------
  123|  1.82G|         *_W++ += *_W1++ >> (mp_word)MP_DIGIT_BIT;
  ------------------
  |  |   82|  1.82G|#   define MP_DIGIT_BIT 60
  ------------------
  124|  1.82G|      }
  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|  54.5M|      tmpx = x->dp;
  135|       |
  136|       |      /* alias for shifted double precision result */
  137|  54.5M|      _W = W + n->used;
  138|       |
  139|  1.93G|      for (ix = 0; ix < (n->used + 1); ix++) {
  ------------------
  |  Branch (139:20): [True: 1.88G, False: 54.5M]
  ------------------
  140|  1.88G|         *tmpx++ = *_W++ & (mp_word)MP_MASK;
  ------------------
  |  |  106|  1.88G|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|  1.88G|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
  141|  1.88G|      }
  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|  54.5M|      MP_ZERO_DIGITS(tmpx, olduse - ix);
  ------------------
  |  |   89|  54.5M|#  define MP_ZERO_DIGITS(mem, digits)                   \
  |  |   90|  54.5M|do {                                                    \
  |  |   91|  54.5M|   int zd_ = (digits);                                  \
  |  |   92|  54.5M|   mp_digit* zm_ = (mem);                               \
  |  |   93|  1.77G|   while (zd_-- > 0) {                                  \
  |  |  ------------------
  |  |  |  Branch (93:11): [True: 1.71G, False: 54.5M]
  |  |  ------------------
  |  |   94|  1.71G|      *zm_++ = 0;                                       \
  |  |   95|  1.71G|   }                                                    \
  |  |   96|  54.5M|} while (0)
  |  |  ------------------
  |  |  |  Branch (96:10): [Folded, False: 54.5M]
  |  |  ------------------
  ------------------
  147|  54.5M|   }
  148|       |
  149|       |   /* set the max used and clamp */
  150|  54.5M|   x->used = n->used + 1;
  151|  54.5M|   mp_clamp(x);
  152|       |
  153|       |   /* if A >= m then A = A - m */
  154|  54.5M|   if (mp_cmp_mag(x, n) != MP_LT) {
  ------------------
  |  |  154|  54.5M|#define MP_LT        -1   /* less than */
  ------------------
  |  Branch (154:8): [True: 3, False: 54.5M]
  ------------------
  155|      3|      return s_mp_sub(x, n, x);
  156|      3|   }
  157|  54.5M|   return MP_OKAY;
  ------------------
  |  |  161|  54.5M|#define MP_OKAY       0   /* no error */
  ------------------
  158|  54.5M|}

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

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

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

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

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

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

buf_put_algolist_all:
  361|  86.9k|void buf_put_algolist_all(buffer * buf, const algo_type localalgos[], int useall) {
  362|  86.9k|	unsigned int i, len;
  363|  86.9k|	unsigned int donefirst = 0;
  364|  86.9k|	unsigned int startpos;
  365|       |
  366|  86.9k|	startpos = buf->pos;
  367|       |	/* Placeholder for length */
  368|  86.9k|	buf_putint(buf, 0); 
  369|   435k|	for (i = 0; localalgos[i].name != NULL; i++) {
  ------------------
  |  Branch (369:14): [True: 348k, False: 86.9k]
  ------------------
  370|   348k|		if (localalgos[i].usable || useall) {
  ------------------
  |  Branch (370:7): [True: 245k, False: 102k]
  |  Branch (370:31): [True: 1.12k, False: 101k]
  ------------------
  371|   246k|			if (donefirst) {
  ------------------
  |  Branch (371:8): [True: 159k, False: 86.9k]
  ------------------
  372|   159k|				buf_putbyte(buf, ',');
  373|   159k|			}
  374|   246k|			donefirst = 1;
  375|   246k|			len = strlen(localalgos[i].name);
  376|   246k|			buf_putbytes(buf, (const unsigned char *) localalgos[i].name, len);
  377|   246k|		}
  378|   348k|	}
  379|       |	/* Fill out the length */
  380|  86.9k|	len = buf->pos - startpos - 4;
  381|  86.9k|	buf_setpos(buf, startpos);
  382|  86.9k|	buf_putint(buf, len);
  383|  86.9k|	TRACE(("algolist add %d '%.*s'", len, len, buf_getptr(buf, len)))
  384|  86.9k|	buf_incrwritepos(buf, len);
  385|  86.9k|}
buf_put_algolist:
  387|  86.8k|void buf_put_algolist(buffer * buf, const algo_type localalgos[]) {
  388|  86.8k|	buf_put_algolist_all(buf, localalgos, 0);
  389|  86.8k|}
buf_has_algo:
  433|  15.8k|int buf_has_algo(buffer *buf, const char *algo) {
  434|  15.8k|	unsigned char* algolist = NULL;
  435|  15.8k|	unsigned int orig_pos = buf->pos;
  436|  15.8k|	unsigned int len, remotecount, i;
  437|  15.8k|	const char *remotenames[MAX_PROPOSED_ALGO];
  438|  15.8k|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  112|  15.8k|#define DROPBEAR_FAILURE -1
  ------------------
  439|       |
  440|  15.8k|	algolist = buf_getstring(buf, &len);
  441|  15.8k|	remotecount = MAX_PROPOSED_ALGO;
  ------------------
  |  |  243|  15.8k|#define MAX_PROPOSED_ALGO 50
  ------------------
  442|  15.8k|	get_algolist(algolist, len, remotenames, &remotecount);
  443|  87.8k|	for (i = 0; i < remotecount; i++)
  ------------------
  |  Branch (443:14): [True: 72.3k, False: 15.4k]
  ------------------
  444|  72.3k|	{
  445|  72.3k|		if (strcmp(remotenames[i], algo) == 0) {
  ------------------
  |  Branch (445:7): [True: 393, False: 71.9k]
  ------------------
  446|    393|			ret = DROPBEAR_SUCCESS;
  ------------------
  |  |  111|    393|#define DROPBEAR_SUCCESS 0
  ------------------
  447|    393|			break;
  448|    393|		}
  449|  72.3k|	}
  450|  15.8k|	if (algolist) {
  ------------------
  |  Branch (450:6): [True: 15.7k, False: 80]
  ------------------
  451|       |		m_free(algolist);
  ------------------
  |  |   24|  15.7k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 15.7k]
  |  |  ------------------
  ------------------
  452|  15.7k|	}
  453|  15.8k|	buf_setpos(buf, orig_pos);
  454|  15.8k|	return ret;
  455|  15.8k|}
buf_match_algo:
  473|  79.0k|		int kexguess2, int *goodguess) {
  474|  79.0k|	char * algolist = NULL;
  475|  79.0k|	const char *remotenames[MAX_PROPOSED_ALGO], *localnames[MAX_PROPOSED_ALGO];
  476|  79.0k|	unsigned int len;
  477|  79.0k|	unsigned int remotecount, localcount, clicount, servcount, i, j;
  478|  79.0k|	algo_type * ret = NULL;
  479|  79.0k|	const char **clinames, **servnames;
  480|       |
  481|  79.0k|	if (goodguess) {
  ------------------
  |  Branch (481:6): [True: 20.0k, False: 58.9k]
  ------------------
  482|  20.0k|		*goodguess = 0;
  483|  20.0k|	}
  484|       |
  485|       |	/* get the comma-separated list from the buffer ie "algo1,algo2,algo3" */
  486|  79.0k|	algolist = buf_getstring(buf, &len);
  487|  79.0k|	DEBUG3(("buf_match_algo: %s", algolist))
  488|  79.0k|	remotecount = MAX_PROPOSED_ALGO;
  ------------------
  |  |  243|  79.0k|#define MAX_PROPOSED_ALGO 50
  ------------------
  489|  79.0k|	get_algolist(algolist, len, remotenames, &remotecount);
  490|       |
  491|   398k|	for (i = 0; localalgos[i].name != NULL; i++) {
  ------------------
  |  Branch (491:14): [True: 319k, False: 79.0k]
  ------------------
  492|   319k|		if (localalgos[i].usable) {
  ------------------
  |  Branch (492:7): [True: 221k, False: 98.4k]
  ------------------
  493|   221k|			localnames[i] = localalgos[i].name;
  494|   221k|		} else {
  495|  98.4k|			localnames[i] = NULL;
  496|  98.4k|		}
  497|   319k|	}
  498|  79.0k|	localcount = i;
  499|       |
  500|  79.0k|	if (IS_DROPBEAR_SERVER) {
  ------------------
  |  |  391|  79.0k|#define IS_DROPBEAR_SERVER (ses.isserver == 1)
  |  |  ------------------
  |  |  |  Branch (391:28): [True: 78.9k, False: 55]
  |  |  ------------------
  ------------------
  501|  78.9k|		clinames = remotenames;
  502|  78.9k|		clicount = remotecount;
  503|  78.9k|		servnames = localnames;
  504|  78.9k|		servcount = localcount;
  505|  78.9k|	} 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|   103k|	for (i = 0; i < clicount; i++) {
  ------------------
  |  Branch (513:14): [True: 99.9k, False: 3.09k]
  ------------------
  514|   440k|		for (j = 0; j < servcount; j++) {
  ------------------
  |  Branch (514:15): [True: 416k, False: 24.0k]
  ------------------
  515|   416k|			if (!(servnames[j] && clinames[i])) {
  ------------------
  |  Branch (515:10): [True: 310k, False: 106k]
  |  Branch (515:26): [True: 310k, False: 0]
  ------------------
  516|       |				/* unusable algos are NULL */
  517|   106k|				continue;
  518|   106k|			}
  519|   310k|			if (strcmp(servnames[j], clinames[i]) == 0) {
  ------------------
  |  Branch (519:8): [True: 75.9k, False: 234k]
  ------------------
  520|       |				/* set if it was a good guess */
  521|  75.9k|				if (goodguess != NULL) {
  ------------------
  |  Branch (521:9): [True: 19.8k, False: 56.1k]
  ------------------
  522|  19.8k|					if (kexguess2) {
  ------------------
  |  Branch (522:10): [True: 325, False: 19.4k]
  ------------------
  523|    325|						if (i == 0) {
  ------------------
  |  Branch (523:11): [True: 233, False: 92]
  ------------------
  524|    233|							*goodguess = 1;
  525|    233|						}
  526|  19.4k|					} else {
  527|  19.4k|						if (i == 0 && j == 0) {
  ------------------
  |  Branch (527:11): [True: 14.9k, False: 4.52k]
  |  Branch (527:21): [True: 4, False: 14.9k]
  ------------------
  528|      4|							*goodguess = 1;
  529|      4|						}
  530|  19.4k|					}
  531|  19.8k|				}
  532|       |				/* set the algo to return */
  533|  75.9k|				if (IS_DROPBEAR_SERVER) {
  ------------------
  |  |  391|  75.9k|#define IS_DROPBEAR_SERVER (ses.isserver == 1)
  |  |  ------------------
  |  |  |  Branch (391:28): [True: 75.9k, False: 0]
  |  |  ------------------
  ------------------
  534|  75.9k|					ret = &localalgos[j];
  535|  75.9k|				} else {
  536|      0|					ret = &localalgos[i];
  537|      0|				}
  538|  75.9k|				goto out;
  539|  75.9k|			}
  540|   310k|		}
  541|  99.9k|	}
  542|       |
  543|  78.9k|out:
  544|       |	m_free(algolist);
  ------------------
  |  |   24|  78.9k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 78.9k]
  |  |  ------------------
  ------------------
  545|  78.9k|	return ret;
  546|  79.0k|}
common-algo.c:void_start:
   52|  8.94k|			int UNUSED(keylen), int UNUSED(num_rounds), void* UNUSED(cipher_state)) {
   53|  8.94k|	return CRYPT_OK;
   54|  8.94k|}
common-algo.c:void_cipher:
   43|   119k|		unsigned long len, void* UNUSED(cipher_state)) {
   44|   119k|	if (in != out) {
  ------------------
  |  Branch (44:6): [True: 0, False: 119k]
  ------------------
   45|      0|		memmove(out, in, len);
   46|      0|	}
   47|   119k|	return CRYPT_OK;
   48|   119k|}
common-algo.c:dropbear_big_endian_ctr_start:
   93|  8.34k|		int num_rounds, symmetric_CTR *ctr) {
   94|  8.34k|	return ctr_start(cipher, IV, key, keylen, num_rounds, CTR_COUNTER_BIG_ENDIAN, ctr);
  ------------------
  |  |  860|  8.34k|#define CTR_COUNTER_BIG_ENDIAN       0x1000
  ------------------
   95|  8.34k|}
common-algo.c:get_algolist:
  396|  94.7k|				const char* *ret_list, unsigned int *ret_count) {
  397|  94.7k|	unsigned int max_count = *ret_count;
  398|  94.7k|	unsigned int i;
  399|       |
  400|  94.7k|	if (*ret_count == 0) {
  ------------------
  |  Branch (400:6): [True: 0, False: 94.7k]
  ------------------
  401|      0|		return;
  402|      0|	}
  403|  94.7k|	if (algolist_len > MAX_PROPOSED_ALGO*(MAX_NAME_LEN+1)) {
  ------------------
  |  |  243|  94.7k|#define MAX_PROPOSED_ALGO 50
  ------------------
              	if (algolist_len > MAX_PROPOSED_ALGO*(MAX_NAME_LEN+1)) {
  ------------------
  |  |  239|  94.7k|#define MAX_NAME_LEN 64 /* maximum length of a protocol name, isn't
  ------------------
  |  Branch (403:6): [True: 8, False: 94.7k]
  ------------------
  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|  94.7k|	ret_list[0] = algolist;
  410|  94.7k|	*ret_count = 1;
  411|  2.32M|	for (i = 0; i < algolist_len; i++) {
  ------------------
  |  Branch (411:14): [True: 2.23M, False: 93.6k]
  ------------------
  412|  2.23M|		if (algolist[i] == '\0') {
  ------------------
  |  Branch (412:7): [True: 1.15k, False: 2.23M]
  ------------------
  413|       |			/* someone is trying something strange */
  414|  1.15k|			*ret_count = 0;
  415|  1.15k|			return;
  416|  1.15k|		}
  417|       |
  418|  2.23M|		if (algolist[i] == ',') {
  ------------------
  |  Branch (418:7): [True: 109k, False: 2.12M]
  ------------------
  419|   109k|			if (*ret_count >= max_count) {
  ------------------
  |  Branch (419:8): [True: 6, False: 109k]
  ------------------
  420|      6|				dropbear_exit("Too many remote algorithms");
  421|      0|				*ret_count = 0;
  422|      0|				return;
  423|      6|			}
  424|   109k|			algolist[i] = '\0';
  425|   109k|			ret_list[*ret_count] = &algolist[i+1];
  426|   109k|			(*ret_count)++;
  427|   109k|		}
  428|  2.23M|	}
  429|  94.7k|}

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

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

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

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|  5.59k|{
  215|  5.59k|  u8 z[32];
  216|  5.59k|  i64 x[80],r,i;
  217|  5.59k|  gf a,b,c,d,e,f;
  218|   173k|  FOR(i,31) z[i]=n[i];
  ------------------
  |  |   34|   178k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 173k, False: 5.59k]
  |  |  ------------------
  ------------------
  219|  5.59k|  z[31]=(n[31]&127)|64;
  220|  5.59k|  z[0]&=248;
  221|  5.59k|  unpack25519(x,p);
  222|  89.4k|  FOR(i,16) {
  ------------------
  |  |   34|  95.0k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 89.4k, False: 5.59k]
  |  |  ------------------
  ------------------
  223|  89.4k|    b[i]=x[i];
  224|  89.4k|    d[i]=a[i]=c[i]=0;
  225|  89.4k|  }
  226|  5.59k|  a[0]=d[0]=1;
  227|  1.43M|  for(i=254;i>=0;--i) {
  ------------------
  |  Branch (227:13): [True: 1.42M, False: 5.59k]
  ------------------
  228|  1.42M|    r=(z[i>>3]>>(i&7))&1;
  229|  1.42M|    sel25519(a,b,r);
  230|  1.42M|    sel25519(c,d,r);
  231|  1.42M|    A(e,a,c);
  232|  1.42M|    Z(a,a,c);
  233|  1.42M|    A(c,b,d);
  234|  1.42M|    Z(b,b,d);
  235|  1.42M|    S(d,e);
  236|  1.42M|    S(f,a);
  237|  1.42M|    M(a,c,a);
  238|  1.42M|    M(c,b,e);
  239|  1.42M|    A(e,a,c);
  240|  1.42M|    Z(a,a,c);
  241|  1.42M|    S(b,a);
  242|  1.42M|    Z(c,d,f);
  243|  1.42M|    M(a,c,_121665);
  244|  1.42M|    A(a,a,d);
  245|  1.42M|    M(c,c,a);
  246|  1.42M|    M(a,d,f);
  247|  1.42M|    M(d,b,x);
  248|  1.42M|    S(b,e);
  249|  1.42M|    sel25519(a,b,r);
  250|  1.42M|    sel25519(c,d,r);
  251|  1.42M|  }
  252|  89.4k|  FOR(i,16) {
  ------------------
  |  |   34|  95.0k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 89.4k, False: 5.59k]
  |  |  ------------------
  ------------------
  253|  89.4k|    x[i+16]=a[i];
  254|  89.4k|    x[i+32]=c[i];
  255|  89.4k|    x[i+48]=b[i];
  256|  89.4k|    x[i+64]=d[i];
  257|  89.4k|  }
  258|  5.59k|  inv25519(x+32,x+32);
  259|  5.59k|  M(x+16,x+16,x+32);
  260|  5.59k|  pack25519(q,x+16);
  261|  5.59k|}
curve25519.c:unpack25519:
  152|  5.59k|{
  153|  5.59k|  int i;
  154|  89.4k|  FOR(i,16) o[i]=n[2*i]+((i64)n[2*i+1]<<8);
  ------------------
  |  |   34|  95.0k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 89.4k, False: 5.59k]
  |  |  ------------------
  ------------------
  155|  5.59k|  o[15]&=0x7fff;
  156|  5.59k|}
curve25519.c:sel25519:
   98|  5.71M|{
   99|  5.71M|  i64 t,i,c=~(b-1);
  100|  91.4M|  FOR(i,16) {
  ------------------
  |  |   34|  97.1M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 91.4M, False: 5.71M]
  |  |  ------------------
  ------------------
  101|  91.4M|    t= c&(p[i]^q[i]);
  102|  91.4M|    p[i]^=t;
  103|  91.4M|    q[i]^=t;
  104|  91.4M|  }
  105|  5.71M|}
curve25519.c:A:
  159|  5.70M|{
  160|  5.70M|  int i;
  161|  91.2M|  FOR(i,16) o[i]=a[i]+b[i];
  ------------------
  |  |   34|  96.9M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 91.2M, False: 5.70M]
  |  |  ------------------
  ------------------
  162|  5.70M|}
curve25519.c:Z:
  165|  5.70M|{
  166|  5.70M|  int i;
  167|  91.2M|  FOR(i,16) o[i]=a[i]-b[i];
  ------------------
  |  |   34|  96.9M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 91.2M, False: 5.70M]
  |  |  ------------------
  ------------------
  168|  5.70M|}
curve25519.c:S:
  182|  7.12M|{
  183|  7.12M|  M(o,a,a);
  184|  7.12M|}
curve25519.c:M:
  171|  17.0M|{
  172|  17.0M|  i64 i,j,t[31];
  173|   530M|  FOR(i,31) t[i]=0;
  ------------------
  |  |   34|   547M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 530M, False: 17.0M]
  |  |  ------------------
  ------------------
  174|  4.37G|  FOR(i,16) FOR(j,16) t[i+j]+=a[i]*b[j];
  ------------------
  |  |   34|   290M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 273M, False: 17.0M]
  |  |  ------------------
  ------------------
                FOR(i,16) FOR(j,16) t[i+j]+=a[i]*b[j];
  ------------------
  |  |   34|  4.65G|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 4.37G, False: 273M]
  |  |  ------------------
  ------------------
  175|   256M|  FOR(i,15) t[i]+=38*t[i+16];
  ------------------
  |  |   34|   273M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 256M, False: 17.0M]
  |  |  ------------------
  ------------------
  176|   273M|  FOR(i,16) o[i]=t[i];
  ------------------
  |  |   34|   290M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 273M, False: 17.0M]
  |  |  ------------------
  ------------------
  177|  17.0M|  car25519(o);
  178|  17.0M|  car25519(o);
  179|  17.0M|}
curve25519.c:car25519:
   86|  34.2M|{
   87|  34.2M|  int i;
   88|  34.2M|  i64 c;
   89|   547M|  FOR(i,16) {
  ------------------
  |  |   34|   581M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 547M, False: 34.2M]
  |  |  ------------------
  ------------------
   90|   547M|    o[i]+=(1LL<<16);
   91|   547M|    c=o[i]>>16;
   92|   547M|    o[(i+1)*(i<15)]+=c-1+37*(c-1)*(i==15);
   93|   547M|    o[i]-=((u64)c)<<16;
   94|   547M|  }
   95|  34.2M|}
curve25519.c:inv25519:
  187|  5.59k|{
  188|  5.59k|  gf c;
  189|  5.59k|  int a;
  190|  89.4k|  FOR(a,16) c[a]=i[a];
  ------------------
  |  |   34|  95.0k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 89.4k, False: 5.59k]
  |  |  ------------------
  ------------------
  191|  1.42M|  for(a=253;a>=0;a--) {
  ------------------
  |  Branch (191:13): [True: 1.42M, False: 5.59k]
  ------------------
  192|  1.42M|    S(c,c);
  193|  1.42M|    if(a!=2&&a!=4) M(c,c,i);
  ------------------
  |  Branch (193:8): [True: 1.41M, False: 5.59k]
  |  Branch (193:14): [True: 1.40M, False: 5.59k]
  ------------------
  194|  1.42M|  }
  195|  89.4k|  FOR(a,16) o[a]=c[a];
  ------------------
  |  |   34|  95.0k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 89.4k, False: 5.59k]
  |  |  ------------------
  ------------------
  196|  5.59k|}
curve25519.c:pack25519:
  108|  5.59k|{
  109|  5.59k|  int i,j,b;
  110|  5.59k|  gf m,t;
  111|  89.4k|  FOR(i,16) t[i]=n[i];
  ------------------
  |  |   34|  95.0k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 89.4k, False: 5.59k]
  |  |  ------------------
  ------------------
  112|  5.59k|  car25519(t);
  113|  5.59k|  car25519(t);
  114|  5.59k|  car25519(t);
  115|  11.1k|  FOR(j,2) {
  ------------------
  |  |   34|  16.7k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 11.1k, False: 5.59k]
  |  |  ------------------
  ------------------
  116|  11.1k|    m[0]=t[0]-0xffed;
  117|   167k|    for(i=1;i<15;i++) {
  ------------------
  |  Branch (117:13): [True: 156k, False: 11.1k]
  ------------------
  118|   156k|      m[i]=t[i]-0xffff-((m[i-1]>>16)&1);
  119|   156k|      m[i-1]&=0xffff;
  120|   156k|    }
  121|  11.1k|    m[15]=t[15]-0x7fff-((m[14]>>16)&1);
  122|  11.1k|    b=(m[15]>>16)&1;
  123|  11.1k|    m[14]&=0xffff;
  124|  11.1k|    sel25519(t,m,1-b);
  125|  11.1k|  }
  126|  89.4k|  FOR(i,16) {
  ------------------
  |  |   34|  95.0k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 89.4k, False: 5.59k]
  |  |  ------------------
  ------------------
  127|  89.4k|    o[2*i]=t[i]&0xff;
  128|  89.4k|    o[2*i+1]=t[i]>>8;
  129|  89.4k|  }
  130|  5.59k|}

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

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

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

dropbear_close:
   95|  1.45k|void dropbear_close(const char* format, ...) {
   96|       |
   97|  1.45k|	va_list param;
   98|       |
   99|  1.45k|	va_start(param, format);
  100|  1.45k|	_dropbear_exit(EXIT_SUCCESS, format, param);
  101|  1.45k|	va_end(param);
  102|       |
  103|      0|}
dropbear_exit:
  105|  2.00k|void dropbear_exit(const char* format, ...) {
  106|       |
  107|  2.00k|	va_list param;
  108|       |
  109|  2.00k|	va_start(param, format);
  110|  2.00k|	_dropbear_exit(EXIT_FAILURE, format, param);
  111|  2.00k|	va_end(param);
  112|      0|}
dropbear_log:
  148|  3.90k|void dropbear_log(int priority, const char* format, ...) {
  149|       |
  150|  3.90k|	va_list param;
  151|       |
  152|  3.90k|	va_start(param, format);
  153|  3.90k|	_dropbear_log(priority, format, param);
  154|       |	va_end(param);
  155|  3.90k|}
m_close:
  615|  1.45k|void m_close(int fd) {
  616|  1.45k|	int val;
  617|       |
  618|  1.45k|	if (fd < 0) {
  ------------------
  |  Branch (618:6): [True: 0, False: 1.45k]
  ------------------
  619|      0|		return;
  620|      0|	}
  621|       |
  622|  1.45k|	do {
  623|  1.45k|		val = close(fd);
  ------------------
  |  |   56|  1.45k|#define close(fd) wrapfd_close(fd)
  ------------------
  624|  1.45k|	} while (val < 0 && errno == EINTR);
  ------------------
  |  Branch (624:11): [True: 0, False: 1.45k]
  |  Branch (624:22): [True: 0, False: 0]
  ------------------
  625|       |
  626|  1.45k|	if (val < 0 && errno != EBADF) {
  ------------------
  |  Branch (626:6): [True: 0, False: 1.45k]
  |  Branch (626:17): [True: 0, False: 0]
  ------------------
  627|       |		/* Linux says EIO can happen */
  628|       |		dropbear_exit("Error closing fd %d, %s", fd, strerror(errno));
  629|      0|	}
  630|  1.45k|}
setnonblocking:
  632|  6.92k|void setnonblocking(int fd) {
  633|       |
  634|  6.92k|	int fl = 0;
  635|  6.92k|	TRACE(("setnonblocking: %d", fd))
  636|       |
  637|  6.92k|#if DROPBEAR_FUZZ
  638|  6.92k|	if (fuzz.fuzzing) {
  ------------------
  |  Branch (638:6): [True: 6.92k, False: 0]
  ------------------
  639|  6.92k|		return;
  640|  6.92k|	}
  641|      0|#endif
  642|      0|	fl = fcntl(fd, F_GETFL, 0);
  643|      0|	if (fl == -1) {
  ------------------
  |  Branch (643:6): [True: 0, False: 0]
  ------------------
  644|       |		/* F_GETFL shouldn't fail */
  645|      0|		dropbear_exit("Couldn't set nonblocking");
  646|      0|	}
  647|       |
  648|      0|	if (fcntl(fd, F_SETFL, fl | O_NONBLOCK) == -1) {
  ------------------
  |  Branch (648:6): [True: 0, False: 0]
  ------------------
  649|      0|		if (errno == ENODEV) {
  ------------------
  |  Branch (649:7): [True: 0, False: 0]
  ------------------
  650|       |			/* Some devices (like /dev/null redirected in)
  651|       |			 * can't be set to non-blocking */
  652|      0|			TRACE(("ignoring ENODEV for setnonblocking"))
  653|      0|		} else {
  654|      0|			dropbear_exit("Couldn't set nonblocking");
  655|      0|		}
  656|      0|	}
  657|      0|	TRACE(("leave setnonblocking"))
  658|      0|}
disallow_core:
  660|      1|void disallow_core() {
  661|      1|	struct rlimit lim = {0};
  662|      1|	if (getrlimit(RLIMIT_CORE, &lim) < 0) {
  ------------------
  |  Branch (662:6): [True: 0, False: 1]
  ------------------
  663|      0|		TRACE(("getrlimit(RLIMIT_CORE) failed"));
  664|      0|	}
  665|      1|	lim.rlim_cur = 0;
  666|      1|	if (setrlimit(RLIMIT_CORE, &lim) < 0) {
  ------------------
  |  Branch (666:6): [True: 0, False: 1]
  ------------------
  667|      0|		TRACE(("setrlimit(RLIMIT_CORE) failed"));
  668|      0|	}
  669|      1|}
expand_homedir_path_home:
  697|      1|char * expand_homedir_path_home(const char *inpath, const char *homedir) {
  698|      1|	if (strncmp(inpath, "~/", 2) == 0 && homedir) {
  ------------------
  |  Branch (698:6): [True: 0, False: 1]
  |  Branch (698:39): [True: 0, False: 0]
  ------------------
  699|      0|		size_t len = strlen(inpath)-2 + strlen(homedir) + 2;
  700|      0|		char *buf = m_malloc(len);
  701|      0|		snprintf(buf, len, "%s/%s", homedir, inpath+2);
  702|      0|		return buf;
  703|      0|	}
  704|       |	/* Fallback */
  705|      1|	return m_strdup(inpath);
  706|      1|}
expand_homedir_path:
  710|      1|char * expand_homedir_path(const char *inpath) {
  711|      1|	struct passwd *pw = NULL;
  712|      1|	char *homedir = getenv("HOME");
  713|       |
  714|      1|	if (!homedir) {
  ------------------
  |  Branch (714:6): [True: 0, False: 1]
  ------------------
  715|      0|		pw = getpwuid(getuid());
  ------------------
  |  |  109|      0|#define getpwuid(x) fuzz_getpwuid(x)
  ------------------
  716|      0|		if (pw) {
  ------------------
  |  Branch (716:7): [True: 0, False: 0]
  ------------------
  717|      0|			homedir = pw->pw_dir;
  718|      0|		}
  719|      0|	}
  720|      1|	return expand_homedir_path_home(inpath, homedir);
  721|      1|}
constant_time_memcmp:
  724|  2.78k|{
  725|  2.78k|	const char *xa = a, *xb = b;
  726|  2.78k|	uint8_t c = 0;
  727|  2.78k|	size_t i;
  728|  92.0k|	for (i = 0; i < n; i++)
  ------------------
  |  Branch (728:14): [True: 89.2k, False: 2.78k]
  ------------------
  729|  89.2k|	{
  730|  89.2k|		c |= (xa[i] ^ xb[i]);
  731|  89.2k|	}
  732|  2.78k|	return c;
  733|  2.78k|}
gettime_wrapper:
  736|   728k|void gettime_wrapper(struct timespec *now) {
  737|   728k|	struct timeval tv;
  738|   728k|#if DROPBEAR_FUZZ
  739|   728k|	if (fuzz.fuzzing) {
  ------------------
  |  Branch (739:6): [True: 728k, False: 0]
  ------------------
  740|       |		/* time stands still when fuzzing */
  741|   728k|		now->tv_sec = 5;
  742|   728k|		now->tv_nsec = 0;
  743|   728k|	}
  744|   728k|#endif
  745|       |
  746|   728k|#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
  747|       |	/* POSIX monotonic clock. Newer Linux, BSD, MacOSX >10.12 */
  748|   728k|	if (clock_gettime(CLOCK_MONOTONIC, now) == 0) {
  ------------------
  |  Branch (748:6): [True: 728k, False: 0]
  ------------------
  749|   728k|		return;
  750|   728k|	}
  751|      0|#endif
  752|       |
  753|      0|#if defined(__linux__) && defined(SYS_clock_gettime)
  754|      0|	{
  755|       |	/* Old linux toolchain - kernel might support it but not the build headers */
  756|       |	/* Also glibc <2.17 requires -lrt which we neglect to add */
  757|      0|	static int linux_monotonic_failed = 0;
  758|      0|	if (!linux_monotonic_failed) {
  ------------------
  |  Branch (758:6): [True: 0, False: 0]
  ------------------
  759|       |		/* CLOCK_MONOTONIC isn't in some headers */
  760|      0|		int clock_source_monotonic = 1; 
  761|      0|		if (syscall(SYS_clock_gettime, clock_source_monotonic, now) == 0) {
  ------------------
  |  Branch (761:7): [True: 0, False: 0]
  ------------------
  762|      0|			return;
  763|      0|		} else {
  764|       |			/* Don't try again */
  765|      0|			linux_monotonic_failed = 1;
  766|      0|		}
  767|      0|	}
  768|      0|	}
  769|      0|#endif /* linux fallback clock_gettime */
  770|       |
  771|       |#if defined(HAVE_MACH_ABSOLUTE_TIME)
  772|       |	{
  773|       |	/* OS X pre 10.12, see https://developer.apple.com/library/mac/qa/qa1398/_index.html */
  774|       |	static mach_timebase_info_data_t timebase_info;
  775|       |	uint64_t scaled_time;
  776|       |	if (timebase_info.denom == 0) {
  777|       |		mach_timebase_info(&timebase_info);
  778|       |	}
  779|       |	scaled_time = mach_absolute_time() * timebase_info.numer / timebase_info.denom;
  780|       |	now->tv_sec = scaled_time / 1000000000;
  781|       |	now->tv_nsec = scaled_time % 1000000000;
  782|       |	}
  783|       |#endif /* osx mach_absolute_time */
  784|       |
  785|       |	/* Fallback for everything else - this will sometimes go backwards */
  786|      0|	gettimeofday(&tv, NULL);
  787|      0|	now->tv_sec = tv.tv_sec;
  788|      0|	now->tv_nsec = 1000*(long)tv.tv_usec;
  789|      0|}
monotonic_now:
  792|   727k|time_t monotonic_now() {
  793|   727k|	struct timespec ts;
  794|   727k|	gettime_wrapper(&ts);
  795|   727k|	return ts.tv_sec;
  796|   727k|}
dropbear_fd_set:
  837|   349k|void dropbear_fd_set(int fd, fd_set *set) {
  838|   349k|	if (fd < 0) {
  ------------------
  |  Branch (838:6): [True: 0, False: 349k]
  ------------------
  839|      0|		return;
  840|      0|	}
  841|   349k|	if (fd >= FD_SETSIZE) {
  ------------------
  |  Branch (841:6): [True: 0, False: 349k]
  ------------------
  842|      0|		dropbear_exit("fd limit %d", fd);
  843|      0|	}
  844|   349k|	FD_SET(fd, set);
  845|   349k|}

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);
  ------------------
  |  |   86|      1|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (86:37): [True: 0, False: 1]
  |  |  |  Branch (86: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);
  ------------------
  |  |   86|      1|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (86:37): [True: 0, False: 1]
  |  |  |  Branch (86: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|    277|ecc_key * buf_get_ecc_raw_pubkey(buffer *buf, const struct dropbear_ecc_curve *curve) {
  148|    277|	ecc_key *key = NULL;
  149|    277|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  112|    277|#define DROPBEAR_FAILURE -1
  ------------------
  150|    277|	const unsigned int size = curve->dp->size;
  151|    277|	unsigned char first;
  152|       |
  153|    277|	TRACE(("enter buf_get_ecc_raw_pubkey"))
  154|       |
  155|    277|	buf_setpos(buf, 0);
  156|    277|	first = buf_getbyte(buf);
  157|    277|	if (first == 2 || first == 3) {
  ------------------
  |  Branch (157:6): [True: 37, False: 240]
  |  Branch (157:20): [True: 80, False: 160]
  ------------------
  158|    114|		dropbear_log(LOG_WARNING, "Dropbear doesn't support ECC point compression");
  159|    114|		return NULL;
  160|    114|	}
  161|    163|	if (first != 4 || buf->len != 1+2*size) {
  ------------------
  |  Branch (161:6): [True: 133, False: 30]
  |  Branch (161:20): [True: 29, False: 1]
  ------------------
  162|    159|		TRACE(("leave, wrong size"))
  163|    159|		return NULL;
  164|    159|	}
  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|  27.1k|{
   12|  27.1k|	return type == DROPBEAR_SIGNKEY_ECDSA_NISTP256
  ------------------
  |  Branch (12:9): [True: 1, False: 27.1k]
  ------------------
   13|  27.1k|		|| type == DROPBEAR_SIGNKEY_ECDSA_NISTP384
  ------------------
  |  Branch (13:6): [True: 0, False: 27.1k]
  ------------------
   14|  27.1k|		|| type == DROPBEAR_SIGNKEY_ECDSA_NISTP521;
  ------------------
  |  Branch (14:6): [True: 0, False: 27.1k]
  ------------------
   15|  27.1k|}
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 (strcmp((char*)identifier, (*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);
  ------------------
  |  |   86|      1|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (86:37): [True: 0, False: 1]
  |  |  |  Branch (86: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.21k|struct kex_dh_param *gen_kexdh_param() {
   22|  6.21k|    struct kex_dh_param *param = NULL;
   23|       |
   24|  6.21k|    DEF_MP_INT(dh_p);
  ------------------
  |  |   83|  6.21k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
   25|  6.21k|    DEF_MP_INT(dh_q);
  ------------------
  |  |   83|  6.21k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
   26|  6.21k|    DEF_MP_INT(dh_g);
  ------------------
  |  |   83|  6.21k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
   27|       |
   28|  6.21k|    TRACE(("enter gen_kexdh_vals"))
   29|       |
   30|  6.21k|    param = m_malloc(sizeof(*param));
   31|  6.21k|    m_mp_init_multi(&param->pub, &param->priv, &dh_g, &dh_p, &dh_q, NULL);
   32|       |
   33|       |    /* read the prime and generator*/
   34|  6.21k|    load_dh_p(&dh_p);
   35|       |    
   36|  6.21k|    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.21k|    if (mp_sub_d(&dh_p, 1, &param->priv) != MP_OKAY) { 
  ------------------
  |  |  161|  6.21k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (40:9): [True: 0, False: 6.21k]
  ------------------
   41|      0|        dropbear_exit("Diffie-Hellman error");
   42|      0|    }
   43|  6.21k|    if (mp_div_2(&param->priv, &dh_q) != MP_OKAY) {
  ------------------
  |  |  161|  6.21k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (43:9): [True: 0, False: 6.21k]
  ------------------
   44|      0|        dropbear_exit("Diffie-Hellman error");
   45|      0|    }
   46|       |
   47|       |    /* Generate a private portion 0 < dh_priv < dh_q */
   48|  6.21k|    gen_random_mpint(&dh_q, &param->priv);
   49|       |
   50|       |    /* f = g^y mod p */
   51|  6.21k|    if (mp_exptmod(&dh_g, &param->priv, &dh_p, &param->pub) != MP_OKAY) {
  ------------------
  |  |  161|  6.21k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (51:9): [True: 0, False: 6.21k]
  ------------------
   52|      0|        dropbear_exit("Diffie-Hellman error");
   53|      0|    }
   54|  6.21k|    mp_clear_multi(&dh_g, &dh_p, &dh_q, NULL);
   55|  6.21k|    return param;
   56|  6.21k|}
free_kexdh_param:
   59|  6.15k|{
   60|  6.15k|    mp_clear_multi(&param->pub, &param->priv, NULL);
   61|       |    m_free(param);
  ------------------
  |  |   24|  6.15k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 6.15k]
  |  |  ------------------
  ------------------
   62|  6.15k|}
kexdh_comb_key:
   69|  6.21k|        sign_key *hostkey) {
   70|       |
   71|  6.21k|    DEF_MP_INT(dh_p);
  ------------------
  |  |   83|  6.21k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
   72|  6.21k|    DEF_MP_INT(dh_p_min1);
  ------------------
  |  |   83|  6.21k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
   73|  6.21k|    mp_int *dh_e = NULL, *dh_f = NULL;
   74|       |
   75|  6.21k|    m_mp_init_multi(&dh_p, &dh_p_min1, NULL);
   76|  6.21k|    load_dh_p(&dh_p);
   77|       |
   78|  6.21k|    if (mp_sub_d(&dh_p, 1, &dh_p_min1) != MP_OKAY) { 
  ------------------
  |  |  161|  6.21k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (78:9): [True: 0, False: 6.21k]
  ------------------
   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.21k|    if (mp_cmp(dh_pub_them, &dh_p_min1) != MP_LT 
  ------------------
  |  |  154|  12.4k|#define MP_LT        -1   /* less than */
  ------------------
  |  Branch (83:9): [True: 3, False: 6.21k]
  ------------------
   84|  6.21k|            || mp_cmp_d(dh_pub_them, 1) != MP_GT) {
  ------------------
  |  |  156|  6.21k|#define MP_GT         1   /* greater than */
  ------------------
  |  Branch (84:16): [True: 55, False: 6.15k]
  ------------------
   85|     58|        dropbear_exit("Diffie-Hellman error");
   86|     58|    }
   87|       |    
   88|       |    /* K = e^y mod p = f^x mod p */
   89|  6.15k|    m_mp_alloc_init_multi(&ses.dh_K, NULL);
   90|  6.15k|    if (mp_exptmod(dh_pub_them, &param->priv, &dh_p, ses.dh_K) != MP_OKAY) {
  ------------------
  |  |  161|  6.15k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (90:9): [True: 0, False: 6.15k]
  ------------------
   91|      0|        dropbear_exit("Diffie-Hellman error");
   92|      0|    }
   93|       |
   94|       |    /* clear no longer needed vars */
   95|  6.15k|    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.15k|    if (IS_DROPBEAR_CLIENT) {
  ------------------
  |  |  392|  6.15k|#define IS_DROPBEAR_CLIENT (ses.isserver == 0)
  |  |  ------------------
  |  |  |  Branch (392:28): [True: 0, False: 6.15k]
  |  |  ------------------
  ------------------
  100|      0|        dh_e = &param->pub;
  101|      0|        dh_f = dh_pub_them;
  102|  6.15k|    } else {
  103|  6.15k|        dh_e = dh_pub_them;
  104|  6.15k|        dh_f = &param->pub;
  105|  6.15k|    } 
  106|       |
  107|       |    /* Create the remainder of the hash buffer, to generate the exchange hash */
  108|       |    /* K_S, the host key */
  109|  6.15k|    buf_put_pub_key(ses.kexhashbuf, hostkey, ses.newkeys->algo_hostkey);
  110|       |    /* e, exchange value sent by the client */
  111|  6.15k|    buf_putmpint(ses.kexhashbuf, dh_e);
  112|       |    /* f, exchange value sent by the server */
  113|  6.15k|    buf_putmpint(ses.kexhashbuf, dh_f);
  114|       |    /* K, the shared secret */
  115|  6.15k|    buf_putmpint(ses.kexhashbuf, ses.dh_K);
  116|       |
  117|       |    /* calculate the hash H to sign */
  118|  6.15k|    finish_kexhashbuf();
  119|  6.15k|}
kex-dh.c:load_dh_p:
   13|  12.4k|{
   14|  12.4k|    bytes_to_mp(dh_p, ses.newkeys->algo_kex->dh_p_bytes, 
   15|  12.4k|        ses.newkeys->algo_kex->dh_p_len);
   16|  12.4k|}

gen_kexecdh_param:
   11|    276|struct kex_ecdh_param *gen_kexecdh_param() {
   12|    276|    struct kex_ecdh_param *param = m_malloc(sizeof(*param));
   13|    276|    const struct dropbear_ecc_curve *curve = ses.newkeys->algo_kex->details;
   14|    276|    if (ecc_make_key_ex(NULL, dropbear_ltc_prng, 
  ------------------
  |  Branch (14:9): [True: 0, False: 276]
  ------------------
   15|    276|        &param->key, curve->dp) != CRYPT_OK) {
   16|      0|        dropbear_exit("ECC error");
   17|      0|    }
   18|    276|    return param;
   19|    276|}
kexecdh_comb_key:
   27|    276|        sign_key *hostkey) {
   28|    276|    const struct dropbear_ecc_curve *curve
   29|    276|        = ses.newkeys->algo_kex->details;
   30|       |    /* public keys from client and server */
   31|    276|    ecc_key *Q_C, *Q_S, *Q_them;
   32|       |
   33|    276|    Q_them = buf_get_ecc_raw_pubkey(pub_them, curve);
   34|    276|    if (Q_them == NULL) {
  ------------------
  |  Branch (34:9): [True: 273, False: 3]
  ------------------
   35|    273|        dropbear_exit("ECC error");
   36|    273|    }
   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) {
  ------------------
  |  |  392|      3|#define IS_DROPBEAR_CLIENT (ses.isserver == 0)
  |  |  ------------------
  |  |  |  Branch (392: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) {
  ------------------
  |  |  392|      2|#define IS_DROPBEAR_CLIENT (ses.isserver == 0)
  |  |  ------------------
  |  |  |  Branch (392: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) {
  ------------------
  |  |  392|      2|#define IS_DROPBEAR_CLIENT (ses.isserver == 0)
  |  |  ------------------
  |  |  |  Branch (392: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) {
  ------------------
  |  |  392|      2|#define IS_DROPBEAR_CLIENT (ses.isserver == 0)
  |  |  ------------------
  |  |  |  Branch (392: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) {
  ------------------
  |  |  392|      0|#define IS_DROPBEAR_CLIENT (ses.isserver == 0)
  |  |  ------------------
  |  |  |  Branch (392: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|  2.80k|struct kex_curve25519_param *gen_kexcurve25519_param() {
   15|       |    /* Per http://cr.yp.to/ecdh.html */
   16|  2.80k|    struct kex_curve25519_param *param = m_malloc(sizeof(*param));
   17|  2.80k|    const unsigned char basepoint[32] = {9};
   18|       |
   19|  2.80k|    genrandom(param->priv, CURVE25519_LEN);
  ------------------
  |  |  122|  2.80k|#define CURVE25519_LEN 32
  ------------------
   20|  2.80k|    dropbear_curve25519_scalarmult(param->pub, param->priv, basepoint);
   21|       |
   22|  2.80k|    return param;
   23|  2.80k|}
free_kexcurve25519_param:
   25|  2.78k|void free_kexcurve25519_param(struct kex_curve25519_param *param) {
   26|  2.78k|    m_burn(param->priv, CURVE25519_LEN);
  ------------------
  |  |  122|  2.78k|#define CURVE25519_LEN 32
  ------------------
   27|       |    m_free(param);
  ------------------
  |  |   24|  2.78k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 2.78k]
  |  |  ------------------
  ------------------
   28|  2.78k|}
kexcurve25519_derive:
   32|  2.80k|    unsigned char *out) {
   33|  2.80k|    char zeroes[CURVE25519_LEN] = {0};
   34|  2.80k|    if (buf_pub_them->len != CURVE25519_LEN)
  ------------------
  |  |  122|  2.80k|#define CURVE25519_LEN 32
  ------------------
  |  Branch (34:9): [True: 15, False: 2.78k]
  ------------------
   35|     15|    {
   36|     15|        dropbear_exit("Bad curve25519");
   37|     15|    }
   38|       |
   39|  2.78k|    dropbear_curve25519_scalarmult(out, param->priv, buf_pub_them->data);
   40|       |
   41|  2.78k|    if (constant_time_memcmp(zeroes, out, CURVE25519_LEN) == 0) {
  ------------------
  |  |  122|  2.78k|#define CURVE25519_LEN 32
  ------------------
  |  Branch (41:9): [True: 1, False: 2.78k]
  ------------------
   42|      1|        dropbear_exit("Bad curve25519");
   43|      1|    }
   44|  2.78k|}
kexcurve25519_comb_key:
   52|  2.80k|    sign_key *hostkey) {
   53|  2.80k|    unsigned char out[CURVE25519_LEN];
   54|  2.80k|    const unsigned char* Q_C = NULL;
   55|  2.80k|    const unsigned char* Q_S = NULL;
   56|       |
   57|  2.80k|    kexcurve25519_derive(param, buf_pub_them, out);
   58|       |
   59|  2.80k|    m_mp_alloc_init_multi(&ses.dh_K, NULL);
   60|  2.80k|    bytes_to_mp(ses.dh_K, out, CURVE25519_LEN);
  ------------------
  |  |  122|  2.80k|#define CURVE25519_LEN 32
  ------------------
   61|  2.80k|    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|  2.80k|    if (IS_DROPBEAR_CLIENT) {
  ------------------
  |  |  392|  2.80k|#define IS_DROPBEAR_CLIENT (ses.isserver == 0)
  |  |  ------------------
  |  |  |  Branch (392:28): [True: 0, False: 2.80k]
  |  |  ------------------
  ------------------
   66|      0|        Q_C = param->pub;
   67|      0|        Q_S = buf_pub_them->data;
   68|  2.80k|    } else {
   69|  2.80k|        Q_S = param->pub;
   70|  2.80k|        Q_C = buf_pub_them->data;
   71|  2.80k|    }
   72|       |
   73|       |    /* K_S, the host key */
   74|  2.80k|    buf_put_pub_key(ses.kexhashbuf, hostkey, ses.newkeys->algo_hostkey);
   75|       |    /* Q_C, client's ephemeral public key octet string */
   76|  2.80k|    buf_putstring(ses.kexhashbuf, (const char*)Q_C, CURVE25519_LEN);
  ------------------
  |  |  122|  2.80k|#define CURVE25519_LEN 32
  ------------------
   77|       |    /* Q_S, server's ephemeral public key octet string */
   78|  2.80k|    buf_putstring(ses.kexhashbuf, (const char*)Q_S, CURVE25519_LEN);
  ------------------
  |  |  122|  2.80k|#define CURVE25519_LEN 32
  ------------------
   79|       |    /* K, the shared secret */
   80|  2.80k|    buf_putmpint(ses.kexhashbuf, ses.dh_K);
   81|       |
   82|       |    /* calculate the hash H to sign */
   83|  2.80k|    finish_kexhashbuf();
   84|  2.80k|}

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

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

remove_connect_pending:
  291|  3.46k|void remove_connect_pending() {
  292|  3.46k|	while (ses.conn_pending.first) {
  ------------------
  |  Branch (292:9): [True: 0, False: 3.46k]
  ------------------
  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.46k|}
set_connect_fds:
  299|   273k|void set_connect_fds(fd_set *writefd) {
  300|   273k|	m_list_elem *iter;
  301|   273k|	iter = ses.conn_pending.first;
  302|   273k|	while (iter) {
  ------------------
  |  Branch (302:9): [True: 0, False: 273k]
  ------------------
  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|			dropbear_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|   273k|}
handle_connect_fds:
  323|   270k|void handle_connect_fds(const fd_set *writefd) {
  324|   270k|	m_list_elem *iter;
  325|   270k|	for (iter = ses.conn_pending.first; iter; iter = iter->next) {
  ------------------
  |  Branch (325:38): [True: 0, False: 270k]
  ------------------
  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|   270k|}
packet_queue_to_iovec:
  364|  50.9k|void packet_queue_to_iovec(const struct Queue *queue, struct iovec *iov, unsigned int *iov_count) {
  365|  50.9k|	struct Link *l;
  366|  50.9k|	unsigned int i;
  367|  50.9k|	int len;
  368|  50.9k|	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|  50.9k|	*iov_count = MIN(MIN(queue->count, IOV_MAX), *iov_count);
  ------------------
  |  Branch (380:15): [True: 50.9k, False: 0]
  |  Branch (380:15): [True: 50.9k, False: 0]
  |  Branch (380:15): [True: 50.9k, False: 0]
  ------------------
  381|       |
  382|   114k|	for (l = queue->head, i = 0; i < *iov_count; l = l->link, i++)
  ------------------
  |  Branch (382:31): [True: 63.6k, False: 50.9k]
  ------------------
  383|  63.6k|	{
  384|  63.6k|		writebuf = (buffer*)l->item;
  385|  63.6k|		len = writebuf->len - writebuf->pos;
  386|  63.6k|		dropbear_assert(len > 0);
  ------------------
  |  |   86|  63.6k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (86:37): [True: 0, False: 63.6k]
  |  |  |  Branch (86:93): [Folded, False: 63.6k]
  |  |  ------------------
  ------------------
  387|  63.6k|		TRACE2(("write_packet writev #%d len %d/%d", i,
  388|  63.6k|				len, writebuf->len))
  389|  63.6k|		iov[i].iov_base = buf_getptr(writebuf, len);
  390|  63.6k|		iov[i].iov_len = len;
  391|  63.6k|	}
  392|  50.9k|}
packet_queue_consume:
  394|  50.9k|void packet_queue_consume(struct Queue *queue, ssize_t written) {
  395|  50.9k|	buffer *writebuf;
  396|  50.9k|	int len;
  397|   101k|	while (written > 0) {
  ------------------
  |  Branch (397:9): [True: 50.9k, False: 50.9k]
  ------------------
  398|  50.9k|		writebuf = (buffer*)examine(queue);
  399|  50.9k|		len = writebuf->len - writebuf->pos;
  400|  50.9k|		if (len > written) {
  ------------------
  |  Branch (400:7): [True: 0, False: 50.9k]
  ------------------
  401|       |			/* partial buffer write */
  402|      0|			buf_incrpos(writebuf, written);
  403|      0|			written = 0;
  404|  50.9k|		} else {
  405|  50.9k|			written -= len;
  406|  50.9k|			dequeue(queue);
  407|  50.9k|			buf_free(writebuf);
  408|  50.9k|		}
  409|  50.9k|	}
  410|  50.9k|}
set_sock_priority:
  430|  3.46k|void set_sock_priority(int sock, enum dropbear_prio prio) {
  431|       |
  432|  3.46k|	int rc;
  433|  3.46k|	int val;
  434|       |
  435|  3.46k|#if DROPBEAR_FUZZ
  436|  3.46k|	if (fuzz.fuzzing) {
  ------------------
  |  Branch (436:6): [True: 3.46k, False: 0]
  ------------------
  437|  3.46k|		TRACE(("fuzzing skips set_sock_prio"))
  438|  3.46k|		return;
  439|  3.46k|	}
  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.92k|{
  684|  6.92k|	struct sockaddr_storage addr;
  685|  6.92k|	socklen_t addrlen;
  686|       |
  687|  6.92k|#if DROPBEAR_FUZZ
  688|  6.92k|	if (fuzz.fuzzing) {
  ------------------
  |  Branch (688:6): [True: 6.92k, False: 0]
  ------------------
  689|  6.92k|		fuzz_get_socket_address(fd, local_host, local_port, remote_host, remote_port, host_lookup);
  690|  6.92k|		return;
  691|  6.92k|	}
  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|  50.9k|void write_packet() {
   59|       |
   60|  50.9k|	ssize_t written;
   61|  50.9k|#if defined(HAVE_WRITEV) && (defined(IOV_MAX) || defined(UIO_MAXIOV))
   62|       |	/* 50 is somewhat arbitrary */
   63|  50.9k|	unsigned int iov_count = 50;
   64|  50.9k|	struct iovec iov[50];
   65|       |#else
   66|       |	int len;
   67|       |	buffer* writebuf;
   68|       |#endif
   69|       |	
   70|  50.9k|	TRACE2(("enter write_packet"))
   71|  50.9k|	dropbear_assert(!isempty(&ses.writequeue));
  ------------------
  |  |   86|  50.9k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (86:37): [True: 0, False: 50.9k]
  |  |  |  Branch (86:93): [Folded, False: 50.9k]
  |  |  ------------------
  ------------------
   72|       |
   73|  50.9k|#if defined(HAVE_WRITEV) && (defined(IOV_MAX) || defined(UIO_MAXIOV))
   74|       |
   75|  50.9k|	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|  50.9k|#if DROPBEAR_FUZZ
   80|  50.9k|	if (fuzz.fuzzing) {
  ------------------
  |  Branch (80:6): [True: 50.9k, False: 0]
  ------------------
   81|       |		/* pretend to write one packet at a time */
   82|       |		/* TODO(fuzz): randomise amount written based on the fuzz input */
   83|  50.9k|		written = iov[0].iov_len;
   84|  50.9k|	}
   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|  50.9k|	packet_queue_consume(&ses.writequeue, written);
  100|  50.9k|	ses.writequeue_len -= written;
  101|       |
  102|  50.9k|	if (written == 0) {
  ------------------
  |  Branch (102:6): [True: 0, False: 50.9k]
  ------------------
  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|  50.9k|	TRACE2(("leave write_packet"))
  145|  50.9k|}
read_packet:
  150|   249k|void read_packet() {
  151|       |
  152|   249k|	int len;
  153|   249k|	unsigned int maxlen;
  154|   249k|	unsigned char blocksize;
  155|       |
  156|   249k|	TRACE2(("enter read_packet"))
  157|   249k|	blocksize = ses.keys->recv.algo_crypt->blocksize;
  158|       |	
  159|   249k|	if (ses.readbuf == NULL || ses.readbuf->len < blocksize) {
  ------------------
  |  Branch (159:6): [True: 51.0k, False: 198k]
  |  Branch (159:29): [True: 93.9k, False: 104k]
  ------------------
  160|   145k|		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|   145k|		ret = read_packet_init();
  166|       |
  167|   145k|		if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  112|   145k|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (167:7): [True: 93.9k, False: 51.0k]
  ------------------
  168|       |			/* didn't read enough to determine the length */
  169|  93.9k|			TRACE2(("leave read_packet: packetinit done"))
  170|  93.9k|			return;
  171|  93.9k|		}
  172|   145k|	}
  173|       |
  174|       |	/* Attempt to read the remainder of the packet, note that there
  175|       |	 * mightn't be any available (EAGAIN) */
  176|   155k|	maxlen = ses.readbuf->len - ses.readbuf->pos;
  177|   155k|	if (maxlen == 0) {
  ------------------
  |  Branch (177:6): [True: 19.1k, False: 136k]
  ------------------
  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.1k|		len = 0;
  182|   136k|	} else {
  183|   136k|		len = read(ses.sock_in, buf_getptr(ses.readbuf, maxlen), maxlen);
  ------------------
  |  |   55|   136k|#define read(fd, buf, count) wrapfd_read(fd, buf, count)
  ------------------
  184|       |
  185|   136k|		if (len == 0) {
  ------------------
  |  Branch (185:7): [True: 168, False: 136k]
  ------------------
  186|    168|			ses.remoteclosed();
  187|    168|		}
  188|       |
  189|   136k|		if (len < 0) {
  ------------------
  |  Branch (189:7): [True: 172, False: 136k]
  ------------------
  190|    172|			if (errno == EINTR || errno == EAGAIN) {
  ------------------
  |  Branch (190:8): [True: 167, False: 5]
  |  Branch (190:26): [True: 0, False: 5]
  ------------------
  191|    167|				TRACE2(("leave read_packet: EINTR or EAGAIN"))
  192|    167|				return;
  193|    167|			} else {
  194|      5|				dropbear_exit("Error reading: %s", strerror(errno));
  195|      5|			}
  196|    172|		}
  197|       |
  198|   136k|		buf_incrpos(ses.readbuf, len);
  199|   136k|	}
  200|       |
  201|   155k|	if ((unsigned int)len == maxlen) {
  ------------------
  |  Branch (201:6): [True: 49.6k, False: 105k]
  ------------------
  202|       |		/* The whole packet has been read */
  203|  49.6k|		decrypt_packet();
  204|       |		/* The main select() loop process_packet() to
  205|       |		 * handle the packet contents... */
  206|  49.6k|	}
  207|   155k|	TRACE2(("leave read_packet"))
  208|   155k|}
decrypt_packet:
  298|  49.6k|void decrypt_packet() {
  299|       |
  300|  49.6k|	unsigned char blocksize;
  301|  49.6k|	unsigned char macsize;
  302|  49.6k|	unsigned int padlen;
  303|  49.6k|	unsigned int len;
  304|       |
  305|  49.6k|	TRACE2(("enter decrypt_packet"))
  306|  49.6k|	blocksize = ses.keys->recv.algo_crypt->blocksize;
  307|  49.6k|	macsize = ses.keys->recv.algo_mac->hashsize;
  308|       |
  309|  49.6k|	ses.kexstate.datarecv += ses.readbuf->len;
  310|       |
  311|  49.6k|#if DROPBEAR_AEAD_MODE
  312|  49.6k|	if (ses.keys->recv.crypt_mode->aead_crypt) {
  ------------------
  |  Branch (312:6): [True: 0, False: 49.6k]
  ------------------
  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|  49.6k|#endif
  328|  49.6k|	{
  329|       |		/* we've already decrypted the first blocksize in read_packet_init */
  330|  49.6k|		buf_setpos(ses.readbuf, blocksize);
  331|       |
  332|       |		/* decrypt it in-place */
  333|  49.6k|		len = ses.readbuf->len - macsize - ses.readbuf->pos;
  334|  49.6k|		if (ses.keys->recv.crypt_mode->decrypt(
  ------------------
  |  Branch (334:7): [True: 0, False: 49.6k]
  ------------------
  335|  49.6k|					buf_getptr(ses.readbuf, len), 
  336|  49.6k|					buf_getwriteptr(ses.readbuf, len),
  337|  49.6k|					len,
  338|  49.6k|					&ses.keys->recv.cipher_state) != CRYPT_OK) {
  339|      0|			dropbear_exit("Error decrypting");
  340|      0|		}
  341|  49.6k|		buf_incrpos(ses.readbuf, len);
  342|       |
  343|       |		/* check the hmac */
  344|  49.6k|		if (checkmac() != DROPBEAR_SUCCESS) {
  ------------------
  |  |  111|  49.6k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (344:7): [True: 0, False: 49.6k]
  ------------------
  345|      0|			dropbear_exit("Integrity error");
  346|      0|		}
  347|       |
  348|  49.6k|	}
  349|       |	
  350|  49.6k|#if DROPBEAR_FUZZ
  351|  49.6k|	fuzz_dump(ses.readbuf->data, ses.readbuf->len);
  352|  49.6k|#endif
  353|       |
  354|       |	/* get padding length */
  355|  49.6k|	buf_setpos(ses.readbuf, PACKET_PADDING_OFF);
  ------------------
  |  |   48|  49.6k|#define PACKET_PADDING_OFF 4
  ------------------
  356|  49.6k|	padlen = buf_getbyte(ses.readbuf);
  357|       |		
  358|       |	/* payload length */
  359|       |	/* - 4 - 1 is for LEN and PADLEN values */
  360|  49.6k|	len = ses.readbuf->len - padlen - 4 - 1 - macsize;
  361|  49.6k|	if ((len > RECV_MAX_PAYLOAD_LEN+ZLIB_COMPRESS_EXPANSION) || (len < 1)) {
  ------------------
  |  |  555|  49.6k|#define RECV_MAX_PAYLOAD_LEN 32768
  ------------------
              	if ((len > RECV_MAX_PAYLOAD_LEN+ZLIB_COMPRESS_EXPANSION) || (len < 1)) {
  ------------------
  |  |   50|  49.6k|#define ZLIB_COMPRESS_EXPANSION (((RECV_MAX_PAYLOAD_LEN/16384)+1)*5 + 6)
  |  |  ------------------
  |  |  |  |  555|  49.6k|#define RECV_MAX_PAYLOAD_LEN 32768
  |  |  ------------------
  ------------------
  |  Branch (361:6): [True: 14, False: 49.5k]
  |  Branch (361:62): [True: 1, False: 49.5k]
  ------------------
  362|     15|		dropbear_exit("Bad packet size %u", len);
  363|     15|	}
  364|       |
  365|  49.5k|	buf_setpos(ses.readbuf, PACKET_PAYLOAD_OFF);
  ------------------
  |  |   49|  49.5k|#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|  49.5k|	{
  377|  49.5k|		ses.payload = ses.readbuf;
  378|  49.5k|		ses.payload_beginning = ses.payload->pos;
  379|  49.5k|		buf_setlen(ses.payload, ses.payload->pos + len);
  380|  49.5k|	}
  381|  49.5k|	ses.readbuf = NULL;
  382|       |
  383|  49.5k|	ses.recvseq++;
  384|       |
  385|  49.5k|	TRACE2(("leave decrypt_packet"))
  386|  49.5k|}
maybe_flush_reply_queue:
  502|   270k|void maybe_flush_reply_queue() {
  503|   270k|	struct packetlist *tmp_item = NULL, *curr_item = NULL;
  504|   270k|	if (!ses.dataallowed)
  ------------------
  |  Branch (504:6): [True: 138k, False: 131k]
  ------------------
  505|   138k|	{
  506|   138k|		TRACE(("maybe_empty_reply_queue - no data allowed"))
  507|   138k|		return;
  508|   138k|	}
  509|       |		
  510|   131k|	for (curr_item = ses.reply_queue_head; curr_item; ) {
  ------------------
  |  Branch (510:41): [True: 0, False: 131k]
  ------------------
  511|      0|		CHECKCLEARTOWRITE();
  512|      0|		buf_putbytes(ses.writepayload,
  513|      0|			curr_item->payload->data, curr_item->payload->len);
  514|       |			
  515|      0|		buf_free(curr_item->payload);
  516|      0|		tmp_item = curr_item;
  517|      0|		curr_item = curr_item->next;
  518|      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]
  |  |  ------------------
  ------------------
  519|      0|		encrypt_packet();
  520|      0|	}
  521|       |	ses.reply_queue_head = ses.reply_queue_tail = NULL;
  522|   131k|	ses.reply_queue_len = 0;
  523|   131k|}
encrypt_packet:
  527|  48.2k|void encrypt_packet() {
  528|       |
  529|  48.2k|	unsigned char padlen;
  530|  48.2k|	unsigned char blocksize, mac_size;
  531|  48.2k|	buffer * writebuf; /* the packet which will go on the wire. This is 
  532|       |	                      encrypted in-place. */
  533|  48.2k|	unsigned char packet_type;
  534|  48.2k|	unsigned int len, encrypt_buf_size;
  535|  48.2k|	unsigned char mac_bytes[MAX_MAC_LEN];
  536|       |
  537|  48.2k|	time_t now;
  538|       |	
  539|  48.2k|	TRACE2(("enter encrypt_packet()"))
  540|       |
  541|  48.2k|	buf_setpos(ses.writepayload, 0);
  542|  48.2k|	packet_type = buf_getbyte(ses.writepayload);
  543|  48.2k|	buf_setpos(ses.writepayload, 0);
  544|       |
  545|  48.2k|	TRACE2(("encrypt_packet type is %d", packet_type))
  546|       |	
  547|  48.2k|	if ((!ses.dataallowed && !packet_is_okay_kex(packet_type))) {
  ------------------
  |  Branch (547:7): [True: 30.5k, False: 17.6k]
  |  Branch (547:27): [True: 0, False: 30.5k]
  ------------------
  548|       |		/* During key exchange only particular packets are allowed.
  549|       |			Since this packet_type isn't OK we just enqueue it to send 
  550|       |			after the KEX, see maybe_flush_reply_queue */
  551|      0|		enqueue_reply_packet();
  552|      0|		return;
  553|      0|	}
  554|       |		
  555|  48.2k|	blocksize = ses.keys->trans.algo_crypt->blocksize;
  556|  48.2k|	mac_size = ses.keys->trans.algo_mac->hashsize;
  557|       |
  558|       |	/* Encrypted packet len is payload+5. We need to then make sure
  559|       |	 * there is enough space for padding or MIN_PACKET_LEN. 
  560|       |	 * Add extra 3 since we need at least 4 bytes of padding */
  561|  48.2k|	encrypt_buf_size = (ses.writepayload->len+4+1) 
  562|  48.2k|		+ MAX(MIN_PACKET_LEN, blocksize) + 3
  ------------------
  |  Branch (562:5): [True: 22.8k, False: 25.3k]
  ------------------
  563|       |	/* add space for the MAC at the end */
  564|  48.2k|				+ mac_size
  565|       |#ifndef DISABLE_ZLIB
  566|       |	/* some extra in case 'compression' makes it larger */
  567|       |				+ ZLIB_COMPRESS_EXPANSION
  568|       |#endif
  569|       |	/* and an extra cleartext (stripped before transmission) byte for the
  570|       |	 * packet type */
  571|  48.2k|				+ 1;
  572|       |
  573|  48.2k|	writebuf = buf_new(encrypt_buf_size);
  574|  48.2k|	buf_setlen(writebuf, PACKET_PAYLOAD_OFF);
  ------------------
  |  |   49|  48.2k|#define PACKET_PAYLOAD_OFF 5
  ------------------
  575|  48.2k|	buf_setpos(writebuf, PACKET_PAYLOAD_OFF);
  ------------------
  |  |   49|  48.2k|#define PACKET_PAYLOAD_OFF 5
  ------------------
  576|       |
  577|       |#ifndef DISABLE_ZLIB
  578|       |	/* compression */
  579|       |	if (is_compress_trans()) {
  580|       |		buf_compress(writebuf, ses.writepayload, ses.writepayload->len);
  581|       |	} else
  582|       |#endif
  583|  48.2k|	{
  584|  48.2k|		memcpy(buf_getwriteptr(writebuf, ses.writepayload->len),
  585|  48.2k|				buf_getptr(ses.writepayload, ses.writepayload->len),
  586|  48.2k|				ses.writepayload->len);
  587|  48.2k|		buf_incrwritepos(writebuf, ses.writepayload->len);
  588|  48.2k|	}
  589|       |
  590|       |	/* finished with payload */
  591|  48.2k|	buf_setpos(ses.writepayload, 0);
  592|  48.2k|	buf_setlen(ses.writepayload, 0);
  593|       |
  594|       |	/* length of padding - packet length excluding the packetlength uint32
  595|       |	 * field in aead mode must be a multiple of blocksize, with a minimum of
  596|       |	 * 4 bytes of padding */
  597|  48.2k|	len = writebuf->len;
  598|  48.2k|#if DROPBEAR_AEAD_MODE
  599|  48.2k|	if (ses.keys->trans.crypt_mode->aead_crypt) {
  ------------------
  |  Branch (599:6): [True: 3.34k, False: 44.8k]
  ------------------
  600|  3.34k|		len -= 4;
  601|  3.34k|	}
  602|  48.2k|#endif
  603|  48.2k|	padlen = blocksize - len % blocksize;
  604|  48.2k|	if (padlen < 4) {
  ------------------
  |  Branch (604:6): [True: 14.0k, False: 34.1k]
  ------------------
  605|  14.0k|		padlen += blocksize;
  606|  14.0k|	}
  607|       |	/* check for min packet length */
  608|  48.2k|	if (writebuf->len + padlen < MIN_PACKET_LEN) {
  ------------------
  |  |  247|  48.2k|#define MIN_PACKET_LEN 16
  ------------------
  |  Branch (608:6): [True: 435, False: 47.7k]
  ------------------
  609|    435|		padlen += blocksize;
  610|    435|	}
  611|       |
  612|  48.2k|	buf_setpos(writebuf, 0);
  613|       |	/* packet length excluding the packetlength uint32 */
  614|  48.2k|	buf_putint(writebuf, writebuf->len + padlen - 4);
  615|       |
  616|       |	/* padding len */
  617|  48.2k|	buf_putbyte(writebuf, padlen);
  618|       |	/* actual padding */
  619|  48.2k|	buf_setpos(writebuf, writebuf->len);
  620|  48.2k|	buf_incrlen(writebuf, padlen);
  621|  48.2k|	genrandom(buf_getptr(writebuf, padlen), padlen);
  622|       |
  623|  48.2k|#if DROPBEAR_AEAD_MODE
  624|  48.2k|	if (ses.keys->trans.crypt_mode->aead_crypt) {
  ------------------
  |  Branch (624:6): [True: 3.34k, False: 44.8k]
  ------------------
  625|       |		/* do the actual encryption, in-place */
  626|  3.34k|		buf_setpos(writebuf, 0);
  627|       |		/* encrypt it in-place*/
  628|  3.34k|		len = writebuf->len;
  629|  3.34k|		buf_incrlen(writebuf, mac_size);
  630|  3.34k|		if (ses.keys->trans.crypt_mode->aead_crypt(ses.transseq,
  ------------------
  |  Branch (630:7): [True: 0, False: 3.34k]
  ------------------
  631|  3.34k|					buf_getptr(writebuf, len),
  632|  3.34k|					buf_getwriteptr(writebuf, len + mac_size),
  633|  3.34k|					len, mac_size,
  634|  3.34k|					&ses.keys->trans.cipher_state, LTC_ENCRYPT) != CRYPT_OK) {
  ------------------
  |  |   68|  3.34k|#define LTC_ENCRYPT 0
  ------------------
  635|      0|			dropbear_exit("Error encrypting");
  636|      0|		}
  637|  3.34k|		buf_incrpos(writebuf, len + mac_size);
  638|  3.34k|	} else
  639|  44.8k|#endif
  640|  44.8k|	{
  641|  44.8k|		make_mac(ses.transseq, &ses.keys->trans, writebuf, writebuf->len, mac_bytes);
  642|       |
  643|       |		/* do the actual encryption, in-place */
  644|  44.8k|		buf_setpos(writebuf, 0);
  645|       |		/* encrypt it in-place*/
  646|  44.8k|		len = writebuf->len;
  647|  44.8k|		if (ses.keys->trans.crypt_mode->encrypt(
  ------------------
  |  Branch (647:7): [True: 0, False: 44.8k]
  ------------------
  648|  44.8k|					buf_getptr(writebuf, len),
  649|  44.8k|					buf_getwriteptr(writebuf, len),
  650|  44.8k|					len,
  651|  44.8k|					&ses.keys->trans.cipher_state) != CRYPT_OK) {
  652|      0|			dropbear_exit("Error encrypting");
  653|      0|		}
  654|  44.8k|		buf_incrpos(writebuf, len);
  655|       |
  656|       |		/* stick the MAC on it */
  657|  44.8k|		buf_putbytes(writebuf, mac_bytes, mac_size);
  658|  44.8k|	}
  659|       |
  660|       |	/* Update counts */
  661|  48.2k|	ses.kexstate.datatrans += writebuf->len;
  662|       |
  663|  48.2k|	writebuf_enqueue(writebuf);
  664|       |
  665|       |	/* Update counts */
  666|  48.2k|	ses.transseq++;
  667|       |
  668|  48.2k|	now = monotonic_now();
  669|  48.2k|	ses.last_packet_time_any_sent = now;
  670|       |	/* idle timeout shouldn't be affected by responses to keepalives.
  671|       |	send_msg_keepalive() itself also does tricks with 
  672|       |	ses.last_packet_idle_time - read that if modifying this code */
  673|  48.2k|	if (packet_type != SSH_MSG_REQUEST_FAILURE
  ------------------
  |  |   65|  96.4k|#define SSH_MSG_REQUEST_FAILURE                 82
  ------------------
  |  Branch (673:6): [True: 48.2k, False: 0]
  ------------------
  674|  48.2k|		&& packet_type != SSH_MSG_UNIMPLEMENTED
  ------------------
  |  |   31|  96.4k|#define SSH_MSG_UNIMPLEMENTED          3
  ------------------
  |  Branch (674:6): [True: 29.6k, False: 18.5k]
  ------------------
  675|  29.6k|		&& packet_type != SSH_MSG_IGNORE) {
  ------------------
  |  |   30|  29.6k|#define SSH_MSG_IGNORE                 2
  ------------------
  |  Branch (675:6): [True: 29.6k, False: 0]
  ------------------
  676|  29.6k|		ses.last_packet_time_idle = now;
  677|       |
  678|  29.6k|	}
  679|       |
  680|  48.2k|	TRACE2(("leave encrypt_packet()"))
  681|  48.2k|}
writebuf_enqueue:
  683|  51.6k|void writebuf_enqueue(buffer * writebuf) {
  684|       |	/* enqueue the packet for sending. It will get freed after transmission. */
  685|  51.6k|	buf_setpos(writebuf, 0);
  686|  51.6k|	enqueue(&ses.writequeue, (void*)writebuf);
  687|  51.6k|	ses.writequeue_len += writebuf->len;
  688|  51.6k|}
packet.c:read_packet_init:
  214|   145k|static int read_packet_init() {
  215|       |
  216|   145k|	unsigned int maxlen;
  217|   145k|	int slen;
  218|   145k|	unsigned int len, plen;
  219|   145k|	unsigned int blocksize;
  220|   145k|	unsigned int macsize;
  221|       |
  222|       |
  223|   145k|	blocksize = ses.keys->recv.algo_crypt->blocksize;
  224|   145k|	macsize = ses.keys->recv.algo_mac->hashsize;
  225|       |
  226|   145k|	if (ses.readbuf == NULL) {
  ------------------
  |  Branch (226:6): [True: 51.0k, False: 93.9k]
  ------------------
  227|       |		/* start of a new packet */
  228|  51.0k|		ses.readbuf = buf_new(INIT_READBUF);
  ------------------
  |  |   51|  51.0k|#define INIT_READBUF 128
  ------------------
  229|  51.0k|	}
  230|       |
  231|   145k|	maxlen = blocksize - ses.readbuf->pos;
  232|       |			
  233|       |	/* read the rest of the packet if possible */
  234|   145k|	slen = read(ses.sock_in, buf_getwriteptr(ses.readbuf, maxlen),
  ------------------
  |  |   55|   145k|#define read(fd, buf, count) wrapfd_read(fd, buf, count)
  ------------------
  235|   145k|			maxlen);
  236|   145k|	if (slen == 0) {
  ------------------
  |  Branch (236:6): [True: 1.16k, False: 143k]
  ------------------
  237|  1.16k|		ses.remoteclosed();
  238|  1.16k|	}
  239|   145k|	if (slen < 0) {
  ------------------
  |  Branch (239:6): [True: 122, False: 144k]
  ------------------
  240|    122|		if (errno == EINTR || errno == EAGAIN) {
  ------------------
  |  Branch (240:7): [True: 120, False: 2]
  |  Branch (240:25): [True: 0, False: 2]
  ------------------
  241|    120|			TRACE2(("leave read_packet_init: EINTR"))
  242|    120|			return DROPBEAR_FAILURE;
  ------------------
  |  |  112|    120|#define DROPBEAR_FAILURE -1
  ------------------
  243|    120|		}
  244|      2|		dropbear_exit("Error reading: %s", strerror(errno));
  245|    122|	}
  246|       |
  247|   144k|	buf_incrwritepos(ses.readbuf, slen);
  248|       |
  249|   144k|	if ((unsigned int)slen != maxlen) {
  ------------------
  |  Branch (249:6): [True: 93.8k, False: 51.0k]
  ------------------
  250|       |		/* don't have enough bytes to determine length, get next time */
  251|  93.8k|		return DROPBEAR_FAILURE;
  ------------------
  |  |  112|  93.8k|#define DROPBEAR_FAILURE -1
  ------------------
  252|  93.8k|	}
  253|       |
  254|       |	/* now we have the first block, need to get packet length, so we decrypt
  255|       |	 * the first block (only need first 4 bytes) */
  256|  51.0k|	buf_setpos(ses.readbuf, 0);
  257|  51.0k|#if DROPBEAR_AEAD_MODE
  258|  51.0k|	if (ses.keys->recv.crypt_mode->aead_crypt) {
  ------------------
  |  Branch (258:6): [True: 0, False: 51.0k]
  ------------------
  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|  51.0k|#endif
  268|  51.0k|	{
  269|  51.0k|		if (ses.keys->recv.crypt_mode->decrypt(buf_getptr(ses.readbuf, blocksize), 
  ------------------
  |  Branch (269:7): [True: 0, False: 51.0k]
  ------------------
  270|  51.0k|					buf_getwriteptr(ses.readbuf, blocksize),
  271|  51.0k|					blocksize,
  272|  51.0k|					&ses.keys->recv.cipher_state) != CRYPT_OK) {
  273|      0|			dropbear_exit("Error decrypting");
  274|      0|		}
  275|  51.0k|		plen = buf_getint(ses.readbuf) + 4;
  276|  51.0k|		len = plen + macsize;
  277|  51.0k|	}
  278|       |
  279|  51.0k|	TRACE2(("packet size is %u, block %u mac %u", len, blocksize, macsize))
  280|       |
  281|       |	/* check packet length. plen max to catch integer wraparound. */
  282|  51.0k|	if ((len > RECV_MAX_PACKET_LEN) ||
  ------------------
  |  |  249|  51.0k|#define RECV_MAX_PACKET_LEN (MAX(35000, ((RECV_MAX_PAYLOAD_LEN)+100)))
  ------------------
  |  Branch (282:6): [True: 1.25k, False: 49.8k]
  |  Branch (282:13): [True: 49.9k, Folded]
  ------------------
  283|  49.8k|	    (plen > RECV_MAX_PACKET_LEN) ||
  ------------------
  |  |  249|  49.8k|#define RECV_MAX_PACKET_LEN (MAX(35000, ((RECV_MAX_PAYLOAD_LEN)+100)))
  ------------------
  |  Branch (283:6): [True: 0, False: 49.8k]
  |  Branch (283:14): [True: 49.8k, Folded]
  ------------------
  284|  49.8k|		(plen < blocksize) ||
  ------------------
  |  Branch (284:3): [True: 5, False: 49.8k]
  ------------------
  285|  49.8k|		(plen % blocksize != 0)) {
  ------------------
  |  Branch (285:3): [True: 65, False: 49.7k]
  ------------------
  286|    161|		dropbear_exit("Integrity error (bad packet size %u)", plen);
  287|    161|	}
  288|       |
  289|  50.9k|	if (len > ses.readbuf->size) {
  ------------------
  |  Branch (289:6): [True: 10.9k, False: 40.0k]
  ------------------
  290|  10.9k|		ses.readbuf = buf_resize(ses.readbuf, len);		
  291|  10.9k|	}
  292|  50.9k|	buf_setlen(ses.readbuf, len);
  293|  50.9k|	buf_setpos(ses.readbuf, blocksize);
  294|  50.9k|	return DROPBEAR_SUCCESS;
  ------------------
  |  |  111|  50.9k|#define DROPBEAR_SUCCESS 0
  ------------------
  295|  51.0k|}
packet.c:checkmac:
  390|  49.6k|static int checkmac() {
  391|       |
  392|  49.6k|	unsigned char mac_bytes[MAX_MAC_LEN];
  393|  49.6k|	unsigned int mac_size, contents_len;
  394|       |	
  395|  49.6k|	mac_size = ses.keys->recv.algo_mac->hashsize;
  396|  49.6k|	contents_len = ses.readbuf->len - mac_size;
  397|       |
  398|  49.6k|	buf_setpos(ses.readbuf, 0);
  399|  49.6k|	make_mac(ses.recvseq, &ses.keys->recv, ses.readbuf, contents_len, mac_bytes);
  400|       |
  401|  49.6k|#if DROPBEAR_FUZZ
  402|  49.6k|	if (fuzz.fuzzing) {
  ------------------
  |  Branch (402:6): [True: 49.6k, False: 0]
  ------------------
  403|       |	 	/* fail 1 in 2000 times to test error path. */
  404|  49.6k|		unsigned int value = 0;
  405|  49.6k|		if (mac_size > sizeof(value)) {
  ------------------
  |  Branch (405:7): [True: 0, False: 49.6k]
  ------------------
  406|      0|			memcpy(&value, mac_bytes, sizeof(value));
  407|      0|		}
  408|  49.6k|		if (value % 2000 == 99) {
  ------------------
  |  Branch (408:7): [True: 0, False: 49.6k]
  ------------------
  409|      0|			return DROPBEAR_FAILURE;
  ------------------
  |  |  112|      0|#define DROPBEAR_FAILURE -1
  ------------------
  410|      0|		}
  411|  49.6k|		return DROPBEAR_SUCCESS;
  ------------------
  |  |  111|  49.6k|#define DROPBEAR_SUCCESS 0
  ------------------
  412|  49.6k|	}
  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.5k|static int packet_is_okay_kex(unsigned char type) {
  465|  30.5k|	if (type >= SSH_MSG_USERAUTH_REQUEST) {
  ------------------
  |  |   42|  30.5k|#define SSH_MSG_USERAUTH_REQUEST            50
  ------------------
  |  Branch (465:6): [True: 0, False: 30.5k]
  ------------------
  466|      0|		return 0;
  467|      0|	}
  468|  30.5k|	if (type == SSH_MSG_SERVICE_REQUEST || type == SSH_MSG_SERVICE_ACCEPT) {
  ------------------
  |  |   33|  61.1k|#define SSH_MSG_SERVICE_REQUEST        5
  ------------------
              	if (type == SSH_MSG_SERVICE_REQUEST || type == SSH_MSG_SERVICE_ACCEPT) {
  ------------------
  |  |   34|  30.5k|#define SSH_MSG_SERVICE_ACCEPT         6
  ------------------
  |  Branch (468:6): [True: 0, False: 30.5k]
  |  Branch (468:41): [True: 0, False: 30.5k]
  ------------------
  469|      0|		return 0;
  470|      0|	}
  471|  30.5k|	if (type == SSH_MSG_KEXINIT) {
  ------------------
  |  |   36|  30.5k|#define SSH_MSG_KEXINIT                20
  ------------------
  |  Branch (471:6): [True: 0, False: 30.5k]
  ------------------
  472|       |		/* XXX should this die horribly if !dataallowed ?? */
  473|      0|		return 0;
  474|      0|	}
  475|  30.5k|	return 1;
  476|  30.5k|}
packet.c:make_mac:
  695|  94.4k|		unsigned char *output_mac) {
  696|  94.4k|	unsigned char seqbuf[4];
  697|  94.4k|	unsigned long bufsize;
  698|  94.4k|	hmac_state hmac;
  699|       |
  700|  94.4k|	if (key_state->algo_mac->hashsize > 0) {
  ------------------
  |  Branch (700:6): [True: 25.3k, False: 69.0k]
  ------------------
  701|       |		/* calculate the mac */
  702|  25.3k|		if (hmac_init(&hmac, 
  ------------------
  |  Branch (702:7): [True: 0, False: 25.3k]
  ------------------
  703|  25.3k|					key_state->hash_index,
  704|  25.3k|					key_state->mackey,
  705|  25.3k|					key_state->algo_mac->keysize) != CRYPT_OK) {
  706|      0|			dropbear_exit("HMAC error");
  707|      0|		}
  708|       |	
  709|       |		/* sequence number */
  710|  25.3k|		STORE32H(seqno, seqbuf);
  ------------------
  |  |   62|  25.3k|#define STORE32H(x, y)                          \
  |  |   63|  25.3k|do { ulong32 __t = __builtin_bswap32 ((x));     \
  |  |   64|  25.3k|      XMEMCPY ((y), &__t, 4); } while(0)
  |  |  ------------------
  |  |  |  |   39|  25.3k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (64:39): [Folded, False: 25.3k]
  |  |  ------------------
  ------------------
  711|  25.3k|		if (hmac_process(&hmac, seqbuf, 4) != CRYPT_OK) {
  ------------------
  |  Branch (711:7): [True: 0, False: 25.3k]
  ------------------
  712|      0|			dropbear_exit("HMAC error");
  713|      0|		}
  714|       |	
  715|       |		/* the actual contents */
  716|  25.3k|		buf_setpos(clear_buf, 0);
  717|  25.3k|		if (hmac_process(&hmac, 
  ------------------
  |  Branch (717:7): [True: 0, False: 25.3k]
  ------------------
  718|  25.3k|					buf_getptr(clear_buf, clear_len),
  719|  25.3k|					clear_len) != CRYPT_OK) {
  720|      0|			dropbear_exit("HMAC error");
  721|      0|		}
  722|       |	
  723|  25.3k|		bufsize = MAX_MAC_LEN;
  ------------------
  |  |  147|  25.3k|#define MAX_MAC_LEN 32
  ------------------
  724|  25.3k|		if (hmac_done(&hmac, output_mac, &bufsize) != CRYPT_OK) {
  ------------------
  |  Branch (724:7): [True: 0, False: 25.3k]
  ------------------
  725|      0|			dropbear_exit("HMAC error");
  726|      0|		}
  727|  25.3k|	}
  728|  94.4k|	TRACE2(("leave writemac"))
  729|  94.4k|}

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

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

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);
  ------------------
  |  |   86|      1|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (86:37): [True: 0, False: 1]
  |  |  |  Branch (86: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);
  ------------------
  |  |   86|      1|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (86:37): [True: 0, False: 1]
  |  |  |  Branch (86: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|  18.2k|void buf_put_rsa_pub_key(buffer* buf, const dropbear_rsa_key *key) {
  163|       |
  164|  18.2k|	TRACE(("enter buf_put_rsa_pub_key"))
  165|  18.2k|	dropbear_assert(key != NULL);
  ------------------
  |  |   86|  18.2k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (86:37): [True: 0, False: 18.2k]
  |  |  |  Branch (86:93): [Folded, False: 18.2k]
  |  |  ------------------
  ------------------
  166|       |
  167|  18.2k|	buf_putstring(buf, SSH_SIGNKEY_RSA, SSH_SIGNKEY_RSA_LEN);
  ------------------
  |  |  116|  18.2k|#define SSH_SIGNKEY_RSA "ssh-rsa"
  ------------------
              	buf_putstring(buf, SSH_SIGNKEY_RSA, SSH_SIGNKEY_RSA_LEN);
  ------------------
  |  |  117|  18.2k|#define SSH_SIGNKEY_RSA_LEN 7
  ------------------
  168|  18.2k|	buf_putmpint(buf, key->e);
  169|  18.2k|	buf_putmpint(buf, key->n);
  170|       |
  171|  18.2k|	TRACE(("leave buf_put_rsa_pub_key"))
  172|       |
  173|  18.2k|}
buf_put_rsa_sign:
  257|  8.94k|		enum signature_type sigtype, const buffer *data_buf) {
  258|  8.94k|	const char *name = NULL;
  259|  8.94k|	unsigned int nsize, ssize, namelen = 0;
  260|  8.94k|	unsigned int i;
  261|  8.94k|	size_t written;
  262|  8.94k|	DEF_MP_INT(rsa_s);
  ------------------
  |  |   83|  8.94k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  263|  8.94k|	DEF_MP_INT(rsa_tmp1);
  ------------------
  |  |   83|  8.94k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  264|  8.94k|	DEF_MP_INT(rsa_tmp2);
  ------------------
  |  |   83|  8.94k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  265|  8.94k|	DEF_MP_INT(rsa_tmp3);
  ------------------
  |  |   83|  8.94k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  266|  8.94k|	DEF_MP_INT(rsa_phi_n);
  ------------------
  |  |   83|  8.94k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  267|  8.94k|	DEF_MP_INT(rsa_b_tmp);
  ------------------
  |  |   83|  8.94k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  268|  8.94k|	DEF_MP_INT(rsa_b_rand);
  ------------------
  |  |   83|  8.94k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  269|  8.94k|	DEF_MP_INT(rsa_b_phi);
  ------------------
  |  |   83|  8.94k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  270|  8.94k|	DEF_MP_INT(rsa_b_d);
  ------------------
  |  |   83|  8.94k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  271|       |	
  272|  8.94k|	TRACE(("enter buf_put_rsa_sign"))
  273|  8.94k|	dropbear_assert(key != NULL);
  ------------------
  |  |   86|  8.94k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (86:37): [True: 0, False: 8.94k]
  |  |  |  Branch (86:93): [Folded, False: 8.94k]
  |  |  ------------------
  ------------------
  274|       |
  275|  8.94k|	m_mp_init_multi(&rsa_s, &rsa_tmp1, &rsa_tmp2, &rsa_tmp3,
  276|  8.94k|		&rsa_phi_n, &rsa_b_tmp, &rsa_b_rand, &rsa_b_phi, &rsa_b_d,
  277|  8.94k|		NULL);
  278|       |
  279|  8.94k|	rsa_pad_em(key, data_buf, &rsa_tmp1, sigtype);
  280|       |
  281|       |	/* the actual signing of the padded data */
  282|       |
  283|  8.94k|#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.94k|	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.94k|	if (mp_exptmod(&rsa_tmp2, key->e, key->n, &rsa_s) != MP_OKAY) {
  ------------------
  |  |  161|  8.94k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (295:6): [True: 0, False: 8.94k]
  ------------------
  296|      0|		dropbear_exit("RSA error");
  297|      0|	}
  298|  8.94k|	if (mp_invmod(&rsa_tmp2, key->n, &rsa_tmp3) != MP_OKAY) {
  ------------------
  |  |  161|  8.94k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (298:6): [True: 0, False: 8.94k]
  ------------------
  299|      0|		dropbear_exit("RSA error");
  300|      0|	}
  301|  8.94k|	if (mp_mulmod(&rsa_tmp1, &rsa_s, key->n, &rsa_tmp2) != MP_OKAY) {
  ------------------
  |  |  161|  8.94k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (301:6): [True: 0, False: 8.94k]
  ------------------
  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.94k|	mp_set_u64(&rsa_b_tmp, UINT64_MAX);
  308|  8.94k|	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.94k|	if (mp_add_d(key->n, 1, &rsa_phi_n) != MP_OKAY) {
  ------------------
  |  |  161|  8.94k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (311:6): [True: 0, False: 8.94k]
  ------------------
  312|      0|		dropbear_exit("RSA error");
  313|      0|	}
  314|       |	/* rsa_b_d as a temporary */
  315|  8.94k|	if (mp_sub(&rsa_phi_n, key->p, &rsa_b_d) != MP_OKAY) {
  ------------------
  |  |  161|  8.94k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (315:6): [True: 0, False: 8.94k]
  ------------------
  316|      0|		dropbear_exit("RSA error");
  317|      0|	}
  318|  8.94k|	if (mp_sub(&rsa_b_d, key->q, &rsa_phi_n) != MP_OKAY) {
  ------------------
  |  |  161|  8.94k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (318:6): [True: 0, False: 8.94k]
  ------------------
  319|      0|		dropbear_exit("RSA error");
  320|      0|	}
  321|       |
  322|       |	/* b*phi(n) */
  323|  8.94k|	if (mp_mul(&rsa_b_rand, &rsa_phi_n, &rsa_b_tmp) != MP_OKAY) {
  ------------------
  |  |  161|  8.94k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (323:6): [True: 0, False: 8.94k]
  ------------------
  324|      0|		dropbear_exit("RSA error");
  325|      0|	}
  326|       |	/* d + b*phi(n) */
  327|  8.94k|	if (mp_add(key->d, &rsa_b_tmp, &rsa_b_d) != MP_OKAY) {
  ------------------
  |  |  161|  8.94k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (327:6): [True: 0, False: 8.94k]
  ------------------
  328|      0|		dropbear_exit("RSA error");
  329|      0|	}
  330|       |
  331|       |	/* rsa_tmp2 is em' */
  332|       |	/* s' = (em')^d mod n */
  333|  8.94k|	if (mp_exptmod(&rsa_tmp2, &rsa_b_d, key->n, &rsa_tmp1) != MP_OKAY) {
  ------------------
  |  |  161|  8.94k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (333:6): [True: 0, False: 8.94k]
  ------------------
  334|      0|		dropbear_exit("RSA error");
  335|      0|	}
  336|       |
  337|  8.94k|	m_mp_burn(&rsa_phi_n);
  338|  8.94k|	m_mp_burn(&rsa_b_tmp);
  339|  8.94k|	m_mp_burn(&rsa_b_rand);
  340|  8.94k|	m_mp_burn(&rsa_b_phi);
  341|  8.94k|	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.94k|	if (mp_mulmod(&rsa_tmp1, &rsa_tmp3, key->n, &rsa_s) != MP_OKAY) {
  ------------------
  |  |  161|  8.94k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (346:6): [True: 0, False: 8.94k]
  ------------------
  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.94k|	mp_clear_multi(&rsa_tmp1, &rsa_tmp2, &rsa_tmp3,
  361|  8.94k|		&rsa_phi_n, &rsa_b_tmp, &rsa_b_rand, &rsa_b_phi, &rsa_b_d,
  362|  8.94k|		NULL);
  363|       |
  364|       |	/* create the signature to return */
  365|  8.94k|	name = signature_name_from_type(sigtype, &namelen);
  366|  8.94k|	buf_putstring(buf, name, namelen);
  367|       |
  368|  8.94k|	nsize = mp_ubin_size(key->n);
  369|       |
  370|       |	/* string rsa_signature_blob length */
  371|  8.94k|	buf_putint(buf, nsize);
  372|       |	/* pad out s to same length as n */
  373|  8.94k|	ssize = mp_ubin_size(&rsa_s);
  374|  8.94k|	dropbear_assert(ssize <= nsize);
  ------------------
  |  |   86|  8.94k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (86:37): [True: 0, False: 8.94k]
  |  |  |  Branch (86:93): [Folded, False: 8.94k]
  |  |  ------------------
  ------------------
  375|  8.98k|	for (i = 0; i < nsize-ssize; i++) {
  ------------------
  |  Branch (375:14): [True: 42, False: 8.94k]
  ------------------
  376|     42|		buf_putbyte(buf, 0x00);
  377|     42|	}
  378|       |
  379|  8.94k|	if (mp_to_ubin(&rsa_s, buf_getwriteptr(buf, ssize), ssize, &written) != MP_OKAY) {
  ------------------
  |  |  161|  8.94k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (379:6): [True: 0, False: 8.94k]
  ------------------
  380|      0|		dropbear_exit("RSA error");
  381|      0|	}
  382|  8.94k|	buf_incrwritepos(buf, written);
  383|  8.94k|	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.94k|	TRACE(("leave buf_put_rsa_sign"))
  393|  8.94k|}
rsa.c:rsa_pad_em:
  398|  8.94k|	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.94k|#if DROPBEAR_RSA_SHA1
  407|  8.94k|	const unsigned char T_sha1[] =
  408|  8.94k|		{0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b,
  409|  8.94k|		 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14};
  410|  8.94k|#endif
  411|  8.94k|#if DROPBEAR_RSA_SHA256
  412|  8.94k|	const unsigned char T_sha256[] =
  413|  8.94k|		{0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01,
  414|  8.94k|		 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20};
  415|  8.94k|#endif
  416|       |
  417|  8.94k|    int Tlen = 0;
  418|  8.94k|    const unsigned char *T = NULL;
  419|  8.94k|	const struct ltc_hash_descriptor *hash_desc = NULL;
  420|  8.94k|	buffer * rsa_EM = NULL;
  421|  8.94k|	hash_state hs;
  422|  8.94k|	unsigned int nsize;
  423|       |
  424|  8.94k|	switch (sigtype) {
  425|      0|#if DROPBEAR_RSA_SHA1
  426|  8.94k|		case DROPBEAR_SIGNATURE_RSA_SHA1:
  ------------------
  |  Branch (426:3): [True: 8.94k, False: 0]
  ------------------
  427|  8.94k|			Tlen = sizeof(T_sha1);
  428|  8.94k|			T = T_sha1;
  429|  8.94k|			hash_desc = &sha1_desc;
  430|  8.94k|			break;
  431|      0|#endif
  432|      0|#if DROPBEAR_RSA_SHA256
  433|      0|		case DROPBEAR_SIGNATURE_RSA_SHA256:
  ------------------
  |  Branch (433:3): [True: 0, False: 8.94k]
  ------------------
  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.94k]
  ------------------
  440|      0|			assert(0);
  ------------------
  |  Branch (440:4): [Folded, False: 0]
  |  Branch (440:4): [Folded, False: 0]
  ------------------
  441|  8.94k|	}
  442|       |	
  443|       |
  444|  8.94k|	nsize = mp_ubin_size(key->n);
  445|       |
  446|  8.94k|	rsa_EM = buf_new(nsize);
  447|       |	/* type byte */
  448|  8.94k|	buf_putbyte(rsa_EM, 0x00);
  449|  8.94k|	buf_putbyte(rsa_EM, 0x01);
  450|       |	/* Padding with PS 0xFF bytes */
  451|  1.95M|	while(rsa_EM->pos != rsa_EM->size - (1 + Tlen + hash_desc->hashsize)) {
  ------------------
  |  Branch (451:8): [True: 1.95M, False: 8.94k]
  ------------------
  452|  1.95M|		buf_putbyte(rsa_EM, 0xff);
  453|  1.95M|	}
  454|  8.94k|	buf_putbyte(rsa_EM, 0x00);
  455|       |	/* Magic ASN1 stuff */
  456|  8.94k|	buf_putbytes(rsa_EM, T, Tlen);
  457|       |
  458|       |	/* The hash of the data */
  459|  8.94k|	hash_desc->init(&hs);
  460|  8.94k|	hash_desc->process(&hs, data_buf->data, data_buf->len);
  461|  8.94k|	hash_desc->done(&hs, buf_getwriteptr(rsa_EM, hash_desc->hashsize));
  462|  8.94k|	buf_incrwritepos(rsa_EM, hash_desc->hashsize);
  463|       |
  464|  8.94k|	dropbear_assert(rsa_EM->pos == rsa_EM->size);
  ------------------
  |  |   86|  8.94k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (86:37): [True: 0, False: 8.94k]
  |  |  |  Branch (86:93): [Folded, False: 8.94k]
  |  |  ------------------
  ------------------
  465|       |
  466|       |	/* Create the mp_int from the encoded bytes */
  467|  8.94k|	buf_setpos(rsa_EM, 0);
  468|  8.94k|	bytes_to_mp(rsa_em, buf_getptr(rsa_EM, rsa_EM->size),
  469|  8.94k|			rsa_EM->size);
  470|  8.94k|	buf_free(rsa_EM);
  471|  8.94k|}

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.94k|const char* signature_name_from_type(enum signature_type type, unsigned int *namelen) {
  123|  8.94k|#if DROPBEAR_RSA
  124|  8.94k|#if DROPBEAR_RSA_SHA256
  125|  8.94k|	if (type == DROPBEAR_SIGNATURE_RSA_SHA256) {
  ------------------
  |  Branch (125:6): [True: 0, False: 8.94k]
  ------------------
  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.94k|#endif
  132|  8.94k|#if DROPBEAR_RSA_SHA1
  133|  8.94k|	if (type == DROPBEAR_SIGNATURE_RSA_SHA1) {
  ------------------
  |  Branch (133:6): [True: 8.94k, False: 0]
  ------------------
  134|  8.94k|		if (namelen) {
  ------------------
  |  Branch (134:7): [True: 8.94k, False: 0]
  ------------------
  135|  8.94k|			*namelen = strlen(SSH_SIGNKEY_RSA);
  ------------------
  |  |  116|  8.94k|#define SSH_SIGNKEY_RSA "ssh-rsa"
  ------------------
  136|  8.94k|		}
  137|  8.94k|		return SSH_SIGNKEY_RSA;
  ------------------
  |  |  116|  8.94k|#define SSH_SIGNKEY_RSA "ssh-rsa"
  ------------------
  138|  8.94k|	}
  139|      0|#endif
  140|      0|#endif /* DROPBEAR_RSA */
  141|      0|	return signkey_name_from_type((enum signkey_type)type, namelen);
  142|  8.94k|}
signkey_type_from_signature:
  173|  18.8k|enum signkey_type signkey_type_from_signature(enum signature_type sigtype) {
  174|  18.8k|#if DROPBEAR_RSA
  175|  18.8k|#if DROPBEAR_RSA_SHA256
  176|  18.8k|	if (sigtype == DROPBEAR_SIGNATURE_RSA_SHA256) {
  ------------------
  |  Branch (176:6): [True: 1, False: 18.8k]
  ------------------
  177|      1|		return DROPBEAR_SIGNKEY_RSA;
  178|      1|	}
  179|  18.8k|#endif
  180|  18.8k|#if DROPBEAR_RSA_SHA1
  181|  18.8k|	if (sigtype == DROPBEAR_SIGNATURE_RSA_SHA1) {
  ------------------
  |  Branch (181:6): [True: 18.7k, False: 80]
  ------------------
  182|  18.7k|		return DROPBEAR_SIGNKEY_RSA;
  183|  18.7k|	}
  184|     80|#endif
  185|     80|#endif /* DROPBEAR_RSA */
  186|  18.8k|	assert((int)sigtype < (int)DROPBEAR_SIGNKEY_NUM_NAMED);
  ------------------
  |  Branch (186:2): [True: 0, False: 80]
  |  Branch (186:2): [True: 80, False: 0]
  ------------------
  187|     80|	return (enum signkey_type)sigtype;
  188|     80|}
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|  18.2k|void buf_put_pub_key(buffer* buf, sign_key *key, enum signkey_type type) {
  420|       |
  421|  18.2k|	buffer *pubkeys;
  422|       |
  423|  18.2k|	TRACE2(("enter buf_put_pub_key"))
  424|  18.2k|	pubkeys = buf_new(MAX_PUBKEY_SIZE);
  ------------------
  |  |  271|  18.2k|#define MAX_PUBKEY_SIZE 600
  ------------------
  425|       |	
  426|  18.2k|#if DROPBEAR_DSS
  427|  18.2k|	if (type == DROPBEAR_SIGNKEY_DSS) {
  ------------------
  |  Branch (427:6): [True: 0, False: 18.2k]
  ------------------
  428|      0|		buf_put_dss_pub_key(pubkeys, key->dsskey);
  429|      0|	}
  430|  18.2k|#endif
  431|  18.2k|#if DROPBEAR_RSA
  432|  18.2k|	if (type == DROPBEAR_SIGNKEY_RSA) {
  ------------------
  |  Branch (432:6): [True: 18.2k, False: 0]
  ------------------
  433|  18.2k|		buf_put_rsa_pub_key(pubkeys, key->rsakey);
  434|  18.2k|	}
  435|  18.2k|#endif
  436|  18.2k|#if DROPBEAR_ECDSA
  437|  18.2k|	if (signkey_is_ecdsa(type)
  ------------------
  |  Branch (437:6): [True: 0, False: 18.2k]
  ------------------
  438|  18.2k|#if DROPBEAR_SK_ECDSA
  439|  18.2k|		|| type == DROPBEAR_SIGNKEY_SK_ECDSA_NISTP256
  ------------------
  |  Branch (439:6): [True: 0, False: 18.2k]
  ------------------
  440|  18.2k|#endif
  441|  18.2k|		) {
  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|  18.2k|#endif
  448|  18.2k|#if DROPBEAR_ED25519
  449|  18.2k|	if (type == DROPBEAR_SIGNKEY_ED25519
  ------------------
  |  Branch (449:6): [True: 0, False: 18.2k]
  ------------------
  450|  18.2k|#if DROPBEAR_SK_ED25519
  451|  18.2k|		|| type == DROPBEAR_SIGNKEY_SK_ED25519
  ------------------
  |  Branch (451:6): [True: 0, False: 18.2k]
  ------------------
  452|  18.2k|#endif
  453|  18.2k|	) {
  454|      0|		buf_put_ed25519_pub_key(pubkeys, key->ed25519key);
  455|      0|	}
  456|  18.2k|#endif
  457|  18.2k|	if (pubkeys->len == 0) {
  ------------------
  |  Branch (457:6): [True: 0, False: 18.2k]
  ------------------
  458|      0|		dropbear_exit("Bad key types in buf_put_pub_key");
  459|      0|	}
  460|       |
  461|  18.2k|	buf_putbufstring(buf, pubkeys);
  462|  18.2k|	buf_free(pubkeys);
  463|  18.2k|	TRACE2(("leave buf_put_pub_key"))
  464|  18.2k|}
buf_put_sign:
  596|  8.94k|	const buffer *data_buf) {
  597|  8.94k|	buffer *sigblob = buf_new(MAX_PUBKEY_SIZE);
  ------------------
  |  |  271|  8.94k|#define MAX_PUBKEY_SIZE 600
  ------------------
  598|  8.94k|	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.94k|#if DROPBEAR_DSS
  609|  8.94k|	if (keytype == DROPBEAR_SIGNKEY_DSS) {
  ------------------
  |  Branch (609:6): [True: 0, False: 8.94k]
  ------------------
  610|      0|		buf_put_dss_sign(sigblob, key->dsskey, data_buf);
  611|      0|	}
  612|  8.94k|#endif
  613|  8.94k|#if DROPBEAR_RSA
  614|  8.94k|	if (keytype == DROPBEAR_SIGNKEY_RSA) {
  ------------------
  |  Branch (614:6): [True: 8.94k, False: 0]
  ------------------
  615|  8.94k|		buf_put_rsa_sign(sigblob, key->rsakey, sigtype, data_buf);
  616|  8.94k|	}
  617|  8.94k|#endif
  618|  8.94k|#if DROPBEAR_ECDSA
  619|  8.94k|	if (signkey_is_ecdsa(keytype)) {
  ------------------
  |  Branch (619:6): [True: 0, False: 8.94k]
  ------------------
  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.94k|#endif
  626|  8.94k|#if DROPBEAR_ED25519
  627|  8.94k|	if (keytype == DROPBEAR_SIGNKEY_ED25519) {
  ------------------
  |  Branch (627:6): [True: 0, False: 8.94k]
  ------------------
  628|      0|		buf_put_ed25519_sign(sigblob, key->ed25519key, data_buf);
  629|      0|	}
  630|  8.94k|#endif
  631|  8.94k|	if (sigblob->len == 0) {
  ------------------
  |  Branch (631:6): [True: 0, False: 8.94k]
  ------------------
  632|      0|		dropbear_exit("Non-matching signing type");
  633|      0|	}
  634|  8.94k|	buf_putbufstring(buf, sigblob);
  635|  8.94k|	buf_free(sigblob);
  636|       |
  637|  8.94k|}

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

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

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

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

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

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

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|      1|	if (svr_opts.multiauthmethod && svr_opts.allowblankpass) {
  ------------------
  |  Branch (496:6): [True: 0, False: 1]
  |  Branch (496:34): [True: 0, False: 0]
  ------------------
  497|      0|		dropbear_exit("-t and -B are incompatible");
  498|      0|	}
  499|       |
  500|      1|	if (strlen(svr_opts.authorized_keys_dir) == 0) {
  ------------------
  |  Branch (500:6): [True: 0, False: 1]
  ------------------
  501|      0|		dropbear_exit("Bad -D");
  502|      0|	}
  503|       |
  504|       |#if DROPBEAR_PLUGIN
  505|       |	if (pubkey_plugin) {
  506|       |		if (svr_opts.multiauthmethod) {
  507|       |			dropbear_exit("-t and plugins are incompatible");
  508|       |		}
  509|       |
  510|       |		svr_opts.pubkey_plugin = m_strdup(pubkey_plugin);
  511|       |		char *args = strchr(svr_opts.pubkey_plugin, ',');
  512|       |		if (args) {
  513|       |			*args='\0';
  514|       |			++args;
  515|       |		}
  516|       |		svr_opts.pubkey_plugin_options = args;
  517|       |	}
  518|       |#endif
  519|      1|	if (algo_print_arg) {
  ------------------
  |  Branch (519:6): [True: 0, False: 1]
  ------------------
  520|      0|		print_algos(algo_print_arg);
  521|       |		/* No return */
  522|      0|	}
  523|      1|}
disable_sig_except:
  567|  1.83k|void disable_sig_except(enum signature_type allow_type) {
  568|  1.83k|	int i;
  569|  1.83k|	TRACE(("Disabling other sigs except %d", allow_type));
  570|  18.3k|	for (i = 0; sigalgs[i].name != NULL; i++) {
  ------------------
  |  Branch (570:14): [True: 16.5k, False: 1.83k]
  ------------------
  571|  16.5k|		enum signature_type sig_type = sigalgs[i].val;
  572|  16.5k|		if (sig_type != allow_type) {
  ------------------
  |  Branch (572:7): [True: 14.6k, False: 1.83k]
  ------------------
  573|  14.6k|			sigalgs[i].usable = 0;
  574|  14.6k|		}
  575|  16.5k|	}
  576|  1.83k|}

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

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

