fuzz_early_setup:
   23|      2|void fuzz_early_setup(void) {
   24|       |    /* Set stderr to point to normal stderr by default */
   25|       |    fuzz.fake_stderr = stderr;
   26|      2|}
fuzz_common_setup:
   28|      1|void fuzz_common_setup(void) {
   29|      1|	disallow_core();
   30|      1|    fuzz.fuzzing = 1;
   31|      1|    fuzz.wrapfds = 1;
   32|      1|    fuzz.do_jmp = 1;
   33|      1|    fuzz.input = m_malloc(sizeof(buffer));
   34|      1|    _dropbear_log = fuzz_dropbear_log;
   35|      1|    crypto_init();
   36|      1|    fuzz_seed("start", 5);
   37|       |    /* let any messages get flushed */
   38|      1|    setlinebuf(stdout);
   39|       |#if DEBUG_TRACE
   40|       |    if (debug_trace)
   41|       |    {
   42|       |        fprintf(stderr, "Dropbear fuzzer: -v specified, not disabling stderr output\n");
   43|       |    }
   44|       |    else
   45|       |#endif
   46|      1|    if (getenv("DROPBEAR_KEEP_STDERR")) {
  ------------------
  |  Branch (46:9): [True: 0, False: 1]
  ------------------
   47|      0|        fprintf(stderr, "Dropbear fuzzer: DROPBEAR_KEEP_STDERR, not disabling stderr output\n");
   48|      0|    } 
   49|      1|    else 
   50|      1|    {
   51|      1|        fprintf(stderr, "Dropbear fuzzer: Disabling stderr output\n");
   52|      1|        fuzz.fake_stderr = fopen("/dev/null", "w");
   53|       |        assert(fuzz.fake_stderr);
  ------------------
  |  Branch (53:9): [True: 0, False: 1]
  |  Branch (53:9): [True: 1, False: 0]
  ------------------
   54|      1|    }
   55|      1|}
fuzz_set_input:
   57|  2.83k|int fuzz_set_input(const uint8_t *Data, size_t Size) {
   58|       |
   59|  2.83k|    fuzz.input->data = (unsigned char*)Data;
   60|  2.83k|    fuzz.input->size = Size;
   61|  2.83k|    fuzz.input->len = Size;
   62|  2.83k|    fuzz.input->pos = 0;
   63|       |
   64|  2.83k|    memset(&ses, 0x0, sizeof(ses));
   65|  2.83k|    memset(&svr_ses, 0x0, sizeof(svr_ses));
   66|  2.83k|    memset(&cli_ses, 0x0, sizeof(cli_ses));
   67|  2.83k|    wrapfd_setup(fuzz.input);
   68|       |    // printhex("input", fuzz.input->data, fuzz.input->len);
   69|       |
   70|  2.83k|    fuzz_seed(fuzz.input->data, MIN(fuzz.input->len, 16));
  ------------------
  |  Branch (70:33): [True: 231, False: 2.59k]
  ------------------
   71|       |
   72|  2.83k|    return DROPBEAR_SUCCESS;
  ------------------
  |  |  111|  2.83k|#define DROPBEAR_SUCCESS 0
  ------------------
   73|  2.83k|}
fuzz-common.c:fuzz_dropbear_log:
   84|    678|static void fuzz_dropbear_log(int UNUSED(priority), const char* UNUSED(format), va_list UNUSED(param)) {
   85|       |    /* No print */
   86|    678|}

wrapfd_setup:
   32|  2.83k|void wrapfd_setup(buffer *buf) {
   33|  2.83k|	TRACE(("wrapfd_setup"))
   34|       |
   35|       |	// clean old ones
   36|  2.83k|	int i;
   37|  2.83k|	for (i = 0; i <= wrapfd_maxfd; i++) {
  ------------------
  |  Branch (37:14): [True: 0, False: 2.83k]
  ------------------
   38|      0|		if (wrap_fds[i].mode != UNUSED) {
  ------------------
  |  Branch (38:7): [True: 0, False: 0]
  ------------------
   39|      0|			wrapfd_remove(i);
   40|      0|		}
   41|      0|	}
   42|  2.83k|	wrapfd_maxfd = -1;
   43|       |
   44|  2.83k|	memset(rand_state, 0x0, sizeof(rand_state));
   45|  2.83k|	wrapfd_setseed(50);
   46|  2.83k|	input_buf = buf;
   47|  2.83k|}
wrapfd_setseed:
   49|  2.83k|void wrapfd_setseed(uint32_t seed) {
   50|  2.83k|	memcpy(rand_state, &seed, sizeof(seed));
   51|  2.83k|	nrand48(rand_state);
   52|  2.83k|}

LLVMFuzzerTestOneInput:
   15|  2.83k|int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
   16|  2.83k|	static int once = 0;
   17|  2.83k|	if (!once) {
  ------------------
  |  Branch (17:6): [True: 1, False: 2.82k]
  ------------------
   18|      1|		setup_fuzzer();
   19|      1|		verifydata = buf_new(30);
   20|      1|		buf_putstring(verifydata, "x", 1);
   21|      1|		once = 1;
   22|      1|	}
   23|       |
   24|  2.83k|	if (fuzz_set_input(Data, Size) == DROPBEAR_FAILURE) {
  ------------------
  |  |  112|  2.83k|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (24:6): [True: 0, False: 2.83k]
  ------------------
   25|      0|		return 0;
   26|      0|	}
   27|       |
   28|  2.83k|	m_malloc_set_epoch(1);
   29|       |
   30|  2.83k|	if (setjmp(fuzz.jmp) == 0) {
  ------------------
  |  Branch (30:6): [True: 2.83k, False: 0]
  ------------------
   31|  2.83k|		sign_key *key = new_sign_key();
   32|  2.83k|		enum signkey_type keytype = DROPBEAR_SIGNKEY_ANY;
   33|  2.83k|		if (buf_get_pub_key(fuzz.input, key, &keytype) == DROPBEAR_SUCCESS) {
  ------------------
  |  |  111|  2.83k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (33:7): [True: 1.71k, False: 1.11k]
  ------------------
   34|  1.71k|			enum signature_type sigtype;
   35|  1.71k|			if (keytype == DROPBEAR_SIGNKEY_RSA) {
  ------------------
  |  Branch (35:8): [True: 875, False: 844]
  ------------------
   36|       |				/* Flip a coin to decide rsa signature type */
   37|    875|				int flag = buf_getbyte(fuzz.input);
   38|    875|				if (flag & 0x01) {
  ------------------
  |  Branch (38:9): [True: 16, False: 859]
  ------------------
   39|     16|					sigtype = DROPBEAR_SIGNATURE_RSA_SHA256;
   40|    859|				} else {
   41|    859|					sigtype = DROPBEAR_SIGNATURE_RSA_SHA1;
   42|    859|				}
   43|    875|			} else {
   44|    844|				sigtype = signature_type_from_signkey(keytype);
   45|    844|			}
   46|  1.71k|			if (buf_verify(fuzz.input, key, sigtype, verifydata) == DROPBEAR_SUCCESS) {
  ------------------
  |  |  111|  1.71k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (46:8): [True: 114, False: 1.60k]
  ------------------
   47|       |				/* The fuzzer is capable of generating keys with a signature to match.
   48|       |				We don't want false positives if the key is bogus, since a client/server 
   49|       |				wouldn't be trusting a bogus key anyway */
   50|    114|				int boguskey = 0;
   51|       |
   52|    114|				if (keytype == DROPBEAR_SIGNKEY_DSS) {
  ------------------
  |  Branch (52:9): [True: 112, False: 2]
  ------------------
   53|       |					/* So far have seen dss keys with bad p/q/g domain parameters */
   54|    112|					int pprime, qprime, trials;
   55|    112|					trials = mp_prime_rabin_miller_trials(mp_count_bits(key->dsskey->p));
   56|    112|					assert(mp_prime_is_prime(key->dsskey->p, trials, &pprime) == MP_OKAY);
  ------------------
  |  Branch (56:6): [True: 0, False: 112]
  |  Branch (56:6): [True: 112, False: 0]
  ------------------
   57|    112|					trials = mp_prime_rabin_miller_trials(mp_count_bits(key->dsskey->q));
   58|    112|					assert(mp_prime_is_prime(key->dsskey->q, trials, &qprime) == MP_OKAY);
  ------------------
  |  Branch (58:6): [True: 0, False: 112]
  |  Branch (58:6): [True: 112, False: 0]
  ------------------
   59|    112|					boguskey = !(pprime && qprime);
  ------------------
  |  Branch (59:19): [True: 0, False: 112]
  |  Branch (59:29): [True: 0, False: 0]
  ------------------
   60|       |					/* Could also check g**q mod p == 1 */
   61|    112|				}
   62|       |
   63|    114|				if (keytype == DROPBEAR_SIGNKEY_SK_ED25519 || keytype == DROPBEAR_SIGNKEY_ED25519) {
  ------------------
  |  Branch (63:9): [True: 2, False: 112]
  |  Branch (63:51): [True: 0, False: 112]
  ------------------
   64|      2|					dropbear_ed25519_key **eck = (dropbear_ed25519_key**)signkey_key_ptr(key, keytype);
   65|      2|					if (eck && *eck) {
  ------------------
  |  Branch (65:10): [True: 2, False: 0]
  |  Branch (65:17): [True: 2, False: 0]
  ------------------
   66|      2|						int i;
   67|       |						/* we've seen all-zero keys validate */
   68|      2|						boguskey = 1;
   69|     66|						for (i = 0; i < CURVE25519_LEN; i++) {
  ------------------
  |  |   34|     66|#define CURVE25519_LEN 32
  ------------------
  |  Branch (69:19): [True: 64, False: 2]
  ------------------
   70|     64|							if ((*eck)->priv[i] != 0x00 || (*eck)->pub[i] != 0x00) {
  ------------------
  |  Branch (70:12): [True: 0, False: 64]
  |  Branch (70:39): [True: 0, False: 64]
  ------------------
   71|      0|								boguskey = 0;
   72|      0|							}
   73|     64|						}
   74|       |
   75|      2|					}
   76|      2|				}
   77|       |
   78|    114|				if (!boguskey) {
  ------------------
  |  Branch (78:9): [True: 0, False: 114]
  ------------------
   79|      0|					printf("Random key/signature managed to verify!\n");
   80|      0|					abort();
   81|      0|				}
   82|       |
   83|       |
   84|    114|			}
   85|  1.71k|		}
   86|  2.83k|		sign_key_free(key);
   87|  2.83k|		m_malloc_free_epoch(1, 0);
   88|  2.83k|	} else {
   89|      0|		m_malloc_free_epoch(1, 1);
   90|      0|		TRACE(("dropbear_exit longjmped"))
   91|       |		/* dropbear_exit jumped here */
   92|      0|	}
   93|       |
   94|  2.83k|	return 0;
   95|  2.83k|}
fuzzer-verify.c:setup_fuzzer:
    8|      1|static void setup_fuzzer(void) {
    9|      1|	fuzz_common_setup();
   10|      1|}

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

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

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

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

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

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

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

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

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

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

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

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

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

ltc_ecc_mul2add:
   39|    259|{
   40|    259|  ecc_point     *precomp[16];
   41|    259|  unsigned       bitbufA, bitbufB, lenA, lenB, len, x, y, nA, nB, nibble;
   42|    259|  unsigned char *tA, *tB;
   43|    259|  int            err, first;
   44|    259|  void          *mp, *mu;
   45|       |
   46|       |  /* argchks */
   47|    259|  LTC_ARGCHK(A       != NULL);
  ------------------
  |  |   32|    259|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 259]
  |  |  |  Branch (32:87): [Folded, False: 259]
  |  |  ------------------
  ------------------
   48|    259|  LTC_ARGCHK(B       != NULL);
  ------------------
  |  |   32|    259|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 259]
  |  |  |  Branch (32:87): [Folded, False: 259]
  |  |  ------------------
  ------------------
   49|    259|  LTC_ARGCHK(C       != NULL);
  ------------------
  |  |   32|    259|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 259]
  |  |  |  Branch (32:87): [Folded, False: 259]
  |  |  ------------------
  ------------------
   50|    259|  LTC_ARGCHK(kA      != NULL);
  ------------------
  |  |   32|    259|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 259]
  |  |  |  Branch (32:87): [Folded, False: 259]
  |  |  ------------------
  ------------------
   51|    259|  LTC_ARGCHK(kB      != NULL);
  ------------------
  |  |   32|    259|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 259]
  |  |  |  Branch (32:87): [Folded, False: 259]
  |  |  ------------------
  ------------------
   52|    259|  LTC_ARGCHK(modulus != NULL);
  ------------------
  |  |   32|    259|#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
  |  |  ------------------
  |  |  |  Branch (32:32): [True: 0, False: 259]
  |  |  |  Branch (32:87): [Folded, False: 259]
  |  |  ------------------
  ------------------
   53|       |
   54|       |  /* allocate memory */
   55|    259|  tA = XCALLOC(1, ECC_BUF_SIZE);
  ------------------
  |  |   19|    259|#define XCALLOC m_calloc
  ------------------
                tA = XCALLOC(1, ECC_BUF_SIZE);
  ------------------
  |  |  246|    259|#define ECC_BUF_SIZE 256
  ------------------
   56|    259|  if (tA == NULL) {
  ------------------
  |  Branch (56:7): [True: 0, False: 259]
  ------------------
   57|      0|     return CRYPT_MEM;
   58|      0|  }
   59|    259|  tB = XCALLOC(1, ECC_BUF_SIZE);
  ------------------
  |  |   19|    259|#define XCALLOC m_calloc
  ------------------
                tB = XCALLOC(1, ECC_BUF_SIZE);
  ------------------
  |  |  246|    259|#define ECC_BUF_SIZE 256
  ------------------
   60|    259|  if (tB == NULL) {
  ------------------
  |  Branch (60:7): [True: 0, False: 259]
  ------------------
   61|      0|     XFREE(tA);
  ------------------
  |  |   17|      0|#define XFREE m_free_direct
  ------------------
   62|      0|     return CRYPT_MEM;
   63|      0|  }
   64|       |
   65|       |  /* get sizes */
   66|    259|  lenA = mp_unsigned_bin_size(kA);
  ------------------
  |  |  539|    259|#define mp_unsigned_bin_size(a)      ltc_mp.unsigned_size(a)
  ------------------
   67|    259|  lenB = mp_unsigned_bin_size(kB);
  ------------------
  |  |  539|    259|#define mp_unsigned_bin_size(a)      ltc_mp.unsigned_size(a)
  ------------------
   68|    259|  len  = MAX(lenA, lenB);
  ------------------
  |  |  421|    259|   #define MAX(x, y) ( ((x)>(y))?(x):(y) )
  |  |  ------------------
  |  |  |  Branch (421:24): [True: 72, False: 187]
  |  |  ------------------
  ------------------
   69|       |
   70|       |  /* sanity check */
   71|    259|  if ((lenA > ECC_BUF_SIZE) || (lenB > ECC_BUF_SIZE)) {
  ------------------
  |  |  246|    259|#define ECC_BUF_SIZE 256
  ------------------
                if ((lenA > ECC_BUF_SIZE) || (lenB > ECC_BUF_SIZE)) {
  ------------------
  |  |  246|    259|#define ECC_BUF_SIZE 256
  ------------------
  |  Branch (71:7): [True: 0, False: 259]
  |  Branch (71:32): [True: 0, False: 259]
  ------------------
   72|      0|     err = CRYPT_INVALID_ARG;
   73|      0|     goto ERR_T;
   74|      0|  }
   75|       |
   76|       |  /* extract and justify kA */
   77|    259|  mp_to_unsigned_bin(kA, (len - lenA) + tA);
  ------------------
  |  |  540|    259|#define mp_to_unsigned_bin(a, b)     ltc_mp.unsigned_write(a, b)
  ------------------
   78|       |
   79|       |  /* extract and justify kB */
   80|    259|  mp_to_unsigned_bin(kB, (len - lenB) + tB);
  ------------------
  |  |  540|    259|#define mp_to_unsigned_bin(a, b)     ltc_mp.unsigned_write(a, b)
  ------------------
   81|       |
   82|       |  /* allocate the table */
   83|  4.40k|  for (x = 0; x < 16; x++) {
  ------------------
  |  Branch (83:15): [True: 4.14k, False: 259]
  ------------------
   84|  4.14k|     precomp[x] = ltc_ecc_new_point();
   85|  4.14k|     if (precomp[x] == NULL) {
  ------------------
  |  Branch (85:10): [True: 0, False: 4.14k]
  ------------------
   86|      0|         for (y = 0; y < x; ++y) {
  ------------------
  |  Branch (86:22): [True: 0, False: 0]
  ------------------
   87|      0|            ltc_ecc_del_point(precomp[y]);
   88|      0|         }
   89|      0|         err = CRYPT_MEM;
   90|      0|         goto ERR_T;
   91|      0|     }
   92|  4.14k|  }
   93|       |
   94|       |  /* init montgomery reduction */
   95|    259|  if ((err = mp_montgomery_setup(modulus, &mp)) != CRYPT_OK) {
  ------------------
  |  |  563|    259|#define mp_montgomery_setup(a, b)    ltc_mp.montgomery_setup(a, b)
  ------------------
  |  Branch (95:7): [True: 0, False: 259]
  ------------------
   96|      0|      goto ERR_P;
   97|      0|  }
   98|    259|  if ((err = mp_init(&mu)) != CRYPT_OK) {
  ------------------
  |  |  516|    259|#define mp_init(a)                   ltc_mp.init(a)
  ------------------
  |  Branch (98:7): [True: 0, False: 259]
  ------------------
   99|      0|      goto ERR_MP;
  100|      0|  }
  101|    259|  if ((err = mp_montgomery_normalization(mu, modulus)) != CRYPT_OK) {
  ------------------
  |  |  564|    259|#define mp_montgomery_normalization(a, b) ltc_mp.montgomery_normalization(a, b)
  ------------------
  |  Branch (101:7): [True: 0, False: 259]
  ------------------
  102|      0|      goto ERR_MU;
  103|      0|  }
  104|       |
  105|       |  /* copy ones ... */
  106|    259|  if ((err = mp_mulmod(A->x, mu, modulus, precomp[1]->x)) != CRYPT_OK)                                         { goto ERR_MU; }
  ------------------
  |  |  559|    259|#define mp_mulmod(a, b, c, d)        ltc_mp.mulmod(a, b, c, d)
  ------------------
  |  Branch (106:7): [True: 0, False: 259]
  ------------------
  107|    259|  if ((err = mp_mulmod(A->y, mu, modulus, precomp[1]->y)) != CRYPT_OK)                                         { goto ERR_MU; }
  ------------------
  |  |  559|    259|#define mp_mulmod(a, b, c, d)        ltc_mp.mulmod(a, b, c, d)
  ------------------
  |  Branch (107:7): [True: 0, False: 259]
  ------------------
  108|    259|  if ((err = mp_mulmod(A->z, mu, modulus, precomp[1]->z)) != CRYPT_OK)                                         { goto ERR_MU; }
  ------------------
  |  |  559|    259|#define mp_mulmod(a, b, c, d)        ltc_mp.mulmod(a, b, c, d)
  ------------------
  |  Branch (108:7): [True: 0, False: 259]
  ------------------
  109|       |
  110|    259|  if ((err = mp_mulmod(B->x, mu, modulus, precomp[1<<2]->x)) != CRYPT_OK)                                      { goto ERR_MU; }
  ------------------
  |  |  559|    259|#define mp_mulmod(a, b, c, d)        ltc_mp.mulmod(a, b, c, d)
  ------------------
  |  Branch (110:7): [True: 0, False: 259]
  ------------------
  111|    259|  if ((err = mp_mulmod(B->y, mu, modulus, precomp[1<<2]->y)) != CRYPT_OK)                                      { goto ERR_MU; }
  ------------------
  |  |  559|    259|#define mp_mulmod(a, b, c, d)        ltc_mp.mulmod(a, b, c, d)
  ------------------
  |  Branch (111:7): [True: 0, False: 259]
  ------------------
  112|    259|  if ((err = mp_mulmod(B->z, mu, modulus, precomp[1<<2]->z)) != CRYPT_OK)                                      { goto ERR_MU; }
  ------------------
  |  |  559|    259|#define mp_mulmod(a, b, c, d)        ltc_mp.mulmod(a, b, c, d)
  ------------------
  |  Branch (112:7): [True: 0, False: 259]
  ------------------
  113|       |
  114|       |  /* precomp [i,0](A + B) table */
  115|    259|  if ((err = ltc_mp.ecc_ptdbl(precomp[1], precomp[2], modulus, mp)) != CRYPT_OK)                               { goto ERR_MU; }
  ------------------
  |  Branch (115:7): [True: 0, False: 259]
  ------------------
  116|    259|  if ((err = ltc_mp.ecc_ptadd(precomp[1], precomp[2], precomp[3], modulus, mp)) != CRYPT_OK)                   { goto ERR_MU; }
  ------------------
  |  Branch (116:7): [True: 0, False: 259]
  ------------------
  117|       |
  118|       |  /* precomp [0,i](A + B) table */
  119|    259|  if ((err = ltc_mp.ecc_ptdbl(precomp[1<<2], precomp[2<<2], modulus, mp)) != CRYPT_OK)                         { goto ERR_MU; }
  ------------------
  |  Branch (119:7): [True: 0, False: 259]
  ------------------
  120|    259|  if ((err = ltc_mp.ecc_ptadd(precomp[1<<2], precomp[2<<2], precomp[3<<2], modulus, mp)) != CRYPT_OK)          { goto ERR_MU; }
  ------------------
  |  Branch (120:7): [True: 0, False: 259]
  ------------------
  121|       |
  122|       |  /* precomp [i,j](A + B) table (i != 0, j != 0) */
  123|  1.03k|  for (x = 1; x < 4; x++) {
  ------------------
  |  Branch (123:15): [True: 777, False: 259]
  ------------------
  124|  3.10k|     for (y = 1; y < 4; y++) {
  ------------------
  |  Branch (124:18): [True: 2.33k, False: 777]
  ------------------
  125|  2.33k|        if ((err = ltc_mp.ecc_ptadd(precomp[x], precomp[(y<<2)], precomp[x+(y<<2)], modulus, mp)) != CRYPT_OK) { goto ERR_MU; }
  ------------------
  |  Branch (125:13): [True: 0, False: 2.33k]
  ------------------
  126|  2.33k|     }
  127|    777|  }
  128|       |
  129|    259|  nibble  = 3;
  130|    259|  first   = 1;
  131|    259|  bitbufA = tA[0];
  132|    259|  bitbufB = tB[0];
  133|       |
  134|       |  /* for every byte of the multiplicands */
  135|  43.8k|  for (x = 0;; ) {
  136|       |     /* grab a nibble */
  137|  43.8k|     if (++nibble == 4) {
  ------------------
  |  Branch (137:10): [True: 11.1k, False: 32.6k]
  ------------------
  138|  11.1k|        if (x == len) break;
  ------------------
  |  Branch (138:13): [True: 259, False: 10.8k]
  ------------------
  139|  10.8k|        bitbufA = tA[x];
  140|  10.8k|        bitbufB = tB[x];
  141|  10.8k|        nibble  = 0;
  142|  10.8k|        ++x;
  143|  10.8k|     }
  144|       |
  145|       |     /* extract two bits from both, shift/update */
  146|  43.5k|     nA = (bitbufA >> 6) & 0x03;
  147|  43.5k|     nB = (bitbufB >> 6) & 0x03;
  148|  43.5k|     bitbufA = (bitbufA << 2) & 0xFF;
  149|  43.5k|     bitbufB = (bitbufB << 2) & 0xFF;
  150|       |
  151|       |     /* if both zero, if first, continue */
  152|  43.5k|     if ((nA == 0) && (nB == 0) && (first == 1)) {
  ------------------
  |  Branch (152:10): [True: 10.9k, False: 32.5k]
  |  Branch (152:23): [True: 4.34k, False: 6.63k]
  |  Branch (152:36): [True: 183, False: 4.16k]
  ------------------
  153|    183|        continue;
  154|    183|     }
  155|       |
  156|       |     /* double twice, only if this isn't the first */
  157|  43.3k|     if (first == 0) {
  ------------------
  |  Branch (157:10): [True: 43.1k, False: 259]
  ------------------
  158|       |        /* double twice */
  159|  43.1k|        if ((err = ltc_mp.ecc_ptdbl(C, C, modulus, mp)) != CRYPT_OK)                  { goto ERR_MU; }
  ------------------
  |  Branch (159:13): [True: 0, False: 43.1k]
  ------------------
  160|  43.1k|        if ((err = ltc_mp.ecc_ptdbl(C, C, modulus, mp)) != CRYPT_OK)                  { goto ERR_MU; }
  ------------------
  |  Branch (160:13): [True: 0, False: 43.1k]
  ------------------
  161|  43.1k|     }
  162|       |
  163|       |     /* if not both zero */
  164|  43.3k|     if ((nA != 0) || (nB != 0)) {
  ------------------
  |  Branch (164:10): [True: 32.5k, False: 10.8k]
  |  Branch (164:23): [True: 6.63k, False: 4.16k]
  ------------------
  165|  39.2k|        if (first == 1) {
  ------------------
  |  Branch (165:13): [True: 259, False: 38.9k]
  ------------------
  166|       |           /* if first, copy from table */
  167|    259|           first = 0;
  168|    259|           if ((err = mp_copy(precomp[nA + (nB<<2)]->x, C->x)) != CRYPT_OK)           { goto ERR_MU; }
  ------------------
  |  |  524|    259|#define mp_copy(a, b)                ltc_mp.copy(a, b)
  ------------------
  |  Branch (168:16): [True: 0, False: 259]
  ------------------
  169|    259|           if ((err = mp_copy(precomp[nA + (nB<<2)]->y, C->y)) != CRYPT_OK)           { goto ERR_MU; }
  ------------------
  |  |  524|    259|#define mp_copy(a, b)                ltc_mp.copy(a, b)
  ------------------
  |  Branch (169:16): [True: 0, False: 259]
  ------------------
  170|    259|           if ((err = mp_copy(precomp[nA + (nB<<2)]->z, C->z)) != CRYPT_OK)           { goto ERR_MU; }
  ------------------
  |  |  524|    259|#define mp_copy(a, b)                ltc_mp.copy(a, b)
  ------------------
  |  Branch (170:16): [True: 0, False: 259]
  ------------------
  171|  38.9k|        } else {
  172|       |           /* if not first, add from table */
  173|  38.9k|           if ((err = ltc_mp.ecc_ptadd(C, precomp[nA + (nB<<2)], C, modulus, mp)) != CRYPT_OK) { goto ERR_MU; }
  ------------------
  |  Branch (173:16): [True: 0, False: 38.9k]
  ------------------
  174|  38.9k|        }
  175|  39.2k|     }
  176|  43.3k|  }
  177|       |
  178|       |  /* reduce to affine */
  179|    259|  err = ltc_ecc_map(C, modulus, mp);
  180|       |
  181|       |  /* clean up */
  182|    259|ERR_MU:
  183|    259|   mp_clear(mu);
  ------------------
  |  |  518|    259|#define mp_clear(a)                  ltc_mp.deinit(a)
  ------------------
  184|    259|ERR_MP:
  185|    259|   mp_montgomery_free(mp);
  ------------------
  |  |  566|    259|#define mp_montgomery_free(a)        ltc_mp.montgomery_deinit(a)
  ------------------
  186|    259|ERR_P:
  187|  4.40k|   for (x = 0; x < 16; x++) {
  ------------------
  |  Branch (187:16): [True: 4.14k, False: 259]
  ------------------
  188|  4.14k|       ltc_ecc_del_point(precomp[x]);
  189|  4.14k|   }
  190|    259|ERR_T:
  191|       |#ifdef LTC_CLEAN_STACK
  192|       |   zeromem(tA, ECC_BUF_SIZE);
  193|       |   zeromem(tB, ECC_BUF_SIZE);
  194|       |#endif
  195|    259|   XFREE(tA);
  ------------------
  |  |   17|    259|#define XFREE m_free_direct
  ------------------
  196|    259|   XFREE(tB);
  ------------------
  |  |   17|    259|#define XFREE m_free_direct
  ------------------
  197|       |
  198|    259|   return err;
  199|    259|}

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

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

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

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

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

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

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

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

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

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

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

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

mp_cnt_lsb:
   12|  2.14k|{
   13|  2.14k|   int x;
   14|  2.14k|   mp_digit q, qq;
   15|       |
   16|       |   /* easy out */
   17|  2.14k|   if (MP_IS_ZERO(a)) {
  ------------------
  |  |  163|  2.14k|#define MP_IS_ZERO(a) ((a)->used == 0)
  |  |  ------------------
  |  |  |  Branch (163:23): [True: 0, False: 2.14k]
  |  |  ------------------
  ------------------
   18|      0|      return 0;
   19|      0|   }
   20|       |
   21|       |   /* scan lower digits until non-zero */
   22|  3.42k|   for (x = 0; (x < a->used) && (a->dp[x] == 0u); x++) {}
  ------------------
  |  Branch (22:16): [True: 3.42k, False: 0]
  |  Branch (22:33): [True: 1.28k, False: 2.14k]
  ------------------
   23|  2.14k|   q = a->dp[x];
   24|  2.14k|   x *= MP_DIGIT_BIT;
  ------------------
  |  |   82|  2.14k|#   define MP_DIGIT_BIT 60
  ------------------
   25|       |
   26|       |   /* now scan this digit until a 1 is found */
   27|  2.14k|   if ((q & 1u) == 0u) {
  ------------------
  |  Branch (27:8): [True: 1.76k, False: 377]
  ------------------
   28|  7.12k|      do {
   29|  7.12k|         qq  = q & 15u;
   30|  7.12k|         x  += lnz[qq];
   31|  7.12k|         q >>= 4;
   32|  7.12k|      } while (qq == 0u);
  ------------------
  |  Branch (32:16): [True: 5.36k, False: 1.76k]
  ------------------
   33|  1.76k|   }
   34|  2.14k|   return x;
   35|  2.14k|}

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

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

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

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

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

