fuzz_early_setup:
   23|      2|void fuzz_early_setup(void) {
   24|       |    /* Set stderr to point to normal stderr by default */
   25|      2|    fuzz.fake_stderr = stderr;
   26|      2|}
fuzz_common_setup:
   28|      1|void fuzz_common_setup(void) {
   29|      1|	disallow_core();
   30|      1|    fuzz.fuzzing = 1;
   31|      1|    fuzz.wrapfds = 1;
   32|      1|    fuzz.do_jmp = 1;
   33|      1|    fuzz.input = m_malloc(sizeof(buffer));
   34|      1|    _dropbear_log = fuzz_dropbear_log;
   35|      1|    crypto_init();
   36|      1|    fuzz_seed("start", 5);
   37|       |    /* let any messages get flushed */
   38|      1|    setlinebuf(stdout);
   39|       |#if DEBUG_TRACE
   40|       |    if (debug_trace)
   41|       |    {
   42|       |        fprintf(stderr, "Dropbear fuzzer: -v specified, not disabling stderr output\n");
   43|       |    }
   44|       |    else
   45|       |#endif
   46|      1|    if (getenv("DROPBEAR_KEEP_STDERR")) {
  ------------------
  |  Branch (46:9): [True: 0, False: 1]
  ------------------
   47|      0|        fprintf(stderr, "Dropbear fuzzer: DROPBEAR_KEEP_STDERR, not disabling stderr output\n");
   48|      0|    } 
   49|      1|    else 
   50|      1|    {
   51|      1|        fprintf(stderr, "Dropbear fuzzer: Disabling stderr output\n");
   52|      1|        fuzz.fake_stderr = fopen("/dev/null", "w");
   53|      1|        assert(fuzz.fake_stderr);
   54|      1|    }
   55|      1|}
fuzz_set_input:
   57|  3.96k|int fuzz_set_input(const uint8_t *Data, size_t Size) {
   58|       |
   59|  3.96k|    fuzz.input->data = (unsigned char*)Data;
   60|  3.96k|    fuzz.input->size = Size;
   61|  3.96k|    fuzz.input->len = Size;
   62|  3.96k|    fuzz.input->pos = 0;
   63|       |
   64|  3.96k|    memset(&ses, 0x0, sizeof(ses));
   65|  3.96k|    memset(&svr_ses, 0x0, sizeof(svr_ses));
   66|  3.96k|    memset(&cli_ses, 0x0, sizeof(cli_ses));
   67|  3.96k|    wrapfd_setup(fuzz.input);
   68|       |    // printhex("input", fuzz.input->data, fuzz.input->len);
   69|       |
   70|  3.96k|    fuzz_seed(fuzz.input->data, MIN(fuzz.input->len, 16));
   71|       |
   72|  3.96k|    return DROPBEAR_SUCCESS;
  ------------------
  |  |  102|  3.96k|#define DROPBEAR_SUCCESS 0
  ------------------
   73|  3.96k|}
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.96k|void fuzz_svr_hook_preloop() {
  106|  3.96k|    if (fuzz.svr_postauth) {
  ------------------
  |  Branch (106:9): [True: 0, False: 3.96k]
  ------------------
  107|      0|        ses.authstate.authdone = 1;
  108|      0|        fill_passwd("root");
  109|      0|    }
  110|  3.96k|}
fuzz_kex_fakealgos:
  197|  18.0k|void fuzz_kex_fakealgos(void) {
  198|  18.0k|    ses.newkeys->recv.crypt_mode = &dropbear_mode_none;
  199|  18.0k|    ses.newkeys->recv.algo_mac = &dropbear_nohash;
  200|  18.0k|}
fuzz_get_socket_address:
  203|  7.93k|                        char **remote_host, char **remote_port, int UNUSED(host_lookup)) {
  204|  7.93k|    if (local_host) {
  ------------------
  |  Branch (204:9): [True: 0, False: 7.93k]
  ------------------
  205|      0|        *local_host = m_strdup("fuzzlocalhost");
  206|      0|    }
  207|  7.93k|    if (local_port) {
  ------------------
  |  Branch (207:9): [True: 0, False: 7.93k]
  ------------------
  208|      0|        *local_port = m_strdup("1234");
  209|      0|    }
  210|  7.93k|    if (remote_host) {
  ------------------
  |  Branch (210:9): [True: 7.93k, False: 0]
  ------------------
  211|  7.93k|        *remote_host = m_strdup("fuzzremotehost");
  212|  7.93k|    }
  213|  7.93k|    if (remote_port) {
  ------------------
  |  Branch (213:9): [True: 3.96k, False: 3.96k]
  ------------------
  214|  3.96k|        *remote_port = m_strdup("9876");
  215|  3.96k|    }
  216|  7.93k|}
fuzz_run_server:
  264|  3.96k|int fuzz_run_server(const uint8_t *Data, size_t Size, int skip_kexmaths, int postauth) {
  265|  3.96k|    static int once = 0;
  266|  3.96k|    if (!once) {
  ------------------
  |  Branch (266:9): [True: 1, False: 3.96k]
  ------------------
  267|      1|        fuzz_svr_setup();
  268|      1|        fuzz.skip_kexmaths = skip_kexmaths;
  269|      1|        once = 1;
  270|      1|    }
  271|       |
  272|  3.96k|    fuzz.svr_postauth = postauth;
  273|       |
  274|  3.96k|    if (fuzz_set_input(Data, Size) == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|  3.96k|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (274:9): [True: 0, False: 3.96k]
  ------------------
  275|      0|        return 0;
  276|      0|    }
  277|       |
  278|  3.96k|    uint32_t wrapseed;
  279|  3.96k|    genrandom((void*)&wrapseed, sizeof(wrapseed));
  280|  3.96k|    wrapfd_setseed(wrapseed);
  281|       |
  282|  3.96k|    int fakesock = wrapfd_new_fuzzinput();
  283|       |
  284|  3.96k|    m_malloc_set_epoch(1);
  285|  3.96k|    fuzz.do_jmp = 1;
  286|  3.96k|    if (setjmp(fuzz.jmp) == 0) {
  ------------------
  |  Branch (286:9): [True: 3.96k, False: 0]
  ------------------
  287|  3.96k|        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.96k|}
fuzz_dump:
  345|   146k|void fuzz_dump(const unsigned char* data, size_t len) {
  346|   146k|    if (fuzz.dumping) {
  ------------------
  |  Branch (346:9): [True: 0, False: 146k]
  ------------------
  347|      0|        TRACE(("dump %zu", len))
  348|      0|        assert(atomicio(vwrite, fuzz.recv_dumpfd, (void*)data, len) == len);
  349|      0|    }
  350|   146k|}
fuzz_getpwnam:
  373|    502|struct passwd* fuzz_getpwnam(const char *login) {
  374|    502|    if (!fuzz.fuzzing) {
  ------------------
  |  Branch (374:9): [True: 0, False: 502]
  ------------------
  375|      0|        return getpwnam(login);
  376|      0|    }
  377|    502|    if (strcmp(login, pwd_other.pw_name) == 0) {
  ------------------
  |  Branch (377:9): [True: 0, False: 502]
  ------------------
  378|      0|        return &pwd_other;
  379|      0|    }
  380|    502|    if (strcmp(login, pwd_root.pw_name) == 0) {
  ------------------
  |  Branch (380:9): [True: 34, False: 468]
  ------------------
  381|     34|        return &pwd_root;
  382|     34|    }
  383|    468|    return NULL;
  384|    502|}
fuzz-common.c:fuzz_dropbear_log:
   84|  4.55k|static void fuzz_dropbear_log(int UNUSED(priority), const char* UNUSED(format), va_list UNUSED(param)) {
   85|       |    /* No print */
   86|  4.55k|}
fuzz-common.c:load_fixed_hostkeys:
  153|      1|static void load_fixed_hostkeys(void) {
  154|       |
  155|      1|    buffer *b = buf_new(3000);
  156|      1|    enum signkey_type type;
  157|       |
  158|      1|    TRACE(("load fixed hostkeys"))
  159|       |
  160|      1|    svr_opts.hostkey = new_sign_key();
  161|       |
  162|      1|    buf_setlen(b, 0);
  163|      1|    buf_putbytes(b, keyr, keyr_len);
  164|      1|    buf_setpos(b, 0);
  165|      1|    type = DROPBEAR_SIGNKEY_RSA;
  166|      1|    if (buf_get_priv_key(b, svr_opts.hostkey, &type) == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (166:9): [True: 0, False: 1]
  ------------------
  167|      0|        dropbear_exit("failed fixed rsa hostkey");
  168|      0|    }
  169|       |
  170|      1|    buf_setlen(b, 0);
  171|      1|    buf_putbytes(b, keyd, keyd_len);
  172|      1|    buf_setpos(b, 0);
  173|      1|    type = DROPBEAR_SIGNKEY_DSS;
  174|      1|    if (buf_get_priv_key(b, svr_opts.hostkey, &type) == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (174:9): [True: 0, False: 1]
  ------------------
  175|      0|        dropbear_exit("failed fixed dss hostkey");
  176|      0|    }
  177|       |
  178|      1|    buf_setlen(b, 0);
  179|      1|    buf_putbytes(b, keye, keye_len);
  180|      1|    buf_setpos(b, 0);
  181|      1|    type = DROPBEAR_SIGNKEY_ECDSA_NISTP256;
  182|      1|    if (buf_get_priv_key(b, svr_opts.hostkey, &type) == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (182:9): [True: 0, False: 1]
  ------------------
  183|      0|        dropbear_exit("failed fixed ecdsa hostkey");
  184|      0|    }
  185|       |
  186|      1|    buf_setlen(b, 0);
  187|      1|    buf_putbytes(b, keyed25519, keyed25519_len);
  188|      1|    buf_setpos(b, 0);
  189|      1|    type = DROPBEAR_SIGNKEY_ED25519;
  190|      1|    if (buf_get_priv_key(b, svr_opts.hostkey, &type) == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (190:9): [True: 0, False: 1]
  ------------------
  191|      0|        dropbear_exit("failed fixed ed25519 hostkey");
  192|      0|    }
  193|       |
  194|      1|    buf_free(b);
  195|      1|}

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

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

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

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

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

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

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

sha1_process:
  491|   214k|int func_name (hash_state * md, const unsigned char *in, unsigned long inlen)               \
  492|   214k|{                                                                                           \
  493|   214k|    unsigned long n;                                                                        \
  494|   214k|    int           err;                                                                      \
  495|   214k|    LTC_ARGCHK(md != NULL);                                                                 \
  ------------------
  |  |   32|   214k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 214k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  496|   214k|    LTC_ARGCHK(in != NULL);                                                                 \
  ------------------
  |  |   32|   214k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 214k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  497|   214k|    if (md-> state_var .curlen > sizeof(md-> state_var .buf)) {                             \
  ------------------
  |  Branch (497:9): [True: 0, False: 214k]
  ------------------
  498|      0|       return CRYPT_INVALID_ARG;                                                            \
  499|      0|    }                                                                                       \
  500|   214k|    if ((md-> state_var .length + inlen) < md-> state_var .length) {                        \
  ------------------
  |  Branch (500:9): [True: 0, False: 214k]
  ------------------
  501|      0|      return CRYPT_HASH_OVERFLOW;                                                           \
  502|      0|    }                                                                                       \
  503|   764k|    while (inlen > 0) {                                                                     \
  ------------------
  |  Branch (503:12): [True: 550k, False: 214k]
  ------------------
  504|   550k|        if (md-> state_var .curlen == 0 && inlen >= block_size) {                           \
  ------------------
  |  Branch (504:13): [True: 380k, False: 169k]
  |  Branch (504:44): [True: 312k, False: 68.7k]
  ------------------
  505|   312k|           if ((err = compress_name (md, (unsigned char *)in)) != CRYPT_OK) {               \
  ------------------
  |  Branch (505:16): [True: 0, False: 312k]
  ------------------
  506|      0|              return err;                                                                   \
  507|      0|           }                                                                                \
  508|   312k|           md-> state_var .length += block_size * 8;                                        \
  509|   312k|           in             += block_size;                                                    \
  510|   312k|           inlen          -= block_size;                                                    \
  511|   312k|        } else {                                                                            \
  512|   238k|           n = MIN(inlen, (block_size - md-> state_var .curlen));                           \
  ------------------
  |  |  425|   238k|   #define MIN(x, y) ( ((x)<(y))?(x):(y) )
  |  |  ------------------
  |  |  |  Branch (425:24): [True: 198k, False: 40.0k]
  |  |  ------------------
  ------------------
  513|   238k|           XMEMCPY(md-> state_var .buf + md-> state_var.curlen, in, (size_t)n);             \
  ------------------
  |  |   39|   238k|#define XMEMCPY  memcpy
  ------------------
  514|   238k|           md-> state_var .curlen += n;                                                     \
  515|   238k|           in             += n;                                                             \
  516|   238k|           inlen          -= n;                                                             \
  517|   238k|           if (md-> state_var .curlen == block_size) {                                      \
  ------------------
  |  Branch (517:16): [True: 40.0k, False: 198k]
  ------------------
  518|  40.0k|              if ((err = compress_name (md, md-> state_var .buf)) != CRYPT_OK) {            \
  ------------------
  |  Branch (518:19): [True: 0, False: 40.0k]
  ------------------
  519|      0|                 return err;                                                                \
  520|      0|              }                                                                             \
  521|  40.0k|              md-> state_var .length += 8*block_size;                                       \
  522|  40.0k|              md-> state_var .curlen = 0;                                                   \
  523|  40.0k|           }                                                                                \
  524|   238k|       }                                                                                    \
  525|   550k|    }                                                                                       \
  526|   214k|    return CRYPT_OK;                                                                        \
  527|   214k|}
sha256_process:
  491|   816k|int func_name (hash_state * md, const unsigned char *in, unsigned long inlen)               \
  492|   816k|{                                                                                           \
  493|   816k|    unsigned long n;                                                                        \
  494|   816k|    int           err;                                                                      \
  495|   816k|    LTC_ARGCHK(md != NULL);                                                                 \
  ------------------
  |  |   32|   816k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 816k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  496|   816k|    LTC_ARGCHK(in != NULL);                                                                 \
  ------------------
  |  |   32|   816k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 816k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  497|   816k|    if (md-> state_var .curlen > sizeof(md-> state_var .buf)) {                             \
  ------------------
  |  Branch (497:9): [True: 0, False: 816k]
  ------------------
  498|      0|       return CRYPT_INVALID_ARG;                                                            \
  499|      0|    }                                                                                       \
  500|   816k|    if ((md-> state_var .length + inlen) < md-> state_var .length) {                        \
  ------------------
  |  Branch (500:9): [True: 0, False: 816k]
  ------------------
  501|      0|      return CRYPT_HASH_OVERFLOW;                                                           \
  502|      0|    }                                                                                       \
  503|  2.00M|    while (inlen > 0) {                                                                     \
  ------------------
  |  Branch (503:12): [True: 1.18M, False: 816k]
  ------------------
  504|  1.18M|        if (md-> state_var .curlen == 0 && inlen >= block_size) {                           \
  ------------------
  |  Branch (504:13): [True: 796k, False: 389k]
  |  Branch (504:44): [True: 414k, False: 382k]
  ------------------
  505|   414k|           if ((err = compress_name (md, (unsigned char *)in)) != CRYPT_OK) {               \
  ------------------
  |  Branch (505:16): [True: 0, False: 414k]
  ------------------
  506|      0|              return err;                                                                   \
  507|      0|           }                                                                                \
  508|   414k|           md-> state_var .length += block_size * 8;                                        \
  509|   414k|           in             += block_size;                                                    \
  510|   414k|           inlen          -= block_size;                                                    \
  511|   771k|        } else {                                                                            \
  512|   771k|           n = MIN(inlen, (block_size - md-> state_var .curlen));                           \
  ------------------
  |  |  425|   771k|   #define MIN(x, y) ( ((x)<(y))?(x):(y) )
  |  |  ------------------
  |  |  |  Branch (425:24): [True: 740k, False: 31.8k]
  |  |  ------------------
  ------------------
  513|   771k|           XMEMCPY(md-> state_var .buf + md-> state_var.curlen, in, (size_t)n);             \
  ------------------
  |  |   39|   771k|#define XMEMCPY  memcpy
  ------------------
  514|   771k|           md-> state_var .curlen += n;                                                     \
  515|   771k|           in             += n;                                                             \
  516|   771k|           inlen          -= n;                                                             \
  517|   771k|           if (md-> state_var .curlen == block_size) {                                      \
  ------------------
  |  Branch (517:16): [True: 31.8k, False: 740k]
  ------------------
  518|  31.8k|              if ((err = compress_name (md, md-> state_var .buf)) != CRYPT_OK) {            \
  ------------------
  |  Branch (518:19): [True: 0, False: 31.8k]
  ------------------
  519|      0|                 return err;                                                                \
  520|      0|              }                                                                             \
  521|  31.8k|              md-> state_var .length += 8*block_size;                                       \
  522|  31.8k|              md-> state_var .curlen = 0;                                                   \
  523|  31.8k|           }                                                                                \
  524|   771k|       }                                                                                    \
  525|  1.18M|    }                                                                                       \
  526|   816k|    return CRYPT_OK;                                                                        \
  527|   816k|}
sha512_process:
  491|  6.07k|int func_name (hash_state * md, const unsigned char *in, unsigned long inlen)               \
  492|  6.07k|{                                                                                           \
  493|  6.07k|    unsigned long n;                                                                        \
  494|  6.07k|    int           err;                                                                      \
  495|  6.07k|    LTC_ARGCHK(md != NULL);                                                                 \
  ------------------
  |  |   32|  6.07k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 6.07k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  496|  6.07k|    LTC_ARGCHK(in != NULL);                                                                 \
  ------------------
  |  |   32|  6.07k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 6.07k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
  497|  6.07k|    if (md-> state_var .curlen > sizeof(md-> state_var .buf)) {                             \
  ------------------
  |  Branch (497:9): [True: 0, False: 6.07k]
  ------------------
  498|      0|       return CRYPT_INVALID_ARG;                                                            \
  499|      0|    }                                                                                       \
  500|  6.07k|    if ((md-> state_var .length + inlen) < md-> state_var .length) {                        \
  ------------------
  |  Branch (500:9): [True: 0, False: 6.07k]
  ------------------
  501|      0|      return CRYPT_HASH_OVERFLOW;                                                           \
  502|      0|    }                                                                                       \
  503|  12.1k|    while (inlen > 0) {                                                                     \
  ------------------
  |  Branch (503:12): [True: 6.07k, False: 6.07k]
  ------------------
  504|  6.07k|        if (md-> state_var .curlen == 0 && inlen >= block_size) {                           \
  ------------------
  |  Branch (504:13): [True: 3.03k, False: 3.03k]
  |  Branch (504:44): [True: 0, False: 3.03k]
  ------------------
  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|  6.07k|        } else {                                                                            \
  512|  6.07k|           n = MIN(inlen, (block_size - md-> state_var .curlen));                           \
  ------------------
  |  |  425|  6.07k|   #define MIN(x, y) ( ((x)<(y))?(x):(y) )
  |  |  ------------------
  |  |  |  Branch (425:24): [True: 6.07k, False: 0]
  |  |  ------------------
  ------------------
  513|  6.07k|           XMEMCPY(md-> state_var .buf + md-> state_var.curlen, in, (size_t)n);             \
  ------------------
  |  |   39|  6.07k|#define XMEMCPY  memcpy
  ------------------
  514|  6.07k|           md-> state_var .curlen += n;                                                     \
  515|  6.07k|           in             += n;                                                             \
  516|  6.07k|           inlen          -= n;                                                             \
  517|  6.07k|           if (md-> state_var .curlen == block_size) {                                      \
  ------------------
  |  Branch (517:16): [True: 0, False: 6.07k]
  ------------------
  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|  6.07k|       }                                                                                    \
  525|  6.07k|    }                                                                                       \
  526|  6.07k|    return CRYPT_OK;                                                                        \
  527|  6.07k|}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

ecc_ansi_x963_export:
   31|  6.37k|{
   32|  6.37k|   unsigned char buf[ECC_BUF_SIZE];
   33|  6.37k|   unsigned long numlen, xlen, ylen;
   34|       |
   35|  6.37k|   LTC_ARGCHK(key    != NULL);
  ------------------
  |  |   32|  6.37k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 6.37k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   36|  6.37k|   LTC_ARGCHK(outlen != NULL);
  ------------------
  |  |   32|  6.37k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 6.37k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   37|       |
   38|  6.37k|   if (ltc_ecc_is_valid_idx(key->idx) == 0) {
  ------------------
  |  Branch (38:8): [True: 0, False: 6.37k]
  ------------------
   39|      0|      return CRYPT_INVALID_ARG;
   40|      0|   }
   41|  6.37k|   numlen = key->dp->size;
   42|  6.37k|   xlen = mp_unsigned_bin_size(key->pubkey.x);
  ------------------
  |  |  539|  6.37k|#define mp_unsigned_bin_size(a)      ltc_mp.unsigned_size(a)
  ------------------
   43|  6.37k|   ylen = mp_unsigned_bin_size(key->pubkey.y);
  ------------------
  |  |  539|  6.37k|#define mp_unsigned_bin_size(a)      ltc_mp.unsigned_size(a)
  ------------------
   44|       |
   45|  6.37k|   if (xlen > numlen || ylen > numlen || sizeof(buf) < numlen) {
  ------------------
  |  Branch (45:8): [True: 0, False: 6.37k]
  |  Branch (45:25): [True: 0, False: 6.37k]
  |  Branch (45:42): [True: 0, False: 6.37k]
  ------------------
   46|      0|      return CRYPT_BUFFER_OVERFLOW;
   47|      0|   }
   48|       |
   49|  6.37k|   if (*outlen < (1 + 2*numlen)) {
  ------------------
  |  Branch (49:8): [True: 0, False: 6.37k]
  ------------------
   50|      0|      *outlen = 1 + 2*numlen;
   51|      0|      return CRYPT_BUFFER_OVERFLOW;
   52|      0|   }
   53|       |
   54|  6.37k|   LTC_ARGCHK(out    != NULL);
  ------------------
  |  |   32|  6.37k|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 6.37k]
  |  |  |  Branch (32:87): [Folded - Ignored]
  |  |  ------------------
  ------------------
   55|       |
   56|       |   /* store byte 0x04 */
   57|  6.37k|   out[0] = 0x04;
   58|       |
   59|       |   /* pad and store x */
   60|  6.37k|   zeromem(buf, sizeof(buf));
   61|  6.37k|   mp_to_unsigned_bin(key->pubkey.x, buf + (numlen - xlen));
  ------------------
  |  |  540|  6.37k|#define mp_to_unsigned_bin(a, b)     ltc_mp.unsigned_write(a, b)
  ------------------
   62|  6.37k|   XMEMCPY(out+1, buf, numlen);
  ------------------
  |  |   39|  6.37k|#define XMEMCPY  memcpy
  ------------------
   63|       |
   64|       |   /* pad and store y */
   65|  6.37k|   zeromem(buf, sizeof(buf));
   66|  6.37k|   mp_to_unsigned_bin(key->pubkey.y, buf + (numlen - ylen));
  ------------------
  |  |  540|  6.37k|#define mp_to_unsigned_bin(a, b)     ltc_mp.unsigned_write(a, b)
  ------------------
   67|  6.37k|   XMEMCPY(out+1+numlen, buf, numlen);
  ------------------
  |  |   39|  6.37k|#define XMEMCPY  memcpy
  ------------------
   68|       |
   69|  6.37k|   *outlen = 1 + 2*numlen;
   70|  6.37k|   return CRYPT_OK;
   71|  6.37k|}

ecc_free:
   29|  3.18k|{
   30|  3.18k|   LTC_ARGCHKVD(key != NULL);
  ------------------
  |  |   33|  3.18k|#define LTC_ARGCHKVD(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (33:34): [True: 0, False: 3.18k]
  |  |  |  Branch (33:89): [Folded - Ignored]
  |  |  ------------------
  ------------------
   31|  3.18k|   mp_clear_multi(key->pubkey.x, key->pubkey.y, key->pubkey.z, key->k, NULL);
  ------------------
  |  |  519|  3.18k|#define mp_clear_multi               ltc_deinit_multi
  ------------------
   32|  3.18k|}

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

ltc_ecc_is_valid_idx:
   29|  6.37k|{
   30|  6.37k|   int x;
   31|       |
   32|  57.3k|   for (x = 0; ltc_ecc_sets[x].size != 0; x++);
  ------------------
  |  Branch (32:16): [True: 51.0k, False: 6.37k]
  ------------------
   33|       |   /* -1 is a valid index --- indicating that the domain params were supplied by the user */
   34|  6.37k|   if ((n >= -1) && (n < x)) {
  ------------------
  |  Branch (34:8): [True: 6.37k, False: 0]
  |  Branch (34:21): [True: 6.37k, False: 0]
  ------------------
   35|  6.37k|      return 1;
   36|  6.37k|   }
   37|      0|   return 0;
   38|  6.37k|}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

mp_mul_2d:
    8|  11.5M|{
    9|  11.5M|   mp_digit d;
   10|  11.5M|   mp_err   err;
   11|       |
   12|  11.5M|   if (b < 0) {
  ------------------
  |  Branch (12:8): [True: 0, False: 11.5M]
  ------------------
   13|      0|      return MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
   14|      0|   }
   15|       |
   16|       |   /* copy */
   17|  11.5M|   if (a != c) {
  ------------------
  |  Branch (17:8): [True: 0, False: 11.5M]
  ------------------
   18|      0|      if ((err = mp_copy(a, c)) != MP_OKAY) {
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (18:11): [True: 0, False: 0]
  ------------------
   19|      0|         return err;
   20|      0|      }
   21|      0|   }
   22|       |
   23|  11.5M|   if (c->alloc < (c->used + (b / MP_DIGIT_BIT) + 1)) {
  ------------------
  |  |   82|  11.5M|#   define MP_DIGIT_BIT 60
  ------------------
  |  Branch (23:8): [True: 282k, False: 11.2M]
  ------------------
   24|   282k|      if ((err = mp_grow(c, c->used + (b / MP_DIGIT_BIT) + 1)) != MP_OKAY) {
  ------------------
  |  |   82|   282k|#   define MP_DIGIT_BIT 60
  ------------------
                    if ((err = mp_grow(c, c->used + (b / MP_DIGIT_BIT) + 1)) != MP_OKAY) {
  ------------------
  |  |  161|   282k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (24:11): [True: 0, False: 282k]
  ------------------
   25|      0|         return err;
   26|      0|      }
   27|   282k|   }
   28|       |
   29|       |   /* shift by as many digits in the bit count */
   30|  11.5M|   if (b >= MP_DIGIT_BIT) {
  ------------------
  |  |   82|  11.5M|#   define MP_DIGIT_BIT 60
  ------------------
  |  Branch (30:8): [True: 0, False: 11.5M]
  ------------------
   31|      0|      if ((err = mp_lshd(c, b / MP_DIGIT_BIT)) != MP_OKAY) {
  ------------------
  |  |   82|      0|#   define MP_DIGIT_BIT 60
  ------------------
                    if ((err = mp_lshd(c, b / MP_DIGIT_BIT)) != MP_OKAY) {
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (31:11): [True: 0, False: 0]
  ------------------
   32|      0|         return err;
   33|      0|      }
   34|      0|   }
   35|       |
   36|       |   /* shift any bit count < MP_DIGIT_BIT */
   37|  11.5M|   d = (mp_digit)(b % MP_DIGIT_BIT);
  ------------------
  |  |   82|  11.5M|#   define MP_DIGIT_BIT 60
  ------------------
   38|  11.5M|   if (d != 0u) {
  ------------------
  |  Branch (38:8): [True: 11.5M, False: 0]
  ------------------
   39|  11.5M|      mp_digit *tmpc, shift, mask, r, rr;
   40|  11.5M|      int x;
   41|       |
   42|       |      /* bitmask for carries */
   43|  11.5M|      mask = ((mp_digit)1 << d) - (mp_digit)1;
   44|       |
   45|       |      /* shift for msbs */
   46|  11.5M|      shift = (mp_digit)MP_DIGIT_BIT - d;
  ------------------
  |  |   82|  11.5M|#   define MP_DIGIT_BIT 60
  ------------------
   47|       |
   48|       |      /* alias */
   49|  11.5M|      tmpc = c->dp;
   50|       |
   51|       |      /* carry */
   52|  11.5M|      r    = 0;
   53|   210M|      for (x = 0; x < c->used; x++) {
  ------------------
  |  Branch (53:19): [True: 199M, False: 11.5M]
  ------------------
   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|  11.5M|      if (r != 0u) {
  ------------------
  |  Branch (66:11): [True: 44.1k, False: 11.5M]
  ------------------
   67|  44.1k|         c->dp[(c->used)++] = r;
   68|  44.1k|      }
   69|  11.5M|   }
   70|  11.5M|   mp_clamp(c);
   71|  11.5M|   return MP_OKAY;
  ------------------
  |  |  161|  11.5M|#define MP_OKAY       0   /* no error */
  ------------------
   72|  11.5M|}

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: 16.2k, False: 4.03M]
  ------------------
   16|  16.2k|      if ((err = mp_grow(c, a->used + 1)) != MP_OKAY) {
  ------------------
  |  |  161|  16.2k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (16:11): [True: 0, False: 16.2k]
  ------------------
   17|      0|         return err;
   18|      0|      }
   19|  16.2k|   }
   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|  34.3M|   for (ix = 0; ix < a->used; ix++) {
  ------------------
  |  Branch (37:17): [True: 30.2M, False: 4.04M]
  ------------------
   38|       |      /* compute product and carry sum for this term */
   39|  30.2M|      r       = (mp_word)u + ((mp_word)*tmpa++ * (mp_word)b);
   40|       |
   41|       |      /* mask off higher bits to get a single digit */
   42|  30.2M|      *tmpc++ = (mp_digit)(r & (mp_word)MP_MASK);
  ------------------
  |  |  106|  30.2M|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|  30.2M|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
   43|       |
   44|       |      /* send carry into next iteration */
   45|  30.2M|      u       = (mp_digit)(r >> (mp_word)MP_DIGIT_BIT);
  ------------------
  |  |   82|  30.2M|#   define MP_DIGIT_BIT 60
  ------------------
   46|  30.2M|   }
   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 - Ignored]
  |  |  ------------------
  ------------------
   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|  80.5k|{
    9|  80.5k|   mp_err err;
   10|  80.5k|   mp_int t;
   11|       |
   12|  80.5k|   if ((err = mp_init_size(&t, c->used)) != MP_OKAY) {
  ------------------
  |  |  161|  80.5k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (12:8): [True: 0, False: 80.5k]
  ------------------
   13|      0|      return err;
   14|      0|   }
   15|       |
   16|  80.5k|   if ((err = mp_mul(a, b, &t)) != MP_OKAY) {
  ------------------
  |  |  161|  80.5k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (16:8): [True: 0, False: 80.5k]
  ------------------
   17|      0|      goto LBL_ERR;
   18|      0|   }
   19|  80.5k|   err = mp_mod(&t, c, d);
   20|       |
   21|  80.5k|LBL_ERR:
   22|  80.5k|   mp_clear(&t);
   23|  80.5k|   return err;
   24|  80.5k|}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

send_msg_kexinit:
   55|  19.2k|void send_msg_kexinit() {
   56|       |
   57|  19.2k|	CHECKCLEARTOWRITE();
   58|  19.2k|	buf_putbyte(ses.writepayload, SSH_MSG_KEXINIT);
  ------------------
  |  |   36|  19.2k|#define SSH_MSG_KEXINIT                20
  ------------------
   59|       |
   60|       |	/* cookie */
   61|  19.2k|	genrandom(buf_getwriteptr(ses.writepayload, 16), 16);
   62|  19.2k|	buf_incrwritepos(ses.writepayload, 16);
   63|       |
   64|       |	/* kex algos */
   65|  19.2k|	buf_put_algolist(ses.writepayload, sshkex);
   66|       |
   67|       |	/* server_host_key_algorithms */
   68|  19.2k|	buf_put_algolist(ses.writepayload, sigalgs);
   69|       |
   70|       |	/* encryption_algorithms_client_to_server */
   71|  19.2k|	buf_put_algolist(ses.writepayload, sshciphers);
   72|       |
   73|       |	/* encryption_algorithms_server_to_client */
   74|  19.2k|	buf_put_algolist(ses.writepayload, sshciphers);
   75|       |
   76|       |	/* mac_algorithms_client_to_server */
   77|  19.2k|	buf_put_algolist(ses.writepayload, sshhashes);
   78|       |
   79|       |	/* mac_algorithms_server_to_client */
   80|  19.2k|	buf_put_algolist(ses.writepayload, sshhashes);
   81|       |
   82|       |
   83|       |	/* compression_algorithms_client_to_server */
   84|  19.2k|	buf_put_algolist(ses.writepayload, ses.compress_algos);
   85|       |
   86|       |	/* compression_algorithms_server_to_client */
   87|  19.2k|	buf_put_algolist(ses.writepayload, ses.compress_algos);
   88|       |
   89|       |	/* languages_client_to_server */
   90|  19.2k|	buf_putstring(ses.writepayload, "", 0);
   91|       |
   92|       |	/* languages_server_to_client */
   93|  19.2k|	buf_putstring(ses.writepayload, "", 0);
   94|       |
   95|       |	/* first_kex_packet_follows */
   96|  19.2k|	buf_putbyte(ses.writepayload, (ses.send_kex_first_guess != NULL));
   97|       |
   98|       |	/* reserved unit32 */
   99|  19.2k|	buf_putint(ses.writepayload, 0);
  100|       |
  101|       |	/* set up transmitted kex packet buffer for hashing. 
  102|       |	 * This is freed after the end of the kex */
  103|  19.2k|	ses.transkexinit = buf_newcopy(ses.writepayload);
  104|       |
  105|  19.2k|	encrypt_packet();
  106|  19.2k|	ses.dataallowed = 0; /* don't send other packets during kex */
  107|       |
  108|  19.2k|	ses.kexstate.sentkexinit = 1;
  109|       |
  110|  19.2k|	ses.newkeys = (struct key_context*)m_malloc(sizeof(struct key_context));
  111|       |
  112|  19.2k|	if (ses.send_kex_first_guess) {
  ------------------
  |  Branch (112:6): [True: 0, False: 19.2k]
  ------------------
  113|      0|		ses.newkeys->algo_kex = first_usable_algo(sshkex)->data;
  114|      0|		ses.newkeys->algo_signature = first_usable_algo(sigalgs)->val;
  115|      0|		ses.newkeys->algo_hostkey = signkey_type_from_signature(ses.newkeys->algo_signature);
  116|      0|		ses.send_kex_first_guess();
  117|      0|	}
  118|       |
  119|  19.2k|	TRACE(("DATAALLOWED=0"))
  120|  19.2k|	TRACE(("-> KEXINIT"))
  121|       |
  122|  19.2k|}
send_msg_newkeys:
  166|  17.2k|void send_msg_newkeys() {
  167|       |
  168|  17.2k|	TRACE(("enter send_msg_newkeys"))
  169|       |
  170|       |	/* generate the kexinit request */
  171|  17.2k|	CHECKCLEARTOWRITE();
  172|  17.2k|	buf_putbyte(ses.writepayload, SSH_MSG_NEWKEYS);
  ------------------
  |  |   37|  17.2k|#define SSH_MSG_NEWKEYS                21
  ------------------
  173|  17.2k|	encrypt_packet();
  174|       |
  175|       |	
  176|       |	/* set up our state */
  177|  17.2k|	ses.kexstate.sentnewkeys = 1;
  178|  17.2k|	if (ses.kexstate.donefirstkex) {
  ------------------
  |  Branch (178:6): [True: 14.9k, False: 2.38k]
  ------------------
  179|  14.9k|		ses.kexstate.donesecondkex = 1;
  180|  14.9k|	}
  181|  17.2k|	ses.kexstate.donefirstkex = 1;
  182|  17.2k|	ses.dataallowed = 1; /* we can send other packets again now */
  183|  17.2k|	gen_new_keys();
  184|  17.2k|	switch_keys();
  185|       |
  186|  17.2k|	TRACE(("leave send_msg_newkeys"))
  187|  17.2k|}
recv_msg_newkeys:
  190|  16.2k|void recv_msg_newkeys() {
  191|       |
  192|  16.2k|	TRACE(("enter recv_msg_newkeys"))
  193|       |
  194|  16.2k|	ses.kexstate.recvnewkeys = 1;
  195|  16.2k|	switch_keys();
  196|       |	
  197|  16.2k|	TRACE(("leave recv_msg_newkeys"))
  198|  16.2k|}
kexfirstinitialise:
  202|  3.96k|void kexfirstinitialise() {
  203|  3.96k|#ifdef DISABLE_ZLIB
  204|  3.96k|	ses.compress_algos = ssh_nocompress;
  205|       |#else
  206|       |	switch (opts.compress_mode)
  207|       |	{
  208|       |		case DROPBEAR_COMPRESS_DELAYED:
  209|       |			ses.compress_algos = ssh_delaycompress;
  210|       |			break;
  211|       |
  212|       |		case DROPBEAR_COMPRESS_ON:
  213|       |			ses.compress_algos = ssh_compress;
  214|       |			break;
  215|       |
  216|       |		case DROPBEAR_COMPRESS_OFF:
  217|       |			ses.compress_algos = ssh_nocompress;
  218|       |			break;
  219|       |	}
  220|       |#endif
  221|  3.96k|	kexinitialise();
  222|  3.96k|}
recv_msg_kexinit:
  474|  18.6k|void recv_msg_kexinit() {
  475|       |	
  476|  18.6k|	unsigned int kexhashbuf_len = 0;
  477|  18.6k|	unsigned int remote_ident_len = 0;
  478|  18.6k|	unsigned int local_ident_len = 0;
  479|       |
  480|  18.6k|	TRACE(("<- KEXINIT"))
  481|  18.6k|	TRACE(("enter recv_msg_kexinit"))
  482|       |	
  483|  18.6k|	if (!ses.kexstate.sentkexinit) {
  ------------------
  |  Branch (483:6): [True: 15.2k, False: 3.38k]
  ------------------
  484|       |		/* we need to send a kex packet */
  485|  15.2k|		send_msg_kexinit();
  486|  15.2k|		TRACE(("continue recv_msg_kexinit: sent kexinit"))
  487|  15.2k|	}
  488|       |
  489|       |	/* "Once a party has sent a SSH_MSG_KEXINIT message ...
  490|       |	further SSH_MSG_KEXINIT messages MUST NOT be sent" */
  491|  18.6k|	if (ses.kexstate.recvkexinit) {
  ------------------
  |  Branch (491:6): [True: 0, False: 18.6k]
  ------------------
  492|      0|		dropbear_exit("Unexpected KEXINIT");
  493|      0|	}
  494|       |
  495|       |	/* start the kex hash */
  496|  18.6k|	local_ident_len = strlen(LOCAL_IDENT);
  ------------------
  |  |   10|  18.6k|#define LOCAL_IDENT "SSH-2.0-dropbear_" DROPBEAR_VERSION
  |  |  ------------------
  |  |  |  |    7|  18.6k|#define DROPBEAR_VERSION "2022.83"
  |  |  ------------------
  ------------------
  497|  18.6k|	remote_ident_len = strlen(ses.remoteident);
  498|       |
  499|  18.6k|	kexhashbuf_len = local_ident_len + remote_ident_len
  500|  18.6k|		+ ses.transkexinit->len + ses.payload->len
  501|  18.6k|		+ KEXHASHBUF_MAX_INTS;
  ------------------
  |  |  240|  18.6k|#define KEXHASHBUF_MAX_INTS (1700 + 130 + 130 + 130)
  ------------------
  502|       |
  503|  18.6k|	ses.kexhashbuf = buf_new(kexhashbuf_len);
  504|       |
  505|  18.6k|	if (IS_DROPBEAR_CLIENT) {
  ------------------
  |  |  320|  18.6k|#define IS_DROPBEAR_CLIENT (ses.isserver == 0)
  |  |  ------------------
  |  |  |  Branch (320:28): [True: 0, False: 18.6k]
  |  |  ------------------
  ------------------
  506|       |
  507|       |		/* read the peer's choice of algos */
  508|      0|		read_kex_algos();
  509|       |
  510|       |		/* V_C, the client's version string (CR and NL excluded) */
  511|      0|		buf_putstring(ses.kexhashbuf, LOCAL_IDENT, local_ident_len);
  ------------------
  |  |   10|      0|#define LOCAL_IDENT "SSH-2.0-dropbear_" DROPBEAR_VERSION
  |  |  ------------------
  |  |  |  |    7|      0|#define DROPBEAR_VERSION "2022.83"
  |  |  ------------------
  ------------------
  512|       |		/* V_S, the server's version string (CR and NL excluded) */
  513|      0|		buf_putstring(ses.kexhashbuf, ses.remoteident, remote_ident_len);
  514|       |
  515|       |		/* I_C, the payload of the client's SSH_MSG_KEXINIT */
  516|      0|		buf_putstring(ses.kexhashbuf,
  517|      0|			(const char*)ses.transkexinit->data, ses.transkexinit->len);
  518|       |		/* I_S, the payload of the server's SSH_MSG_KEXINIT */
  519|      0|		buf_setpos(ses.payload, ses.payload_beginning);
  520|      0|		buf_putstring(ses.kexhashbuf,
  521|      0|			(const char*)buf_getptr(ses.payload, ses.payload->len-ses.payload->pos),
  522|      0|			ses.payload->len-ses.payload->pos);
  523|      0|		ses.requirenext = SSH_MSG_KEXDH_REPLY;
  ------------------
  |  |   39|      0|#define SSH_MSG_KEXDH_REPLY            31
  ------------------
  524|  18.6k|	} else {
  525|       |		/* SERVER */
  526|       |
  527|       |		/* read the peer's choice of algos */
  528|  18.6k|		read_kex_algos();
  529|       |		/* V_C, the client's version string (CR and NL excluded) */
  530|  18.6k|		buf_putstring(ses.kexhashbuf, ses.remoteident, remote_ident_len);
  531|       |		/* V_S, the server's version string (CR and NL excluded) */
  532|  18.6k|		buf_putstring(ses.kexhashbuf, LOCAL_IDENT, local_ident_len);
  ------------------
  |  |   10|  18.6k|#define LOCAL_IDENT "SSH-2.0-dropbear_" DROPBEAR_VERSION
  |  |  ------------------
  |  |  |  |    7|  18.6k|#define DROPBEAR_VERSION "2022.83"
  |  |  ------------------
  ------------------
  533|       |
  534|       |		/* I_C, the payload of the client's SSH_MSG_KEXINIT */
  535|  18.6k|		buf_setpos(ses.payload, ses.payload_beginning);
  536|  18.6k|		buf_putstring(ses.kexhashbuf, 
  537|  18.6k|			(const char*)buf_getptr(ses.payload, ses.payload->len-ses.payload->pos),
  538|  18.6k|			ses.payload->len-ses.payload->pos);
  539|       |
  540|       |		/* I_S, the payload of the server's SSH_MSG_KEXINIT */
  541|  18.6k|		buf_putstring(ses.kexhashbuf,
  542|  18.6k|			(const char*)ses.transkexinit->data, ses.transkexinit->len);
  543|       |
  544|  18.6k|		ses.requirenext = SSH_MSG_KEXDH_INIT;
  ------------------
  |  |   38|  18.6k|#define SSH_MSG_KEXDH_INIT             30
  ------------------
  545|  18.6k|	}
  546|       |
  547|  18.6k|	buf_free(ses.transkexinit);
  548|  18.6k|	ses.transkexinit = NULL;
  549|       |	/* the rest of ses.kexhashbuf will be done after DH exchange */
  550|       |
  551|  18.6k|	ses.kexstate.recvkexinit = 1;
  552|       |
  553|  18.6k|	TRACE(("leave recv_msg_kexinit"))
  554|  18.6k|}
gen_kexdh_param:
  566|  10.2k|struct kex_dh_param *gen_kexdh_param() {
  567|  10.2k|	struct kex_dh_param *param = NULL;
  568|       |
  569|  10.2k|	DEF_MP_INT(dh_p);
  ------------------
  |  |   80|  10.2k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  570|  10.2k|	DEF_MP_INT(dh_q);
  ------------------
  |  |   80|  10.2k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  571|  10.2k|	DEF_MP_INT(dh_g);
  ------------------
  |  |   80|  10.2k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  572|       |
  573|  10.2k|	TRACE(("enter gen_kexdh_vals"))
  574|       |
  575|  10.2k|	param = m_malloc(sizeof(*param));
  576|  10.2k|	m_mp_init_multi(&param->pub, &param->priv, &dh_g, &dh_p, &dh_q, NULL);
  577|       |
  578|       |	/* read the prime and generator*/
  579|  10.2k|	load_dh_p(&dh_p);
  580|       |	
  581|  10.2k|	mp_set_ul(&dh_g, DH_G_VAL);
  582|       |
  583|       |	/* calculate q = (p-1)/2 */
  584|       |	/* dh_priv is just a temp var here */
  585|  10.2k|	if (mp_sub_d(&dh_p, 1, &param->priv) != MP_OKAY) { 
  ------------------
  |  |  161|  10.2k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (585:6): [True: 0, False: 10.2k]
  ------------------
  586|      0|		dropbear_exit("Diffie-Hellman error");
  587|      0|	}
  588|  10.2k|	if (mp_div_2(&param->priv, &dh_q) != MP_OKAY) {
  ------------------
  |  |  161|  10.2k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (588:6): [True: 0, False: 10.2k]
  ------------------
  589|      0|		dropbear_exit("Diffie-Hellman error");
  590|      0|	}
  591|       |
  592|       |	/* Generate a private portion 0 < dh_priv < dh_q */
  593|  10.2k|	gen_random_mpint(&dh_q, &param->priv);
  594|       |
  595|       |	/* f = g^y mod p */
  596|  10.2k|	if (mp_exptmod(&dh_g, &param->priv, &dh_p, &param->pub) != MP_OKAY) {
  ------------------
  |  |  161|  10.2k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (596:6): [True: 0, False: 10.2k]
  ------------------
  597|      0|		dropbear_exit("Diffie-Hellman error");
  598|      0|	}
  599|  10.2k|	mp_clear_multi(&dh_g, &dh_p, &dh_q, NULL);
  600|  10.2k|	return param;
  601|  10.2k|}
free_kexdh_param:
  604|  10.1k|{
  605|  10.1k|	mp_clear_multi(&param->pub, &param->priv, NULL);
  606|  10.1k|	m_free(param);
  ------------------
  |  |   24|  10.1k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  607|  10.1k|}
kexdh_comb_key:
  614|  10.2k|		sign_key *hostkey) {
  615|       |
  616|  10.2k|	DEF_MP_INT(dh_p);
  ------------------
  |  |   80|  10.2k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  617|  10.2k|	DEF_MP_INT(dh_p_min1);
  ------------------
  |  |   80|  10.2k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  618|  10.2k|	mp_int *dh_e = NULL, *dh_f = NULL;
  619|       |
  620|  10.2k|	m_mp_init_multi(&dh_p, &dh_p_min1, NULL);
  621|  10.2k|	load_dh_p(&dh_p);
  622|       |
  623|  10.2k|	if (mp_sub_d(&dh_p, 1, &dh_p_min1) != MP_OKAY) { 
  ------------------
  |  |  161|  10.2k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (623:6): [True: 0, False: 10.2k]
  ------------------
  624|      0|		dropbear_exit("Diffie-Hellman error");
  625|      0|	}
  626|       |
  627|       |	/* Check that dh_pub_them (dh_e or dh_f) is in the range [2, p-2] */
  628|  10.2k|	if (mp_cmp(dh_pub_them, &dh_p_min1) != MP_LT 
  ------------------
  |  |  154|  20.4k|#define MP_LT        -1   /* less than */
  ------------------
  |  Branch (628:6): [True: 2, False: 10.2k]
  ------------------
  629|  10.2k|			|| mp_cmp_d(dh_pub_them, 1) != MP_GT) {
  ------------------
  |  |  156|  10.2k|#define MP_GT         1   /* greater than */
  ------------------
  |  Branch (629:7): [True: 46, False: 10.1k]
  ------------------
  630|     48|		dropbear_exit("Diffie-Hellman error");
  631|     48|	}
  632|       |	
  633|       |	/* K = e^y mod p = f^x mod p */
  634|  10.1k|	m_mp_alloc_init_multi(&ses.dh_K, NULL);
  635|  10.1k|	if (mp_exptmod(dh_pub_them, &param->priv, &dh_p, ses.dh_K) != MP_OKAY) {
  ------------------
  |  |  161|  10.1k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (635:6): [True: 0, False: 10.1k]
  ------------------
  636|      0|		dropbear_exit("Diffie-Hellman error");
  637|      0|	}
  638|       |
  639|       |	/* clear no longer needed vars */
  640|  10.1k|	mp_clear_multi(&dh_p, &dh_p_min1, NULL);
  641|       |
  642|       |	/* From here on, the code needs to work with the _same_ vars on each side,
  643|       |	 * not vice-versaing for client/server */
  644|  10.1k|	if (IS_DROPBEAR_CLIENT) {
  ------------------
  |  |  320|  10.1k|#define IS_DROPBEAR_CLIENT (ses.isserver == 0)
  |  |  ------------------
  |  |  |  Branch (320:28): [True: 0, False: 10.1k]
  |  |  ------------------
  ------------------
  645|      0|		dh_e = &param->pub;
  646|      0|		dh_f = dh_pub_them;
  647|  10.1k|	} else {
  648|  10.1k|		dh_e = dh_pub_them;
  649|  10.1k|		dh_f = &param->pub;
  650|  10.1k|	} 
  651|       |
  652|       |	/* Create the remainder of the hash buffer, to generate the exchange hash */
  653|       |	/* K_S, the host key */
  654|  10.1k|	buf_put_pub_key(ses.kexhashbuf, hostkey, ses.newkeys->algo_hostkey);
  655|       |	/* e, exchange value sent by the client */
  656|  10.1k|	buf_putmpint(ses.kexhashbuf, dh_e);
  657|       |	/* f, exchange value sent by the server */
  658|  10.1k|	buf_putmpint(ses.kexhashbuf, dh_f);
  659|       |	/* K, the shared secret */
  660|  10.1k|	buf_putmpint(ses.kexhashbuf, ses.dh_K);
  661|       |
  662|       |	/* calculate the hash H to sign */
  663|  10.1k|	finish_kexhashbuf();
  664|  10.1k|}
