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

wrapfd_setup:
   32|  2.85k|void wrapfd_setup(buffer *buf) {
   33|  2.85k|	TRACE(("wrapfd_setup"))
   34|       |
   35|       |	// clean old ones
   36|  2.85k|	int i;
   37|  2.85k|	for (i = 0; i <= wrapfd_maxfd; i++) {
  ------------------
  |  Branch (37:14): [True: 0, False: 2.85k]
  ------------------
   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.85k|	wrapfd_maxfd = -1;
   43|       |
   44|  2.85k|	memset(rand_state, 0x0, sizeof(rand_state));
   45|  2.85k|	wrapfd_setseed(50);
   46|  2.85k|	input_buf = buf;
   47|  2.85k|}
wrapfd_setseed:
   49|  2.85k|void wrapfd_setseed(uint32_t seed) {
   50|  2.85k|	memcpy(rand_state, &seed, sizeof(seed));
   51|  2.85k|	nrand48(rand_state);
   52|  2.85k|}

LLVMFuzzerTestOneInput:
   15|  2.85k|int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
   16|  2.85k|	static int once = 0;
   17|  2.85k|	if (!once) {
  ------------------
  |  Branch (17:6): [True: 1, False: 2.85k]
  ------------------
   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.85k|	if (fuzz_set_input(Data, Size) == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|  2.85k|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (24:6): [True: 0, False: 2.85k]
  ------------------
   25|      0|		return 0;
   26|      0|	}
   27|       |
   28|  2.85k|	m_malloc_set_epoch(1);
   29|       |
   30|  2.85k|	if (setjmp(fuzz.jmp) == 0) {
  ------------------
  |  Branch (30:6): [True: 2.85k, False: 0]
  ------------------
   31|  2.85k|		sign_key *key = new_sign_key();
   32|  2.85k|		enum signkey_type keytype = DROPBEAR_SIGNKEY_ANY;
   33|  2.85k|		if (buf_get_pub_key(fuzz.input, key, &keytype) == DROPBEAR_SUCCESS) {
  ------------------
  |  |  102|  2.85k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (33:7): [True: 1.71k, False: 1.14k]
  ------------------
   34|  1.71k|			enum signature_type sigtype;
   35|  1.71k|			if (keytype == DROPBEAR_SIGNKEY_RSA) {
  ------------------
  |  Branch (35:8): [True: 912, False: 804]
  ------------------
   36|       |				/* Flip a coin to decide rsa signature type */
   37|    912|				int flag = buf_getbyte(fuzz.input);
   38|    912|				if (flag & 0x01) {
  ------------------
  |  Branch (38:9): [True: 15, False: 897]
  ------------------
   39|     15|					sigtype = DROPBEAR_SIGNATURE_RSA_SHA256;
   40|    897|				} else {
   41|    897|					sigtype = DROPBEAR_SIGNATURE_RSA_SHA1;
   42|    897|				}
   43|    912|			} else {
   44|    804|				sigtype = signature_type_from_signkey(keytype);
   45|    804|			}
   46|  1.71k|			if (buf_verify(fuzz.input, key, sigtype, verifydata) == DROPBEAR_SUCCESS) {
  ------------------
  |  |  102|  1.71k|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (46:8): [True: 118, False: 1.59k]
  ------------------
   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|    118|				int boguskey = 0;
   51|       |
   52|    118|				if (keytype == DROPBEAR_SIGNKEY_DSS) {
  ------------------
  |  Branch (52:9): [True: 116, False: 2]
  ------------------
   53|       |					/* So far have seen dss keys with bad p/q/g domain parameters */
   54|    116|					int pprime, qprime, trials;
   55|    116|					trials = mp_prime_rabin_miller_trials(mp_count_bits(key->dsskey->p));
   56|    116|					assert(mp_prime_is_prime(key->dsskey->p, trials, &pprime) == MP_OKAY);
   57|    116|					trials = mp_prime_rabin_miller_trials(mp_count_bits(key->dsskey->q));
   58|    116|					assert(mp_prime_is_prime(key->dsskey->q, trials, &qprime) == MP_OKAY);
   59|    116|					boguskey = !(pprime && qprime);
  ------------------
  |  Branch (59:19): [True: 0, False: 116]
  |  Branch (59:29): [True: 0, False: 0]
  ------------------
   60|       |					/* Could also check g**q mod p == 1 */
   61|    116|				}
   62|       |
   63|    118|				if (keytype == DROPBEAR_SIGNKEY_SK_ED25519 || keytype == DROPBEAR_SIGNKEY_ED25519) {
  ------------------
  |  Branch (63:9): [True: 2, False: 116]
  |  Branch (63:51): [True: 0, False: 116]
  ------------------
   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|    118|				if (!boguskey) {
  ------------------
  |  Branch (78:9): [True: 0, False: 118]
  ------------------
   79|      0|					printf("Random key/signature managed to verify!\n");
   80|      0|					abort();
   81|      0|				}
   82|       |
   83|       |
   84|    118|			}
   85|  1.71k|		}
   86|  2.85k|		sign_key_free(key);
   87|  2.85k|		m_malloc_free_epoch(1, 0);
   88|  2.85k|	} 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.85k|	return 0;
   95|  2.85k|}
fuzzer-verify.c:setup_fuzzer:
    8|      1|static void setup_fuzzer(void) {
    9|      1|	fuzz_common_setup();
   10|      1|}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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.54k|   for (x = 0; (x < a->used) && (a->dp[x] == 0u); x++) {}
  ------------------
  |  Branch (22:16): [True: 3.54k, False: 0]
  |  Branch (22:33): [True: 1.40k, 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.91k, False: 231]
  ------------------
   28|  8.38k|      do {
   29|  8.38k|         qq  = q & 15u;
   30|  8.38k|         x  += lnz[qq];
   31|  8.38k|         q >>= 4;
   32|  8.38k|      } while (qq == 0u);
  ------------------
  |  Branch (32:16): [True: 6.46k, False: 1.91k]
  ------------------
   33|  1.91k|   }
   34|  2.14k|   return x;
   35|  2.14k|}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

mp_is_square:
   30|    136|{
   31|    136|   mp_err        err;
   32|    136|   mp_digit      c;
   33|    136|   mp_int        t;
   34|    136|   unsigned long r;
   35|       |
   36|       |   /* Default to Non-square :) */
   37|    136|   *ret = MP_NO;
  ------------------
  |  |  159|    136|#define MP_NO         0
  ------------------
   38|       |
   39|    136|   if (arg->sign == MP_NEG) {
  ------------------
  |  |  152|    136|#define MP_NEG        1   /* negative */
  ------------------
  |  Branch (39:8): [True: 0, False: 136]
  ------------------
   40|      0|      return MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
   41|      0|   }
   42|       |
   43|    136|   if (MP_IS_ZERO(arg)) {
  ------------------
  |  |  163|    136|#define MP_IS_ZERO(a) ((a)->used == 0)
  |  |  ------------------
  |  |  |  Branch (163:23): [True: 0, False: 136]
  |  |  ------------------
  ------------------
   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|    136|   if (rem_128[127u & arg->dp[0]] == (char)1) {
  ------------------
  |  Branch (48:8): [True: 16, False: 120]
  ------------------
   49|     16|      return MP_OKAY;
  ------------------
  |  |  161|     16|#define MP_OKAY       0   /* no error */
  ------------------
   50|     16|   }
   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: 81, False: 39]
  ------------------
   57|     81|      return MP_OKAY;
  ------------------
  |  |  161|     81|#define MP_OKAY       0   /* no error */
  ------------------
   58|     81|   }
   59|       |
   60|       |
   61|     39|   if ((err = mp_init_u32(&t, 11u*13u*17u*19u*23u*29u*31u)) != MP_OKAY) {
  ------------------
  |  |  161|     39|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (61:8): [True: 0, False: 39]
  ------------------
   62|      0|      return err;
   63|      0|   }
   64|     39|   if ((err = mp_mod(arg, &t, &t)) != MP_OKAY) {
  ------------------
  |  |  161|     39|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (64:8): [True: 0, False: 39]
  ------------------
   65|      0|      goto LBL_ERR;
   66|      0|   }
   67|     39|   r = mp_get_u32(&t);
  ------------------
  |  |  310|     39|#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|     39|   if (((1uL<<(r%11uL)) & 0x5C4uL) != 0uL)         goto LBL_ERR;
  ------------------
  |  Branch (72:8): [True: 9, False: 30]
  ------------------
   73|     30|   if (((1uL<<(r%13uL)) & 0x9E4uL) != 0uL)         goto LBL_ERR;
  ------------------
  |  Branch (73:8): [True: 8, False: 22]
  ------------------
   74|     22|   if (((1uL<<(r%17uL)) & 0x5CE8uL) != 0uL)        goto LBL_ERR;
  ------------------
  |  Branch (74:8): [True: 5, False: 17]
  ------------------
   75|     17|   if (((1uL<<(r%19uL)) & 0x4F50CuL) != 0uL)       goto LBL_ERR;
  ------------------
  |  Branch (75:8): [True: 9, False: 8]
  ------------------
   76|      8|   if (((1uL<<(r%23uL)) & 0x7ACCA0uL) != 0uL)      goto LBL_ERR;
  ------------------
  |  Branch (76:8): [True: 1, False: 7]
  ------------------
   77|      7|   if (((1uL<<(r%29uL)) & 0xC2EDD0CuL) != 0uL)     goto LBL_ERR;
  ------------------
  |  Branch (77:8): [True: 1, False: 6]
  ------------------
   78|      6|   if (((1uL<<(r%31uL)) & 0x6DE2B848uL) != 0uL)    goto LBL_ERR;
  ------------------
  |  Branch (78:8): [True: 1, False: 5]
  ------------------
   79|       |
   80|       |   /* Final check - is sqr(sqrt(arg)) == arg ? */
   81|      5|   if ((err = mp_sqrt(arg, &t)) != MP_OKAY) {
  ------------------
  |  |  161|      5|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (81:8): [True: 0, False: 5]
  ------------------
   82|      0|      goto LBL_ERR;
   83|      0|   }
   84|      5|   if ((err = mp_sqr(&t, &t)) != MP_OKAY) {
  ------------------
  |  |  161|      5|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (84:8): [True: 0, False: 5]
  ------------------
   85|      0|      goto LBL_ERR;
   86|      0|   }
   87|       |
   88|      5|   *ret = (mp_cmp_mag(&t, arg) == MP_EQ) ? MP_YES : MP_NO;
  ------------------
  |  |  155|      5|#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|      9|#define MP_NO         0
  ------------------
  |  Branch (88:11): [True: 1, False: 4]
  ------------------
   89|     39|LBL_ERR:
   90|     39|   mp_clear(&t);
   91|     39|   return err;
   92|      5|}

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

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