mp_div_3:
    8|    137|{
    9|    137|   mp_int   q;
   10|    137|   mp_word  w, t;
   11|    137|   mp_digit b;
   12|    137|   mp_err   err;
   13|    137|   int      ix;
   14|       |
   15|       |   /* b = 2**MP_DIGIT_BIT / 3 */
   16|    137|   b = ((mp_word)1 << (mp_word)MP_DIGIT_BIT) / (mp_word)3;
  ------------------
  |  |   82|    137|#   define MP_DIGIT_BIT 60
  ------------------
   17|       |
   18|    137|   if ((err = mp_init_size(&q, a->used)) != MP_OKAY) {
  ------------------
  |  |  161|    137|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (18:8): [True: 0, False: 137]
  ------------------
   19|      0|      return err;
   20|      0|   }
   21|       |
   22|    137|   q.used = a->used;
   23|    137|   q.sign = a->sign;
   24|    137|   w = 0;
   25|    953|   for (ix = a->used - 1; ix >= 0; ix--) {
  ------------------
  |  Branch (25:27): [True: 816, False: 137]
  ------------------
   26|    816|      w = (w << (mp_word)MP_DIGIT_BIT) | (mp_word)a->dp[ix];
  ------------------
  |  |   82|    816|#   define MP_DIGIT_BIT 60
  ------------------
   27|       |
   28|    816|      if (w >= 3u) {
  ------------------
  |  Branch (28:11): [True: 703, False: 113]
  ------------------
   29|       |         /* multiply w by [1/3] */
   30|    703|         t = (w * (mp_word)b) >> (mp_word)MP_DIGIT_BIT;
  ------------------
  |  |   82|    703|#   define MP_DIGIT_BIT 60
  ------------------
   31|       |
   32|       |         /* now subtract 3 * [w/3] from w, to get the remainder */
   33|    703|         w -= t+t+t;
   34|       |
   35|       |         /* fixup the remainder as required since
   36|       |          * the optimization is not exact.
   37|       |          */
   38|  1.11k|         while (w >= 3u) {
  ------------------
  |  Branch (38:17): [True: 412, False: 703]
  ------------------
   39|    412|            t += 1u;
   40|    412|            w -= 3u;
   41|    412|         }
   42|    703|      } else {
   43|    113|         t = 0;
   44|    113|      }
   45|    816|      q.dp[ix] = (mp_digit)t;
   46|    816|   }
   47|       |
   48|       |   /* [optional] store the remainder */
   49|    137|   if (d != NULL) {
  ------------------
  |  Branch (49:8): [True: 137, False: 0]
  ------------------
   50|    137|      *d = (mp_digit)w;
   51|    137|   }
   52|       |
   53|       |   /* [optional] store the quotient */
   54|    137|   if (c != NULL) {
  ------------------
  |  Branch (54:8): [True: 0, False: 137]
  ------------------
   55|      0|      mp_clamp(&q);
   56|      0|      mp_exch(&q, c);
   57|      0|   }
   58|    137|   mp_clear(&q);
   59|       |
   60|    137|   return err;
   61|    137|}

mp_div_d:
    8|  24.4k|{
    9|  24.4k|   mp_int  q;
   10|  24.4k|   mp_word w;
   11|  24.4k|   mp_digit t;
   12|  24.4k|   mp_err err;
   13|  24.4k|   int ix;
   14|       |
   15|       |   /* cannot divide by zero */
   16|  24.4k|   if (b == 0u) {
  ------------------
  |  Branch (16:8): [True: 0, False: 24.4k]
  ------------------
   17|      0|      return MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
   18|      0|   }
   19|       |
   20|       |   /* quick outs */
   21|  24.4k|   if ((b == 1u) || MP_IS_ZERO(a)) {
  ------------------
  |  |  163|  24.4k|#define MP_IS_ZERO(a) ((a)->used == 0)
  |  |  ------------------
  |  |  |  Branch (163:23): [True: 0, False: 24.4k]
  |  |  ------------------
  ------------------
  |  Branch (21:8): [True: 0, False: 24.4k]
  ------------------
   22|      0|      if (d != NULL) {
  ------------------
  |  Branch (22:11): [True: 0, False: 0]
  ------------------
   23|      0|         *d = 0;
   24|      0|      }
   25|      0|      if (c != NULL) {
  ------------------
  |  Branch (25:11): [True: 0, False: 0]
  ------------------
   26|      0|         return mp_copy(a, c);
   27|      0|      }
   28|      0|      return MP_OKAY;
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
   29|      0|   }
   30|       |
   31|       |   /* power of two ? */
   32|  24.4k|   if ((b & (b - 1u)) == 0u) {
  ------------------
  |  Branch (32:8): [True: 137, False: 24.3k]
  ------------------
   33|    137|      ix = 1;
   34|    137|      while ((ix < MP_DIGIT_BIT) && (b != (((mp_digit)1)<<ix))) {
  ------------------
  |  |   82|    137|#   define MP_DIGIT_BIT 60
  ------------------
  |  Branch (34:14): [True: 137, False: 0]
  |  Branch (34:37): [True: 0, False: 137]
  ------------------
   35|      0|         ix++;
   36|      0|      }
   37|    137|      if (d != NULL) {
  ------------------
  |  Branch (37:11): [True: 137, False: 0]
  ------------------
   38|    137|         *d = a->dp[0] & (((mp_digit)1<<(mp_digit)ix) - 1uL);
   39|    137|      }
   40|    137|      if (c != NULL) {
  ------------------
  |  Branch (40:11): [True: 0, False: 137]
  ------------------
   41|      0|         return mp_div_2d(a, ix, c, NULL);
   42|      0|      }
   43|    137|      return MP_OKAY;
  ------------------
  |  |  161|    137|#define MP_OKAY       0   /* no error */
  ------------------
   44|    137|   }
   45|       |
   46|       |   /* three? */
   47|  24.3k|   if (MP_HAS(MP_DIV_3) && (b == 3u)) {
  ------------------
  |  |  150|  48.6k|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|  24.3k|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|  24.3k|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [True: 24.3k, Folded]
  |  |  ------------------
  ------------------
  |  Branch (47:28): [True: 137, False: 24.1k]
  ------------------
   48|    137|      return mp_div_3(a, c, d);
   49|    137|   }
   50|       |
   51|       |   /* no easy answer [c'est la vie].  Just division */
   52|  24.1k|   if ((err = mp_init_size(&q, a->used)) != MP_OKAY) {
  ------------------
  |  |  161|  24.1k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (52:8): [True: 0, False: 24.1k]
  ------------------
   53|      0|      return err;
   54|      0|   }
   55|       |
   56|  24.1k|   q.used = a->used;
   57|  24.1k|   q.sign = a->sign;
   58|  24.1k|   w = 0;
   59|   105k|   for (ix = a->used - 1; ix >= 0; ix--) {
  ------------------
  |  Branch (59:27): [True: 81.0k, False: 24.1k]
  ------------------
   60|  81.0k|      w = (w << (mp_word)MP_DIGIT_BIT) | (mp_word)a->dp[ix];
  ------------------
  |  |   82|  81.0k|#   define MP_DIGIT_BIT 60
  ------------------
   61|       |
   62|  81.0k|      if (w >= b) {
  ------------------
  |  Branch (62:11): [True: 80.4k, False: 665]
  ------------------
   63|  80.4k|         t = (mp_digit)(w / b);
   64|  80.4k|         w -= (mp_word)t * (mp_word)b;
   65|  80.4k|      } else {
   66|    665|         t = 0;
   67|    665|      }
   68|  81.0k|      q.dp[ix] = t;
   69|  81.0k|   }
   70|       |
   71|  24.1k|   if (d != NULL) {
  ------------------
  |  Branch (71:8): [True: 24.1k, False: 0]
  ------------------
   72|  24.1k|      *d = (mp_digit)w;
   73|  24.1k|   }
   74|       |
   75|  24.1k|   if (c != NULL) {
  ------------------
  |  Branch (75:8): [True: 0, False: 24.1k]
  ------------------
   76|      0|      mp_clamp(&q);
   77|      0|      mp_exch(&q, c);
   78|      0|   }
   79|  24.1k|   mp_clear(&q);
   80|       |
   81|  24.1k|   return err;
   82|  24.1k|}

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

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

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

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

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

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

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

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

mp_init_set:
    8|     91|{
    9|     91|   mp_err err;
   10|     91|   if ((err = mp_init(a)) != MP_OKAY) {
  ------------------
  |  |  161|     91|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (10:8): [True: 0, False: 91]
  ------------------
   11|      0|      return err;
   12|      0|   }
   13|     91|   mp_set(a, b);
   14|     91|   return err;
   15|     91|}

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

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

mp_is_square:
   30|    138|{
   31|    138|   mp_err        err;
   32|    138|   mp_digit      c;
   33|    138|   mp_int        t;
   34|    138|   unsigned long r;
   35|       |
   36|       |   /* Default to Non-square :) */
   37|    138|   *ret = MP_NO;
  ------------------
  |  |  159|    138|#define MP_NO         0
  ------------------
   38|       |
   39|    138|   if (arg->sign == MP_NEG) {
  ------------------
  |  |  152|    138|#define MP_NEG        1   /* negative */
  ------------------
  |  Branch (39:8): [True: 0, False: 138]
  ------------------
   40|      0|      return MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
   41|      0|   }
   42|       |
   43|    138|   if (MP_IS_ZERO(arg)) {
  ------------------
  |  |  163|    138|#define MP_IS_ZERO(a) ((a)->used == 0)
  |  |  ------------------
  |  |  |  Branch (163:23): [True: 0, False: 138]
  |  |  ------------------
  ------------------
   44|      0|      return MP_OKAY;
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
   45|      0|   }
   46|       |
   47|       |   /* First check mod 128 (suppose that MP_DIGIT_BIT is at least 7) */
   48|    138|   if (rem_128[127u & arg->dp[0]] == (char)1) {
  ------------------
  |  Branch (48:8): [True: 18, False: 120]
  ------------------
   49|     18|      return MP_OKAY;
  ------------------
  |  |  161|     18|#define MP_OKAY       0   /* no error */
  ------------------
   50|     18|   }
   51|       |
   52|       |   /* Next check mod 105 (3*5*7) */
   53|    120|   if ((err = mp_mod_d(arg, 105uL, &c)) != MP_OKAY) {
  ------------------
  |  |  161|    120|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (53:8): [True: 0, False: 120]
  ------------------
   54|      0|      return err;
   55|      0|   }
   56|    120|   if (rem_105[c] == (char)1) {
  ------------------
  |  Branch (56:8): [True: 86, False: 34]
  ------------------
   57|     86|      return MP_OKAY;
  ------------------
  |  |  161|     86|#define MP_OKAY       0   /* no error */
  ------------------
   58|     86|   }
   59|       |
   60|       |
   61|     34|   if ((err = mp_init_u32(&t, 11u*13u*17u*19u*23u*29u*31u)) != MP_OKAY) {
  ------------------
  |  |  161|     34|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (61:8): [True: 0, False: 34]
  ------------------
   62|      0|      return err;
   63|      0|   }
   64|     34|   if ((err = mp_mod(arg, &t, &t)) != MP_OKAY) {
  ------------------
  |  |  161|     34|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (64:8): [True: 0, False: 34]
  ------------------
   65|      0|      goto LBL_ERR;
   66|      0|   }
   67|     34|   r = mp_get_u32(&t);
  ------------------
  |  |  310|     34|#define mp_get_u32(a) ((uint32_t)mp_get_i32(a))
  ------------------
   68|       |   /* Check for other prime modules, note it's not an ERROR but we must
   69|       |    * free "t" so the easiest way is to goto LBL_ERR.  We know that err
   70|       |    * is already equal to MP_OKAY from the mp_mod call
   71|       |    */
   72|     34|   if (((1uL<<(r%11uL)) & 0x5C4uL) != 0uL)         goto LBL_ERR;
  ------------------
  |  Branch (72:8): [True: 8, False: 26]
  ------------------
   73|     26|   if (((1uL<<(r%13uL)) & 0x9E4uL) != 0uL)         goto LBL_ERR;
  ------------------
  |  Branch (73:8): [True: 8, False: 18]
  ------------------
   74|     18|   if (((1uL<<(r%17uL)) & 0x5CE8uL) != 0uL)        goto LBL_ERR;
  ------------------
  |  Branch (74:8): [True: 3, False: 15]
  ------------------
   75|     15|   if (((1uL<<(r%19uL)) & 0x4F50CuL) != 0uL)       goto LBL_ERR;
  ------------------
  |  Branch (75:8): [True: 6, False: 9]
  ------------------
   76|      9|   if (((1uL<<(r%23uL)) & 0x7ACCA0uL) != 0uL)      goto LBL_ERR;
  ------------------
  |  Branch (76:8): [True: 1, False: 8]
  ------------------
   77|      8|   if (((1uL<<(r%29uL)) & 0xC2EDD0CuL) != 0uL)     goto LBL_ERR;
  ------------------
  |  Branch (77:8): [True: 1, False: 7]
  ------------------
   78|      7|   if (((1uL<<(r%31uL)) & 0x6DE2B848uL) != 0uL)    goto LBL_ERR;
  ------------------
  |  Branch (78:8): [True: 1, False: 6]
  ------------------
   79|       |
   80|       |   /* Final check - is sqr(sqrt(arg)) == arg ? */
   81|      6|   if ((err = mp_sqrt(arg, &t)) != MP_OKAY) {
  ------------------
  |  |  161|      6|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (81:8): [True: 0, False: 6]
  ------------------
   82|      0|      goto LBL_ERR;
   83|      0|   }
   84|      6|   if ((err = mp_sqr(&t, &t)) != MP_OKAY) {
  ------------------
  |  |  161|      6|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (84:8): [True: 0, False: 6]
  ------------------
   85|      0|      goto LBL_ERR;
   86|      0|   }
   87|       |
   88|      6|   *ret = (mp_cmp_mag(&t, arg) == MP_EQ) ? MP_YES : MP_NO;
  ------------------
  |  |  155|      6|#define MP_EQ         0   /* equal to */
  ------------------
                 *ret = (mp_cmp_mag(&t, arg) == MP_EQ) ? MP_YES : MP_NO;
  ------------------
  |  |  158|      1|#define MP_YES        1
  ------------------
                 *ret = (mp_cmp_mag(&t, arg) == MP_EQ) ? MP_YES : MP_NO;
  ------------------
  |  |  159|     11|#define MP_NO         0
  ------------------
  |  Branch (88:11): [True: 1, False: 5]
  ------------------
   89|     34|LBL_ERR:
   90|     34|   mp_clear(&t);
   91|     34|   return err;
   92|      6|}

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

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

mp_mod_2d:
    8|  2.67M|{
    9|  2.67M|   int x;
   10|  2.67M|   mp_err err;
   11|       |
   12|       |   /* if b is <= 0 then zero the int */
   13|  2.67M|   if (b <= 0) {
  ------------------
  |  Branch (13:8): [True: 0, False: 2.67M]
  ------------------
   14|      0|      mp_zero(c);
   15|      0|      return MP_OKAY;
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
   16|      0|   }
   17|       |
   18|       |   /* if the modulus is larger than the value than return */
   19|  2.67M|   if (b >= (a->used * MP_DIGIT_BIT)) {
  ------------------
  |  |   82|  2.67M|#   define MP_DIGIT_BIT 60
  ------------------
  |  Branch (19:8): [True: 32.2k, False: 2.63M]
  ------------------
   20|  32.2k|      return mp_copy(a, c);
   21|  32.2k|   }
   22|       |
   23|       |   /* copy */
   24|  2.63M|   if ((err = mp_copy(a, c)) != MP_OKAY) {
  ------------------
  |  |  161|  2.63M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (24:8): [True: 0, False: 2.63M]
  ------------------
   25|      0|      return err;
   26|      0|   }
   27|       |
   28|       |   /* zero digits above the last digit of the modulus */
   29|  2.63M|   x = (b / MP_DIGIT_BIT) + (((b % MP_DIGIT_BIT) == 0) ? 0 : 1);
  ------------------
  |  |   82|  2.63M|#   define MP_DIGIT_BIT 60
  ------------------
                 x = (b / MP_DIGIT_BIT) + (((b % MP_DIGIT_BIT) == 0) ? 0 : 1);
  ------------------
  |  |   82|  2.63M|#   define MP_DIGIT_BIT 60
  ------------------
  |  Branch (29:30): [True: 93.4k, False: 2.54M]
  ------------------
   30|  2.63M|   MP_ZERO_DIGITS(c->dp + x, c->used - x);
  ------------------
  |  |   89|  2.63M|#  define MP_ZERO_DIGITS(mem, digits)                   \
  |  |   90|  2.63M|do {                                                    \
  |  |   91|  2.63M|   int zd_ = (digits);                                  \
  |  |   92|  2.63M|   mp_digit* zm_ = (mem);                               \
  |  |   93|  29.6M|   while (zd_-- > 0) {                                  \
  |  |  ------------------
  |  |  |  Branch (93:11): [True: 27.0M, False: 2.63M]
  |  |  ------------------
  |  |   94|  27.0M|      *zm_++ = 0;                                       \
  |  |   95|  27.0M|   }                                                    \
  |  |   96|  2.63M|} while (0)
  |  |  ------------------
  |  |  |  Branch (96:10): [Folded, False: 2.63M]
  |  |  ------------------
  ------------------
   31|       |
   32|       |   /* clear the digit that is not completely outside/inside the modulus */
   33|  2.63M|   c->dp[b / MP_DIGIT_BIT] &=
  ------------------
  |  |   82|  2.63M|#   define MP_DIGIT_BIT 60
  ------------------
   34|  2.63M|      ((mp_digit)1 << (mp_digit)(b % MP_DIGIT_BIT)) - (mp_digit)1;
  ------------------
  |  |   82|  2.63M|#   define MP_DIGIT_BIT 60
  ------------------
   35|  2.63M|   mp_clamp(c);
   36|  2.63M|   return MP_OKAY;
  ------------------
  |  |  161|  2.63M|#define MP_OKAY       0   /* no error */
  ------------------
   37|  2.63M|}

mp_mod_d:
    7|  24.4k|{
    8|       |   return mp_div_d(a, b, NULL, c);
    9|  24.4k|}

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

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

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

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

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

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

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

mp_prime_is_prime:
   18|    224|{
   19|    224|   mp_int  b;
   20|    224|   int     ix, p_max = 0, size_a, len;
   21|    224|   mp_bool res;
   22|    224|   mp_err  err;
   23|    224|   unsigned int fips_rand, mask;
   24|       |
   25|       |   /* default to no */
   26|    224|   *result = MP_NO;
  ------------------
  |  |  159|    224|#define MP_NO         0
  ------------------
   27|       |
   28|       |   /* Some shortcuts */
   29|       |   /* N > 3 */
   30|    224|   if (a->used == 1) {
  ------------------
  |  Branch (30:8): [True: 0, False: 224]
  ------------------
   31|      0|      if ((a->dp[0] == 0u) || (a->dp[0] == 1u)) {
  ------------------
  |  Branch (31:11): [True: 0, False: 0]
  |  Branch (31:31): [True: 0, False: 0]
  ------------------
   32|      0|         *result = MP_NO;
  ------------------
  |  |  159|      0|#define MP_NO         0
  ------------------
   33|      0|         return MP_OKAY;
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
   34|      0|      }
   35|      0|      if (a->dp[0] == 2u) {
  ------------------
  |  Branch (35:11): [True: 0, False: 0]
  ------------------
   36|      0|         *result = MP_YES;
  ------------------
  |  |  158|      0|#define MP_YES        1
  ------------------
   37|      0|         return MP_OKAY;
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
   38|      0|      }
   39|      0|   }
   40|       |
   41|       |   /* N must be odd */
   42|    224|   if (MP_IS_EVEN(a)) {
  ------------------
  |  |  164|    224|#define MP_IS_EVEN(a) (((a)->used == 0) || (((a)->dp[0] & 1u) == 0u))
  |  |  ------------------
  |  |  |  Branch (164:24): [True: 0, False: 224]
  |  |  |  Branch (164:44): [True: 86, False: 138]
  |  |  ------------------
  ------------------
   43|     86|      return MP_OKAY;
  ------------------
  |  |  161|     86|#define MP_OKAY       0   /* no error */
  ------------------
   44|     86|   }
   45|       |   /* N is not a perfect square: floor(sqrt(N))^2 != N */
   46|    138|   if ((err = mp_is_square(a, &res)) != MP_OKAY) {
  ------------------
  |  |  161|    138|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (46:8): [True: 0, False: 138]
  ------------------
   47|      0|      return err;
   48|      0|   }
   49|    138|   if (res != MP_NO) {
  ------------------
  |  |  159|    138|#define MP_NO         0
  ------------------
  |  Branch (49:8): [True: 1, False: 137]
  ------------------
   50|      1|      return MP_OKAY;
  ------------------
  |  |  161|      1|#define MP_OKAY       0   /* no error */
  ------------------
   51|      1|   }
   52|       |
   53|       |   /* is the input equal to one of the primes in the table? */
   54|  35.2k|   for (ix = 0; ix < PRIVATE_MP_PRIME_TAB_SIZE; ix++) {
  ------------------
  |  |  633|  35.2k|#  define PRIVATE_MP_PRIME_TAB_SIZE 256
  ------------------
  |  Branch (54:17): [True: 35.0k, False: 137]
  ------------------
   55|  35.0k|      if (mp_cmp_d(a, s_mp_prime_tab[ix]) == MP_EQ) {
  ------------------
  |  |  155|  35.0k|#define MP_EQ         0   /* equal to */
  ------------------
  |  Branch (55:11): [True: 0, False: 35.0k]
  ------------------
   56|      0|         *result = MP_YES;
  ------------------
  |  |  158|      0|#define MP_YES        1
  ------------------
   57|      0|         return MP_OKAY;
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
   58|      0|      }
   59|  35.0k|   }
   60|       |#ifdef MP_8BIT
   61|       |   /* The search in the loop above was exhaustive in this case */
   62|       |   if ((a->used == 1) && (PRIVATE_MP_PRIME_TAB_SIZE >= 31)) {
   63|       |      return MP_OKAY;
   64|       |   }
   65|       |#endif
   66|       |
   67|       |   /* first perform trial division */
   68|    137|   if ((err = s_mp_prime_is_divisible(a, &res)) != MP_OKAY) {
  ------------------
  |  |  161|    137|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (68:8): [True: 0, False: 137]
  ------------------
   69|      0|      return err;
   70|      0|   }
   71|       |
   72|       |   /* return if it was trivially divisible */
   73|    137|   if (res == MP_YES) {
  ------------------
  |  |  158|    137|#define MP_YES        1
  ------------------
  |  Branch (73:8): [True: 46, False: 91]
  ------------------
   74|     46|      return MP_OKAY;
  ------------------
  |  |  161|     46|#define MP_OKAY       0   /* no error */
  ------------------
   75|     46|   }
   76|       |
   77|       |   /*
   78|       |       Run the Miller-Rabin test with base 2 for the BPSW test.
   79|       |    */
   80|     91|   if ((err = mp_init_set(&b, 2uL)) != MP_OKAY) {
  ------------------
  |  |  161|     91|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (80:8): [True: 0, False: 91]
  ------------------
   81|      0|      return err;
   82|      0|   }
   83|       |
   84|     91|   if ((err = mp_prime_miller_rabin(a, &b, &res)) != MP_OKAY) {
  ------------------
  |  |  161|     91|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (84:8): [True: 0, False: 91]
  ------------------
   85|      0|      goto LBL_B;
   86|      0|   }
   87|     91|   if (res == MP_NO) {
  ------------------
  |  |  159|     91|#define MP_NO         0
  ------------------
  |  Branch (87:8): [True: 34, False: 57]
  ------------------
   88|     34|      goto LBL_B;
   89|     34|   }
   90|       |   /*
   91|       |      Rumours have it that Mathematica does a second M-R test with base 3.
   92|       |      Other rumours have it that their strong L-S test is slightly different.
   93|       |      It does not hurt, though, beside a bit of extra runtime.
   94|       |   */
   95|     57|   b.dp[0]++;
   96|     57|   if ((err = mp_prime_miller_rabin(a, &b, &res)) != MP_OKAY) {
  ------------------
  |  |  161|     57|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (96:8): [True: 0, False: 57]
  ------------------
   97|      0|      goto LBL_B;
   98|      0|   }
   99|     57|   if (res == MP_NO) {
  ------------------
  |  |  159|     57|#define MP_NO         0
  ------------------
  |  Branch (99:8): [True: 0, False: 57]
  ------------------
  100|      0|      goto LBL_B;
  101|      0|   }
  102|       |
  103|       |   /*
  104|       |    * Both, the Frobenius-Underwood test and the the Lucas-Selfridge test are quite
  105|       |    * slow so if speed is an issue, define LTM_USE_ONLY_MR to use M-R tests with
  106|       |    * bases 2, 3 and t random bases.
  107|       |    */
  108|       |#ifndef LTM_USE_ONLY_MR
  109|       |   if (t >= 0) {
  110|       |      /*
  111|       |       * Use a Frobenius-Underwood test instead of the Lucas-Selfridge test for
  112|       |       * MP_8BIT (It is unknown if the Lucas-Selfridge test works with 16-bit
  113|       |       * integers but the necesssary analysis is on the todo-list).
  114|       |       */
  115|       |#if defined (MP_8BIT) || defined (LTM_USE_FROBENIUS_TEST)
  116|       |      err = mp_prime_frobenius_underwood(a, &res);
  117|       |      if ((err != MP_OKAY) && (err != MP_ITER)) {
  118|       |         goto LBL_B;
  119|       |      }
  120|       |      if (res == MP_NO) {
  121|       |         goto LBL_B;
  122|       |      }
  123|       |#else
  124|       |      if ((err = mp_prime_strong_lucas_selfridge(a, &res)) != MP_OKAY) {
  125|       |         goto LBL_B;
  126|       |      }
  127|       |      if (res == MP_NO) {
  128|       |         goto LBL_B;
  129|       |      }
  130|       |#endif
  131|       |   }
  132|       |#endif
  133|       |
  134|       |   /* run at least one Miller-Rabin test with a random base */
  135|     57|   if (t == 0) {
  ------------------
  |  Branch (135:8): [True: 0, False: 57]
  ------------------
  136|      0|      t = 1;
  137|      0|   }
  138|       |
  139|       |   /*
  140|       |      Only recommended if the input range is known to be < 3317044064679887385961981
  141|       |
  142|       |      It uses the bases necessary for a deterministic M-R test if the input is
  143|       |      smaller than  3317044064679887385961981
  144|       |      The caller has to check the size.
  145|       |      TODO: can be made a bit finer grained but comparing is not free.
  146|       |   */
  147|     57|   if (t < 0) {
  ------------------
  |  Branch (147:8): [True: 0, False: 57]
  ------------------
  148|       |      /*
  149|       |          Sorenson, Jonathan; Webster, Jonathan (2015).
  150|       |           "Strong Pseudoprimes to Twelve Prime Bases".
  151|       |       */
  152|       |      /* 0x437ae92817f9fc85b7e5 = 318665857834031151167461 */
  153|      0|      if ((err =   mp_read_radix(&b, "437ae92817f9fc85b7e5", 16)) != MP_OKAY) {
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (153:11): [True: 0, False: 0]
  ------------------
  154|      0|         goto LBL_B;
  155|      0|      }
  156|       |
  157|      0|      if (mp_cmp(a, &b) == MP_LT) {
  ------------------
  |  |  154|      0|#define MP_LT        -1   /* less than */
  ------------------
  |  Branch (157:11): [True: 0, False: 0]
  ------------------
  158|      0|         p_max = 12;
  159|      0|      } else {
  160|       |         /* 0x2be6951adc5b22410a5fd = 3317044064679887385961981 */
  161|      0|         if ((err = mp_read_radix(&b, "2be6951adc5b22410a5fd", 16)) != MP_OKAY) {
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (161:14): [True: 0, False: 0]
  ------------------
  162|      0|            goto LBL_B;
  163|      0|         }
  164|       |
  165|      0|         if (mp_cmp(a, &b) == MP_LT) {
  ------------------
  |  |  154|      0|#define MP_LT        -1   /* less than */
  ------------------
  |  Branch (165:14): [True: 0, False: 0]
  ------------------
  166|      0|            p_max = 13;
  167|      0|         } else {
  168|      0|            err = MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
  169|      0|            goto LBL_B;
  170|      0|         }
  171|      0|      }
  172|       |
  173|       |      /* we did bases 2 and 3  already, skip them */
  174|      0|      for (ix = 2; ix < p_max; ix++) {
  ------------------
  |  Branch (174:20): [True: 0, False: 0]
  ------------------
  175|      0|         mp_set(&b, s_mp_prime_tab[ix]);
  176|      0|         if ((err = mp_prime_miller_rabin(a, &b, &res)) != MP_OKAY) {
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (176:14): [True: 0, False: 0]
  ------------------
  177|      0|            goto LBL_B;
  178|      0|         }
  179|      0|         if (res == MP_NO) {
  ------------------
  |  |  159|      0|#define MP_NO         0
  ------------------
  |  Branch (179:14): [True: 0, False: 0]
  ------------------
  180|      0|            goto LBL_B;
  181|      0|         }
  182|      0|      }
  183|      0|   }
  184|       |   /*
  185|       |       Do "t" M-R tests with random bases between 3 and "a".
  186|       |       See Fips 186.4 p. 126ff
  187|       |   */
  188|     57|   else if (t > 0) {
  ------------------
  |  Branch (188:13): [True: 57, False: 0]
  ------------------
  189|       |      /*
  190|       |       * The mp_digit's have a defined bit-size but the size of the
  191|       |       * array a.dp is a simple 'int' and this library can not assume full
  192|       |       * compliance to the current C-standard (ISO/IEC 9899:2011) because
  193|       |       * it gets used for small embeded processors, too. Some of those MCUs
  194|       |       * have compilers that one cannot call standard compliant by any means.
  195|       |       * Hence the ugly type-fiddling in the following code.
  196|       |       */
  197|     57|      size_a = mp_count_bits(a);
  198|     57|      mask = (1u << s_floor_ilog2(size_a)) - 1u;
  199|       |      /*
  200|       |         Assuming the General Rieman hypothesis (never thought to write that in a
  201|       |         comment) the upper bound can be lowered to  2*(log a)^2.
  202|       |         E. Bach, "Explicit bounds for primality testing and related problems,"
  203|       |         Math. Comp. 55 (1990), 355-380.
  204|       |
  205|       |            size_a = (size_a/10) * 7;
  206|       |            len = 2 * (size_a * size_a);
  207|       |
  208|       |         E.g.: a number of size 2^2048 would be reduced to the upper limit
  209|       |
  210|       |            floor(2048/10)*7 = 1428
  211|       |            2 * 1428^2       = 4078368
  212|       |
  213|       |         (would have been ~4030331.9962 with floats and natural log instead)
  214|       |         That number is smaller than 2^28, the default bit-size of mp_digit.
  215|       |      */
  216|       |
  217|       |      /*
  218|       |        How many tests, you might ask? Dana Jacobsen of Math::Prime::Util fame
  219|       |        does exactly 1. In words: one. Look at the end of _GMP_is_prime() in
  220|       |        Math-Prime-Util-GMP-0.50/primality.c if you do not believe it.
  221|       |
  222|       |        The function mp_rand() goes to some length to use a cryptographically
  223|       |        good PRNG. That also means that the chance to always get the same base
  224|       |        in the loop is non-zero, although very low.
  225|       |        If the BPSW test and/or the addtional Frobenious test have been
  226|       |        performed instead of just the Miller-Rabin test with the bases 2 and 3,
  227|       |        a single extra test should suffice, so such a very unlikely event
  228|       |        will not do much harm.
  229|       |
  230|       |        To preemptivly answer the dangling question: no, a witness does not
  231|       |        need to be prime.
  232|       |      */
  233|  2.05k|      for (ix = 0; ix < t; ix++) {
  ------------------
  |  Branch (233:20): [True: 1.99k, False: 57]
  ------------------
  234|       |         /* mp_rand() guarantees the first digit to be non-zero */
  235|  1.99k|         if ((err = mp_rand(&b, 1)) != MP_OKAY) {
  ------------------
  |  |  161|  1.99k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (235:14): [True: 0, False: 1.99k]
  ------------------
  236|      0|            goto LBL_B;
  237|      0|         }
  238|       |         /*
  239|       |          * Reduce digit before casting because mp_digit might be bigger than
  240|       |          * an unsigned int and "mask" on the other side is most probably not.
  241|       |          */
  242|  1.99k|         fips_rand = (unsigned int)(b.dp[0] & (mp_digit) mask);
  243|       |#ifdef MP_8BIT
  244|       |         /*
  245|       |          * One 8-bit digit is too small, so concatenate two if the size of
  246|       |          * unsigned int allows for it.
  247|       |          */
  248|       |         if ((MP_SIZEOF_BITS(unsigned int)/2) >= MP_SIZEOF_BITS(mp_digit)) {
  249|       |            if ((err = mp_rand(&b, 1)) != MP_OKAY) {
  250|       |               goto LBL_B;
  251|       |            }
  252|       |            fips_rand <<= MP_SIZEOF_BITS(mp_digit);
  253|       |            fips_rand |= (unsigned int) b.dp[0];
  254|       |            fips_rand &= mask;
  255|       |         }
  256|       |#endif
  257|  1.99k|         if (fips_rand > (unsigned int)(INT_MAX - MP_DIGIT_BIT)) {
  ------------------
  |  |   82|  1.99k|#   define MP_DIGIT_BIT 60
  ------------------
  |  Branch (257:14): [True: 0, False: 1.99k]
  ------------------
  258|      0|            len = INT_MAX / MP_DIGIT_BIT;
  ------------------
  |  |   82|      0|#   define MP_DIGIT_BIT 60
  ------------------
  259|  1.99k|         } else {
  260|  1.99k|            len = (((int)fips_rand + MP_DIGIT_BIT) / MP_DIGIT_BIT);
  ------------------
  |  |   82|  1.99k|#   define MP_DIGIT_BIT 60
  ------------------
                          len = (((int)fips_rand + MP_DIGIT_BIT) / MP_DIGIT_BIT);
  ------------------
  |  |   82|  1.99k|#   define MP_DIGIT_BIT 60
  ------------------
  261|  1.99k|         }
  262|       |         /*  Unlikely. */
  263|  1.99k|         if (len < 0) {
  ------------------
  |  Branch (263:14): [True: 0, False: 1.99k]
  ------------------
  264|      0|            ix--;
  265|      0|            continue;
  266|      0|         }
  267|       |         /*
  268|       |          * As mentioned above, one 8-bit digit is too small and
  269|       |          * although it can only happen in the unlikely case that
  270|       |          * an "unsigned int" is smaller than 16 bit a simple test
  271|       |          * is cheap and the correction even cheaper.
  272|       |          */
  273|       |#ifdef MP_8BIT
  274|       |         /* All "a" < 2^8 have been caught before */
  275|       |         if (len == 1) {
  276|       |            len++;
  277|       |         }
  278|       |#endif
  279|  1.99k|         if ((err = mp_rand(&b, len)) != MP_OKAY) {
  ------------------
  |  |  161|  1.99k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (279:14): [True: 0, False: 1.99k]
  ------------------
  280|      0|            goto LBL_B;
  281|      0|         }
  282|       |         /*
  283|       |          * That number might got too big and the witness has to be
  284|       |          * smaller than "a"
  285|       |          */
  286|  1.99k|         len = mp_count_bits(&b);
  287|  1.99k|         if (len >= size_a) {
  ------------------
  |  Branch (287:14): [True: 223, False: 1.77k]
  ------------------
  288|    223|            len = (len - size_a) + 1;
  289|    223|            if ((err = mp_div_2d(&b, len, &b, NULL)) != MP_OKAY) {
  ------------------
  |  |  161|    223|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (289:17): [True: 0, False: 223]
  ------------------
  290|      0|               goto LBL_B;
  291|      0|            }
  292|    223|         }
  293|       |         /* Although the chance for b <= 3 is miniscule, try again. */
  294|  1.99k|         if (mp_cmp_d(&b, 3uL) != MP_GT) {
  ------------------
  |  |  156|  1.99k|#define MP_GT         1   /* greater than */
  ------------------
  |  Branch (294:14): [True: 0, False: 1.99k]
  ------------------
  295|      0|            ix--;
  296|      0|            continue;
  297|      0|         }
  298|  1.99k|         if ((err = mp_prime_miller_rabin(a, &b, &res)) != MP_OKAY) {
  ------------------
  |  |  161|  1.99k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (298:14): [True: 0, False: 1.99k]
  ------------------
  299|      0|            goto LBL_B;
  300|      0|         }
  301|  1.99k|         if (res == MP_NO) {
  ------------------
  |  |  159|  1.99k|#define MP_NO         0
  ------------------
  |  Branch (301:14): [True: 0, False: 1.99k]
  ------------------
  302|      0|            goto LBL_B;
  303|      0|         }
  304|  1.99k|      }
  305|     57|   }
  306|       |
  307|       |   /* passed the test */
  308|     57|   *result = MP_YES;
  ------------------
  |  |  158|     57|#define MP_YES        1
  ------------------
  309|     91|LBL_B:
  310|     91|   mp_clear(&b);
  311|     91|   return err;
  312|     57|}