gen_kexecdh_param:
  668|    313|struct kex_ecdh_param *gen_kexecdh_param() {
  669|    313|	struct kex_ecdh_param *param = m_malloc(sizeof(*param));
  670|    313|	if (ecc_make_key_ex(NULL, dropbear_ltc_prng, 
  ------------------
  |  Branch (670:6): [True: 0, False: 313]
  ------------------
  671|    313|		&param->key, ses.newkeys->algo_kex->ecc_curve->dp) != CRYPT_OK) {
  672|      0|		dropbear_exit("ECC error");
  673|      0|	}
  674|    313|	return param;
  675|    313|}
kexecdh_comb_key:
  683|    313|		sign_key *hostkey) {
  684|    313|	const struct dropbear_kex *algo_kex = ses.newkeys->algo_kex;
  685|       |	/* public keys from client and server */
  686|    313|	ecc_key *Q_C, *Q_S, *Q_them;
  687|       |
  688|    313|	Q_them = buf_get_ecc_raw_pubkey(pub_them, algo_kex->ecc_curve);
  689|    313|	if (Q_them == NULL) {
  ------------------
  |  Branch (689:6): [True: 312, False: 1]
  ------------------
  690|    312|		dropbear_exit("ECC error");
  691|    312|	}
  692|       |
  693|      1|	ses.dh_K = dropbear_ecc_shared_secret(Q_them, &param->key);
  694|       |
  695|       |	/* Create the remainder of the hash buffer, to generate the exchange hash
  696|       |	   See RFC5656 section 4 page 7 */
  697|      1|	if (IS_DROPBEAR_CLIENT) {
  ------------------
  |  |  320|      1|#define IS_DROPBEAR_CLIENT (ses.isserver == 0)
  |  |  ------------------
  |  |  |  Branch (320:28): [True: 0, False: 1]
  |  |  ------------------
  ------------------
  698|      0|		Q_C = &param->key;
  699|      0|		Q_S = Q_them;
  700|      1|	} else {
  701|      1|		Q_C = Q_them;
  702|      1|		Q_S = &param->key;
  703|      1|	} 
  704|       |
  705|       |	/* K_S, the host key */
  706|      1|	buf_put_pub_key(ses.kexhashbuf, hostkey, ses.newkeys->algo_hostkey);
  707|       |	/* Q_C, client's ephemeral public key octet string */
  708|      1|	buf_put_ecc_raw_pubkey_string(ses.kexhashbuf, Q_C);
  709|       |	/* Q_S, server's ephemeral public key octet string */
  710|      1|	buf_put_ecc_raw_pubkey_string(ses.kexhashbuf, Q_S);
  711|       |	/* K, the shared secret */
  712|      1|	buf_putmpint(ses.kexhashbuf, ses.dh_K);
  713|       |
  714|      1|	ecc_free(Q_them);
  715|      1|	m_free(Q_them);
  ------------------
  |  |   24|      1|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  716|       |
  717|       |	/* calculate the hash H to sign */
  718|      1|	finish_kexhashbuf();
  719|      1|}
gen_kexcurve25519_param:
  723|  7.15k|struct kex_curve25519_param *gen_kexcurve25519_param() {
  724|       |	/* Per http://cr.yp.to/ecdh.html */
  725|  7.15k|	struct kex_curve25519_param *param = m_malloc(sizeof(*param));
  726|  7.15k|	const unsigned char basepoint[32] = {9};
  727|       |
  728|  7.15k|	genrandom(param->priv, CURVE25519_LEN);
  ------------------
  |  |  106|  7.15k|#define CURVE25519_LEN 32
  ------------------
  729|  7.15k|	dropbear_curve25519_scalarmult(param->pub, param->priv, basepoint);
  730|       |
  731|  7.15k|	return param;
  732|  7.15k|}
free_kexcurve25519_param:
  734|  7.12k|void free_kexcurve25519_param(struct kex_curve25519_param *param) {
  735|  7.12k|	m_burn(param->priv, CURVE25519_LEN);
  ------------------
  |  |  106|  7.12k|#define CURVE25519_LEN 32
  ------------------
  736|  7.12k|	m_free(param);
  ------------------
  |  |   24|  7.12k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  737|  7.12k|}
kexcurve25519_comb_key:
  740|  7.15k|	sign_key *hostkey) {
  741|  7.15k|	unsigned char out[CURVE25519_LEN];
  742|  7.15k|	const unsigned char* Q_C = NULL;
  743|  7.15k|	const unsigned char* Q_S = NULL;
  744|  7.15k|	char zeroes[CURVE25519_LEN] = {0};
  745|       |
  746|  7.15k|	if (buf_pub_them->len != CURVE25519_LEN)
  ------------------
  |  |  106|  7.15k|#define CURVE25519_LEN 32
  ------------------
  |  Branch (746:6): [True: 33, False: 7.12k]
  ------------------
  747|     33|	{
  748|     33|		dropbear_exit("Bad curve25519");
  749|     33|	}
  750|       |
  751|  7.12k|	dropbear_curve25519_scalarmult(out, param->priv, buf_pub_them->data);
  752|       |
  753|  7.12k|	if (constant_time_memcmp(zeroes, out, CURVE25519_LEN) == 0) {
  ------------------
  |  |  106|  7.12k|#define CURVE25519_LEN 32
  ------------------
  |  Branch (753:6): [True: 1, False: 7.12k]
  ------------------
  754|      1|		dropbear_exit("Bad curve25519");
  755|      1|	}
  756|       |
  757|  7.12k|	m_mp_alloc_init_multi(&ses.dh_K, NULL);
  758|  7.12k|	bytes_to_mp(ses.dh_K, out, CURVE25519_LEN);
  ------------------
  |  |  106|  7.12k|#define CURVE25519_LEN 32
  ------------------
  759|  7.12k|	m_burn(out, sizeof(out));
  760|       |
  761|       |	/* Create the remainder of the hash buffer, to generate the exchange hash.
  762|       |	   See RFC5656 section 4 page 7 */
  763|  7.12k|	if (IS_DROPBEAR_CLIENT) {
  ------------------
  |  |  320|  7.12k|#define IS_DROPBEAR_CLIENT (ses.isserver == 0)
  |  |  ------------------
  |  |  |  Branch (320:28): [True: 0, False: 7.12k]
  |  |  ------------------
  ------------------
  764|      0|		Q_C = param->pub;
  765|      0|		Q_S = buf_pub_them->data;
  766|  7.12k|	} else {
  767|  7.12k|		Q_S = param->pub;
  768|  7.12k|		Q_C = buf_pub_them->data;
  769|  7.12k|	}
  770|       |
  771|       |	/* K_S, the host key */
  772|  7.12k|	buf_put_pub_key(ses.kexhashbuf, hostkey, ses.newkeys->algo_hostkey);
  773|       |	/* Q_C, client's ephemeral public key octet string */
  774|  7.12k|	buf_putstring(ses.kexhashbuf, (const char*)Q_C, CURVE25519_LEN);
  ------------------
  |  |  106|  7.12k|#define CURVE25519_LEN 32
  ------------------
  775|       |	/* Q_S, server's ephemeral public key octet string */
  776|  7.12k|	buf_putstring(ses.kexhashbuf, (const char*)Q_S, CURVE25519_LEN);
  ------------------
  |  |  106|  7.12k|#define CURVE25519_LEN 32
  ------------------
  777|       |	/* K, the shared secret */
  778|  7.12k|	buf_putmpint(ses.kexhashbuf, ses.dh_K);
  779|       |
  780|       |	/* calculate the hash H to sign */
  781|  7.12k|	finish_kexhashbuf();
  782|  7.12k|}
finish_kexhashbuf:
  786|  17.3k|void finish_kexhashbuf(void) {
  787|  17.3k|	hash_state hs;
  788|  17.3k|	const struct ltc_hash_descriptor *hash_desc = ses.newkeys->algo_kex->hash_desc;
  789|       |
  790|  17.3k|	hash_desc->init(&hs);
  791|  17.3k|	buf_setpos(ses.kexhashbuf, 0);
  792|  17.3k|	hash_desc->process(&hs, buf_getptr(ses.kexhashbuf, ses.kexhashbuf->len),
  793|  17.3k|			ses.kexhashbuf->len);
  794|  17.3k|	ses.hash = buf_new(hash_desc->hashsize);
  795|  17.3k|	hash_desc->done(&hs, buf_getwriteptr(ses.hash, hash_desc->hashsize));
  796|  17.3k|	buf_setlen(ses.hash, hash_desc->hashsize);
  797|       |
  798|       |#if defined(DEBUG_KEXHASH) && DEBUG_TRACE
  799|       |	if (!debug_trace) {
  800|       |		printhex("kexhashbuf", ses.kexhashbuf->data, ses.kexhashbuf->len);
  801|       |		printhex("kexhash", ses.hash->data, ses.hash->len);
  802|       |	}
  803|       |#endif
  804|       |
  805|  17.3k|	buf_burn_free(ses.kexhashbuf);
  806|  17.3k|	m_burn(&hs, sizeof(hash_state));
  807|  17.3k|	ses.kexhashbuf = NULL;
  808|       |	
  809|       |	/* first time around, we set the session_id to H */
  810|  17.3k|	if (ses.session_id == NULL) {
  ------------------
  |  Branch (810:6): [True: 2.39k, False: 14.9k]
  ------------------
  811|       |		/* create the session_id, this never needs freeing */
  812|  2.39k|		ses.session_id = buf_newcopy(ses.hash);
  813|  2.39k|	}
  814|  17.3k|}