mp_mod_2d:
    8|  3.14M|{
    9|  3.14M|   int x;
   10|  3.14M|   mp_err err;
   11|       |
   12|       |   /* if b is <= 0 then zero the int */
   13|  3.14M|   if (b <= 0) {
  ------------------
  |  Branch (13:8): [True: 0, False: 3.14M]
  ------------------
   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|  3.14M|   if (b >= (a->used * MP_DIGIT_BIT)) {
  ------------------
  |  |   82|  3.14M|#   define MP_DIGIT_BIT 60
  ------------------
  |  Branch (19:8): [True: 35.6k, False: 3.11M]
  ------------------
   20|  35.6k|      return mp_copy(a, c);
   21|  35.6k|   }
   22|       |
   23|       |   /* copy */
   24|  3.11M|   if ((err = mp_copy(a, c)) != MP_OKAY) {
  ------------------
  |  |  161|  3.11M|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (24:8): [True: 0, False: 3.11M]
  ------------------
   25|      0|      return err;
   26|      0|   }
   27|       |
   28|       |   /* zero digits above the last digit of the modulus */
   29|  3.11M|   x = (b / MP_DIGIT_BIT) + (((b % MP_DIGIT_BIT) == 0) ? 0 : 1);
  ------------------
  |  |   82|  3.11M|#   define MP_DIGIT_BIT 60
  ------------------
                 x = (b / MP_DIGIT_BIT) + (((b % MP_DIGIT_BIT) == 0) ? 0 : 1);
  ------------------
  |  |   82|  3.11M|#   define MP_DIGIT_BIT 60
  ------------------
  |  Branch (29:30): [True: 93.3k, False: 3.01M]
  ------------------
   30|  3.11M|   MP_ZERO_DIGITS(c->dp + x, c->used - x);
  ------------------
  |  |   89|  3.11M|#  define MP_ZERO_DIGITS(mem, digits)                   \
  |  |   90|  3.11M|do {                                                    \
  |  |   91|  3.11M|   int zd_ = (digits);                                  \
  |  |   92|  3.11M|   mp_digit* zm_ = (mem);                               \
  |  |   93|  31.3M|   while (zd_-- > 0) {                                  \
  |  |  ------------------
  |  |  |  Branch (93:11): [True: 28.1M, False: 3.11M]
  |  |  ------------------
  |  |   94|  28.1M|      *zm_++ = 0;                                       \
  |  |   95|  28.1M|   }                                                    \
  |  |   96|  3.11M|} while (0)
  |  |  ------------------
  |  |  |  Branch (96:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
   31|       |
   32|       |   /* clear the digit that is not completely outside/inside the modulus */
   33|  3.11M|   c->dp[b / MP_DIGIT_BIT] &=
  ------------------
  |  |   82|  3.11M|#   define MP_DIGIT_BIT 60
  ------------------
   34|  3.11M|      ((mp_digit)1 << (mp_digit)(b % MP_DIGIT_BIT)) - (mp_digit)1;
  ------------------
  |  |   82|  3.11M|#   define MP_DIGIT_BIT 60
  ------------------
   35|  3.11M|   mp_clamp(c);
   36|  3.11M|   return MP_OKAY;
  ------------------
  |  |  161|  3.11M|#define MP_OKAY       0   /* no error */
  ------------------
   37|  3.11M|}

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

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

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

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

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

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

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

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

mp_prime_is_prime:
   18|    232|{
   19|    232|   mp_int  b;
   20|    232|   int     ix, p_max = 0, size_a, len;
   21|    232|   mp_bool res;
   22|    232|   mp_err  err;
   23|    232|   unsigned int fips_rand, mask;
   24|       |
   25|       |   /* default to no */
   26|    232|   *result = MP_NO;
  ------------------
  |  |  159|    232|#define MP_NO         0
  ------------------
   27|       |
   28|       |   /* Some shortcuts */
   29|       |   /* N > 3 */
   30|    232|   if (a->used == 1) {
  ------------------
  |  Branch (30:8): [True: 0, False: 232]
  ------------------
   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|    232|   if (MP_IS_EVEN(a)) {
  ------------------
  |  |  164|    232|#define MP_IS_EVEN(a) (((a)->used == 0) || (((a)->dp[0] & 1u) == 0u))
  |  |  ------------------
  |  |  |  Branch (164:24): [True: 0, False: 232]
  |  |  |  Branch (164:44): [True: 96, False: 136]
  |  |  ------------------
  ------------------
   43|     96|      return MP_OKAY;
  ------------------
  |  |  161|     96|#define MP_OKAY       0   /* no error */
  ------------------
   44|     96|   }
   45|       |   /* N is not a perfect square: floor(sqrt(N))^2 != N */
   46|    136|   if ((err = mp_is_square(a, &res)) != MP_OKAY) {
  ------------------
  |  |  161|    136|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (46:8): [True: 0, False: 136]
  ------------------
   47|      0|      return err;
   48|      0|   }
   49|    136|   if (res != MP_NO) {
  ------------------
  |  |  159|    136|#define MP_NO         0
  ------------------
  |  Branch (49:8): [True: 1, False: 135]
  ------------------
   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|  34.6k|   for (ix = 0; ix < PRIVATE_MP_PRIME_TAB_SIZE; ix++) {
  ------------------
  |  |  633|  34.6k|#  define PRIVATE_MP_PRIME_TAB_SIZE 256
  ------------------
  |  Branch (54:17): [True: 34.5k, False: 135]
  ------------------
   55|  34.5k|      if (mp_cmp_d(a, s_mp_prime_tab[ix]) == MP_EQ) {
  ------------------
  |  |  155|  34.5k|#define MP_EQ         0   /* equal to */
  ------------------
  |  Branch (55:11): [True: 0, False: 34.5k]
  ------------------
   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|  34.5k|   }
   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|    135|   if ((err = s_mp_prime_is_divisible(a, &res)) != MP_OKAY) {
  ------------------
  |  |  161|    135|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (68:8): [True: 0, False: 135]
  ------------------
   69|      0|      return err;
   70|      0|   }
   71|       |
   72|       |   /* return if it was trivially divisible */
   73|    135|   if (res == MP_YES) {
  ------------------
  |  |  158|    135|#define MP_YES        1
  ------------------
  |  Branch (73:8): [True: 40, False: 95]
  ------------------
   74|     40|      return MP_OKAY;
  ------------------
  |  |  161|     40|#define MP_OKAY       0   /* no error */
  ------------------
   75|     40|   }
   76|       |
   77|       |   /*
   78|       |       Run the Miller-Rabin test with base 2 for the BPSW test.
   79|       |    */
   80|     95|   if ((err = mp_init_set(&b, 2uL)) != MP_OKAY) {
  ------------------
  |  |  161|     95|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (80:8): [True: 0, False: 95]
  ------------------
   81|      0|      return err;
   82|      0|   }
   83|       |
   84|     95|   if ((err = mp_prime_miller_rabin(a, &b, &res)) != MP_OKAY) {
  ------------------
  |  |  161|     95|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (84:8): [True: 0, False: 95]
  ------------------
   85|      0|      goto LBL_B;
   86|      0|   }
   87|     95|   if (res == MP_NO) {
  ------------------
  |  |  159|     95|#define MP_NO         0
  ------------------
  |  Branch (87:8): [True: 38, False: 57]
  ------------------
   88|     38|      goto LBL_B;
   89|     38|   }
   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|     95|LBL_B:
  310|     95|   mp_clear(&b);
  311|     95|   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|  2.03k|#define MP_EQ         0   /* equal to */
  ------------------
  |  Branch (59:8): [True: 2.03k, False: 116]
  |  Branch (59:40): [True: 1.94k, False: 91]
  ------------------
   60|  1.94k|      j = 1;
   61|       |      /* while j <= s-1 and y != n1 */
   62|   109k|      while ((j <= (s - 1)) && (mp_cmp(&y, &n1) != MP_EQ)) {
  ------------------
  |  |  155|   108k|#define MP_EQ         0   /* equal to */
  ------------------
  |  Branch (62:14): [True: 108k, False: 1.01k]
  |  Branch (62:32): [True: 107k, False: 923]
  ------------------
   63|   107k|         if ((err = mp_sqrmod(&y, a, &y)) != MP_OKAY) {
  ------------------
  |  |  161|   107k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (63:14): [True: 0, False: 107k]
  ------------------
   64|      0|            goto LBL_Y;
   65|      0|         }
   66|       |
   67|       |         /* if y == 1 then composite */
   68|   107k|         if (mp_cmp_d(&y, 1uL) == MP_EQ) {
  ------------------
  |  |  155|   107k|#define MP_EQ         0   /* equal to */
  ------------------
  |  Branch (68:14): [True: 0, False: 107k]
  ------------------
   69|      0|            goto LBL_Y;
   70|      0|         }
   71|       |
   72|   107k|         ++j;
   73|   107k|      }
   74|       |
   75|       |      /* if y != n1 then composite */
   76|  1.94k|      if (mp_cmp(&y, &n1) != MP_EQ) {
  ------------------
  |  |  155|  1.94k|#define MP_EQ         0   /* equal to */
  ------------------
  |  Branch (76:11): [True: 38, False: 1.90k]
  ------------------
   77|     38|         goto LBL_Y;
   78|     38|      }
   79|  1.94k|   }
   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|    232|{
   34|    232|   int x;
   35|       |
   36|  1.85k|   for (x = 0; x < (int)(sizeof(sizes)/(sizeof(sizes[0]))); x++) {
  ------------------
  |  Branch (36:16): [True: 1.85k, False: 0]
  ------------------
   37|  1.85k|      if (sizes[x].k == size) {
  ------------------
  |  Branch (37:11): [True: 232, False: 1.62k]
  ------------------
   38|    232|         return sizes[x].t;
   39|  1.62k|      } else if (sizes[x].k > size) {
  ------------------
  |  Branch (39:18): [True: 0, False: 1.62k]
  ------------------
   40|      0|         return (x == 0) ? sizes[0].t : sizes[x - 1].t;
  ------------------
  |  Branch (40:17): [True: 0, False: 0]
  ------------------
   41|      0|      }
   42|  1.85k|   }
   43|      0|   return sizes[x-1].t;
   44|    232|}

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

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

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

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

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

mp_reduce_is_2k_l:
    8|  3.37k|{
    9|  3.37k|   int ix, iy;
   10|       |
   11|  3.37k|   if (a->used == 0) {
  ------------------
  |  Branch (11:8): [True: 0, False: 3.37k]
  ------------------
   12|      0|      return MP_NO;
  ------------------
  |  |  159|      0|#define MP_NO         0
  ------------------
   13|  3.37k|   } else if (a->used == 1) {
  ------------------
  |  Branch (13:15): [True: 0, False: 3.37k]
  ------------------
   14|      0|      return MP_YES;
  ------------------
  |  |  158|      0|#define MP_YES        1
  ------------------
   15|  3.37k|   } else if (a->used > 1) {
  ------------------
  |  Branch (15:15): [True: 3.37k, False: 0]
  ------------------
   16|       |      /* if more than half of the digits are -1 we're sold */
   17|  45.3k|      for (iy = ix = 0; ix < a->used; ix++) {
  ------------------
  |  Branch (17:25): [True: 41.9k, False: 3.37k]
  ------------------
   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.82k, False: 35.1k]
  ------------------
   19|  6.82k|            ++iy;
   20|  6.82k|         }
   21|  41.9k|      }
   22|  3.37k|      return (iy >= (a->used/2)) ? MP_YES : MP_NO;
  ------------------
  |  |  158|    318|#define MP_YES        1
  ------------------
                    return (iy >= (a->used/2)) ? MP_YES : MP_NO;
  ------------------
  |  |  159|  3.05k|#define MP_NO         0
  ------------------
  |  Branch (22:14): [True: 318, False: 3.05k]
  ------------------
   23|  3.37k|   } else {
   24|      0|      return MP_NO;
  ------------------
  |  |  159|      0|#define MP_NO         0
  ------------------
   25|      0|   }
   26|  3.37k|}

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

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

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

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

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

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

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

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.58k|      for (ix = 0; ix < a->used; ix++) {
  ------------------
  |  Branch (60:20): [True: 6.44k, False: 2.14k]
  ------------------
   61|  6.44k|         *tmpc    = *tmpa++ - mu;
   62|  6.44k|         mu       = *tmpc >> (MP_SIZEOF_BITS(mp_digit) - 1u);
  ------------------
  |  |  167|  6.44k|#define MP_SIZEOF_BITS(type)    ((size_t)CHAR_BIT * sizeof(type))
  ------------------
   63|  6.44k|         *tmpc++ &= MP_MASK;
  ------------------
  |  |  106|  6.44k|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|  6.44k|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
   64|  6.44k|      }
   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 - Ignored]
  |  |  ------------------
  ------------------
   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|    454|{
    9|    454|   size_t  x, count;
   10|    454|   mp_err  err;
   11|    454|   mp_int  t;
   12|       |
   13|    454|   count = mp_ubin_size(a);
   14|    454|   if (count > maxlen) {
  ------------------
  |  Branch (14:8): [True: 0, False: 454]
  ------------------
   15|      0|      return MP_BUF;
  ------------------
  |  |  167|      0|#define MP_BUF        -5  /* buffer overflow, supplied buffer too small */
  ------------------
   16|      0|   }
   17|       |
   18|    454|   if ((err = mp_init_copy(&t, a)) != MP_OKAY) {
  ------------------
  |  |  161|    454|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (18:8): [True: 0, False: 454]
  ------------------
   19|      0|      return err;
   20|      0|   }
   21|       |
   22|  18.3k|   for (x = count; x --> 0u;) {
  ------------------
  |  Branch (22:20): [True: 17.9k, False: 454]
  ------------------
   23|  17.9k|#ifndef MP_8BIT
   24|  17.9k|      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|  17.9k|      if ((err = mp_div_2d(&t, 8, &t, NULL)) != MP_OKAY) {
  ------------------
  |  |  161|  17.9k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (28:11): [True: 0, False: 17.9k]
  ------------------
   29|      0|         goto LBL_ERR;
   30|      0|      }
   31|  17.9k|   }
   32|       |
   33|    454|   if (written != NULL) {
  ------------------
  |  Branch (33:8): [True: 0, False: 454]
  ------------------
   34|      0|      *written = count;
   35|      0|   }
   36|       |
   37|    454|LBL_ERR:
   38|    454|   mp_clear(&t);
   39|    454|   return err;
   40|    454|}

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

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

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

s_mp_exptmod:
   15|    867|{
   16|    867|   mp_int  M[TAB_SIZE], res, mu;
   17|    867|   mp_digit buf;
   18|    867|   mp_err   err;
   19|    867|   int      bitbuf, bitcpy, bitcnt, mode, digidx, x, y, winsize;
   20|    867|   mp_err(*redux)(mp_int *x, const mp_int *m, const mp_int *mu);
   21|       |
   22|       |   /* find window size */
   23|    867|   x = mp_count_bits(X);
   24|    867|   if (x <= 7) {
  ------------------
  |  Branch (24:8): [True: 191, False: 676]
  ------------------
   25|    191|      winsize = 2;
   26|    676|   } else if (x <= 36) {
  ------------------
  |  Branch (26:15): [True: 255, False: 421]
  ------------------
   27|    255|      winsize = 3;
   28|    421|   } else if (x <= 140) {
  ------------------
  |  Branch (28:15): [True: 130, False: 291]
  ------------------
   29|    130|      winsize = 4;
   30|    291|   } else if (x <= 450) {
  ------------------
  |  Branch (30:15): [True: 291, False: 0]
  ------------------
   31|    291|      winsize = 5;
   32|    291|   } 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|    867|   winsize = MAX_WINSIZE ? MP_MIN(MAX_WINSIZE, winsize) : winsize;
  ------------------
  |  |   11|    867|#   define MAX_WINSIZE 0
  |  |  ------------------
  |  |  |  Branch (11:24): [Folded - Ignored]
  |  |  ------------------
  ------------------
                 winsize = MAX_WINSIZE ? MP_MIN(MAX_WINSIZE, winsize) : winsize;
  ------------------
  |  |  156|      0|#define MP_MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (156:23): [True: 0, False: 0]
  |  |  ------------------
  ------------------
   41|       |
   42|       |   /* init M array */
   43|       |   /* init first cell */
   44|    867|   if ((err = mp_init(&M[1])) != MP_OKAY) {
  ------------------
  |  |  161|    867|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (44:8): [True: 0, False: 867]
  ------------------
   45|      0|      return err;
   46|      0|   }
   47|       |
   48|       |   /* now init the second half of the array */
   49|  7.96k|   for (x = 1<<(winsize-1); x < (1 << winsize); x++) {
  ------------------
  |  Branch (49:29): [True: 7.09k, False: 867]
  ------------------
   50|  7.09k|      if ((err = mp_init(&M[x])) != MP_OKAY) {
  ------------------
  |  |  161|  7.09k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (50:11): [True: 0, False: 7.09k]
  ------------------
   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.09k|   }
   58|       |
   59|       |   /* create mu, used for Barrett reduction */
   60|    867|   if ((err = mp_init(&mu)) != MP_OKAY)                           goto LBL_M;
  ------------------
  |  |  161|    867|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (60:8): [True: 0, False: 867]
  ------------------
   61|       |
   62|    867|   if (redmode == 0) {
  ------------------
  |  Branch (62:8): [True: 549, False: 318]
  ------------------
   63|    549|      if ((err = mp_reduce_setup(&mu, P)) != MP_OKAY)             goto LBL_MU;
  ------------------
  |  |  161|    549|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (63:11): [True: 0, False: 549]
  ------------------
   64|    549|      redux = mp_reduce;
   65|    549|   } else {
   66|    318|      if ((err = mp_reduce_2k_setup_l(P, &mu)) != MP_OKAY)        goto LBL_MU;
  ------------------
  |  |  161|    318|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (66:11): [True: 0, False: 318]
  ------------------
   67|    318|      redux = mp_reduce_2k_l;
   68|    318|   }
   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|    867|   if ((err = mp_mod(G, P, &M[1])) != MP_OKAY)                    goto LBL_MU;
  ------------------
  |  |  161|    867|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (78:8): [True: 0, False: 867]
  ------------------
   79|       |
   80|       |   /* compute the value at M[1<<(winsize-1)] by squaring
   81|       |    * M[1] (winsize-1) times
   82|       |    */
   83|    867|   if ((err = mp_copy(&M[1], &M[(size_t)1 << (winsize - 1)])) != MP_OKAY) goto LBL_MU;
  ------------------
  |  |  161|    867|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (83:8): [True: 0, False: 867]
  ------------------
   84|       |
   85|  3.12k|   for (x = 0; x < (winsize - 1); x++) {
  ------------------
  |  Branch (85:16): [True: 2.25k, False: 867]
  ------------------
   86|       |      /* square it */
   87|  2.25k|      if ((err = mp_sqr(&M[(size_t)1 << (winsize - 1)],
  ------------------
  |  Branch (87:11): [True: 0, False: 2.25k]
  ------------------
   88|  2.25k|                        &M[(size_t)1 << (winsize - 1)])) != MP_OKAY) goto LBL_MU;
  ------------------
  |  |  161|  2.25k|#define MP_OKAY       0   /* no error */
  ------------------
   89|       |
   90|       |      /* reduce modulo P */
   91|  2.25k|      if ((err = redux(&M[(size_t)1 << (winsize - 1)], P, &mu)) != MP_OKAY) goto LBL_MU;
  ------------------
  |  |  161|  2.25k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (91:11): [True: 0, False: 2.25k]
  ------------------
   92|  2.25k|   }
   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.09k|   for (x = (1 << (winsize - 1)) + 1; x < (1 << winsize); x++) {
  ------------------
  |  Branch (97:39): [True: 6.23k, False: 867]
  ------------------
   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|    867|   if ((err = mp_init(&res)) != MP_OKAY)                          goto LBL_MU;
  ------------------
  |  |  161|    867|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (103:8): [True: 0, False: 867]
  ------------------
  104|    867|   mp_set(&res, 1uL);
  105|       |
  106|       |   /* set initial mode and bit cnt */
  107|    867|   mode   = 0;
  108|    867|   bitcnt = 1;
  109|    867|   buf    = 0;
  110|    867|   digidx = X->used - 1;
  111|    867|   bitcpy = 0;
  112|    867|   bitbuf = 0;
  113|       |
  114|  85.8k|   for (;;) {
  115|       |      /* grab next digit as required */
  116|  85.8k|      if (--bitcnt == 0) {
  ------------------
  |  Branch (116:11): [True: 2.28k, False: 83.5k]
  ------------------
  117|       |         /* if digidx == -1 we are out of digits */
  118|  2.28k|         if (digidx == -1) {
  ------------------
  |  Branch (118:14): [True: 867, False: 1.41k]
  ------------------
  119|    867|            break;
  120|    867|         }
  121|       |         /* read next digit and reset the bitcnt */
  122|  1.41k|         buf    = X->dp[digidx--];
  123|  1.41k|         bitcnt = (int)MP_DIGIT_BIT;
  ------------------
  |  |   82|  1.41k|#   define MP_DIGIT_BIT 60
  ------------------
  124|  1.41k|      }
  125|       |
  126|       |      /* grab the next msb from the exponent */
  127|  84.9k|      y     = (buf >> (mp_digit)(MP_DIGIT_BIT - 1)) & 1uL;
  ------------------
  |  |   82|  84.9k|#   define MP_DIGIT_BIT 60
  ------------------
  128|  84.9k|      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|  84.9k|      if ((mode == 0) && (y == 0)) {
  ------------------
  |  Branch (135:11): [True: 23.9k, False: 60.9k]
  |  Branch (135:26): [True: 23.2k, False: 727]
  ------------------
  136|  23.2k|         continue;
  137|  23.2k|      }
  138|       |
  139|       |      /* if the bit is zero and mode == 1 then we square */
  140|  61.7k|      if ((mode == 1) && (y == 0)) {
  ------------------
  |  Branch (140:11): [True: 22.1k, False: 39.5k]
  |  Branch (140:26): [True: 11.9k, False: 10.2k]
  ------------------
  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|  49.8k|      bitbuf |= (y << (winsize - ++bitcpy));
  148|  49.8k|      mode    = 2;
  149|       |
  150|  49.8k|      if (bitcpy == winsize) {
  ------------------
  |  Branch (150:11): [True: 10.5k, False: 39.2k]
  ------------------
  151|       |         /* ok window is filled so square as required and multiply  */
  152|       |         /* square first */
  153|  59.4k|         for (x = 0; x < winsize; x++) {
  ------------------
  |  Branch (153:22): [True: 48.8k, False: 10.5k]
  ------------------
  154|  48.8k|            if ((err = mp_sqr(&res, &res)) != MP_OKAY)            goto LBL_RES;
  ------------------
  |  |  161|  48.8k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (154:17): [True: 0, False: 48.8k]
  ------------------
  155|  48.8k|            if ((err = redux(&res, P, &mu)) != MP_OKAY)           goto LBL_RES;
  ------------------
  |  |  161|  48.8k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (155:17): [True: 0, False: 48.8k]
  ------------------
  156|  48.8k|         }
  157|       |
  158|       |         /* then multiply */
  159|  10.5k|         if ((err = mp_mul(&res, &M[bitbuf], &res)) != MP_OKAY)  goto LBL_RES;
  ------------------
  |  |  161|  10.5k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (159:14): [True: 0, False: 10.5k]
  ------------------
  160|  10.5k|         if ((err = redux(&res, P, &mu)) != MP_OKAY)             goto LBL_RES;
  ------------------
  |  |  161|  10.5k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (160:14): [True: 0, False: 10.5k]
  ------------------
  161|       |
  162|       |         /* empty window and reset */
  163|  10.5k|         bitcpy = 0;
  164|  10.5k|         bitbuf = 0;
  165|  10.5k|         mode   = 1;
  166|  10.5k|      }
  167|  49.8k|   }
  168|       |
  169|       |   /* if bits remain then square/multiply */
  170|    867|   if ((mode == 2) && (bitcpy > 0)) {
  ------------------
  |  Branch (170:8): [True: 380, False: 487]
  |  Branch (170:23): [True: 380, False: 0]
  ------------------
  171|       |      /* square then multiply if the bit is set */
  172|  1.31k|      for (x = 0; x < bitcpy; x++) {
  ------------------
  |  Branch (172:19): [True: 936, False: 380]
  ------------------
  173|    936|         if ((err = mp_sqr(&res, &res)) != MP_OKAY)               goto LBL_RES;
  ------------------
  |  |  161|    936|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (173:14): [True: 0, False: 936]
  ------------------
  174|    936|         if ((err = redux(&res, P, &mu)) != MP_OKAY)              goto LBL_RES;
  ------------------
  |  |  161|    936|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (174:14): [True: 0, False: 936]
  ------------------
  175|       |
  176|    936|         bitbuf <<= 1;
  177|    936|         if ((bitbuf & (1 << winsize)) != 0) {
  ------------------
  |  Branch (177:14): [True: 736, False: 200]
  ------------------
  178|       |            /* then multiply */
  179|    736|            if ((err = mp_mul(&res, &M[1], &res)) != MP_OKAY)     goto LBL_RES;
  ------------------
  |  |  161|    736|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (179:17): [True: 0, False: 736]
  ------------------
  180|    736|            if ((err = redux(&res, P, &mu)) != MP_OKAY)           goto LBL_RES;
  ------------------
  |  |  161|    736|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (180:17): [True: 0, False: 736]
  ------------------
  181|    736|         }
  182|    936|      }
  183|    380|   }
  184|       |
  185|    867|   mp_exch(&res, Y);
  186|    867|   err = MP_OKAY;
  ------------------
  |  |  161|    867|#define MP_OKAY       0   /* no error */
  ------------------
  187|    867|LBL_RES:
  188|    867|   mp_clear(&res);
  189|    867|LBL_MU:
  190|    867|   mp_clear(&mu);
  191|    867|LBL_M:
  192|    867|   mp_clear(&M[1]);
  193|  7.96k|   for (x = 1<<(winsize-1); x < (1 << winsize); x++) {
  ------------------
  |  Branch (193:29): [True: 7.09k, False: 867]
  ------------------
  194|  7.09k|      mp_clear(&M[x]);
  195|  7.09k|   }
  196|    867|   return err;
  197|    867|}

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

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

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

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

s_mp_mul_digs:
   11|  47.1k|{
   12|  47.1k|   mp_int  t;
   13|  47.1k|   mp_err  err;
   14|  47.1k|   int     pa, pb, ix, iy;
   15|  47.1k|   mp_digit u;
   16|  47.1k|   mp_word r;
   17|  47.1k|   mp_digit tmpx, *tmpt, *tmpy;
   18|       |
   19|  47.1k|   if (digs < 0) {
  ------------------
  |  Branch (19:8): [True: 0, False: 47.1k]
  ------------------
   20|      0|      return MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
   21|      0|   }
   22|       |
   23|       |   /* can we use the fast multiplier? */
   24|  47.1k|   if ((digs < MP_WARRAY) &&
  ------------------
  |  |  172|  47.1k|#define MP_WARRAY PRIVATE_MP_WARRAY
  |  |  ------------------
  |  |  |  |  203|  47.1k|#define PRIVATE_MP_WARRAY (int)(1uLL << (((CHAR_BIT * sizeof(private_mp_word)) - (2 * MP_DIGIT_BIT)) + 1))
  |  |  |  |  ------------------
  |  |  |  |  |  |   82|  47.1k|#   define MP_DIGIT_BIT 60
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (24:8): [True: 47.1k, False: 0]
  ------------------
   25|  47.1k|       (MP_MIN(a->used, b->used) < MP_MAXFAST)) {
  ------------------
  |  |  156|  47.1k|#define MP_MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (156:23): [True: 40.2k, False: 6.93k]
  |  |  ------------------
  ------------------
                     (MP_MIN(a->used, b->used) < MP_MAXFAST)) {
  ------------------
  |  |  168|  47.1k|#define MP_MAXFAST              (int)(1uL << (MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT)))
  |  |  ------------------
  |  |  |  |  167|  47.1k|#define MP_SIZEOF_BITS(type)    ((size_t)CHAR_BIT * sizeof(type))
  |  |  ------------------
  |  |               #define MP_MAXFAST              (int)(1uL << (MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT)))
  |  |  ------------------
  |  |  |  |   82|  47.1k|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
  |  Branch (25:8): [True: 47.1k, False: 0]
  ------------------
   26|  47.1k|      return s_mp_mul_digs_fast(a, b, c, digs);
   27|  47.1k|   }
   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.98M|{
   24|  3.98M|   int      olduse, pa, ix, iz;
   25|  3.98M|   mp_err   err;
   26|  3.98M|   mp_digit W[MP_WARRAY];
   27|  3.98M|   mp_word  _W;
   28|       |
   29|  3.98M|   if (digs < 0) {
  ------------------
  |  Branch (29:8): [True: 0, False: 3.98M]
  ------------------
   30|      0|      return MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
   31|      0|   }
   32|       |
   33|       |   /* grow the destination as required */
   34|  3.98M|   if (c->alloc < digs) {
  ------------------
  |  Branch (34:8): [True: 9.03k, False: 3.97M]
  ------------------
   35|  9.03k|      if ((err = mp_grow(c, digs)) != MP_OKAY) {
  ------------------
  |  |  161|  9.03k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (35:11): [True: 0, False: 9.03k]
  ------------------
   36|      0|         return err;
   37|      0|      }
   38|  9.03k|   }
   39|       |
   40|       |   /* number of output digits to produce */
   41|  3.98M|   pa = MP_MIN(digs, a->used + b->used);
  ------------------
  |  |  156|  3.98M|#define MP_MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (156:23): [True: 18.8k, False: 3.96M]
  |  |  ------------------
  ------------------
   42|       |
   43|       |   /* clear the carry */
   44|  3.98M|   _W = 0;
   45|   104M|   for (ix = 0; ix < pa; ix++) {
  ------------------
  |  Branch (45:17): [True: 100M, False: 3.98M]
  ------------------
   46|   100M|      int      tx, ty;
   47|   100M|      int      iy;
   48|   100M|      mp_digit *tmpx, *tmpy;
   49|       |
   50|       |      /* get offsets into the two bignums */
   51|   100M|      ty = MP_MIN(b->used-1, ix);
  ------------------
  |  |  156|   100M|#define MP_MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (156:23): [True: 35.0M, False: 65.0M]
  |  |  ------------------
  ------------------
   52|   100M|      tx = ix - ty;
   53|       |
   54|       |      /* setup temp aliases */
   55|   100M|      tmpx = a->dp + tx;
   56|   100M|      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|   100M|      iy = MP_MIN(a->used-tx, ty+1);
  ------------------
  |  |  156|   100M|#define MP_MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (156:23): [True: 64.7M, False: 35.2M]
  |  |  ------------------
  ------------------
   62|       |
   63|       |      /* execute loop */
   64|  2.34G|      for (iz = 0; iz < iy; ++iz) {
  ------------------
  |  Branch (64:20): [True: 2.24G, False: 100M]
  ------------------
   65|  2.24G|         _W += (mp_word)*tmpx++ * (mp_word)*tmpy--;
   66|       |
   67|  2.24G|      }
   68|       |
   69|       |      /* store term */
   70|   100M|      W[ix] = (mp_digit)_W & MP_MASK;
  ------------------
  |  |  106|   100M|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|   100M|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
   71|       |
   72|       |      /* make next carry */
   73|   100M|      _W = _W >> (mp_word)MP_DIGIT_BIT;
  ------------------
  |  |   82|   100M|#   define MP_DIGIT_BIT 60
  ------------------
   74|   100M|   }
   75|       |
   76|       |   /* setup dest */
   77|  3.98M|   olduse  = c->used;
   78|  3.98M|   c->used = pa;
   79|       |
   80|  3.98M|   {
   81|  3.98M|      mp_digit *tmpc;
   82|  3.98M|      tmpc = c->dp;
   83|   104M|      for (ix = 0; ix < pa; ix++) {
  ------------------
  |  Branch (83:20): [True: 100M, False: 3.98M]
  ------------------
   84|       |         /* now extract the previous digit [below the carry] */
   85|   100M|         *tmpc++ = W[ix];
   86|   100M|      }
   87|       |
   88|       |      /* clear unused digits [that existed in the old copy of c] */
   89|  3.98M|      MP_ZERO_DIGITS(tmpc, olduse - ix);
  ------------------
  |  |   89|  3.98M|#  define MP_ZERO_DIGITS(mem, digits)                   \
  |  |   90|  3.98M|do {                                                    \
  |  |   91|  3.98M|   int zd_ = (digits);                                  \
  |  |   92|  3.98M|   mp_digit* zm_ = (mem);                               \
  |  |   93|  3.98M|   while (zd_-- > 0) {                                  \
  |  |  ------------------
  |  |  |  Branch (93:11): [True: 0, False: 3.98M]
  |  |  ------------------
  |  |   94|      0|      *zm_++ = 0;                                       \
  |  |   95|      0|   }                                                    \
  |  |   96|  3.98M|} while (0)
  |  |  ------------------
  |  |  |  Branch (96:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
   90|  3.98M|   }
   91|  3.98M|   mp_clamp(c);
   92|  3.98M|   return MP_OKAY;
  ------------------
  |  |  161|  3.98M|#define MP_OKAY       0   /* no error */
  ------------------
   93|  3.98M|}

s_mp_mul_high_digs:
   10|  47.1k|{
   11|  47.1k|   mp_int   t;
   12|  47.1k|   int      pa, pb, ix, iy;
   13|  47.1k|   mp_err   err;
   14|  47.1k|   mp_digit u;
   15|  47.1k|   mp_word  r;
   16|  47.1k|   mp_digit tmpx, *tmpt, *tmpy;
   17|       |
   18|  47.1k|   if (digs < 0) {
  ------------------
  |  Branch (18:8): [True: 0, False: 47.1k]
  ------------------
   19|      0|      return MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
   20|      0|   }
   21|       |
   22|       |   /* can we use the fast multiplier? */
   23|  47.1k|   if (MP_HAS(S_MP_MUL_HIGH_DIGS_FAST)
  ------------------
  |  |  150|  94.2k|#define MP_HAS(x)        (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u)
  |  |  ------------------
  |  |  |  |  148|  47.1k|#define MP_STRINGIZE(x)  MP__STRINGIZE(x)
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|  47.1k|#define MP__STRINGIZE(x) ""#x""
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (150:26): [Folded - Ignored]
  |  |  ------------------
  ------------------
   24|  47.1k|       && ((a->used + b->used + 1) < MP_WARRAY)
  ------------------
  |  |  172|  47.1k|#define MP_WARRAY PRIVATE_MP_WARRAY
  |  |  ------------------
  |  |  |  |  203|  47.1k|#define PRIVATE_MP_WARRAY (int)(1uLL << (((CHAR_BIT * sizeof(private_mp_word)) - (2 * MP_DIGIT_BIT)) + 1))
  |  |  |  |  ------------------
  |  |  |  |  |  |   82|  47.1k|#   define MP_DIGIT_BIT 60
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (24:11): [True: 47.1k, False: 0]
  ------------------
   25|  47.1k|       && (MP_MIN(a->used, b->used) < MP_MAXFAST)) {
  ------------------
  |  |  156|  47.1k|#define MP_MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (156:23): [True: 47.0k, False: 114]
  |  |  ------------------
  ------------------
                     && (MP_MIN(a->used, b->used) < MP_MAXFAST)) {
  ------------------
  |  |  168|  47.1k|#define MP_MAXFAST              (int)(1uL << (MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT)))
  |  |  ------------------
  |  |  |  |  167|  47.1k|#define MP_SIZEOF_BITS(type)    ((size_t)CHAR_BIT * sizeof(type))
  |  |  ------------------
  |  |               #define MP_MAXFAST              (int)(1uL << (MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT)))
  |  |  ------------------
  |  |  |  |   82|  47.1k|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
  |  Branch (25:11): [True: 47.1k, False: 0]
  ------------------
   26|  47.1k|      return s_mp_mul_high_digs_fast(a, b, c, digs);
   27|  47.1k|   }
   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|  47.1k|{
   17|  47.1k|   int     olduse, pa, ix, iz;
   18|  47.1k|   mp_err   err;
   19|  47.1k|   mp_digit W[MP_WARRAY];
   20|  47.1k|   mp_word  _W;
   21|       |
   22|  47.1k|   if (digs < 0) {
  ------------------
  |  Branch (22:8): [True: 0, False: 47.1k]
  ------------------
   23|      0|      return MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
   24|      0|   }
   25|       |
   26|       |   /* grow the destination as required */
   27|  47.1k|   pa = a->used + b->used;
   28|  47.1k|   if (c->alloc < pa) {
  ------------------
  |  Branch (28:8): [True: 47.1k, False: 0]
  ------------------
   29|  47.1k|      if ((err = mp_grow(c, pa)) != MP_OKAY) {
  ------------------
  |  |  161|  47.1k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (29:11): [True: 0, False: 47.1k]
  ------------------
   30|      0|         return err;
   31|      0|      }
   32|  47.1k|   }
   33|       |
   34|       |   /* number of output digits to produce */
   35|  47.1k|   pa = a->used + b->used;
   36|  47.1k|   _W = 0;
   37|   358k|   for (ix = digs; ix < pa; ix++) {
  ------------------
  |  Branch (37:20): [True: 311k, False: 47.1k]
  ------------------
   38|   311k|      int      tx, ty, iy;
   39|   311k|      mp_digit *tmpx, *tmpy;
   40|       |
   41|       |      /* get offsets into the two bignums */
   42|   311k|      ty = MP_MIN(b->used-1, ix);
  ------------------
  |  |  156|   311k|#define MP_MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (156:23): [True: 263k, False: 47.2k]
  |  |  ------------------
  ------------------
   43|   311k|      tx = ix - ty;
   44|       |
   45|       |      /* setup temp aliases */
   46|   311k|      tmpx = a->dp + tx;
   47|   311k|      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|   311k|      iy = MP_MIN(a->used-tx, ty+1);
  ------------------
  |  |  156|   311k|#define MP_MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (156:23): [True: 311k, False: 114]
  |  |  ------------------
  ------------------
   53|       |
   54|       |      /* execute loop */
   55|  3.00M|      for (iz = 0; iz < iy; iz++) {
  ------------------
  |  Branch (55:20): [True: 2.69M, False: 311k]
  ------------------
   56|  2.69M|         _W += (mp_word)*tmpx++ * (mp_word)*tmpy--;
   57|  2.69M|      }
   58|       |
   59|       |      /* store term */
   60|   311k|      W[ix] = (mp_digit)_W & MP_MASK;
  ------------------
  |  |  106|   311k|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|   311k|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
   61|       |
   62|       |      /* make next carry */
   63|   311k|      _W = _W >> (mp_word)MP_DIGIT_BIT;
  ------------------
  |  |   82|   311k|#   define MP_DIGIT_BIT 60
  ------------------
   64|   311k|   }
   65|       |
   66|       |   /* setup dest */
   67|  47.1k|   olduse  = c->used;
   68|  47.1k|   c->used = pa;
   69|       |
   70|  47.1k|   {
   71|  47.1k|      mp_digit *tmpc;
   72|       |
   73|  47.1k|      tmpc = c->dp + digs;
   74|   358k|      for (ix = digs; ix < pa; ix++) {
  ------------------
  |  Branch (74:23): [True: 311k, False: 47.1k]
  ------------------
   75|       |         /* now extract the previous digit [below the carry] */
   76|   311k|         *tmpc++ = W[ix];
   77|   311k|      }
   78|       |
   79|       |      /* clear unused digits [that existed in the old copy of c] */
   80|  47.1k|      MP_ZERO_DIGITS(tmpc, olduse - ix);
  ------------------
  |  |   89|  47.1k|#  define MP_ZERO_DIGITS(mem, digits)                   \
  |  |   90|  47.1k|do {                                                    \
  |  |   91|  47.1k|   int zd_ = (digits);                                  \
  |  |   92|  47.1k|   mp_digit* zm_ = (mem);                               \
  |  |   93|  47.1k|   while (zd_-- > 0) {                                  \
  |  |  ------------------
  |  |  |  Branch (93:11): [True: 0, False: 47.1k]
  |  |  ------------------
  |  |   94|      0|      *zm_++ = 0;                                       \
  |  |   95|      0|   }                                                    \
  |  |   96|  47.1k|} while (0)
  |  |  ------------------
  |  |  |  Branch (96:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
   81|  47.1k|   }
   82|  47.1k|   mp_clamp(c);
   83|  47.1k|   return MP_OKAY;
  ------------------
  |  |  161|  47.1k|#define MP_OKAY       0   /* no error */
  ------------------
   84|  47.1k|}

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

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

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

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

mp_set_u32:
  253|    493|    {                                                                                  \
  254|    493|        int i = 0;                                                                     \
  255|    493|        while (b != 0u) {                                                              \
  ------------------
  |  Branch (255:16): [True: 493, False: 0]
  ------------------
  256|    493|            a->dp[i++] = ((mp_digit)b & MP_MASK);                                      \
  ------------------
  |  |  106|    493|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|    493|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
  257|    493|            if (MP_SIZEOF_BITS(type) <= MP_DIGIT_BIT) { break; }                       \
  ------------------
  |  |  167|    493|#define MP_SIZEOF_BITS(type)    ((size_t)CHAR_BIT * sizeof(type))
  ------------------
                          if (MP_SIZEOF_BITS(type) <= MP_DIGIT_BIT) { break; }                       \
  ------------------
  |  |   82|    493|#   define MP_DIGIT_BIT 60
  ------------------
  |  Branch (257:17): [Folded - Ignored]
  ------------------
  258|    493|            b >>= ((MP_SIZEOF_BITS(type) <= MP_DIGIT_BIT) ? 0 : MP_DIGIT_BIT);         \
  ------------------
  |  |  167|      0|#define MP_SIZEOF_BITS(type)    ((size_t)CHAR_BIT * sizeof(type))
  ------------------
                          b >>= ((MP_SIZEOF_BITS(type) <= MP_DIGIT_BIT) ? 0 : MP_DIGIT_BIT);         \
  ------------------
  |  |   82|      0|#   define MP_DIGIT_BIT 60
  ------------------
                          b >>= ((MP_SIZEOF_BITS(type) <= MP_DIGIT_BIT) ? 0 : MP_DIGIT_BIT);         \
  ------------------
  |  |   82|      0|#   define MP_DIGIT_BIT 60
  ------------------
  |  Branch (258:20): [Folded - Ignored]
  ------------------
  259|      0|        }                                                                              \
  260|    493|        a->used = i;                                                                   \
  261|    493|        a->sign = MP_ZPOS;                                                             \
  ------------------
  |  |  151|    493|#define MP_ZPOS       0   /* positive integer */
  ------------------
  262|    493|        MP_ZERO_DIGITS(a->dp + a->used, a->alloc - a->used);                           \
  ------------------
  |  |   89|    493|#  define MP_ZERO_DIGITS(mem, digits)                   \
  |  |   90|    493|do {                                                    \
  |  |   91|    493|   int zd_ = (digits);                                  \
  |  |   92|    493|   mp_digit* zm_ = (mem);                               \
  |  |   93|  15.7k|   while (zd_-- > 0) {                                  \
  |  |  ------------------
  |  |  |  Branch (93:11): [True: 15.2k, False: 493]
  |  |  ------------------
  |  |   94|  15.2k|      *zm_++ = 0;                                       \
  |  |   95|  15.2k|   }                                                    \
  |  |   96|    493|} while (0)
  |  |  ------------------
  |  |  |  Branch (96:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
  263|    493|    }
mp_get_i32:
  298|     39|    {                                                         \
  299|     39|        utype res = mag(a);                                   \
  300|     39|        return (a->sign == MP_NEG) ? (type)-res : (type)res;  \
  ------------------
  |  |  152|     39|#define MP_NEG        1   /* negative */
  ------------------
  |  Branch (300:16): [True: 0, False: 39]
  ------------------
  301|     39|    }
mp_get_mag_u32:
  285|     39|    {                                                                                  \
  286|     39|        unsigned i = MP_MIN((unsigned)a->used, (unsigned)((MP_SIZEOF_BITS(type) + MP_DIGIT_BIT - 1) / MP_DIGIT_BIT)); \
  ------------------
  |  |  156|     39|#define MP_MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (156:23): [True: 0, False: 39]
  |  |  ------------------
  ------------------
  287|     39|        type res = 0u;                                                                 \
  288|     39|        while (i --> 0u) {                                                             \
  ------------------
  |  Branch (288:16): [True: 39, False: 0]
  ------------------
  289|     39|            res <<= ((MP_SIZEOF_BITS(type) <= MP_DIGIT_BIT) ? 0 : MP_DIGIT_BIT);       \
  ------------------
  |  |  167|     39|#define MP_SIZEOF_BITS(type)    ((size_t)CHAR_BIT * sizeof(type))
  ------------------
                          res <<= ((MP_SIZEOF_BITS(type) <= MP_DIGIT_BIT) ? 0 : MP_DIGIT_BIT);       \
  ------------------
  |  |   82|     39|#   define MP_DIGIT_BIT 60
  ------------------
                          res <<= ((MP_SIZEOF_BITS(type) <= MP_DIGIT_BIT) ? 0 : MP_DIGIT_BIT);       \
  ------------------
  |  |   82|      0|#   define MP_DIGIT_BIT 60
  ------------------
  |  Branch (289:22): [Folded - Ignored]
  ------------------
  290|     39|            res |= (type)a->dp[i];                                                     \
  291|     39|            if (MP_SIZEOF_BITS(type) <= MP_DIGIT_BIT) { break; }                       \
  ------------------
  |  |  167|     39|#define MP_SIZEOF_BITS(type)    ((size_t)CHAR_BIT * sizeof(type))
  ------------------
                          if (MP_SIZEOF_BITS(type) <= MP_DIGIT_BIT) { break; }                       \
  ------------------
  |  |   82|     39|#   define MP_DIGIT_BIT 60
  ------------------
  |  Branch (291:17): [Folded - Ignored]
  ------------------
  292|     39|        }                                                                              \
  293|     39|        return res;                                                                    \
  294|     39|    }
mp_init_u32:
  274|     39|    {                                                    \
  275|     39|        mp_err err;                                      \
  276|     39|        if ((err = mp_init(a)) != MP_OKAY) {             \
  ------------------
  |  |  161|     39|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (276:13): [True: 0, False: 39]
  ------------------
  277|      0|            return err;                                  \
  278|      0|        }                                                \
  279|     39|        set(a, b);                                       \
  280|     39|        return MP_OKAY;                                  \
  ------------------
  |  |  161|     39|#define MP_OKAY       0   /* no error */
  ------------------
  281|     39|    }

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

buf_new:
   41|  1.42k|buffer* buf_new(unsigned int size) {
   42|  1.42k|	buffer* buf;
   43|  1.42k|	if (size > BUF_MAX_SIZE) {
  ------------------
  |  |   35|  1.42k|#define BUF_MAX_SIZE 1000000000
  ------------------
  |  Branch (43:6): [True: 0, False: 1.42k]
  ------------------
   44|      0|		dropbear_exit("buf->size too big");
   45|      0|	}
   46|       |
   47|  1.42k|	buf = (buffer*)m_malloc(sizeof(buffer)+size);
   48|  1.42k|	buf->data = (unsigned char*)buf + sizeof(buffer);
   49|  1.42k|	buf->size = size;
   50|  1.42k|	return buf;
   51|  1.42k|}
buf_free:
   54|  1.43k|void buf_free(buffer* buf) {
   55|  1.43k|	m_free(buf);
  ------------------
  |  |   24|  1.43k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
   56|  1.43k|}
buf_incrlen:
  104|   176k|void buf_incrlen(buffer* buf, unsigned int incr) {
  105|   176k|	if (incr > BUF_MAX_INCR || buf->len + incr > buf->size) {
  ------------------
  |  |   34|   352k|#define BUF_MAX_INCR 1000000000
  ------------------
  |  Branch (105:6): [True: 0, False: 176k]
  |  Branch (105:29): [True: 0, False: 176k]
  ------------------
  106|      0|		dropbear_exit("Bad buf_incrlen");
  107|      0|	}
  108|   176k|	buf->len += incr;
  109|   176k|}
buf_setpos:
  111|  1.86k|void buf_setpos(buffer* buf, unsigned int pos) {
  112|       |
  113|  1.86k|	if (pos > buf->len) {
  ------------------
  |  Branch (113:6): [True: 0, False: 1.86k]
  ------------------
  114|      0|		dropbear_exit("Bad buf_setpos");
  115|      0|	}
  116|  1.86k|	buf->pos = pos;
  117|  1.86k|}
buf_incrwritepos:
  120|  1.76k|void buf_incrwritepos(buffer* buf, unsigned int incr) {
  121|  1.76k|	if (incr > BUF_MAX_INCR || buf->pos + incr > buf->size) {
  ------------------
  |  |   34|  3.53k|#define BUF_MAX_INCR 1000000000
  ------------------
  |  Branch (121:6): [True: 0, False: 1.76k]
  |  Branch (121:29): [True: 0, False: 1.76k]
  ------------------
  122|      0|		dropbear_exit("Bad buf_incrwritepos");
  123|      0|	}
  124|  1.76k|	buf->pos += incr;
  125|  1.76k|	if (buf->pos > buf->len) {
  ------------------
  |  Branch (125:6): [True: 1.76k, False: 0]
  ------------------
  126|  1.76k|		buf->len = buf->pos;
  127|  1.76k|	}
  128|  1.76k|}
buf_incrpos:
  131|  27.7k|void buf_incrpos(buffer* buf, unsigned int incr) {
  132|  27.7k|	if (incr > BUF_MAX_INCR 
  ------------------
  |  |   34|  55.5k|#define BUF_MAX_INCR 1000000000
  ------------------
  |  Branch (132:6): [True: 0, False: 27.7k]
  ------------------
  133|  27.7k|		|| (buf->pos + incr) > buf->len) {
  ------------------
  |  Branch (133:6): [True: 0, False: 27.7k]
  ------------------
  134|      0|		dropbear_exit("Bad buf_incrpos");
  135|      0|	}
  136|  27.7k|	buf->pos += incr;
  137|  27.7k|}
buf_decrpos:
  140|  2.78k|void buf_decrpos(buffer* buf, unsigned int decr) {
  141|  2.78k|	if (decr > buf->pos) {
  ------------------
  |  Branch (141:6): [True: 0, False: 2.78k]
  ------------------
  142|      0|		dropbear_exit("Bad buf_decrpos");
  143|      0|	}
  144|  2.78k|	buf->pos -= decr;
  145|  2.78k|}
buf_getbyte:
  148|  1.51k|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.51k|	if (buf->pos >= buf->len) {
  ------------------
  |  Branch (152:6): [True: 22, False: 1.49k]
  ------------------
  153|     22|		dropbear_exit("Bad buf_getbyte");
  154|     22|	}
  155|  1.49k|	return buf->data[buf->pos++];
  156|  1.51k|}
buf_putbyte:
  169|   175k|void buf_putbyte(buffer* buf, unsigned char val) {
  170|       |
  171|   175k|	if (buf->pos >= buf->len) {
  ------------------
  |  Branch (171:6): [True: 175k, False: 0]
  ------------------
  172|   175k|		buf_incrlen(buf, 1);
  173|   175k|	}
  174|   175k|	buf->data[buf->pos] = val;
  175|   175k|	buf->pos++;
  176|   175k|}
buf_getptr:
  180|  31.2k|unsigned char* buf_getptr(const buffer* buf, unsigned int len) {
  181|       |
  182|  31.2k|	if (len > BUF_MAX_INCR || buf->pos + len > buf->len) {
  ------------------
  |  |   34|  62.5k|#define BUF_MAX_INCR 1000000000
  ------------------
  |  Branch (182:6): [True: 0, False: 31.2k]
  |  Branch (182:28): [True: 387, False: 30.8k]
  ------------------
  183|    387|		dropbear_exit("Bad buf_getptr");
  184|    387|	}
  185|  30.8k|	return &buf->data[buf->pos];
  186|  31.2k|}
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.83k|char* buf_getstring(buffer* buf, unsigned int *retlen) {
  202|       |
  203|  6.83k|	unsigned int len;
  204|  6.83k|	char* ret;
  205|  6.83k|	void* src = NULL;
  206|  6.83k|	len = buf_getint(buf);
  207|  6.83k|	if (len > MAX_STRING_LEN) {
  ------------------
  |  |  228|  6.83k|#define MAX_STRING_LEN (MAX(MAX_CMD_LEN, 2400)) /* Sun SSH needs 2400 for algos,
  ------------------
  |  Branch (207:6): [True: 40, False: 6.79k]
  ------------------
  208|     40|		dropbear_exit("String too long");
  209|     40|	}
  210|       |
  211|  6.79k|	if (retlen != NULL) {
  ------------------
  |  Branch (211:6): [True: 6.70k, False: 90]
  ------------------
  212|  6.70k|		*retlen = len;
  213|  6.70k|	}
  214|  6.79k|	src = buf_getptr(buf, len);
  215|  6.79k|	ret = m_malloc(len+1);
  216|  6.79k|	memcpy(ret, src, len);
  217|  6.79k|	buf_incrpos(buf, len);
  218|  6.79k|	ret[len] = '\0';
  219|       |
  220|  6.79k|	return ret;
  221|  6.83k|}
buf_getstringbuf:
  246|    615|buffer * buf_getstringbuf(buffer *buf) {
  247|    615|	return buf_getstringbuf_int(buf, 0);
  248|    615|}
buf_getint:
  263|  15.0k|unsigned int buf_getint(buffer* buf) {
  264|  15.0k|	unsigned int ret;
  265|       |
  266|  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 - Ignored]
  |  |  ------------------
  ------------------
  267|  15.0k|	buf_incrpos(buf, 4);
  268|  15.0k|	return ret;
  269|  15.0k|}
buf_putint:
  272|     65|void buf_putint(buffer* buf, int unsigned val) {
  273|       |
  274|     65|	STORE32H(val, buf_getwriteptr(buf, 4));
  ------------------
  |  |   62|     65|#define STORE32H(x, y)                          \
  |  |   63|     65|do { ulong32 __t = __builtin_bswap32 ((x));     \
  |  |   64|     65|      XMEMCPY ((y), &__t, 4); } while(0)
  |  |  ------------------
  |  |  |  |   39|     65|#define XMEMCPY  memcpy
  |  |  ------------------
  |  |  |  Branch (64:39): [Folded - Ignored]
  |  |  ------------------
  ------------------
  275|     65|	buf_incrwritepos(buf, 4);
  276|       |
  277|     65|}
buf_putstring:
  280|      1|void buf_putstring(buffer* buf, const char* str, unsigned int len) {
  281|       |	
  282|      1|	buf_putint(buf, len);
  283|      1|	buf_putbytes(buf, (const unsigned char*)str, len);
  284|       |
  285|      1|}
buf_putbytes:
  294|    915|void buf_putbytes(buffer *buf, const unsigned char *bytes, unsigned int len) {
  295|    915|	memcpy(buf_getwriteptr(buf, len), bytes, len);
  296|    915|	buf_incrwritepos(buf, len);
  297|    915|}
buf_getmpint:
  347|  4.13k|int buf_getmpint(buffer* buf, mp_int* mp) {
  348|       |
  349|  4.13k|	unsigned int len;
  350|  4.13k|	len = buf_getint(buf);
  351|       |	
  352|  4.13k|	if (len == 0) {
  ------------------
  |  Branch (352:6): [True: 898, False: 3.24k]
  ------------------
  353|    898|		mp_zero(mp);
  354|    898|		return DROPBEAR_SUCCESS;
  ------------------
  |  |  102|    898|#define DROPBEAR_SUCCESS 0
  ------------------
  355|    898|	}
  356|       |
  357|  3.24k|	if (len > BUF_MAX_MPINT) {
  ------------------
  |  |   38|  3.24k|#define BUF_MAX_MPINT (8240 / 8)
  ------------------
  |  Branch (357:6): [True: 69, False: 3.17k]
  ------------------
  358|     69|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|     69|#define DROPBEAR_FAILURE -1
  ------------------
  359|     69|	}
  360|       |
  361|       |	/* check for negative */
  362|  3.17k|	if (*buf_getptr(buf, 1) & (1 << (CHAR_BIT-1))) {
  ------------------
  |  Branch (362:6): [True: 9, False: 3.16k]
  ------------------
  363|      9|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|      9|#define DROPBEAR_FAILURE -1
  ------------------
  364|      9|	}
  365|       |
  366|  3.16k|	if (mp_from_ubin(mp, buf_getptr(buf, len), len) != MP_OKAY) {
  ------------------
  |  |  161|  3.16k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (366:6): [True: 0, False: 3.16k]
  ------------------
  367|      0|		return DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
  368|      0|	}
  369|       |
  370|  3.16k|	buf_incrpos(buf, len);
  371|  3.16k|	return DROPBEAR_SUCCESS;
  ------------------
  |  |  102|  3.16k|#define DROPBEAR_SUCCESS 0
  ------------------
  372|  3.16k|}
buffer.c:buf_getstringbuf_int:
  224|    615|static buffer * buf_getstringbuf_int(buffer *buf, int incllen) {
  225|    615|	buffer *ret = NULL;
  226|    615|	unsigned int len = buf_getint(buf);
  227|    615|	int extra = 0;
  228|    615|	if (len > MAX_STRING_LEN) {
  ------------------
  |  |  228|    615|#define MAX_STRING_LEN (MAX(MAX_CMD_LEN, 2400)) /* Sun SSH needs 2400 for algos,
  ------------------
  |  Branch (228:6): [True: 29, False: 586]
  ------------------
  229|     29|		dropbear_exit("String too long");
  230|     29|	}
  231|    586|	if (incllen) {
  ------------------
  |  Branch (231:6): [True: 0, False: 586]
  ------------------
  232|      0|		extra = 4;
  233|      0|	}
  234|    586|	ret = buf_new(len+extra);
  235|    586|	if (incllen) {
  ------------------
  |  Branch (235:6): [True: 0, False: 586]
  ------------------
  236|      0|		buf_putint(ret, len);
  237|      0|	}
  238|    586|	memcpy(buf_getwriteptr(ret, len), buf_getptr(buf, len), len);
  239|    586|	buf_incrpos(buf, len);
  240|    586|	buf_incrlen(ret, len);
  241|    586|	buf_setpos(ret, 0);
  242|    586|	return ret;
  243|    615|}

crypto_init:
   21|      1|void crypto_init() {
   22|       |
   23|      1|	const struct ltc_cipher_descriptor *regciphers[] = {
   24|      1|#if DROPBEAR_AES
   25|      1|		&aes_desc,
   26|      1|#endif
   27|       |#if DROPBEAR_3DES
   28|       |		&des3_desc,
   29|       |#endif
   30|      1|		NULL
   31|      1|	};
   32|       |
   33|      1|	const struct ltc_hash_descriptor *reghashes[] = {
   34|      1|#if DROPBEAR_SHA1_HMAC
   35|      1|		&sha1_desc,
   36|      1|#endif
   37|      1|#if DROPBEAR_SHA256
   38|      1|		&sha256_desc,
   39|      1|#endif
   40|      1|#if DROPBEAR_SHA384
   41|      1|		&sha384_desc,
   42|      1|#endif
   43|      1|#if DROPBEAR_SHA512
   44|      1|		&sha512_desc,
   45|      1|#endif
   46|      1|		NULL
   47|      1|	};
   48|      1|	int i;
   49|       |
   50|      2|	for (i = 0; regciphers[i] != NULL; i++) {
  ------------------
  |  Branch (50:14): [True: 1, False: 1]
  ------------------
   51|      1|		if (register_cipher(regciphers[i]) == -1) {
  ------------------
  |  Branch (51:7): [True: 0, False: 1]
  ------------------
   52|      0|			dropbear_exit("Error registering crypto");
   53|      0|		}
   54|      1|	}
   55|       |
   56|      5|	for (i = 0; reghashes[i] != NULL; i++) {
  ------------------
  |  Branch (56:14): [True: 4, False: 1]
  ------------------
   57|      4|		if (register_hash(reghashes[i]) == -1) {
  ------------------
  |  Branch (57:7): [True: 0, False: 4]
  ------------------
   58|      0|			dropbear_exit("Error registering crypto");
   59|      0|		}
   60|      4|	}
   61|       |
   62|      1|#if DROPBEAR_LTC_PRNG
   63|      1|	dropbear_ltc_prng = register_prng(&dropbear_prng_desc);
   64|      1|	if (dropbear_ltc_prng == -1) {
  ------------------
  |  Branch (64:6): [True: 0, False: 1]
  ------------------
   65|      0|		dropbear_exit("Error registering crypto");
   66|      0|	}
   67|      1|#endif
   68|       |
   69|      1|	mp_rand_source(dropbear_rand_source);
   70|       |
   71|      1|#if DROPBEAR_ECC
   72|      1|	ltc_mp = ltm_desc;
   73|      1|	dropbear_ecc_fill_dp();
   74|      1|#endif
   75|      1|}
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:
  466|     80|{
  467|     80|  hash_state hs;
  468|     80|  u8 t[32],h[64];
  469|     80|  gf p[4],q[4];
  470|       |
  471|     80|  if (slen < 64) return -1;
  ------------------
  |  Branch (471:7): [True: 0, False: 80]
  ------------------
  472|       |
  473|     80|  if (unpackneg(q,pk)) return -1;
  ------------------
  |  Branch (473:7): [True: 27, False: 53]
  ------------------
  474|       |
  475|     53|  sha512_init(&hs);
  476|     53|  sha512_process(&hs,s,32);
  477|     53|  sha512_process(&hs,pk,32);
  478|     53|  sha512_process(&hs,m,mlen);
  479|     53|  sha512_done(&hs,h);
  480|       |
  481|     53|  reduce(h);
  482|     53|  scalarmult(p,q,h);
  483|       |
  484|     53|  scalarbase(q,s + 32);
  485|     53|  add(p,q);
  486|     53|  pack(t,p);
  487|       |
  488|     53|  if (crypto_verify_32(s, t))
  ------------------
  |  Branch (488:7): [True: 51, False: 2]
  ------------------
  489|     51|    return -1;
  490|       |
  491|      2|  return 0;
  492|     53|}
curve25519.c:unpack25519:
  150|     80|{
  151|     80|  int i;
  152|  1.28k|  FOR(i,16) o[i]=n[2*i]+((i64)n[2*i+1]<<8);
  ------------------
  |  |   34|  1.36k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 1.28k, False: 80]
  |  |  ------------------
  ------------------
  153|     80|  o[15]&=0x7fff;
  154|     80|}
curve25519.c:sel25519:
   96|   218k|{
   97|   218k|  i64 t,i,c=~(b-1);
   98|  3.48M|  FOR(i,16) {
  ------------------
  |  |   34|  3.70M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 3.48M, False: 218k]
  |  |  ------------------
  ------------------
   99|  3.48M|    t= c&(p[i]^q[i]);
  100|  3.48M|    p[i]^=t;
  101|  3.48M|    q[i]^=t;
  102|  3.48M|  }
  103|   218k|}
curve25519.c:A:
  157|   271k|{
  158|   271k|  int i;
  159|  4.34M|  FOR(i,16) o[i]=a[i]+b[i];
  ------------------
  |  |   34|  4.61M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 4.34M, False: 271k]
  |  |  ------------------
  ------------------
  160|   271k|}
curve25519.c:Z:
  163|   217k|{
  164|   217k|  int i;
  165|  3.47M|  FOR(i,16) o[i]=a[i]-b[i];
  ------------------
  |  |   34|  3.69M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 3.47M, False: 217k]
  |  |  ------------------
  ------------------
  166|   217k|}
curve25519.c:S:
  180|  33.9k|{
  181|  33.9k|  M(o,a,a);
  182|  33.9k|}
curve25519.c:M:
  169|   557k|{
  170|   557k|  i64 i,j,t[31];
  171|  17.2M|  FOR(i,31) t[i]=0;
  ------------------
  |  |   34|  17.8M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 17.2M, False: 557k]
  |  |  ------------------
  ------------------
  172|   142M|  FOR(i,16) FOR(j,16) t[i+j]+=a[i]*b[j];
  ------------------
  |  |   34|  9.47M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 8.91M, False: 557k]
  |  |  ------------------
  ------------------
                FOR(i,16) FOR(j,16) t[i+j]+=a[i]*b[j];
  ------------------
  |  |   34|   151M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 142M, False: 8.91M]
  |  |  ------------------
  ------------------
  173|  8.35M|  FOR(i,15) t[i]+=38*t[i+16];
  ------------------
  |  |   34|  8.91M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 8.35M, False: 557k]
  |  |  ------------------
  ------------------
  174|  8.91M|  FOR(i,16) o[i]=t[i];
  ------------------
  |  |   34|  9.47M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 8.91M, False: 557k]
  |  |  ------------------
  ------------------
  175|   557k|  car25519(o);
  176|   557k|  car25519(o);
  177|   557k|}