bn_mp_prime_is_prime.c:s_floor_ilog2:
    8|     57|{
    9|     57|   unsigned int r = 0;
   10|    456|   while ((value >>= 1) != 0) {
  ------------------
  |  Branch (10:11): [True: 399, False: 57]
  ------------------
   11|    399|      r++;
   12|    399|   }
   13|     57|   return r;
   14|     57|}

mp_prime_miller_rabin:
   14|  2.14k|{
   15|  2.14k|   mp_int  n1, y, r;
   16|  2.14k|   mp_err  err;
   17|  2.14k|   int     s, j;
   18|       |
   19|       |   /* default */
   20|  2.14k|   *result = MP_NO;
  ------------------
  |  |  159|  2.14k|#define MP_NO         0
  ------------------
   21|       |
   22|       |   /* ensure b > 1 */
   23|  2.14k|   if (mp_cmp_d(b, 1uL) != MP_GT) {
  ------------------
  |  |  156|  2.14k|#define MP_GT         1   /* greater than */
  ------------------
  |  Branch (23:8): [True: 0, False: 2.14k]
  ------------------
   24|      0|      return MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
   25|      0|   }
   26|       |
   27|       |   /* get n1 = a - 1 */
   28|  2.14k|   if ((err = mp_init_copy(&n1, a)) != MP_OKAY) {
  ------------------
  |  |  161|  2.14k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (28:8): [True: 0, False: 2.14k]
  ------------------
   29|      0|      return err;
   30|      0|   }
   31|  2.14k|   if ((err = mp_sub_d(&n1, 1uL, &n1)) != MP_OKAY) {
  ------------------
  |  |  161|  2.14k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (31:8): [True: 0, False: 2.14k]
  ------------------
   32|      0|      goto LBL_N1;
   33|      0|   }
   34|       |
   35|       |   /* set 2**s * r = n1 */
   36|  2.14k|   if ((err = mp_init_copy(&r, &n1)) != MP_OKAY) {
  ------------------
  |  |  161|  2.14k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (36:8): [True: 0, False: 2.14k]
  ------------------
   37|      0|      goto LBL_N1;
   38|      0|   }
   39|       |
   40|       |   /* count the number of least significant bits
   41|       |    * which are zero
   42|       |    */
   43|  2.14k|   s = mp_cnt_lsb(&r);
   44|       |
   45|       |   /* now divide n - 1 by 2**s */
   46|  2.14k|   if ((err = mp_div_2d(&r, s, &r, NULL)) != MP_OKAY) {
  ------------------
  |  |  161|  2.14k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (46:8): [True: 0, False: 2.14k]
  ------------------
   47|      0|      goto LBL_R;
   48|      0|   }
   49|       |
   50|       |   /* compute y = b**r mod a */
   51|  2.14k|   if ((err = mp_init(&y)) != MP_OKAY) {
  ------------------
  |  |  161|  2.14k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (51:8): [True: 0, False: 2.14k]
  ------------------
   52|      0|      goto LBL_R;
   53|      0|   }
   54|  2.14k|   if ((err = mp_exptmod(b, &r, a, &y)) != MP_OKAY) {
  ------------------
  |  |  161|  2.14k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (54:8): [True: 0, False: 2.14k]
  ------------------
   55|      0|      goto LBL_Y;
   56|      0|   }
   57|       |
   58|       |   /* if y != 1 and y != n1 do */
   59|  2.14k|   if ((mp_cmp_d(&y, 1uL) != MP_EQ) && (mp_cmp(&y, &n1) != MP_EQ)) {
  ------------------
  |  |  155|  2.14k|#define MP_EQ         0   /* equal to */
  ------------------
                 if ((mp_cmp_d(&y, 1uL) != MP_EQ) && (mp_cmp(&y, &n1) != MP_EQ)) {
  ------------------
  |  |  155|  1.94k|#define MP_EQ         0   /* equal to */
  ------------------
  |  Branch (59:8): [True: 1.94k, False: 197]
  |  Branch (59:40): [True: 1.82k, False: 126]
  ------------------
   60|  1.82k|      j = 1;
   61|       |      /* while j <= s-1 and y != n1 */
   62|  98.8k|      while ((j <= (s - 1)) && (mp_cmp(&y, &n1) != MP_EQ)) {
  ------------------
  |  |  155|  97.8k|#define MP_EQ         0   /* equal to */
  ------------------
  |  Branch (62:14): [True: 97.8k, False: 982]
  |  Branch (62:32): [True: 97.0k, False: 838]
  ------------------
   63|  97.0k|         if ((err = mp_sqrmod(&y, a, &y)) != MP_OKAY) {
  ------------------
  |  |  161|  97.0k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (63:14): [True: 0, False: 97.0k]
  ------------------
   64|      0|            goto LBL_Y;
   65|      0|         }
   66|       |
   67|       |         /* if y == 1 then composite */
   68|  97.0k|         if (mp_cmp_d(&y, 1uL) == MP_EQ) {
  ------------------
  |  |  155|  97.0k|#define MP_EQ         0   /* equal to */
  ------------------
  |  Branch (68:14): [True: 0, False: 97.0k]
  ------------------
   69|      0|            goto LBL_Y;
   70|      0|         }
   71|       |
   72|  97.0k|         ++j;
   73|  97.0k|      }
   74|       |
   75|       |      /* if y != n1 then composite */
   76|  1.82k|      if (mp_cmp(&y, &n1) != MP_EQ) {
  ------------------
  |  |  155|  1.82k|#define MP_EQ         0   /* equal to */
  ------------------
  |  Branch (76:11): [True: 34, False: 1.78k]
  ------------------
   77|     34|         goto LBL_Y;
   78|     34|      }
   79|  1.82k|   }
   80|       |
   81|       |   /* probably prime now */
   82|  2.10k|   *result = MP_YES;
  ------------------
  |  |  158|  2.10k|#define MP_YES        1
  ------------------
   83|  2.14k|LBL_Y:
   84|  2.14k|   mp_clear(&y);
   85|  2.14k|LBL_R:
   86|  2.14k|   mp_clear(&r);
   87|  2.14k|LBL_N1:
   88|  2.14k|   mp_clear(&n1);
   89|  2.14k|   return err;
   90|  2.14k|}

mp_prime_rabin_miller_trials:
   33|    224|{
   34|    224|   int x;
   35|       |
   36|  1.79k|   for (x = 0; x < (int)(sizeof(sizes)/(sizeof(sizes[0]))); x++) {
  ------------------
  |  Branch (36:16): [True: 1.79k, False: 0]
  ------------------
   37|  1.79k|      if (sizes[x].k == size) {
  ------------------
  |  Branch (37:11): [True: 224, False: 1.56k]
  ------------------
   38|    224|         return sizes[x].t;
   39|  1.56k|      } else if (sizes[x].k > size) {
  ------------------
  |  Branch (39:18): [True: 0, False: 1.56k]
  ------------------
   40|      0|         return (x == 0) ? sizes[0].t : sizes[x - 1].t;
  ------------------
  |  Branch (40:17): [True: 0, False: 0]
  ------------------
   41|      0|      }
   42|  1.79k|   }
   43|      0|   return sizes[x-1].t;
   44|    224|}

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_rand:
   16|  3.99k|{
   17|  3.99k|   int i;
   18|  3.99k|   mp_err err;
   19|       |
   20|  3.99k|   mp_zero(a);
   21|       |
   22|  3.99k|   if (digits <= 0) {
  ------------------
  |  Branch (22:8): [True: 0, False: 3.99k]
  ------------------
   23|      0|      return MP_OKAY;
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
   24|      0|   }
   25|       |
   26|  3.99k|   if ((err = mp_grow(a, digits)) != MP_OKAY) {
  ------------------
  |  |  161|  3.99k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (26:8): [True: 0, False: 3.99k]
  ------------------
   27|      0|      return err;
   28|      0|   }
   29|       |
   30|  3.99k|   if ((err = s_mp_rand_source(a->dp, (size_t)digits * sizeof(mp_digit))) != MP_OKAY) {
  ------------------
  |  |  161|  3.99k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (30:8): [True: 0, False: 3.99k]
  ------------------
   31|      0|      return err;
   32|      0|   }
   33|       |
   34|       |   /* TODO: We ensure that the highest digit is nonzero. Should this be removed? */
   35|  3.99k|   while ((a->dp[digits - 1] & MP_MASK) == 0u) {
  ------------------
  |  |  106|  3.99k|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|  3.99k|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
  |  Branch (35:11): [True: 0, False: 3.99k]
  ------------------
   36|      0|      if ((err = s_mp_rand_source(a->dp + digits - 1, sizeof(mp_digit))) != MP_OKAY) {
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (36:11): [True: 0, False: 0]
  ------------------
   37|      0|         return err;
   38|      0|      }
   39|      0|   }
   40|       |
   41|  3.99k|   a->used = digits;
   42|  9.12k|   for (i = 0; i < digits; ++i) {
  ------------------
  |  Branch (42:16): [True: 5.13k, False: 3.99k]
  ------------------
   43|  5.13k|      a->dp[i] &= MP_MASK;
  ------------------
  |  |  106|  5.13k|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|  5.13k|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
   44|  5.13k|   }
   45|       |
   46|  3.99k|   return MP_OKAY;
  ------------------
  |  |  161|  3.99k|#define MP_OKAY       0   /* no error */
  ------------------
   47|  3.99k|}

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

mp_reduce:
   11|  41.3k|{
   12|  41.3k|   mp_int  q;
   13|  41.3k|   mp_err  err;
   14|  41.3k|   int     um = m->used;
   15|       |
   16|       |   /* q = x */
   17|  41.3k|   if ((err = mp_init_copy(&q, x)) != MP_OKAY) {
  ------------------
  |  |  161|  41.3k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (17:8): [True: 0, False: 41.3k]
  ------------------
   18|      0|      return err;
   19|      0|   }
   20|       |
   21|       |   /* q1 = x / b**(k-1)  */
   22|  41.3k|   mp_rshd(&q, um - 1);
   23|       |
   24|       |   /* according to HAC this optimization is ok */
   25|  41.3k|   if ((mp_digit)um > ((mp_digit)1 << (MP_DIGIT_BIT - 1))) {
  ------------------
  |  |   82|  41.3k|#   define MP_DIGIT_BIT 60
  ------------------
  |  Branch (25:8): [True: 0, False: 41.3k]
  ------------------
   26|      0|      if ((err = mp_mul(&q, mu, &q)) != MP_OKAY) {
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (26:11): [True: 0, False: 0]
  ------------------
   27|      0|         goto CLEANUP;
   28|      0|      }
   29|  41.3k|   } else if (MP_HAS(S_MP_MUL_HIGH_DIGS)) {
  ------------------
  |  |  150|  41.3k|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|  41.3k|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|  41.3k|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [True: 41.3k, Folded]
  |  |  ------------------
  ------------------
   30|  41.3k|      if ((err = s_mp_mul_high_digs(&q, mu, &q, um)) != MP_OKAY) {
  ------------------
  |  |  161|  41.3k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (30:11): [True: 0, False: 41.3k]
  ------------------
   31|      0|         goto CLEANUP;
   32|      0|      }
   33|  41.3k|   } else if (MP_HAS(S_MP_MUL_HIGH_DIGS_FAST)) {
  ------------------
  |  |  150|      0|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|      0|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|      0|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [True: 0, Folded]
  |  |  ------------------
  ------------------
   34|      0|      if ((err = s_mp_mul_high_digs_fast(&q, mu, &q, um)) != MP_OKAY) {
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (34:11): [True: 0, False: 0]
  ------------------
   35|      0|         goto CLEANUP;
   36|      0|      }
   37|      0|   } else {
   38|      0|      err = MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
   39|      0|      goto CLEANUP;
   40|      0|   }
   41|       |
   42|       |   /* q3 = q2 / b**(k+1) */
   43|  41.3k|   mp_rshd(&q, um + 1);
   44|       |
   45|       |   /* x = x mod b**(k+1), quick (no division) */
   46|  41.3k|   if ((err = mp_mod_2d(x, MP_DIGIT_BIT * (um + 1), x)) != MP_OKAY) {
  ------------------
  |  |   82|  41.3k|#   define MP_DIGIT_BIT 60
  ------------------
                 if ((err = mp_mod_2d(x, MP_DIGIT_BIT * (um + 1), x)) != MP_OKAY) {
  ------------------
  |  |  161|  41.3k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (46:8): [True: 0, False: 41.3k]
  ------------------
   47|      0|      goto CLEANUP;
   48|      0|   }
   49|       |
   50|       |   /* q = q * m mod b**(k+1), quick (no division) */
   51|  41.3k|   if ((err = s_mp_mul_digs(&q, m, &q, um + 1)) != MP_OKAY) {
  ------------------
  |  |  161|  41.3k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (51:8): [True: 0, False: 41.3k]
  ------------------
   52|      0|      goto CLEANUP;
   53|      0|   }
   54|       |
   55|       |   /* x = x - q */
   56|  41.3k|   if ((err = mp_sub(x, &q, x)) != MP_OKAY) {
  ------------------
  |  |  161|  41.3k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (56:8): [True: 0, False: 41.3k]
  ------------------
   57|      0|      goto CLEANUP;
   58|      0|   }
   59|       |
   60|       |   /* If x < 0, add b**(k+1) to it */
   61|  41.3k|   if (mp_cmp_d(x, 0uL) == MP_LT) {
  ------------------
  |  |  154|  41.3k|#define MP_LT        -1   /* less than */
  ------------------
  |  Branch (61:8): [True: 6.26k, False: 35.0k]
  ------------------
   62|  6.26k|      mp_set(&q, 1uL);
   63|  6.26k|      if ((err = mp_lshd(&q, um + 1)) != MP_OKAY) {
  ------------------
  |  |  161|  6.26k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (63:11): [True: 0, False: 6.26k]
  ------------------
   64|      0|         goto CLEANUP;
   65|      0|      }
   66|  6.26k|      if ((err = mp_add(x, &q, x)) != MP_OKAY) {
  ------------------
  |  |  161|  6.26k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (66:11): [True: 0, False: 6.26k]
  ------------------
   67|      0|         goto CLEANUP;
   68|      0|      }
   69|  6.26k|   }
   70|       |
   71|       |   /* Back off if it's too big */
   72|  77.2k|   while (mp_cmp(x, m) != MP_LT) {
  ------------------
  |  |  154|  77.2k|#define MP_LT        -1   /* less than */
  ------------------
  |  Branch (72:11): [True: 35.8k, False: 41.3k]
  ------------------
   73|  35.8k|      if ((err = s_mp_sub(x, m, x)) != MP_OKAY) {
  ------------------
  |  |  161|  35.8k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (73:11): [True: 0, False: 35.8k]
  ------------------
   74|      0|         goto CLEANUP;
   75|      0|      }
   76|  35.8k|   }
   77|       |
   78|  41.3k|CLEANUP:
   79|  41.3k|   mp_clear(&q);
   80|       |
   81|  41.3k|   return err;
   82|  41.3k|}

mp_reduce_2k_l:
   11|  43.2k|{
   12|  43.2k|   mp_int q;
   13|  43.2k|   mp_err err;
   14|  43.2k|   int    p;
   15|       |
   16|  43.2k|   if ((err = mp_init(&q)) != MP_OKAY) {
  ------------------
  |  |  161|  43.2k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (16:8): [True: 0, False: 43.2k]
  ------------------
   17|      0|      return err;
   18|      0|   }
   19|       |
   20|  43.2k|   p = mp_count_bits(n);
   21|  2.62M|top:
   22|       |   /* q = a/2**p, a = a mod 2**p */
   23|  2.62M|   if ((err = mp_div_2d(a, p, &q, a)) != MP_OKAY) {
  ------------------
  |  |  161|  2.62M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (23:8): [True: 0, False: 2.62M]
  ------------------
   24|      0|      goto LBL_ERR;
   25|      0|   }
   26|       |
   27|       |   /* q = q * d */
   28|  2.62M|   if ((err = mp_mul(&q, d, &q)) != MP_OKAY) {
  ------------------
  |  |  161|  2.62M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (28:8): [True: 0, False: 2.62M]
  ------------------
   29|      0|      goto LBL_ERR;
   30|      0|   }
   31|       |
   32|       |   /* a = a + q */
   33|  2.62M|   if ((err = s_mp_add(a, &q, a)) != MP_OKAY) {
  ------------------
  |  |  161|  2.62M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (33:8): [True: 0, False: 2.62M]
  ------------------
   34|      0|      goto LBL_ERR;
   35|      0|   }
   36|       |
   37|  2.62M|   if (mp_cmp_mag(a, n) != MP_LT) {
  ------------------
  |  |  154|  2.62M|#define MP_LT        -1   /* less than */
  ------------------
  |  Branch (37:8): [True: 2.58M, False: 43.2k]
  ------------------
   38|  2.58M|      if ((err = s_mp_sub(a, n, a)) != MP_OKAY) {
  ------------------
  |  |  161|  2.58M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (38:11): [True: 0, False: 2.58M]
  ------------------
   39|      0|         goto LBL_ERR;
   40|      0|      }
   41|  2.58M|      goto top;
   42|  2.58M|   }
   43|       |
   44|  43.2k|LBL_ERR:
   45|  43.2k|   mp_clear(&q);
   46|  43.2k|   return err;
   47|  2.62M|}

mp_reduce_2k_setup_l:
    8|    393|{
    9|    393|   mp_err err;
   10|    393|   mp_int tmp;
   11|       |
   12|    393|   if ((err = mp_init(&tmp)) != MP_OKAY) {
  ------------------
  |  |  161|    393|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (12:8): [True: 0, False: 393]
  ------------------
   13|      0|      return err;
   14|      0|   }
   15|       |
   16|    393|   if ((err = mp_2expt(&tmp, mp_count_bits(a))) != MP_OKAY) {
  ------------------
  |  |  161|    393|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (16:8): [True: 0, False: 393]
  ------------------
   17|      0|      goto LBL_ERR;
   18|      0|   }
   19|       |
   20|    393|   if ((err = s_mp_sub(&tmp, a, d)) != MP_OKAY) {
  ------------------
  |  |  161|    393|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (20:8): [True: 0, False: 393]
  ------------------
   21|      0|      goto LBL_ERR;
   22|      0|   }
   23|       |
   24|    393|LBL_ERR:
   25|    393|   mp_clear(&tmp);
   26|    393|   return err;
   27|    393|}

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

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

mp_reduce_setup:
   10|    521|{
   11|    521|   mp_err err;
   12|    521|   if ((err = mp_2expt(a, b->used * 2 * MP_DIGIT_BIT)) != MP_OKAY) {
  ------------------
  |  |   82|    521|#   define MP_DIGIT_BIT 60
  ------------------
                 if ((err = mp_2expt(a, b->used * 2 * MP_DIGIT_BIT)) != MP_OKAY) {
  ------------------
  |  |  161|    521|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (12:8): [True: 0, False: 521]
  ------------------
   13|      0|      return err;
   14|      0|   }
   15|    521|   return mp_div(a, b, a, NULL);
   16|    521|}

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

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

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

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

mp_sqrt:
    8|      6|{
    9|      6|   mp_err err;
   10|      6|   mp_int t1, t2;
   11|       |
   12|       |   /* must be positive */
   13|      6|   if (arg->sign == MP_NEG) {
  ------------------
  |  |  152|      6|#define MP_NEG        1   /* negative */
  ------------------
  |  Branch (13:8): [True: 0, False: 6]
  ------------------
   14|      0|      return MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
   15|      0|   }
   16|       |
   17|       |   /* easy out */
   18|      6|   if (MP_IS_ZERO(arg)) {
  ------------------
  |  |  163|      6|#define MP_IS_ZERO(a) ((a)->used == 0)
  |  |  ------------------
  |  |  |  Branch (163:23): [True: 0, False: 6]
  |  |  ------------------
  ------------------
   19|      0|      mp_zero(ret);
   20|      0|      return MP_OKAY;
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
   21|      0|   }
   22|       |
   23|      6|   if ((err = mp_init_copy(&t1, arg)) != MP_OKAY) {
  ------------------
  |  |  161|      6|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (23:8): [True: 0, False: 6]
  ------------------
   24|      0|      return err;
   25|      0|   }
   26|       |
   27|      6|   if ((err = mp_init(&t2)) != MP_OKAY) {
  ------------------
  |  |  161|      6|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (27:8): [True: 0, False: 6]
  ------------------
   28|      0|      goto E2;
   29|      0|   }
   30|       |
   31|       |   /* First approx. (not very bad for large arg) */
   32|      6|   mp_rshd(&t1, t1.used/2);
   33|       |
   34|       |   /* t1 > 0  */
   35|      6|   if ((err = mp_div(arg, &t1, &t2, NULL)) != MP_OKAY) {
  ------------------
  |  |  161|      6|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (35:8): [True: 0, False: 6]
  ------------------
   36|      0|      goto E1;
   37|      0|   }
   38|      6|   if ((err = mp_add(&t1, &t2, &t1)) != MP_OKAY) {
  ------------------
  |  |  161|      6|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (38:8): [True: 0, False: 6]
  ------------------
   39|      0|      goto E1;
   40|      0|   }
   41|      6|   if ((err = mp_div_2(&t1, &t1)) != MP_OKAY) {
  ------------------
  |  |  161|      6|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (41:8): [True: 0, False: 6]
  ------------------
   42|      0|      goto E1;
   43|      0|   }
   44|       |   /* And now t1 > sqrt(arg) */
   45|    172|   do {
   46|    172|      if ((err = mp_div(arg, &t1, &t2, NULL)) != MP_OKAY) {
  ------------------
  |  |  161|    172|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (46:11): [True: 0, False: 172]
  ------------------
   47|      0|         goto E1;
   48|      0|      }
   49|    172|      if ((err = mp_add(&t1, &t2, &t1)) != MP_OKAY) {
  ------------------
  |  |  161|    172|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (49:11): [True: 0, False: 172]
  ------------------
   50|      0|         goto E1;
   51|      0|      }
   52|    172|      if ((err = mp_div_2(&t1, &t1)) != MP_OKAY) {
  ------------------
  |  |  161|    172|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (52:11): [True: 0, False: 172]
  ------------------
   53|      0|         goto E1;
   54|      0|      }
   55|       |      /* t1 >= sqrt(arg) >= t2 at this point */
   56|    172|   } while (mp_cmp_mag(&t1, &t2) == MP_GT);
  ------------------
  |  |  156|    172|#define MP_GT         1   /* greater than */
  ------------------
  |  Branch (56:13): [True: 166, False: 6]
  ------------------
   57|       |
   58|      6|   mp_exch(&t1, ret);
   59|       |
   60|      6|E1:
   61|      6|   mp_clear(&t2);
   62|      6|E2:
   63|      6|   mp_clear(&t1);
   64|      6|   return err;
   65|      6|}

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

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

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

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

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

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

s_mp_exptmod:
   15|    914|{
   16|    914|   mp_int  M[TAB_SIZE], res, mu;
   17|    914|   mp_digit buf;
   18|    914|   mp_err   err;
   19|    914|   int      bitbuf, bitcpy, bitcnt, mode, digidx, x, y, winsize;
   20|    914|   mp_err(*redux)(mp_int *x, const mp_int *m, const mp_int *mu);
   21|       |
   22|       |   /* find window size */
   23|    914|   x = mp_count_bits(X);
   24|    914|   if (x <= 7) {
  ------------------
  |  Branch (24:8): [True: 209, False: 705]
  ------------------
   25|    209|      winsize = 2;
   26|    705|   } else if (x <= 36) {
  ------------------
  |  Branch (26:15): [True: 248, False: 457]
  ------------------
   27|    248|      winsize = 3;
   28|    457|   } else if (x <= 140) {
  ------------------
  |  Branch (28:15): [True: 197, False: 260]
  ------------------
   29|    197|      winsize = 4;
   30|    260|   } else if (x <= 450) {
  ------------------
  |  Branch (30:15): [True: 260, False: 0]
  ------------------
   31|    260|      winsize = 5;
   32|    260|   } else if (x <= 1303) {
  ------------------
  |  Branch (32:15): [True: 0, False: 0]
  ------------------
   33|      0|      winsize = 6;
   34|      0|   } else if (x <= 3529) {
  ------------------
  |  Branch (34:15): [True: 0, False: 0]
  ------------------
   35|      0|      winsize = 7;
   36|      0|   } else {
   37|      0|      winsize = 8;
   38|      0|   }
   39|       |
   40|    914|   winsize = MAX_WINSIZE ? MP_MIN(MAX_WINSIZE, winsize) : winsize;
  ------------------
  |  |   11|    914|#   define MAX_WINSIZE 0
  |  |  ------------------
  |  |  |  Branch (11:24): [Folded, False: 914]
  |  |  ------------------
  ------------------
                 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]
  |  |  ------------------
  ------------------
   41|       |
   42|       |   /* init M array */
   43|       |   /* init first cell */
   44|    914|   if ((err = mp_init(&M[1])) != MP_OKAY) {
  ------------------
  |  |  161|    914|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (44:8): [True: 0, False: 914]
  ------------------
   45|      0|      return err;
   46|      0|   }
   47|       |
   48|       |   /* now init the second half of the array */
   49|  8.06k|   for (x = 1<<(winsize-1); x < (1 << winsize); x++) {
  ------------------
  |  Branch (49:29): [True: 7.14k, False: 914]
  ------------------
   50|  7.14k|      if ((err = mp_init(&M[x])) != MP_OKAY) {
  ------------------
  |  |  161|  7.14k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (50:11): [True: 0, False: 7.14k]
  ------------------
   51|      0|         for (y = 1<<(winsize-1); y < x; y++) {
  ------------------
  |  Branch (51:35): [True: 0, False: 0]
  ------------------
   52|      0|            mp_clear(&M[y]);
   53|      0|         }
   54|      0|         mp_clear(&M[1]);
   55|      0|         return err;
   56|      0|      }
   57|  7.14k|   }
   58|       |
   59|       |   /* create mu, used for Barrett reduction */
   60|    914|   if ((err = mp_init(&mu)) != MP_OKAY)                           goto LBL_M;
  ------------------
  |  |  161|    914|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (60:8): [True: 0, False: 914]
  ------------------
   61|       |
   62|    914|   if (redmode == 0) {
  ------------------
  |  Branch (62:8): [True: 521, False: 393]
  ------------------
   63|    521|      if ((err = mp_reduce_setup(&mu, P)) != MP_OKAY)             goto LBL_MU;
  ------------------
  |  |  161|    521|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (63:11): [True: 0, False: 521]
  ------------------
   64|    521|      redux = mp_reduce;
   65|    521|   } else {
   66|    393|      if ((err = mp_reduce_2k_setup_l(P, &mu)) != MP_OKAY)        goto LBL_MU;
  ------------------
  |  |  161|    393|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (66:11): [True: 0, False: 393]
  ------------------
   67|    393|      redux = mp_reduce_2k_l;
   68|    393|   }
   69|       |
   70|       |   /* create M table
   71|       |    *
   72|       |    * The M table contains powers of the base,
   73|       |    * e.g. M[x] = G**x mod P
   74|       |    *
   75|       |    * The first half of the table is not
   76|       |    * computed though accept for M[0] and M[1]
   77|       |    */
   78|    914|   if ((err = mp_mod(G, P, &M[1])) != MP_OKAY)                    goto LBL_MU;
  ------------------
  |  |  161|    914|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (78:8): [True: 0, False: 914]
  ------------------
   79|       |
   80|       |   /* compute the value at M[1<<(winsize-1)] by squaring
   81|       |    * M[1] (winsize-1) times
   82|       |    */
   83|    914|   if ((err = mp_copy(&M[1], &M[(size_t)1 << (winsize - 1)])) != MP_OKAY) goto LBL_MU;
  ------------------
  |  |  161|    914|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (83:8): [True: 0, False: 914]
  ------------------
   84|       |
   85|  3.25k|   for (x = 0; x < (winsize - 1); x++) {
  ------------------
  |  Branch (85:16): [True: 2.33k, False: 914]
  ------------------
   86|       |      /* square it */
   87|  2.33k|      if ((err = mp_sqr(&M[(size_t)1 << (winsize - 1)],
  ------------------
  |  Branch (87:11): [True: 0, False: 2.33k]
  ------------------
   88|  2.33k|                        &M[(size_t)1 << (winsize - 1)])) != MP_OKAY) goto LBL_MU;
  ------------------
  |  |  161|  2.33k|#define MP_OKAY       0   /* no error */
  ------------------
   89|       |
   90|       |      /* reduce modulo P */
   91|  2.33k|      if ((err = redux(&M[(size_t)1 << (winsize - 1)], P, &mu)) != MP_OKAY) goto LBL_MU;
  ------------------
  |  |  161|  2.33k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (91:11): [True: 0, False: 2.33k]
  ------------------
   92|  2.33k|   }
   93|       |
   94|       |   /* create upper table, that is M[x] = M[x-1] * M[1] (mod P)
   95|       |    * for x = (2**(winsize - 1) + 1) to (2**winsize - 1)
   96|       |    */
   97|  7.14k|   for (x = (1 << (winsize - 1)) + 1; x < (1 << winsize); x++) {
  ------------------
  |  Branch (97:39): [True: 6.23k, False: 914]
  ------------------
   98|  6.23k|      if ((err = mp_mul(&M[x - 1], &M[1], &M[x])) != MP_OKAY)     goto LBL_MU;
  ------------------
  |  |  161|  6.23k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (98:11): [True: 0, False: 6.23k]
  ------------------
   99|  6.23k|      if ((err = redux(&M[x], P, &mu)) != MP_OKAY)                goto LBL_MU;
  ------------------
  |  |  161|  6.23k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (99:11): [True: 0, False: 6.23k]
  ------------------
  100|  6.23k|   }
  101|       |
  102|       |   /* setup result */
  103|    914|   if ((err = mp_init(&res)) != MP_OKAY)                          goto LBL_MU;
  ------------------
  |  |  161|    914|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (103:8): [True: 0, False: 914]
  ------------------
  104|    914|   mp_set(&res, 1uL);
  105|       |
  106|       |   /* set initial mode and bit cnt */
  107|    914|   mode   = 0;
  108|    914|   bitcnt = 1;
  109|    914|   buf    = 0;
  110|    914|   digidx = X->used - 1;
  111|    914|   bitcpy = 0;
  112|    914|   bitbuf = 0;
  113|       |
  114|  88.3k|   for (;;) {
  115|       |      /* grab next digit as required */
  116|  88.3k|      if (--bitcnt == 0) {
  ------------------
  |  Branch (116:11): [True: 2.37k, False: 86.0k]
  ------------------
  117|       |         /* if digidx == -1 we are out of digits */
  118|  2.37k|         if (digidx == -1) {
  ------------------
  |  Branch (118:14): [True: 914, False: 1.45k]
  ------------------
  119|    914|            break;
  120|    914|         }
  121|       |         /* read next digit and reset the bitcnt */
  122|  1.45k|         buf    = X->dp[digidx--];
  123|  1.45k|         bitcnt = (int)MP_DIGIT_BIT;
  ------------------
  |  |   82|  1.45k|#   define MP_DIGIT_BIT 60
  ------------------
  124|  1.45k|      }
  125|       |
  126|       |      /* grab the next msb from the exponent */
  127|  87.4k|      y     = (buf >> (mp_digit)(MP_DIGIT_BIT - 1)) & 1uL;
  ------------------
  |  |   82|  87.4k|#   define MP_DIGIT_BIT 60
  ------------------
  128|  87.4k|      buf <<= (mp_digit)1;
  129|       |
  130|       |      /* if the bit is zero and mode == 0 then we ignore it
  131|       |       * These represent the leading zero bits before the first 1 bit
  132|       |       * in the exponent.  Technically this opt is not required but it
  133|       |       * does lower the # of trivial squaring/reductions used
  134|       |       */
  135|  87.4k|      if ((mode == 0) && (y == 0)) {
  ------------------
  |  Branch (135:11): [True: 24.3k, False: 63.1k]
  |  Branch (135:26): [True: 23.6k, False: 767]
  ------------------
  136|  23.6k|         continue;
  137|  23.6k|      }
  138|       |
  139|       |      /* if the bit is zero and mode == 1 then we square */
  140|  63.8k|      if ((mode == 1) && (y == 0)) {
  ------------------
  |  Branch (140:11): [True: 22.8k, False: 41.0k]
  |  Branch (140:26): [True: 11.9k, False: 10.9k]
  ------------------
  141|  11.9k|         if ((err = mp_sqr(&res, &res)) != MP_OKAY)               goto LBL_RES;
  ------------------
  |  |  161|  11.9k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (141:14): [True: 0, False: 11.9k]
  ------------------
  142|  11.9k|         if ((err = redux(&res, P, &mu)) != MP_OKAY)              goto LBL_RES;
  ------------------
  |  |  161|  11.9k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (142:14): [True: 0, False: 11.9k]
  ------------------
  143|  11.9k|         continue;
  144|  11.9k|      }
  145|       |
  146|       |      /* else we add it to the window */
  147|  51.9k|      bitbuf |= (y << (winsize - ++bitcpy));
  148|  51.9k|      mode    = 2;
  149|       |
  150|  51.9k|      if (bitcpy == winsize) {
  ------------------
  |  Branch (150:11): [True: 11.3k, False: 40.6k]
  ------------------
  151|       |         /* ok window is filled so square as required and multiply  */
  152|       |         /* square first */
  153|  62.3k|         for (x = 0; x < winsize; x++) {
  ------------------
  |  Branch (153:22): [True: 51.0k, False: 11.3k]
  ------------------
  154|  51.0k|            if ((err = mp_sqr(&res, &res)) != MP_OKAY)            goto LBL_RES;
  ------------------
  |  |  161|  51.0k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (154:17): [True: 0, False: 51.0k]
  ------------------
  155|  51.0k|            if ((err = redux(&res, P, &mu)) != MP_OKAY)           goto LBL_RES;
  ------------------
  |  |  161|  51.0k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (155:17): [True: 0, False: 51.0k]
  ------------------
  156|  51.0k|         }
  157|       |
  158|       |         /* then multiply */
  159|  11.3k|         if ((err = mp_mul(&res, &M[bitbuf], &res)) != MP_OKAY)  goto LBL_RES;
  ------------------
  |  |  161|  11.3k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (159:14): [True: 0, False: 11.3k]
  ------------------
  160|  11.3k|         if ((err = redux(&res, P, &mu)) != MP_OKAY)             goto LBL_RES;
  ------------------
  |  |  161|  11.3k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (160:14): [True: 0, False: 11.3k]
  ------------------
  161|       |
  162|       |         /* empty window and reset */
  163|  11.3k|         bitcpy = 0;
  164|  11.3k|         bitbuf = 0;
  165|  11.3k|         mode   = 1;
  166|  11.3k|      }
  167|  51.9k|   }
  168|       |
  169|       |   /* if bits remain then square/multiply */
  170|    914|   if ((mode == 2) && (bitcpy > 0)) {
  ------------------
  |  Branch (170:8): [True: 391, False: 523]
  |  Branch (170:23): [True: 391, False: 0]
  ------------------
  171|       |      /* square then multiply if the bit is set */
  172|  1.31k|      for (x = 0; x < bitcpy; x++) {
  ------------------
  |  Branch (172:19): [True: 919, False: 391]
  ------------------
  173|    919|         if ((err = mp_sqr(&res, &res)) != MP_OKAY)               goto LBL_RES;
  ------------------
  |  |  161|    919|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (173:14): [True: 0, False: 919]
  ------------------
  174|    919|         if ((err = redux(&res, P, &mu)) != MP_OKAY)              goto LBL_RES;
  ------------------
  |  |  161|    919|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (174:14): [True: 0, False: 919]
  ------------------
  175|       |
  176|    919|         bitbuf <<= 1;
  177|    919|         if ((bitbuf & (1 << winsize)) != 0) {
  ------------------
  |  Branch (177:14): [True: 753, False: 166]
  ------------------
  178|       |            /* then multiply */
  179|    753|            if ((err = mp_mul(&res, &M[1], &res)) != MP_OKAY)     goto LBL_RES;
  ------------------
  |  |  161|    753|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (179:17): [True: 0, False: 753]
  ------------------
  180|    753|            if ((err = redux(&res, P, &mu)) != MP_OKAY)           goto LBL_RES;
  ------------------
  |  |  161|    753|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (180:17): [True: 0, False: 753]
  ------------------
  181|    753|         }
  182|    919|      }
  183|    391|   }
  184|       |
  185|    914|   mp_exch(&res, Y);
  186|    914|   err = MP_OKAY;
  ------------------
  |  |  161|    914|#define MP_OKAY       0   /* no error */
  ------------------
  187|    914|LBL_RES:
  188|    914|   mp_clear(&res);
  189|    914|LBL_MU:
  190|    914|   mp_clear(&mu);
  191|    914|LBL_M:
  192|    914|   mp_clear(&M[1]);
  193|  8.06k|   for (x = 1<<(winsize-1); x < (1 << winsize); x++) {
  ------------------
  |  Branch (193:29): [True: 7.14k, False: 914]
  ------------------
  194|  7.14k|      mp_clear(&M[x]);
  195|  7.14k|   }
  196|    914|   return err;
  197|    914|}

s_mp_exptmod_fast:
   23|  2.38k|{
   24|  2.38k|   mp_int  M[TAB_SIZE], res;
   25|  2.38k|   mp_digit buf, mp;
   26|  2.38k|   int     bitbuf, bitcpy, bitcnt, mode, digidx, x, y, winsize;
   27|  2.38k|   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|  2.38k|   mp_err(*redux)(mp_int *x, const mp_int *n, mp_digit rho);
   34|       |
   35|       |   /* find window size */
   36|  2.38k|   x = mp_count_bits(X);
   37|  2.38k|   if (x <= 7) {
  ------------------
  |  Branch (37:8): [True: 303, False: 2.08k]
  ------------------
   38|    303|      winsize = 2;
   39|  2.08k|   } else if (x <= 36) {
  ------------------
  |  Branch (39:15): [True: 118, False: 1.96k]
  ------------------
   40|    118|      winsize = 3;
   41|  1.96k|   } else if (x <= 140) {
  ------------------
  |  Branch (41:15): [True: 1.23k, False: 726]
  ------------------
   42|  1.23k|      winsize = 4;
   43|  1.23k|   } else if (x <= 450) {
  ------------------
  |  Branch (43:15): [True: 726, False: 0]
  ------------------
   44|    726|      winsize = 5;
   45|    726|   } else if (x <= 1303) {
  ------------------
  |  Branch (45:15): [True: 0, False: 0]
  ------------------
   46|      0|      winsize = 6;
   47|      0|   } else if (x <= 3529) {
  ------------------
  |  Branch (47:15): [True: 0, False: 0]
  ------------------
   48|      0|      winsize = 7;
   49|      0|   } else {
   50|      0|      winsize = 8;
   51|      0|   }
   52|       |
   53|  2.38k|   winsize = MAX_WINSIZE ? MP_MIN(MAX_WINSIZE, winsize) : winsize;
  ------------------
  |  |   19|  2.38k|#   define MAX_WINSIZE 0
  |  |  ------------------
  |  |  |  Branch (19:24): [Folded, False: 2.38k]
  |  |  ------------------
  ------------------
                 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|  2.38k|   if ((err = mp_init_size(&M[1], P->alloc)) != MP_OKAY) {
  ------------------
  |  |  161|  2.38k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (57:8): [True: 0, False: 2.38k]
  ------------------
   58|      0|      return err;
   59|      0|   }
   60|       |
   61|       |   /* now init the second half of the array */
   62|  24.9k|   for (x = 1<<(winsize-1); x < (1 << winsize); x++) {
  ------------------
  |  Branch (62:29): [True: 22.6k, False: 2.38k]
  ------------------
   63|  22.6k|      if ((err = mp_init_size(&M[x], P->alloc)) != MP_OKAY) {
  ------------------
  |  |  161|  22.6k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (63:11): [True: 0, False: 22.6k]
  ------------------
   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|  22.6k|   }
   71|       |
   72|       |   /* determine and setup reduction code */
   73|  2.38k|   if (redmode == 0) {
  ------------------
  |  Branch (73:8): [True: 2.38k, False: 0]
  ------------------
   74|  2.38k|      if (MP_HAS(MP_MONTGOMERY_SETUP)) {
  ------------------
  |  |  150|  2.38k|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|  2.38k|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|  2.38k|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [True: 2.38k, Folded]
  |  |  ------------------
  ------------------
   75|       |         /* now setup montgomery  */
   76|  2.38k|         if ((err = mp_montgomery_setup(P, &mp)) != MP_OKAY)      goto LBL_M;
  ------------------
  |  |  161|  2.38k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (76:14): [True: 0, False: 2.38k]
  ------------------
   77|  2.38k|      } 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|  2.38k|      if (MP_HAS(S_MP_MONTGOMERY_REDUCE_FAST) &&
  ------------------
  |  |  150|  4.77k|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|  2.38k|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|  2.38k|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [True: 2.38k, Folded]
  |  |  ------------------
  ------------------
   84|  2.38k|          (((P->used * 2) + 1) < MP_WARRAY) &&
  ------------------
  |  |  172|  2.38k|#define MP_WARRAY PRIVATE_MP_WARRAY
  |  |  ------------------
  |  |  |  |  203|  2.38k|#define PRIVATE_MP_WARRAY (int)(1uLL << (((CHAR_BIT * sizeof(private_mp_word)) - (2 * MP_DIGIT_BIT)) + 1))
  |  |  |  |  ------------------
  |  |  |  |  |  |   82|  2.38k|#   define MP_DIGIT_BIT 60
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (84:11): [True: 2.38k, False: 0]
  ------------------
   85|  2.38k|          (P->used < MP_MAXFAST)) {
  ------------------
  |  |  168|  2.38k|#define MP_MAXFAST              (int)(1uL << (MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT)))
  |  |  ------------------
  |  |  |  |  167|  2.38k|#define MP_SIZEOF_BITS(type)    ((size_t)CHAR_BIT * sizeof(type))
  |  |  ------------------
  |  |               #define MP_MAXFAST              (int)(1uL << (MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT)))
  |  |  ------------------
  |  |  |  |   82|  2.38k|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
  |  Branch (85:11): [True: 2.38k, False: 0]
  ------------------
   86|  2.38k|         redux = s_mp_montgomery_reduce_fast;
   87|  2.38k|      } else if (MP_HAS(MP_MONTGOMERY_REDUCE)) {
  ------------------
  |  |  150|      0|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|      0|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|      0|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [True: 0, Folded]
  |  |  ------------------
  ------------------
   88|       |         /* use slower baseline Montgomery method */
   89|      0|         redux = mp_montgomery_reduce;
   90|      0|      } else {
   91|      0|         err = MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
   92|      0|         goto LBL_M;
   93|      0|      }
   94|  2.38k|   } else if (redmode == 1) {
  ------------------
  |  Branch (94:15): [True: 0, False: 0]
  ------------------
   95|      0|      if (MP_HAS(MP_DR_SETUP) && MP_HAS(MP_DR_REDUCE)) {
  ------------------
  |  |  150|      0|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|      0|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|      0|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [True: 0, Folded]
  |  |  ------------------
  ------------------
                    if (MP_HAS(MP_DR_SETUP) && MP_HAS(MP_DR_REDUCE)) {
  ------------------
  |  |  150|      0|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|      0|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|      0|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [True: 0, Folded]
  |  |  ------------------
  ------------------
   96|       |         /* setup DR reduction for moduli of the form B**k - b */
   97|      0|         mp_dr_setup(P, &mp);
   98|      0|         redux = mp_dr_reduce;
   99|      0|      } else {
  100|      0|         err = MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
  101|      0|         goto LBL_M;
  102|      0|      }
  103|      0|   } else if (MP_HAS(MP_REDUCE_2K_SETUP) && MP_HAS(MP_REDUCE_2K)) {
  ------------------
  |  |  150|      0|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|      0|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|      0|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [True: 0, Folded]
  |  |  ------------------
  ------------------
                 } else if (MP_HAS(MP_REDUCE_2K_SETUP) && MP_HAS(MP_REDUCE_2K)) {
  ------------------
  |  |  150|      0|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|      0|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|      0|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [True: 0, Folded]
  |  |  ------------------
  ------------------
  104|       |      /* setup DR reduction for moduli of the form 2**k - b */
  105|      0|      if ((err = mp_reduce_2k_setup(P, &mp)) != MP_OKAY)          goto LBL_M;
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (105:11): [True: 0, False: 0]
  ------------------
  106|      0|      redux = mp_reduce_2k;
  107|      0|   } else {
  108|      0|      err = MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
  109|      0|      goto LBL_M;
  110|      0|   }
  111|       |
  112|       |   /* setup result */
  113|  2.38k|   if ((err = mp_init_size(&res, P->alloc)) != MP_OKAY)           goto LBL_M;
  ------------------
  |  |  161|  2.38k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (113:8): [True: 0, False: 2.38k]
  ------------------
  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|  2.38k|   if (redmode == 0) {
  ------------------
  |  Branch (122:8): [True: 2.38k, False: 0]
  ------------------
  123|  2.38k|      if (MP_HAS(MP_MONTGOMERY_CALC_NORMALIZATION)) {
  ------------------
  |  |  150|  2.38k|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|  2.38k|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|  2.38k|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [True: 2.38k, Folded]
  |  |  ------------------
  ------------------
  124|       |         /* now we need R mod m */
  125|  2.38k|         if ((err = mp_montgomery_calc_normalization(&res, P)) != MP_OKAY) goto LBL_RES;
  ------------------
  |  |  161|  2.38k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (125:14): [True: 0, False: 2.38k]
  ------------------
  126|       |
  127|       |         /* now set M[1] to G * R mod m */
  128|  2.38k|         if ((err = mp_mulmod(G, &res, P, &M[1])) != MP_OKAY)     goto LBL_RES;
  ------------------
  |  |  161|  2.38k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (128:14): [True: 0, False: 2.38k]
  ------------------
  129|  2.38k|      } else {
  130|      0|         err = MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
  131|      0|         goto LBL_RES;
  132|      0|      }
  133|  2.38k|   } 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|  2.38k|   if ((err = mp_copy(&M[1], &M[(size_t)1 << (winsize - 1)])) != MP_OKAY) goto LBL_RES;
  ------------------
  |  |  161|  2.38k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (139:8): [True: 0, False: 2.38k]
  ------------------
  140|       |
  141|  9.54k|   for (x = 0; x < (winsize - 1); x++) {
  ------------------
  |  Branch (141:16): [True: 7.16k, False: 2.38k]
  ------------------
  142|  7.16k|      if ((err = mp_sqr(&M[(size_t)1 << (winsize - 1)], &M[(size_t)1 << (winsize - 1)])) != MP_OKAY) goto LBL_RES;
  ------------------
  |  |  161|  7.16k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (142:11): [True: 0, False: 7.16k]
  ------------------
  143|  7.16k|      if ((err = redux(&M[(size_t)1 << (winsize - 1)], P, mp)) != MP_OKAY) goto LBL_RES;
  ------------------
  |  |  161|  7.16k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (143:11): [True: 0, False: 7.16k]
  ------------------
  144|  7.16k|   }
  145|       |
  146|       |   /* create upper table */
  147|  22.6k|   for (x = (1 << (winsize - 1)) + 1; x < (1 << winsize); x++) {
  ------------------
  |  Branch (147:39): [True: 20.2k, False: 2.38k]
  ------------------
  148|  20.2k|      if ((err = mp_mul(&M[x - 1], &M[1], &M[x])) != MP_OKAY)     goto LBL_RES;
  ------------------
  |  |  161|  20.2k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (148:11): [True: 0, False: 20.2k]
  ------------------
  149|  20.2k|      if ((err = redux(&M[x], P, mp)) != MP_OKAY)                 goto LBL_RES;
  ------------------
  |  |  161|  20.2k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (149:11): [True: 0, False: 20.2k]
  ------------------
  150|  20.2k|   }
  151|       |
  152|       |   /* set initial mode and bit cnt */
  153|  2.38k|   mode   = 0;
  154|  2.38k|   bitcnt = 1;
  155|  2.38k|   buf    = 0;
  156|  2.38k|   digidx = X->used - 1;
  157|  2.38k|   bitcpy = 0;
  158|  2.38k|   bitbuf = 0;
  159|       |
  160|   292k|   for (;;) {
  161|       |      /* grab next digit as required */
  162|   292k|      if (--bitcnt == 0) {
  ------------------
  |  Branch (162:11): [True: 7.22k, False: 285k]
  ------------------
  163|       |         /* if digidx == -1 we are out of digits so break */
  164|  7.22k|         if (digidx == -1) {
  ------------------
  |  Branch (164:14): [True: 2.38k, False: 4.84k]
  ------------------
  165|  2.38k|            break;
  166|  2.38k|         }
  167|       |         /* read next digit and reset bitcnt */
  168|  4.84k|         buf    = X->dp[digidx--];
  169|  4.84k|         bitcnt = (int)MP_DIGIT_BIT;
  ------------------
  |  |   82|  4.84k|#   define MP_DIGIT_BIT 60
  ------------------
  170|  4.84k|      }
  171|       |
  172|       |      /* grab the next msb from the exponent */
  173|   290k|      y     = (mp_digit)(buf >> (MP_DIGIT_BIT - 1)) & 1uL;
  ------------------
  |  |   82|   290k|#   define MP_DIGIT_BIT 60
  ------------------
  174|   290k|      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|   290k|      if ((mode == 0) && (y == 0)) {
  ------------------
  |  Branch (181:11): [True: 60.5k, False: 229k]
  |  Branch (181:26): [True: 58.4k, False: 2.17k]
  ------------------
  182|  58.4k|         continue;
  183|  58.4k|      }
  184|       |
  185|       |      /* if the bit is zero and mode == 1 then we square */
  186|   231k|      if ((mode == 1) && (y == 0)) {
  ------------------
  |  Branch (186:11): [True: 111k, False: 120k]
  |  Branch (186:26): [True: 77.4k, False: 34.4k]
  ------------------
  187|  77.4k|         if ((err = mp_sqr(&res, &res)) != MP_OKAY)               goto LBL_RES;
  ------------------
  |  |  161|  77.4k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (187:14): [True: 0, False: 77.4k]
  ------------------
  188|  77.4k|         if ((err = redux(&res, P, mp)) != MP_OKAY)               goto LBL_RES;
  ------------------
  |  |  161|  77.4k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (188:14): [True: 0, False: 77.4k]
  ------------------
  189|  77.4k|         continue;
  190|  77.4k|      }
  191|       |
  192|       |      /* else we add it to the window */
  193|   154k|      bitbuf |= (y << (winsize - ++bitcpy));
  194|   154k|      mode    = 2;
  195|       |
  196|   154k|      if (bitcpy == winsize) {
  ------------------
  |  Branch (196:11): [True: 34.6k, False: 119k]
  ------------------
  197|       |         /* ok window is filled so square as required and multiply  */
  198|       |         /* square first */
  199|   185k|         for (x = 0; x < winsize; x++) {
  ------------------
  |  Branch (199:22): [True: 150k, False: 34.6k]
  ------------------
  200|   150k|            if ((err = mp_sqr(&res, &res)) != MP_OKAY)            goto LBL_RES;
  ------------------
  |  |  161|   150k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (200:17): [True: 0, False: 150k]
  ------------------
  201|   150k|            if ((err = redux(&res, P, mp)) != MP_OKAY)            goto LBL_RES;
  ------------------
  |  |  161|   150k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (201:17): [True: 0, False: 150k]
  ------------------
  202|   150k|         }
  203|       |
  204|       |         /* then multiply */
  205|  34.6k|         if ((err = mp_mul(&res, &M[bitbuf], &res)) != MP_OKAY)   goto LBL_RES;
  ------------------
  |  |  161|  34.6k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (205:14): [True: 0, False: 34.6k]
  ------------------
  206|  34.6k|         if ((err = redux(&res, P, mp)) != MP_OKAY)               goto LBL_RES;
  ------------------
  |  |  161|  34.6k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (206:14): [True: 0, False: 34.6k]
  ------------------
  207|       |
  208|       |         /* empty window and reset */
  209|  34.6k|         bitcpy = 0;
  210|  34.6k|         bitbuf = 0;
  211|  34.6k|         mode   = 1;
  212|  34.6k|      }
  213|   154k|   }
  214|       |
  215|       |   /* if bits remain then square/multiply */
  216|  2.38k|   if ((mode == 2) && (bitcpy > 0)) {
  ------------------
  |  Branch (216:8): [True: 1.90k, False: 477]
  |  Branch (216:23): [True: 1.90k, False: 0]
  ------------------
  217|       |      /* square then multiply if the bit is set */
  218|  5.87k|      for (x = 0; x < bitcpy; x++) {
  ------------------
  |  Branch (218:19): [True: 3.96k, False: 1.90k]
  ------------------
  219|  3.96k|         if ((err = mp_sqr(&res, &res)) != MP_OKAY)               goto LBL_RES;
  ------------------
  |  |  161|  3.96k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (219:14): [True: 0, False: 3.96k]
  ------------------
  220|  3.96k|         if ((err = redux(&res, P, mp)) != MP_OKAY)               goto LBL_RES;
  ------------------
  |  |  161|  3.96k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (220:14): [True: 0, False: 3.96k]
  ------------------
  221|       |
  222|       |         /* get next bit of the window */
  223|  3.96k|         bitbuf <<= 1;
  224|  3.96k|         if ((bitbuf & (1 << winsize)) != 0) {
  ------------------
  |  Branch (224:14): [True: 3.38k, False: 586]
  ------------------
  225|       |            /* then multiply */
  226|  3.38k|            if ((err = mp_mul(&res, &M[1], &res)) != MP_OKAY)     goto LBL_RES;
  ------------------
  |  |  161|  3.38k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (226:17): [True: 0, False: 3.38k]
  ------------------
  227|  3.38k|            if ((err = redux(&res, P, mp)) != MP_OKAY)            goto LBL_RES;
  ------------------
  |  |  161|  3.38k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (227:17): [True: 0, False: 3.38k]
  ------------------
  228|  3.38k|         }
  229|  3.96k|      }
  230|  1.90k|   }
  231|       |
  232|  2.38k|   if (redmode == 0) {
  ------------------
  |  Branch (232:8): [True: 2.38k, 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|  2.38k|      if ((err = redux(&res, P, mp)) != MP_OKAY)                  goto LBL_RES;
  ------------------
  |  |  161|  2.38k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (239:11): [True: 0, False: 2.38k]
  ------------------
  240|  2.38k|   }
  241|       |
  242|       |   /* swap res with Y */
  243|  2.38k|   mp_exch(&res, Y);
  244|  2.38k|   err = MP_OKAY;
  ------------------
  |  |  161|  2.38k|#define MP_OKAY       0   /* no error */
  ------------------
  245|  2.38k|LBL_RES:
  246|  2.38k|   mp_clear(&res);
  247|  2.38k|LBL_M:
  248|  2.38k|   mp_clear(&M[1]);
  249|  24.9k|   for (x = 1<<(winsize-1); x < (1 << winsize); x++) {
  ------------------
  |  Branch (249:29): [True: 22.6k, False: 2.38k]
  ------------------
  250|  22.6k|      mp_clear(&M[x]);
  251|  22.6k|   }
  252|  2.38k|   return err;
  253|  2.38k|}

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

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

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

s_mp_mul_digs:
   11|  41.3k|{
   12|  41.3k|   mp_int  t;
   13|  41.3k|   mp_err  err;
   14|  41.3k|   int     pa, pb, ix, iy;
   15|  41.3k|   mp_digit u;
   16|  41.3k|   mp_word r;
   17|  41.3k|   mp_digit tmpx, *tmpt, *tmpy;
   18|       |
   19|  41.3k|   if (digs < 0) {
  ------------------
  |  Branch (19:8): [True: 0, False: 41.3k]
  ------------------
   20|      0|      return MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
   21|      0|   }
   22|       |
   23|       |   /* can we use the fast multiplier? */
   24|  41.3k|   if ((digs < MP_WARRAY) &&
  ------------------
  |  |  172|  41.3k|#define MP_WARRAY PRIVATE_MP_WARRAY
  |  |  ------------------
  |  |  |  |  203|  41.3k|#define PRIVATE_MP_WARRAY (int)(1uLL << (((CHAR_BIT * sizeof(private_mp_word)) - (2 * MP_DIGIT_BIT)) + 1))
  |  |  |  |  ------------------
  |  |  |  |  |  |   82|  41.3k|#   define MP_DIGIT_BIT 60
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (24:8): [True: 41.3k, False: 0]
  ------------------
   25|  41.3k|       (MP_MIN(a->used, b->used) < MP_MAXFAST)) {
  ------------------
  |  |  156|  41.3k|#define MP_MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (156:23): [True: 35.0k, False: 6.22k]
  |  |  ------------------
  ------------------
                     (MP_MIN(a->used, b->used) < MP_MAXFAST)) {
  ------------------
  |  |  168|  41.3k|#define MP_MAXFAST              (int)(1uL << (MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT)))
  |  |  ------------------
  |  |  |  |  167|  41.3k|#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|  41.3k|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
  |  Branch (25:8): [True: 41.3k, False: 0]
  ------------------
   26|  41.3k|      return s_mp_mul_digs_fast(a, b, c, digs);
   27|  41.3k|   }
   28|       |
   29|      0|   if ((err = mp_init_size(&t, digs)) != MP_OKAY) {
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (29:8): [True: 0, False: 0]
  ------------------
   30|      0|      return err;
   31|      0|   }
   32|      0|   t.used = digs;
   33|       |
   34|       |   /* compute the digits of the product directly */
   35|      0|   pa = a->used;
   36|      0|   for (ix = 0; ix < pa; ix++) {
  ------------------
  |  Branch (36:17): [True: 0, False: 0]
  ------------------
   37|       |      /* set the carry to zero */
   38|      0|      u = 0;
   39|       |
   40|       |      /* limit ourselves to making digs digits of output */
   41|      0|      pb = MP_MIN(b->used, digs - ix);
  ------------------
  |  |  156|      0|#define MP_MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (156:23): [True: 0, False: 0]
  |  |  ------------------
  ------------------
   42|       |
   43|       |      /* setup some aliases */
   44|       |      /* copy of the digit from a used within the nested loop */
   45|      0|      tmpx = a->dp[ix];
   46|       |
   47|       |      /* an alias for the destination shifted ix places */
   48|      0|      tmpt = t.dp + ix;
   49|       |
   50|       |      /* an alias for the digits of b */
   51|      0|      tmpy = b->dp;
   52|       |
   53|       |      /* compute the columns of the output and propagate the carry */
   54|      0|      for (iy = 0; iy < pb; iy++) {
  ------------------
  |  Branch (54:20): [True: 0, False: 0]
  ------------------
   55|       |         /* compute the column as a mp_word */
   56|      0|         r       = (mp_word)*tmpt +
   57|      0|                   ((mp_word)tmpx * (mp_word)*tmpy++) +
   58|      0|                   (mp_word)u;
   59|       |
   60|       |         /* the new column is the lower part of the result */
   61|      0|         *tmpt++ = (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
  |  |  ------------------
  ------------------
   62|       |
   63|       |         /* get the carry word from the result */
   64|      0|         u       = (mp_digit)(r >> (mp_word)MP_DIGIT_BIT);
  ------------------
  |  |   82|      0|#   define MP_DIGIT_BIT 60
  ------------------
   65|      0|      }
   66|       |      /* set carry if it is placed below digs */
   67|      0|      if ((ix + iy) < digs) {
  ------------------
  |  Branch (67:11): [True: 0, False: 0]
  ------------------
   68|      0|         *tmpt = u;
   69|      0|      }
   70|      0|   }
   71|       |
   72|      0|   mp_clamp(&t);
   73|      0|   mp_exch(&t, c);
   74|       |
   75|      0|   mp_clear(&t);
   76|      0|   return MP_OKAY;
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
   77|      0|}

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

s_mp_mul_high_digs:
   10|  41.3k|{
   11|  41.3k|   mp_int   t;
   12|  41.3k|   int      pa, pb, ix, iy;
   13|  41.3k|   mp_err   err;
   14|  41.3k|   mp_digit u;
   15|  41.3k|   mp_word  r;
   16|  41.3k|   mp_digit tmpx, *tmpt, *tmpy;
   17|       |
   18|  41.3k|   if (digs < 0) {
  ------------------
  |  Branch (18:8): [True: 0, False: 41.3k]
  ------------------
   19|      0|      return MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
   20|      0|   }
   21|       |
   22|       |   /* can we use the fast multiplier? */
   23|  41.3k|   if (MP_HAS(S_MP_MUL_HIGH_DIGS_FAST)
  ------------------
  |  |  150|  82.6k|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|  41.3k|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|  41.3k|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [True: 41.3k, Folded]
  |  |  ------------------
  ------------------
   24|  41.3k|       && ((a->used + b->used + 1) < MP_WARRAY)
  ------------------
  |  |  172|  41.3k|#define MP_WARRAY PRIVATE_MP_WARRAY
  |  |  ------------------
  |  |  |  |  203|  41.3k|#define PRIVATE_MP_WARRAY (int)(1uLL << (((CHAR_BIT * sizeof(private_mp_word)) - (2 * MP_DIGIT_BIT)) + 1))
  |  |  |  |  ------------------
  |  |  |  |  |  |   82|  41.3k|#   define MP_DIGIT_BIT 60
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (24:11): [True: 41.3k, False: 0]
  ------------------
   25|  41.3k|       && (MP_MIN(a->used, b->used) < MP_MAXFAST)) {
  ------------------
  |  |  156|  41.3k|#define MP_MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (156:23): [True: 40.9k, False: 396]
  |  |  ------------------
  ------------------
                     && (MP_MIN(a->used, b->used) < MP_MAXFAST)) {
  ------------------
  |  |  168|  41.3k|#define MP_MAXFAST              (int)(1uL << (MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT)))
  |  |  ------------------
  |  |  |  |  167|  41.3k|#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|  41.3k|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
  |  Branch (25:11): [True: 41.3k, False: 0]
  ------------------
   26|  41.3k|      return s_mp_mul_high_digs_fast(a, b, c, digs);
   27|  41.3k|   }
   28|       |
   29|      0|   if ((err = mp_init_size(&t, a->used + b->used + 1)) != MP_OKAY) {
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (29:8): [True: 0, False: 0]
  ------------------
   30|      0|      return err;
   31|      0|   }
   32|      0|   t.used = a->used + b->used + 1;
   33|       |
   34|      0|   pa = a->used;
   35|      0|   pb = b->used;
   36|      0|   for (ix = 0; ix < pa; ix++) {
  ------------------
  |  Branch (36:17): [True: 0, False: 0]
  ------------------
   37|       |      /* clear the carry */
   38|      0|      u = 0;
   39|       |
   40|       |      /* left hand side of A[ix] * B[iy] */
   41|      0|      tmpx = a->dp[ix];
   42|       |
   43|       |      /* alias to the address of where the digits will be stored */
   44|      0|      tmpt = &(t.dp[digs]);
   45|       |
   46|       |      /* alias for where to read the right hand side from */
   47|      0|      tmpy = b->dp + (digs - ix);
   48|       |
   49|      0|      for (iy = digs - ix; iy < pb; iy++) {
  ------------------
  |  Branch (49:28): [True: 0, False: 0]
  ------------------
   50|       |         /* calculate the double precision result */
   51|      0|         r       = (mp_word)*tmpt +
   52|      0|                   ((mp_word)tmpx * (mp_word)*tmpy++) +
   53|      0|                   (mp_word)u;
   54|       |
   55|       |         /* get the lower part */
   56|      0|         *tmpt++ = (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
  |  |  ------------------
  ------------------
   57|       |
   58|       |         /* carry the carry */
   59|      0|         u       = (mp_digit)(r >> (mp_word)MP_DIGIT_BIT);
  ------------------
  |  |   82|      0|#   define MP_DIGIT_BIT 60
  ------------------
   60|      0|      }
   61|      0|      *tmpt = u;
   62|      0|   }
   63|      0|   mp_clamp(&t);
   64|      0|   mp_exch(&t, c);
   65|      0|   mp_clear(&t);
   66|      0|   return MP_OKAY;
  ------------------
  |  |  161|      0|#define MP_OKAY       0   /* no error */
  ------------------
   67|      0|}

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

s_mp_prime_is_divisible:
   12|    137|{
   13|    137|   int      ix;
   14|    137|   mp_err   err;
   15|    137|   mp_digit res;
   16|       |
   17|       |   /* default to not */
   18|    137|   *result = MP_NO;
  ------------------
  |  |  159|    137|#define MP_NO         0
  ------------------
   19|       |
   20|  24.4k|   for (ix = 0; ix < PRIVATE_MP_PRIME_TAB_SIZE; ix++) {
  ------------------
  |  |  633|  24.4k|#  define PRIVATE_MP_PRIME_TAB_SIZE 256
  ------------------
  |  Branch (20:17): [True: 24.3k, False: 91]
  ------------------
   21|       |      /* what is a mod LBL_prime_tab[ix] */
   22|  24.3k|      if ((err = mp_mod_d(a, s_mp_prime_tab[ix], &res)) != MP_OKAY) {
  ------------------
  |  |  161|  24.3k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (22:11): [True: 0, False: 24.3k]
  ------------------
   23|      0|         return err;
   24|      0|      }
   25|       |
   26|       |      /* is the residue zero? */
   27|  24.3k|      if (res == 0u) {
  ------------------
  |  Branch (27:11): [True: 46, False: 24.2k]
  ------------------
   28|     46|         *result = MP_YES;
  ------------------
  |  |  158|     46|#define MP_YES        1
  ------------------
   29|     46|         return MP_OKAY;
  ------------------
  |  |  161|     46|#define MP_OKAY       0   /* no error */
  ------------------
   30|     46|      }
   31|  24.3k|   }
   32|       |
   33|     91|   return MP_OKAY;
  ------------------
  |  |  161|     91|#define MP_OKAY       0   /* no error */
  ------------------
   34|    137|}

s_mp_sqr:
    8|    211|{
    9|    211|   mp_int   t;
   10|    211|   int      ix, iy, pa;
   11|    211|   mp_err   err;
   12|    211|   mp_word  r;
   13|    211|   mp_digit u, tmpx, *tmpt;
   14|       |
   15|    211|   pa = a->used;
   16|    211|   if ((err = mp_init_size(&t, (2 * pa) + 1)) != MP_OKAY) {
  ------------------
  |  |  161|    211|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (16:8): [True: 0, False: 211]
  ------------------
   17|      0|      return err;
   18|      0|   }
   19|       |
   20|       |   /* default used is maximum possible size */
   21|    211|   t.used = (2 * pa) + 1;
   22|       |
   23|  27.9k|   for (ix = 0; ix < pa; ix++) {
  ------------------
  |  Branch (23:17): [True: 27.6k, False: 211]
  ------------------
   24|       |      /* first calculate the digit at 2*ix */
   25|       |      /* calculate double precision result */
   26|  27.6k|      r = (mp_word)t.dp[2*ix] +
   27|  27.6k|          ((mp_word)a->dp[ix] * (mp_word)a->dp[ix]);
   28|       |
   29|       |      /* store lower part in result */
   30|  27.6k|      t.dp[ix+ix] = (mp_digit)(r & (mp_word)MP_MASK);
  ------------------
  |  |  106|  27.6k|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|  27.6k|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
   31|       |
   32|       |      /* get the carry */
   33|  27.6k|      u           = (mp_digit)(r >> (mp_word)MP_DIGIT_BIT);
  ------------------
  |  |   82|  27.6k|#   define MP_DIGIT_BIT 60
  ------------------
   34|       |
   35|       |      /* left hand side of A[ix] * A[iy] */
   36|  27.6k|      tmpx        = a->dp[ix];
   37|       |
   38|       |      /* alias for where to store the results */
   39|  27.6k|      tmpt        = t.dp + ((2 * ix) + 1);
   40|       |
   41|  1.83M|      for (iy = ix + 1; iy < pa; iy++) {
  ------------------
  |  Branch (41:25): [True: 1.80M, False: 27.6k]
  ------------------
   42|       |         /* first calculate the product */
   43|  1.80M|         r       = (mp_word)tmpx * (mp_word)a->dp[iy];
   44|       |
   45|       |         /* now calculate the double precision result, note we use
   46|       |          * addition instead of *2 since it's easier to optimize
   47|       |          */
   48|  1.80M|         r       = (mp_word)*tmpt + r + r + (mp_word)u;
   49|       |
   50|       |         /* store lower part */
   51|  1.80M|         *tmpt++ = (mp_digit)(r & (mp_word)MP_MASK);
  ------------------
  |  |  106|  1.80M|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|  1.80M|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
   52|       |
   53|       |         /* get carry */
   54|  1.80M|         u       = (mp_digit)(r >> (mp_word)MP_DIGIT_BIT);
  ------------------
  |  |   82|  1.80M|#   define MP_DIGIT_BIT 60
  ------------------
   55|  1.80M|      }
   56|       |      /* propagate upwards */
   57|  50.1k|      while (u != 0uL) {
  ------------------
  |  Branch (57:14): [True: 22.4k, False: 27.6k]
  ------------------
   58|  22.4k|         r       = (mp_word)*tmpt + (mp_word)u;
   59|  22.4k|         *tmpt++ = (mp_digit)(r & (mp_word)MP_MASK);
  ------------------
  |  |  106|  22.4k|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|  22.4k|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
   60|  22.4k|         u       = (mp_digit)(r >> (mp_word)MP_DIGIT_BIT);
  ------------------
  |  |   82|  22.4k|#   define MP_DIGIT_BIT 60
  ------------------
   61|  22.4k|      }
   62|  27.6k|   }
   63|       |
   64|    211|   mp_clamp(&t);
   65|    211|   mp_exch(&t, b);
   66|    211|   mp_clear(&t);
   67|    211|   return MP_OKAY;
  ------------------
  |  |  161|    211|#define MP_OKAY       0   /* no error */
  ------------------
   68|    211|}

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

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

mp_get_i32:
  298|     34|    {                                                         \
  299|     34|        utype res = mag(a);                                   \
  300|     34|        return (a->sign == MP_NEG) ? (type)-res : (type)res;  \
  ------------------
  |  |  152|     34|#define MP_NEG        1   /* negative */
  ------------------
  |  Branch (300:16): [True: 0, False: 34]
  ------------------
  301|     34|    }
mp_init_u32:
  274|     34|    {                                                    \
  275|     34|        mp_err err;                                      \
  276|     34|        if ((err = mp_init(a)) != MP_OKAY) {             \
  ------------------
  |  |  161|     34|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (276:13): [True: 0, False: 34]
  ------------------
  277|      0|            return err;                                  \
  278|      0|        }                                                \
  279|     34|        set(a, b);                                       \
  280|     34|        return MP_OKAY;                                  \
  ------------------
  |  |  161|     34|#define MP_OKAY       0   /* no error */
  ------------------
  281|     34|    }

m_mp_init_multi:
   41|  1.07k|{
   42|  1.07k|	mp_int* cur_arg = mp;
   43|  1.07k|	va_list args;
   44|       |
   45|  1.07k|	va_start(args, mp);        /* init args to next argument from caller */
   46|  4.53k|	while (cur_arg != NULL) {
  ------------------
  |  Branch (46:9): [True: 3.46k, False: 1.07k]
  ------------------
   47|  3.46k|		if (mp_init(cur_arg) != MP_OKAY) {
  ------------------
  |  |  161|  3.46k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (47:7): [True: 0, False: 3.46k]
  ------------------
   48|      0|			dropbear_exit("Mem alloc error");
   49|      0|		}
   50|  3.46k|		cur_arg = va_arg(args, mp_int*);
   51|  3.46k|	}
   52|  1.07k|	va_end(args);
   53|  1.07k|}
m_mp_alloc_init_multi:
   56|  2.48k|{
   57|  2.48k|	mp_int** cur_arg = mp;
   58|  2.48k|	va_list args;
   59|       |
   60|  2.48k|	va_start(args, mp);        /* init args to next argument from caller */
   61|  10.1k|	while (cur_arg != NULL) {
  ------------------
  |  Branch (61:9): [True: 7.65k, False: 2.48k]
  ------------------
   62|  7.65k|		*cur_arg = m_malloc(sizeof(mp_int));
   63|  7.65k|		if (mp_init(*cur_arg) != MP_OKAY) {
  ------------------
  |  |  161|  7.65k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (63:7): [True: 0, False: 7.65k]
  ------------------
   64|      0|			dropbear_exit("Mem alloc error");
   65|      0|		}
   66|  7.65k|		cur_arg = va_arg(args, mp_int**);
   67|  7.65k|	}
   68|  2.48k|	va_end(args);
   69|  2.48k|}
m_mp_free_multi:
   72|  1.48k|{
   73|  1.48k|	mp_int** cur_arg = mp;
   74|  1.48k|	va_list args;
   75|       |
   76|  1.48k|	va_start(args, mp);        /* init args to next argument from caller */
   77|  8.42k|	while (cur_arg != NULL) {
  ------------------
  |  Branch (77:9): [True: 6.94k, False: 1.48k]
  ------------------
   78|  6.94k|		if (*cur_arg) {
  ------------------
  |  Branch (78:7): [True: 3.15k, False: 3.78k]
  ------------------
   79|  3.15k|			mp_clear(*cur_arg);
   80|  3.15k|		}
   81|  6.94k|		m_free(*cur_arg);
  ------------------
  |  |   24|  6.94k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 6.94k]
  |  |  ------------------
  ------------------
   82|  6.94k|		cur_arg = va_arg(args, mp_int**);
   83|  6.94k|	}
   84|       |	va_end(args);
   85|  1.48k|}
bytes_to_mp:
   87|  1.37k|void bytes_to_mp(mp_int *mp, const unsigned char* bytes, unsigned int len) {
   88|       |
   89|  1.37k|	if (mp_from_ubin(mp, (unsigned char*)bytes, len) != MP_OKAY) {
  ------------------
  |  |  161|  1.37k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (89:6): [True: 0, False: 1.37k]
  ------------------
   90|      0|		dropbear_exit("Mem alloc error");
   91|      0|	}
   92|  1.37k|}

buf_new:
   41|  1.43k|buffer* buf_new(unsigned int size) {
   42|  1.43k|	buffer* buf;
   43|  1.43k|	if (size > BUF_MAX_SIZE) {
  ------------------
  |  |   35|  1.43k|#define BUF_MAX_SIZE 1000000000
  ------------------
  |  Branch (43:6): [True: 0, False: 1.43k]
  ------------------
   44|      0|		dropbear_exit("buf->size too big");
   45|      0|	}
   46|       |
   47|  1.43k|	buf = (buffer*)m_malloc(sizeof(buffer)+size);
   48|  1.43k|	buf->data = (unsigned char*)buf + sizeof(buffer);
   49|  1.43k|	buf->size = size;
   50|  1.43k|	return buf;
   51|  1.43k|}
buf_free:
   54|  1.43k|void buf_free(buffer* buf) {
   55|       |	m_free(buf);
  ------------------
  |  |   24|  1.43k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 1.43k]
  |  |  ------------------
  ------------------
   56|  1.43k|}
buf_incrlen:
  104|   182k|void buf_incrlen(buffer* buf, unsigned int incr) {
  105|   182k|	if (incr > BUF_MAX_INCR || buf->len + incr > buf->size) {
  ------------------
  |  |   34|   364k|#define BUF_MAX_INCR 1000000000
  ------------------
  |  Branch (105:6): [True: 0, False: 182k]
  |  Branch (105:29): [True: 0, False: 182k]
  ------------------
  106|      0|		dropbear_exit("Bad buf_incrlen");
  107|      0|	}
  108|   182k|	buf->len += incr;
  109|   182k|}
buf_setpos:
  111|  1.89k|void buf_setpos(buffer* buf, unsigned int pos) {
  112|       |
  113|  1.89k|	if (pos > buf->len) {
  ------------------
  |  Branch (113:6): [True: 0, False: 1.89k]
  ------------------
  114|      0|		dropbear_exit("Bad buf_setpos");
  115|      0|	}
  116|  1.89k|	buf->pos = pos;
  117|  1.89k|}
buf_incrwritepos:
  120|  1.73k|void buf_incrwritepos(buffer* buf, unsigned int incr) {
  121|  1.73k|	if (incr > BUF_MAX_INCR || buf->pos + incr > buf->size) {
  ------------------
  |  |   34|  3.46k|#define BUF_MAX_INCR 1000000000
  ------------------
  |  Branch (121:6): [True: 0, False: 1.73k]
  |  Branch (121:29): [True: 0, False: 1.73k]
  ------------------
  122|      0|		dropbear_exit("Bad buf_incrwritepos");
  123|      0|	}
  124|  1.73k|	buf->pos += incr;
  125|  1.73k|	if (buf->pos > buf->len) {
  ------------------
  |  Branch (125:6): [True: 1.73k, False: 0]
  ------------------
  126|  1.73k|		buf->len = buf->pos;
  127|  1.73k|	}
  128|  1.73k|}
buf_incrpos:
  131|  27.9k|void buf_incrpos(buffer* buf, unsigned int incr) {
  132|  27.9k|	if (incr > BUF_MAX_INCR 
  ------------------
  |  |   34|  55.9k|#define BUF_MAX_INCR 1000000000
  ------------------
  |  Branch (132:6): [True: 0, False: 27.9k]
  ------------------
  133|  27.9k|		|| (buf->pos + incr) > buf->len) {
  ------------------
  |  Branch (133:6): [True: 0, False: 27.9k]
  ------------------
  134|      0|		dropbear_exit("Bad buf_incrpos");
  135|      0|	}
  136|  27.9k|	buf->pos += incr;
  137|  27.9k|}
buf_decrpos:
  140|  2.76k|void buf_decrpos(buffer* buf, unsigned int decr) {
  141|  2.76k|	if (decr > buf->pos) {
  ------------------
  |  Branch (141:6): [True: 0, False: 2.76k]
  ------------------
  142|      0|		dropbear_exit("Bad buf_decrpos");
  143|      0|	}
  144|  2.76k|	buf->pos -= decr;
  145|  2.76k|}
buf_getbyte:
  148|  1.52k|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|  1.52k|	if (buf->pos >= buf->len) {
  ------------------
  |  Branch (152:6): [True: 23, False: 1.49k]
  ------------------
  153|     23|		dropbear_exit("Bad buf_getbyte");
  154|     23|	}
  155|  1.49k|	return buf->data[buf->pos++];
  156|  1.52k|}
buf_putbyte:
  169|   181k|void buf_putbyte(buffer* buf, unsigned char val) {
  170|       |
  171|   181k|	if (buf->pos >= buf->len) {
  ------------------
  |  Branch (171:6): [True: 181k, False: 0]
  ------------------
  172|   181k|		buf_incrlen(buf, 1);
  173|   181k|	}
  174|   181k|	buf->data[buf->pos] = val;
  175|   181k|	buf->pos++;
  176|   181k|}
buf_getptr:
  180|  31.4k|unsigned char* buf_getptr(const buffer* buf, unsigned int len) {
  181|       |
  182|  31.4k|	if (len > BUF_MAX_INCR || buf->pos + len > buf->len) {
  ------------------
  |  |   34|  62.9k|#define BUF_MAX_INCR 1000000000
  ------------------
  |  Branch (182:6): [True: 0, False: 31.4k]
  |  Branch (182:28): [True: 362, False: 31.1k]
  ------------------
  183|    362|		dropbear_exit("Bad buf_getptr");
  184|    362|	}
  185|  31.1k|	return &buf->data[buf->pos];
  186|  31.4k|}
buf_getwriteptr:
  190|  2.34k|unsigned char* buf_getwriteptr(const buffer* buf, unsigned int len) {
  191|       |
  192|  2.34k|	if (len > BUF_MAX_INCR || buf->pos + len > buf->size) {
  ------------------
  |  |   34|  4.68k|#define BUF_MAX_INCR 1000000000
  ------------------
  |  Branch (192:6): [True: 0, False: 2.34k]
  |  Branch (192:28): [True: 0, False: 2.34k]
  ------------------
  193|      0|		dropbear_exit("Bad buf_getwriteptr");
  194|      0|	}
  195|  2.34k|	return &buf->data[buf->pos];
  196|  2.34k|}
buf_getstring:
  201|  6.87k|char* buf_getstring(buffer* buf, unsigned int *retlen) {
  202|       |
  203|  6.87k|	unsigned int len;
  204|  6.87k|	char* ret;
  205|  6.87k|	void* src = NULL;
  206|  6.87k|	len = buf_getint(buf);
  207|  6.87k|	if (len > MAX_STRING_LEN) {
  ------------------
  |  |  259|  6.87k|#define MAX_STRING_LEN (MAX(MAX_CMD_LEN, 2400)) /* Sun SSH needs 2400 for algos,
  ------------------
  |  Branch (207:6): [True: 37, False: 6.84k]
  |  Branch (207:12): [True: 6.79k, Folded]
  ------------------
  208|     37|		dropbear_exit("String too long");
  209|     37|	}
  210|       |
  211|  6.84k|	if (retlen != NULL) {
  ------------------
  |  Branch (211:6): [True: 6.75k, False: 87]
  ------------------
  212|  6.75k|		*retlen = len;
  213|  6.75k|	}
  214|  6.84k|	src = buf_getptr(buf, len);
  215|  6.84k|	ret = m_malloc(len+1);
  216|  6.84k|	memcpy(ret, src, len);
  217|  6.84k|	buf_incrpos(buf, len);
  218|  6.84k|	ret[len] = '\0';
  219|       |
  220|  6.84k|	return ret;
  221|  6.87k|}
buf_getstringbuf:
  246|    647|buffer * buf_getstringbuf(buffer *buf) {
  247|    647|	return buf_getstringbuf_int(buf, 0);
  248|    647|}
buf_getint:
  272|  15.0k|unsigned int buf_getint(buffer* buf) {
  273|  15.0k|	unsigned int ret;
  274|       |
  275|  15.0k|	LOAD32H(ret, buf_getptr(buf, 4));
  ------------------
  |  |   66|  15.0k|#define LOAD32H(x, y)                           \
  |  |   67|  15.0k|do { XMEMCPY (&(x), (y), 4);                    \
  |  |  ------------------
  |  |  |  |   39|  15.0k|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |   68|  15.0k|      (x) = __builtin_bswap32 ((x)); } while(0)
  |  |  ------------------
  |  |  |  Branch (68:46): [Folded, False: 15.0k]
  |  |  ------------------
  ------------------
  276|  15.0k|	buf_incrpos(buf, 4);
  277|  15.0k|	return ret;
  278|  15.0k|}
buf_putint:
  281|     74|void buf_putint(buffer* buf, int unsigned val) {
  282|       |
  283|     74|	STORE32H(val, buf_getwriteptr(buf, 4));
  ------------------
  |  |   62|     74|#define STORE32H(x, y)                          \
  |  |   63|     74|do { ulong32 __t = __builtin_bswap32 ((x));     \
  |  |   64|     74|      XMEMCPY ((y), &__t, 4); } while(0)
  |  |  ------------------
  |  |  |  |   39|     74|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (64:39): [Folded, False: 74]
  |  |  ------------------
  ------------------
  284|     74|	buf_incrwritepos(buf, 4);
  285|       |
  286|     74|}
buf_putstring:
  289|      1|void buf_putstring(buffer* buf, const char* str, unsigned int len) {
  290|       |	
  291|      1|	buf_putint(buf, len);
  292|      1|	buf_putbytes(buf, (const unsigned char*)str, len);
  293|       |
  294|      1|}
buf_putbytes:
  303|    902|void buf_putbytes(buffer *buf, const unsigned char *bytes, unsigned int len) {
  304|    902|	memcpy(buf_getwriteptr(buf, len), bytes, len);
  305|    902|	buf_incrwritepos(buf, len);
  306|    902|}
buf_getmpint:
  356|  4.06k|int buf_getmpint(buffer* buf, mp_int* mp) {
  357|       |
  358|  4.06k|	unsigned int len;
  359|  4.06k|	len = buf_getint(buf);
  360|       |	
  361|  4.06k|	if (len == 0) {
  ------------------
  |  Branch (361:6): [True: 848, False: 3.22k]
  ------------------
  362|    848|		mp_zero(mp);
  363|    848|		return DROPBEAR_SUCCESS;
  ------------------
  |  |  111|    848|#define DROPBEAR_SUCCESS 0
  ------------------
  364|    848|	}
  365|       |
  366|  3.22k|	if (len > BUF_MAX_MPINT) {
  ------------------
  |  |   38|  3.22k|#define BUF_MAX_MPINT (8240 / 8)
  ------------------
  |  Branch (366:6): [True: 60, False: 3.16k]
  ------------------
  367|     60|		return DROPBEAR_FAILURE;
  ------------------
  |  |  112|     60|#define DROPBEAR_FAILURE -1
  ------------------
  368|     60|	}
  369|       |
  370|       |	/* check for negative */
  371|  3.16k|	if (*buf_getptr(buf, 1) & (1 << (CHAR_BIT-1))) {
  ------------------
  |  Branch (371:6): [True: 9, False: 3.15k]
  ------------------
  372|      9|		return DROPBEAR_FAILURE;
  ------------------
  |  |  112|      9|#define DROPBEAR_FAILURE -1
  ------------------
  373|      9|	}
  374|       |
  375|  3.15k|	if (mp_from_ubin(mp, buf_getptr(buf, len), len) != MP_OKAY) {
  ------------------
  |  |  161|  3.15k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (375:6): [True: 0, False: 3.15k]
  ------------------
  376|      0|		return DROPBEAR_FAILURE;
  ------------------
  |  |  112|      0|#define DROPBEAR_FAILURE -1
  ------------------
  377|      0|	}
  378|       |
  379|  3.15k|	buf_incrpos(buf, len);
  380|  3.15k|	return DROPBEAR_SUCCESS;
  ------------------
  |  |  111|  3.15k|#define DROPBEAR_SUCCESS 0
  ------------------
  381|  3.15k|}
buffer.c:buf_getstringbuf_int:
  224|    647|static buffer * buf_getstringbuf_int(buffer *buf, int incllen) {
  225|    647|	buffer *ret = NULL;
  226|    647|	unsigned int len = buf_getint(buf);
  227|    647|	int extra = 0;
  228|    647|	if (len > MAX_STRING_LEN) {
  ------------------
  |  |  259|    647|#define MAX_STRING_LEN (MAX(MAX_CMD_LEN, 2400)) /* Sun SSH needs 2400 for algos,
  ------------------
  |  Branch (228:6): [True: 27, False: 620]
  |  Branch (228:12): [True: 637, Folded]
  ------------------
  229|     27|		dropbear_exit("String too long");
  230|     27|	}
  231|    620|	if (incllen) {
  ------------------
  |  Branch (231:6): [True: 0, False: 620]
  ------------------
  232|      0|		extra = 4;
  233|      0|	}
  234|    620|	ret = buf_new(len+extra);
  235|    620|	if (incllen) {
  ------------------
  |  Branch (235:6): [True: 0, False: 620]
  ------------------
  236|      0|		buf_putint(ret, len);
  237|      0|	}
  238|    620|	memcpy(buf_getwriteptr(ret, len), buf_getptr(buf, len), len);
  239|    620|	buf_incrpos(buf, len);
  240|    620|	buf_incrlen(ret, len);
  241|    620|	buf_setpos(ret, 0);
  242|    620|	return ret;
  243|    647|}

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

dropbear_ed25519_verify:
  506|    119|{
  507|    119|  hash_state hs;
  508|    119|  u8 t[32],h[64];
  509|    119|  gf p[4],q[4];
  510|       |
  511|    119|  if (slen < 64) return -1;
  ------------------
  |  Branch (511:7): [True: 0, False: 119]
  ------------------
  512|       |
  513|    119|  if (s_lt_l(s + 32) == -1) {
  ------------------
  |  Branch (513:7): [True: 69, False: 50]
  ------------------
  514|     69|    return -1;
  515|     69|  }
  516|       |
  517|     50|  if (unpackneg(q,pk)) return -1;
  ------------------
  |  Branch (517:7): [True: 21, False: 29]
  ------------------
  518|       |
  519|     29|  sha512_init(&hs);
  520|     29|  sha512_process(&hs,s,32);
  521|     29|  sha512_process(&hs,pk,32);
  522|     29|  sha512_process(&hs,m,mlen);
  523|     29|  sha512_done(&hs,h);
  524|       |
  525|     29|  reduce(h);
  526|     29|  scalarmult(p,q,h);
  527|       |
  528|     29|  scalarbase(q,s + 32);
  529|     29|  add(p,q);
  530|     29|  pack(t,p);
  531|       |
  532|     29|  if (crypto_verify_32(s, t))
  ------------------
  |  Branch (532:7): [True: 27, False: 2]
  ------------------
  533|     27|    return -1;
  534|       |
  535|      2|  return 0;
  536|     29|}
curve25519.c:unpack25519:
  152|     50|{
  153|     50|  int i;
  154|    800|  FOR(i,16) o[i]=n[2*i]+((i64)n[2*i+1]<<8);
  ------------------
  |  |   34|    850|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 800, False: 50]
  |  |  ------------------
  ------------------
  155|     50|  o[15]&=0x7fff;
  156|     50|}
curve25519.c:sel25519:
   98|   119k|{
   99|   119k|  i64 t,i,c=~(b-1);
  100|  1.90M|  FOR(i,16) {
  ------------------
  |  |   34|  2.02M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 1.90M, False: 119k]
  |  |  ------------------
  ------------------
  101|  1.90M|    t= c&(p[i]^q[i]);
  102|  1.90M|    p[i]^=t;
  103|  1.90M|    q[i]^=t;
  104|  1.90M|  }
  105|   119k|}
curve25519.c:A:
  159|   148k|{
  160|   148k|  int i;
  161|  2.37M|  FOR(i,16) o[i]=a[i]+b[i];
  ------------------
  |  |   34|  2.52M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 2.37M, False: 148k]
  |  |  ------------------
  ------------------
  162|   148k|}
curve25519.c:Z:
  165|   118k|{
  166|   118k|  int i;
  167|  1.90M|  FOR(i,16) o[i]=a[i]-b[i];
  ------------------
  |  |   34|  2.02M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 1.90M, False: 118k]
  |  |  ------------------
  ------------------
  168|   118k|}