common-kex.c:switch_keys:
  124|  33.5k|static void switch_keys() {
  125|  33.5k|	TRACE2(("enter switch_keys"))
  126|  33.5k|	if (!(ses.kexstate.sentkexinit && ses.kexstate.recvkexinit)) {
  ------------------
  |  Branch (126:8): [True: 33.5k, False: 7]
  |  Branch (126:36): [True: 33.5k, False: 0]
  ------------------
  127|      7|		dropbear_exit("Unexpected newkeys message");
  128|      7|	}
  129|       |
  130|  33.5k|	if (!ses.keys) {
  ------------------
  |  Branch (130:6): [True: 0, False: 33.5k]
  ------------------
  131|      0|		ses.keys = m_malloc(sizeof(*ses.newkeys));
  132|      0|	}
  133|  33.5k|	if (ses.kexstate.recvnewkeys && ses.newkeys->recv.valid) {
  ------------------
  |  Branch (133:6): [True: 16.2k, False: 17.2k]
  |  Branch (133:34): [True: 16.2k, False: 0]
  ------------------
  134|  16.2k|		TRACE(("switch_keys recv"))
  135|       |#ifndef DISABLE_ZLIB
  136|       |		gen_new_zstream_recv();
  137|       |#endif
  138|  16.2k|		ses.keys->recv = ses.newkeys->recv;
  139|  16.2k|		m_burn(&ses.newkeys->recv, sizeof(ses.newkeys->recv));
  140|  16.2k|		ses.newkeys->recv.valid = 0;
  141|  16.2k|	}
  142|  33.5k|	if (ses.kexstate.sentnewkeys && ses.newkeys->trans.valid) {
  ------------------
  |  Branch (142:6): [True: 33.5k, False: 0]
  |  Branch (142:34): [True: 17.2k, False: 16.2k]
  ------------------
  143|  17.2k|		TRACE(("switch_keys trans"))
  144|       |#ifndef DISABLE_ZLIB
  145|       |		gen_new_zstream_trans();
  146|       |#endif
  147|  17.2k|		ses.keys->trans = ses.newkeys->trans;
  148|  17.2k|		m_burn(&ses.newkeys->trans, sizeof(ses.newkeys->trans));
  149|  17.2k|		ses.newkeys->trans.valid = 0;
  150|  17.2k|	}
  151|  33.5k|	if (ses.kexstate.sentnewkeys && ses.kexstate.recvnewkeys)
  ------------------
  |  Branch (151:6): [True: 33.5k, False: 0]
  |  Branch (151:34): [True: 16.2k, False: 17.2k]
  ------------------
  152|  16.2k|	{
  153|  16.2k|		TRACE(("switch_keys done"))
  154|  16.2k|		ses.keys->algo_kex = ses.newkeys->algo_kex;
  155|  16.2k|		ses.keys->algo_hostkey = ses.newkeys->algo_hostkey;
  156|  16.2k|		ses.keys->algo_signature = ses.newkeys->algo_signature;
  157|  16.2k|		ses.keys->allow_compress = 0;
  158|  16.2k|		m_free(ses.newkeys);
  ------------------
  |  |   24|  16.2k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  159|  16.2k|		ses.newkeys = NULL;
  160|  16.2k|		kexinitialise();
  161|  16.2k|	}
  162|  33.5k|	TRACE2(("leave switch_keys"))
  163|  33.5k|}
common-kex.c:kexinitialise:
  225|  20.2k|static void kexinitialise() {
  226|       |
  227|  20.2k|	TRACE(("kexinitialise()"))
  228|       |
  229|       |	/* sent/recv'd MSG_KEXINIT */
  230|  20.2k|	ses.kexstate.sentkexinit = 0;
  231|  20.2k|	ses.kexstate.recvkexinit = 0;
  232|       |
  233|       |	/* sent/recv'd MSG_NEWKEYS */
  234|  20.2k|	ses.kexstate.recvnewkeys = 0;
  235|  20.2k|	ses.kexstate.sentnewkeys = 0;
  236|       |
  237|       |	/* first_packet_follows */
  238|  20.2k|	ses.kexstate.them_firstfollows = 0;
  239|       |
  240|  20.2k|	ses.kexstate.datatrans = 0;
  241|  20.2k|	ses.kexstate.datarecv = 0;
  242|       |
  243|  20.2k|	ses.kexstate.our_first_follows_matches = 0;
  244|       |
  245|  20.2k|	ses.kexstate.lastkextime = monotonic_now();
  246|       |
  247|  20.2k|}
common-kex.c:gen_new_keys:
  288|  17.2k|static void gen_new_keys() {
  289|       |
  290|  17.2k|	unsigned char C2S_IV[MAX_IV_LEN];
  291|  17.2k|	unsigned char C2S_key[MAX_KEY_LEN];
  292|  17.2k|	unsigned char S2C_IV[MAX_IV_LEN];
  293|  17.2k|	unsigned char S2C_key[MAX_KEY_LEN];
  294|       |	/* unsigned char key[MAX_KEY_LEN]; */
  295|  17.2k|	unsigned char *trans_IV, *trans_key, *recv_IV, *recv_key;
  296|       |
  297|  17.2k|	hash_state hs;
  298|  17.2k|	const struct ltc_hash_descriptor *hash_desc = ses.newkeys->algo_kex->hash_desc;
  299|  17.2k|	char mactransletter, macrecvletter; /* Client or server specific */
  300|       |
  301|  17.2k|	TRACE(("enter gen_new_keys"))
  302|       |	/* the dh_K and hash are the start of all hashes, we make use of that */
  303|       |
  304|  17.2k|	hash_desc->init(&hs);
  305|  17.2k|	hash_process_mp(hash_desc, &hs, ses.dh_K);
  306|  17.2k|	mp_clear(ses.dh_K);
  307|  17.2k|	m_free(ses.dh_K);
  ------------------
  |  |   24|  17.2k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  308|  17.2k|	hash_desc->process(&hs, ses.hash->data, ses.hash->len);
  309|  17.2k|	buf_burn_free(ses.hash);
  310|  17.2k|	ses.hash = NULL;
  311|       |
  312|  17.2k|	if (IS_DROPBEAR_CLIENT) {
  ------------------
  |  |  320|  17.2k|#define IS_DROPBEAR_CLIENT (ses.isserver == 0)
  |  |  ------------------
  |  |  |  Branch (320:28): [True: 0, False: 17.2k]
  |  |  ------------------
  ------------------
  313|      0|		trans_IV	= C2S_IV;
  314|      0|		recv_IV		= S2C_IV;
  315|      0|		trans_key	= C2S_key;
  316|      0|		recv_key	= S2C_key;
  317|      0|		mactransletter = 'E';
  318|      0|		macrecvletter = 'F';
  319|  17.2k|	} else {
  320|  17.2k|		trans_IV	= S2C_IV;
  321|  17.2k|		recv_IV		= C2S_IV;
  322|  17.2k|		trans_key	= S2C_key;
  323|  17.2k|		recv_key	= C2S_key;
  324|  17.2k|		mactransletter = 'F';
  325|  17.2k|		macrecvletter = 'E';
  326|  17.2k|	}
  327|       |
  328|  17.2k|	hashkeys(C2S_IV, sizeof(C2S_IV), &hs, 'A');
  329|  17.2k|	hashkeys(S2C_IV, sizeof(S2C_IV), &hs, 'B');
  330|  17.2k|	hashkeys(C2S_key, sizeof(C2S_key), &hs, 'C');
  331|  17.2k|	hashkeys(S2C_key, sizeof(S2C_key), &hs, 'D');
  332|       |
  333|  17.2k|	if (ses.newkeys->recv.algo_crypt->cipherdesc != NULL) {
  ------------------
  |  Branch (333:6): [True: 17.2k, False: 0]
  ------------------
  334|  17.2k|		int recv_cipher = -1;
  335|  17.2k|		if (ses.newkeys->recv.algo_crypt->cipherdesc->name != NULL) {
  ------------------
  |  Branch (335:7): [True: 13.6k, False: 3.69k]
  ------------------
  336|  13.6k|			recv_cipher = find_cipher(ses.newkeys->recv.algo_crypt->cipherdesc->name);
  337|  13.6k|			if (recv_cipher < 0) {
  ------------------
  |  Branch (337:8): [True: 0, False: 13.6k]
  ------------------
  338|      0|				dropbear_exit("Crypto error");
  339|      0|			}
  340|  13.6k|		}
  341|  17.2k|		if (ses.newkeys->recv.crypt_mode->start(recv_cipher, 
  ------------------
  |  Branch (341:7): [True: 0, False: 17.2k]
  ------------------
  342|  17.2k|				recv_IV, recv_key, 
  343|  17.2k|				ses.newkeys->recv.algo_crypt->keysize, 0, 
  344|  17.2k|				&ses.newkeys->recv.cipher_state) != CRYPT_OK) {
  345|      0|			dropbear_exit("Crypto error");
  346|      0|		}
  347|  17.2k|	}
  348|       |
  349|  17.2k|	if (ses.newkeys->trans.algo_crypt->cipherdesc != NULL) {
  ------------------
  |  Branch (349:6): [True: 17.2k, False: 0]
  ------------------
  350|  17.2k|		int trans_cipher = -1;
  351|  17.2k|		if (ses.newkeys->trans.algo_crypt->cipherdesc->name != NULL) {
  ------------------
  |  Branch (351:7): [True: 13.6k, False: 3.66k]
  ------------------
  352|  13.6k|			trans_cipher = find_cipher(ses.newkeys->trans.algo_crypt->cipherdesc->name);
  353|  13.6k|			if (trans_cipher < 0) {
  ------------------
  |  Branch (353:8): [True: 0, False: 13.6k]
  ------------------
  354|      0|				dropbear_exit("Crypto error");
  355|      0|			}
  356|  13.6k|		}
  357|  17.2k|		if (ses.newkeys->trans.crypt_mode->start(trans_cipher, 
  ------------------
  |  Branch (357:7): [True: 0, False: 17.2k]
  ------------------
  358|  17.2k|				trans_IV, trans_key, 
  359|  17.2k|				ses.newkeys->trans.algo_crypt->keysize, 0, 
  360|  17.2k|				&ses.newkeys->trans.cipher_state) != CRYPT_OK) {
  361|      0|			dropbear_exit("Crypto error");
  362|      0|		}
  363|  17.2k|	}
  364|       |
  365|  17.2k|	if (ses.newkeys->trans.algo_mac->hash_desc != NULL) {
  ------------------
  |  Branch (365:6): [True: 13.6k, False: 3.66k]
  ------------------
  366|  13.6k|		hashkeys(ses.newkeys->trans.mackey, 
  367|  13.6k|				ses.newkeys->trans.algo_mac->keysize, &hs, mactransletter);
  368|  13.6k|		ses.newkeys->trans.hash_index = find_hash(ses.newkeys->trans.algo_mac->hash_desc->name);
  369|  13.6k|	}
  370|       |
  371|  17.2k|	if (ses.newkeys->recv.algo_mac->hash_desc != NULL) {
  ------------------
  |  Branch (371:6): [True: 0, False: 17.2k]
  ------------------
  372|      0|		hashkeys(ses.newkeys->recv.mackey, 
  373|      0|				ses.newkeys->recv.algo_mac->keysize, &hs, macrecvletter);
  374|      0|		ses.newkeys->recv.hash_index = find_hash(ses.newkeys->recv.algo_mac->hash_desc->name);
  375|      0|	}
  376|       |
  377|       |	/* Ready to switch over */
  378|  17.2k|	ses.newkeys->trans.valid = 1;
  379|  17.2k|	ses.newkeys->recv.valid = 1;
  380|       |
  381|  17.2k|	m_burn(C2S_IV, sizeof(C2S_IV));
  382|  17.2k|	m_burn(C2S_key, sizeof(C2S_key));
  383|  17.2k|	m_burn(S2C_IV, sizeof(S2C_IV));
  384|  17.2k|	m_burn(S2C_key, sizeof(S2C_key));
  385|  17.2k|	m_burn(&hs, sizeof(hash_state));
  386|       |
  387|  17.2k|	TRACE(("leave gen_new_keys"))
  388|  17.2k|}
common-kex.c:hashkeys:
  256|  82.8k|		const hash_state * hs, const unsigned char X) {
  257|       |
  258|  82.8k|	const struct ltc_hash_descriptor *hash_desc = ses.newkeys->algo_kex->hash_desc;
  259|  82.8k|	hash_state hs2;
  260|  82.8k|	unsigned int offset;
  261|  82.8k|	unsigned char tmpout[MAX_HASH_SIZE];
  262|       |
  263|  82.8k|	memcpy(&hs2, hs, sizeof(hash_state));
  264|  82.8k|	hash_desc->process(&hs2, &X, 1);
  265|  82.8k|	hash_desc->process(&hs2, ses.session_id->data, ses.session_id->len);
  266|  82.8k|	hash_desc->done(&hs2, tmpout);
  267|  82.8k|	memcpy(out, tmpout, MIN(hash_desc->hashsize, outlen));
  268|  82.8k|	for (offset = hash_desc->hashsize; 
  269|   162k|			offset < outlen; 
  ------------------
  |  Branch (269:4): [True: 79.8k, False: 82.8k]
  ------------------
  270|  82.8k|			offset += hash_desc->hashsize)
  271|  79.8k|	{
  272|       |		/* need to extend */
  273|  79.8k|		memcpy(&hs2, hs, sizeof(hash_state));
  274|  79.8k|		hash_desc->process(&hs2, out, offset);
  275|  79.8k|		hash_desc->done(&hs2, tmpout);
  276|  79.8k|		memcpy(&out[offset], tmpout, MIN(outlen - offset, hash_desc->hashsize));
  277|  79.8k|	}
  278|  82.8k|	m_burn(&hs2, sizeof(hash_state));
  279|  82.8k|}
common-kex.c:load_dh_p:
  558|  20.4k|{
  559|  20.4k|	bytes_to_mp(dh_p, ses.newkeys->algo_kex->dh_p_bytes, 
  560|  20.4k|		ses.newkeys->algo_kex->dh_p_len);
  561|  20.4k|}
common-kex.c:read_kex_algos:
  818|  18.6k|static void read_kex_algos() {
  819|       |
  820|       |	/* for asymmetry */
  821|  18.6k|	algo_type * c2s_hash_algo = NULL;
  822|  18.6k|	algo_type * s2c_hash_algo = NULL;
  823|  18.6k|	algo_type * c2s_cipher_algo = NULL;
  824|  18.6k|	algo_type * s2c_cipher_algo = NULL;
  825|  18.6k|	algo_type * c2s_comp_algo = NULL;
  826|  18.6k|	algo_type * s2c_comp_algo = NULL;
  827|       |	/* the generic one */
  828|  18.6k|	algo_type * algo = NULL;
  829|       |
  830|       |	/* which algo couldn't match */
  831|  18.6k|	char * erralgo = NULL;
  832|       |
  833|  18.6k|	int goodguess = 0;
  834|  18.6k|	int allgood = 1; /* we AND this with each goodguess and see if its still
  835|       |						true after */
  836|  18.6k|	int kexguess2 = 0;
  837|       |
  838|  18.6k|	buf_incrpos(ses.payload, 16); /* start after the cookie */
  839|       |
  840|  18.6k|	memset(ses.newkeys, 0x0, sizeof(*ses.newkeys));
  841|       |
  842|       |	/* kex_algorithms */
  843|  18.6k|#if DROPBEAR_KEXGUESS2
  844|  18.6k|	if (buf_has_algo(ses.payload, KEXGUESS2_ALGO_NAME) == DROPBEAR_SUCCESS) {
  ------------------
  |  |  128|  18.6k|#define KEXGUESS2_ALGO_NAME "kexguess2@matt.ucc.asn.au"
  ------------------
              	if (buf_has_algo(ses.payload, KEXGUESS2_ALGO_NAME) == DROPBEAR_SUCCESS) {
  ------------------
  |  |  102|  18.6k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (844:6): [True: 1.63k, False: 17.0k]
  ------------------
  845|  1.63k|		kexguess2 = 1;
  846|  1.63k|	}
  847|  18.6k|#endif
  848|       |
  849|  18.6k|#if DROPBEAR_EXT_INFO
  850|       |	/* Determine if SSH_MSG_EXT_INFO messages should be sent.
  851|       |	Should be done for the first key exchange. Only required on server side
  852|       |    for server-sig-algs */
  853|  18.6k|	if (IS_DROPBEAR_SERVER) {
  ------------------
  |  |  319|  18.6k|#define IS_DROPBEAR_SERVER (ses.isserver == 1)
  |  |  ------------------
  |  |  |  Branch (319:28): [True: 18.5k, False: 118]
  |  |  ------------------
  ------------------
  854|  18.5k|		if (!ses.kexstate.donefirstkex) {
  ------------------
  |  Branch (854:7): [True: 3.31k, False: 15.2k]
  ------------------
  855|  3.31k|			if (buf_has_algo(ses.payload, SSH_EXT_INFO_C) == DROPBEAR_SUCCESS) {
  ------------------
  |  |  100|  3.31k|#define SSH_EXT_INFO_C "ext-info-c"
  ------------------
              			if (buf_has_algo(ses.payload, SSH_EXT_INFO_C) == DROPBEAR_SUCCESS) {
  ------------------
  |  |  102|  3.31k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (855:8): [True: 50, False: 3.26k]
  ------------------
  856|     50|				ses.allow_ext_info = 1;
  857|     50|			}
  858|  3.31k|		}
  859|  18.5k|	}
  860|  18.6k|#endif
  861|       |
  862|  18.6k|	algo = buf_match_algo(ses.payload, sshkex, kexguess2, &goodguess);
  863|  18.6k|	allgood &= goodguess;
  864|  18.6k|	if (algo == NULL || algo->data == NULL) {
  ------------------
  |  Branch (864:6): [True: 371, False: 18.2k]
  |  Branch (864:22): [True: 13, False: 18.2k]
  ------------------
  865|       |		/* kexguess2, ext-info-c, ext-info-s should not match negotiation */
  866|    266|		erralgo = "kex";
  867|    266|		goto error;
  868|    266|	}
  869|  18.3k|	TRACE(("kexguess2 %d", kexguess2))
  870|  18.3k|	DEBUG3(("kex algo %s", algo->name))
  871|  18.3k|	ses.newkeys->algo_kex = algo->data;
  872|       |
  873|       |	/* server_host_key_algorithms */
  874|  18.3k|	algo = buf_match_algo(ses.payload, sigalgs, kexguess2, &goodguess);
  875|  18.3k|	allgood &= goodguess;
  876|  18.3k|	if (algo == NULL) {
  ------------------
  |  Branch (876:6): [True: 5, False: 18.3k]
  ------------------
  877|      5|		erralgo = "hostkey";
  878|      5|		goto error;
  879|      5|	}
  880|  18.3k|	DEBUG2(("hostkey algo %s", algo->name))
  881|  18.3k|	ses.newkeys->algo_signature = algo->val;
  882|  18.3k|	ses.newkeys->algo_hostkey = signkey_type_from_signature(ses.newkeys->algo_signature);
  883|       |
  884|       |	/* encryption_algorithms_client_to_server */
  885|  18.3k|	c2s_cipher_algo = buf_match_algo(ses.payload, sshciphers, 0, NULL);
  886|  18.3k|	if (c2s_cipher_algo == NULL) {
  ------------------
  |  Branch (886:6): [True: 16, False: 18.3k]
  ------------------
  887|     16|		erralgo = "enc c->s";
  888|     16|		goto error;
  889|     16|	}
  890|  18.3k|	DEBUG2(("enc  c2s is %s", c2s_cipher_algo->name))
  891|       |
  892|       |	/* encryption_algorithms_server_to_client */
  893|  18.3k|	s2c_cipher_algo = buf_match_algo(ses.payload, sshciphers, 0, NULL);
  894|  18.3k|	if (s2c_cipher_algo == NULL) {
  ------------------
  |  Branch (894:6): [True: 15, False: 18.3k]
  ------------------
  895|     15|		erralgo = "enc s->c";
  896|     15|		goto error;
  897|     15|	}
  898|  18.3k|	DEBUG2(("enc  s2c is %s", s2c_cipher_algo->name))
  899|       |
  900|       |	/* mac_algorithms_client_to_server */
  901|  18.3k|	c2s_hash_algo = buf_match_algo(ses.payload, sshhashes, 0, NULL);
  902|  18.3k|#if DROPBEAR_AEAD_MODE
  903|  18.3k|	if (((struct dropbear_cipher_mode*)c2s_cipher_algo->mode)->aead_crypt != NULL) {
  ------------------
  |  Branch (903:6): [True: 3.76k, False: 14.5k]
  ------------------
  904|  3.76k|		c2s_hash_algo = NULL;
  905|  3.76k|	} else
  906|  14.5k|#endif
  907|  14.5k|	if (c2s_hash_algo == NULL) {
  ------------------
  |  Branch (907:6): [True: 11, False: 14.5k]
  ------------------
  908|     11|		erralgo = "mac c->s";
  909|     11|		goto error;
  910|     11|	}
  911|  18.3k|	DEBUG2(("hmac c2s is %s", c2s_hash_algo ? c2s_hash_algo->name : "<implicit>"))
  912|       |
  913|       |	/* mac_algorithms_server_to_client */
  914|  18.3k|	s2c_hash_algo = buf_match_algo(ses.payload, sshhashes, 0, NULL);
  915|  18.3k|#if DROPBEAR_AEAD_MODE
  916|  18.3k|	if (((struct dropbear_cipher_mode*)s2c_cipher_algo->mode)->aead_crypt != NULL) {
  ------------------
  |  Branch (916:6): [True: 3.71k, False: 14.6k]
  ------------------
  917|  3.71k|		s2c_hash_algo = NULL;
  918|  3.71k|	} else
  919|  14.6k|#endif
  920|  14.6k|	if (s2c_hash_algo == NULL) {
  ------------------
  |  Branch (920:6): [True: 5, False: 14.6k]
  ------------------
  921|      5|		erralgo = "mac s->c";
  922|      5|		goto error;
  923|      5|	}
  924|  18.3k|	DEBUG2(("hmac s2c is %s", s2c_hash_algo ? s2c_hash_algo->name : "<implicit>"))
  925|       |
  926|       |	/* compression_algorithms_client_to_server */
  927|  18.3k|	c2s_comp_algo = buf_match_algo(ses.payload, ses.compress_algos, 0, NULL);
  928|  18.3k|	if (c2s_comp_algo == NULL) {
  ------------------
  |  Branch (928:6): [True: 5, False: 18.3k]
  ------------------
  929|      5|		erralgo = "comp c->s";
  930|      5|		goto error;
  931|      5|	}
  932|  18.3k|	DEBUG2(("comp c2s is %s", c2s_comp_algo->name))
  933|       |
  934|       |	/* compression_algorithms_server_to_client */
  935|  18.3k|	s2c_comp_algo = buf_match_algo(ses.payload, ses.compress_algos, 0, NULL);
  936|  18.3k|	if (s2c_comp_algo == NULL) {
  ------------------
  |  Branch (936:6): [True: 4, False: 18.3k]
  ------------------
  937|      4|		erralgo = "comp s->c";
  938|      4|		goto error;
  939|      4|	}
  940|  18.3k|	DEBUG2(("comp s2c is %s", s2c_comp_algo->name))
  941|       |
  942|       |	/* languages_client_to_server */
  943|  18.3k|	buf_eatstring(ses.payload);
  944|       |
  945|       |	/* languages_server_to_client */
  946|  18.3k|	buf_eatstring(ses.payload);
  947|       |
  948|       |	/* their first_kex_packet_follows */
  949|  18.3k|	if (buf_getbool(ses.payload)) {
  ------------------
  |  Branch (949:6): [True: 1.70k, False: 16.6k]
  ------------------
  950|  1.70k|		TRACE(("them kex firstfollows. allgood %d", allgood))
  951|  1.70k|		ses.kexstate.them_firstfollows = 1;
  952|       |		/* if the guess wasn't good, we ignore the packet sent */
  953|  1.70k|		if (!allgood) {
  ------------------
  |  Branch (953:7): [True: 188, False: 1.51k]
  ------------------
  954|    188|			ses.ignorenext = 1;
  955|    188|		}
  956|  1.70k|	}
  957|       |
  958|       |	/* Handle the asymmetry */
  959|  18.3k|	if (IS_DROPBEAR_CLIENT) {
  ------------------
  |  |  320|  18.3k|#define IS_DROPBEAR_CLIENT (ses.isserver == 0)
  |  |  ------------------
  |  |  |  Branch (320:28): [True: 0, False: 18.3k]
  |  |  ------------------
  ------------------
  960|      0|		ses.newkeys->recv.algo_crypt = 
  961|      0|			(struct dropbear_cipher*)s2c_cipher_algo->data;
  962|      0|		ses.newkeys->trans.algo_crypt = 
  963|      0|			(struct dropbear_cipher*)c2s_cipher_algo->data;
  964|      0|		ses.newkeys->recv.crypt_mode = 
  965|      0|			(struct dropbear_cipher_mode*)s2c_cipher_algo->mode;
  966|      0|		ses.newkeys->trans.crypt_mode =
  967|      0|			(struct dropbear_cipher_mode*)c2s_cipher_algo->mode;
  968|      0|		ses.newkeys->recv.algo_mac = 
  969|      0|#if DROPBEAR_AEAD_MODE
  970|      0|			s2c_hash_algo == NULL ? ses.newkeys->recv.crypt_mode->aead_mac :
  ------------------
  |  Branch (970:4): [True: 0, False: 0]
  ------------------
  971|      0|#endif
  972|      0|			(struct dropbear_hash*)s2c_hash_algo->data;
  973|      0|		ses.newkeys->trans.algo_mac = 
  974|      0|#if DROPBEAR_AEAD_MODE
  975|      0|			c2s_hash_algo == NULL ? ses.newkeys->trans.crypt_mode->aead_mac :
  ------------------
  |  Branch (975:4): [True: 0, False: 0]
  ------------------
  976|      0|#endif
  977|      0|			(struct dropbear_hash*)c2s_hash_algo->data;
  978|      0|		ses.newkeys->recv.algo_comp = s2c_comp_algo->val;
  979|      0|		ses.newkeys->trans.algo_comp = c2s_comp_algo->val;
  980|  18.3k|	} else {
  981|       |		/* SERVER */
  982|  18.3k|		ses.newkeys->recv.algo_crypt = 
  983|  18.3k|			(struct dropbear_cipher*)c2s_cipher_algo->data;
  984|  18.3k|		ses.newkeys->trans.algo_crypt = 
  985|  18.3k|			(struct dropbear_cipher*)s2c_cipher_algo->data;
  986|  18.3k|		ses.newkeys->recv.crypt_mode =
  987|  18.3k|			(struct dropbear_cipher_mode*)c2s_cipher_algo->mode;
  988|  18.3k|		ses.newkeys->trans.crypt_mode =
  989|  18.3k|			(struct dropbear_cipher_mode*)s2c_cipher_algo->mode;
  990|  18.3k|		ses.newkeys->recv.algo_mac = 
  991|  18.3k|#if DROPBEAR_AEAD_MODE
  992|  18.3k|			c2s_hash_algo == NULL ? ses.newkeys->recv.crypt_mode->aead_mac :
  ------------------
  |  Branch (992:4): [True: 3.73k, False: 14.5k]
  ------------------
  993|  18.3k|#endif
  994|  18.3k|			(struct dropbear_hash*)c2s_hash_algo->data;
  995|  18.3k|		ses.newkeys->trans.algo_mac = 
  996|  18.3k|#if DROPBEAR_AEAD_MODE
  997|  18.3k|			s2c_hash_algo == NULL ? ses.newkeys->trans.crypt_mode->aead_mac :
  ------------------
  |  Branch (997:4): [True: 3.69k, False: 14.6k]
  ------------------
  998|  18.3k|#endif
  999|  18.3k|			(struct dropbear_hash*)s2c_hash_algo->data;
 1000|  18.3k|		ses.newkeys->recv.algo_comp = c2s_comp_algo->val;
 1001|  18.3k|		ses.newkeys->trans.algo_comp = s2c_comp_algo->val;
 1002|  18.3k|	}
 1003|       |
 1004|  18.3k|#if DROPBEAR_FUZZ
 1005|  18.3k|	if (fuzz.fuzzing) {
  ------------------
  |  Branch (1005:6): [True: 18.0k, False: 293]
  ------------------
 1006|  18.0k|		fuzz_kex_fakealgos();
 1007|  18.0k|	}
 1008|  18.3k|#endif
 1009|       |
 1010|       |	/* reserved for future extensions */
 1011|  18.3k|	buf_getint(ses.payload);
 1012|       |
 1013|  18.3k|	if (ses.send_kex_first_guess && allgood) {
  ------------------
  |  Branch (1013:6): [True: 0, False: 18.3k]
  |  Branch (1013:34): [True: 0, False: 0]
  ------------------
 1014|      0|		TRACE(("our_first_follows_matches 1"))
 1015|      0|		ses.kexstate.our_first_follows_matches = 1;
 1016|      0|	}
 1017|  18.3k|	return;
 1018|       |
 1019|    327|error:
 1020|    327|	dropbear_exit("No matching algo %s", erralgo);
 1021|  18.3k|}

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

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

dropbear_curve25519_scalarmult:
  212|  14.2k|{
  213|  14.2k|  u8 z[32];
  214|  14.2k|  i64 x[80],r,i;
  215|  14.2k|  gf a,b,c,d,e,f;
  216|   442k|  FOR(i,31) z[i]=n[i];
  ------------------
  |  |   34|   457k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 442k, False: 14.2k]
  |  |  ------------------
  ------------------
  217|  14.2k|  z[31]=(n[31]&127)|64;
  218|  14.2k|  z[0]&=248;
  219|  14.2k|  unpack25519(x,p);
  220|   228k|  FOR(i,16) {
  ------------------
  |  |   34|   242k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 228k, False: 14.2k]
  |  |  ------------------
  ------------------
  221|   228k|    b[i]=x[i];
  222|   228k|    d[i]=a[i]=c[i]=0;
  223|   228k|  }
  224|  14.2k|  a[0]=d[0]=1;
  225|  3.65M|  for(i=254;i>=0;--i) {
  ------------------
  |  Branch (225:13): [True: 3.64M, False: 14.2k]
  ------------------
  226|  3.64M|    r=(z[i>>3]>>(i&7))&1;
  227|  3.64M|    sel25519(a,b,r);
  228|  3.64M|    sel25519(c,d,r);
  229|  3.64M|    A(e,a,c);
  230|  3.64M|    Z(a,a,c);
  231|  3.64M|    A(c,b,d);
  232|  3.64M|    Z(b,b,d);
  233|  3.64M|    S(d,e);
  234|  3.64M|    S(f,a);
  235|  3.64M|    M(a,c,a);
  236|  3.64M|    M(c,b,e);
  237|  3.64M|    A(e,a,c);
  238|  3.64M|    Z(a,a,c);
  239|  3.64M|    S(b,a);
  240|  3.64M|    Z(c,d,f);
  241|  3.64M|    M(a,c,_121665);
  242|  3.64M|    A(a,a,d);
  243|  3.64M|    M(c,c,a);
  244|  3.64M|    M(a,d,f);
  245|  3.64M|    M(d,b,x);
  246|  3.64M|    S(b,e);
  247|  3.64M|    sel25519(a,b,r);
  248|  3.64M|    sel25519(c,d,r);
  249|  3.64M|  }
  250|   228k|  FOR(i,16) {
  ------------------
  |  |   34|   242k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 228k, False: 14.2k]
  |  |  ------------------
  ------------------
  251|   228k|    x[i+16]=a[i];
  252|   228k|    x[i+32]=c[i];
  253|   228k|    x[i+48]=b[i];
  254|   228k|    x[i+64]=d[i];
  255|   228k|  }
  256|  14.2k|  inv25519(x+32,x+32);
  257|  14.2k|  M(x+16,x+16,x+32);
  258|  14.2k|  pack25519(q,x+16);
  259|  14.2k|}