curve25519.c:car25519:
   84|  1.11M|{
   85|  1.11M|  int i;
   86|  1.11M|  i64 c;
   87|  17.8M|  FOR(i,16) {
  ------------------
  |  |   34|  18.9M|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 17.8M, False: 1.11M]
  |  |  ------------------
  ------------------
   88|  17.8M|    o[i]+=(1LL<<16);
   89|  17.8M|    c=o[i]>>16;
   90|  17.8M|    o[(i+1)*(i<15)]+=c-1+37*(c-1)*(i==15);
   91|  17.8M|    o[i]-=c<<16;
   92|  17.8M|  }
   93|  1.11M|}
curve25519.c:inv25519:
  185|     53|{
  186|     53|  gf c;
  187|     53|  int a;
  188|    848|  FOR(a,16) c[a]=i[a];
  ------------------
  |  |   34|    901|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 848, False: 53]
  |  |  ------------------
  ------------------
  189|  13.5k|  for(a=253;a>=0;a--) {
  ------------------
  |  Branch (189:13): [True: 13.4k, False: 53]
  ------------------
  190|  13.4k|    S(c,c);
  191|  13.4k|    if(a!=2&&a!=4) M(c,c,i);
  ------------------
  |  Branch (191:8): [True: 13.4k, False: 53]
  |  Branch (191:14): [True: 13.3k, False: 53]
  ------------------
  192|  13.4k|  }
  193|    848|  FOR(a,16) o[a]=c[a];
  ------------------
  |  |   34|    901|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 848, False: 53]
  |  |  ------------------
  ------------------
  194|     53|}