curve25519.c:S:
  182|  18.6k|{
  183|  18.6k|  M(o,a,a);
  184|  18.6k|}
curve25519.c:M:
  171|   305k|{
  172|   305k|  i64 i,j,t[31];
  173|  9.45M|  FOR(i,31) t[i]=0;
  ------------------
  |  |   34|  9.76M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 9.45M, False: 305k]
  |  |  ------------------
  ------------------
  174|  78.0M|  FOR(i,16) FOR(j,16) t[i+j]+=a[i]*b[j];
  ------------------
  |  |   34|  5.18M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 4.88M, False: 305k]
  |  |  ------------------
  ------------------
                FOR(i,16) FOR(j,16) t[i+j]+=a[i]*b[j];
  ------------------
  |  |   34|  82.9M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 78.0M, False: 4.88M]
  |  |  ------------------
  ------------------
  175|  4.57M|  FOR(i,15) t[i]+=38*t[i+16];
  ------------------
  |  |   34|  4.88M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 4.57M, False: 305k]
  |  |  ------------------
  ------------------
  176|  4.88M|  FOR(i,16) o[i]=t[i];
  ------------------
  |  |   34|  5.18M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 4.88M, False: 305k]
  |  |  ------------------
  ------------------
  177|   305k|  car25519(o);
  178|   305k|  car25519(o);
  179|   305k|}