dropbear_ed25519_sign:
  393|  1.01k|{
  394|  1.01k|  hash_state hs;
  395|  1.01k|  u8 d[64],h[64],r[64];
  396|  1.01k|  i64 x[64];
  397|  1.01k|  gf p[4];
  398|  1.01k|  u32 i,j;
  399|       |
  400|  1.01k|  crypto_hash(d, sk, 32);
  401|  1.01k|  d[0] &= 248;
  402|  1.01k|  d[31] &= 127;
  403|  1.01k|  d[31] |= 64;
  404|       |
  405|  1.01k|  *slen = 64;
  406|       |
  407|  1.01k|  sha512_init(&hs);
  408|  1.01k|  sha512_process(&hs,d + 32,32);
  409|  1.01k|  sha512_process(&hs,m,mlen);
  410|  1.01k|  sha512_done(&hs,r);
  411|  1.01k|  reduce(r);
  412|  1.01k|  scalarbase(p,r);
  413|  1.01k|  pack(s,p);
  414|       |
  415|  1.01k|  sha512_init(&hs);
  416|  1.01k|  sha512_process(&hs,s,32);
  417|  1.01k|  sha512_process(&hs,pk,32);
  418|  1.01k|  sha512_process(&hs,m,mlen);
  419|  1.01k|  sha512_done(&hs,h);
  420|  1.01k|  reduce(h);
  421|       |
  422|  64.8k|  FOR(i,64) x[i] = 0;
  ------------------
  |  |   34|  65.8k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 64.8k, False: 1.01k]
  |  |  ------------------
  ------------------
  423|  32.4k|  FOR(i,32) x[i] = (u64) r[i];
  ------------------
  |  |   34|  33.4k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 32.4k, False: 1.01k]
  |  |  ------------------
  ------------------
  424|  1.03M|  FOR(i,32) FOR(j,32) x[i+j] += h[i] * (u64) d[j];
  ------------------
  |  |   34|  33.4k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 32.4k, False: 1.01k]
  |  |  ------------------
  ------------------
                FOR(i,32) FOR(j,32) x[i+j] += h[i] * (u64) d[j];
  ------------------
  |  |   34|  1.06M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 1.03M, False: 32.4k]
  |  |  ------------------
  ------------------
  425|  1.01k|  modL(s + 32,x);
  426|  1.01k|}
curve25519.c:unpack25519:
  150|  14.2k|{
  151|  14.2k|  int i;
  152|   228k|  FOR(i,16) o[i]=n[2*i]+((i64)n[2*i+1]<<8);
  ------------------
  |  |   34|   242k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 228k, False: 14.2k]
  |  |  ------------------
  ------------------
  153|  14.2k|  o[15]&=0x7fff;
  154|  14.2k|}
curve25519.c:sel25519:
   96|  16.6M|{
   97|  16.6M|  i64 t,i,c=~(b-1);
   98|   266M|  FOR(i,16) {
  ------------------
  |  |   34|   283M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 266M, False: 16.6M]
  |  |  ------------------
  ------------------
   99|   266M|    t= c&(p[i]^q[i]);
  100|   266M|    p[i]^=t;
  101|   266M|    q[i]^=t;
  102|   266M|  }
  103|  16.6M|}
curve25519.c:A:
  157|  17.1M|{
  158|  17.1M|  int i;
  159|   274M|  FOR(i,16) o[i]=a[i]+b[i];
  ------------------
  |  |   34|   291M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 274M, False: 17.1M]
  |  |  ------------------
  ------------------
  160|  17.1M|}
curve25519.c:Z:
  163|  16.6M|{
  164|  16.6M|  int i;
  165|   266M|  FOR(i,16) o[i]=a[i]-b[i];
  ------------------
  |  |   34|   282M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 266M, False: 16.6M]
  |  |  ------------------
  ------------------
  166|  16.6M|}
curve25519.c:S:
  180|  18.4M|{
  181|  18.4M|  M(o,a,a);
  182|  18.4M|}
curve25519.c:M:
  169|  48.8M|{
  170|  48.8M|  i64 i,j,t[31];
  171|  1.51G|  FOR(i,31) t[i]=0;
  ------------------
  |  |   34|  1.56G|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 1.51G, False: 48.8M]
  |  |  ------------------
  ------------------
  172|  12.5G|  FOR(i,16) FOR(j,16) t[i+j]+=a[i]*b[j];
  ------------------
  |  |   34|   830M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 781M, False: 48.8M]
  |  |  ------------------
  ------------------
                FOR(i,16) FOR(j,16) t[i+j]+=a[i]*b[j];
  ------------------
  |  |   34|  13.2G|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 12.5G, False: 781M]
  |  |  ------------------
  ------------------
  173|   732M|  FOR(i,15) t[i]+=38*t[i+16];
  ------------------
  |  |   34|   781M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 732M, False: 48.8M]
  |  |  ------------------
  ------------------
  174|   781M|  FOR(i,16) o[i]=t[i];
  ------------------
  |  |   34|   830M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 781M, False: 48.8M]
  |  |  ------------------
  ------------------
  175|  48.8M|  car25519(o);
  176|  48.8M|  car25519(o);
  177|  48.8M|}
curve25519.c:car25519:
   84|  97.7M|{
   85|  97.7M|  int i;
   86|  97.7M|  i64 c;
   87|  1.56G|  FOR(i,16) {
  ------------------
  |  |   34|  1.66G|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 1.56G, False: 97.7M]
  |  |  ------------------
  ------------------
   88|  1.56G|    o[i]+=(1LL<<16);
   89|  1.56G|    c=o[i]>>16;
   90|  1.56G|    o[(i+1)*(i<15)]+=c-1+37*(c-1)*(i==15);
   91|  1.56G|    o[i]-=c<<16;
   92|  1.56G|  }
   93|  97.7M|}
curve25519.c:inv25519:
  185|  15.2k|{
  186|  15.2k|  gf c;
  187|  15.2k|  int a;
  188|   244k|  FOR(a,16) c[a]=i[a];
  ------------------
  |  |   34|   260k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 244k, False: 15.2k]
  |  |  ------------------
  ------------------
  189|  3.90M|  for(a=253;a>=0;a--) {
  ------------------
  |  Branch (189:13): [True: 3.88M, False: 15.2k]
  ------------------
  190|  3.88M|    S(c,c);
  191|  3.88M|    if(a!=2&&a!=4) M(c,c,i);
  ------------------
  |  Branch (191:8): [True: 3.86M, False: 15.2k]
  |  Branch (191:14): [True: 3.85M, False: 15.2k]
  ------------------
  192|  3.88M|  }
  193|   244k|  FOR(a,16) o[a]=c[a];
  ------------------
  |  |   34|   260k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 244k, False: 15.2k]
  |  |  ------------------
  ------------------
  194|  15.2k|}
curve25519.c:pack25519:
  106|  16.3k|{
  107|  16.3k|  int i,j,b;
  108|  16.3k|  gf m,t;
  109|   260k|  FOR(i,16) t[i]=n[i];
  ------------------
  |  |   34|   277k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 260k, False: 16.3k]
  |  |  ------------------
  ------------------
  110|  16.3k|  car25519(t);
  111|  16.3k|  car25519(t);
  112|  16.3k|  car25519(t);
  113|  32.6k|  FOR(j,2) {
  ------------------
  |  |   34|  48.9k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 32.6k, False: 16.3k]
  |  |  ------------------
  ------------------
  114|  32.6k|    m[0]=t[0]-0xffed;
  115|   489k|    for(i=1;i<15;i++) {
  ------------------
  |  Branch (115:13): [True: 456k, False: 32.6k]
  ------------------
  116|   456k|      m[i]=t[i]-0xffff-((m[i-1]>>16)&1);
  117|   456k|      m[i-1]&=0xffff;
  118|   456k|    }
  119|  32.6k|    m[15]=t[15]-0x7fff-((m[14]>>16)&1);
  120|  32.6k|    b=(m[15]>>16)&1;
  121|  32.6k|    m[14]&=0xffff;
  122|  32.6k|    sel25519(t,m,1-b);
  123|  32.6k|  }
  124|   260k|  FOR(i,16) {
  ------------------
  |  |   34|   277k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 260k, False: 16.3k]
  |  |  ------------------
  ------------------
  125|   260k|    o[2*i]=t[i]&0xff;
  126|   260k|    o[2*i+1]=t[i]>>8;
  127|   260k|  }
  128|  16.3k|}
curve25519.c:crypto_hash:
  264|  1.01k|{
  265|  1.01k|  hash_state hs;
  266|       |
  267|  1.01k|  sha512_init(&hs);
  268|  1.01k|  sha512_process(&hs, m, n);
  269|  1.01k|  return sha512_done(&hs, out);
  270|  1.01k|}
curve25519.c:scalarbase:
  331|  1.01k|{
  332|  1.01k|  gf q[4];
  333|  1.01k|  set25519(q[0],X);
  334|  1.01k|  set25519(q[1],Y);
  335|  1.01k|  set25519(q[2],gf1);
  336|  1.01k|  M(q[3],X,Y);
  337|  1.01k|  scalarmult(p,q,s);
  338|  1.01k|}
curve25519.c:set25519:
   77|  7.09k|{
   78|  7.09k|  int i;
   79|   113k|  FOR(i,16) r[i]=a[i];
  ------------------
  |  |   34|   120k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 113k, False: 7.09k]
  |  |  ------------------
  ------------------
   80|  7.09k|}
curve25519.c:pack:
  305|  1.01k|{
  306|  1.01k|  gf tx, ty, zi;
  307|  1.01k|  inv25519(zi, p[2]); 
  308|  1.01k|  M(tx, p[0], zi);
  309|  1.01k|  M(ty, p[1], zi);
  310|  1.01k|  pack25519(r, ty);
  311|  1.01k|  r[31] ^= par25519(tx) << 7;
  312|  1.01k|}
curve25519.c:par25519:
  142|  1.01k|{
  143|  1.01k|  u8 d[32];
  144|  1.01k|  pack25519(d,a);
  145|  1.01k|  return d[0]&1;
  146|  1.01k|}
curve25519.c:reduce:
  385|  2.02k|{
  386|  2.02k|  i64 x[64],i;
  387|   129k|  FOR(i,64) x[i] = (u64) r[i];
  ------------------
  |  |   34|   131k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 129k, False: 2.02k]
  |  |  ------------------
  ------------------
  388|   129k|  FOR(i,64) r[i] = 0;
  ------------------
  |  |   34|   131k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 129k, False: 2.02k]
  |  |  ------------------
  ------------------
  389|  2.02k|  modL(r,x);
  390|  2.02k|}
curve25519.c:modL:
  359|  3.03k|{
  360|  3.03k|  i64 carry,i,j;
  361|   100k|  for (i = 63;i >= 32;--i) {
  ------------------
  |  Branch (361:15): [True: 97.2k, False: 3.03k]
  ------------------
  362|  97.2k|    carry = 0;
  363|  2.04M|    for (j = i - 32;j < i - 12;++j) {
  ------------------
  |  Branch (363:21): [True: 1.94M, False: 97.2k]
  ------------------
  364|  1.94M|      x[j] += carry - 16 * x[i] * L[j - (i - 32)];
  365|  1.94M|      carry = (x[j] + 128) >> 8;
  366|  1.94M|      x[j] -= carry << 8;
  367|  1.94M|    }
  368|  97.2k|    x[j] += carry;
  369|  97.2k|    x[i] = 0;
  370|  97.2k|  }
  371|  3.03k|  carry = 0;
  372|  97.2k|  FOR(j,32) {
  ------------------
  |  |   34|   100k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 97.2k, False: 3.03k]
  |  |  ------------------
  ------------------
  373|  97.2k|    x[j] += carry - (x[31] >> 4) * L[j];
  374|  97.2k|    carry = x[j] >> 8;
  375|  97.2k|    x[j] &= 255;
  376|  97.2k|  }
  377|  97.2k|  FOR(j,32) x[j] -= carry * L[j];
  ------------------
  |  |   34|   100k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 97.2k, False: 3.03k]
  |  |  ------------------
  ------------------
  378|  97.2k|  FOR(i,32) {
  ------------------
  |  |   34|   100k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 97.2k, False: 3.03k]
  |  |  ------------------
  ------------------
  379|  97.2k|    x[i+1] += x[i] >> 8;
  380|  97.2k|    r[i] = x[i] & 255;
  381|  97.2k|  }
  382|  3.03k|}
curve25519.c:scalarmult:
  315|  1.01k|{
  316|  1.01k|  int i;
  317|  1.01k|  set25519(p[0],gf0);
  318|  1.01k|  set25519(p[1],gf1);
  319|  1.01k|  set25519(p[2],gf1);
  320|  1.01k|  set25519(p[3],gf0);
  321|   260k|  for (i = 255;i >= 0;--i) {
  ------------------
  |  Branch (321:16): [True: 259k, False: 1.01k]
  ------------------
  322|   259k|    u8 b = (s[i/8]>>(i&7))&1;
  323|   259k|    cswap(p,q,b);
  324|   259k|    add(q,p);
  325|   259k|    add(p,p);
  326|   259k|    cswap(p,q,b);
  327|   259k|  }
  328|  1.01k|}
curve25519.c:cswap:
  298|   518k|{
  299|   518k|  int i;
  300|   518k|  FOR(i,4)
  ------------------
  |  |   34|  2.59M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 2.07M, False: 518k]
  |  |  ------------------
  ------------------
  301|  2.07M|    sel25519(p[i],q[i],b);
  302|   518k|}
curve25519.c:add:
  273|   518k|{
  274|   518k|  gf a,b,c,d,t,e,f,g,h;
  275|       |  
  276|   518k|  Z(a, p[1], p[0]);
  277|   518k|  Z(t, q[1], q[0]);
  278|   518k|  M(a, a, t);
  279|   518k|  A(b, p[0], p[1]);
  280|   518k|  A(t, q[0], q[1]);
  281|   518k|  M(b, b, t);
  282|   518k|  M(c, p[3], q[3]);
  283|   518k|  M(c, c, D2);
  284|   518k|  M(d, p[2], q[2]);
  285|   518k|  A(d, d, d);
  286|   518k|  Z(e, b, a);
  287|   518k|  Z(f, d, c);
  288|   518k|  A(g, d, c);
  289|   518k|  A(h, b, a);
  290|       |
  291|   518k|  M(p[0], e, f);
  292|   518k|  M(p[1], h, g);
  293|   518k|  M(p[2], g, f);
  294|   518k|  M(p[3], e, h);
  295|   518k|}

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

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

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

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

buf_get_dss_pub_key:
   46|      1|int buf_get_dss_pub_key(buffer* buf, dropbear_dss_key *key) {
   47|      1|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
   48|       |
   49|      1|	TRACE(("enter buf_get_dss_pub_key"))
   50|      1|	dropbear_assert(key != NULL);
  ------------------
  |  |   83|      1|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 1]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
   51|      1|	m_mp_alloc_init_multi(&key->p, &key->q, &key->g, &key->y, NULL);
   52|      1|	key->x = NULL;
   53|       |
   54|      1|	buf_incrpos(buf, 4+SSH_SIGNKEY_DSS_LEN); /* int + "ssh-dss" */
  ------------------
  |  |  111|      1|#define SSH_SIGNKEY_DSS_LEN 7
  ------------------
   55|      1|	if (buf_getmpint(buf, key->p) == DROPBEAR_FAILURE
  ------------------
  |  |  103|      2|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (55:6): [True: 0, False: 1]
  ------------------
   56|      1|	 || buf_getmpint(buf, key->q) == DROPBEAR_FAILURE
  ------------------
  |  |  103|      2|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (56:6): [True: 0, False: 1]
  ------------------
   57|      1|	 || buf_getmpint(buf, key->g) == DROPBEAR_FAILURE
  ------------------
  |  |  103|      2|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (57:6): [True: 0, False: 1]
  ------------------
   58|      1|	 || buf_getmpint(buf, key->y) == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (58:6): [True: 0, False: 1]
  ------------------
   59|      0|		TRACE(("leave buf_get_dss_pub_key: failed reading mpints"))
   60|      0|		ret = DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
   61|      0|		goto out;
   62|      0|	}
   63|       |
   64|      1|	if (mp_count_bits(key->p) != DSS_P_BITS) {
  ------------------
  |  |   44|      1|#define DSS_P_BITS 1024
  ------------------
  |  Branch (64:6): [True: 0, False: 1]
  ------------------
   65|      0|		dropbear_log(LOG_WARNING, "Bad DSS p");
   66|      0|		ret = DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
   67|      0|		goto out;
   68|      0|	}
   69|       |
   70|      1|	if (mp_count_bits(key->q) != DSS_Q_BITS) {
  ------------------
  |  |   45|      1|#define DSS_Q_BITS 160
  ------------------
  |  Branch (70:6): [True: 0, False: 1]
  ------------------
   71|      0|		dropbear_log(LOG_WARNING, "Bad DSS q");
   72|      0|		ret = DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
   73|      0|		goto out;
   74|      0|	}
   75|       |
   76|       |	/* test 1 < g < p */
   77|      1|	if (mp_cmp_d(key->g, 1) != MP_GT) {
  ------------------
  |  |  156|      1|#define MP_GT         1   /* greater than */
  ------------------
  |  Branch (77:6): [True: 0, False: 1]
  ------------------
   78|      0|		dropbear_log(LOG_WARNING, "Bad DSS g");
   79|      0|		ret = DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
   80|      0|		goto out;
   81|      0|	}
   82|      1|	if (mp_cmp(key->g, key->p) != MP_LT) {
  ------------------
  |  |  154|      1|#define MP_LT        -1   /* less than */
  ------------------
  |  Branch (82:6): [True: 0, False: 1]
  ------------------
   83|      0|		dropbear_log(LOG_WARNING, "Bad DSS g");
   84|      0|		ret = DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
   85|      0|		goto out;
   86|      0|	}
   87|       |
   88|      1|	ret = DROPBEAR_SUCCESS;
  ------------------
  |  |  102|      1|#define DROPBEAR_SUCCESS 0
  ------------------
   89|      1|	TRACE(("leave buf_get_dss_pub_key: success"))
   90|      1|out:
   91|      1|	if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (91:6): [True: 0, False: 1]
  ------------------
   92|      0|		m_mp_free_multi(&key->p, &key->q, &key->g, &key->y, NULL);
   93|      0|	}
   94|      1|	return ret;
   95|      1|}
buf_get_dss_priv_key:
  100|      1|int buf_get_dss_priv_key(buffer* buf, dropbear_dss_key *key) {
  101|       |
  102|      1|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  103|       |
  104|      1|	dropbear_assert(key != NULL);
  ------------------
  |  |   83|      1|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 1]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
  105|       |
  106|      1|	ret = buf_get_dss_pub_key(buf, key);
  107|      1|	if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (107:6): [True: 0, False: 1]
  ------------------
  108|      0|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
  109|      0|	}
  110|       |
  111|      1|	m_mp_alloc_init_multi(&key->x, NULL);
  112|      1|	ret = buf_getmpint(buf, key->x);
  113|      1|	if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (113:6): [True: 0, False: 1]
  ------------------
  114|      0|		m_mp_free_multi(&key->x, NULL);
  115|      0|	}
  116|       |
  117|      1|	return ret;
  118|      1|}
dss_key_free:
  122|      1|void dss_key_free(dropbear_dss_key *key) {
  123|       |
  124|      1|	TRACE2(("enter dsa_key_free"))
  125|      1|	if (key == NULL) {
  ------------------
  |  Branch (125:6): [True: 1, False: 0]
  ------------------
  126|      1|		TRACE2(("enter dsa_key_free: key == NULL"))
  127|      1|		return;
  128|      1|	}
  129|      0|	m_mp_free_multi(&key->p, &key->q, &key->g, &key->y, &key->x, NULL);
  130|      0|	m_free(key);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  131|      0|	TRACE2(("leave dsa_key_free"))
  132|      0|}
buf_put_dss_pub_key:
  142|  18.3k|void buf_put_dss_pub_key(buffer* buf, const dropbear_dss_key *key) {
  143|       |
  144|  18.3k|	dropbear_assert(key != NULL);
  ------------------
  |  |   83|  18.3k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 18.3k]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
  145|  18.3k|	buf_putstring(buf, SSH_SIGNKEY_DSS, SSH_SIGNKEY_DSS_LEN);
  ------------------
  |  |  110|  18.3k|#define SSH_SIGNKEY_DSS "ssh-dss"
  ------------------
              	buf_putstring(buf, SSH_SIGNKEY_DSS, SSH_SIGNKEY_DSS_LEN);
  ------------------
  |  |  111|  18.3k|#define SSH_SIGNKEY_DSS_LEN 7
  ------------------
  146|  18.3k|	buf_putmpint(buf, key->p);
  147|  18.3k|	buf_putmpint(buf, key->q);
  148|  18.3k|	buf_putmpint(buf, key->g);
  149|  18.3k|	buf_putmpint(buf, key->y);
  150|       |
  151|  18.3k|}
buf_put_dss_sign:
  283|  9.15k|void buf_put_dss_sign(buffer* buf, const dropbear_dss_key *key, const buffer *data_buf) {
  284|  9.15k|	unsigned char msghash[SHA1_HASH_SIZE];
  285|  9.15k|	unsigned int writelen;
  286|  9.15k|	unsigned int i;
  287|  9.15k|	size_t written;
  288|  9.15k|	DEF_MP_INT(dss_k);
  ------------------
  |  |   80|  9.15k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  289|  9.15k|	DEF_MP_INT(dss_m);
  ------------------
  |  |   80|  9.15k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  290|  9.15k|	DEF_MP_INT(dss_temp1);
  ------------------
  |  |   80|  9.15k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  291|  9.15k|	DEF_MP_INT(dss_temp2);
  ------------------
  |  |   80|  9.15k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  292|  9.15k|	DEF_MP_INT(dss_r);
  ------------------
  |  |   80|  9.15k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  293|  9.15k|	DEF_MP_INT(dss_s);
  ------------------
  |  |   80|  9.15k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  294|  9.15k|	hash_state hs;
  295|       |	
  296|  9.15k|	TRACE(("enter buf_put_dss_sign"))
  297|  9.15k|	dropbear_assert(key != NULL);
  ------------------
  |  |   83|  9.15k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 9.15k]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
  298|       |	
  299|       |	/* hash the data */
  300|  9.15k|	sha1_init(&hs);
  301|  9.15k|	sha1_process(&hs, data_buf->data, data_buf->len);
  302|  9.15k|	sha1_done(&hs, msghash);
  303|       |
  304|  9.15k|	m_mp_init_multi(&dss_k, &dss_temp1, &dss_temp2, &dss_r, &dss_s,
  305|  9.15k|			&dss_m, NULL);
  306|       |	/* the random number generator's input has included the private key which
  307|       |	 * avoids DSS's problem of private key exposure due to low entropy */
  308|  9.15k|	gen_random_mpint(key->q, &dss_k);
  309|       |
  310|       |	/* now generate the actual signature */
  311|  9.15k|	bytes_to_mp(&dss_m, msghash, SHA1_HASH_SIZE);
  ------------------
  |  |  120|  9.15k|#define SHA1_HASH_SIZE 20
  ------------------
  312|       |
  313|       |	/* g^k mod p */
  314|  9.15k|	if (mp_exptmod(key->g, &dss_k, key->p, &dss_temp1) !=  MP_OKAY) {
  ------------------
  |  |  161|  9.15k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (314:6): [True: 0, False: 9.15k]
  ------------------
  315|      0|		dropbear_exit("DSS error");
  316|      0|	}
  317|       |	/* r = (g^k mod p) mod q */
  318|  9.15k|	if (mp_mod(&dss_temp1, key->q, &dss_r) != MP_OKAY) {
  ------------------
  |  |  161|  9.15k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (318:6): [True: 0, False: 9.15k]
  ------------------
  319|      0|		dropbear_exit("DSS error");
  320|      0|	}
  321|       |
  322|       |	/* x*r mod q */
  323|  9.15k|	if (mp_mulmod(&dss_r, key->x, key->q, &dss_temp1) != MP_OKAY) {
  ------------------
  |  |  161|  9.15k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (323:6): [True: 0, False: 9.15k]
  ------------------
  324|      0|		dropbear_exit("DSS error");
  325|      0|	}
  326|       |	/* (SHA1(M) + xr) mod q) */
  327|  9.15k|	if (mp_addmod(&dss_m, &dss_temp1, key->q, &dss_temp2) != MP_OKAY) {
  ------------------
  |  |  161|  9.15k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (327:6): [True: 0, False: 9.15k]
  ------------------
  328|      0|		dropbear_exit("DSS error");
  329|      0|	}
  330|       |	
  331|       |	/* (k^-1) mod q */
  332|  9.15k|	if (mp_invmod(&dss_k, key->q, &dss_temp1) != MP_OKAY) {
  ------------------
  |  |  161|  9.15k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (332:6): [True: 0, False: 9.15k]
  ------------------
  333|      0|		dropbear_exit("DSS error");
  334|      0|	}
  335|       |
  336|       |	/* s = (k^-1(SHA1(M) + xr)) mod q */
  337|  9.15k|	if (mp_mulmod(&dss_temp1, &dss_temp2, key->q, &dss_s) != MP_OKAY) {
  ------------------
  |  |  161|  9.15k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (337:6): [True: 0, False: 9.15k]
  ------------------
  338|      0|		dropbear_exit("DSS error");
  339|      0|	}
  340|       |
  341|  9.15k|	buf_putstring(buf, SSH_SIGNKEY_DSS, SSH_SIGNKEY_DSS_LEN);
  ------------------
  |  |  110|  9.15k|#define SSH_SIGNKEY_DSS "ssh-dss"
  ------------------
              	buf_putstring(buf, SSH_SIGNKEY_DSS, SSH_SIGNKEY_DSS_LEN);
  ------------------
  |  |  111|  9.15k|#define SSH_SIGNKEY_DSS_LEN 7
  ------------------
  342|  9.15k|	buf_putint(buf, 2*SHA1_HASH_SIZE);
  ------------------
  |  |  120|  9.15k|#define SHA1_HASH_SIZE 20
  ------------------
  343|       |
  344|  9.15k|	writelen = mp_ubin_size(&dss_r);
  345|  9.15k|	dropbear_assert(writelen <= SHA1_HASH_SIZE);
  ------------------
  |  |   83|  9.15k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 9.15k]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
  346|       |	/* need to pad to 160 bits with leading zeros */
  347|  9.20k|	for (i = 0; i < SHA1_HASH_SIZE - writelen; i++) {
  ------------------
  |  |  120|  9.20k|#define SHA1_HASH_SIZE 20
  ------------------
  |  Branch (347:14): [True: 51, False: 9.15k]
  ------------------
  348|     51|		buf_putbyte(buf, 0);
  349|     51|	}
  350|  9.15k|	if (mp_to_ubin(&dss_r, buf_getwriteptr(buf, writelen), writelen, &written)
  ------------------
  |  Branch (350:6): [True: 0, False: 9.15k]
  ------------------
  351|  9.15k|			!= MP_OKAY) {
  ------------------
  |  |  161|  9.15k|#define MP_OKAY       0   /* no error */
  ------------------
  352|      0|		dropbear_exit("DSS error");
  353|      0|	}
  354|  9.15k|	mp_clear(&dss_r);
  355|  9.15k|	buf_incrwritepos(buf, written);
  356|       |
  357|  9.15k|	writelen = mp_ubin_size(&dss_s);
  358|  9.15k|	dropbear_assert(writelen <= SHA1_HASH_SIZE);
  ------------------
  |  |   83|  9.15k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 9.15k]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
  359|       |	/* need to pad to 160 bits with leading zeros */
  360|  9.19k|	for (i = 0; i < SHA1_HASH_SIZE - writelen; i++) {
  ------------------
  |  |  120|  9.19k|#define SHA1_HASH_SIZE 20
  ------------------
  |  Branch (360:14): [True: 43, False: 9.15k]
  ------------------
  361|     43|		buf_putbyte(buf, 0);
  362|     43|	}
  363|  9.15k|	if (mp_to_ubin(&dss_s, buf_getwriteptr(buf, writelen), writelen, &written)
  ------------------
  |  Branch (363:6): [True: 0, False: 9.15k]
  ------------------
  364|  9.15k|			!= MP_OKAY) {
  ------------------
  |  |  161|  9.15k|#define MP_OKAY       0   /* no error */
  ------------------
  365|      0|		dropbear_exit("DSS error");
  366|      0|	}
  367|  9.15k|	mp_clear(&dss_s);
  368|  9.15k|	buf_incrwritepos(buf, written);
  369|       |
  370|  9.15k|	mp_clear_multi(&dss_k, &dss_temp1, &dss_temp2, &dss_r, &dss_s,
  371|  9.15k|			&dss_m, NULL);
  372|       |	
  373|       |	/* create the signature to return */
  374|       |
  375|  9.15k|	TRACE(("leave buf_put_dss_sign"))
  376|  9.15k|}