curve25519.c:pack25519:
  106|    479|{
  107|    479|  int i,j,b;
  108|    479|  gf m,t;
  109|  7.66k|  FOR(i,16) t[i]=n[i];
  ------------------
  |  |   34|  8.14k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 7.66k, False: 479]
  |  |  ------------------
  ------------------
  110|    479|  car25519(t);
  111|    479|  car25519(t);
  112|    479|  car25519(t);
  113|    958|  FOR(j,2) {
  ------------------
  |  |   34|  1.43k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 958, False: 479]
  |  |  ------------------
  ------------------
  114|    958|    m[0]=t[0]-0xffed;
  115|  14.3k|    for(i=1;i<15;i++) {
  ------------------
  |  Branch (115:13): [True: 13.4k, False: 958]
  ------------------
  116|  13.4k|      m[i]=t[i]-0xffff-((m[i-1]>>16)&1);
  117|  13.4k|      m[i-1]&=0xffff;
  118|  13.4k|    }
  119|    958|    m[15]=t[15]-0x7fff-((m[14]>>16)&1);
  120|    958|    b=(m[15]>>16)&1;
  121|    958|    m[14]&=0xffff;
  122|    958|    sel25519(t,m,1-b);
  123|    958|  }
  124|  7.66k|  FOR(i,16) {
  ------------------
  |  |   34|  8.14k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 7.66k, False: 479]
  |  |  ------------------
  ------------------
  125|  7.66k|    o[2*i]=t[i]&0xff;
  126|  7.66k|    o[2*i+1]=t[i]>>8;
  127|  7.66k|  }
  128|    479|}