curve25519.c:car25519:
   86|   610k|{
   87|   610k|  int i;
   88|   610k|  i64 c;
   89|  9.77M|  FOR(i,16) {
  ------------------
  |  |   34|  10.3M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 9.77M, False: 610k]
  |  |  ------------------
  ------------------
   90|  9.77M|    o[i]+=(1LL<<16);
   91|  9.77M|    c=o[i]>>16;
   92|  9.77M|    o[(i+1)*(i<15)]+=c-1+37*(c-1)*(i==15);
   93|  9.77M|    o[i]-=((u64)c)<<16;
   94|  9.77M|  }
   95|   610k|}
curve25519.c:inv25519:
  187|     29|{
  188|     29|  gf c;
  189|     29|  int a;
  190|    464|  FOR(a,16) c[a]=i[a];
  ------------------
  |  |   34|    493|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 464, False: 29]
  |  |  ------------------
  ------------------
  191|  7.39k|  for(a=253;a>=0;a--) {
  ------------------
  |  Branch (191:13): [True: 7.36k, False: 29]
  ------------------
  192|  7.36k|    S(c,c);
  193|  7.36k|    if(a!=2&&a!=4) M(c,c,i);
  ------------------
  |  Branch (193:8): [True: 7.33k, False: 29]
  |  Branch (193:14): [True: 7.30k, False: 29]
  ------------------
  194|  7.36k|  }
  195|    464|  FOR(a,16) o[a]=c[a];
  ------------------
  |  |   34|    493|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 464, False: 29]
  |  |  ------------------
  ------------------
  196|     29|}