dropbear_ecc_fill_dp:
   47|      1|void dropbear_ecc_fill_dp() {
   48|      1|	struct dropbear_ecc_curve **curve;
   49|       |	/* libtomcrypt guarantees they're ordered by size */
   50|      1|	const ltc_ecc_set_type *dp = ltc_ecc_sets;
   51|      4|	for (curve = dropbear_ecc_curves; *curve; curve++) {
  ------------------
  |  Branch (51:36): [True: 3, False: 1]
  ------------------
   52|     10|		for (;dp->size > 0; dp++) {
  ------------------
  |  Branch (52:9): [True: 10, False: 0]
  ------------------
   53|     10|			if (dp->size == (*curve)->ltc_size) {
  ------------------
  |  Branch (53:8): [True: 3, False: 7]
  ------------------
   54|      3|				(*curve)->dp = dp;
   55|      3|				break;
   56|      3|			}
   57|     10|		}
   58|      3|		if (!(*curve)->dp) {
  ------------------
  |  Branch (58:7): [True: 0, False: 3]
  ------------------
   59|      0|			dropbear_exit("Missing ECC params %s", (*curve)->name);
   60|      0|		}
   61|      3|	}
   62|      1|}
curve_for_dp:
   64|  9.56k|struct dropbear_ecc_curve* curve_for_dp(const ltc_ecc_set_type *dp) {
   65|  9.56k|	struct dropbear_ecc_curve **curve = NULL;
   66|  9.56k|	for (curve = dropbear_ecc_curves; *curve; curve++) {
  ------------------
  |  Branch (66:36): [True: 9.56k, False: 0]
  ------------------
   67|  9.56k|		if ((*curve)->dp == dp) {
  ------------------
  |  Branch (67:7): [True: 9.56k, False: 0]
  ------------------
   68|  9.56k|			break;
   69|  9.56k|		}
   70|  9.56k|	}
   71|  9.56k|	assert(*curve);
   72|  9.56k|	return *curve;
   73|  9.56k|}
new_ecc_key:
   75|      1|ecc_key * new_ecc_key(void) {
   76|      1|	ecc_key *key = m_malloc(sizeof(*key));
   77|      1|	m_mp_alloc_init_multi((mp_int**)&key->pubkey.x, (mp_int**)&key->pubkey.y, 
   78|      1|		(mp_int**)&key->pubkey.z, (mp_int**)&key->k, NULL);
   79|      1|	return key;
   80|      1|}
buf_put_ecc_raw_pubkey_string:
  135|  6.37k|void buf_put_ecc_raw_pubkey_string(buffer *buf, ecc_key *key) {
  136|  6.37k|	unsigned long len = key->dp->size*2 + 1;
  137|  6.37k|	int err;
  138|  6.37k|	buf_putint(buf, len);
  139|  6.37k|	err = ecc_ansi_x963_export(key, buf_getwriteptr(buf, len), &len);
  140|  6.37k|	if (err != CRYPT_OK) {
  ------------------
  |  Branch (140:6): [True: 0, False: 6.37k]
  ------------------
  141|      0|		dropbear_exit("ECC error");
  142|      0|	}
  143|  6.37k|	buf_incrwritepos(buf, len);
  144|  6.37k|}
buf_get_ecc_raw_pubkey:
  147|    314|ecc_key * buf_get_ecc_raw_pubkey(buffer *buf, const struct dropbear_ecc_curve *curve) {
  148|    314|	ecc_key *key = NULL;
  149|    314|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  103|    314|#define DROPBEAR_FAILURE -1
  ------------------
  150|    314|	const unsigned int size = curve->dp->size;
  151|    314|	unsigned char first;
  152|       |
  153|    314|	TRACE(("enter buf_get_ecc_raw_pubkey"))
  154|       |
  155|    314|	buf_setpos(buf, 0);
  156|    314|	first = buf_getbyte(buf);
  157|    314|	if (first == 2 || first == 3) {
  ------------------
  |  Branch (157:6): [True: 13, False: 301]
  |  Branch (157:20): [True: 102, False: 199]
  ------------------
  158|    114|		dropbear_log(LOG_WARNING, "Dropbear doesn't support ECC point compression");
  159|    114|		return NULL;
  160|    114|	}
  161|    200|	if (first != 4 || buf->len != 1+2*size) {
  ------------------
  |  Branch (161:6): [True: 182, False: 18]
  |  Branch (161:20): [True: 17, False: 1]
  ------------------
  162|    198|		TRACE(("leave, wrong size"))
  163|    198|		return NULL;
  164|    198|	}
  165|       |
  166|      2|	key = new_ecc_key();
  167|      2|	key->dp = curve->dp;
  168|       |
  169|      2|	if (mp_from_ubin(key->pubkey.x, buf_getptr(buf, size), size) != MP_OKAY) {
  ------------------
  |  |  161|      2|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (169:6): [True: 0, False: 2]
  ------------------
  170|      0|		TRACE(("failed to read x"))
  171|      0|		goto out;
  172|      0|	}
  173|      2|	buf_incrpos(buf, size);
  174|       |
  175|      2|	if (mp_from_ubin(key->pubkey.y, buf_getptr(buf, size), size) != MP_OKAY) {
  ------------------
  |  |  161|      2|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (175:6): [True: 0, False: 2]
  ------------------
  176|      0|		TRACE(("failed to read y"))
  177|      0|		goto out;
  178|      0|	}
  179|      2|	buf_incrpos(buf, size);
  180|       |
  181|      2|	mp_set(key->pubkey.z, 1);
  182|       |
  183|      2|	if (ecc_is_point(key) != CRYPT_OK) {
  ------------------
  |  Branch (183:6): [True: 0, False: 2]
  ------------------
  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|      2|	if (mp_cmp_d(key->pubkey.x, 0) == LTC_MP_EQ) {
  ------------------
  |  |   13|      2|#define LTC_MP_EQ    0
  ------------------
  |  Branch (189:6): [True: 0, False: 2]
  ------------------
  190|      0|		TRACE(("failed, x == 0"))
  191|      0|		goto out;
  192|      0|	}
  193|      2|	if (mp_cmp_d(key->pubkey.y, 0) == LTC_MP_EQ) {
  ------------------
  |  |   13|      2|#define LTC_MP_EQ    0
  ------------------
  |  Branch (193:6): [True: 0, False: 2]
  ------------------
  194|      0|		TRACE(("failed, y == 0"))
  195|      0|		goto out;
  196|      0|	}
  197|       |
  198|      2|	ret = DROPBEAR_SUCCESS;
  ------------------
  |  |  102|      2|#define DROPBEAR_SUCCESS 0
  ------------------
  199|       |
  200|      2|	out:
  201|      1|	if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (201:6): [True: 0, False: 1]
  ------------------
  202|      0|		if (key) {
  ------------------
  |  Branch (202:7): [True: 0, False: 0]
  ------------------
  203|      0|			ecc_free(key);
  204|      0|			m_free(key);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  205|      0|			key = NULL;
  206|      0|		}
  207|      0|	}
  208|       |
  209|      1|	return key;
  210|       |
  211|      2|}
ecc.c:ecc_is_point:
   85|      1|{
   86|      1|	mp_int *prime, *b, *t1, *t2;
   87|      1|	int err;
   88|       |	
   89|      1|	m_mp_alloc_init_multi(&prime, &b, &t1, &t2, NULL);
   90|       |	
   91|       |   /* load prime and b */
   92|      1|	if ((err = mp_read_radix(prime, key->dp->prime, 16)) != CRYPT_OK)                          { goto error; }
  ------------------
  |  Branch (92:6): [True: 0, False: 1]
  ------------------
   93|      1|	if ((err = mp_read_radix(b, key->dp->B, 16)) != CRYPT_OK)                                  { goto error; }
  ------------------
  |  Branch (93:6): [True: 0, False: 1]
  ------------------
   94|       |	
   95|       |   /* compute y^2 */
   96|      1|	if ((err = mp_sqr(key->pubkey.y, t1)) != CRYPT_OK)                                         { goto error; }
  ------------------
  |  Branch (96:6): [True: 0, False: 1]
  ------------------
   97|       |	
   98|       |   /* compute x^3 */
   99|      1|	if ((err = mp_sqr(key->pubkey.x, t2)) != CRYPT_OK)                                         { goto error; }
  ------------------
  |  Branch (99:6): [True: 0, False: 1]
  ------------------
  100|      1|	if ((err = mp_mod(t2, prime, t2)) != CRYPT_OK)                                             { goto error; }
  ------------------
  |  Branch (100:6): [True: 0, False: 1]
  ------------------
  101|      1|	if ((err = mp_mul(key->pubkey.x, t2, t2)) != CRYPT_OK)                                     { goto error; }
  ------------------
  |  Branch (101:6): [True: 0, False: 1]
  ------------------
  102|       |	
  103|       |   /* compute y^2 - x^3 */
  104|      1|	if ((err = mp_sub(t1, t2, t1)) != CRYPT_OK)                                                { goto error; }
  ------------------
  |  Branch (104:6): [True: 0, False: 1]
  ------------------
  105|       |	
  106|       |   /* compute y^2 - x^3 + 3x */
  107|      1|	if ((err = mp_add(t1, key->pubkey.x, t1)) != CRYPT_OK)                                     { goto error; }
  ------------------
  |  Branch (107:6): [True: 0, False: 1]
  ------------------
  108|      1|	if ((err = mp_add(t1, key->pubkey.x, t1)) != CRYPT_OK)                                     { goto error; }
  ------------------
  |  Branch (108:6): [True: 0, False: 1]
  ------------------
  109|      1|	if ((err = mp_add(t1, key->pubkey.x, t1)) != CRYPT_OK)                                     { goto error; }
  ------------------
  |  Branch (109:6): [True: 0, False: 1]
  ------------------
  110|      1|	if ((err = mp_mod(t1, prime, t1)) != CRYPT_OK)                                             { goto error; }
  ------------------
  |  Branch (110:6): [True: 0, False: 1]
  ------------------
  111|      1|	while (mp_cmp_d(t1, 0) == LTC_MP_LT) {
  ------------------
  |  |   12|      1|#define LTC_MP_LT   -1
  ------------------
  |  Branch (111:9): [True: 0, False: 1]
  ------------------
  112|      0|		if ((err = mp_add(t1, prime, t1)) != CRYPT_OK)                                          { goto error; }
  ------------------
  |  Branch (112:7): [True: 0, False: 0]
  ------------------
  113|      0|	}
  114|      1|	while (mp_cmp(t1, prime) != LTC_MP_LT) {
  ------------------
  |  |   12|      1|#define LTC_MP_LT   -1
  ------------------
  |  Branch (114:9): [True: 0, False: 1]
  ------------------
  115|      0|		if ((err = mp_sub(t1, prime, t1)) != CRYPT_OK)                                          { goto error; }
  ------------------
  |  Branch (115:7): [True: 0, False: 0]
  ------------------
  116|      0|	}
  117|       |	
  118|       |   /* compare to b */
  119|      1|	if (mp_cmp(t1, b) != LTC_MP_EQ) {
  ------------------
  |  |   13|      1|#define LTC_MP_EQ    0
  ------------------
  |  Branch (119:6): [True: 0, False: 1]
  ------------------
  120|      0|		err = CRYPT_INVALID_PACKET;
  121|      1|	} else {
  122|      1|		err = CRYPT_OK;
  123|      1|	}
  124|       |	
  125|      1|	error:
  126|      1|	mp_clear_multi(prime, b, t1, t2, NULL);
  127|      1|	m_free(prime);
  ------------------
  |  |   24|      1|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  128|      1|	m_free(b);
  ------------------
  |  |   24|      1|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  129|      1|	m_free(t1);
  ------------------
  |  |   24|      1|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  130|      1|	m_free(t2);
  ------------------
  |  |   24|      1|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  131|      1|	return err;
  132|      1|}

signkey_is_ecdsa:
   11|  52.3k|{
   12|  52.3k|	return type == DROPBEAR_SIGNKEY_ECDSA_NISTP256
  ------------------
  |  Branch (12:9): [True: 9.56k, False: 42.7k]
  ------------------
   13|  52.3k|		|| type == DROPBEAR_SIGNKEY_ECDSA_NISTP384
  ------------------
  |  Branch (13:6): [True: 1, False: 42.7k]
  ------------------
   14|  52.3k|		|| type == DROPBEAR_SIGNKEY_ECDSA_NISTP521;
  ------------------
  |  Branch (14:6): [True: 1, False: 42.7k]
  ------------------
   15|  52.3k|}
buf_get_ecdsa_pub_key:
   77|      1|ecc_key *buf_get_ecdsa_pub_key(buffer* buf) {
   78|      1|	unsigned char *key_ident = NULL, *identifier = NULL;
   79|      1|	unsigned int key_ident_len, identifier_len;
   80|      1|	buffer *q_buf = NULL;
   81|      1|	struct dropbear_ecc_curve **curve;
   82|      1|	ecc_key *new_key = NULL;
   83|       |
   84|       |	/* string   "ecdsa-sha2-[identifier]" or "sk-ecdsa-sha2-nistp256@openssh.com" */
   85|      1|	key_ident = (unsigned char*)buf_getstring(buf, &key_ident_len);
   86|       |	/* string   "[identifier]" */
   87|      1|	identifier = (unsigned char*)buf_getstring(buf, &identifier_len);
   88|       |
   89|      1|	if (strcmp (key_ident, "sk-ecdsa-sha2-nistp256@openssh.com") == 0) {
  ------------------
  |  Branch (89:6): [True: 0, False: 1]
  ------------------
   90|      0|		if (strcmp (identifier, "nistp256") != 0) {
  ------------------
  |  Branch (90:7): [True: 0, False: 0]
  ------------------
   91|      0|			TRACE(("mismatching identifiers"))
   92|      0|			goto out;
   93|      0|		}
   94|      1|	} else {
   95|      1|		if (key_ident_len != identifier_len + strlen ("ecdsa-sha2-")) {
  ------------------
  |  Branch (95:7): [True: 0, False: 1]
  ------------------
   96|      0|			TRACE(("Bad identifier lengths"))
   97|      0|			goto out;
   98|      0|		}
   99|      1|		if (memcmp(&key_ident[strlen ("ecdsa-sha2-")], identifier, identifier_len) != 0) {
  ------------------
  |  Branch (99:7): [True: 0, False: 1]
  ------------------
  100|      0|			TRACE(("mismatching identifiers"))
  101|      0|			goto out;
  102|      0|		}
  103|      1|	}
  104|       |
  105|      1|	for (curve = dropbear_ecc_curves; *curve; curve++) {
  ------------------
  |  Branch (105:36): [True: 1, False: 0]
  ------------------
  106|      1|		if (memcmp(identifier, (char*)(*curve)->name, strlen((char*)(*curve)->name)) == 0) {
  ------------------
  |  Branch (106:7): [True: 1, False: 0]
  ------------------
  107|      1|			break;
  108|      1|		}
  109|      1|	}
  110|      1|	if (!*curve) {
  ------------------
  |  Branch (110:6): [True: 0, False: 1]
  ------------------
  111|      0|		TRACE(("couldn't match ecc curve"))
  112|      0|		goto out;
  113|      0|	}
  114|       |
  115|       |	/* string Q */
  116|      1|	q_buf = buf_getstringbuf(buf);
  117|      1|	new_key = buf_get_ecc_raw_pubkey(q_buf, *curve);
  118|       |
  119|      1|out:
  120|      1|	m_free(key_ident);
  ------------------
  |  |   24|      1|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  121|      1|	m_free(identifier);
  ------------------
  |  |   24|      1|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  122|      1|	if (q_buf) {
  ------------------
  |  Branch (122:6): [True: 1, False: 0]
  ------------------
  123|      1|		buf_free(q_buf);
  124|      1|		q_buf = NULL;
  125|      1|	}
  126|      1|	TRACE(("leave buf_get_ecdsa_pub_key"))	
  127|      1|	return new_key;
  128|      1|}
buf_get_ecdsa_priv_key:
  130|      1|ecc_key *buf_get_ecdsa_priv_key(buffer *buf) {
  131|      1|	ecc_key *new_key = NULL;
  132|      1|	TRACE(("enter buf_get_ecdsa_priv_key"))
  133|      1|	new_key = buf_get_ecdsa_pub_key(buf);
  134|      1|	if (!new_key) {
  ------------------
  |  Branch (134:6): [True: 0, False: 1]
  ------------------
  135|      0|		return NULL;
  136|      0|	}
  137|       |
  138|      1|	if (buf_getmpint(buf, new_key->k) != DROPBEAR_SUCCESS) {
  ------------------
  |  |  102|      1|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (138:6): [True: 0, False: 1]
  ------------------
  139|      0|		ecc_free(new_key);
  140|      0|		m_free(new_key);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  141|      0|		return NULL;
  142|      0|	}
  143|       |
  144|      1|	return new_key;
  145|      1|}
buf_put_ecdsa_pub_key:
  147|  6.37k|void buf_put_ecdsa_pub_key(buffer *buf, ecc_key *key) {
  148|  6.37k|	struct dropbear_ecc_curve *curve = NULL;
  149|  6.37k|	char key_ident[30];
  150|       |
  151|  6.37k|	curve = curve_for_dp(key->dp);
  152|  6.37k|	snprintf(key_ident, sizeof(key_ident), "ecdsa-sha2-%s", curve->name);
  153|  6.37k|	buf_putstring(buf, key_ident, strlen(key_ident));
  154|  6.37k|	buf_putstring(buf, curve->name, strlen(curve->name));
  155|  6.37k|	buf_put_ecc_raw_pubkey_string(buf, key);
  156|  6.37k|}
buf_put_ecdsa_sign:
  163|  3.18k|void buf_put_ecdsa_sign(buffer *buf, const ecc_key *key, const buffer *data_buf) {
  164|       |	/* Based on libtomcrypt's ecc_sign_hash but without the asn1 */
  165|  3.18k|	int err = DROPBEAR_FAILURE;
  ------------------
  |  |  103|  3.18k|#define DROPBEAR_FAILURE -1
  ------------------
  166|  3.18k|	struct dropbear_ecc_curve *curve = NULL;
  167|  3.18k|	hash_state hs;
  168|  3.18k|	unsigned char hash[64];
  169|  3.18k|	void *e = NULL, *p = NULL, *s = NULL, *r;
  170|  3.18k|	char key_ident[30];
  171|  3.18k|	buffer *sigbuf = NULL;
  172|       |
  173|  3.18k|	TRACE(("buf_put_ecdsa_sign"))
  174|  3.18k|	curve = curve_for_dp(key->dp);
  175|       |
  176|  3.18k|	if (ltc_init_multi(&r, &s, &p, &e, NULL) != CRYPT_OK) { 
  ------------------
  |  Branch (176:6): [True: 0, False: 3.18k]
  ------------------
  177|      0|		goto out;
  178|      0|	}
  179|       |
  180|  3.18k|	curve->hash_desc->init(&hs);
  181|  3.18k|	curve->hash_desc->process(&hs, data_buf->data, data_buf->len);
  182|  3.18k|	curve->hash_desc->done(&hs, hash);
  183|       |
  184|  3.18k|	if (ltc_mp.unsigned_read(e, hash, curve->hash_desc->hashsize) != CRYPT_OK) {
  ------------------
  |  Branch (184:6): [True: 0, False: 3.18k]
  ------------------
  185|      0|		goto out;
  186|      0|	}
  187|       |
  188|  3.18k|	if (ltc_mp.read_radix(p, (char *)key->dp->order, 16) != CRYPT_OK) { 
  ------------------
  |  Branch (188:6): [True: 0, False: 3.18k]
  ------------------
  189|      0|		goto out; 
  190|      0|	}
  191|       |
  192|  3.18k|	for (;;) {
  193|  3.18k|		ecc_key R_key; /* ephemeral key */
  194|  3.18k|		if (ecc_make_key_ex(NULL, dropbear_ltc_prng, &R_key, key->dp) != CRYPT_OK) {
  ------------------
  |  Branch (194:7): [True: 0, False: 3.18k]
  ------------------
  195|      0|			goto out;
  196|      0|		}
  197|  3.18k|		if (ltc_mp.mpdiv(R_key.pubkey.x, p, NULL, r) != CRYPT_OK) {
  ------------------
  |  Branch (197:7): [True: 0, False: 3.18k]
  ------------------
  198|      0|			goto out;
  199|      0|		}
  200|  3.18k|		if (ltc_mp.compare_d(r, 0) == LTC_MP_EQ) {
  ------------------
  |  |   13|  3.18k|#define LTC_MP_EQ    0
  ------------------
  |  Branch (200:7): [True: 0, False: 3.18k]
  ------------------
  201|       |			/* try again */
  202|      0|			ecc_free(&R_key);
  203|      0|			continue;
  204|      0|		}
  205|       |		/* k = 1/k */
  206|  3.18k|		if (ltc_mp.invmod(R_key.k, p, R_key.k) != CRYPT_OK) {
  ------------------
  |  Branch (206:7): [True: 0, False: 3.18k]
  ------------------
  207|      0|			goto out;
  208|      0|		}
  209|       |		/* s = xr */
  210|  3.18k|		if (ltc_mp.mulmod(key->k, r, p, s) != CRYPT_OK) {
  ------------------
  |  Branch (210:7): [True: 0, False: 3.18k]
  ------------------
  211|      0|			goto out;
  212|      0|		}
  213|       |		/* s = e +  xr */
  214|  3.18k|		if (ltc_mp.add(e, s, s) != CRYPT_OK) {
  ------------------
  |  Branch (214:7): [True: 0, False: 3.18k]
  ------------------
  215|      0|			goto out;
  216|      0|		}
  217|  3.18k|		if (ltc_mp.mpdiv(s, p, NULL, s) != CRYPT_OK) {
  ------------------
  |  Branch (217:7): [True: 0, False: 3.18k]
  ------------------
  218|      0|			goto out;
  219|      0|		}
  220|       |		/* s = (e + xr)/k */
  221|  3.18k|		if (ltc_mp.mulmod(s, R_key.k, p, s) != CRYPT_OK) {
  ------------------
  |  Branch (221:7): [True: 0, False: 3.18k]
  ------------------
  222|      0|			goto out;
  223|      0|		}
  224|  3.18k|		ecc_free(&R_key);
  225|       |
  226|  3.18k|		if (ltc_mp.compare_d(s, 0) != LTC_MP_EQ) {
  ------------------
  |  |   13|  3.18k|#define LTC_MP_EQ    0
  ------------------
  |  Branch (226:7): [True: 3.18k, False: 0]
  ------------------
  227|  3.18k|			break;
  228|  3.18k|		}
  229|  3.18k|	}
  230|       |
  231|  3.18k|	snprintf(key_ident, sizeof(key_ident), "ecdsa-sha2-%s", curve->name);
  232|  3.18k|	buf_putstring(buf, key_ident, strlen(key_ident));
  233|       |	/* enough for nistp521 */
  234|  3.18k|	sigbuf = buf_new(200);
  235|  3.18k|	buf_putmpint(sigbuf, (mp_int*)r);
  236|  3.18k|	buf_putmpint(sigbuf, (mp_int*)s);
  237|  3.18k|	buf_putbufstring(buf, sigbuf);
  238|       |
  239|  3.18k|	err = DROPBEAR_SUCCESS;
  ------------------
  |  |  102|  3.18k|#define DROPBEAR_SUCCESS 0
  ------------------
  240|       |
  241|  3.18k|out:
  242|  3.18k|	if (r && s && p && e) {
  ------------------
  |  Branch (242:6): [True: 3.18k, False: 0]
  |  Branch (242:11): [True: 3.18k, False: 0]
  |  Branch (242:16): [True: 3.18k, False: 0]
  |  Branch (242:21): [True: 3.18k, False: 0]
  ------------------
  243|  3.18k|		ltc_deinit_multi(r, s, p, e, NULL);
  244|  3.18k|	}
  245|       |
  246|  3.18k|	if (sigbuf) {
  ------------------
  |  Branch (246:6): [True: 3.18k, False: 0]
  ------------------
  247|  3.18k|		buf_free(sigbuf);
  248|  3.18k|	}
  249|       |
  250|  3.18k|	if (err == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|  3.18k|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (250:6): [True: 0, False: 3.18k]
  ------------------
  251|      0|		dropbear_exit("ECC error");
  252|      0|	}
  253|  3.18k|}

buf_get_ed25519_priv_key:
   78|      1|int buf_get_ed25519_priv_key(buffer *buf, dropbear_ed25519_key *key) {
   79|       |
   80|      1|	unsigned int len;
   81|       |
   82|      1|	TRACE(("enter buf_get_ed25519_priv_key"))
   83|      1|	dropbear_assert(key != NULL);
  ------------------
  |  |   83|      1|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 1]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
   84|       |
   85|      1|	buf_incrpos(buf, 4+SSH_SIGNKEY_ED25519_LEN); /* int + "ssh-ed25519" */
  ------------------
  |  |  115|      1|#define SSH_SIGNKEY_ED25519_LEN 11
  ------------------
   86|       |
   87|      1|	len = buf_getint(buf);
   88|      1|	if (len != CURVE25519_LEN*2 || buf->len - buf->pos < len) {
  ------------------
  |  |   34|      1|#define CURVE25519_LEN 32
  ------------------
  |  Branch (88:6): [True: 0, False: 1]
  |  Branch (88:33): [True: 0, False: 1]
  ------------------
   89|      0|		TRACE(("leave buf_get_ed25519_priv_key: failure"))
   90|      0|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
   91|      0|	}
   92|       |
   93|      1|	memcpy(key->priv, buf_getptr(buf, CURVE25519_LEN), CURVE25519_LEN);
  ------------------
  |  |   34|      1|#define CURVE25519_LEN 32
  ------------------
              	memcpy(key->priv, buf_getptr(buf, CURVE25519_LEN), CURVE25519_LEN);
  ------------------
  |  |   34|      1|#define CURVE25519_LEN 32
  ------------------
   94|      1|	buf_incrpos(buf, CURVE25519_LEN);
  ------------------
  |  |   34|      1|#define CURVE25519_LEN 32
  ------------------
   95|      1|	memcpy(key->pub, buf_getptr(buf, CURVE25519_LEN), CURVE25519_LEN);
  ------------------
  |  |   34|      1|#define CURVE25519_LEN 32
  ------------------
              	memcpy(key->pub, buf_getptr(buf, CURVE25519_LEN), CURVE25519_LEN);
  ------------------
  |  |   34|      1|#define CURVE25519_LEN 32
  ------------------
   96|      1|	buf_incrpos(buf, CURVE25519_LEN);
  ------------------
  |  |   34|      1|#define CURVE25519_LEN 32
  ------------------
   97|       |
   98|      1|	TRACE(("leave buf_get_ed25519_priv_key: success"))
   99|      1|	return DROPBEAR_SUCCESS;
  ------------------
  |  |  102|      1|#define DROPBEAR_SUCCESS 0
  ------------------
  100|      1|}
ed25519_key_free:
  103|      1|void ed25519_key_free(dropbear_ed25519_key *key) {
  104|       |
  105|      1|	TRACE2(("enter ed25519_key_free"))
  106|       |
  107|      1|	if (key == NULL) {
  ------------------
  |  Branch (107:6): [True: 1, False: 0]
  ------------------
  108|      1|		TRACE2(("leave ed25519_key_free: key == NULL"))
  109|      1|		return;
  110|      1|	}
  111|      0|	m_burn(key->priv, CURVE25519_LEN);
  ------------------
  |  |   34|      0|#define CURVE25519_LEN 32
  ------------------
  112|      0|	m_free(key);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  113|       |
  114|      0|	TRACE2(("leave ed25519_key_free"))
  115|      0|}