curve25519.c:scalarbase:
  331|     53|{
  332|     53|  gf q[4];
  333|     53|  set25519(q[0],X);
  334|     53|  set25519(q[1],Y);
  335|     53|  set25519(q[2],gf1);
  336|     53|  M(q[3],X,Y);
  337|     53|  scalarmult(p,q,s);
  338|     53|}
curve25519.c:set25519:
   77|    663|{
   78|    663|  int i;
   79|  10.6k|  FOR(i,16) r[i]=a[i];
  ------------------
  |  |   34|  11.2k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 10.6k, False: 663]
  |  |  ------------------
  ------------------
   80|    663|}
curve25519.c:pack:
  305|     53|{
  306|     53|  gf tx, ty, zi;
  307|     53|  inv25519(zi, p[2]); 
  308|     53|  M(tx, p[0], zi);
  309|     53|  M(ty, p[1], zi);
  310|     53|  pack25519(r, ty);
  311|     53|  r[31] ^= par25519(tx) << 7;
  312|     53|}
curve25519.c:par25519:
  142|    106|{
  143|    106|  u8 d[32];
  144|    106|  pack25519(d,a);
  145|    106|  return d[0]&1;
  146|    106|}
curve25519.c:reduce:
  385|     53|{
  386|     53|  i64 x[64],i;
  387|  3.39k|  FOR(i,64) x[i] = (u64) r[i];
  ------------------
  |  |   34|  3.44k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 3.39k, False: 53]
  |  |  ------------------
  ------------------
  388|  3.39k|  FOR(i,64) r[i] = 0;
  ------------------
  |  |   34|  3.44k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 3.39k, False: 53]
  |  |  ------------------
  ------------------
  389|     53|  modL(r,x);
  390|     53|}
curve25519.c:modL:
  359|     53|{
  360|     53|  i64 carry,i,j;
  361|  1.74k|  for (i = 63;i >= 32;--i) {
  ------------------
  |  Branch (361:15): [True: 1.69k, False: 53]
  ------------------
  362|  1.69k|    carry = 0;
  363|  35.6k|    for (j = i - 32;j < i - 12;++j) {
  ------------------
  |  Branch (363:21): [True: 33.9k, False: 1.69k]
  ------------------
  364|  33.9k|      x[j] += carry - 16 * x[i] * L[j - (i - 32)];
  365|  33.9k|      carry = (x[j] + 128) >> 8;
  366|  33.9k|      x[j] -= carry << 8;
  367|  33.9k|    }
  368|  1.69k|    x[j] += carry;
  369|  1.69k|    x[i] = 0;
  370|  1.69k|  }
  371|     53|  carry = 0;
  372|  1.69k|  FOR(j,32) {
  ------------------
  |  |   34|  1.74k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 1.69k, False: 53]
  |  |  ------------------
  ------------------
  373|  1.69k|    x[j] += carry - (x[31] >> 4) * L[j];
  374|  1.69k|    carry = x[j] >> 8;
  375|  1.69k|    x[j] &= 255;
  376|  1.69k|  }
  377|  1.69k|  FOR(j,32) x[j] -= carry * L[j];
  ------------------
  |  |   34|  1.74k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 1.69k, False: 53]
  |  |  ------------------
  ------------------
  378|  1.69k|  FOR(i,32) {
  ------------------
  |  |   34|  1.74k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 1.69k, False: 53]
  |  |  ------------------
  ------------------
  379|  1.69k|    x[i+1] += x[i] >> 8;
  380|  1.69k|    r[i] = x[i] & 255;
  381|  1.69k|  }
  382|     53|}
curve25519.c:unpackneg:
  430|     80|{
  431|     80|  gf t, chk, num, den, den2, den4, den6;
  432|     80|  set25519(r[2],gf1);
  433|     80|  unpack25519(r[1],p);
  434|     80|  S(num,r[1]);
  435|     80|  M(den,num,D);
  436|     80|  Z(num,num,r[2]);
  437|     80|  A(den,r[2],den);
  438|       |
  439|     80|  S(den2,den);
  440|     80|  S(den4,den2);
  441|     80|  M(den6,den4,den2);
  442|     80|  M(t,den6,num);
  443|     80|  M(t,t,den);
  444|       |
  445|     80|  pow2523(t,t);
  446|     80|  M(t,t,num);
  447|     80|  M(t,t,den);
  448|     80|  M(t,t,den);
  449|     80|  M(r[0],t,den);
  450|       |
  451|     80|  S(chk,r[0]);
  452|     80|  M(chk,chk,den);
  453|     80|  if (neq25519(chk, num)) M(r[0],r[0],I);
  ------------------
  |  Branch (453:7): [True: 56, False: 24]
  ------------------
  454|       |
  455|     80|  S(chk,r[0]);
  456|     80|  M(chk,chk,den);
  457|     80|  if (neq25519(chk, num)) return -1;
  ------------------
  |  Branch (457:7): [True: 27, False: 53]
  ------------------
  458|       |
  459|     53|  if (par25519(r[0]) == (p[31]>>7)) Z(r[0],gf0,r[0]);
  ------------------
  |  Branch (459:7): [True: 28, False: 25]
  ------------------
  460|       |
  461|     53|  M(r[3],r[0],r[1]);
  462|     53|  return 0;
  463|     80|}
curve25519.c:pow2523:
  198|     80|{
  199|     80|  gf c;
  200|     80|  int a;
  201|  1.28k|  FOR(a,16) c[a]=i[a];
  ------------------
  |  |   34|  1.36k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 1.28k, False: 80]
  |  |  ------------------
  ------------------
  202|  20.1k|  for(a=250;a>=0;a--) {
  ------------------
  |  Branch (202:13): [True: 20.0k, False: 80]
  ------------------
  203|  20.0k|    S(c,c);
  204|  20.0k|    if(a!=1) M(c,c,i);
  ------------------
  |  Branch (204:8): [True: 20.0k, False: 80]
  ------------------
  205|  20.0k|  }
  206|  1.28k|  FOR(a,16) o[a]=c[a];
  ------------------
  |  |   34|  1.36k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 1.28k, False: 80]
  |  |  ------------------
  ------------------
  207|     80|}
curve25519.c:neq25519:
  133|    160|{
  134|    160|  u8 c[32],d[32];
  135|    160|  pack25519(c,a);
  136|    160|  pack25519(d,b);
  137|    160|  return crypto_verify_32(c,d);
  138|    160|}
curve25519.c:scalarmult:
  315|    106|{
  316|    106|  int i;
  317|    106|  set25519(p[0],gf0);
  318|    106|  set25519(p[1],gf1);
  319|    106|  set25519(p[2],gf1);
  320|    106|  set25519(p[3],gf0);
  321|  27.2k|  for (i = 255;i >= 0;--i) {
  ------------------
  |  Branch (321:16): [True: 27.1k, False: 106]
  ------------------
  322|  27.1k|    u8 b = (s[i/8]>>(i&7))&1;
  323|  27.1k|    cswap(p,q,b);
  324|  27.1k|    add(q,p);
  325|  27.1k|    add(p,p);
  326|  27.1k|    cswap(p,q,b);
  327|  27.1k|  }
  328|    106|}