curve25519.c:pack25519:
  108|    263|{
  109|    263|  int i,j,b;
  110|    263|  gf m,t;
  111|  4.20k|  FOR(i,16) t[i]=n[i];
  ------------------
  |  |   34|  4.47k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 4.20k, False: 263]
  |  |  ------------------
  ------------------
  112|    263|  car25519(t);
  113|    263|  car25519(t);
  114|    263|  car25519(t);
  115|    526|  FOR(j,2) {
  ------------------
  |  |   34|    789|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 526, False: 263]
  |  |  ------------------
  ------------------
  116|    526|    m[0]=t[0]-0xffed;
  117|  7.89k|    for(i=1;i<15;i++) {
  ------------------
  |  Branch (117:13): [True: 7.36k, False: 526]
  ------------------
  118|  7.36k|      m[i]=t[i]-0xffff-((m[i-1]>>16)&1);
  119|  7.36k|      m[i-1]&=0xffff;
  120|  7.36k|    }
  121|    526|    m[15]=t[15]-0x7fff-((m[14]>>16)&1);
  122|    526|    b=(m[15]>>16)&1;
  123|    526|    m[14]&=0xffff;
  124|    526|    sel25519(t,m,1-b);
  125|    526|  }
  126|  4.20k|  FOR(i,16) {
  ------------------
  |  |   34|  4.47k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 4.20k, False: 263]
  |  |  ------------------
  ------------------
  127|  4.20k|    o[2*i]=t[i]&0xff;
  128|  4.20k|    o[2*i+1]=t[i]>>8;
  129|  4.20k|  }
  130|    263|}
curve25519.c:scalarbase:
  333|     29|{
  334|     29|  gf q[4];
  335|     29|  set25519(q[0],X);
  336|     29|  set25519(q[1],Y);
  337|     29|  set25519(q[2],gf1);
  338|     29|  M(q[3],X,Y);
  339|     29|  scalarmult(p,q,s);
  340|     29|}
curve25519.c:set25519:
   79|    369|{
   80|    369|  int i;
   81|  5.90k|  FOR(i,16) r[i]=a[i];
  ------------------
  |  |   34|  6.27k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 5.90k, False: 369]
  |  |  ------------------
  ------------------
   82|    369|}
curve25519.c:pack:
  307|     29|{
  308|     29|  gf tx, ty, zi;
  309|     29|  inv25519(zi, p[2]); 
  310|     29|  M(tx, p[0], zi);
  311|     29|  M(ty, p[1], zi);
  312|     29|  pack25519(r, ty);
  313|     29|  r[31] ^= par25519(tx) << 7;
  314|     29|}
curve25519.c:par25519:
  144|     58|{
  145|     58|  u8 d[32];
  146|     58|  pack25519(d,a);
  147|     58|  return d[0]&1;
  148|     58|}
curve25519.c:reduce:
  387|     29|{
  388|     29|  i64 x[64],i;
  389|  1.85k|  FOR(i,64) x[i] = (u64) r[i];
  ------------------
  |  |   34|  1.88k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 1.85k, False: 29]
  |  |  ------------------
  ------------------
  390|  1.85k|  FOR(i,64) r[i] = 0;
  ------------------
  |  |   34|  1.88k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 1.85k, False: 29]
  |  |  ------------------
  ------------------
  391|     29|  modL(r,x);
  392|     29|}
curve25519.c:modL:
  361|     29|{
  362|     29|  i64 carry,i,j;
  363|    957|  for (i = 63;i >= 32;--i) {
  ------------------
  |  Branch (363:15): [True: 928, False: 29]
  ------------------
  364|    928|    carry = 0;
  365|  19.4k|    for (j = i - 32;j < i - 12;++j) {
  ------------------
  |  Branch (365:21): [True: 18.5k, False: 928]
  ------------------
  366|  18.5k|      x[j] += carry - 16 * x[i] * L[j - (i - 32)];
  367|  18.5k|      carry = (x[j] + 128) >> 8;
  368|  18.5k|      x[j] -= ((u64)carry) << 8;
  369|  18.5k|    }
  370|    928|    x[j] += carry;
  371|    928|    x[i] = 0;
  372|    928|  }
  373|     29|  carry = 0;
  374|    928|  FOR(j,32) {
  ------------------
  |  |   34|    957|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 928, False: 29]
  |  |  ------------------
  ------------------
  375|    928|    x[j] += carry - (x[31] >> 4) * L[j];
  376|    928|    carry = x[j] >> 8;
  377|    928|    x[j] &= 255;
  378|    928|  }
  379|    928|  FOR(j,32) x[j] -= carry * L[j];
  ------------------
  |  |   34|    957|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 928, False: 29]
  |  |  ------------------
  ------------------
  380|    928|  FOR(i,32) {
  ------------------
  |  |   34|    957|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 928, False: 29]
  |  |  ------------------
  ------------------
  381|    928|    x[i+1] += x[i] >> 8;
  382|    928|    r[i] = x[i] & 255;
  383|    928|  }
  384|     29|}
curve25519.c:s_lt_l:
  434|    119|static int s_lt_l(const u8 *s) {
  435|    119|  int i;
  436|    230|  for (i = 31; i >= 0; i--) {
  ------------------
  |  Branch (436:16): [True: 230, False: 0]
  ------------------
  437|    230|    if (s[i] < L[i]) {
  ------------------
  |  Branch (437:9): [True: 50, False: 180]
  ------------------
  438|     50|      return 0;
  439|     50|    }
  440|    180|    if (s[i] > L[i]) {
  ------------------
  |  Branch (440:9): [True: 69, False: 111]
  ------------------
  441|     69|      return -1;
  442|     69|    }
  443|    180|  }
  444|      0|  return -1;
  445|    119|}
curve25519.c:unpackneg:
  464|     50|{
  465|     50|  gf t, chk, num, den, den2, den4, den6;
  466|     50|  set25519(r[2],gf1);
  467|     50|  unpack25519(r[1],p);
  468|       |
  469|       |  /* Check that pubkey y < 2^255 - 19 */
  470|     50|  if (y_lt_p(r[1])) {
  ------------------
  |  Branch (470:7): [True: 6, False: 44]
  ------------------
  471|      6|    return -1;
  472|      6|  }
  473|       |
  474|     44|  S(num,r[1]);
  475|     44|  M(den,num,D);
  476|     44|  Z(num,num,r[2]);
  477|     44|  A(den,r[2],den);
  478|       |
  479|     44|  S(den2,den);
  480|     44|  S(den4,den2);
  481|     44|  M(den6,den4,den2);
  482|     44|  M(t,den6,num);
  483|     44|  M(t,t,den);
  484|       |
  485|     44|  pow2523(t,t);
  486|     44|  M(t,t,num);
  487|     44|  M(t,t,den);
  488|     44|  M(t,t,den);
  489|     44|  M(r[0],t,den);
  490|       |
  491|     44|  S(chk,r[0]);
  492|     44|  M(chk,chk,den);
  493|     44|  if (neq25519(chk, num)) M(r[0],r[0],I);
  ------------------
  |  Branch (493:7): [True: 31, False: 13]
  ------------------
  494|       |
  495|     44|  S(chk,r[0]);
  496|     44|  M(chk,chk,den);
  497|     44|  if (neq25519(chk, num)) return -1;
  ------------------
  |  Branch (497:7): [True: 15, False: 29]
  ------------------
  498|       |
  499|     29|  if (par25519(r[0]) == (p[31]>>7)) Z(r[0],gf0,r[0]);
  ------------------
  |  Branch (499:7): [True: 13, False: 16]
  ------------------
  500|       |
  501|     29|  M(r[3],r[0],r[1]);
  502|     29|  return 0;
  503|     44|}
curve25519.c:y_lt_p:
  450|     50|static int y_lt_p(const gf y) {
  451|     50|  int i;
  452|    182|  for (i = 15; i >= 0; i--) {
  ------------------
  |  Branch (452:16): [True: 181, False: 1]
  ------------------
  453|    181|    if (y[i] < field_prime[i]) {
  ------------------
  |  Branch (453:9): [True: 44, False: 137]
  ------------------
  454|     44|      return 0;
  455|     44|    }
  456|    137|    if (y[i] > field_prime[i]) {
  ------------------
  |  Branch (456:9): [True: 5, False: 132]
  ------------------
  457|      5|      return -1;
  458|      5|    }
  459|    137|  }
  460|      1|  return -1;
  461|     50|}
curve25519.c:pow2523:
  200|     44|{
  201|     44|  gf c;
  202|     44|  int a;
  203|    704|  FOR(a,16) c[a]=i[a];
  ------------------
  |  |   34|    748|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 704, False: 44]
  |  |  ------------------
  ------------------
  204|  11.0k|  for(a=250;a>=0;a--) {
  ------------------
  |  Branch (204:13): [True: 11.0k, False: 44]
  ------------------
  205|  11.0k|    S(c,c);
  206|  11.0k|    if(a!=1) M(c,c,i);
  ------------------
  |  Branch (206:8): [True: 11.0k, False: 44]
  ------------------
  207|  11.0k|  }
  208|    704|  FOR(a,16) o[a]=c[a];
  ------------------
  |  |   34|    748|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 704, False: 44]
  |  |  ------------------
  ------------------
  209|     44|}
curve25519.c:neq25519:
  135|     88|{
  136|     88|  u8 c[32],d[32];
  137|     88|  pack25519(c,a);
  138|     88|  pack25519(d,b);
  139|     88|  return crypto_verify_32(c,d);
  140|     88|}
curve25519.c:scalarmult:
  317|     58|{
  318|     58|  int i;
  319|     58|  set25519(p[0],gf0);
  320|     58|  set25519(p[1],gf1);
  321|     58|  set25519(p[2],gf1);
  322|     58|  set25519(p[3],gf0);
  323|  14.9k|  for (i = 255;i >= 0;--i) {
  ------------------
  |  Branch (323:16): [True: 14.8k, False: 58]
  ------------------
  324|  14.8k|    u8 b = (s[i/8]>>(i&7))&1;
  325|  14.8k|    cswap(p,q,b);
  326|  14.8k|    add(q,p);
  327|  14.8k|    add(p,p);
  328|  14.8k|    cswap(p,q,b);
  329|  14.8k|  }
  330|     58|}
curve25519.c:cswap:
  300|  29.6k|{
  301|  29.6k|  int i;
  302|  29.6k|  FOR(i,4)
  ------------------
  |  |   34|   148k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 118k, False: 29.6k]
  |  |  ------------------
  ------------------
  303|   118k|    sel25519(p[i],q[i],b);
  304|  29.6k|}
curve25519.c:add:
  275|  29.7k|{
  276|  29.7k|  gf a,b,c,d,t,e,f,g,h;
  277|       |  
  278|  29.7k|  Z(a, p[1], p[0]);
  279|  29.7k|  Z(t, q[1], q[0]);
  280|  29.7k|  M(a, a, t);
  281|  29.7k|  A(b, p[0], p[1]);
  282|  29.7k|  A(t, q[0], q[1]);
  283|  29.7k|  M(b, b, t);
  284|  29.7k|  M(c, p[3], q[3]);
  285|  29.7k|  M(c, c, D2);
  286|  29.7k|  M(d, p[2], q[2]);
  287|  29.7k|  A(d, d, d);
  288|  29.7k|  Z(e, b, a);
  289|  29.7k|  Z(f, d, c);
  290|  29.7k|  A(g, d, c);
  291|  29.7k|  A(h, b, a);
  292|       |
  293|  29.7k|  M(p[0], e, f);
  294|  29.7k|  M(p[1], h, g);
  295|  29.7k|  M(p[2], g, f);
  296|  29.7k|  M(p[3], e, h);
  297|  29.7k|}
curve25519.c:crypto_verify_32:
   73|    117|{
   74|    117|  return vn(x,y,32);
   75|    117|}
curve25519.c:vn:
   66|    117|{
   67|    117|  u32 i,d = 0;
   68|  3.74k|  FOR(i,n) d |= x[i]^y[i];
  ------------------
  |  |   34|  3.86k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 3.74k, False: 117]
  |  |  ------------------
  ------------------
   69|    117|  return (1 & ((d - 1) >> 8)) - 1;
   70|    117|}

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

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

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

dropbear_exit:
  105|    532|void dropbear_exit(const char* format, ...) {
  106|       |
  107|    532|	va_list param;
  108|       |
  109|    532|	va_start(param, format);
  110|    532|	_dropbear_exit(EXIT_FAILURE, format, param);
  111|    532|	va_end(param);
  112|      0|}
dropbear_log:
  148|    146|void dropbear_log(int priority, const char* format, ...) {
  149|       |
  150|    146|	va_list param;
  151|       |
  152|    146|	va_start(param, format);
  153|    146|	_dropbear_log(priority, format, param);
  154|       |	va_end(param);
  155|    146|}
disallow_core:
  660|      1|void disallow_core() {
  661|      1|	struct rlimit lim = {0};
  662|      1|	if (getrlimit(RLIMIT_CORE, &lim) < 0) {
  ------------------
  |  Branch (662:6): [True: 0, False: 1]
  ------------------
  663|      0|		TRACE(("getrlimit(RLIMIT_CORE) failed"));
  664|      0|	}
  665|      1|	lim.rlim_cur = 0;
  666|      1|	if (setrlimit(RLIMIT_CORE, &lim) < 0) {
  ------------------
  |  Branch (666:6): [True: 0, False: 1]
  ------------------
  667|      0|		TRACE(("setrlimit(RLIMIT_CORE) failed"));
  668|      0|	}
  669|      1|}
dbutil.c:generic_dropbear_exit:
  115|    532|		va_list param) {
  116|       |
  117|    532|	char fmtbuf[300];
  118|       |
  119|    532|	snprintf(fmtbuf, sizeof(fmtbuf), "Exited: %s", format);
  120|       |
  121|    532|	_dropbear_log(LOG_INFO, fmtbuf, param);
  122|       |
  123|    532|#if DROPBEAR_FUZZ
  124|    532|    if (fuzz.do_jmp) {
  ------------------
  |  Branch (124:9): [True: 532, False: 0]
  ------------------
  125|    532|        longjmp(fuzz.jmp, 1);
  126|    532|    }
  127|      0|#endif
  128|       |
  129|      0|	exit(exitcode);
  130|    532|}

buf_get_dss_pub_key:
   46|    344|int buf_get_dss_pub_key(buffer* buf, dropbear_dss_key *key) {
   47|    344|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  112|    344|#define DROPBEAR_FAILURE -1
  ------------------
   48|       |
   49|    344|	TRACE(("enter buf_get_dss_pub_key"))
   50|    344|	dropbear_assert(key != NULL);
  ------------------
  |  |   86|    344|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (86:37): [True: 0, False: 344]
  |  |  |  Branch (86:93): [Folded, False: 344]
  |  |  ------------------
  ------------------
   51|    344|	m_mp_alloc_init_multi(&key->p, &key->q, &key->g, &key->y, NULL);
   52|    344|	key->x = NULL;
   53|       |
   54|    344|	buf_incrpos(buf, 4+SSH_SIGNKEY_DSS_LEN); /* int + "ssh-dss" */
  ------------------
  |  |  115|    344|#define SSH_SIGNKEY_DSS_LEN 7
  ------------------
   55|    344|	if (buf_getmpint(buf, key->p) == DROPBEAR_FAILURE
  ------------------
  |  |  112|    688|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (55:6): [True: 17, False: 327]
  ------------------
   56|    327|	 || buf_getmpint(buf, key->q) == DROPBEAR_FAILURE
  ------------------
  |  |  112|    671|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (56:6): [True: 24, False: 303]
  ------------------
   57|    303|	 || buf_getmpint(buf, key->g) == DROPBEAR_FAILURE
  ------------------
  |  |  112|    647|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (57:6): [True: 8, False: 295]
  ------------------
   58|    295|	 || buf_getmpint(buf, key->y) == DROPBEAR_FAILURE) {
  ------------------
  |  |  112|    295|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (58:6): [True: 8, False: 287]
  ------------------
   59|     14|		TRACE(("leave buf_get_dss_pub_key: failed reading mpints"))
   60|     14|		ret = DROPBEAR_FAILURE;
  ------------------
  |  |  112|     14|#define DROPBEAR_FAILURE -1
  ------------------
   61|     14|		goto out;
   62|     14|	}
   63|       |
   64|    330|	if (mp_count_bits(key->p) != DSS_P_BITS) {
  ------------------
  |  |   44|    330|#define DSS_P_BITS 1024
  ------------------
  |  Branch (64:6): [True: 24, False: 306]
  ------------------
   65|     24|		dropbear_log(LOG_WARNING, "Bad DSS p");
   66|     24|		ret = DROPBEAR_FAILURE;
  ------------------
  |  |  112|     24|#define DROPBEAR_FAILURE -1
  ------------------
   67|     24|		goto out;
   68|     24|	}
   69|       |
   70|    306|	if (mp_count_bits(key->q) != DSS_Q_BITS) {
  ------------------
  |  |   45|    306|#define DSS_Q_BITS 160
  ------------------
  |  Branch (70:6): [True: 26, False: 280]
  ------------------
   71|     26|		dropbear_log(LOG_WARNING, "Bad DSS q");
   72|     26|		ret = DROPBEAR_FAILURE;
  ------------------
  |  |  112|     26|#define DROPBEAR_FAILURE -1
  ------------------
   73|     26|		goto out;
   74|     26|	}
   75|       |
   76|       |	/* test 1 < g < p */
   77|    280|	if (mp_cmp_d(key->g, 1) != MP_GT) {
  ------------------
  |  |  156|    280|#define MP_GT         1   /* greater than */
  ------------------
  |  Branch (77:6): [True: 1, False: 279]
  ------------------
   78|      1|		dropbear_log(LOG_WARNING, "Bad DSS g");
   79|      1|		ret = DROPBEAR_FAILURE;
  ------------------
  |  |  112|      1|#define DROPBEAR_FAILURE -1
  ------------------
   80|      1|		goto out;
   81|      1|	}
   82|    279|	if (mp_cmp(key->g, key->p) != MP_LT) {
  ------------------
  |  |  154|    279|#define MP_LT        -1   /* less than */
  ------------------
  |  Branch (82:6): [True: 2, False: 277]
  ------------------
   83|      2|		dropbear_log(LOG_WARNING, "Bad DSS g");
   84|      2|		ret = DROPBEAR_FAILURE;
  ------------------
  |  |  112|      2|#define DROPBEAR_FAILURE -1
  ------------------
   85|      2|		goto out;
   86|      2|	}
   87|       |
   88|    277|	ret = DROPBEAR_SUCCESS;
  ------------------
  |  |  111|    277|#define DROPBEAR_SUCCESS 0
  ------------------
   89|    277|	TRACE(("leave buf_get_dss_pub_key: success"))
   90|    301|out:
   91|    301|	if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  112|    301|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (91:6): [True: 67, False: 234]
  ------------------
   92|       |		m_mp_free_multi(&key->p, &key->q, &key->g, &key->y, NULL);
   93|     67|	}
   94|    301|	return ret;
   95|    277|}
dss_key_free:
  122|  2.70k|void dss_key_free(dropbear_dss_key *key) {
  123|       |
  124|  2.70k|	TRACE2(("enter dsa_key_free"))
  125|  2.70k|	if (key == NULL) {
  ------------------
  |  Branch (125:6): [True: 2.41k, False: 299]
  ------------------
  126|  2.41k|		TRACE2(("enter dsa_key_free: key == NULL"))
  127|  2.41k|		return;
  128|  2.41k|	}
  129|    299|	m_mp_free_multi(&key->p, &key->q, &key->g, &key->y, &key->x, NULL);
  130|       |	m_free(key);
  ------------------
  |  |   24|    299|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 299]
  |  |  ------------------
  ------------------
  131|    299|	TRACE2(("leave dsa_key_free"))
  132|    299|}
buf_dss_verify:
  165|    233|int buf_dss_verify(buffer* buf, const dropbear_dss_key *key, const buffer *data_buf) {
  166|    233|	unsigned char msghash[SHA1_HASH_SIZE];
  167|    233|	hash_state hs;
  168|    233|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  112|    233|#define DROPBEAR_FAILURE -1
  ------------------
  169|    233|	DEF_MP_INT(val1);
  ------------------
  |  |   83|    233|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  170|    233|	DEF_MP_INT(val2);
  ------------------
  |  |   83|    233|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  171|    233|	DEF_MP_INT(val3);
  ------------------
  |  |   83|    233|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  172|    233|	DEF_MP_INT(val4);
  ------------------
  |  |   83|    233|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  173|    233|	char * string = NULL;
  174|    233|	unsigned int stringlen;
  175|       |
  176|    233|	TRACE(("enter buf_dss_verify"))
  177|    233|	dropbear_assert(key != NULL);
  ------------------
  |  |   86|    233|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (86:37): [True: 0, False: 233]
  |  |  |  Branch (86:93): [Folded, False: 233]
  |  |  ------------------
  ------------------
  178|       |
  179|    233|	m_mp_init_multi(&val1, &val2, &val3, &val4, NULL);
  180|       |
  181|       |	/* get blob, check length */
  182|    233|	string = buf_getstring(buf, &stringlen);
  183|    233|	if (stringlen != 2*SHA1_HASH_SIZE) {
  ------------------
  |  |  133|    233|#define SHA1_HASH_SIZE 20
  ------------------
  |  Branch (183:6): [True: 18, False: 215]
  ------------------
  184|     18|		goto out;
  185|     18|	}
  186|       |
  187|       |#if DEBUG_DSS_VERIFY
  188|       |	printmpint("dss verify p", key->p);
  189|       |	printmpint("dss verify q", key->q);
  190|       |	printmpint("dss verify g", key->g);
  191|       |	printmpint("dss verify y", key->y);
  192|       |#endif
  193|       |
  194|       |	/* hash the data */
  195|    215|	sha1_init(&hs);
  196|    215|	sha1_process(&hs, data_buf->data, data_buf->len);
  197|    215|	sha1_done(&hs, msghash);
  198|       |
  199|       |	/* create the signature - s' and r' are the received signatures in buf */
  200|       |	/* w = (s')-1 mod q */
  201|       |	/* let val1 = s' */
  202|    215|	bytes_to_mp(&val1, (const unsigned char*) &string[SHA1_HASH_SIZE], SHA1_HASH_SIZE);
  ------------------
  |  |  133|    215|#define SHA1_HASH_SIZE 20
  ------------------
              	bytes_to_mp(&val1, (const unsigned char*) &string[SHA1_HASH_SIZE], SHA1_HASH_SIZE);
  ------------------
  |  |  133|    215|#define SHA1_HASH_SIZE 20
  ------------------
  203|       |#if DEBUG_DSS_VERIFY
  204|       |	printmpint("dss verify s'", &val1);
  205|       |#endif
  206|       |
  207|    215|	if (mp_cmp(&val1, key->q) != MP_LT) {
  ------------------
  |  |  154|    215|#define MP_LT        -1   /* less than */
  ------------------
  |  Branch (207:6): [True: 2, False: 213]
  ------------------
  208|      2|		TRACE(("verify failed, s' >= q"))
  209|      2|		goto out;
  210|      2|	}
  211|    213|	if (mp_cmp_d(&val1, 0) != MP_GT) {
  ------------------
  |  |  156|    213|#define MP_GT         1   /* greater than */
  ------------------
  |  Branch (211:6): [True: 1, False: 212]
  ------------------
  212|      1|		TRACE(("verify failed, s' <= 0"))
  213|      1|		goto out;
  214|      1|	}
  215|       |	/* let val2 = w = (s')^-1 mod q*/
  216|    212|	if (mp_invmod(&val1, key->q, &val2) != MP_OKAY) {
  ------------------
  |  |  161|    212|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (216:6): [True: 7, False: 205]
  ------------------
  217|      7|		goto out;
  218|      7|	}
  219|       |
  220|       |	/* u1 = ((SHA(M')w) mod q */
  221|       |	/* let val1 = SHA(M') = msghash */
  222|    205|	bytes_to_mp(&val1, msghash, SHA1_HASH_SIZE);
  ------------------
  |  |  133|    205|#define SHA1_HASH_SIZE 20
  ------------------
  223|       |#if DEBUG_DSS_VERIFY
  224|       |	printmpint("dss verify r'", &val1);
  225|       |#endif
  226|       |
  227|       |	/* let val3 = u1 = ((SHA(M')w) mod q */
  228|    205|	if (mp_mulmod(&val1, &val2, key->q, &val3) != MP_OKAY) {
  ------------------
  |  |  161|    205|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (228:6): [True: 0, False: 205]
  ------------------
  229|      0|		goto out;
  230|      0|	}
  231|       |
  232|       |	/* u2 = ((r')w) mod q */
  233|       |	/* let val1 = r' */
  234|    205|	bytes_to_mp(&val1, (const unsigned char*) &string[0], SHA1_HASH_SIZE);
  ------------------
  |  |  133|    205|#define SHA1_HASH_SIZE 20
  ------------------
  235|    205|	if (mp_cmp(&val1, key->q) != MP_LT) {
  ------------------
  |  |  154|    205|#define MP_LT        -1   /* less than */
  ------------------
  |  Branch (235:6): [True: 2, False: 203]
  ------------------
  236|      2|		TRACE(("verify failed, r' >= q"))
  237|      2|		goto out;
  238|      2|	}
  239|    203|	if (mp_cmp_d(&val1, 0) != MP_GT) {
  ------------------
  |  |  156|    203|#define MP_GT         1   /* greater than */
  ------------------
  |  Branch (239:6): [True: 1, False: 202]
  ------------------
  240|      1|		TRACE(("verify failed, r' <= 0"))
  241|      1|		goto out;
  242|      1|	}
  243|       |	/* let val4 = u2 = ((r')w) mod q */
  244|    202|	if (mp_mulmod(&val1, &val2, key->q, &val4) != MP_OKAY) {
  ------------------
  |  |  161|    202|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (244:6): [True: 0, False: 202]
  ------------------
  245|      0|		goto out;
  246|      0|	}
  247|       |
  248|       |	/* v = (((g)^u1 (y)^u2) mod p) mod q */
  249|       |	/* val2 = g^u1 mod p */
  250|    202|	if (mp_exptmod(key->g, &val3, key->p, &val2) != MP_OKAY) {
  ------------------
  |  |  161|    202|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (250:6): [True: 0, False: 202]
  ------------------
  251|      0|		goto out;
  252|      0|	}
  253|       |	/* val3 = y^u2 mod p */
  254|    202|	if (mp_exptmod(key->y, &val4, key->p, &val3) != MP_OKAY) {
  ------------------
  |  |  161|    202|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (254:6): [True: 0, False: 202]
  ------------------
  255|      0|		goto out;
  256|      0|	}
  257|       |	/* val4 = ((g)^u1 (y)^u2) mod p */
  258|    202|	if (mp_mulmod(&val2, &val3, key->p, &val4) != MP_OKAY) {
  ------------------
  |  |  161|    202|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (258:6): [True: 0, False: 202]
  ------------------
  259|      0|		goto out;
  260|      0|	}
  261|       |	/* val2 = v = (((g)^u1 (y)^u2) mod p) mod q */
  262|    202|	if (mp_mod(&val4, key->q, &val2) != MP_OKAY) {
  ------------------
  |  |  161|    202|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (262:6): [True: 0, False: 202]
  ------------------
  263|      0|		goto out;
  264|      0|	}
  265|       |	
  266|       |	/* check whether signatures verify */
  267|    202|	if (mp_cmp(&val2, &val1) == MP_EQ) {
  ------------------
  |  |  155|    202|#define MP_EQ         0   /* equal to */
  ------------------
  |  Branch (267:6): [True: 112, False: 90]
  ------------------
  268|       |		/* good sig */
  269|    112|		ret = DROPBEAR_SUCCESS;
  ------------------
  |  |  111|    112|#define DROPBEAR_SUCCESS 0
  ------------------
  270|    112|	}
  271|       |
  272|    232|out:
  273|    232|	mp_clear_multi(&val1, &val2, &val3, &val4, NULL);
  274|    232|	m_free(string);
  ------------------
  |  |   24|    232|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 232]
  |  |  ------------------
  ------------------
  275|       |
  276|    232|	return ret;
  277|       |
  278|    202|}

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