buf_put_ed25519_pub_key:
  118|  2.04k|void buf_put_ed25519_pub_key(buffer *buf, const dropbear_ed25519_key *key) {
  119|       |
  120|  2.04k|	TRACE(("enter buf_put_ed25519_pub_key"))
  121|  2.04k|	dropbear_assert(key != NULL);
  ------------------
  |  |   83|  2.04k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 2.04k]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
  122|       |
  123|  2.04k|	buf_putstring(buf, SSH_SIGNKEY_ED25519, SSH_SIGNKEY_ED25519_LEN);
  ------------------
  |  |  114|  2.04k|#define SSH_SIGNKEY_ED25519 "ssh-ed25519"
  ------------------
              	buf_putstring(buf, SSH_SIGNKEY_ED25519, SSH_SIGNKEY_ED25519_LEN);
  ------------------
  |  |  115|  2.04k|#define SSH_SIGNKEY_ED25519_LEN 11
  ------------------
  124|  2.04k|	buf_putstring(buf, key->pub, CURVE25519_LEN);
  ------------------
  |  |   34|  2.04k|#define CURVE25519_LEN 32
  ------------------
  125|       |
  126|  2.04k|	TRACE(("leave buf_put_ed25519_pub_key"))
  127|  2.04k|}
buf_put_ed25519_sign:
  145|  1.01k|void buf_put_ed25519_sign(buffer* buf, const dropbear_ed25519_key *key, const buffer *data_buf) {
  146|       |
  147|  1.01k|	unsigned char s[64];
  148|  1.01k|	unsigned long slen = sizeof(s);
  149|       |
  150|  1.01k|	TRACE(("enter buf_put_ed25519_sign"))
  151|  1.01k|	dropbear_assert(key != NULL);
  ------------------
  |  |   83|  1.01k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 1.01k]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
  152|       |
  153|  1.01k|	dropbear_ed25519_sign(data_buf->data, data_buf->len, s, &slen, key->priv, key->pub);
  154|  1.01k|	buf_putstring(buf, SSH_SIGNKEY_ED25519, SSH_SIGNKEY_ED25519_LEN);
  ------------------
  |  |  114|  1.01k|#define SSH_SIGNKEY_ED25519 "ssh-ed25519"
  ------------------
              	buf_putstring(buf, SSH_SIGNKEY_ED25519, SSH_SIGNKEY_ED25519_LEN);
  ------------------
  |  |  115|  1.01k|#define SSH_SIGNKEY_ED25519_LEN 11
  ------------------
  155|  1.01k|	buf_putstring(buf, s, slen);
  156|       |
  157|  1.01k|	TRACE(("leave buf_put_ed25519_sign"))
  158|  1.01k|}

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

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

remove_connect_pending:
  228|  3.96k|void remove_connect_pending() {
  229|  3.96k|	while (ses.conn_pending.first) {
  ------------------
  |  Branch (229:9): [True: 0, False: 3.96k]
  ------------------
  230|      0|		struct dropbear_progress_connection *c = ses.conn_pending.first->item;
  231|      0|		remove_connect(c, ses.conn_pending.first);
  232|      0|	}
  233|  3.96k|}
set_connect_fds:
  236|   412k|void set_connect_fds(fd_set *writefd) {
  237|   412k|	m_list_elem *iter;
  238|   412k|	iter = ses.conn_pending.first;
  239|   412k|	while (iter) {
  ------------------
  |  Branch (239:9): [True: 0, False: 412k]
  ------------------
  240|      0|		m_list_elem *next_iter = iter->next;
  241|      0|		struct dropbear_progress_connection *c = iter->item;
  242|       |		/* Set one going */
  243|      0|		while (c->res_iter && c->sock < 0) {
  ------------------
  |  Branch (243:10): [True: 0, False: 0]
  |  Branch (243:25): [True: 0, False: 0]
  ------------------
  244|      0|			connect_try_next(c);
  245|      0|		}
  246|      0|		if (c->sock >= 0) {
  ------------------
  |  Branch (246:7): [True: 0, False: 0]
  ------------------
  247|      0|			FD_SET(c->sock, writefd);
  248|      0|		} else {
  249|       |			/* Final failure */
  250|      0|			if (!c->errstring) {
  ------------------
  |  Branch (250:8): [True: 0, False: 0]
  ------------------
  251|      0|				c->errstring = m_strdup("unexpected failure");
  252|      0|			}
  253|      0|			c->cb(DROPBEAR_FAILURE, -1, c->cb_data, c->errstring);
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
  254|      0|			remove_connect(c, iter);
  255|      0|		}
  256|      0|		iter = next_iter;
  257|      0|	}
  258|   412k|}
handle_connect_fds:
  260|   408k|void handle_connect_fds(const fd_set *writefd) {
  261|   408k|	m_list_elem *iter;
  262|   408k|	for (iter = ses.conn_pending.first; iter; iter = iter->next) {
  ------------------
  |  Branch (262:38): [True: 0, False: 408k]
  ------------------
  263|      0|		int val;
  264|      0|		socklen_t vallen = sizeof(val);
  265|      0|		struct dropbear_progress_connection *c = iter->item;
  266|       |
  267|      0|		if (c->sock < 0 || !FD_ISSET(c->sock, writefd)) {
  ------------------
  |  Branch (267:7): [True: 0, False: 0]
  |  Branch (267:22): [True: 0, False: 0]
  ------------------
  268|      0|			continue;
  269|      0|		}
  270|       |
  271|      0|		TRACE(("handling %s port %s socket %d", c->remotehost, c->remoteport, c->sock));
  272|       |
  273|      0|		if (getsockopt(c->sock, SOL_SOCKET, SO_ERROR, &val, &vallen) != 0) {
  ------------------
  |  Branch (273:7): [True: 0, False: 0]
  ------------------
  274|      0|			TRACE(("handle_connect_fds getsockopt(%d) SO_ERROR failed: %s", c->sock, strerror(errno)))
  275|       |			/* This isn't expected to happen - Unix has surprises though, continue gracefully. */
  276|      0|			m_close(c->sock);
  277|      0|			c->sock = -1;
  278|      0|		} else if (val != 0) {
  ------------------
  |  Branch (278:14): [True: 0, False: 0]
  ------------------
  279|       |			/* Connect failed */
  280|      0|			TRACE(("connect to %s port %s failed.", c->remotehost, c->remoteport))
  281|      0|			m_close(c->sock);
  282|      0|			c->sock = -1;
  283|       |
  284|      0|			m_free(c->errstring);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  285|      0|			c->errstring = m_strdup(strerror(val));
  286|      0|		} else {
  287|       |			/* New connection has been established */
  288|      0|			c->cb(DROPBEAR_SUCCESS, c->sock, c->cb_data, NULL);
  ------------------
  |  |  102|      0|#define DROPBEAR_SUCCESS 0
  ------------------
  289|      0|			remove_connect(c, iter);
  290|      0|			TRACE(("leave handle_connect_fds - success"))
  291|       |			/* Must return here - remove_connect() invalidates iter */
  292|      0|			return; 
  293|      0|		}
  294|      0|	}
  295|   408k|}
packet_queue_to_iovec:
  301|  74.6k|void packet_queue_to_iovec(const struct Queue *queue, struct iovec *iov, unsigned int *iov_count) {
  302|  74.6k|	struct Link *l;
  303|  74.6k|	unsigned int i;
  304|  74.6k|	int len;
  305|  74.6k|	buffer *writebuf;
  306|       |
  307|       |#ifndef IOV_MAX
  308|       |	#if defined(__CYGWIN__) && !defined(UIO_MAXIOV)
  309|       |		#define IOV_MAX 1024
  310|       |	#elif defined(__sgi)
  311|       |		#define IOV_MAX 512 
  312|       |	#else 
  313|       |		#define IOV_MAX UIO_MAXIOV
  314|       |	#endif
  315|       |#endif
  316|       |
  317|  74.6k|	*iov_count = MIN(MIN(queue->count, IOV_MAX), *iov_count);
  318|       |
  319|   170k|	for (l = queue->head, i = 0; i < *iov_count; l = l->link, i++)
  ------------------
  |  Branch (319:31): [True: 96.0k, False: 74.6k]
  ------------------
  320|  96.0k|	{
  321|  96.0k|		writebuf = (buffer*)l->item;
  322|  96.0k|		len = writebuf->len - writebuf->pos;
  323|  96.0k|		dropbear_assert(len > 0);
  ------------------
  |  |   83|  96.0k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 96.0k]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
  324|  96.0k|		TRACE2(("write_packet writev #%d len %d/%d", i,
  325|  96.0k|				len, writebuf->len))
  326|  96.0k|		iov[i].iov_base = buf_getptr(writebuf, len);
  327|  96.0k|		iov[i].iov_len = len;
  328|  96.0k|	}
  329|  74.6k|}
packet_queue_consume:
  331|  74.6k|void packet_queue_consume(struct Queue *queue, ssize_t written) {
  332|  74.6k|	buffer *writebuf;
  333|  74.6k|	int len;
  334|   149k|	while (written > 0) {
  ------------------
  |  Branch (334:9): [True: 74.6k, False: 74.6k]
  ------------------
  335|  74.6k|		writebuf = (buffer*)examine(queue);
  336|  74.6k|		len = writebuf->len - writebuf->pos;
  337|  74.6k|		if (len > written) {
  ------------------
  |  Branch (337:7): [True: 0, False: 74.6k]
  ------------------
  338|       |			/* partial buffer write */
  339|      0|			buf_incrpos(writebuf, written);
  340|      0|			written = 0;
  341|  74.6k|		} else {
  342|  74.6k|			written -= len;
  343|  74.6k|			dequeue(queue);
  344|  74.6k|			buf_free(writebuf);
  345|  74.6k|		}
  346|  74.6k|	}
  347|  74.6k|}
set_sock_priority:
  367|  3.96k|void set_sock_priority(int sock, enum dropbear_prio prio) {
  368|       |
  369|  3.96k|	int rc;
  370|  3.96k|	int val;
  371|       |
  372|  3.96k|#if DROPBEAR_FUZZ
  373|  3.96k|	if (fuzz.fuzzing) {
  ------------------
  |  Branch (373:6): [True: 3.96k, False: 0]
  ------------------
  374|  3.96k|		TRACE(("fuzzing skips set_sock_prio"))
  375|  3.96k|		return;
  376|  3.96k|	}
  377|      0|#endif
  378|       |	/* Don't log ENOTSOCK errors so that this can harmlessly be called
  379|       |	 * on a client '-J' proxy pipe */
  380|       |
  381|      0|	if (opts.disable_ip_tos == 0) {
  ------------------
  |  Branch (381:6): [True: 0, False: 0]
  ------------------
  382|      0|#ifdef IP_TOS
  383|       |	/* Set the DSCP field for outbound IP packet priority.
  384|       |	rfc4594 has some guidance to meanings.
  385|       |
  386|       |	We set AF21 as "Low-Latency" class for interactive (tty session,
  387|       |	also handshake/setup packets). Other traffic is left at the default.
  388|       |
  389|       |	OpenSSH at present uses AF21/CS1, rationale
  390|       |	https://cvsweb.openbsd.org/src/usr.bin/ssh/readconf.c#rev1.284
  391|       |
  392|       |	Old Dropbear/OpenSSH and Debian/Ubuntu OpenSSH (at Jan 2022) use
  393|       |	IPTOS_LOWDELAY/IPTOS_THROUGHPUT
  394|       |
  395|       |	DSCP constants are from Linux headers, applicable to other platforms
  396|       |	such as macos.
  397|       |	*/
  398|      0|	if (prio == DROPBEAR_PRIO_LOWDELAY) {
  ------------------
  |  Branch (398:6): [True: 0, False: 0]
  ------------------
  399|      0|		val = 0x48; /* IPTOS_DSCP_AF21 */
  400|      0|	} else {
  401|      0|		val = 0; /* default */
  402|      0|	}
  403|      0|#if defined(IPPROTO_IPV6) && defined(IPV6_TCLASS)
  404|      0|	rc = setsockopt(sock, IPPROTO_IPV6, IPV6_TCLASS, (void*)&val, sizeof(val));
  405|      0|	if (rc < 0 && errno != ENOTSOCK) {
  ------------------
  |  Branch (405:6): [True: 0, False: 0]
  |  Branch (405:16): [True: 0, False: 0]
  ------------------
  406|      0|		TRACE(("Couldn't set IPV6_TCLASS (%s)", strerror(errno)));
  407|      0|	}
  408|      0|#endif
  409|      0|	rc = setsockopt(sock, IPPROTO_IP, IP_TOS, (void*)&val, sizeof(val));
  410|      0|	if (rc < 0 && errno != ENOTSOCK) {
  ------------------
  |  Branch (410:6): [True: 0, False: 0]
  |  Branch (410:16): [True: 0, False: 0]
  ------------------
  411|      0|		TRACE(("Couldn't set IP_TOS (%s)", strerror(errno)));
  412|      0|	}
  413|      0|#endif /* IP_TOS */
  414|      0|	}
  415|       |
  416|      0|#ifdef HAVE_LINUX_PKT_SCHED_H
  417|       |	/* Set scheduling priority within the local Linux network stack */
  418|      0|	if (prio == DROPBEAR_PRIO_LOWDELAY) {
  ------------------
  |  Branch (418:6): [True: 0, False: 0]
  ------------------
  419|      0|		val = TC_PRIO_INTERACTIVE;
  420|      0|	} else {
  421|      0|		val = 0;
  422|      0|	}
  423|       |	/* linux specific, sets QoS class. see tc-prio(8) */
  424|      0|	rc = setsockopt(sock, SOL_SOCKET, SO_PRIORITY, (void*) &val, sizeof(val));
  425|      0|	if (rc < 0 && errno != ENOTSOCK) {
  ------------------
  |  Branch (425:6): [True: 0, False: 0]
  |  Branch (425:16): [True: 0, False: 0]
  ------------------
  426|      0|		TRACE(("Couldn't set SO_PRIORITY (%s)", strerror(errno)))
  427|      0|    }
  428|      0|#endif
  429|       |
  430|      0|}
get_socket_address:
  620|  7.93k|{
  621|  7.93k|	struct sockaddr_storage addr;
  622|  7.93k|	socklen_t addrlen;
  623|       |
  624|  7.93k|#if DROPBEAR_FUZZ
  625|  7.93k|	if (fuzz.fuzzing) {
  ------------------
  |  Branch (625:6): [True: 7.93k, False: 0]
  ------------------
  626|  7.93k|		fuzz_get_socket_address(fd, local_host, local_port, remote_host, remote_port, host_lookup);
  627|  7.93k|		return;
  628|  7.93k|	}
  629|      0|#endif
  630|       |	
  631|      0|	if (local_host || local_port) {
  ------------------
  |  Branch (631:6): [True: 0, False: 0]
  |  Branch (631:20): [True: 0, False: 0]
  ------------------
  632|      0|		addrlen = sizeof(addr);
  633|      0|		if (getsockname(fd, (struct sockaddr*)&addr, &addrlen) < 0) {
  ------------------
  |  Branch (633:7): [True: 0, False: 0]
  ------------------
  634|      0|			dropbear_exit("Failed socket address: %s", strerror(errno));
  635|      0|		}
  636|      0|		getaddrstring(&addr, local_host, local_port, host_lookup);		
  637|      0|	}
  638|      0|	if (remote_host || remote_port) {
  ------------------
  |  Branch (638:6): [True: 0, False: 0]
  |  Branch (638:21): [True: 0, False: 0]
  ------------------
  639|      0|		addrlen = sizeof(addr);
  640|      0|		if (getpeername(fd, (struct sockaddr*)&addr, &addrlen) < 0) {
  ------------------
  |  Branch (640:7): [True: 0, False: 0]
  ------------------
  641|      0|			dropbear_exit("Failed socket address: %s", strerror(errno));
  642|      0|		}
  643|      0|		getaddrstring(&addr, remote_host, remote_port, host_lookup);		
  644|      0|	}
  645|      0|}

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

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

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

buf_get_rsa_pub_key:
   53|      1|int buf_get_rsa_pub_key(buffer* buf, dropbear_rsa_key *key) {
   54|       |
   55|      1|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
   56|      1|	TRACE(("enter buf_get_rsa_pub_key"))
   57|      1|	dropbear_assert(key != NULL);
  ------------------
  |  |   83|      1|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 1]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
   58|      1|	m_mp_alloc_init_multi(&key->e, &key->n, NULL);
   59|      1|	key->d = NULL;
   60|      1|	key->p = NULL;
   61|      1|	key->q = NULL;
   62|       |
   63|      1|	buf_incrpos(buf, 4+SSH_SIGNKEY_RSA_LEN); /* int + "ssh-rsa" */
  ------------------
  |  |  113|      1|#define SSH_SIGNKEY_RSA_LEN 7
  ------------------
   64|       |
   65|      1|	if (buf_getmpint(buf, key->e) == DROPBEAR_FAILURE
  ------------------
  |  |  103|      2|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (65:6): [True: 0, False: 1]
  ------------------
   66|      1|	 || buf_getmpint(buf, key->n) == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (66:6): [True: 0, False: 1]
  ------------------
   67|      0|		TRACE(("leave buf_get_rsa_pub_key: failure"))
   68|      0|		goto out;
   69|      0|	}
   70|       |
   71|      1|	if (mp_count_bits(key->n) < MIN_RSA_KEYLEN) {
  ------------------
  |  |   65|      1|#define MIN_RSA_KEYLEN 1024
  ------------------
  |  Branch (71:6): [True: 0, False: 1]
  ------------------
   72|      0|		dropbear_log(LOG_WARNING, "RSA key too short");
   73|      0|		goto out;
   74|      0|	}
   75|       |
   76|       |	/* 64 bit is limit used by openssl, so we won't block any keys in the wild */
   77|      1|	if (mp_count_bits(key->e) > 64) {
  ------------------
  |  Branch (77:6): [True: 0, False: 1]
  ------------------
   78|      0|		dropbear_log(LOG_WARNING, "RSA key bad e");
   79|      0|		goto out;
   80|      0|	}
   81|       |
   82|      1|	TRACE(("leave buf_get_rsa_pub_key: success"))
   83|      1|	ret = DROPBEAR_SUCCESS;
  ------------------
  |  |  102|      1|#define DROPBEAR_SUCCESS 0
  ------------------
   84|      1|out:
   85|      1|	if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (85:6): [True: 0, False: 1]
  ------------------
   86|      0|		m_mp_free_multi(&key->e, &key->n, NULL);
   87|      0|	}
   88|      1|	return ret;
   89|      1|}
buf_get_rsa_priv_key:
   94|      1|int buf_get_rsa_priv_key(buffer* buf, dropbear_rsa_key *key) {
   95|      1|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
   96|       |
   97|      1|	TRACE(("enter buf_get_rsa_priv_key"))
   98|      1|	dropbear_assert(key != NULL);
  ------------------
  |  |   83|      1|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 1]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
   99|       |
  100|      1|	if (buf_get_rsa_pub_key(buf, key) == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (100:6): [True: 0, False: 1]
  ------------------
  101|      0|		TRACE(("leave buf_get_rsa_priv_key: pub: ret == DROPBEAR_FAILURE"))
  102|      0|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
  103|      0|	}
  104|       |	
  105|      1|	key->d = NULL;
  106|      1|	key->p = NULL;
  107|      1|	key->q = NULL;
  108|       |
  109|      1|	m_mp_alloc_init_multi(&key->d, NULL);
  110|      1|	if (buf_getmpint(buf, key->d) == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (110:6): [True: 0, False: 1]
  ------------------
  111|      0|		TRACE(("leave buf_get_rsa_priv_key: d: ret == DROPBEAR_FAILURE"))
  112|      0|		goto out;
  113|      0|	}
  114|       |
  115|      1|	if (buf->pos == buf->len) {
  ------------------
  |  Branch (115:6): [True: 0, False: 1]
  ------------------
  116|       |		/* old Dropbear private keys didn't keep p and q, so we will ignore them*/
  117|      1|	} else {
  118|      1|		m_mp_alloc_init_multi(&key->p, &key->q, NULL);
  119|       |
  120|      1|		if (buf_getmpint(buf, key->p) == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (120:7): [True: 0, False: 1]
  ------------------
  121|      0|			TRACE(("leave buf_get_rsa_priv_key: p: ret == DROPBEAR_FAILURE"))
  122|      0|			goto out;
  123|      0|		}
  124|       |
  125|      1|		if (buf_getmpint(buf, key->q) == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (125:7): [True: 0, False: 1]
  ------------------
  126|      0|			TRACE(("leave buf_get_rsa_priv_key: q: ret == DROPBEAR_FAILURE"))
  127|      0|			goto out;
  128|      0|		}
  129|      1|	}
  130|       |
  131|      1|	ret = DROPBEAR_SUCCESS;
  ------------------
  |  |  102|      1|#define DROPBEAR_SUCCESS 0
  ------------------
  132|      1|out:
  133|      1|	if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (133:6): [True: 0, False: 1]
  ------------------
  134|      0|		m_mp_free_multi(&key->d, &key->p, &key->q, NULL);
  135|      0|	}
  136|      1|	TRACE(("leave buf_get_rsa_priv_key"))
  137|      1|	return ret;
  138|      1|}
rsa_key_free:
  142|      1|void rsa_key_free(dropbear_rsa_key *key) {
  143|       |
  144|      1|	TRACE2(("enter rsa_key_free"))
  145|       |
  146|      1|	if (key == NULL) {
  ------------------
  |  Branch (146:6): [True: 1, False: 0]
  ------------------
  147|      1|		TRACE2(("leave rsa_key_free: key == NULL"))
  148|      1|		return;
  149|      1|	}
  150|      0|	m_mp_free_multi(&key->d, &key->e, &key->p, &key->q, &key->n, NULL);
  151|      0|	m_free(key);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  152|      0|	TRACE2(("leave rsa_key_free"))
  153|      0|}
buf_put_rsa_pub_key:
  161|  8.21k|void buf_put_rsa_pub_key(buffer* buf, const dropbear_rsa_key *key) {
  162|       |
  163|  8.21k|	TRACE(("enter buf_put_rsa_pub_key"))
  164|  8.21k|	dropbear_assert(key != NULL);
  ------------------
  |  |   83|  8.21k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 8.21k]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
  165|       |
  166|  8.21k|	buf_putstring(buf, SSH_SIGNKEY_RSA, SSH_SIGNKEY_RSA_LEN);
  ------------------
  |  |  112|  8.21k|#define SSH_SIGNKEY_RSA "ssh-rsa"
  ------------------
              	buf_putstring(buf, SSH_SIGNKEY_RSA, SSH_SIGNKEY_RSA_LEN);
  ------------------
  |  |  113|  8.21k|#define SSH_SIGNKEY_RSA_LEN 7
  ------------------
  167|  8.21k|	buf_putmpint(buf, key->e);
  168|  8.21k|	buf_putmpint(buf, key->n);
  169|       |
  170|  8.21k|	TRACE(("leave buf_put_rsa_pub_key"))
  171|       |
  172|  8.21k|}
buf_put_rsa_sign:
  256|  3.94k|		enum signature_type sigtype, const buffer *data_buf) {
  257|  3.94k|	const char *name = NULL;
  258|  3.94k|	unsigned int nsize, ssize, namelen = 0;
  259|  3.94k|	unsigned int i;
  260|  3.94k|	size_t written;
  261|  3.94k|	DEF_MP_INT(rsa_s);
  ------------------
  |  |   80|  3.94k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  262|  3.94k|	DEF_MP_INT(rsa_tmp1);
  ------------------
  |  |   80|  3.94k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  263|  3.94k|	DEF_MP_INT(rsa_tmp2);
  ------------------
  |  |   80|  3.94k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  264|  3.94k|	DEF_MP_INT(rsa_tmp3);
  ------------------
  |  |   80|  3.94k|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  265|       |	
  266|  3.94k|	TRACE(("enter buf_put_rsa_sign"))
  267|  3.94k|	dropbear_assert(key != NULL);
  ------------------
  |  |   83|  3.94k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 3.94k]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
  268|       |
  269|  3.94k|	m_mp_init_multi(&rsa_s, &rsa_tmp1, &rsa_tmp2, &rsa_tmp3, NULL);
  270|       |
  271|  3.94k|	rsa_pad_em(key, data_buf, &rsa_tmp1, sigtype);
  272|       |
  273|       |	/* the actual signing of the padded data */
  274|       |
  275|  3.94k|#if DROPBEAR_RSA_BLINDING
  276|       |
  277|       |	/* With blinding, s = (r^(-1))((em)*r^e)^d mod n */
  278|       |
  279|       |	/* generate the r blinding value */
  280|       |	/* rsa_tmp2 is r */
  281|  3.94k|	gen_random_mpint(key->n, &rsa_tmp2);
  282|       |
  283|       |	/* rsa_tmp1 is em */
  284|       |	/* em' = em * r^e mod n */
  285|       |
  286|       |	/* rsa_s used as a temp var*/
  287|  3.94k|	if (mp_exptmod(&rsa_tmp2, key->e, key->n, &rsa_s) != MP_OKAY) {
  ------------------
  |  |  161|  3.94k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (287:6): [True: 0, False: 3.94k]
  ------------------
  288|      0|		dropbear_exit("RSA error");
  289|      0|	}
  290|  3.94k|	if (mp_invmod(&rsa_tmp2, key->n, &rsa_tmp3) != MP_OKAY) {
  ------------------
  |  |  161|  3.94k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (290:6): [True: 0, False: 3.94k]
  ------------------
  291|      0|		dropbear_exit("RSA error");
  292|      0|	}
  293|  3.94k|	if (mp_mulmod(&rsa_tmp1, &rsa_s, key->n, &rsa_tmp2) != MP_OKAY) {
  ------------------
  |  |  161|  3.94k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (293:6): [True: 0, False: 3.94k]
  ------------------
  294|      0|		dropbear_exit("RSA error");
  295|      0|	}
  296|       |
  297|       |	/* rsa_tmp2 is em' */
  298|       |	/* s' = (em')^d mod n */
  299|  3.94k|	if (mp_exptmod(&rsa_tmp2, key->d, key->n, &rsa_tmp1) != MP_OKAY) {
  ------------------
  |  |  161|  3.94k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (299:6): [True: 0, False: 3.94k]
  ------------------
  300|      0|		dropbear_exit("RSA error");
  301|      0|	}
  302|       |
  303|       |	/* rsa_tmp1 is s' */
  304|       |	/* rsa_tmp3 is r^(-1) mod n */
  305|       |	/* s = (s')r^(-1) mod n */
  306|  3.94k|	if (mp_mulmod(&rsa_tmp1, &rsa_tmp3, key->n, &rsa_s) != MP_OKAY) {
  ------------------
  |  |  161|  3.94k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (306:6): [True: 0, False: 3.94k]
  ------------------
  307|      0|		dropbear_exit("RSA error");
  308|      0|	}
  309|       |
  310|       |#else
  311|       |
  312|       |	/* s = em^d mod n */
  313|       |	/* rsa_tmp1 is em */
  314|       |	if (mp_exptmod(&rsa_tmp1, key->d, key->n, &rsa_s) != MP_OKAY) {
  315|       |		dropbear_exit("RSA error");
  316|       |	}
  317|       |
  318|       |#endif /* DROPBEAR_RSA_BLINDING */
  319|       |
  320|  3.94k|	mp_clear_multi(&rsa_tmp1, &rsa_tmp2, &rsa_tmp3, NULL);
  321|       |	
  322|       |	/* create the signature to return */
  323|  3.94k|	name = signature_name_from_type(sigtype, &namelen);
  324|  3.94k|	buf_putstring(buf, name, namelen);
  325|       |
  326|  3.94k|	nsize = mp_ubin_size(key->n);
  327|       |
  328|       |	/* string rsa_signature_blob length */
  329|  3.94k|	buf_putint(buf, nsize);
  330|       |	/* pad out s to same length as n */
  331|  3.94k|	ssize = mp_ubin_size(&rsa_s);
  332|  3.94k|	dropbear_assert(ssize <= nsize);
  ------------------
  |  |   83|  3.94k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 3.94k]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
  333|  3.98k|	for (i = 0; i < nsize-ssize; i++) {
  ------------------
  |  Branch (333:14): [True: 43, False: 3.94k]
  ------------------
  334|     43|		buf_putbyte(buf, 0x00);
  335|     43|	}
  336|       |
  337|  3.94k|	if (mp_to_ubin(&rsa_s, buf_getwriteptr(buf, ssize), ssize, &written) != MP_OKAY) {
  ------------------
  |  |  161|  3.94k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (337:6): [True: 0, False: 3.94k]
  ------------------
  338|      0|		dropbear_exit("RSA error");
  339|      0|	}
  340|  3.94k|	buf_incrwritepos(buf, written);
  341|  3.94k|	mp_clear(&rsa_s);
  342|       |
  343|       |#if defined(DEBUG_RSA) && DEBUG_TRACE
  344|       |	if (!debug_trace) {
  345|       |		printhex("RSA sig", buf->data, buf->len);
  346|       |	}
  347|       |#endif
  348|       |	
  349|       |
  350|  3.94k|	TRACE(("leave buf_put_rsa_sign"))
  351|  3.94k|}