curve25519.c:cswap:
  298|  54.2k|{
  299|  54.2k|  int i;
  300|  54.2k|  FOR(i,4)
  ------------------
  |  |   34|   271k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 217k, False: 54.2k]
  |  |  ------------------
  ------------------
  301|   217k|    sel25519(p[i],q[i],b);
  302|  54.2k|}
curve25519.c:add:
  273|  54.3k|{
  274|  54.3k|  gf a,b,c,d,t,e,f,g,h;
  275|       |  
  276|  54.3k|  Z(a, p[1], p[0]);
  277|  54.3k|  Z(t, q[1], q[0]);
  278|  54.3k|  M(a, a, t);
  279|  54.3k|  A(b, p[0], p[1]);
  280|  54.3k|  A(t, q[0], q[1]);
  281|  54.3k|  M(b, b, t);
  282|  54.3k|  M(c, p[3], q[3]);
  283|  54.3k|  M(c, c, D2);
  284|  54.3k|  M(d, p[2], q[2]);
  285|  54.3k|  A(d, d, d);
  286|  54.3k|  Z(e, b, a);
  287|  54.3k|  Z(f, d, c);
  288|  54.3k|  A(g, d, c);
  289|  54.3k|  A(h, b, a);
  290|       |
  291|  54.3k|  M(p[0], e, f);
  292|  54.3k|  M(p[1], h, g);
  293|  54.3k|  M(p[2], g, f);
  294|  54.3k|  M(p[3], e, h);
  295|  54.3k|}
curve25519.c:crypto_verify_32:
   71|    213|{
   72|    213|  return vn(x,y,32);
   73|    213|}
curve25519.c:vn:
   64|    213|{
   65|    213|  u32 i,d = 0;
   66|  6.81k|  FOR(i,n) d |= x[i]^y[i];
  ------------------
  |  |   34|  7.02k|#define FOR(i,n) for (i = 0;i < n;++i)
  |  |  ------------------
  |  |  |  Branch (34:29): [True: 6.81k, False: 213]
  |  |  ------------------
  ------------------
   67|    213|  return (1 & ((d - 1) >> 8)) - 1;
   68|    213|}

m_burn:
    5|  4.45k|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|  4.45k|	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.45k|}

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

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

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

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

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

signkey_is_ecdsa:
   11|  3.07k|{
   12|  3.07k|	return type == DROPBEAR_SIGNKEY_ECDSA_NISTP256
  ------------------
  |  Branch (12:9): [True: 614, False: 2.46k]
  ------------------
   13|  3.07k|		|| type == DROPBEAR_SIGNKEY_ECDSA_NISTP384
  ------------------
  |  Branch (13:6): [True: 147, False: 2.31k]
  ------------------
   14|  3.07k|		|| type == DROPBEAR_SIGNKEY_ECDSA_NISTP521;
  ------------------
  |  Branch (14:6): [True: 169, False: 2.14k]
  ------------------
   15|  3.07k|}
buf_get_ecdsa_pub_key:
   77|    746|ecc_key *buf_get_ecdsa_pub_key(buffer* buf) {
   78|    746|	unsigned char *key_ident = NULL, *identifier = NULL;
   79|    746|	unsigned int key_ident_len, identifier_len;
   80|    746|	buffer *q_buf = NULL;
   81|    746|	struct dropbear_ecc_curve **curve;
   82|    746|	ecc_key *new_key = NULL;
   83|       |
   84|       |	/* string   "ecdsa-sha2-[identifier]" or "sk-ecdsa-sha2-nistp256@openssh.com" */
   85|    746|	key_ident = (unsigned char*)buf_getstring(buf, &key_ident_len);
   86|       |	/* string   "[identifier]" */
   87|    746|	identifier = (unsigned char*)buf_getstring(buf, &identifier_len);
   88|       |
   89|    746|	if (strcmp (key_ident, "sk-ecdsa-sha2-nistp256@openssh.com") == 0) {
  ------------------
  |  Branch (89:6): [True: 94, False: 652]
  ------------------
   90|     94|		if (strcmp (identifier, "nistp256") != 0) {
  ------------------
  |  Branch (90:7): [True: 76, False: 18]
  ------------------
   91|     76|			TRACE(("mismatching identifiers"))
   92|     76|			goto out;
   93|     76|		}
   94|    652|	} else {
   95|    652|		if (key_ident_len != identifier_len + strlen ("ecdsa-sha2-")) {
  ------------------
  |  Branch (95:7): [True: 33, False: 619]
  ------------------
   96|     33|			TRACE(("Bad identifier lengths"))
   97|     33|			goto out;
   98|     33|		}
   99|    619|		if (memcmp(&key_ident[strlen ("ecdsa-sha2-")], identifier, identifier_len) != 0) {
  ------------------
  |  Branch (99:7): [True: 18, False: 601]
  ------------------
  100|     18|			TRACE(("mismatching identifiers"))
  101|     18|			goto out;
  102|     18|		}
  103|    619|	}
  104|       |
  105|    895|	for (curve = dropbear_ecc_curves; *curve; curve++) {
  ------------------
  |  Branch (105:36): [True: 891, False: 4]
  ------------------
  106|    891|		if (memcmp(identifier, (char*)(*curve)->name, strlen((char*)(*curve)->name)) == 0) {
  ------------------
  |  Branch (106:7): [True: 615, False: 276]
  ------------------
  107|    615|			break;
  108|    615|		}
  109|    891|	}
  110|    619|	if (!*curve) {
  ------------------
  |  Branch (110:6): [True: 0, False: 619]
  ------------------
  111|      0|		TRACE(("couldn't match ecc curve"))
  112|      0|		goto out;
  113|      0|	}
  114|       |
  115|       |	/* string Q */
  116|    619|	q_buf = buf_getstringbuf(buf);
  117|    619|	new_key = buf_get_ecc_raw_pubkey(q_buf, *curve);
  118|       |
  119|    663|out:
  120|    663|	m_free(key_ident);
  ------------------
  |  |   24|    663|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  121|    663|	m_free(identifier);
  ------------------
  |  |   24|    663|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  122|    663|	if (q_buf) {
  ------------------
  |  Branch (122:6): [True: 536, False: 127]
  ------------------
  123|    536|		buf_free(q_buf);
  124|    536|		q_buf = NULL;
  125|    536|	}
  126|    663|	TRACE(("leave buf_get_ecdsa_pub_key"))	
  127|    663|	return new_key;
  128|    619|}
buf_ecdsa_verify:
  281|    279|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|    279|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  103|    279|#define DROPBEAR_FAILURE -1
  ------------------
  284|    279|	hash_state hs;
  285|    279|	struct dropbear_ecc_curve *curve = NULL;
  286|    279|	unsigned char hash[64];
  287|    279|	ecc_point *mG = NULL, *mQ = NULL;
  288|    279|	void *r = NULL, *s = NULL, *v = NULL, *w = NULL, *u1 = NULL, *u2 = NULL, 
  289|    279|		*e = NULL, *p = NULL, *m = NULL;
  290|    279|	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|    279|	TRACE(("buf_ecdsa_verify"))
  303|    279|	curve = curve_for_dp(key->dp);
  304|       |
  305|    279|	mG = ltc_ecc_new_point();
  306|    279|	mQ = ltc_ecc_new_point();
  307|    279|	if (ltc_init_multi(&r, &s, &v, &w, &u1, &u2, &p, &e, &m, NULL) != CRYPT_OK
  ------------------
  |  Branch (307:6): [True: 0, False: 279]
  ------------------
  308|    279|		|| !mG
  ------------------
  |  Branch (308:6): [True: 0, False: 279]
  ------------------
  309|    279|		|| !mQ) {
  ------------------
  |  Branch (309:6): [True: 0, False: 279]
  ------------------
  310|      0|		dropbear_exit("ECC error");
  311|      0|	}
  312|       |
  313|    279|	if (buf_get_ecdsa_verify_params(buf, r, s) != DROPBEAR_SUCCESS) {
  ------------------
  |  |  102|    279|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (313:6): [True: 42, False: 237]
  ------------------
  314|     42|		goto out;
  315|     42|	}
  316|       |
  317|    237|	curve->hash_desc->init(&hs);
  318|    237|	curve->hash_desc->process(&hs, data_buf->data, data_buf->len);
  319|    237|	curve->hash_desc->done(&hs, hash);
  320|       |
  321|    237|	if (ltc_mp.unsigned_read(e, hash, curve->hash_desc->hashsize) != CRYPT_OK) {
  ------------------
  |  Branch (321:6): [True: 0, False: 237]
  ------------------
  322|      0|		goto out;
  323|      0|	}
  324|       |
  325|       |   /* get the order */
  326|    237|	if (ltc_mp.read_radix(p, (char *)key->dp->order, 16) != CRYPT_OK) { 
  ------------------
  |  Branch (326:6): [True: 0, False: 237]
  ------------------
  327|      0|		goto out; 
  328|      0|	}
  329|       |
  330|       |   /* get the modulus */
  331|    237|	if (ltc_mp.read_radix(m, (char *)key->dp->prime, 16) != CRYPT_OK) { 
  ------------------
  |  Branch (331:6): [True: 0, False: 237]
  ------------------
  332|      0|		goto out; 
  333|      0|	}
  334|       |
  335|       |   /* check for zero */
  336|    237|	if (ltc_mp.compare_d(r, 0) == LTC_MP_EQ 
  ------------------
  |  |   13|    474|#define LTC_MP_EQ    0
  ------------------
  |  Branch (336:6): [True: 7, False: 230]
  ------------------
  337|    237|		|| ltc_mp.compare_d(s, 0) == LTC_MP_EQ 
  ------------------
  |  |   13|    467|#define LTC_MP_EQ    0
  ------------------
  |  Branch (337:6): [True: 1, False: 229]
  ------------------
  338|    237|		|| ltc_mp.compare(r, p) != LTC_MP_LT 
  ------------------
  |  |   12|    466|#define LTC_MP_LT   -1
  ------------------
  |  Branch (338:6): [True: 1, False: 228]
  ------------------
  339|    237|		|| ltc_mp.compare(s, p) != LTC_MP_LT) {
  ------------------
  |  |   12|    228|#define LTC_MP_LT   -1
  ------------------
  |  Branch (339:6): [True: 1, False: 227]
  ------------------
  340|      6|		goto out;
  341|      6|	}
  342|       |
  343|       |   /*  w  = s^-1 mod n */
  344|    231|	if (ltc_mp.invmod(s, p, w) != CRYPT_OK) { 
  ------------------
  |  Branch (344:6): [True: 0, False: 231]
  ------------------
  345|      0|		goto out; 
  346|      0|	}
  347|       |
  348|       |   /* u1 = ew */
  349|    231|	if (ltc_mp.mulmod(e, w, p, u1) != CRYPT_OK) { 
  ------------------
  |  Branch (349:6): [True: 0, False: 231]
  ------------------
  350|      0|		goto out; 
  351|      0|	}
  352|       |
  353|       |   /* u2 = rw */
  354|    231|	if (ltc_mp.mulmod(r, w, p, u2) != CRYPT_OK) { 
  ------------------
  |  Branch (354:6): [True: 0, False: 231]
  ------------------
  355|      0|		goto out; 
  356|      0|	}
  357|       |
  358|       |   /* find mG and mQ */
  359|    231|	if (ltc_mp.read_radix(mG->x, (char *)key->dp->Gx, 16) != CRYPT_OK) { 
  ------------------
  |  Branch (359:6): [True: 0, False: 231]
  ------------------
  360|      0|		goto out; 
  361|      0|	}
  362|    231|	if (ltc_mp.read_radix(mG->y, (char *)key->dp->Gy, 16) != CRYPT_OK) { 
  ------------------
  |  Branch (362:6): [True: 0, False: 231]
  ------------------
  363|      0|		goto out; 
  364|      0|	}
  365|    231|	if (ltc_mp.set_int(mG->z, 1) != CRYPT_OK) { 
  ------------------
  |  Branch (365:6): [True: 0, False: 231]
  ------------------
  366|      0|		goto out; 
  367|      0|	}
  368|       |
  369|    231|	if (ltc_mp.copy(key->pubkey.x, mQ->x) != CRYPT_OK
  ------------------
  |  Branch (369:6): [True: 4, False: 227]
  ------------------
  370|    231|		|| ltc_mp.copy(key->pubkey.y, mQ->y) != CRYPT_OK
  ------------------
  |  Branch (370:6): [True: 0, False: 227]
  ------------------
  371|    231|		|| ltc_mp.copy(key->pubkey.z, mQ->z) != CRYPT_OK) { 
  ------------------
  |  Branch (371:6): [True: 0, False: 227]
  ------------------
  372|      0|		goto out; 
  373|      0|	}
  374|       |
  375|       |   /* compute u1*mG + u2*mQ = mG */
  376|    231|	if (ltc_mp.ecc_mul2add == NULL) {
  ------------------
  |  Branch (376:6): [True: 0, False: 231]
  ------------------
  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|    231|	} else {
  399|       |		/* use Shamir's trick to compute u1*mG + u2*mQ using half of the doubles */
  400|    231|		if (ltc_mp.ecc_mul2add(mG, u1, mQ, u2, mG, m) != CRYPT_OK) { 
  ------------------
  |  Branch (400:7): [True: 0, False: 231]
  ------------------
  401|      0|			goto out; 
  402|      0|		}
  403|    231|	}
  404|       |
  405|       |   /* v = X_x1 mod n */
  406|    231|	if (ltc_mp.mpdiv(mG->x, p, NULL, v) != CRYPT_OK) { 
  ------------------
  |  Branch (406:6): [True: 0, False: 231]
  ------------------
  407|      0|		goto out; 
  408|      0|	}
  409|       |
  410|       |   /* does v == r */
  411|    231|	if (ltc_mp.compare(v, r) == LTC_MP_EQ) {
  ------------------
  |  |   13|    231|#define LTC_MP_EQ    0
  ------------------
  |  Branch (411:6): [True: 0, False: 231]
  ------------------
  412|      0|		ret = DROPBEAR_SUCCESS;
  ------------------
  |  |  102|      0|#define DROPBEAR_SUCCESS 0
  ------------------
  413|      0|	}
  414|       |
  415|    275|out:
  416|    275|	ltc_ecc_del_point(mG);
  417|    275|	ltc_ecc_del_point(mQ);
  418|    275|	ltc_deinit_multi(r, s, v, w, u1, u2, p, e, m, NULL);
  419|    275|	if (mp != NULL) { 
  ------------------
  |  Branch (419:6): [True: 0, False: 275]
  ------------------
  420|      0|		ltc_mp.montgomery_deinit(mp);
  421|      0|	}
  422|    275|	return ret;
  423|    231|}
ecdsa.c:buf_get_ecdsa_verify_params:
  258|    279|			void *r, void* s) {
  259|    279|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  103|    279|#define DROPBEAR_FAILURE -1
  ------------------
  260|    279|	unsigned int sig_len;
  261|    279|	unsigned int sig_pos;
  262|       |
  263|    279|	sig_len = buf_getint(buf);
  264|    279|	sig_pos = buf->pos;
  265|    279|	if (buf_getmpint(buf, r) != DROPBEAR_SUCCESS) {
  ------------------
  |  |  102|    279|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (265:6): [True: 3, False: 276]
  ------------------
  266|      3|		goto out;
  267|      3|	}
  268|    276|	if (buf_getmpint(buf, s) != DROPBEAR_SUCCESS) {
  ------------------
  |  |  102|    276|#define DROPBEAR_SUCCESS 0
  ------------------
  |  Branch (268:6): [True: 1, False: 275]
  ------------------
  269|      1|		goto out;
  270|      1|	}
  271|    275|	if (buf->pos - sig_pos != sig_len) {
  ------------------
  |  Branch (271:6): [True: 38, False: 237]
  ------------------
  272|     38|		goto out;
  273|     38|	}
  274|    237|	ret = DROPBEAR_SUCCESS;
  ------------------
  |  |  102|    237|#define DROPBEAR_SUCCESS 0
  ------------------
  275|       |
  276|    275|out:
  277|    275|	return ret;
  278|    237|}

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