signkey_is_ecdsa:
   11|  3.12k|{
   12|  3.12k|	return type == DROPBEAR_SIGNKEY_ECDSA_NISTP256
  ------------------
  |  Branch (12:9): [True: 656, False: 2.46k]
  ------------------
   13|  2.46k|		|| type == DROPBEAR_SIGNKEY_ECDSA_NISTP384
  ------------------
  |  Branch (13:6): [True: 144, False: 2.32k]
  ------------------
   14|  2.32k|		|| type == DROPBEAR_SIGNKEY_ECDSA_NISTP521;
  ------------------
  |  Branch (14:6): [True: 184, False: 2.13k]
  ------------------
   15|  3.12k|}
buf_get_ecdsa_pub_key:
   77|    773|ecc_key *buf_get_ecdsa_pub_key(buffer* buf) {
   78|    773|	unsigned char *key_ident = NULL, *identifier = NULL;
   79|    773|	unsigned int key_ident_len, identifier_len;
   80|    773|	buffer *q_buf = NULL;
   81|    773|	struct dropbear_ecc_curve **curve;
   82|    773|	ecc_key *new_key = NULL;
   83|       |
   84|       |	/* string   "ecdsa-sha2-[identifier]" or "sk-ecdsa-sha2-nistp256@openssh.com" */
   85|    773|	key_ident = (unsigned char*)buf_getstring(buf, &key_ident_len);
   86|       |	/* string   "[identifier]" */
   87|    773|	identifier = (unsigned char*)buf_getstring(buf, &identifier_len);
   88|       |
   89|    773|	if (strcmp (key_ident, "sk-ecdsa-sha2-nistp256@openssh.com") == 0) {
  ------------------
  |  Branch (89:6): [True: 93, False: 680]
  ------------------
   90|     93|		if (strcmp (identifier, "nistp256") != 0) {
  ------------------
  |  Branch (90:7): [True: 76, False: 17]
  ------------------
   91|     76|			TRACE(("mismatching identifiers"))
   92|     76|			goto out;
   93|     76|		}
   94|    680|	} else {
   95|    680|		if (key_ident_len != identifier_len + strlen ("ecdsa-sha2-")) {
  ------------------
  |  Branch (95:7): [True: 30, False: 650]
  ------------------
   96|     30|			TRACE(("Bad identifier lengths"))
   97|     30|			goto out;
   98|     30|		}
   99|    650|		if (memcmp(&key_ident[strlen ("ecdsa-sha2-")], identifier, identifier_len) != 0) {
  ------------------
  |  Branch (99:7): [True: 16, False: 634]
  ------------------
  100|     16|			TRACE(("mismatching identifiers"))
  101|     16|			goto out;
  102|     16|		}
  103|    650|	}
  104|       |
  105|    956|	for (curve = dropbear_ecc_curves; *curve; curve++) {
  ------------------
  |  Branch (105:36): [True: 952, False: 4]
  ------------------
  106|    952|		if (strcmp((char*)identifier, (*curve)->name) == 0) {
  ------------------
  |  Branch (106:7): [True: 647, False: 305]
  ------------------
  107|    647|			break;
  108|    647|		}
  109|    952|	}
  110|    651|	if (!*curve) {
  ------------------
  |  Branch (110:6): [True: 0, False: 651]
  ------------------
  111|      0|		TRACE(("couldn't match ecc curve"))
  112|      0|		goto out;
  113|      0|	}
  114|       |
  115|       |	/* string Q */
  116|    651|	q_buf = buf_getstringbuf(buf);
  117|    651|	new_key = buf_get_ecc_raw_pubkey(q_buf, *curve);
  118|       |
  119|    686|out:
  120|    686|	m_free(key_ident);
  ------------------
  |  |   24|    686|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 686]
  |  |  ------------------
  ------------------
  121|    686|	m_free(identifier);
  ------------------
  |  |   24|    686|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 686]
  |  |  ------------------
  ------------------
  122|    686|	if (q_buf) {
  ------------------
  |  Branch (122:6): [True: 564, False: 122]
  ------------------
  123|    564|		buf_free(q_buf);
  124|       |		q_buf = NULL;
  125|    564|	}
  126|    686|	TRACE(("leave buf_get_ecdsa_pub_key"))	
  127|    686|	return new_key;
  128|    651|}
buf_ecdsa_verify:
  281|    305|int buf_ecdsa_verify(buffer *buf, const ecc_key *key, const buffer *data_buf) {
  282|       |	/* Based on libtomcrypt's ecc_verify_hash but without the asn1 */
  283|    305|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  112|    305|#define DROPBEAR_FAILURE -1
  ------------------
  284|    305|	hash_state hs;
  285|    305|	struct dropbear_ecc_curve *curve = NULL;
  286|    305|	unsigned char hash[64];
  287|    305|	ecc_point *mG = NULL, *mQ = NULL;
  288|    305|	void *r = NULL, *s = NULL, *v = NULL, *w = NULL, *u1 = NULL, *u2 = NULL, 
  289|    305|		*e = NULL, *p = NULL, *m = NULL;
  290|    305|	void *mp = NULL;
  291|       |
  292|       |	/* verify 
  293|       |	 *
  294|       |	 * w  = s^-1 mod n
  295|       |	 * u1 = xw 
  296|       |	 * u2 = rw
  297|       |	 * X = u1*G + u2*Q
  298|       |	 * v = X_x1 mod n
  299|       |	 * accept if v == r
  300|       |	 */
  301|       |
  302|    305|	TRACE(("buf_ecdsa_verify"))
  303|    305|	curve = curve_for_dp(key->dp);
  304|       |
  305|    305|	mG = ltc_ecc_new_point();
  306|    305|	mQ = ltc_ecc_new_point();
  307|    305|	if (ltc_init_multi(&r, &s, &v, &w, &u1, &u2, &p, &e, &m, NULL) != CRYPT_OK
  ------------------
  |  Branch (307:6): [True: 0, False: 305]
  ------------------
  308|    305|		|| !mG
  ------------------
  |  Branch (308:6): [True: 0, False: 305]
  ------------------
  309|    305|		|| !mQ) {
  ------------------
  |  Branch (309:6): [True: 0, False: 305]
  ------------------
  310|      0|		dropbear_exit("ECC error");
  311|      0|	}
  312|       |
  313|    305|	if (buf_get_ecdsa_verify_params(buf, r, s) != DROPBEAR_SUCCESS) {
  ------------------
  |  |  111|    305|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (313:6): [True: 37, False: 268]
  ------------------
  314|     37|		goto out;
  315|     37|	}
  316|       |
  317|    268|	curve->hash_desc->init(&hs);
  318|    268|	curve->hash_desc->process(&hs, data_buf->data, data_buf->len);
  319|    268|	curve->hash_desc->done(&hs, hash);
  320|       |
  321|    268|	if (ltc_mp.unsigned_read(e, hash, curve->hash_desc->hashsize) != CRYPT_OK) {
  ------------------
  |  Branch (321:6): [True: 0, False: 268]
  ------------------
  322|      0|		goto out;
  323|      0|	}
  324|       |
  325|       |   /* get the order */
  326|    268|	if (ltc_mp.read_radix(p, (char *)key->dp->order, 16) != CRYPT_OK) { 
  ------------------
  |  Branch (326:6): [True: 0, False: 268]
  ------------------
  327|      0|		goto out; 
  328|      0|	}
  329|       |
  330|       |   /* get the modulus */
  331|    268|	if (ltc_mp.read_radix(m, (char *)key->dp->prime, 16) != CRYPT_OK) { 
  ------------------
  |  Branch (331:6): [True: 0, False: 268]
  ------------------
  332|      0|		goto out; 
  333|      0|	}
  334|       |
  335|       |   /* check for zero */
  336|    268|	if (ltc_mp.compare_d(r, 0) == LTC_MP_EQ 
  ------------------
  |  |   13|    536|#define LTC_MP_EQ    0
  ------------------
  |  Branch (336:6): [True: 6, False: 262]
  ------------------
  337|    262|		|| ltc_mp.compare_d(s, 0) == LTC_MP_EQ 
  ------------------
  |  |   13|    530|#define LTC_MP_EQ    0
  ------------------
  |  Branch (337:6): [True: 1, False: 261]
  ------------------
  338|    261|		|| ltc_mp.compare(r, p) != LTC_MP_LT 
  ------------------
  |  |   12|    529|#define LTC_MP_LT   -1
  ------------------
  |  Branch (338:6): [True: 1, False: 260]
  ------------------
  339|    260|		|| ltc_mp.compare(s, p) != LTC_MP_LT) {
  ------------------
  |  |   12|    260|#define LTC_MP_LT   -1
  ------------------
  |  Branch (339:6): [True: 1, False: 259]
  ------------------
  340|      6|		goto out;
  341|      6|	}
  342|       |
  343|       |   /*  w  = s^-1 mod n */
  344|    262|	if (ltc_mp.invmod(s, p, w) != CRYPT_OK) { 
  ------------------
  |  Branch (344:6): [True: 0, False: 262]
  ------------------
  345|      0|		goto out; 
  346|      0|	}
  347|       |
  348|       |   /* u1 = ew */
  349|    262|	if (ltc_mp.mulmod(e, w, p, u1) != CRYPT_OK) { 
  ------------------
  |  Branch (349:6): [True: 0, False: 262]
  ------------------
  350|      0|		goto out; 
  351|      0|	}
  352|       |
  353|       |   /* u2 = rw */
  354|    262|	if (ltc_mp.mulmod(r, w, p, u2) != CRYPT_OK) { 
  ------------------
  |  Branch (354:6): [True: 0, False: 262]
  ------------------
  355|      0|		goto out; 
  356|      0|	}
  357|       |
  358|       |   /* find mG and mQ */
  359|    262|	if (ltc_mp.read_radix(mG->x, (char *)key->dp->Gx, 16) != CRYPT_OK) { 
  ------------------
  |  Branch (359:6): [True: 0, False: 262]
  ------------------
  360|      0|		goto out; 
  361|      0|	}
  362|    262|	if (ltc_mp.read_radix(mG->y, (char *)key->dp->Gy, 16) != CRYPT_OK) { 
  ------------------
  |  Branch (362:6): [True: 0, False: 262]
  ------------------
  363|      0|		goto out; 
  364|      0|	}
  365|    262|	if (ltc_mp.set_int(mG->z, 1) != CRYPT_OK) { 
  ------------------
  |  Branch (365:6): [True: 0, False: 262]
  ------------------
  366|      0|		goto out; 
  367|      0|	}
  368|       |
  369|    262|	if (ltc_mp.copy(key->pubkey.x, mQ->x) != CRYPT_OK
  ------------------
  |  Branch (369:6): [True: 3, False: 259]
  ------------------
  370|    259|		|| ltc_mp.copy(key->pubkey.y, mQ->y) != CRYPT_OK
  ------------------
  |  Branch (370:6): [True: 0, False: 259]
  ------------------
  371|    259|		|| ltc_mp.copy(key->pubkey.z, mQ->z) != CRYPT_OK) { 
  ------------------
  |  Branch (371:6): [True: 0, False: 259]
  ------------------
  372|      0|		goto out; 
  373|      0|	}
  374|       |
  375|       |   /* compute u1*mG + u2*mQ = mG */
  376|    262|	if (ltc_mp.ecc_mul2add == NULL) {
  ------------------
  |  Branch (376:6): [True: 0, False: 262]
  ------------------
  377|      0|		if (ltc_mp.ecc_ptmul(u1, mG, mG, m, 0) != CRYPT_OK) { 
  ------------------
  |  Branch (377:7): [True: 0, False: 0]
  ------------------
  378|      0|			goto out; 
  379|      0|		}
  380|      0|		if (ltc_mp.ecc_ptmul(u2, mQ, mQ, m, 0) != CRYPT_OK) {
  ------------------
  |  Branch (380:7): [True: 0, False: 0]
  ------------------
  381|      0|			goto out; 
  382|      0|		}
  383|       |
  384|       |		/* find the montgomery mp */
  385|      0|		if (ltc_mp.montgomery_setup(m, &mp) != CRYPT_OK) { 
  ------------------
  |  Branch (385:7): [True: 0, False: 0]
  ------------------
  386|      0|			goto out; 
  387|      0|		}
  388|       |
  389|       |		/* add them */
  390|      0|		if (ltc_mp.ecc_ptadd(mQ, mG, mG, m, mp) != CRYPT_OK) { 
  ------------------
  |  Branch (390:7): [True: 0, False: 0]
  ------------------
  391|      0|			goto out; 
  392|      0|		}
  393|       |
  394|       |		/* reduce */
  395|      0|		if (ltc_mp.ecc_map(mG, m, mp) != CRYPT_OK) { 
  ------------------
  |  Branch (395:7): [True: 0, False: 0]
  ------------------
  396|      0|			goto out; 
  397|      0|		}
  398|    262|	} else {
  399|       |		/* use Shamir's trick to compute u1*mG + u2*mQ using half of the doubles */
  400|    262|		if (ltc_mp.ecc_mul2add(mG, u1, mQ, u2, mG, m) != CRYPT_OK) { 
  ------------------
  |  Branch (400:7): [True: 0, False: 262]
  ------------------
  401|      0|			goto out; 
  402|      0|		}
  403|    262|	}
  404|       |
  405|       |   /* v = X_x1 mod n */
  406|    262|	if (ltc_mp.mpdiv(mG->x, p, NULL, v) != CRYPT_OK) { 
  ------------------
  |  Branch (406:6): [True: 0, False: 262]
  ------------------
  407|      0|		goto out; 
  408|      0|	}
  409|       |
  410|       |   /* does v == r */
  411|    262|	if (ltc_mp.compare(v, r) == LTC_MP_EQ) {
  ------------------
  |  |   13|    262|#define LTC_MP_EQ    0
  ------------------
  |  Branch (411:6): [True: 0, False: 262]
  ------------------
  412|      0|		ret = DROPBEAR_SUCCESS;
  ------------------
  |  |  111|      0|#define DROPBEAR_SUCCESS 0
  ------------------
  413|      0|	}
  414|       |
  415|    302|out:
  416|    302|	ltc_ecc_del_point(mG);
  417|    302|	ltc_ecc_del_point(mQ);
  418|    302|	ltc_deinit_multi(r, s, v, w, u1, u2, p, e, m, NULL);
  419|    302|	if (mp != NULL) { 
  ------------------
  |  Branch (419:6): [True: 0, False: 302]
  ------------------
  420|      0|		ltc_mp.montgomery_deinit(mp);
  421|      0|	}
  422|    302|	return ret;
  423|    262|}
ecdsa.c:buf_get_ecdsa_verify_params:
  258|    305|			void *r, void* s) {
  259|    305|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  112|    305|#define DROPBEAR_FAILURE -1
  ------------------
  260|    305|	unsigned int sig_len;
  261|    305|	unsigned int sig_pos;
  262|       |
  263|    305|	sig_len = buf_getint(buf);
  264|    305|	sig_pos = buf->pos;
  265|    305|	if (buf_getmpint(buf, r) != DROPBEAR_SUCCESS) {
  ------------------
  |  |  111|    305|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (265:6): [True: 3, False: 302]
  ------------------
  266|      3|		goto out;
  267|      3|	}
  268|    302|	if (buf_getmpint(buf, s) != DROPBEAR_SUCCESS) {
  ------------------
  |  |  111|    302|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (268:6): [True: 1, False: 301]
  ------------------
  269|      1|		goto out;
  270|      1|	}
  271|    301|	if (buf->pos - sig_pos != sig_len) {
  ------------------
  |  Branch (271:6): [True: 33, False: 268]
  ------------------
  272|     33|		goto out;
  273|     33|	}
  274|    268|	ret = DROPBEAR_SUCCESS;
  ------------------
  |  |  111|    268|#define DROPBEAR_SUCCESS 0
  ------------------
  275|       |
  276|    302|out:
  277|    302|	return ret;
  278|    268|}

buf_get_ed25519_pub_key:
   42|    366|	enum signkey_type expect_keytype) {
   43|       |
   44|       |
   45|    366|	unsigned int len, typelen;
   46|    366|	char *keytype = NULL;
   47|    366|	enum signkey_type buf_keytype;
   48|       |
   49|    366|	TRACE(("enter buf_get_ed25519_pub_key"))
   50|    366|	dropbear_assert(key != NULL);
  ------------------
  |  |   86|    366|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (86:37): [True: 0, False: 366]
  |  |  |  Branch (86:93): [Folded, False: 366]
  |  |  ------------------
  ------------------
   51|       |
   52|       |	/* consume and check the key string */
   53|    366|	keytype = buf_getstring(buf, &typelen);
   54|    366|	buf_keytype = signkey_type_from_name(keytype, typelen);
   55|    366|	m_free(keytype);
  ------------------
  |  |   24|    366|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 366]
  |  |  ------------------
  ------------------
   56|    366|	if (buf_keytype != expect_keytype) {
  ------------------
  |  Branch (56:6): [True: 0, False: 366]
  ------------------
   57|      0|		TRACE(("leave buf_get_ed25519_pub_key: mismatch key type"))
   58|      0|		return DROPBEAR_FAILURE;
  ------------------
  |  |  112|      0|#define DROPBEAR_FAILURE -1
  ------------------
   59|      0|	}
   60|       |
   61|    366|	len = buf_getint(buf);
   62|    366|	if (len != CURVE25519_LEN || buf->len - buf->pos < len) {
  ------------------
  |  |   34|    732|#define CURVE25519_LEN 32
  ------------------
  |  Branch (62:6): [True: 55, False: 311]
  |  Branch (62:31): [True: 9, False: 302]
  ------------------
   63|     58|		TRACE(("leave buf_get_ed25519_pub_key: failure"))
   64|     58|		return DROPBEAR_FAILURE;
  ------------------
  |  |  112|     58|#define DROPBEAR_FAILURE -1
  ------------------
   65|     58|	}
   66|       |
   67|    308|	m_burn(key->priv, CURVE25519_LEN);
  ------------------
  |  |   34|    308|#define CURVE25519_LEN 32
  ------------------
   68|    308|	memcpy(key->pub, buf_getptr(buf, CURVE25519_LEN), CURVE25519_LEN);
  ------------------
  |  |   34|    308|#define CURVE25519_LEN 32
  ------------------
              	memcpy(key->pub, buf_getptr(buf, CURVE25519_LEN), CURVE25519_LEN);
  ------------------
  |  |   34|    308|#define CURVE25519_LEN 32
  ------------------
   69|    308|	buf_incrpos(buf, CURVE25519_LEN);
  ------------------
  |  |   34|    308|#define CURVE25519_LEN 32
  ------------------
   70|       |
   71|    308|	TRACE(("leave buf_get_ed25519_pub_key: success"))
   72|    308|	return DROPBEAR_SUCCESS;
  ------------------
  |  |  111|    308|#define DROPBEAR_SUCCESS 0
  ------------------
   73|    366|}
ed25519_key_free:
  103|  2.66k|void ed25519_key_free(dropbear_ed25519_key *key) {
  104|       |
  105|  2.66k|	TRACE2(("enter ed25519_key_free"))
  106|       |
  107|  2.66k|	if (key == NULL) {
  ------------------
  |  Branch (107:6): [True: 2.45k, False: 213]
  ------------------
  108|  2.45k|		TRACE2(("leave ed25519_key_free: key == NULL"))
  109|  2.45k|		return;
  110|  2.45k|	}
  111|    213|	m_burn(key->priv, CURVE25519_LEN);
  ------------------
  |  |   34|    213|#define CURVE25519_LEN 32
  ------------------
  112|    213|	m_free(key);
  ------------------
  |  |   24|    213|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 213]
  |  |  ------------------
  ------------------
  113|       |
  114|    213|	TRACE2(("leave ed25519_key_free"))
  115|    213|}
buf_ed25519_verify:
  163|     97|int buf_ed25519_verify(buffer *buf, const dropbear_ed25519_key *key, const buffer *data_buf) {
  164|       |
  165|     97|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  112|     97|#define DROPBEAR_FAILURE -1
  ------------------
  166|     97|	unsigned char *s;
  167|     97|	unsigned long slen;
  168|       |
  169|     97|	TRACE(("enter buf_ed25519_verify"))
  170|     97|	dropbear_assert(key != NULL);
  ------------------
  |  |   86|     97|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (86:37): [True: 0, False: 97]
  |  |  |  Branch (86:93): [Folded, False: 97]
  |  |  ------------------
  ------------------
  171|       |
  172|     97|	slen = buf_getint(buf);
  173|     97|	if (slen != 64 || buf->len - buf->pos < slen) {
  ------------------
  |  Branch (173:6): [True: 40, False: 57]
  |  Branch (173:20): [True: 11, False: 46]
  ------------------
  174|     50|		TRACE(("leave buf_ed25519_verify: bad size"))
  175|     50|		goto out;
  176|     50|	}
  177|     47|	s = buf_getptr(buf, slen);
  178|       |
  179|     47|	if (dropbear_ed25519_verify(data_buf->data, data_buf->len,
  ------------------
  |  Branch (179:6): [True: 0, False: 47]
  ------------------
  180|     47|				    s, slen, key->pub) == 0) {
  181|       |		/* signature is valid */
  182|      0|		TRACE(("leave buf_ed25519_verify: success!"))
  183|      0|		ret = DROPBEAR_SUCCESS;
  ------------------
  |  |  111|      0|#define DROPBEAR_SUCCESS 0
  ------------------
  184|      0|	}
  185|       |
  186|     96|out:
  187|     96|	TRACE(("leave buf_ed25519_verify: ret %d", ret))
  188|     96|	return ret;
  189|     47|}

buf_get_rsa_pub_key:
   53|  1.13k|int buf_get_rsa_pub_key(buffer* buf, dropbear_rsa_key *key) {
   54|       |
   55|  1.13k|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  112|  1.13k|#define DROPBEAR_FAILURE -1
  ------------------
   56|  1.13k|	TRACE(("enter buf_get_rsa_pub_key"))
   57|  1.13k|	dropbear_assert(key != NULL);
  ------------------
  |  |   86|  1.13k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (86:37): [True: 0, False: 1.13k]
  |  |  |  Branch (86:93): [Folded, False: 1.13k]
  |  |  ------------------
  ------------------
   58|  1.13k|	m_mp_alloc_init_multi(&key->e, &key->n, NULL);
   59|  1.13k|	key->d = NULL;
   60|  1.13k|	key->p = NULL;
   61|  1.13k|	key->q = NULL;
   62|       |
   63|  1.13k|	buf_incrpos(buf, 4+SSH_SIGNKEY_RSA_LEN); /* int + "ssh-rsa" */
  ------------------
  |  |  117|  1.13k|#define SSH_SIGNKEY_RSA_LEN 7
  ------------------
   64|       |
   65|  1.13k|	if (buf_getmpint(buf, key->e) == DROPBEAR_FAILURE
  ------------------
  |  |  112|  2.27k|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (65:6): [True: 76, False: 1.06k]
  ------------------
   66|  1.06k|	 || buf_getmpint(buf, key->n) == DROPBEAR_FAILURE) {
  ------------------
  |  |  112|  1.06k|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (66:6): [True: 98, False: 963]
  ------------------
   67|     51|		TRACE(("leave buf_get_rsa_pub_key: failure"))
   68|     51|		goto out;
   69|     51|	}
   70|       |
   71|  1.08k|	if (mp_count_bits(key->n) < MIN_RSA_KEYLEN) {
  ------------------
  |  |   69|  1.08k|#define MIN_RSA_KEYLEN 1024
  ------------------
  |  Branch (71:6): [True: 81, False: 1.00k]
  ------------------
   72|     81|		dropbear_log(LOG_WARNING, "RSA key too short");
   73|     81|		goto out;
   74|     81|	}
   75|       |
   76|       |	/* 64 bit is limit used by openssl, so we won't block any keys in the wild */
   77|  1.00k|	if (mp_count_bits(key->e) > 64) {
  ------------------
  |  Branch (77:6): [True: 7, False: 998]
  ------------------
   78|      7|		dropbear_log(LOG_WARNING, "RSA key bad e");
   79|      7|		goto out;
   80|      7|	}
   81|       |
   82|    998|	TRACE(("leave buf_get_rsa_pub_key: success"))
   83|    998|	ret = DROPBEAR_SUCCESS;
  ------------------
  |  |  111|    998|#define DROPBEAR_SUCCESS 0
  ------------------
   84|  1.01k|out:
   85|  1.01k|	if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  112|  1.01k|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (85:6): [True: 139, False: 875]
  ------------------
   86|       |		m_mp_free_multi(&key->e, &key->n, NULL);
   87|    139|	}
   88|  1.01k|	return ret;
   89|    998|}
rsa_key_free:
  143|  3.57k|void rsa_key_free(dropbear_rsa_key *key) {
  144|       |
  145|  3.57k|	TRACE2(("enter rsa_key_free"))
  146|       |
  147|  3.57k|	if (key == NULL) {
  ------------------
  |  Branch (147:6): [True: 2.59k, False: 980]
  ------------------
  148|  2.59k|		TRACE2(("leave rsa_key_free: key == NULL"))
  149|  2.59k|		return;
  150|  2.59k|	}
  151|    980|	m_mp_free_multi(&key->d, &key->e, &key->p, &key->q, &key->n, NULL);
  152|       |	m_free(key);
  ------------------
  |  |   24|    980|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 980]
  |  |  ------------------
  ------------------
  153|    980|	TRACE2(("leave rsa_key_free"))
  154|    980|}
buf_rsa_verify:
  201|    843|		enum signature_type sigtype, const buffer *data_buf) {
  202|    843|	unsigned int slen;
  203|    843|	DEF_MP_INT(rsa_s);
  ------------------
  |  |   83|    843|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  204|    843|	DEF_MP_INT(rsa_mdash);
  ------------------
  |  |   83|    843|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  205|    843|	DEF_MP_INT(rsa_em);
  ------------------
  |  |   83|    843|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  206|    843|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  112|    843|#define DROPBEAR_FAILURE -1
  ------------------
  207|       |
  208|    843|	TRACE(("enter buf_rsa_verify"))
  209|       |
  210|    843|	dropbear_assert(key != NULL);
  ------------------
  |  |   86|    843|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (86:37): [True: 0, False: 843]
  |  |  |  Branch (86:93): [Folded, False: 843]
  |  |  ------------------
  ------------------
  211|       |
  212|    843|	m_mp_init_multi(&rsa_mdash, &rsa_s, &rsa_em, NULL);
  213|       |
  214|    843|	slen = buf_getint(buf);
  215|    843|	if (slen != (unsigned int)mp_ubin_size(key->n)) {
  ------------------
  |  Branch (215:6): [True: 49, False: 794]
  ------------------
  216|     49|		TRACE(("bad size"))
  217|     49|		goto out;
  218|     49|	}
  219|       |
  220|    794|	if (mp_from_ubin(&rsa_s, buf_getptr(buf, buf->len - buf->pos),
  ------------------
  |  Branch (220:6): [True: 0, False: 794]
  ------------------
  221|    794|				buf->len - buf->pos) != MP_OKAY) {
  ------------------
  |  |  161|    794|#define MP_OKAY       0   /* no error */
  ------------------
  222|      0|		TRACE(("failed reading rsa_s"))
  223|      0|		goto out;
  224|      0|	}
  225|       |
  226|       |	/* check that s <= n-1 */
  227|    794|	if (mp_cmp(&rsa_s, key->n) != MP_LT) {
  ------------------
  |  |  154|    794|#define MP_LT        -1   /* less than */
  ------------------
  |  Branch (227:6): [True: 37, False: 757]
  ------------------
  228|     37|		TRACE(("s > n-1"))
  229|     37|		goto out;
  230|     37|	}
  231|       |
  232|       |	/* create the magic PKCS padded value */
  233|    757|	rsa_pad_em(key, data_buf, &rsa_em, sigtype);
  234|       |
  235|    757|	if (mp_exptmod(&rsa_s, key->e, key->n, &rsa_mdash) != MP_OKAY) {
  ------------------
  |  |  161|    757|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (235:6): [True: 0, False: 757]
  ------------------
  236|      0|		TRACE(("failed exptmod rsa_s"))
  237|      0|		goto out;
  238|      0|	}
  239|       |
  240|    757|	if (mp_cmp(&rsa_em, &rsa_mdash) == MP_EQ) {
  ------------------
  |  |  155|    757|#define MP_EQ         0   /* equal to */
  ------------------
  |  Branch (240:6): [True: 0, False: 757]
  ------------------
  241|       |		/* signature is valid */
  242|      0|		TRACE(("success!"))
  243|      0|		ret = DROPBEAR_SUCCESS;
  ------------------
  |  |  111|      0|#define DROPBEAR_SUCCESS 0
  ------------------
  244|      0|	}
  245|       |
  246|    841|out:
  247|       |	mp_clear_multi(&rsa_mdash, &rsa_s, &rsa_em, NULL);
  248|    841|	TRACE(("leave buf_rsa_verify: ret %d", ret))
  249|    841|	return ret;
  250|    757|}
rsa.c:rsa_pad_em:
  398|    755|	const buffer *data_buf, mp_int * rsa_em, enum signature_type sigtype) {
  399|       |    /* EM = 0x00 || 0x01 || PS || 0x00 || T 
  400|       |	   PS is padding of 0xff to make EM the size of key->n
  401|       |
  402|       |	   T is the DER encoding of the hash alg (sha1 or sha256)
  403|       |	*/
  404|       |
  405|       |	/* From rfc8017 page 46 */
  406|    755|#if DROPBEAR_RSA_SHA1
  407|    755|	const unsigned char T_sha1[] =
  408|    755|		{0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b,
  409|    755|		 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14};
  410|    755|#endif
  411|    755|#if DROPBEAR_RSA_SHA256
  412|    755|	const unsigned char T_sha256[] =
  413|    755|		{0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01,
  414|    755|		 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20};
  415|    755|#endif
  416|       |
  417|    755|    int Tlen = 0;
  418|    755|    const unsigned char *T = NULL;
  419|    755|	const struct ltc_hash_descriptor *hash_desc = NULL;
  420|    755|	buffer * rsa_EM = NULL;
  421|    755|	hash_state hs;
  422|    755|	unsigned int nsize;
  423|       |
  424|    755|	switch (sigtype) {
  425|      0|#if DROPBEAR_RSA_SHA1
  426|    749|		case DROPBEAR_SIGNATURE_RSA_SHA1:
  ------------------
  |  Branch (426:3): [True: 749, False: 6]
  ------------------
  427|    749|			Tlen = sizeof(T_sha1);
  428|    749|			T = T_sha1;
  429|    749|			hash_desc = &sha1_desc;
  430|    749|			break;
  431|      0|#endif
  432|      0|#if DROPBEAR_RSA_SHA256
  433|      6|		case DROPBEAR_SIGNATURE_RSA_SHA256:
  ------------------
  |  Branch (433:3): [True: 6, False: 749]
  ------------------
  434|      6|			Tlen = sizeof(T_sha256);
  435|      6|			T = T_sha256;
  436|      6|			hash_desc = &sha256_desc;
  437|      6|			break;
  438|      0|#endif
  439|      0|		default:
  ------------------
  |  Branch (439:3): [True: 0, False: 755]
  ------------------
  440|      0|			assert(0);
  ------------------
  |  Branch (440:4): [Folded, False: 0]
  |  Branch (440:4): [Folded, False: 0]
  ------------------
  441|    755|	}
  442|       |	
  443|       |
  444|    755|	nsize = mp_ubin_size(key->n);
  445|       |
  446|    755|	rsa_EM = buf_new(nsize);
  447|       |	/* type byte */
  448|    755|	buf_putbyte(rsa_EM, 0x00);
  449|    755|	buf_putbyte(rsa_EM, 0x01);
  450|       |	/* Padding with PS 0xFF bytes */
  451|   180k|	while(rsa_EM->pos != rsa_EM->size - (1 + Tlen + hash_desc->hashsize)) {
  ------------------
  |  Branch (451:8): [True: 179k, False: 755]
  ------------------
  452|   179k|		buf_putbyte(rsa_EM, 0xff);
  453|   179k|	}
  454|    755|	buf_putbyte(rsa_EM, 0x00);
  455|       |	/* Magic ASN1 stuff */
  456|    755|	buf_putbytes(rsa_EM, T, Tlen);
  457|       |
  458|       |	/* The hash of the data */
  459|    755|	hash_desc->init(&hs);
  460|    755|	hash_desc->process(&hs, data_buf->data, data_buf->len);
  461|    755|	hash_desc->done(&hs, buf_getwriteptr(rsa_EM, hash_desc->hashsize));
  462|    755|	buf_incrwritepos(rsa_EM, hash_desc->hashsize);
  463|       |
  464|    755|	dropbear_assert(rsa_EM->pos == rsa_EM->size);
  ------------------
  |  |   86|    755|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (86:37): [True: 0, False: 755]
  |  |  |  Branch (86:93): [Folded, False: 755]
  |  |  ------------------
  ------------------
  465|       |
  466|       |	/* Create the mp_int from the encoded bytes */
  467|    755|	buf_setpos(rsa_EM, 0);
  468|    755|	bytes_to_mp(rsa_em, buf_getptr(rsa_EM, rsa_EM->size),
  469|    755|			rsa_EM->size);
  470|    755|	buf_free(rsa_EM);
  471|    755|}