rsa.c:rsa_pad_em:
  356|  3.94k|	const buffer *data_buf, mp_int * rsa_em, enum signature_type sigtype) {
  357|       |    /* EM = 0x00 || 0x01 || PS || 0x00 || T 
  358|       |	   PS is padding of 0xff to make EM the size of key->n
  359|       |
  360|       |	   T is the DER encoding of the hash alg (sha1 or sha256)
  361|       |	*/
  362|       |
  363|       |	/* From rfc8017 page 46 */
  364|  3.94k|#if DROPBEAR_RSA_SHA1
  365|  3.94k|	const unsigned char T_sha1[] =
  366|  3.94k|		{0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b,
  367|  3.94k|		 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14};
  368|  3.94k|#endif
  369|  3.94k|#if DROPBEAR_RSA_SHA256
  370|  3.94k|	const unsigned char T_sha256[] =
  371|  3.94k|		{0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01,
  372|  3.94k|		 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20};
  373|  3.94k|#endif
  374|       |
  375|  3.94k|    int Tlen = 0;
  376|  3.94k|    const unsigned char *T = NULL;
  377|  3.94k|	const struct ltc_hash_descriptor *hash_desc = NULL;
  378|  3.94k|	buffer * rsa_EM = NULL;
  379|  3.94k|	hash_state hs;
  380|  3.94k|	unsigned int nsize;
  381|       |
  382|  3.94k|	switch (sigtype) {
  383|      0|#if DROPBEAR_RSA_SHA1
  384|  3.41k|		case DROPBEAR_SIGNATURE_RSA_SHA1:
  ------------------
  |  Branch (384:3): [True: 3.41k, False: 527]
  ------------------
  385|  3.41k|			Tlen = sizeof(T_sha1);
  386|  3.41k|			T = T_sha1;
  387|  3.41k|			hash_desc = &sha1_desc;
  388|  3.41k|			break;
  389|      0|#endif
  390|      0|#if DROPBEAR_RSA_SHA256
  391|    527|		case DROPBEAR_SIGNATURE_RSA_SHA256:
  ------------------
  |  Branch (391:3): [True: 527, False: 3.41k]
  ------------------
  392|    527|			Tlen = sizeof(T_sha256);
  393|    527|			T = T_sha256;
  394|    527|			hash_desc = &sha256_desc;
  395|    527|			break;
  396|      0|#endif
  397|      0|		default:
  ------------------
  |  Branch (397:3): [True: 0, False: 3.94k]
  ------------------
  398|      0|			assert(0);
  399|  3.94k|	}
  400|       |	
  401|       |
  402|  3.94k|	nsize = mp_ubin_size(key->n);
  403|       |
  404|  3.94k|	rsa_EM = buf_new(nsize);
  405|       |	/* type byte */
  406|  3.94k|	buf_putbyte(rsa_EM, 0x00);
  407|  3.94k|	buf_putbyte(rsa_EM, 0x01);
  408|       |	/* Padding with PS 0xFF bytes */
  409|   855k|	while(rsa_EM->pos != rsa_EM->size - (1 + Tlen + hash_desc->hashsize)) {
  ------------------
  |  Branch (409:8): [True: 851k, False: 3.94k]
  ------------------
  410|   851k|		buf_putbyte(rsa_EM, 0xff);
  411|   851k|	}
  412|  3.94k|	buf_putbyte(rsa_EM, 0x00);
  413|       |	/* Magic ASN1 stuff */
  414|  3.94k|	buf_putbytes(rsa_EM, T, Tlen);
  415|       |
  416|       |	/* The hash of the data */
  417|  3.94k|	hash_desc->init(&hs);
  418|  3.94k|	hash_desc->process(&hs, data_buf->data, data_buf->len);
  419|  3.94k|	hash_desc->done(&hs, buf_getwriteptr(rsa_EM, hash_desc->hashsize));
  420|  3.94k|	buf_incrwritepos(rsa_EM, hash_desc->hashsize);
  421|       |
  422|  3.94k|	dropbear_assert(rsa_EM->pos == rsa_EM->size);
  ------------------
  |  |   83|  3.94k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 3.94k]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
  423|       |
  424|       |	/* Create the mp_int from the encoded bytes */
  425|  3.94k|	buf_setpos(rsa_EM, 0);
  426|  3.94k|	bytes_to_mp(rsa_em, buf_getptr(rsa_EM, rsa_EM->size),
  427|  3.94k|			rsa_EM->size);
  428|  3.94k|	buf_free(rsa_EM);
  429|  3.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|    563|enum signkey_type signkey_type_from_name(const char* name, unsigned int namelen) {
   87|    563|	int i;
   88|  5.04k|	for (i = 0; i < DROPBEAR_SIGNKEY_NUM_NAMED; i++) {
  ------------------
  |  Branch (88:14): [True: 4.48k, False: 559]
  ------------------
   89|  4.48k|		const char *fixed_name = signkey_names[i];
   90|  4.48k|		if (namelen == strlen(fixed_name)
  ------------------
  |  Branch (90:7): [True: 5, False: 4.48k]
  ------------------
   91|  4.48k|			&& memcmp(fixed_name, name, namelen) == 0) {
  ------------------
  |  Branch (91:7): [True: 4, False: 1]
  ------------------
   92|       |
   93|      4|#if DROPBEAR_ECDSA
   94|       |			/* Some of the ECDSA key sizes are defined even if they're not compiled in */
   95|      4|			if (0
  ------------------
  |  Branch (95:8): [Folded - Ignored]
  ------------------
   96|       |#if !DROPBEAR_ECC_256
   97|       |				|| i == DROPBEAR_SIGNKEY_ECDSA_NISTP256
   98|       |#endif
   99|       |#if !DROPBEAR_ECC_384
  100|       |				|| i == DROPBEAR_SIGNKEY_ECDSA_NISTP384
  101|       |#endif
  102|       |#if !DROPBEAR_ECC_521
  103|       |				|| i == DROPBEAR_SIGNKEY_ECDSA_NISTP521
  104|       |#endif
  105|      4|				) {
  106|      0|				TRACE(("attempt to use ecdsa type %d not compiled in", i))
  107|      0|				return DROPBEAR_SIGNKEY_NONE;
  108|      0|			}
  109|      4|#endif
  110|       |
  111|      4|			return (enum signkey_type)i;
  112|      4|		}
  113|  4.48k|	}
  114|       |
  115|    559|	TRACE(("signkey_type_from_name unexpected key type."))
  116|       |
  117|    559|	return DROPBEAR_SIGNKEY_NONE;
  118|    563|}
signature_name_from_type:
  122|  3.94k|const char* signature_name_from_type(enum signature_type type, unsigned int *namelen) {
  123|  3.94k|#if DROPBEAR_RSA
  124|  3.94k|#if DROPBEAR_RSA_SHA256
  125|  3.94k|	if (type == DROPBEAR_SIGNATURE_RSA_SHA256) {
  ------------------
  |  Branch (125:6): [True: 527, False: 3.41k]
  ------------------
  126|    527|		if (namelen) {
  ------------------
  |  Branch (126:7): [True: 527, False: 0]
  ------------------
  127|    527|			*namelen = strlen(SSH_SIGNATURE_RSA_SHA256);
  ------------------
  |  |  117|    527|#define SSH_SIGNATURE_RSA_SHA256 "rsa-sha2-256"
  ------------------
  128|    527|		}
  129|    527|		return SSH_SIGNATURE_RSA_SHA256;
  ------------------
  |  |  117|    527|#define SSH_SIGNATURE_RSA_SHA256 "rsa-sha2-256"
  ------------------
  130|    527|	}
  131|  3.41k|#endif
  132|  3.41k|#if DROPBEAR_RSA_SHA1
  133|  3.41k|	if (type == DROPBEAR_SIGNATURE_RSA_SHA1) {
  ------------------
  |  Branch (133:6): [True: 3.41k, False: 0]
  ------------------
  134|  3.41k|		if (namelen) {
  ------------------
  |  Branch (134:7): [True: 3.41k, False: 0]
  ------------------
  135|  3.41k|			*namelen = strlen(SSH_SIGNKEY_RSA);
  ------------------
  |  |  112|  3.41k|#define SSH_SIGNKEY_RSA "ssh-rsa"
  ------------------
  136|  3.41k|		}
  137|  3.41k|		return SSH_SIGNKEY_RSA;
  ------------------
  |  |  112|  3.41k|#define SSH_SIGNKEY_RSA "ssh-rsa"
  ------------------
  138|  3.41k|	}
  139|      0|#endif
  140|      0|#endif /* DROPBEAR_RSA */
  141|      0|	return signkey_name_from_type((enum signkey_type)type, namelen);
  142|  3.41k|}
signature_type_from_name:
  145|    559|enum signature_type signature_type_from_name(const char* name, unsigned int namelen) {
  146|    559|#if DROPBEAR_RSA
  147|    559|#if DROPBEAR_RSA_SHA256
  148|    559|	if (namelen == strlen(SSH_SIGNATURE_RSA_SHA256) 
  ------------------
  |  |  117|    559|#define SSH_SIGNATURE_RSA_SHA256 "rsa-sha2-256"
  ------------------
  |  Branch (148:6): [True: 559, False: 0]
  ------------------
  149|    559|		&& memcmp(name, SSH_SIGNATURE_RSA_SHA256, namelen) == 0) {
  ------------------
  |  |  117|    559|#define SSH_SIGNATURE_RSA_SHA256 "rsa-sha2-256"
  ------------------
  |  Branch (149:6): [True: 0, False: 559]
  ------------------
  150|      0|		return DROPBEAR_SIGNATURE_RSA_SHA256;
  151|      0|	}
  152|    559|#endif
  153|    559|#if DROPBEAR_RSA_SHA1
  154|    559|	if (namelen == strlen(SSH_SIGNKEY_RSA) 
  ------------------
  |  |  112|    559|#define SSH_SIGNKEY_RSA "ssh-rsa"
  ------------------
  |  Branch (154:6): [True: 0, False: 559]
  ------------------
  155|    559|		&& memcmp(name, SSH_SIGNKEY_RSA, namelen) == 0) {
  ------------------
  |  |  112|      0|#define SSH_SIGNKEY_RSA "ssh-rsa"
  ------------------
  |  Branch (155:6): [True: 0, False: 0]
  ------------------
  156|      0|		return DROPBEAR_SIGNATURE_RSA_SHA1;
  157|      0|	}
  158|    559|#endif
  159|    559|#endif /* DROPBEAR_RSA */
  160|    559|	return (enum signature_type)signkey_type_from_name(name, namelen);
  161|    559|}
signkey_type_from_signature:
  173|  35.5k|enum signkey_type signkey_type_from_signature(enum signature_type sigtype) {
  174|  35.5k|#if DROPBEAR_RSA
  175|  35.5k|#if DROPBEAR_RSA_SHA256
  176|  35.5k|	if (sigtype == DROPBEAR_SIGNATURE_RSA_SHA256) {
  ------------------
  |  Branch (176:6): [True: 1.06k, False: 34.4k]
  ------------------
  177|  1.06k|		return DROPBEAR_SIGNKEY_RSA;
  178|  1.06k|	}
  179|  34.4k|#endif
  180|  34.4k|#if DROPBEAR_RSA_SHA1
  181|  34.4k|	if (sigtype == DROPBEAR_SIGNATURE_RSA_SHA1) {
  ------------------
  |  Branch (181:6): [True: 7.40k, False: 27.0k]
  ------------------
  182|  7.40k|		return DROPBEAR_SIGNKEY_RSA;
  183|  7.40k|	}
  184|  27.0k|#endif
  185|  27.0k|#endif /* DROPBEAR_RSA */
  186|  27.0k|	assert((int)sigtype < (int)DROPBEAR_SIGNKEY_NUM_NAMED);
  187|  27.0k|	return (enum signkey_type)sigtype;
  188|  27.0k|}
signkey_key_ptr:
  193|  9.56k|signkey_key_ptr(sign_key *key, enum signkey_type type) {
  194|  9.56k|	switch (type) {
  195|      0|#if DROPBEAR_ED25519
  196|      0|		case DROPBEAR_SIGNKEY_ED25519:
  ------------------
  |  Branch (196:3): [True: 0, False: 9.56k]
  ------------------
  197|      0|#if DROPBEAR_SK_ED25519
  198|      0|		case DROPBEAR_SIGNKEY_SK_ED25519:
  ------------------
  |  Branch (198:3): [True: 0, False: 9.56k]
  ------------------
  199|      0|#endif
  200|      0|			return (void**)&key->ed25519key;
  201|      0|#endif
  202|      0|#if DROPBEAR_ECDSA
  203|      0|#if DROPBEAR_ECC_256
  204|  9.56k|		case DROPBEAR_SIGNKEY_ECDSA_NISTP256:
  ------------------
  |  Branch (204:3): [True: 9.56k, False: 2]
  ------------------
  205|  9.56k|#if DROPBEAR_SK_ECDSA
  206|  9.56k|		case DROPBEAR_SIGNKEY_SK_ECDSA_NISTP256:
  ------------------
  |  Branch (206:3): [True: 0, False: 9.56k]
  ------------------
  207|  9.56k|#endif
  208|  9.56k|			return (void**)&key->ecckey256;
  209|      0|#endif
  210|      0|#if DROPBEAR_ECC_384
  211|      1|		case DROPBEAR_SIGNKEY_ECDSA_NISTP384:
  ------------------
  |  Branch (211:3): [True: 1, False: 9.56k]
  ------------------
  212|      1|			return (void**)&key->ecckey384;
  213|      0|#endif
  214|      0|#if DROPBEAR_ECC_521
  215|      1|		case DROPBEAR_SIGNKEY_ECDSA_NISTP521:
  ------------------
  |  Branch (215:3): [True: 1, False: 9.56k]
  ------------------
  216|      1|			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: 9.56k]
  ------------------
  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: 9.56k]
  ------------------
  225|      0|			return (void**)&key->dsskey;
  226|      0|#endif
  227|      0|		default:
  ------------------
  |  Branch (227:3): [True: 0, False: 9.56k]
  ------------------
  228|      0|			return NULL;
  229|  9.56k|	}
  230|  9.56k|}
buf_get_priv_key:
  339|      4|int buf_get_priv_key(buffer *buf, sign_key *key, enum signkey_type *type) {
  340|       |
  341|      4|	char *ident;
  342|      4|	unsigned int len;
  343|      4|	enum signkey_type keytype;
  344|      4|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  103|      4|#define DROPBEAR_FAILURE -1
  ------------------
  345|       |
  346|      4|	TRACE2(("enter buf_get_priv_key"))
  347|       |
  348|      4|	ident = buf_getstring(buf, &len);
  349|      4|	keytype = signkey_type_from_name(ident, len);
  350|      4|	m_free(ident);
  ------------------
  |  |   24|      4|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  351|       |
  352|      4|	if (*type != DROPBEAR_SIGNKEY_ANY && *type != keytype) {
  ------------------
  |  Branch (352:6): [True: 4, False: 0]
  |  Branch (352:39): [True: 0, False: 4]
  ------------------
  353|      0|		TRACE(("wrong key type: %d %d", *type, keytype))
  354|      0|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
  355|      0|	}
  356|       |
  357|      4|	*type = keytype;
  358|       |
  359|       |	/* Rewind the buffer back before "ssh-rsa" etc */
  360|      4|	buf_decrpos(buf, len + 4);
  361|       |
  362|      4|#if DROPBEAR_DSS
  363|      4|	if (keytype == DROPBEAR_SIGNKEY_DSS) {
  ------------------
  |  Branch (363:6): [True: 1, False: 3]
  ------------------
  364|      1|		dss_key_free(key->dsskey);
  365|      1|		key->dsskey = m_malloc(sizeof(*key->dsskey));
  366|      1|		ret = buf_get_dss_priv_key(buf, key->dsskey);
  367|      1|		if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (367:7): [True: 0, False: 1]
  ------------------
  368|      0|			dss_key_free(key->dsskey);
  369|      0|			key->dsskey = NULL;
  370|      0|		}
  371|      1|	}
  372|      4|#endif
  373|      4|#if DROPBEAR_RSA
  374|      4|	if (keytype == DROPBEAR_SIGNKEY_RSA) {
  ------------------
  |  Branch (374:6): [True: 1, False: 3]
  ------------------
  375|      1|		rsa_key_free(key->rsakey);
  376|      1|		key->rsakey = m_malloc(sizeof(*key->rsakey));
  377|      1|		ret = buf_get_rsa_priv_key(buf, key->rsakey);
  378|      1|		if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (378:7): [True: 0, False: 1]
  ------------------
  379|      0|			rsa_key_free(key->rsakey);
  380|      0|			key->rsakey = NULL;
  381|      0|		}
  382|      1|	}
  383|      4|#endif
  384|      4|#if DROPBEAR_ECDSA
  385|      4|	if (signkey_is_ecdsa(keytype)) {
  ------------------
  |  Branch (385:6): [True: 1, False: 3]
  ------------------
  386|      1|		ecc_key **eck = (ecc_key**)signkey_key_ptr(key, keytype);
  387|      1|		if (eck) {
  ------------------
  |  Branch (387:7): [True: 1, False: 0]
  ------------------
  388|      1|			if (*eck) {
  ------------------
  |  Branch (388:8): [True: 0, False: 1]
  ------------------
  389|      0|				ecc_free(*eck);
  390|      0|				m_free(*eck);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  391|      0|				*eck = NULL;
  392|      0|			}
  393|      1|			*eck = buf_get_ecdsa_priv_key(buf);
  394|      1|			if (*eck) {
  ------------------
  |  Branch (394:8): [True: 1, False: 0]
  ------------------
  395|      1|				ret = DROPBEAR_SUCCESS;
  ------------------
  |  |  102|      1|#define DROPBEAR_SUCCESS 0
  ------------------
  396|      1|			}
  397|      1|		}
  398|      1|	}
  399|      4|#endif
  400|      4|#if DROPBEAR_ED25519
  401|      4|	if (keytype == DROPBEAR_SIGNKEY_ED25519) {
  ------------------
  |  Branch (401:6): [True: 1, False: 3]
  ------------------
  402|      1|		ed25519_key_free(key->ed25519key);
  403|      1|		key->ed25519key = m_malloc(sizeof(*key->ed25519key));
  404|      1|		ret = buf_get_ed25519_priv_key(buf, key->ed25519key);
  405|      1|		if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|      1|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (405:7): [True: 0, False: 1]
  ------------------
  406|      0|			m_free(key->ed25519key);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  407|      0|			key->ed25519key = NULL;
  408|      0|		}
  409|      1|	}
  410|      4|#endif
  411|       |
  412|      4|	TRACE2(("leave buf_get_priv_key"))
  413|       |
  414|      4|	return ret;
  415|       |	
  416|      4|}
buf_put_pub_key:
  419|  35.0k|void buf_put_pub_key(buffer* buf, sign_key *key, enum signkey_type type) {
  420|       |
  421|  35.0k|	buffer *pubkeys;
  422|       |
  423|  35.0k|	TRACE2(("enter buf_put_pub_key"))
  424|  35.0k|	pubkeys = buf_new(MAX_PUBKEY_SIZE);
  ------------------
  |  |  232|  35.0k|#define MAX_PUBKEY_SIZE 1700
  ------------------
  425|       |	
  426|  35.0k|#if DROPBEAR_DSS
  427|  35.0k|	if (type == DROPBEAR_SIGNKEY_DSS) {
  ------------------
  |  Branch (427:6): [True: 18.3k, False: 16.6k]
  ------------------
  428|  18.3k|		buf_put_dss_pub_key(pubkeys, key->dsskey);
  429|  18.3k|	}
  430|  35.0k|#endif
  431|  35.0k|#if DROPBEAR_RSA
  432|  35.0k|	if (type == DROPBEAR_SIGNKEY_RSA) {
  ------------------
  |  Branch (432:6): [True: 8.21k, False: 26.7k]
  ------------------
  433|  8.21k|		buf_put_rsa_pub_key(pubkeys, key->rsakey);
  434|  8.21k|	}
  435|  35.0k|#endif
  436|  35.0k|#if DROPBEAR_ECDSA
  437|  35.0k|	if (signkey_is_ecdsa(type)) {
  ------------------
  |  Branch (437:6): [True: 6.37k, False: 28.6k]
  ------------------
  438|  6.37k|		ecc_key **eck = (ecc_key**)signkey_key_ptr(key, type);
  439|  6.37k|		if (eck && *eck) {
  ------------------
  |  Branch (439:7): [True: 6.37k, False: 0]
  |  Branch (439:14): [True: 6.37k, False: 2]
  ------------------
  440|  6.37k|			buf_put_ecdsa_pub_key(pubkeys, *eck);
  441|  6.37k|		}
  442|  6.37k|	}
  443|  35.0k|#endif
  444|  35.0k|#if DROPBEAR_ED25519
  445|  35.0k|	if (type == DROPBEAR_SIGNKEY_ED25519
  ------------------
  |  Branch (445:6): [True: 2.02k, False: 32.9k]
  ------------------
  446|  35.0k|#if DROPBEAR_SK_ED25519
  447|  35.0k|		|| type == DROPBEAR_SIGNKEY_SK_ED25519
  ------------------
  |  Branch (447:6): [True: 11, False: 32.9k]
  ------------------
  448|  35.0k|#endif
  449|  35.0k|	) {
  450|  2.04k|		buf_put_ed25519_pub_key(pubkeys, key->ed25519key);
  451|  2.04k|	}
  452|  35.0k|#endif
  453|  35.0k|	if (pubkeys->len == 0) {
  ------------------
  |  Branch (453:6): [True: 2, False: 35.0k]
  ------------------
  454|      2|		dropbear_exit("Bad key types in buf_put_pub_key");
  455|      2|	}
  456|       |
  457|  35.0k|	buf_putbufstring(buf, pubkeys);
  458|  35.0k|	buf_free(pubkeys);
  459|  35.0k|	TRACE2(("leave buf_put_pub_key"))
  460|  35.0k|}
buf_put_sign:
  592|  17.3k|	const buffer *data_buf) {
  593|  17.3k|	buffer *sigblob = buf_new(MAX_PUBKEY_SIZE);
  ------------------
  |  |  232|  17.3k|#define MAX_PUBKEY_SIZE 1700
  ------------------
  594|  17.3k|	enum signkey_type keytype = signkey_type_from_signature(sigtype);
  595|       |
  596|       |#if DEBUG_TRACE > DROPBEAR_VERBOSE_LEVEL
  597|       |	{
  598|       |		const char* signame = signature_name_from_type(sigtype, NULL);
  599|       |		TRACE(("buf_put_sign type %d %s", sigtype, signame));
  600|       |	}
  601|       |#endif
  602|       |
  603|       |
  604|  17.3k|#if DROPBEAR_DSS
  605|  17.3k|	if (keytype == DROPBEAR_SIGNKEY_DSS) {
  ------------------
  |  Branch (605:6): [True: 9.15k, False: 8.14k]
  ------------------
  606|  9.15k|		buf_put_dss_sign(sigblob, key->dsskey, data_buf);
  607|  9.15k|	}
  608|  17.3k|#endif
  609|  17.3k|#if DROPBEAR_RSA
  610|  17.3k|	if (keytype == DROPBEAR_SIGNKEY_RSA) {
  ------------------
  |  Branch (610:6): [True: 3.94k, False: 13.3k]
  ------------------
  611|  3.94k|		buf_put_rsa_sign(sigblob, key->rsakey, sigtype, data_buf);
  612|  3.94k|	}
  613|  17.3k|#endif
  614|  17.3k|#if DROPBEAR_ECDSA
  615|  17.3k|	if (signkey_is_ecdsa(keytype)) {
  ------------------
  |  Branch (615:6): [True: 3.18k, False: 14.1k]
  ------------------
  616|  3.18k|		ecc_key **eck = (ecc_key**)signkey_key_ptr(key, keytype);
  617|  3.18k|		if (eck && *eck) {
  ------------------
  |  Branch (617:7): [True: 3.18k, False: 0]
  |  Branch (617:14): [True: 3.18k, False: 0]
  ------------------
  618|  3.18k|			buf_put_ecdsa_sign(sigblob, *eck, data_buf);
  619|  3.18k|		}
  620|  3.18k|	}
  621|  17.3k|#endif
  622|  17.3k|#if DROPBEAR_ED25519
  623|  17.3k|	if (keytype == DROPBEAR_SIGNKEY_ED25519) {
  ------------------
  |  Branch (623:6): [True: 1.01k, False: 16.2k]
  ------------------
  624|  1.01k|		buf_put_ed25519_sign(sigblob, key->ed25519key, data_buf);
  625|  1.01k|	}
  626|  17.3k|#endif
  627|  17.3k|	if (sigblob->len == 0) {
  ------------------
  |  Branch (627:6): [True: 5, False: 17.2k]
  ------------------
  628|      5|		dropbear_exit("Non-matching signing type");
  629|      5|	}
  630|  17.2k|	buf_putbufstring(buf, sigblob);
  631|  17.2k|	buf_free(sigblob);
  632|       |
  633|  17.2k|}

svr_authinitialise:
   42|  3.96k|void svr_authinitialise() {
   43|  3.96k|	memset(&ses.authstate, 0, sizeof(ses.authstate));
   44|  3.96k|#if DROPBEAR_SVR_PUBKEY_AUTH
   45|  3.96k|	ses.authstate.authtypes |= AUTH_TYPE_PUBKEY;
  ------------------
  |  |   88|  3.96k|#define AUTH_TYPE_PUBKEY    (1 << 1)
  ------------------
   46|  3.96k|#endif
   47|  3.96k|#if DROPBEAR_SVR_PASSWORD_AUTH || DROPBEAR_SVR_PAM_AUTH
   48|  3.96k|	if (!svr_opts.noauthpass) {
  ------------------
  |  Branch (48:6): [True: 3.96k, False: 0]
  ------------------
   49|  3.96k|		ses.authstate.authtypes |= AUTH_TYPE_PASSWORD;
  ------------------
  |  |   89|  3.96k|#define AUTH_TYPE_PASSWORD  (1 << 2)
  ------------------
   50|  3.96k|	}
   51|  3.96k|#endif
   52|  3.96k|}