buf_get_rsa_pub_key:
   53|  1.18k|int buf_get_rsa_pub_key(buffer* buf, dropbear_rsa_key *key) {
   54|       |
   55|  1.18k|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  103|  1.18k|#define DROPBEAR_FAILURE -1
  ------------------
   56|  1.18k|	TRACE(("enter buf_get_rsa_pub_key"))
   57|  1.18k|	dropbear_assert(key != NULL);
  ------------------
  |  |   83|  1.18k|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 1.18k]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
   58|  1.18k|	m_mp_alloc_init_multi(&key->e, &key->n, NULL);
   59|  1.18k|	key->d = NULL;
   60|  1.18k|	key->p = NULL;
   61|  1.18k|	key->q = NULL;
   62|       |
   63|  1.18k|	buf_incrpos(buf, 4+SSH_SIGNKEY_RSA_LEN); /* int + "ssh-rsa" */
  ------------------
  |  |  113|  1.18k|#define SSH_SIGNKEY_RSA_LEN 7
  ------------------
   64|       |
   65|  1.18k|	if (buf_getmpint(buf, key->e) == DROPBEAR_FAILURE
  ------------------
  |  |  103|  2.37k|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (65:6): [True: 82, False: 1.10k]
  ------------------
   66|  1.18k|	 || buf_getmpint(buf, key->n) == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|  1.10k|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (66:6): [True: 111, False: 996]
  ------------------
   67|     48|		TRACE(("leave buf_get_rsa_pub_key: failure"))
   68|     48|		goto out;
   69|     48|	}
   70|       |
   71|  1.14k|	if (mp_count_bits(key->n) < MIN_RSA_KEYLEN) {
  ------------------
  |  |   65|  1.14k|#define MIN_RSA_KEYLEN 1024
  ------------------
  |  Branch (71:6): [True: 83, False: 1.05k]
  ------------------
   72|     83|		dropbear_log(LOG_WARNING, "RSA key too short");
   73|     83|		goto out;
   74|     83|	}
   75|       |
   76|       |	/* 64 bit is limit used by openssl, so we won't block any keys in the wild */
   77|  1.05k|	if (mp_count_bits(key->e) > 64) {
  ------------------
  |  Branch (77:6): [True: 1, False: 1.05k]
  ------------------
   78|      1|		dropbear_log(LOG_WARNING, "RSA key bad e");
   79|      1|		goto out;
   80|      1|	}
   81|       |
   82|  1.05k|	TRACE(("leave buf_get_rsa_pub_key: success"))
   83|  1.05k|	ret = DROPBEAR_SUCCESS;
  ------------------
  |  |  102|  1.05k|#define DROPBEAR_SUCCESS 0
  ------------------
   84|  1.05k|out:
   85|  1.04k|	if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|  1.04k|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (85:6): [True: 132, False: 912]
  ------------------
   86|    132|		m_mp_free_multi(&key->e, &key->n, NULL);
   87|    132|	}
   88|  1.04k|	return ret;
   89|  1.05k|}
rsa_key_free:
  142|  3.61k|void rsa_key_free(dropbear_rsa_key *key) {
  143|       |
  144|  3.61k|	TRACE2(("enter rsa_key_free"))
  145|       |
  146|  3.61k|	if (key == NULL) {
  ------------------
  |  Branch (146:6): [True: 2.60k, False: 1.00k]
  ------------------
  147|  2.60k|		TRACE2(("leave rsa_key_free: key == NULL"))
  148|  2.60k|		return;
  149|  2.60k|	}
  150|  1.00k|	m_mp_free_multi(&key->d, &key->e, &key->p, &key->q, &key->n, NULL);
  151|  1.00k|	m_free(key);
  ------------------
  |  |   24|  1.00k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  152|  1.00k|	TRACE2(("leave rsa_key_free"))
  153|  1.00k|}
buf_rsa_verify:
  200|    876|		enum signature_type sigtype, const buffer *data_buf) {
  201|    876|	unsigned int slen;
  202|    876|	DEF_MP_INT(rsa_s);
  ------------------
  |  |   80|    876|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  203|    876|	DEF_MP_INT(rsa_mdash);
  ------------------
  |  |   80|    876|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  204|    876|	DEF_MP_INT(rsa_em);
  ------------------
  |  |   80|    876|#define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}
  ------------------
  205|    876|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  103|    876|#define DROPBEAR_FAILURE -1
  ------------------
  206|       |
  207|    876|	TRACE(("enter buf_rsa_verify"))
  208|       |
  209|    876|	dropbear_assert(key != NULL);
  ------------------
  |  |   83|    876|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 876]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
  210|       |
  211|    876|	m_mp_init_multi(&rsa_mdash, &rsa_s, &rsa_em, NULL);
  212|       |
  213|    876|	slen = buf_getint(buf);
  214|    876|	if (slen != (unsigned int)mp_ubin_size(key->n)) {
  ------------------
  |  Branch (214:6): [True: 47, False: 829]
  ------------------
  215|     47|		TRACE(("bad size"))
  216|     47|		goto out;
  217|     47|	}
  218|       |
  219|    829|	if (mp_from_ubin(&rsa_s, buf_getptr(buf, buf->len - buf->pos),
  ------------------
  |  Branch (219:6): [True: 0, False: 829]
  ------------------
  220|    829|				buf->len - buf->pos) != MP_OKAY) {
  ------------------
  |  |  161|    829|#define MP_OKAY       0   /* no error */
  ------------------
  221|      0|		TRACE(("failed reading rsa_s"))
  222|      0|		goto out;
  223|      0|	}
  224|       |
  225|       |	/* check that s <= n-1 */
  226|    829|	if (mp_cmp(&rsa_s, key->n) != MP_LT) {
  ------------------
  |  |  154|    829|#define MP_LT        -1   /* less than */
  ------------------
  |  Branch (226:6): [True: 41, False: 788]
  ------------------
  227|     41|		TRACE(("s > n-1"))
  228|     41|		goto out;
  229|     41|	}
  230|       |
  231|       |	/* create the magic PKCS padded value */
  232|    788|	rsa_pad_em(key, data_buf, &rsa_em, sigtype);
  233|       |
  234|    788|	if (mp_exptmod(&rsa_s, key->e, key->n, &rsa_mdash) != MP_OKAY) {
  ------------------
  |  |  161|    788|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (234:6): [True: 0, False: 788]
  ------------------
  235|      0|		TRACE(("failed exptmod rsa_s"))
  236|      0|		goto out;
  237|      0|	}
  238|       |
  239|    788|	if (mp_cmp(&rsa_em, &rsa_mdash) == MP_EQ) {
  ------------------
  |  |  155|    788|#define MP_EQ         0   /* equal to */
  ------------------
  |  Branch (239:6): [True: 0, False: 788]
  ------------------
  240|       |		/* signature is valid */
  241|      0|		TRACE(("success!"))
  242|      0|		ret = DROPBEAR_SUCCESS;
  ------------------
  |  |  102|      0|#define DROPBEAR_SUCCESS 0
  ------------------
  243|      0|	}
  244|       |
  245|    874|out:
  246|    874|	mp_clear_multi(&rsa_mdash, &rsa_s, &rsa_em, NULL);
  247|    874|	TRACE(("leave buf_rsa_verify: ret %d", ret))
  248|    874|	return ret;
  249|    788|}
rsa.c:rsa_pad_em:
  356|    786|	const buffer *data_buf, mp_int * rsa_em, enum signature_type sigtype) {
  357|       |    /* EM = 0x00 || 0x01 || PS || 0x00 || T 
  358|       |	   PS is padding of 0xff to make EM the size of key->n
  359|       |
  360|       |	   T is the DER encoding of the hash alg (sha1 or sha256)
  361|       |	*/
  362|       |
  363|       |	/* From rfc8017 page 46 */
  364|    786|#if DROPBEAR_RSA_SHA1
  365|    786|	const unsigned char T_sha1[] =
  366|    786|		{0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b,
  367|    786|		 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14};
  368|    786|#endif
  369|    786|#if DROPBEAR_RSA_SHA256
  370|    786|	const unsigned char T_sha256[] =
  371|    786|		{0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01,
  372|    786|		 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20};
  373|    786|#endif
  374|       |
  375|    786|    int Tlen = 0;
  376|    786|    const unsigned char *T = NULL;
  377|    786|	const struct ltc_hash_descriptor *hash_desc = NULL;
  378|    786|	buffer * rsa_EM = NULL;
  379|    786|	hash_state hs;
  380|    786|	unsigned int nsize;
  381|       |
  382|    786|	switch (sigtype) {
  383|      0|#if DROPBEAR_RSA_SHA1
  384|    780|		case DROPBEAR_SIGNATURE_RSA_SHA1:
  ------------------
  |  Branch (384:3): [True: 780, False: 6]
  ------------------
  385|    780|			Tlen = sizeof(T_sha1);
  386|    780|			T = T_sha1;
  387|    780|			hash_desc = &sha1_desc;
  388|    780|			break;
  389|      0|#endif
  390|      0|#if DROPBEAR_RSA_SHA256
  391|      6|		case DROPBEAR_SIGNATURE_RSA_SHA256:
  ------------------
  |  Branch (391:3): [True: 6, False: 780]
  ------------------
  392|      6|			Tlen = sizeof(T_sha256);
  393|      6|			T = T_sha256;
  394|      6|			hash_desc = &sha256_desc;
  395|      6|			break;
  396|      0|#endif
  397|      0|		default:
  ------------------
  |  Branch (397:3): [True: 0, False: 786]
  ------------------
  398|      0|			assert(0);
  399|    786|	}
  400|       |	
  401|       |
  402|    786|	nsize = mp_ubin_size(key->n);
  403|       |
  404|    786|	rsa_EM = buf_new(nsize);
  405|       |	/* type byte */
  406|    786|	buf_putbyte(rsa_EM, 0x00);
  407|    786|	buf_putbyte(rsa_EM, 0x01);
  408|       |	/* Padding with PS 0xFF bytes */
  409|   173k|	while(rsa_EM->pos != rsa_EM->size - (1 + Tlen + hash_desc->hashsize)) {
  ------------------
  |  Branch (409:8): [True: 173k, False: 786]
  ------------------
  410|   173k|		buf_putbyte(rsa_EM, 0xff);
  411|   173k|	}
  412|    786|	buf_putbyte(rsa_EM, 0x00);
  413|       |	/* Magic ASN1 stuff */
  414|    786|	buf_putbytes(rsa_EM, T, Tlen);
  415|       |
  416|       |	/* The hash of the data */
  417|    786|	hash_desc->init(&hs);
  418|    786|	hash_desc->process(&hs, data_buf->data, data_buf->len);
  419|    786|	hash_desc->done(&hs, buf_getwriteptr(rsa_EM, hash_desc->hashsize));
  420|    786|	buf_incrwritepos(rsa_EM, hash_desc->hashsize);
  421|       |
  422|    786|	dropbear_assert(rsa_EM->pos == rsa_EM->size);
  ------------------
  |  |   83|    786|#define dropbear_assert(X) do { if (!(X)) { fail_assert(#X, __FILE__, __LINE__); } } while (0)
  |  |  ------------------
  |  |  |  Branch (83:37): [True: 0, False: 786]
  |  |  |  Branch (83:93): [Folded - Ignored]
  |  |  ------------------
  ------------------
  423|       |
  424|       |	/* Create the mp_int from the encoded bytes */
  425|    786|	buf_setpos(rsa_EM, 0);
  426|    786|	bytes_to_mp(rsa_em, buf_getptr(rsa_EM, rsa_EM->size),
  427|    786|			rsa_EM->size);
  428|    786|	buf_free(rsa_EM);
  429|    786|}

new_sign_key:
   62|  2.85k|sign_key * new_sign_key() {
   63|       |
   64|  2.85k|	sign_key * ret;
   65|       |
   66|  2.85k|	ret = (sign_key*)m_malloc(sizeof(sign_key));
   67|  2.85k|	ret->type = DROPBEAR_SIGNKEY_NONE;
   68|  2.85k|	ret->source = SIGNKEY_SOURCE_INVALID;
   69|  2.85k|	return ret;
   70|  2.85k|}
signkey_type_from_name:
   86|  3.92k|enum signkey_type signkey_type_from_name(const char* name, unsigned int namelen) {
   87|  3.92k|	int i;
   88|  14.8k|	for (i = 0; i < DROPBEAR_SIGNKEY_NUM_NAMED; i++) {
  ------------------
  |  Branch (88:14): [True: 14.6k, False: 233]
  ------------------
   89|  14.6k|		const char *fixed_name = signkey_names[i];
   90|  14.6k|		if (namelen == strlen(fixed_name)
  ------------------
  |  Branch (90:7): [True: 5.05k, False: 9.59k]
  ------------------
   91|  14.6k|			&& memcmp(fixed_name, name, namelen) == 0) {
  ------------------
  |  Branch (91:7): [True: 3.69k, False: 1.36k]
  ------------------
   92|       |
   93|  3.69k|#if DROPBEAR_ECDSA
   94|       |			/* Some of the ECDSA key sizes are defined even if they're not compiled in */
   95|  3.69k|			if (0
  ------------------
  |  Branch (95:8): [Folded - Ignored]
  ------------------
   96|       |#if !DROPBEAR_ECC_256
   97|       |				|| i == DROPBEAR_SIGNKEY_ECDSA_NISTP256
   98|       |#endif
   99|       |#if !DROPBEAR_ECC_384
  100|       |				|| i == DROPBEAR_SIGNKEY_ECDSA_NISTP384
  101|       |#endif
  102|       |#if !DROPBEAR_ECC_521
  103|       |				|| i == DROPBEAR_SIGNKEY_ECDSA_NISTP521
  104|       |#endif
  105|  3.69k|				) {
  106|      0|				TRACE(("attempt to use ecdsa type %d not compiled in", i))
  107|      0|				return DROPBEAR_SIGNKEY_NONE;
  108|      0|			}
  109|  3.69k|#endif
  110|       |
  111|  3.69k|			return (enum signkey_type)i;
  112|  3.69k|		}
  113|  14.6k|	}
  114|       |
  115|    233|	TRACE(("signkey_type_from_name unexpected key type."))
  116|       |
  117|    233|	return DROPBEAR_SIGNKEY_NONE;
  118|  3.92k|}
signature_type_from_name:
  145|  1.67k|enum signature_type signature_type_from_name(const char* name, unsigned int namelen) {
  146|  1.67k|#if DROPBEAR_RSA
  147|  1.67k|#if DROPBEAR_RSA_SHA256
  148|  1.67k|	if (namelen == strlen(SSH_SIGNATURE_RSA_SHA256) 
  ------------------
  |  |  117|  1.67k|#define SSH_SIGNATURE_RSA_SHA256 "rsa-sha2-256"
  ------------------
  |  Branch (148:6): [True: 25, False: 1.64k]
  ------------------
  149|  1.67k|		&& memcmp(name, SSH_SIGNATURE_RSA_SHA256, namelen) == 0) {
  ------------------
  |  |  117|     25|#define SSH_SIGNATURE_RSA_SHA256 "rsa-sha2-256"
  ------------------
  |  Branch (149:6): [True: 8, False: 17]
  ------------------
  150|      8|		return DROPBEAR_SIGNATURE_RSA_SHA256;
  151|      8|	}
  152|  1.66k|#endif
  153|  1.66k|#if DROPBEAR_RSA_SHA1
  154|  1.66k|	if (namelen == strlen(SSH_SIGNKEY_RSA) 
  ------------------
  |  |  112|  1.66k|#define SSH_SIGNKEY_RSA "ssh-rsa"
  ------------------
  |  Branch (154:6): [True: 1.11k, False: 550]
  ------------------
  155|  1.66k|		&& memcmp(name, SSH_SIGNKEY_RSA, namelen) == 0) {
  ------------------
  |  |  112|  1.11k|#define SSH_SIGNKEY_RSA "ssh-rsa"
  ------------------
  |  Branch (155:6): [True: 871, False: 241]
  ------------------
  156|    871|		return DROPBEAR_SIGNATURE_RSA_SHA1;
  157|    871|	}
  158|    791|#endif
  159|    791|#endif /* DROPBEAR_RSA */
  160|    791|	return (enum signature_type)signkey_type_from_name(name, namelen);
  161|  1.66k|}
signature_type_from_signkey:
  165|    804|enum signature_type signature_type_from_signkey(enum signkey_type keytype) {
  166|    804|#if DROPBEAR_RSA
  167|    804|	assert(keytype != DROPBEAR_SIGNKEY_RSA);
  168|    804|#endif
  169|    804|	assert(keytype < DROPBEAR_SIGNKEY_NUM_NAMED);
  170|    804|	return (enum signature_type)keytype;
  171|    804|}
signkey_type_from_signature:
  173|  1.58k|enum signkey_type signkey_type_from_signature(enum signature_type sigtype) {
  174|  1.58k|#if DROPBEAR_RSA
  175|  1.58k|#if DROPBEAR_RSA_SHA256
  176|  1.58k|	if (sigtype == DROPBEAR_SIGNATURE_RSA_SHA256) {
  ------------------
  |  Branch (176:6): [True: 7, False: 1.57k]
  ------------------
  177|      7|		return DROPBEAR_SIGNKEY_RSA;
  178|      7|	}
  179|  1.57k|#endif
  180|  1.57k|#if DROPBEAR_RSA_SHA1
  181|  1.57k|	if (sigtype == DROPBEAR_SIGNATURE_RSA_SHA1) {
  ------------------
  |  Branch (181:6): [True: 869, False: 707]
  ------------------
  182|    869|		return DROPBEAR_SIGNKEY_RSA;
  183|    869|	}
  184|    707|#endif
  185|    707|#endif /* DROPBEAR_RSA */
  186|    707|	assert((int)sigtype < (int)DROPBEAR_SIGNKEY_NUM_NAMED);
  187|    707|	return (enum signkey_type)sigtype;
  188|    707|}