new_sign_key:
   62|  2.83k|sign_key * new_sign_key() {
   63|       |
   64|  2.83k|	sign_key * ret;
   65|       |
   66|  2.83k|	ret = (sign_key*)m_malloc(sizeof(sign_key));
   67|  2.83k|	ret->type = DROPBEAR_SIGNKEY_NONE;
   68|  2.83k|	ret->source = SIGNKEY_SOURCE_INVALID;
   69|  2.83k|	return ret;
   70|  2.83k|}
signkey_type_from_name:
   86|  3.96k|enum signkey_type signkey_type_from_name(const char* name, unsigned int namelen) {
   87|  3.96k|	int i;
   88|  15.3k|	for (i = 0; i < DROPBEAR_SIGNKEY_NUM_NAMED; i++) {
  ------------------
  |  Branch (88:14): [True: 15.1k, False: 222]
  ------------------
   89|  15.1k|		const char *fixed_name = signkey_names[i];
   90|  15.1k|		if (namelen == strlen(fixed_name)
  ------------------
  |  Branch (90:7): [True: 5.11k, False: 10.0k]
  ------------------
   91|  5.11k|			&& memcmp(fixed_name, name, namelen) == 0) {
  ------------------
  |  Branch (91:7): [True: 3.74k, False: 1.36k]
  ------------------
   92|       |
   93|  3.74k|#if DROPBEAR_ECDSA
   94|       |			/* Some of the ECDSA key sizes are defined even if they're not compiled in */
   95|  3.74k|			if (0
  ------------------
  |  Branch (95:8): [Folded, False: 3.74k]
  ------------------
   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|  3.74k|				) {
  106|      0|				TRACE(("attempt to use ecdsa type %d not compiled in", i))
  107|      0|				return DROPBEAR_SIGNKEY_NONE;
  108|      0|			}
  109|  3.74k|#endif
  110|       |
  111|  3.74k|			return (enum signkey_type)i;
  112|  3.74k|		}
  113|  15.1k|	}
  114|       |
  115|    222|	TRACE(("signkey_type_from_name unexpected key type."))
  116|       |
  117|    222|	return DROPBEAR_SIGNKEY_NONE;
  118|  3.96k|}
signature_type_from_name:
  145|  1.68k|enum signature_type signature_type_from_name(const char* name, unsigned int namelen) {
  146|  1.68k|#if DROPBEAR_RSA
  147|  1.68k|#if DROPBEAR_RSA_SHA256
  148|  1.68k|	if (namelen == strlen(SSH_SIGNATURE_RSA_SHA256) 
  ------------------
  |  |  121|  1.68k|#define SSH_SIGNATURE_RSA_SHA256 "rsa-sha2-256"
  ------------------
  |  Branch (148:6): [True: 24, False: 1.65k]
  ------------------
  149|     24|		&& memcmp(name, SSH_SIGNATURE_RSA_SHA256, namelen) == 0) {
  ------------------
  |  |  121|     24|#define SSH_SIGNATURE_RSA_SHA256 "rsa-sha2-256"
  ------------------
  |  Branch (149:6): [True: 8, False: 16]
  ------------------
  150|      8|		return DROPBEAR_SIGNATURE_RSA_SHA256;
  151|      8|	}
  152|  1.67k|#endif
  153|  1.67k|#if DROPBEAR_RSA_SHA1
  154|  1.67k|	if (namelen == strlen(SSH_SIGNKEY_RSA) 
  ------------------
  |  |  116|  1.67k|#define SSH_SIGNKEY_RSA "ssh-rsa"
  ------------------
  |  Branch (154:6): [True: 1.07k, False: 598]
  ------------------
  155|  1.07k|		&& memcmp(name, SSH_SIGNKEY_RSA, namelen) == 0) {
  ------------------
  |  |  116|  1.07k|#define SSH_SIGNKEY_RSA "ssh-rsa"
  ------------------
  |  Branch (155:6): [True: 837, False: 237]
  ------------------
  156|    837|		return DROPBEAR_SIGNATURE_RSA_SHA1;
  157|    837|	}
  158|    835|#endif
  159|    835|#endif /* DROPBEAR_RSA */
  160|    835|	return (enum signature_type)signkey_type_from_name(name, namelen);
  161|  1.67k|}
signature_type_from_signkey:
  165|    844|enum signature_type signature_type_from_signkey(enum signkey_type keytype) {
  166|    844|#if DROPBEAR_RSA
  167|    844|	assert(keytype != DROPBEAR_SIGNKEY_RSA);
  ------------------
  |  Branch (167:2): [True: 0, False: 844]
  |  Branch (167:2): [True: 844, False: 0]
  ------------------
  168|    844|#endif
  169|    844|	assert(keytype < DROPBEAR_SIGNKEY_NUM_NAMED);
  ------------------
  |  Branch (169:2): [True: 0, False: 844]
  |  Branch (169:2): [True: 844, False: 0]
  ------------------
  170|    844|	return (enum signature_type)keytype;
  171|    844|}
signkey_type_from_signature:
  173|  1.59k|enum signkey_type signkey_type_from_signature(enum signature_type sigtype) {
  174|  1.59k|#if DROPBEAR_RSA
  175|  1.59k|#if DROPBEAR_RSA_SHA256
  176|  1.59k|	if (sigtype == DROPBEAR_SIGNATURE_RSA_SHA256) {
  ------------------
  |  Branch (176:6): [True: 7, False: 1.59k]
  ------------------
  177|      7|		return DROPBEAR_SIGNKEY_RSA;
  178|      7|	}
  179|  1.59k|#endif
  180|  1.59k|#if DROPBEAR_RSA_SHA1
  181|  1.59k|	if (sigtype == DROPBEAR_SIGNATURE_RSA_SHA1) {
  ------------------
  |  Branch (181:6): [True: 836, False: 754]
  ------------------
  182|    836|		return DROPBEAR_SIGNKEY_RSA;
  183|    836|	}
  184|    754|#endif
  185|    754|#endif /* DROPBEAR_RSA */
  186|  1.59k|	assert((int)sigtype < (int)DROPBEAR_SIGNKEY_NUM_NAMED);
  ------------------
  |  Branch (186:2): [True: 0, False: 754]
  |  Branch (186:2): [True: 754, False: 0]
  ------------------
  187|    754|	return (enum signkey_type)sigtype;
  188|    754|}
signkey_key_ptr:
  193|  1.19k|signkey_key_ptr(sign_key *key, enum signkey_type type) {
  194|  1.19k|	switch (type) {
  195|      0|#if DROPBEAR_ED25519
  196|      0|		case DROPBEAR_SIGNKEY_ED25519:
  ------------------
  |  Branch (196:3): [True: 0, False: 1.19k]
  ------------------
  197|      0|#if DROPBEAR_SK_ED25519
  198|    121|		case DROPBEAR_SIGNKEY_SK_ED25519:
  ------------------
  |  Branch (198:3): [True: 121, False: 1.07k]
  ------------------
  199|    121|#endif
  200|    121|			return (void**)&key->ed25519key;
  201|      0|#endif
  202|      0|#if DROPBEAR_ECDSA
  203|      0|#if DROPBEAR_ECC_256
  204|    656|		case DROPBEAR_SIGNKEY_ECDSA_NISTP256:
  ------------------
  |  Branch (204:3): [True: 656, False: 543]
  ------------------
  205|    656|#if DROPBEAR_SK_ECDSA
  206|    750|		case DROPBEAR_SIGNKEY_SK_ECDSA_NISTP256:
  ------------------
  |  Branch (206:3): [True: 94, False: 1.10k]
  ------------------
  207|    750|#endif
  208|    750|			return (void**)&key->ecckey256;
  209|      0|#endif
  210|      0|#if DROPBEAR_ECC_384
  211|    144|		case DROPBEAR_SIGNKEY_ECDSA_NISTP384:
  ------------------
  |  Branch (211:3): [True: 144, False: 1.05k]
  ------------------
  212|    144|			return (void**)&key->ecckey384;
  213|      0|#endif
  214|      0|#if DROPBEAR_ECC_521
  215|    184|		case DROPBEAR_SIGNKEY_ECDSA_NISTP521:
  ------------------
  |  Branch (215:3): [True: 184, False: 1.01k]
  ------------------
  216|    184|			return (void**)&key->ecckey521;
  217|      0|#endif
  218|      0|#endif /* DROPBEAR_ECDSA */
  219|      0|#if DROPBEAR_RSA
  220|      0|		case DROPBEAR_SIGNKEY_RSA:
  ------------------
  |  Branch (220:3): [True: 0, False: 1.19k]
  ------------------
  221|      0|			return (void**)&key->rsakey;
  222|      0|#endif
  223|      0|#if DROPBEAR_DSS
  224|      0|		case DROPBEAR_SIGNKEY_DSS:
  ------------------
  |  Branch (224:3): [True: 0, False: 1.19k]
  ------------------
  225|      0|			return (void**)&key->dsskey;
  226|      0|#endif
  227|      0|		default:
  ------------------
  |  Branch (227:3): [True: 0, False: 1.19k]
  ------------------
  228|       |			return NULL;
  229|  1.19k|	}
  230|  1.19k|}
buf_get_pub_key:
  235|  2.83k|int buf_get_pub_key(buffer *buf, sign_key *key, enum signkey_type *type) {
  236|       |
  237|  2.83k|	char *ident;
  238|  2.83k|	unsigned int len;
  239|  2.83k|	enum signkey_type keytype;
  240|  2.83k|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  112|  2.83k|#define DROPBEAR_FAILURE -1
  ------------------
  241|       |
  242|  2.83k|	TRACE2(("enter buf_get_pub_key"))
  243|       |
  244|  2.83k|	ident = buf_getstring(buf, &len);
  245|  2.83k|	keytype = signkey_type_from_name(ident, len);
  246|  2.83k|	m_free(ident);
  ------------------
  |  |   24|  2.83k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 2.83k]
  |  |  ------------------
  ------------------
  247|       |
  248|  2.83k|	if (*type != DROPBEAR_SIGNKEY_ANY && *type != keytype) {
  ------------------
  |  Branch (248:6): [True: 0, False: 2.83k]
  |  Branch (248:39): [True: 0, False: 0]
  ------------------
  249|      0|		TRACE(("buf_get_pub_key bad type - got %d, expected %d", keytype, *type))
  250|      0|		return DROPBEAR_FAILURE;
  ------------------
  |  |  112|      0|#define DROPBEAR_FAILURE -1
  ------------------
  251|      0|	}
  252|       |	
  253|  2.83k|	TRACE2(("buf_get_pub_key keytype is %d", keytype))
  254|       |
  255|  2.83k|	*type = keytype;
  256|       |
  257|       |	/* Rewind the buffer back before "ssh-rsa" etc */
  258|  2.83k|	buf_decrpos(buf, len + 4);
  259|       |
  260|  2.83k|#if DROPBEAR_DSS
  261|  2.83k|	if (keytype == DROPBEAR_SIGNKEY_DSS) {
  ------------------
  |  Branch (261:6): [True: 344, False: 2.48k]
  ------------------
  262|    344|		dss_key_free(key->dsskey);
  263|    344|		key->dsskey = m_malloc(sizeof(*key->dsskey));
  264|    344|		ret = buf_get_dss_pub_key(buf, key->dsskey);
  265|    344|		if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  112|    344|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (265:7): [True: 67, False: 277]
  ------------------
  266|     67|			dss_key_free(key->dsskey);
  267|     67|			key->dsskey = NULL;
  268|     67|		}
  269|    344|	}
  270|  2.83k|#endif
  271|  2.83k|#if DROPBEAR_RSA
  272|  2.83k|	if (keytype == DROPBEAR_SIGNKEY_RSA) {
  ------------------
  |  Branch (272:6): [True: 1.13k, False: 1.69k]
  ------------------
  273|  1.13k|		rsa_key_free(key->rsakey);
  274|  1.13k|		key->rsakey = m_malloc(sizeof(*key->rsakey));
  275|  1.13k|		ret = buf_get_rsa_pub_key(buf, key->rsakey);
  276|  1.13k|		if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  112|  1.13k|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (276:7): [True: 139, False: 998]
  ------------------
  277|    139|			rsa_key_free(key->rsakey);
  278|    139|			key->rsakey = NULL;
  279|    139|		}
  280|  1.13k|	}
  281|  2.83k|#endif
  282|  2.83k|#if DROPBEAR_ECDSA
  283|  2.83k|	if (signkey_is_ecdsa(keytype)
  ------------------
  |  Branch (283:6): [True: 909, False: 1.92k]
  ------------------
  284|  1.92k|#if DROPBEAR_SK_ECDSA
  285|  1.92k|		|| keytype == DROPBEAR_SIGNKEY_SK_ECDSA_NISTP256
  ------------------
  |  Branch (285:6): [True: 94, False: 1.82k]
  ------------------
  286|  2.83k|#endif
  287|  2.83k|	) {
  288|    773|		ecc_key **eck = (ecc_key**)signkey_key_ptr(key, keytype);
  289|    773|		if (eck) {
  ------------------
  |  Branch (289:7): [True: 773, False: 0]
  ------------------
  290|    773|			if (*eck) {
  ------------------
  |  Branch (290:8): [True: 0, False: 773]
  ------------------
  291|      0|				ecc_free(*eck);
  292|      0|				m_free(*eck);
  ------------------
  |  |   24|      0|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 0]
  |  |  ------------------
  ------------------
  293|      0|				*eck = NULL;
  294|      0|			}
  295|    773|			*eck = buf_get_ecdsa_pub_key(buf);
  296|    773|			if (*eck) {
  ------------------
  |  Branch (296:8): [True: 308, False: 465]
  ------------------
  297|    308|				ret = DROPBEAR_SUCCESS;
  ------------------
  |  |  111|    308|#define DROPBEAR_SUCCESS 0
  ------------------
  298|    308|			}
  299|    773|		}
  300|    773|	}
  301|  2.83k|#endif
  302|  2.83k|#if DROPBEAR_ED25519
  303|  2.83k|	if (keytype == DROPBEAR_SIGNKEY_ED25519
  ------------------
  |  Branch (303:6): [True: 551, False: 2.27k]
  ------------------
  304|  2.27k|#if DROPBEAR_SK_ED25519
  305|  2.27k|		|| keytype == DROPBEAR_SIGNKEY_SK_ED25519
  ------------------
  |  Branch (305:6): [True: 132, False: 2.14k]
  ------------------
  306|  2.83k|#endif
  307|  2.83k|    ) {
  308|    366|		ed25519_key_free(key->ed25519key);
  309|    366|		key->ed25519key = m_malloc(sizeof(*key->ed25519key));
  310|    366|		ret = buf_get_ed25519_pub_key(buf, key->ed25519key, keytype);
  311|    366|		if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  112|    366|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (311:7): [True: 58, False: 308]
  ------------------
  312|     58|			m_free(key->ed25519key);
  ------------------
  |  |   24|     58|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 58]
  |  |  ------------------
  ------------------
  313|     58|			key->ed25519key = NULL;
  314|     58|		}
  315|    366|	}
  316|  2.83k|#endif
  317|       |
  318|  2.83k|#if DROPBEAR_SK_ECDSA || DROPBEAR_SK_ED25519
  319|  2.83k|	if (0
  ------------------
  |  Branch (319:6): [Folded, False: 2.50k]
  ------------------
  320|  2.50k|#if DROPBEAR_SK_ED25519
  321|  2.50k|		|| keytype == DROPBEAR_SIGNKEY_SK_ED25519
  ------------------
  |  Branch (321:6): [True: 130, False: 2.37k]
  ------------------
  322|  2.37k|#endif
  323|  2.37k|#if DROPBEAR_SK_ECDSA
  324|  2.37k|		|| keytype == DROPBEAR_SIGNKEY_SK_ECDSA_NISTP256
  ------------------
  |  Branch (324:6): [True: 81, False: 2.29k]
  ------------------
  325|  2.83k|#endif
  326|  2.83k|	) {
  327|    211|		key->sk_app = buf_getstring(buf, &key->sk_applen);
  328|    211|	}
  329|  2.83k|#endif
  330|       |
  331|  2.83k|	TRACE2(("leave buf_get_pub_key"))
  332|       |
  333|  2.83k|	return ret;
  334|  2.83k|}
sign_key_free:
  506|  2.29k|void sign_key_free(sign_key *key) {
  507|       |
  508|  2.29k|	TRACE2(("enter sign_key_free"))
  509|       |
  510|  2.29k|#if DROPBEAR_DSS
  511|  2.29k|	dss_key_free(key->dsskey);
  512|  2.29k|	key->dsskey = NULL;
  513|  2.29k|#endif
  514|  2.29k|#if DROPBEAR_RSA
  515|  2.29k|	rsa_key_free(key->rsakey);
  516|  2.29k|	key->rsakey = NULL;
  517|  2.29k|#endif
  518|  2.29k|#if DROPBEAR_ECDSA
  519|  2.29k|#if DROPBEAR_ECC_256
  520|  2.29k|	if (key->ecckey256) {
  ------------------
  |  Branch (520:6): [True: 196, False: 2.10k]
  ------------------
  521|    196|		ecc_free(key->ecckey256);
  522|    196|		m_free(key->ecckey256);
  ------------------
  |  |   24|    196|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 196]
  |  |  ------------------
  ------------------
  523|    196|		key->ecckey256 = NULL;
  524|    196|	}
  525|  2.29k|#endif
  526|  2.29k|#if DROPBEAR_ECC_384
  527|  2.29k|	if (key->ecckey384) {
  ------------------
  |  Branch (527:6): [True: 49, False: 2.24k]
  ------------------
  528|     49|		ecc_free(key->ecckey384);
  529|     49|		m_free(key->ecckey384);
  ------------------
  |  |   24|     49|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 49]
  |  |  ------------------
  ------------------
  530|     49|		key->ecckey384 = NULL;
  531|     49|	}
  532|  2.29k|#endif
  533|  2.29k|#if DROPBEAR_ECC_521
  534|  2.29k|	if (key->ecckey521) {
  ------------------
  |  Branch (534:6): [True: 57, False: 2.24k]
  ------------------
  535|     57|		ecc_free(key->ecckey521);
  536|     57|		m_free(key->ecckey521);
  ------------------
  |  |   24|     57|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 57]
  |  |  ------------------
  ------------------
  537|     57|		key->ecckey521 = NULL;
  538|     57|	}
  539|  2.29k|#endif
  540|  2.29k|#endif
  541|  2.29k|#if DROPBEAR_ED25519
  542|  2.29k|	ed25519_key_free(key->ed25519key);
  543|  2.29k|	key->ed25519key = NULL;
  544|  2.29k|#endif
  545|       |
  546|  2.29k|	m_free(key->filename);
  ------------------
  |  |   24|  2.29k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 2.29k]
  |  |  ------------------
  ------------------
  547|  2.29k|#if DROPBEAR_SK_ECDSA || DROPBEAR_SK_ED25519
  548|  2.29k|	if (key->sk_app) {
  ------------------
  |  Branch (548:6): [True: 122, False: 2.17k]
  ------------------
  549|    122|		m_free(key->sk_app);
  ------------------
  |  |   24|    122|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 122]
  |  |  ------------------
  ------------------
  550|    122|	}
  551|  2.29k|#endif
  552|       |
  553|       |	m_free(key);
  ------------------
  |  |   24|  2.29k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 2.29k]
  |  |  ------------------
  ------------------
  554|  2.29k|	TRACE2(("leave sign_key_free"))
  555|  2.29k|}
buf_verify:
  645|  1.70k|int buf_verify(buffer * buf, sign_key *key, enum signature_type expect_sigtype, const buffer *data_buf) {
  646|       |	
  647|  1.70k|	char *type_name = NULL;
  648|  1.70k|	unsigned int type_name_len = 0;
  649|  1.70k|	enum signature_type sigtype;
  650|  1.70k|	enum signkey_type keytype;
  651|       |
  652|  1.70k|	TRACE(("enter buf_verify"))
  653|       |
  654|  1.70k|	buf_getint(buf); /* blob length */
  655|  1.70k|	type_name = buf_getstring(buf, &type_name_len);
  656|  1.70k|	sigtype = signature_type_from_name(type_name, type_name_len);
  657|  1.70k|	m_free(type_name);
  ------------------
  |  |   24|  1.70k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded, False: 1.70k]
  |  |  ------------------
  ------------------
  658|       |
  659|  1.70k|	if (expect_sigtype != sigtype) {
  ------------------
  |  Branch (659:6): [True: 83, False: 1.62k]
  ------------------
  660|     83|			dropbear_exit("Non-matching signing type");
  661|     83|	}
  662|       |
  663|  1.62k|	keytype = signkey_type_from_signature(sigtype);
  664|  1.62k|#if DROPBEAR_DSS
  665|  1.62k|	if (keytype == DROPBEAR_SIGNKEY_DSS) {
  ------------------
  |  Branch (665:6): [True: 233, False: 1.38k]
  ------------------
  666|    233|		if (key->dsskey == NULL) {
  ------------------
  |  Branch (666:7): [True: 0, False: 233]
  ------------------
  667|      0|			dropbear_exit("No DSS key to verify signature");
  668|      0|		}
  669|    233|		return buf_dss_verify(buf, key->dsskey, data_buf);
  670|    233|	}
  671|  1.38k|#endif
  672|       |
  673|  1.38k|#if DROPBEAR_RSA
  674|  1.38k|	if (keytype == DROPBEAR_SIGNKEY_RSA) {
  ------------------
  |  Branch (674:6): [True: 843, False: 544]
  ------------------
  675|    843|		if (key->rsakey == NULL) {
  ------------------
  |  Branch (675:7): [True: 0, False: 843]
  ------------------
  676|      0|			dropbear_exit("No RSA key to verify signature");
  677|      0|		}
  678|    843|		return buf_rsa_verify(buf, key->rsakey, sigtype, data_buf);
  679|    843|	}
  680|    544|#endif
  681|    544|#if DROPBEAR_ECDSA
  682|    544|	if (signkey_is_ecdsa(keytype)) {
  ------------------
  |  Branch (682:6): [True: 305, False: 239]
  ------------------
  683|    305|		ecc_key **eck = (ecc_key**)signkey_key_ptr(key, keytype);
  684|    305|		if (eck && *eck) {
  ------------------
  |  Branch (684:7): [True: 305, False: 0]
  |  Branch (684:14): [True: 305, False: 0]
  ------------------
  685|    305|			return buf_ecdsa_verify(buf, *eck, data_buf);
  686|    305|		}
  687|    305|	}
  688|    239|#endif
  689|    239|#if DROPBEAR_ED25519
  690|    239|	if (keytype == DROPBEAR_SIGNKEY_ED25519) {
  ------------------
  |  Branch (690:6): [True: 97, False: 142]
  ------------------
  691|     97|		if (key->ed25519key == NULL) {
  ------------------
  |  Branch (691:7): [True: 0, False: 97]
  ------------------
  692|      0|			dropbear_exit("No Ed25519 key to verify signature");
  693|      0|		}
  694|     97|		return buf_ed25519_verify(buf, key->ed25519key, data_buf);
  695|     97|	}
  696|    142|#endif
  697|    142|#if DROPBEAR_SK_ECDSA
  698|    142|	if (keytype == DROPBEAR_SIGNKEY_SK_ECDSA_NISTP256) {
  ------------------
  |  Branch (698:6): [True: 0, False: 142]
  ------------------
  699|      0|		ecc_key **eck = (ecc_key**)signkey_key_ptr(key, keytype);
  700|      0|		if (eck && *eck) {
  ------------------
  |  Branch (700:7): [True: 0, False: 0]
  |  Branch (700:14): [True: 0, False: 0]
  ------------------
  701|      0|			return buf_sk_ecdsa_verify(buf, *eck, data_buf, key->sk_app, key->sk_applen, key->sk_flags_mask);
  702|      0|		}
  703|      0|	}
  704|    142|#endif
  705|    142|#if DROPBEAR_SK_ED25519
  706|    142|	if (keytype == DROPBEAR_SIGNKEY_SK_ED25519) {
  ------------------
  |  Branch (706:6): [True: 119, False: 23]
  ------------------
  707|    119|		dropbear_ed25519_key **eck = (dropbear_ed25519_key**)signkey_key_ptr(key, keytype);
  708|    119|		if (eck && *eck) {
  ------------------
  |  Branch (708:7): [True: 119, False: 0]
  |  Branch (708:14): [True: 119, False: 0]
  ------------------
  709|    119|			return buf_sk_ed25519_verify(buf, *eck, data_buf, key->sk_app, key->sk_applen, key->sk_flags_mask);
  710|    119|		}
  711|    119|	}
  712|     23|#endif
  713|       |
  714|     23|	dropbear_exit("Non-matching signing type");
  715|      0|	return DROPBEAR_FAILURE;
  ------------------
  |  |  112|      0|#define DROPBEAR_FAILURE -1
  ------------------
  716|    142|}

buf_sk_ed25519_verify:
   13|    119|			unsigned char sk_flags_mask) {
   14|       |
   15|    119|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  112|    119|#define DROPBEAR_FAILURE -1
  ------------------
   16|    119|	unsigned char *s;
   17|    119|	unsigned long slen;
   18|    119|	hash_state hs;
   19|    119|	unsigned char hash[SHA256_HASH_SIZE];
   20|    119|	buffer *sk_buffer = NULL;
   21|    119|	unsigned char flags;
   22|    119|	unsigned int counter;
   23|       |
   24|    119|	TRACE(("enter buf_sk_ed25519_verify"))
   25|    119|	dropbear_assert(key != NULL);
  ------------------
  |  |   86|    119|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (86:37): [True: 0, False: 119]
  |  |  |  Branch (86:93): [Folded, False: 119]
  |  |  ------------------
  ------------------
   26|       |
   27|    119|	slen = buf_getint(buf);
   28|    119|	if (slen != 64 || buf->len - buf->pos < slen) {
  ------------------
  |  Branch (28:6): [True: 41, False: 78]
  |  Branch (28:20): [True: 4, False: 74]
  ------------------
   29|     44|		TRACE(("leave buf_sk_ed25519_verify: bad size"))
   30|     44|		goto out;
   31|     44|	}
   32|     75|	s = buf_getptr(buf, slen);
   33|     75|	buf_incrpos(buf, slen);
   34|       |
   35|     75|	flags = buf_getbyte (buf);
   36|     75|	counter = buf_getint (buf);
   37|       |	/* create the message to be signed */
   38|     75|	sk_buffer = buf_new (2*SHA256_HASH_SIZE+5);
  ------------------
  |  |  134|     75|#define SHA256_HASH_SIZE 32
  ------------------
   39|     75|	sha256_init (&hs);
   40|     75|	sha256_process (&hs, app, applen);
   41|     75|	sha256_done (&hs, hash);
   42|     75|	buf_putbytes (sk_buffer, hash, sizeof (hash));
   43|     75|	buf_putbyte (sk_buffer, flags);
   44|     75|	buf_putint (sk_buffer, counter);
   45|     75|	sha256_init (&hs);
   46|     75|	sha256_process (&hs, data_buf->data, data_buf->len);
   47|     75|	sha256_done (&hs, hash);
   48|     75|	buf_putbytes (sk_buffer, hash, sizeof (hash));
   49|       |
   50|     75|	if (dropbear_ed25519_verify(sk_buffer->data, sk_buffer->len,
  ------------------
  |  Branch (50:6): [True: 2, False: 73]
  ------------------
   51|     75|				    s, slen, key->pub) == 0) {
   52|       |		/* signature is valid */
   53|      2|		TRACE(("leave buf_sk_ed25519_verify: success!"))
   54|      2|		ret = DROPBEAR_SUCCESS;
  ------------------
  |  |  111|      2|#define DROPBEAR_SUCCESS 0
  ------------------
   55|      2|	}
   56|       |
   57|     75|	if (~flags & sk_flags_mask & SSH_SK_USER_PRESENCE_REQD) {
  ------------------
  |  |  135|     75|#define SSH_SK_USER_PRESENCE_REQD       0x01
  ------------------
  |  Branch (57:6): [True: 0, False: 75]
  ------------------
   58|      0|		if (ret == DROPBEAR_SUCCESS) {
  ------------------
  |  |  111|      0|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (58:7): [True: 0, False: 0]
  ------------------
   59|      0|			dropbear_log(LOG_WARNING, "Rejecting, user-presence not set");
   60|      0|		}
   61|      0|		ret = DROPBEAR_FAILURE;
  ------------------
  |  |  112|      0|#define DROPBEAR_FAILURE -1
  ------------------
   62|      0|	}
   63|     75|	if (~flags & sk_flags_mask & SSH_SK_USER_VERIFICATION_REQD) {
  ------------------
  |  |  136|     75|#define SSH_SK_USER_VERIFICATION_REQD   0x04
  ------------------
  |  Branch (63:6): [True: 0, False: 75]
  ------------------
   64|      0|		if (ret == DROPBEAR_SUCCESS) {
  ------------------
  |  |  111|      0|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (64:7): [True: 0, False: 0]
  ------------------
   65|      0|			dropbear_log(LOG_WARNING, "Rejecting, user-verification not set");
   66|      0|		}
   67|      0|		ret = DROPBEAR_FAILURE;
  ------------------
  |  |  112|      0|#define DROPBEAR_FAILURE -1
  ------------------
   68|      0|	}
   69|    117|out:
   70|    117|	buf_free(sk_buffer);
   71|    117|	TRACE(("leave buf_sk_ed25519_verify: ret %d", ret))
   72|    117|	return ret;
   73|     75|}