recv_msg_userauth_request:
   73|  1.82k|void recv_msg_userauth_request() {
   74|       |
   75|  1.82k|	char *username = NULL, *servicename = NULL, *methodname = NULL;
   76|  1.82k|	unsigned int userlen, servicelen, methodlen;
   77|  1.82k|	int valid_user = 0;
   78|       |
   79|  1.82k|	TRACE(("enter recv_msg_userauth_request"))
   80|       |
   81|       |	/* for compensating failure delay */
   82|  1.82k|	gettime_wrapper(&ses.authstate.auth_starttime);
   83|       |
   84|       |	/* ignore packets if auth is already done */
   85|  1.82k|	if (ses.authstate.authdone == 1) {
  ------------------
  |  Branch (85:6): [True: 0, False: 1.82k]
  ------------------
   86|      0|		TRACE(("leave recv_msg_userauth_request: authdone already"))
   87|      0|		return;
   88|      0|	}
   89|       |
   90|       |	/* send the banner if it exists, it will only exist once */
   91|  1.82k|	if (svr_opts.banner) {
  ------------------
  |  Branch (91:6): [True: 0, False: 1.82k]
  ------------------
   92|      0|		send_msg_userauth_banner(svr_opts.banner);
   93|      0|		buf_free(svr_opts.banner);
   94|      0|		svr_opts.banner = NULL;
   95|      0|	}
   96|       |
   97|  1.82k|	username = buf_getstring(ses.payload, &userlen);
   98|  1.82k|	servicename = buf_getstring(ses.payload, &servicelen);
   99|  1.82k|	methodname = buf_getstring(ses.payload, &methodlen);
  100|       |
  101|       |	/* only handle 'ssh-connection' currently */
  102|  1.82k|	if (servicelen != SSH_SERVICE_CONNECTION_LEN
  ------------------
  |  |  107|  3.64k|#define SSH_SERVICE_CONNECTION_LEN 14
  ------------------
  |  Branch (102:6): [True: 148, False: 1.67k]
  ------------------
  103|  1.82k|			&& (strncmp(servicename, SSH_SERVICE_CONNECTION,
  ------------------
  |  |  106|    148|#define SSH_SERVICE_CONNECTION "ssh-connection"
  ------------------
  |  Branch (103:7): [True: 130, False: 18]
  ------------------
  104|    148|					SSH_SERVICE_CONNECTION_LEN) != 0)) {
  ------------------
  |  |  107|    148|#define SSH_SERVICE_CONNECTION_LEN 14
  ------------------
  105|       |		
  106|       |		/* TODO - disconnect here */
  107|    130|		m_free(username);
  ------------------
  |  |   24|    130|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  108|    130|		m_free(servicename);
  ------------------
  |  |   24|    130|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  109|    130|		m_free(methodname);
  ------------------
  |  |   24|    130|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  110|    130|		dropbear_exit("unknown service in auth");
  111|    130|	}
  112|       |
  113|       |	/* check username is good before continuing. 
  114|       |	 * the 'incrfail' varies depending on the auth method to
  115|       |	 * avoid giving away which users exist on the system through
  116|       |	 * the time delay. */
  117|  1.69k|	if (checkusername(username, userlen) == DROPBEAR_SUCCESS) {
  ------------------
  |  |  102|  1.69k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (117:6): [True: 787, False: 907]
  ------------------
  118|    787|		valid_user = 1;
  119|    787|	}
  120|       |
  121|       |	/* user wants to know what methods are supported */
  122|  1.69k|	if (methodlen == AUTH_METHOD_NONE_LEN &&
  ------------------
  |  |   93|  3.38k|#define AUTH_METHOD_NONE_LEN 4
  ------------------
  |  Branch (122:6): [True: 324, False: 1.37k]
  ------------------
  123|  1.69k|			strncmp(methodname, AUTH_METHOD_NONE,
  ------------------
  |  |   92|    324|#define AUTH_METHOD_NONE "none"
  ------------------
  |  Branch (123:4): [True: 188, False: 136]
  ------------------
  124|    324|				AUTH_METHOD_NONE_LEN) == 0) {
  ------------------
  |  |   93|    324|#define AUTH_METHOD_NONE_LEN 4
  ------------------
  125|    188|		TRACE(("recv_msg_userauth_request: 'none' request"))
  126|    188|		if (valid_user
  ------------------
  |  Branch (126:7): [True: 187, False: 1]
  ------------------
  127|    188|				&& svr_opts.allowblankpass
  ------------------
  |  Branch (127:8): [True: 0, False: 187]
  ------------------
  128|    188|				&& !svr_opts.noauthpass
  ------------------
  |  Branch (128:8): [True: 0, False: 0]
  ------------------
  129|    188|				&& !(svr_opts.norootpass && ses.authstate.pw_uid == 0) 
  ------------------
  |  Branch (129:10): [True: 0, False: 0]
  |  Branch (129:33): [True: 0, False: 0]
  ------------------
  130|    188|				&& ses.authstate.pw_passwd[0] == '\0') 
  ------------------
  |  Branch (130:8): [True: 0, False: 0]
  ------------------
  131|      0|		{
  132|      0|			dropbear_log(LOG_NOTICE, 
  133|      0|					"Auth succeeded with blank password for '%s' from %s",
  134|      0|					ses.authstate.pw_name,
  135|      0|					svr_ses.addrstring);
  136|      0|			send_msg_userauth_success();
  137|      0|			goto out;
  138|      0|		}
  139|    188|		else
  140|    188|		{
  141|       |			/* 'none' has no failure delay */
  142|    188|			send_msg_userauth_failure(0, 0);
  143|    188|			goto out;
  144|    188|		}
  145|    188|	}
  146|       |	
  147|  1.50k|#if DROPBEAR_SVR_PASSWORD_AUTH
  148|  1.50k|	if (!svr_opts.noauthpass &&
  ------------------
  |  Branch (148:6): [True: 1.35k, False: 148]
  ------------------
  149|  1.50k|			!(svr_opts.norootpass && ses.authstate.pw_uid == 0) ) {
  ------------------
  |  Branch (149:6): [True: 0, False: 1.35k]
  |  Branch (149:29): [True: 0, False: 0]
  ------------------
  150|       |		/* user wants to try password auth */
  151|  1.35k|		if (methodlen == AUTH_METHOD_PASSWORD_LEN &&
  ------------------
  |  |   97|  2.71k|#define AUTH_METHOD_PASSWORD_LEN 8
  ------------------
  |  Branch (151:7): [True: 180, False: 1.17k]
  ------------------
  152|  1.35k|				strncmp(methodname, AUTH_METHOD_PASSWORD,
  ------------------
  |  |   96|    180|#define AUTH_METHOD_PASSWORD "password"
  ------------------
  |  Branch (152:5): [True: 50, False: 130]
  ------------------
  153|    180|					AUTH_METHOD_PASSWORD_LEN) == 0) {
  ------------------
  |  |   97|    180|#define AUTH_METHOD_PASSWORD_LEN 8
  ------------------
  154|     50|			svr_auth_password(valid_user);
  155|     50|			goto out;
  156|     50|		}
  157|  1.35k|	}
  158|  1.45k|#endif
  159|       |
  160|       |#if DROPBEAR_SVR_PAM_AUTH
  161|       |	if (!svr_opts.noauthpass &&
  162|       |			!(svr_opts.norootpass && ses.authstate.pw_uid == 0) ) {
  163|       |		/* user wants to try password auth */
  164|       |		if (methodlen == AUTH_METHOD_PASSWORD_LEN &&
  165|       |				strncmp(methodname, AUTH_METHOD_PASSWORD,
  166|       |					AUTH_METHOD_PASSWORD_LEN) == 0) {
  167|       |			svr_auth_pam(valid_user);
  168|       |			goto out;
  169|       |		}
  170|       |	}
  171|       |#endif
  172|       |
  173|  1.45k|#if DROPBEAR_SVR_PUBKEY_AUTH
  174|       |	/* user wants to try pubkey auth */
  175|  1.45k|	if (methodlen == AUTH_METHOD_PUBKEY_LEN &&
  ------------------
  |  |   95|  2.91k|#define AUTH_METHOD_PUBKEY_LEN 9
  ------------------
  |  Branch (175:6): [True: 883, False: 573]
  ------------------
  176|  1.45k|			strncmp(methodname, AUTH_METHOD_PUBKEY,
  ------------------
  |  |   94|    883|#define AUTH_METHOD_PUBKEY "publickey"
  ------------------
  |  Branch (176:4): [True: 787, False: 96]
  ------------------
  177|    883|				AUTH_METHOD_PUBKEY_LEN) == 0) {
  ------------------
  |  |   95|    883|#define AUTH_METHOD_PUBKEY_LEN 9
  ------------------
  178|    787|		svr_auth_pubkey(valid_user);
  179|    787|		goto out;
  180|    787|	}
  181|    669|#endif
  182|       |
  183|       |	/* nothing matched, we just fail with a delay */
  184|    669|	send_msg_userauth_failure(0, 1);
  185|       |
  186|  1.47k|out:
  187|       |
  188|  1.47k|	m_free(username);
  ------------------
  |  |   24|  1.47k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  189|  1.47k|	m_free(servicename);
  ------------------
  |  |   24|  1.47k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  190|  1.47k|	m_free(methodname);
  ------------------
  |  |   24|  1.47k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  191|  1.47k|}
send_msg_userauth_failure:
  348|  1.47k|void send_msg_userauth_failure(int partial, int incrfail) {
  349|       |
  350|  1.47k|	buffer *typebuf = NULL;
  351|       |
  352|  1.47k|	TRACE(("enter send_msg_userauth_failure"))
  353|       |
  354|  1.47k|	CHECKCLEARTOWRITE();
  355|       |	
  356|  1.47k|	buf_putbyte(ses.writepayload, SSH_MSG_USERAUTH_FAILURE);
  ------------------
  |  |   43|  1.47k|#define SSH_MSG_USERAUTH_FAILURE            51
  ------------------
  357|       |
  358|       |	/* put a list of allowed types */
  359|  1.47k|	typebuf = buf_new(30); /* long enough for PUBKEY and PASSWORD */
  360|       |
  361|  1.47k|	if (ses.authstate.authtypes & AUTH_TYPE_PUBKEY) {
  ------------------
  |  |   88|  1.47k|#define AUTH_TYPE_PUBKEY    (1 << 1)
  ------------------
  |  Branch (361:6): [True: 1.47k, False: 0]
  ------------------
  362|  1.47k|		buf_putbytes(typebuf, (const unsigned char *)AUTH_METHOD_PUBKEY, AUTH_METHOD_PUBKEY_LEN);
  ------------------
  |  |   94|  1.47k|#define AUTH_METHOD_PUBKEY "publickey"
  ------------------
              		buf_putbytes(typebuf, (const unsigned char *)AUTH_METHOD_PUBKEY, AUTH_METHOD_PUBKEY_LEN);
  ------------------
  |  |   95|  1.47k|#define AUTH_METHOD_PUBKEY_LEN 9
  ------------------
  363|  1.47k|		if (ses.authstate.authtypes & AUTH_TYPE_PASSWORD) {
  ------------------
  |  |   89|  1.47k|#define AUTH_TYPE_PASSWORD  (1 << 2)
  ------------------
  |  Branch (363:7): [True: 1.47k, False: 0]
  ------------------
  364|  1.47k|			buf_putbyte(typebuf, ',');
  365|  1.47k|		}
  366|  1.47k|	}
  367|       |	
  368|  1.47k|	if (ses.authstate.authtypes & AUTH_TYPE_PASSWORD) {
  ------------------
  |  |   89|  1.47k|#define AUTH_TYPE_PASSWORD  (1 << 2)
  ------------------
  |  Branch (368:6): [True: 1.47k, False: 0]
  ------------------
  369|  1.47k|		buf_putbytes(typebuf, (const unsigned char *)AUTH_METHOD_PASSWORD, AUTH_METHOD_PASSWORD_LEN);
  ------------------
  |  |   96|  1.47k|#define AUTH_METHOD_PASSWORD "password"
  ------------------
              		buf_putbytes(typebuf, (const unsigned char *)AUTH_METHOD_PASSWORD, AUTH_METHOD_PASSWORD_LEN);
  ------------------
  |  |   97|  1.47k|#define AUTH_METHOD_PASSWORD_LEN 8
  ------------------
  370|  1.47k|	}
  371|       |
  372|  1.47k|	buf_putbufstring(ses.writepayload, typebuf);
  373|       |
  374|  1.47k|	TRACE(("auth fail: methods %d, '%.*s'", ses.authstate.authtypes,
  375|  1.47k|				typebuf->len, typebuf->data))
  376|       |
  377|  1.47k|	buf_free(typebuf);
  378|       |
  379|  1.47k|	buf_putbyte(ses.writepayload, partial ? 1 : 0);
  ------------------
  |  Branch (379:32): [True: 0, False: 1.47k]
  ------------------
  380|  1.47k|	encrypt_packet();
  381|       |
  382|  1.47k|	if (incrfail) {
  ------------------
  |  Branch (382:6): [True: 569, False: 910]
  ------------------
  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|    569|		const unsigned int mindelay = 250000000;
  391|    569|		const unsigned int vardelay = 100000000;
  392|    569|		suseconds_t rand_delay;
  393|    569|		struct timespec delay;
  394|       |
  395|    569|		gettime_wrapper(&delay);
  396|    569|		delay.tv_sec -= ses.authstate.auth_starttime.tv_sec;
  397|    569|		delay.tv_nsec -= ses.authstate.auth_starttime.tv_nsec;
  398|       |
  399|       |		/* carry */
  400|    569|		if (delay.tv_nsec < 0) {
  ------------------
  |  Branch (400:7): [True: 0, False: 569]
  ------------------
  401|      0|			delay.tv_nsec += 1000000000;
  402|      0|			delay.tv_sec -= 1;
  403|      0|		}
  404|       |
  405|    569|		genrandom((unsigned char*)&rand_delay, sizeof(rand_delay));
  406|    569|		rand_delay = mindelay + (rand_delay % vardelay);
  407|       |
  408|    569|		if (delay.tv_sec == 0 && delay.tv_nsec <= mindelay) {
  ------------------
  |  Branch (408:7): [True: 569, False: 0]
  |  Branch (408:28): [True: 569, False: 0]
  ------------------
  409|       |			/* Compensate for elapsed time */
  410|    569|			delay.tv_nsec = rand_delay - delay.tv_nsec;
  411|    569|		} 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|    569|#if DROPBEAR_FUZZ
  419|    569|		if (!fuzz.fuzzing)
  ------------------
  |  Branch (419:7): [True: 0, False: 569]
  ------------------
  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|    569|		ses.authstate.failcount++;
  426|    569|	}
  427|       |
  428|  1.47k|	if (ses.authstate.failcount >= svr_opts.maxauthtries) {
  ------------------
  |  Branch (428:6): [True: 2, False: 1.47k]
  ------------------
  429|      2|		char * userstr;
  430|       |		/* XXX - send disconnect ? */
  431|      2|		TRACE(("Max auth tries reached, exiting"))
  432|       |
  433|      2|		if (ses.authstate.pw_name == NULL) {
  ------------------
  |  Branch (433:7): [True: 1, False: 1]
  ------------------
  434|      1|			userstr = "is invalid";
  435|      1|		} else {
  436|      1|			userstr = ses.authstate.pw_name;
  437|      1|		}
  438|      2|		dropbear_exit("Max auth tries reached - user '%s'",
  439|      2|				userstr);
  440|      2|	}
  441|       |	
  442|  1.47k|	TRACE(("leave send_msg_userauth_failure"))
  443|  1.47k|}
svr-auth.c:checkusername:
  231|  1.68k|static int checkusername(const char *username, unsigned int userlen) {
  232|       |
  233|  1.68k|	char* listshell = NULL;
  234|  1.68k|	char* usershell = NULL;
  235|  1.68k|	uid_t uid;
  236|       |
  237|  1.68k|	TRACE(("enter checkusername"))
  238|  1.68k|	if (userlen > MAX_USERNAME_LEN) {
  ------------------
  |  |   85|  1.68k|#define MAX_USERNAME_LEN 100 /* arbitrary for the moment */
  ------------------
  |  Branch (238:6): [True: 18, False: 1.67k]
  ------------------
  239|     18|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|     18|#define DROPBEAR_FAILURE -1
  ------------------
  240|     18|	}
  241|       |
  242|  1.67k|	if (strlen(username) != userlen) {
  ------------------
  |  Branch (242:6): [True: 10, False: 1.66k]
  ------------------
  243|     10|		dropbear_exit("Attempted username with a null byte");
  244|     10|	}
  245|       |
  246|  1.66k|	if (ses.authstate.username == NULL) {
  ------------------
  |  Branch (246:6): [True: 502, False: 1.15k]
  ------------------
  247|       |		/* first request */
  248|    502|		fill_passwd(username);
  249|    502|		ses.authstate.username = m_strdup(username);
  250|  1.15k|	} else {
  251|       |		/* check username hasn't changed */
  252|  1.15k|		if (strcmp(username, ses.authstate.username) != 0) {
  ------------------
  |  Branch (252:7): [True: 132, False: 1.02k]
  ------------------
  253|    132|			dropbear_exit("Client trying multiple usernames");
  254|    132|		}
  255|  1.15k|	}
  256|       |
  257|       |	/* avoids cluttering logs with repeated failure messages from
  258|       |	consecutive authentication requests in a sesssion */
  259|  1.52k|	if (ses.authstate.checkusername_failed) {
  ------------------
  |  Branch (259:6): [True: 273, False: 1.25k]
  ------------------
  260|    273|		TRACE(("checkusername: returning cached failure"))
  261|    273|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|    273|#define DROPBEAR_FAILURE -1
  ------------------
  262|    273|	}
  263|       |
  264|       |	/* check that user exists */
  265|  1.25k|	if (!ses.authstate.pw_name) {
  ------------------
  |  Branch (265:6): [True: 468, False: 787]
  ------------------
  266|    468|		TRACE(("leave checkusername: user '%s' doesn't exist", username))
  267|    468|		dropbear_log(LOG_WARNING,
  268|    468|				"Login attempt for nonexistent user");
  269|    468|		ses.authstate.checkusername_failed = 1;
  270|    468|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|    468|#define DROPBEAR_FAILURE -1
  ------------------
  271|    468|	}
  272|       |
  273|       |	/* check if we are running as non-root, and login user is different from the server */
  274|    787|	uid = geteuid();
  275|    787|	if (!(DROPBEAR_SVR_MULTIUSER && uid == 0) && uid != ses.authstate.pw_uid) {
  ------------------
  |  |  364|  1.57k|#define DROPBEAR_SVR_MULTIUSER 1
  |  |  ------------------
  |  |  |  Branch (364:32): [Folded - Ignored]
  |  |  ------------------
  ------------------
  |  Branch (275:34): [True: 787, False: 0]
  |  Branch (275:47): [True: 0, False: 0]
  ------------------
  276|      0|		TRACE(("running as nonroot, only server uid is allowed"))
  277|      0|		dropbear_log(LOG_WARNING,
  278|      0|				"Login attempt with wrong user %s",
  279|      0|				ses.authstate.pw_name);
  280|      0|		ses.authstate.checkusername_failed = 1;
  281|      0|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
  282|      0|	}
  283|       |
  284|       |	/* check for non-root if desired */
  285|    787|	if (svr_opts.norootlogin && ses.authstate.pw_uid == 0) {
  ------------------
  |  Branch (285:6): [True: 0, False: 787]
  |  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;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
  290|      0|	}
  291|       |
  292|       |	/* check for login restricted to certain group if desired */
  293|    787|#ifdef HAVE_GETGROUPLIST
  294|    787|	if (svr_opts.restrict_group) {
  ------------------
  |  Branch (294:6): [True: 0, False: 787]
  ------------------
  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) {
  ------------------
  |  |  103|      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;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
  302|      0|		}
  303|      0|	}
  304|    787|#endif /* HAVE_GETGROUPLIST */
  305|       |
  306|    787|	TRACE(("shell is %s", ses.authstate.pw_shell))
  307|       |
  308|       |	/* check that the shell is set */
  309|    787|	usershell = ses.authstate.pw_shell;
  310|    787|	if (usershell[0] == '\0') {
  ------------------
  |  Branch (310:6): [True: 0, False: 787]
  ------------------
  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|    787|	setusershell();
  319|    787|	while ((listshell = getusershell()) != NULL) {
  ------------------
  |  Branch (319:9): [True: 787, False: 0]
  ------------------
  320|    787|		TRACE(("test shell is '%s'", listshell))
  321|    787|		if (strcmp(listshell, usershell) == 0) {
  ------------------
  |  Branch (321:7): [True: 787, False: 0]
  ------------------
  322|       |			/* have a match */
  323|    787|			goto goodshell;
  324|    787|		}
  325|    787|	}
  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;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
  333|       |	
  334|    787|goodshell:
  335|    787|	endusershell();
  336|    787|	TRACE(("matching shell"))
  337|       |
  338|    787|	TRACE(("uid = %d", ses.authstate.pw_uid))
  339|    787|	TRACE(("leave checkusername"))
  340|    787|	return DROPBEAR_SUCCESS;
  ------------------
  |  |  102|    787|#define DROPBEAR_SUCCESS 0
  ------------------
  341|    787|}

svr_auth_password:
   51|     50|void svr_auth_password(int valid_user) {
   52|       |	
   53|     50|	char * passwdcrypt = NULL; /* the crypt from /etc/passwd or /etc/shadow */
   54|     50|	char * testcrypt = NULL; /* crypt generated from the user's password sent */
   55|     50|	char * password = NULL;
   56|     50|	unsigned int passwordlen;
   57|     50|	unsigned int changepw;
   58|       |
   59|       |	/* check if client wants to change password */
   60|     50|	changepw = buf_getbool(ses.payload);
   61|     50|	if (changepw) {
  ------------------
  |  Branch (61:6): [True: 26, False: 24]
  ------------------
   62|       |		/* not implemented by this server */
   63|     26|		send_msg_userauth_failure(0, 1);
   64|     26|		return;
   65|     26|	}
   66|       |
   67|     24|	password = buf_getstring(ses.payload, &passwordlen);
   68|     24|	if (valid_user && passwordlen <= DROPBEAR_MAX_PASSWORD_LEN) {
  ------------------
  |  |  118|      0|#define DROPBEAR_MAX_PASSWORD_LEN 100
  ------------------
  |  Branch (68:6): [True: 0, False: 24]
  |  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|     24|	m_burn(password, passwordlen);
   74|     24|	m_free(password);
  ------------------
  |  |   24|     24|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
   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|     24|	if (!valid_user) {
  ------------------
  |  Branch (78:6): [True: 22, False: 2]
  ------------------
   79|     22|		send_msg_userauth_failure(0, 1);
   80|     22|		return;
   81|     22|	}
   82|       |
   83|      2|	if (passwordlen > DROPBEAR_MAX_PASSWORD_LEN) {
  ------------------
  |  |  118|      2|#define DROPBEAR_MAX_PASSWORD_LEN 100
  ------------------
  |  Branch (83:6): [True: 0, False: 2]
  ------------------
   84|      0|		dropbear_log(LOG_WARNING,
   85|      0|				"Too-long password attempt for '%s' from %s",
   86|      0|				ses.authstate.pw_name,
   87|      0|				svr_ses.addrstring);
   88|      0|		send_msg_userauth_failure(0, 1);
   89|      0|		return;
   90|      0|	}
   91|       |
   92|      2|	if (testcrypt == NULL) {
  ------------------
  |  Branch (92:6): [True: 0, False: 2]
  ------------------
   93|       |		/* crypt() with an invalid salt like "!!" */
   94|      0|		dropbear_log(LOG_WARNING, "User account '%s' is locked",
   95|      0|				ses.authstate.pw_name);
   96|      0|		send_msg_userauth_failure(0, 1);
   97|      0|		return;
   98|      0|	}
   99|       |
  100|       |	/* check for empty password */
  101|      2|	if (passwdcrypt[0] == '\0') {
  ------------------
  |  Branch (101:6): [True: 0, False: 2]
  ------------------
  102|      0|		dropbear_log(LOG_WARNING, "User '%s' has blank password, rejected",
  103|      0|				ses.authstate.pw_name);
  104|      0|		send_msg_userauth_failure(0, 1);
  105|      0|		return;
  106|      0|	}
  107|       |
  108|      2|	if (constant_time_strcmp(testcrypt, passwdcrypt) == 0) {
  ------------------
  |  Branch (108:6): [True: 0, False: 2]
  ------------------
  109|      0|		if (svr_opts.multiauthmethod && (ses.authstate.authtypes & ~AUTH_TYPE_PASSWORD)) {
  ------------------
  |  |   89|      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 */
  ------------------
  |  |   89|      0|#define AUTH_TYPE_PASSWORD  (1 << 2)
  ------------------
  116|      0|			send_msg_userauth_failure(1, 0);  /* Send partial success */
  117|      0|		} else {
  118|       |			/* successful authentication */
  119|      0|			dropbear_log(LOG_NOTICE, 
  120|      0|					"Password auth succeeded for '%s' from %s",
  121|      0|					ses.authstate.pw_name,
  122|      0|					svr_ses.addrstring);
  123|      0|			send_msg_userauth_success();
  124|      0|		}
  125|      2|	} else {
  126|      2|		dropbear_log(LOG_WARNING,
  127|      2|				"Bad password attempt for '%s' from %s",
  128|      2|				ses.authstate.pw_name,
  129|      2|				svr_ses.addrstring);
  130|      2|		send_msg_userauth_failure(0, 1);
  131|      2|	}
  132|      2|}

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

svr_pubkey_options_cleanup:
  135|  4.69k|void svr_pubkey_options_cleanup() {
  136|  4.69k|	if (ses.authstate.pubkey_options) {
  ------------------
  |  Branch (136:6): [True: 0, False: 4.69k]
  ------------------
  137|      0|		if (ses.authstate.pubkey_options->forced_command) {
  ------------------
  |  Branch (137:7): [True: 0, False: 0]
  ------------------
  138|      0|			m_free(ses.authstate.pubkey_options->forced_command);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  139|      0|		}
  140|      0|		if (ses.authstate.pubkey_options->permit_open_destinations) {
  ------------------
  |  Branch (140:7): [True: 0, False: 0]
  ------------------
  141|      0|			m_list_elem *iter = ses.authstate.pubkey_options->permit_open_destinations->first;
  142|      0|			while (iter) {
  ------------------
  |  Branch (142:11): [True: 0, False: 0]
  ------------------
  143|      0|				struct PermitTCPFwdEntry *entry = (struct PermitTCPFwdEntry*)list_remove(iter);
  144|      0|				m_free(entry->host);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  145|      0|				m_free(entry);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  146|      0|				iter = ses.authstate.pubkey_options->permit_open_destinations->first;
  147|      0|			}
  148|      0|			m_free(ses.authstate.pubkey_options->permit_open_destinations);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  149|      0|		}
  150|      0|		m_free(ses.authstate.pubkey_options);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  151|      0|	}
  152|  4.69k|	if (ses.authstate.pubkey_info) {
  ------------------
  |  Branch (152:6): [True: 0, False: 4.69k]
  ------------------
  153|      0|		m_free(ses.authstate.pubkey_info);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  154|      0|	}
  155|  4.69k|}

svr_chansess_checksignal:
   95|   408k|void svr_chansess_checksignal(void) {
   96|   408k|	int status;
   97|   408k|	pid_t pid;
   98|       |
   99|   408k|	if (!ses.channel_signal_pending) {
  ------------------
  |  Branch (99:6): [True: 408k, False: 0]
  ------------------
  100|   408k|		return;
  101|   408k|	}
  102|       |
  103|      0|	while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
  ------------------
  |  Branch (103:9): [True: 0, False: 0]
  ------------------
  104|      0|		unsigned int i;
  105|      0|		struct exitinfo *ex = NULL;
  106|      0|		TRACE(("svr_chansess_checksignal : pid %d", pid))
  107|       |
  108|      0|		ex = NULL;
  109|       |		/* find the corresponding chansess */
  110|      0|		for (i = 0; i < svr_ses.childpidsize; i++) {
  ------------------
  |  Branch (110:15): [True: 0, False: 0]
  ------------------
  111|      0|			if (svr_ses.childpids[i].pid == pid) {
  ------------------
  |  Branch (111:8): [True: 0, False: 0]
  ------------------
  112|      0|				TRACE(("found match session"));
  113|      0|				ex = &svr_ses.childpids[i].chansess->exit;
  114|      0|				break;
  115|      0|			}
  116|      0|		}
  117|       |
  118|       |		/* If the pid wasn't matched, then we might have hit the race mentioned
  119|       |		 * above. So we just store the info for the parent to deal with */
  120|      0|		if (ex == NULL) {
  ------------------
  |  Branch (120:7): [True: 0, False: 0]
  ------------------
  121|      0|			TRACE(("using lastexit"));
  122|      0|			ex = &svr_ses.lastexit;
  123|      0|		}
  124|       |
  125|      0|		ex->exitpid = pid;
  126|      0|		if (WIFEXITED(status)) {
  127|      0|			ex->exitstatus = WEXITSTATUS(status);
  128|      0|		}
  129|      0|		if (WIFSIGNALED(status)) {
  130|      0|			ex->exitsignal = WTERMSIG(status);
  131|      0|#if !defined(AIX) && defined(WCOREDUMP)
  132|      0|			ex->exitcore = WCOREDUMP(status);
  133|       |#else
  134|       |			ex->exitcore = 0;
  135|       |#endif
  136|      0|		} else {
  137|       |			/* we use this to determine how pid exited */
  138|      0|			ex->exitsignal = -1;
  139|      0|		}
  140|      0|	}
  141|      0|}
svr_chansessinitialise:
 1077|  3.96k|void svr_chansessinitialise() {
 1078|       |
 1079|  3.96k|	struct sigaction sa_chld;
 1080|       |
 1081|       |	/* single child process intially */
 1082|  3.96k|	svr_ses.childpids = (struct ChildPid*)m_malloc(sizeof(struct ChildPid));
 1083|  3.96k|	svr_ses.childpids[0].pid = -1; /* unused */
 1084|  3.96k|	svr_ses.childpids[0].chansess = NULL;
 1085|  3.96k|	svr_ses.childpidsize = 1;
 1086|  3.96k|	svr_ses.lastexit.exitpid = -1; /* Nothing has exited yet */
 1087|  3.96k|	sa_chld.sa_handler = sesssigchild_handler;
 1088|  3.96k|	sa_chld.sa_flags = SA_NOCLDSTOP;
 1089|  3.96k|	sigemptyset(&sa_chld.sa_mask);
 1090|  3.96k|	if (sigaction(SIGCHLD, &sa_chld, NULL) < 0) {
  ------------------
  |  Branch (1090:6): [True: 0, False: 3.96k]
  ------------------
 1091|      0|		dropbear_exit("signal() error");
 1092|      0|	}
 1093|       |	
 1094|  3.96k|}

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

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

recv_msg_service_request:
   37|    648|void recv_msg_service_request() {
   38|       |
   39|    648|	char * name;
   40|    648|	unsigned int len;
   41|       |
   42|    648|	TRACE(("enter recv_msg_service_request"))
   43|       |
   44|    648|	name = buf_getstring(ses.payload, &len);
   45|       |
   46|       |	/* ssh-userauth */
   47|    648|	if (len == SSH_SERVICE_USERAUTH_LEN && 
  ------------------
  |  |  105|  1.29k|#define SSH_SERVICE_USERAUTH_LEN 12
  ------------------
  |  Branch (47:6): [True: 526, False: 122]
  ------------------
   48|    648|			strncmp(SSH_SERVICE_USERAUTH, name, len) == 0) {
  ------------------
  |  |  104|    526|#define SSH_SERVICE_USERAUTH "ssh-userauth"
  ------------------
  |  Branch (48:4): [True: 423, False: 103]
  ------------------
   49|       |
   50|    423|		send_msg_service_accept(name, len);
   51|    423|		m_free(name);
  ------------------
  |  |   24|    423|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
   52|    423|		TRACE(("leave recv_msg_service_request: done ssh-userauth"))
   53|    423|		return;
   54|    423|	}
   55|       |
   56|       |	/* ssh-connection */
   57|    225|	if (len == SSH_SERVICE_CONNECTION_LEN &&
  ------------------
  |  |  107|    450|#define SSH_SERVICE_CONNECTION_LEN 14
  ------------------
  |  Branch (57:6): [True: 117, False: 108]
  ------------------
   58|    225|			(strncmp(SSH_SERVICE_CONNECTION, name, len) == 0)) {
  ------------------
  |  |  106|    117|#define SSH_SERVICE_CONNECTION "ssh-connection"
  ------------------
  |  Branch (58:4): [True: 1, False: 116]
  ------------------
   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 - Ignored]
  |  |  ------------------
  ------------------
   65|      0|		TRACE(("leave recv_msg_service_request: done ssh-connection"))
   66|      0|		return;
   67|      1|	}
   68|       |
   69|    224|	m_free(name);
  ------------------
  |  |   24|    224|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
   70|       |	/* TODO this should be a MSG_DISCONNECT */
   71|    224|	dropbear_exit("Unrecognised SSH_MSG_SERVICE_REQUEST");
   72|       |
   73|       |
   74|    225|}
svr-service.c:send_msg_service_accept:
   76|    423|static void send_msg_service_accept(const char *name, int len) {
   77|       |
   78|    423|	TRACE(("accepting service %s", name))
   79|       |
   80|    423|	CHECKCLEARTOWRITE();
   81|       |
   82|    423|	buf_putbyte(ses.writepayload, SSH_MSG_SERVICE_ACCEPT);
  ------------------
  |  |   34|    423|#define SSH_MSG_SERVICE_ACCEPT         6
  ------------------
   83|    423|	buf_putstring(ses.writepayload, name, len);
   84|       |
   85|    423|	encrypt_packet();
   86|       |
   87|    423|}

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