signkey_key_ptr:
  193|  1.14k|signkey_key_ptr(sign_key *key, enum signkey_type type) {
  194|  1.14k|	switch (type) {
  195|      0|#if DROPBEAR_ED25519
  196|      0|		case DROPBEAR_SIGNKEY_ED25519:
  ------------------
  |  Branch (196:3): [True: 0, False: 1.14k]
  ------------------
  197|      0|#if DROPBEAR_SK_ED25519
  198|    117|		case DROPBEAR_SIGNKEY_SK_ED25519:
  ------------------
  |  Branch (198:3): [True: 117, False: 1.02k]
  ------------------
  199|    117|#endif
  200|    117|			return (void**)&key->ed25519key;
  201|      0|#endif
  202|      0|#if DROPBEAR_ECDSA
  203|      0|#if DROPBEAR_ECC_256
  204|    614|		case DROPBEAR_SIGNKEY_ECDSA_NISTP256:
  ------------------
  |  Branch (204:3): [True: 614, False: 528]
  ------------------
  205|    614|#if DROPBEAR_SK_ECDSA
  206|    709|		case DROPBEAR_SIGNKEY_SK_ECDSA_NISTP256:
  ------------------
  |  Branch (206:3): [True: 95, False: 1.04k]
  ------------------
  207|    709|#endif
  208|    709|			return (void**)&key->ecckey256;
  209|      0|#endif
  210|      0|#if DROPBEAR_ECC_384
  211|    147|		case DROPBEAR_SIGNKEY_ECDSA_NISTP384:
  ------------------
  |  Branch (211:3): [True: 147, False: 995]
  ------------------
  212|    147|			return (void**)&key->ecckey384;
  213|      0|#endif
  214|      0|#if DROPBEAR_ECC_521
  215|    169|		case DROPBEAR_SIGNKEY_ECDSA_NISTP521:
  ------------------
  |  Branch (215:3): [True: 169, False: 973]
  ------------------
  216|    169|			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.14k]
  ------------------
  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.14k]
  ------------------
  225|      0|			return (void**)&key->dsskey;
  226|      0|#endif
  227|      0|		default:
  ------------------
  |  Branch (227:3): [True: 0, False: 1.14k]
  ------------------
  228|      0|			return NULL;
  229|  1.14k|	}
  230|  1.14k|}
buf_get_pub_key:
  235|  2.85k|int buf_get_pub_key(buffer *buf, sign_key *key, enum signkey_type *type) {
  236|       |
  237|  2.85k|	char *ident;
  238|  2.85k|	unsigned int len;
  239|  2.85k|	enum signkey_type keytype;
  240|  2.85k|	int ret = DROPBEAR_FAILURE;
  ------------------
  |  |  103|  2.85k|#define DROPBEAR_FAILURE -1
  ------------------
  241|       |
  242|  2.85k|	TRACE2(("enter buf_get_pub_key"))
  243|       |
  244|  2.85k|	ident = buf_getstring(buf, &len);
  245|  2.85k|	keytype = signkey_type_from_name(ident, len);
  246|  2.85k|	m_free(ident);
  ------------------
  |  |   24|  2.85k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  247|       |
  248|  2.85k|	if (*type != DROPBEAR_SIGNKEY_ANY && *type != keytype) {
  ------------------
  |  Branch (248:6): [True: 0, False: 2.85k]
  |  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;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
  251|      0|	}
  252|       |	
  253|  2.85k|	TRACE2(("buf_get_pub_key keytype is %d", keytype))
  254|       |
  255|  2.85k|	*type = keytype;
  256|       |
  257|       |	/* Rewind the buffer back before "ssh-rsa" etc */
  258|  2.85k|	buf_decrpos(buf, len + 4);
  259|       |
  260|  2.85k|#if DROPBEAR_DSS
  261|  2.85k|	if (keytype == DROPBEAR_SIGNKEY_DSS) {
  ------------------
  |  Branch (261:6): [True: 351, False: 2.50k]
  ------------------
  262|    351|		dss_key_free(key->dsskey);
  263|    351|		key->dsskey = m_malloc(sizeof(*key->dsskey));
  264|    351|		ret = buf_get_dss_pub_key(buf, key->dsskey);
  265|    351|		if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|    351|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (265:7): [True: 75, False: 276]
  ------------------
  266|     75|			dss_key_free(key->dsskey);
  267|     75|			key->dsskey = NULL;
  268|     75|		}
  269|    351|	}
  270|  2.85k|#endif
  271|  2.85k|#if DROPBEAR_RSA
  272|  2.85k|	if (keytype == DROPBEAR_SIGNKEY_RSA) {
  ------------------
  |  Branch (272:6): [True: 1.18k, False: 1.67k]
  ------------------
  273|  1.18k|		rsa_key_free(key->rsakey);
  274|  1.18k|		key->rsakey = m_malloc(sizeof(*key->rsakey));
  275|  1.18k|		ret = buf_get_rsa_pub_key(buf, key->rsakey);
  276|  1.18k|		if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|  1.18k|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (276:7): [True: 132, False: 1.05k]
  ------------------
  277|    132|			rsa_key_free(key->rsakey);
  278|    132|			key->rsakey = NULL;
  279|    132|		}
  280|  1.18k|	}
  281|  2.85k|#endif
  282|  2.85k|#if DROPBEAR_ECDSA
  283|  2.85k|	if (signkey_is_ecdsa(keytype)
  ------------------
  |  Branch (283:6): [True: 904, False: 1.95k]
  ------------------
  284|  2.85k|#if DROPBEAR_SK_ECDSA
  285|  2.85k|		|| keytype == DROPBEAR_SIGNKEY_SK_ECDSA_NISTP256
  ------------------
  |  Branch (285:6): [True: 95, False: 1.86k]
  ------------------
  286|  2.85k|#endif
  287|  2.85k|	) {
  288|    746|		ecc_key **eck = (ecc_key**)signkey_key_ptr(key, keytype);
  289|    746|		if (eck) {
  ------------------
  |  Branch (289:7): [True: 746, False: 0]
  ------------------
  290|    746|			if (*eck) {
  ------------------
  |  Branch (290:8): [True: 0, False: 746]
  ------------------
  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 - Ignored]
  |  |  ------------------
  ------------------
  293|      0|				*eck = NULL;
  294|      0|			}
  295|    746|			*eck = buf_get_ecdsa_pub_key(buf);
  296|    746|			if (*eck) {
  ------------------
  |  Branch (296:8): [True: 282, False: 464]
  ------------------
  297|    282|				ret = DROPBEAR_SUCCESS;
  ------------------
  |  |  102|    282|#define DROPBEAR_SUCCESS 0
  ------------------
  298|    282|			}
  299|    746|		}
  300|    746|	}
  301|  2.85k|#endif
  302|  2.85k|#if DROPBEAR_ED25519
  303|  2.85k|	if (keytype == DROPBEAR_SIGNKEY_ED25519
  ------------------
  |  Branch (303:6): [True: 551, False: 2.30k]
  ------------------
  304|  2.85k|#if DROPBEAR_SK_ED25519
  305|  2.85k|		|| keytype == DROPBEAR_SIGNKEY_SK_ED25519
  ------------------
  |  Branch (305:6): [True: 131, False: 2.17k]
  ------------------
  306|  2.85k|#endif
  307|  2.85k|    ) {
  308|    346|		ed25519_key_free(key->ed25519key);
  309|    346|		key->ed25519key = m_malloc(sizeof(*key->ed25519key));
  310|    346|		ret = buf_get_ed25519_pub_key(buf, key->ed25519key, keytype);
  311|    346|		if (ret == DROPBEAR_FAILURE) {
  ------------------
  |  |  103|    346|#define DROPBEAR_FAILURE -1
  ------------------
  |  Branch (311:7): [True: 58, False: 288]
  ------------------
  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 - Ignored]
  |  |  ------------------
  ------------------
  313|     58|			key->ed25519key = NULL;
  314|     58|		}
  315|    346|	}
  316|  2.85k|#endif
  317|       |
  318|  2.85k|#if DROPBEAR_SK_ECDSA || DROPBEAR_SK_ED25519
  319|  2.85k|	if (0
  ------------------
  |  Branch (319:6): [Folded - Ignored]
  ------------------
  320|  2.85k|#if DROPBEAR_SK_ED25519
  321|  2.85k|		|| keytype == DROPBEAR_SIGNKEY_SK_ED25519
  ------------------
  |  Branch (321:6): [True: 129, False: 2.38k]
  ------------------
  322|  2.85k|#endif
  323|  2.85k|#if DROPBEAR_SK_ECDSA
  324|  2.85k|		|| keytype == DROPBEAR_SIGNKEY_SK_ECDSA_NISTP256
  ------------------
  |  Branch (324:6): [True: 86, False: 2.30k]
  ------------------
  325|  2.85k|#endif
  326|  2.85k|	) {
  327|    215|		key->sk_app = buf_getstring(buf, &key->sk_applen);
  328|    215|	}
  329|  2.85k|#endif
  330|       |
  331|  2.85k|	TRACE2(("leave buf_get_pub_key"))
  332|       |
  333|  2.85k|	return ret;
  334|  2.85k|}
sign_key_free:
  502|  2.29k|void sign_key_free(sign_key *key) {
  503|       |
  504|  2.29k|	TRACE2(("enter sign_key_free"))
  505|       |
  506|  2.29k|#if DROPBEAR_DSS
  507|  2.29k|	dss_key_free(key->dsskey);
  508|  2.29k|	key->dsskey = NULL;
  509|  2.29k|#endif
  510|  2.29k|#if DROPBEAR_RSA
  511|  2.29k|	rsa_key_free(key->rsakey);
  512|  2.29k|	key->rsakey = NULL;
  513|  2.29k|#endif
  514|  2.29k|#if DROPBEAR_ECDSA
  515|  2.29k|#if DROPBEAR_ECC_256
  516|  2.29k|	if (key->ecckey256) {
  ------------------
  |  Branch (516:6): [True: 176, False: 2.11k]
  ------------------
  517|    176|		ecc_free(key->ecckey256);
  518|    176|		m_free(key->ecckey256);
  ------------------
  |  |   24|    176|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  519|    176|		key->ecckey256 = NULL;
  520|    176|	}
  521|  2.29k|#endif
  522|  2.29k|#if DROPBEAR_ECC_384
  523|  2.29k|	if (key->ecckey384) {
  ------------------
  |  Branch (523:6): [True: 45, False: 2.24k]
  ------------------
  524|     45|		ecc_free(key->ecckey384);
  525|     45|		m_free(key->ecckey384);
  ------------------
  |  |   24|     45|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  526|     45|		key->ecckey384 = NULL;
  527|     45|	}
  528|  2.29k|#endif
  529|  2.29k|#if DROPBEAR_ECC_521
  530|  2.29k|	if (key->ecckey521) {
  ------------------
  |  Branch (530:6): [True: 54, False: 2.24k]
  ------------------
  531|     54|		ecc_free(key->ecckey521);
  532|     54|		m_free(key->ecckey521);
  ------------------
  |  |   24|     54|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  533|     54|		key->ecckey521 = NULL;
  534|     54|	}
  535|  2.29k|#endif
  536|  2.29k|#endif
  537|  2.29k|#if DROPBEAR_ED25519
  538|  2.29k|	ed25519_key_free(key->ed25519key);
  539|  2.29k|	key->ed25519key = NULL;
  540|  2.29k|#endif
  541|       |
  542|  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 - Ignored]
  |  |  ------------------
  ------------------
  543|  2.29k|#if DROPBEAR_SK_ECDSA || DROPBEAR_SK_ED25519
  544|  2.29k|	if (key->sk_app) {
  ------------------
  |  Branch (544:6): [True: 121, False: 2.17k]
  ------------------
  545|    121|		m_free(key->sk_app);
  ------------------
  |  |   24|    121|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  546|    121|	}
  547|  2.29k|#endif
  548|       |
  549|  2.29k|	m_free(key);
  ------------------
  |  |   24|  2.29k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  550|  2.29k|	TRACE2(("leave sign_key_free"))
  551|  2.29k|}
buf_verify:
  641|  1.69k|int buf_verify(buffer * buf, sign_key *key, enum signature_type expect_sigtype, const buffer *data_buf) {
  642|       |	
  643|  1.69k|	char *type_name = NULL;
  644|  1.69k|	unsigned int type_name_len = 0;
  645|  1.69k|	enum signature_type sigtype;
  646|  1.69k|	enum signkey_type keytype;
  647|       |
  648|  1.69k|	TRACE(("enter buf_verify"))
  649|       |
  650|  1.69k|	buf_getint(buf); /* blob length */
  651|  1.69k|	type_name = buf_getstring(buf, &type_name_len);
  652|  1.69k|	sigtype = signature_type_from_name(type_name, type_name_len);
  653|  1.69k|	m_free(type_name);
  ------------------
  |  |   24|  1.69k|#define m_free(X) do {m_free_direct(X); (X) = NULL;} while (0)
  |  |  ------------------
  |  |  |  Branch (24:61): [Folded - Ignored]
  |  |  ------------------
  ------------------
  654|       |
  655|  1.69k|	if (expect_sigtype != sigtype) {
  ------------------
  |  Branch (655:6): [True: 87, False: 1.61k]
  ------------------
  656|     87|			dropbear_exit("Non-matching signing type");
  657|     87|	}
  658|       |
  659|  1.61k|	keytype = signkey_type_from_signature(sigtype);
  660|  1.61k|#if DROPBEAR_DSS
  661|  1.61k|	if (keytype == DROPBEAR_SIGNKEY_DSS) {
  ------------------
  |  Branch (661:6): [True: 239, False: 1.37k]
  ------------------
  662|    239|		if (key->dsskey == NULL) {
  ------------------
  |  Branch (662:7): [True: 0, False: 239]
  ------------------
  663|      0|			dropbear_exit("No DSS key to verify signature");
  664|      0|		}
  665|    239|		return buf_dss_verify(buf, key->dsskey, data_buf);
  666|    239|	}
  667|  1.37k|#endif
  668|       |
  669|  1.37k|#if DROPBEAR_RSA
  670|  1.37k|	if (keytype == DROPBEAR_SIGNKEY_RSA) {
  ------------------
  |  Branch (670:6): [True: 876, False: 496]
  ------------------
  671|    876|		if (key->rsakey == NULL) {
  ------------------
  |  Branch (671:7): [True: 0, False: 876]
  ------------------
  672|      0|			dropbear_exit("No RSA key to verify signature");
  673|      0|		}
  674|    876|		return buf_rsa_verify(buf, key->rsakey, sigtype, data_buf);
  675|    876|	}
  676|    496|#endif
  677|    496|#if DROPBEAR_ECDSA
  678|    496|	if (signkey_is_ecdsa(keytype)) {
  ------------------
  |  Branch (678:6): [True: 279, False: 217]
  ------------------
  679|    279|		ecc_key **eck = (ecc_key**)signkey_key_ptr(key, keytype);
  680|    279|		if (eck && *eck) {
  ------------------
  |  Branch (680:7): [True: 279, False: 0]
  |  Branch (680:14): [True: 279, False: 0]
  ------------------
  681|    279|			return buf_ecdsa_verify(buf, *eck, data_buf);
  682|    279|		}
  683|    279|	}
  684|    217|#endif
  685|    217|#if DROPBEAR_ED25519
  686|    217|	if (keytype == DROPBEAR_SIGNKEY_ED25519) {
  ------------------
  |  Branch (686:6): [True: 74, False: 143]
  ------------------
  687|     74|		if (key->ed25519key == NULL) {
  ------------------
  |  Branch (687:7): [True: 0, False: 74]
  ------------------
  688|      0|			dropbear_exit("No Ed25519 key to verify signature");
  689|      0|		}
  690|     74|		return buf_ed25519_verify(buf, key->ed25519key, data_buf);
  691|     74|	}
  692|    143|#endif
  693|    143|#if DROPBEAR_SK_ECDSA
  694|    143|	if (keytype == DROPBEAR_SIGNKEY_SK_ECDSA_NISTP256) {
  ------------------
  |  Branch (694:6): [True: 0, False: 143]
  ------------------
  695|      0|		ecc_key **eck = (ecc_key**)signkey_key_ptr(key, keytype);
  696|      0|		if (eck && *eck) {
  ------------------
  |  Branch (696:7): [True: 0, False: 0]
  |  Branch (696:14): [True: 0, False: 0]
  ------------------
  697|      0|			return buf_sk_ecdsa_verify(buf, *eck, data_buf, key->sk_app, key->sk_applen, key->sk_flags_mask);
  698|      0|		}
  699|      0|	}
  700|    143|#endif
  701|    143|#if DROPBEAR_SK_ED25519
  702|    143|	if (keytype == DROPBEAR_SIGNKEY_SK_ED25519) {
  ------------------
  |  Branch (702:6): [True: 115, False: 28]
  ------------------
  703|    115|		dropbear_ed25519_key **eck = (dropbear_ed25519_key**)signkey_key_ptr(key, keytype);
  704|    115|		if (eck && *eck) {
  ------------------
  |  Branch (704:7): [True: 115, False: 0]
  |  Branch (704:14): [True: 115, False: 0]
  ------------------
  705|    115|			return buf_sk_ed25519_verify(buf, *eck, data_buf, key->sk_app, key->sk_applen, key->sk_flags_mask);
  706|    115|		}
  707|    115|	}
  708|     28|#endif
  709|       |
  710|     28|	dropbear_exit("Non-matching signing type");
  711|      0|	return DROPBEAR_FAILURE;
  ------------------
  |  |  103|      0|#define DROPBEAR_FAILURE -1
  ------------------
  712|    143|}

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

