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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

mp_cmp_mag:
    8|  7.05M|{
    9|  7.05M|   int     n;
   10|  7.05M|   const mp_digit *tmpa, *tmpb;
   11|       |
   12|       |   /* compare based on # of non-zero digits */
   13|  7.05M|   if (a->used > b->used) {
  ------------------
  |  Branch (13:8): [True: 1.85M, False: 5.20M]
  ------------------
   14|  1.85M|      return MP_GT;
  ------------------
  |  |  156|  1.85M|#define MP_GT         1   /* greater than */
  ------------------
   15|  1.85M|   }
   16|       |
   17|  5.20M|   if (a->used < b->used) {
  ------------------
  |  Branch (17:8): [True: 108k, False: 5.09M]
  ------------------
   18|   108k|      return MP_LT;
  ------------------
  |  |  154|   108k|#define MP_LT        -1   /* less than */
  ------------------
   19|   108k|   }
   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.68M|   for (n = 0; n < a->used; ++n, --tmpa, --tmpb) {
  ------------------
  |  Branch (28:16): [True: 5.66M, False: 16.0k]
  ------------------
   29|  5.66M|      if (*tmpa > *tmpb) {
  ------------------
  |  Branch (29:11): [True: 1.78M, False: 3.88M]
  ------------------
   30|  1.78M|         return MP_GT;
  ------------------
  |  |  156|  1.78M|#define MP_GT         1   /* greater than */
  ------------------
   31|  1.78M|      }
   32|       |
   33|  3.88M|      if (*tmpa < *tmpb) {
  ------------------
  |  Branch (33:11): [True: 3.29M, False: 590k]
  ------------------
   34|  3.29M|         return MP_LT;
  ------------------
  |  |  154|  3.29M|#define MP_LT        -1   /* less than */
  ------------------
   35|  3.29M|      }
   36|  3.88M|   }
   37|  16.0k|   return MP_EQ;
  ------------------
  |  |  155|  16.0k|#define MP_EQ         0   /* equal to */
  ------------------
   38|  5.09M|}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

mp_is_square:
   30|    144|{
   31|    144|   mp_err        err;
   32|    144|   mp_digit      c;
   33|    144|   mp_int        t;
   34|    144|   unsigned long r;
   35|       |
   36|       |   /* Default to Non-square :) */
   37|    144|   *ret = MP_NO;
  ------------------
  |  |  159|    144|#define MP_NO         0
  ------------------
   38|       |
   39|    144|   if (arg->sign == MP_NEG) {
  ------------------
  |  |  152|    144|#define MP_NEG        1   /* negative */
  ------------------
  |  Branch (39:8): [True: 0, False: 144]
  ------------------
   40|      0|      return MP_VAL;
  ------------------
  |  |  164|      0|#define MP_VAL        -3  /* invalid input */
  ------------------
   41|      0|   }
   42|       |
   43|    144|   if (MP_IS_ZERO(arg)) {
  ------------------
  |  |  163|    144|#define MP_IS_ZERO(a) ((a)->used == 0)
  |  |  ------------------
  |  |  |  Branch (163:23): [True: 0, False: 144]
  |  |  ------------------
  ------------------
   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|    144|   if (rem_128[127u & arg->dp[0]] == (char)1) {
  ------------------
  |  Branch (48:8): [True: 21, False: 123]
  ------------------
   49|     21|      return MP_OKAY;
  ------------------
  |  |  161|     21|#define MP_OKAY       0   /* no error */
  ------------------
   50|     21|   }
   51|       |
   52|       |   /* Next check mod 105 (3*5*7) */
   53|    123|   if ((err = mp_mod_d(arg, 105uL, &c)) != MP_OKAY) {
  ------------------
  |  |  161|    123|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (53:8): [True: 0, False: 123]
  ------------------
   54|      0|      return err;
   55|      0|   }
   56|    123|   if (rem_105[c] == (char)1) {
  ------------------
  |  Branch (56:8): [True: 85, False: 38]
  ------------------
   57|     85|      return MP_OKAY;
  ------------------
  |  |  161|     85|#define MP_OKAY       0   /* no error */
  ------------------
   58|     85|   }
   59|       |
   60|       |
   61|     38|   if ((err = mp_init_u32(&t, 11u*13u*17u*19u*23u*29u*31u)) != MP_OKAY) {
  ------------------
  |  |  161|     38|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (61:8): [True: 0, False: 38]
  ------------------
   62|      0|      return err;
   63|      0|   }
   64|     38|   if ((err = mp_mod(arg, &t, &t)) != MP_OKAY) {
  ------------------
  |  |  161|     38|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (64:8): [True: 0, False: 38]
  ------------------
   65|      0|      goto LBL_ERR;
   66|      0|   }
   67|     38|   r = mp_get_u32(&t);
  ------------------
  |  |  310|     38|#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|     38|   if (((1uL<<(r%11uL)) & 0x5C4uL) != 0uL)         goto LBL_ERR;
  ------------------
  |  Branch (72:8): [True: 12, False: 26]
  ------------------
   73|     26|   if (((1uL<<(r%13uL)) & 0x9E4uL) != 0uL)         goto LBL_ERR;
  ------------------
  |  Branch (73:8): [True: 8, False: 18]
  ------------------
   74|     18|   if (((1uL<<(r%17uL)) & 0x5CE8uL) != 0uL)        goto LBL_ERR;
  ------------------
  |  Branch (74:8): [True: 4, False: 14]
  ------------------
   75|     14|   if (((1uL<<(r%19uL)) & 0x4F50CuL) != 0uL)       goto LBL_ERR;
  ------------------
  |  Branch (75:8): [True: 5, False: 9]
  ------------------
   76|      9|   if (((1uL<<(r%23uL)) & 0x7ACCA0uL) != 0uL)      goto LBL_ERR;
  ------------------
  |  Branch (76:8): [True: 1, False: 8]
  ------------------
   77|      8|   if (((1uL<<(r%29uL)) & 0xC2EDD0CuL) != 0uL)     goto LBL_ERR;
  ------------------
  |  Branch (77:8): [True: 2, 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|     38|LBL_ERR:
   90|     38|   mp_clear(&t);
   91|     38|   return err;
   92|      5|}

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

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

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

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

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

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

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

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

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

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

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

mp_prime_is_prime:
   18|    228|{
   19|    228|   mp_int  b;
   20|    228|   int     ix, p_max = 0, size_a, len;
   21|    228|   mp_bool res;
   22|    228|   mp_err  err;
   23|    228|   unsigned int fips_rand, mask;
   24|       |
   25|       |   /* default to no */
   26|    228|   *result = MP_NO;
  ------------------
  |  |  159|    228|#define MP_NO         0
  ------------------
   27|       |
   28|       |   /* Some shortcuts */
   29|       |   /* N > 3 */
   30|    228|   if (a->used == 1) {
  ------------------
  |  Branch (30:8): [True: 0, False: 228]
  ------------------
   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|    228|   if (MP_IS_EVEN(a)) {
  ------------------
  |  |  164|    228|#define MP_IS_EVEN(a) (((a)->used == 0) || (((a)->dp[0] & 1u) == 0u))
  |  |  ------------------
  |  |  |  Branch (164:24): [True: 0, False: 228]
  |  |  |  Branch (164:44): [True: 84, False: 144]
  |  |  ------------------
  ------------------
   43|     84|      return MP_OKAY;
  ------------------
  |  |  161|     84|#define MP_OKAY       0   /* no error */
  ------------------
   44|     84|   }
   45|       |   /* N is not a perfect square: floor(sqrt(N))^2 != N */
   46|    144|   if ((err = mp_is_square(a, &res)) != MP_OKAY) {
  ------------------
  |  |  161|    144|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (46:8): [True: 0, False: 144]
  ------------------
   47|      0|      return err;
   48|      0|   }
   49|    144|   if (res != MP_NO) {
  ------------------
  |  |  159|    144|#define MP_NO         0
  ------------------
  |  Branch (49:8): [True: 1, False: 143]
  ------------------
   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|  36.7k|   for (ix = 0; ix < PRIVATE_MP_PRIME_TAB_SIZE; ix++) {
  ------------------
  |  |  633|  36.7k|#  define PRIVATE_MP_PRIME_TAB_SIZE 256
  ------------------
  |  Branch (54:17): [True: 36.6k, False: 143]
  ------------------
   55|  36.6k|      if (mp_cmp_d(a, s_mp_prime_tab[ix]) == MP_EQ) {
  ------------------
  |  |  155|  36.6k|#define MP_EQ         0   /* equal to */
  ------------------
  |  Branch (55:11): [True: 0, False: 36.6k]
  ------------------
   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|  36.6k|   }
   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|    143|   if ((err = s_mp_prime_is_divisible(a, &res)) != MP_OKAY) {
  ------------------
  |  |  161|    143|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (68:8): [True: 0, False: 143]
  ------------------
   69|      0|      return err;
   70|      0|   }
   71|       |
   72|       |   /* return if it was trivially divisible */
   73|    143|   if (res == MP_YES) {
  ------------------
  |  |  158|    143|#define MP_YES        1
  ------------------
  |  Branch (73:8): [True: 53, False: 90]
  ------------------
   74|     53|      return MP_OKAY;
  ------------------
  |  |  161|     53|#define MP_OKAY       0   /* no error */
  ------------------
   75|     53|   }
   76|       |
   77|       |   /*
   78|       |       Run the Miller-Rabin test with base 2 for the BPSW test.
   79|       |    */
   80|     90|   if ((err = mp_init_set(&b, 2uL)) != MP_OKAY) {
  ------------------
  |  |  161|     90|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (80:8): [True: 0, False: 90]
  ------------------
   81|      0|      return err;
   82|      0|   }
   83|       |
   84|     90|   if ((err = mp_prime_miller_rabin(a, &b, &res)) != MP_OKAY) {
  ------------------
  |  |  161|     90|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (84:8): [True: 0, False: 90]
  ------------------
   85|      0|      goto LBL_B;
   86|      0|   }
   87|     90|   if (res == MP_NO) {
  ------------------
  |  |  159|     90|#define MP_NO         0
  ------------------
  |  Branch (87:8): [True: 37, False: 53]
  ------------------
   88|     37|      goto LBL_B;
   89|     37|   }
   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|     53|   b.dp[0]++;
   96|     53|   if ((err = mp_prime_miller_rabin(a, &b, &res)) != MP_OKAY) {
  ------------------
  |  |  161|     53|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (96:8): [True: 0, False: 53]
  ------------------
   97|      0|      goto LBL_B;
   98|      0|   }
   99|     53|   if (res == MP_NO) {
  ------------------
  |  |  159|     53|#define MP_NO         0
  ------------------
  |  Branch (99:8): [True: 0, False: 53]
  ------------------
  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|     53|   if (t == 0) {
  ------------------
  |  Branch (135:8): [True: 0, False: 53]
  ------------------
  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|     53|   if (t < 0) {
  ------------------
  |  Branch (147:8): [True: 0, False: 53]
  ------------------
  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|     53|   else if (t > 0) {
  ------------------
  |  Branch (188:13): [True: 53, 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|     53|      size_a = mp_count_bits(a);
  198|     53|      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|  1.90k|      for (ix = 0; ix < t; ix++) {
  ------------------
  |  Branch (233:20): [True: 1.85k, False: 53]
  ------------------
  234|       |         /* mp_rand() guarantees the first digit to be non-zero */
  235|  1.85k|         if ((err = mp_rand(&b, 1)) != MP_OKAY) {
  ------------------
  |  |  161|  1.85k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (235:14): [True: 0, False: 1.85k]
  ------------------
  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.85k|         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.85k|         if (fips_rand > (unsigned int)(INT_MAX - MP_DIGIT_BIT)) {
  ------------------
  |  |   82|  1.85k|#   define MP_DIGIT_BIT 60
  ------------------
  |  Branch (257:14): [True: 0, False: 1.85k]
  ------------------
  258|      0|            len = INT_MAX / MP_DIGIT_BIT;
  ------------------
  |  |   82|      0|#   define MP_DIGIT_BIT 60
  ------------------
  259|  1.85k|         } else {
  260|  1.85k|            len = (((int)fips_rand + MP_DIGIT_BIT) / MP_DIGIT_BIT);
  ------------------
  |  |   82|  1.85k|#   define MP_DIGIT_BIT 60
  ------------------
                          len = (((int)fips_rand + MP_DIGIT_BIT) / MP_DIGIT_BIT);
  ------------------
  |  |   82|  1.85k|#   define MP_DIGIT_BIT 60
  ------------------
  261|  1.85k|         }
  262|       |         /*  Unlikely. */
  263|  1.85k|         if (len < 0) {
  ------------------
  |  Branch (263:14): [True: 0, False: 1.85k]
  ------------------
  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.85k|         if ((err = mp_rand(&b, len)) != MP_OKAY) {
  ------------------
  |  |  161|  1.85k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (279:14): [True: 0, False: 1.85k]
  ------------------
  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.85k|         len = mp_count_bits(&b);
  287|  1.85k|         if (len >= size_a) {
  ------------------
  |  Branch (287:14): [True: 207, False: 1.64k]
  ------------------
  288|    207|            len = (len - size_a) + 1;
  289|    207|            if ((err = mp_div_2d(&b, len, &b, NULL)) != MP_OKAY) {
  ------------------
  |  |  161|    207|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (289:17): [True: 0, False: 207]
  ------------------
  290|      0|               goto LBL_B;
  291|      0|            }
  292|    207|         }
  293|       |         /* Although the chance for b <= 3 is miniscule, try again. */
  294|  1.85k|         if (mp_cmp_d(&b, 3uL) != MP_GT) {
  ------------------
  |  |  156|  1.85k|#define MP_GT         1   /* greater than */
  ------------------
  |  Branch (294:14): [True: 0, False: 1.85k]
  ------------------
  295|      0|            ix--;
  296|      0|            continue;
  297|      0|         }
  298|  1.85k|         if ((err = mp_prime_miller_rabin(a, &b, &res)) != MP_OKAY) {
  ------------------
  |  |  161|  1.85k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (298:14): [True: 0, False: 1.85k]
  ------------------
  299|      0|            goto LBL_B;
  300|      0|         }
  301|  1.85k|         if (res == MP_NO) {
  ------------------
  |  |  159|  1.85k|#define MP_NO         0
  ------------------
  |  Branch (301:14): [True: 0, False: 1.85k]
  ------------------
  302|      0|            goto LBL_B;
  303|      0|         }
  304|  1.85k|      }
  305|     53|   }
  306|       |
  307|       |   /* passed the test */
  308|     53|   *result = MP_YES;
  ------------------
  |  |  158|     53|#define MP_YES        1
  ------------------
  309|     90|LBL_B:
  310|     90|   mp_clear(&b);
  311|     90|   return err;
  312|     53|}
bn_mp_prime_is_prime.c:s_floor_ilog2:
    8|     53|{
    9|     53|   unsigned int r = 0;
   10|    424|   while ((value >>= 1) != 0) {
  ------------------
  |  Branch (10:11): [True: 371, False: 53]
  ------------------
   11|    371|      r++;
   12|    371|   }
   13|     53|   return r;
   14|     53|}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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|    136|   do {
   46|    136|      if ((err = mp_div(arg, &t1, &t2, NULL)) != MP_OKAY) {
  ------------------
  |  |  161|    136|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (46:11): [True: 0, False: 136]
  ------------------
   47|      0|         goto E1;
   48|      0|      }
   49|    136|      if ((err = mp_add(&t1, &t2, &t1)) != MP_OKAY) {
  ------------------
  |  |  161|    136|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (49:11): [True: 0, False: 136]
  ------------------
   50|      0|         goto E1;
   51|      0|      }
   52|    136|      if ((err = mp_div_2(&t1, &t1)) != MP_OKAY) {
  ------------------
  |  |  161|    136|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (52:11): [True: 0, False: 136]
  ------------------
   53|      0|         goto E1;
   54|      0|      }
   55|       |      /* t1 >= sqrt(arg) >= t2 at this point */
   56|    136|   } while (mp_cmp_mag(&t1, &t2) == MP_GT);
  ------------------
  |  |  156|    136|#define MP_GT         1   /* greater than */
  ------------------
  |  Branch (56:13): [True: 131, 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.74M|{
    9|  1.74M|   mp_sign sa = a->sign, sb = b->sign;
   10|  1.74M|   mp_err err;
   11|       |
   12|  1.74M|   if (sa != sb) {
  ------------------
  |  Branch (12:8): [True: 136k, False: 1.61M]
  ------------------
   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|   136k|      c->sign = sa;
   18|   136k|      err = s_mp_add(a, b, c);
   19|  1.61M|   } 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.61M|      if (mp_cmp_mag(a, b) != MP_LT) {
  ------------------
  |  |  154|  1.61M|#define MP_LT        -1   /* less than */
  ------------------
  |  Branch (24:11): [True: 1.17M, False: 437k]
  ------------------
   25|       |         /* Copy the sign from the first */
   26|  1.17M|         c->sign = sa;
   27|       |         /* The first has a larger or equal magnitude */
   28|  1.17M|         err = s_mp_sub(a, b, c);
   29|  1.17M|      } else {
   30|       |         /* The result has the *opposite* sign from */
   31|       |         /* the first number. */
   32|   437k|         c->sign = (sa == MP_ZPOS) ? MP_NEG : MP_ZPOS;
  ------------------
  |  |  151|   437k|#define MP_ZPOS       0   /* positive integer */
  ------------------
                       c->sign = (sa == MP_ZPOS) ? MP_NEG : MP_ZPOS;
  ------------------
  |  |  152|   397k|#define MP_NEG        1   /* negative */
  ------------------
                       c->sign = (sa == MP_ZPOS) ? MP_NEG : MP_ZPOS;
  ------------------
  |  |  151|   478k|#define MP_ZPOS       0   /* positive integer */
  ------------------
  |  Branch (32:20): [True: 397k, False: 40.5k]
  ------------------
   33|       |         /* The second has a larger magnitude */
   34|   437k|         err = s_mp_sub(b, a, c);
   35|   437k|      }
   36|  1.61M|   }
   37|  1.74M|   return err;
   38|  1.74M|}

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

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

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

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

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

s_mp_exptmod:
   15|    846|{
   16|    846|   mp_int  M[TAB_SIZE], res, mu;
   17|    846|   mp_digit buf;
   18|    846|   mp_err   err;
   19|    846|   int      bitbuf, bitcpy, bitcnt, mode, digidx, x, y, winsize;
   20|    846|   mp_err(*redux)(mp_int *x, const mp_int *m, const mp_int *mu);
   21|       |
   22|       |   /* find window size */
   23|    846|   x = mp_count_bits(X);
   24|    846|   if (x <= 7) {
  ------------------
  |  Branch (24:8): [True: 219, False: 627]
  ------------------
   25|    219|      winsize = 2;
   26|    627|   } else if (x <= 36) {
  ------------------
  |  Branch (26:15): [True: 243, False: 384]
  ------------------
   27|    243|      winsize = 3;
   28|    384|   } else if (x <= 140) {
  ------------------
  |  Branch (28:15): [True: 85, False: 299]
  ------------------
   29|     85|      winsize = 4;
   30|    299|   } else if (x <= 450) {
  ------------------
  |  Branch (30:15): [True: 299, False: 0]
  ------------------
   31|    299|      winsize = 5;
   32|    299|   } 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|    846|   winsize = MAX_WINSIZE ? MP_MIN(MAX_WINSIZE, winsize) : winsize;
  ------------------
  |  |   11|    846|#   define MAX_WINSIZE 0
  |  |  ------------------
  |  |  |  Branch (11:24): [Folded, False: 846]
  |  |  ------------------
  ------------------
                 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|    846|   if ((err = mp_init(&M[1])) != MP_OKAY) {
  ------------------
  |  |  161|    846|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (44:8): [True: 0, False: 846]
  ------------------
   45|      0|      return err;
   46|      0|   }
   47|       |
   48|       |   /* now init the second half of the array */
   49|  7.72k|   for (x = 1<<(winsize-1); x < (1 << winsize); x++) {
  ------------------
  |  Branch (49:29): [True: 6.87k, False: 846]
  ------------------
   50|  6.87k|      if ((err = mp_init(&M[x])) != MP_OKAY) {
  ------------------
  |  |  161|  6.87k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (50:11): [True: 0, False: 6.87k]
  ------------------
   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|  6.87k|   }
   58|       |
   59|       |   /* create mu, used for Barrett reduction */
   60|    846|   if ((err = mp_init(&mu)) != MP_OKAY)                           goto LBL_M;
  ------------------
  |  |  161|    846|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (60:8): [True: 0, False: 846]
  ------------------
   61|       |
   62|    846|   if (redmode == 0) {
  ------------------
  |  Branch (62:8): [True: 538, False: 308]
  ------------------
   63|    538|      if ((err = mp_reduce_setup(&mu, P)) != MP_OKAY)             goto LBL_MU;
  ------------------
  |  |  161|    538|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (63:11): [True: 0, False: 538]
  ------------------
   64|    538|      redux = mp_reduce;
   65|    538|   } else {
   66|    308|      if ((err = mp_reduce_2k_setup_l(P, &mu)) != MP_OKAY)        goto LBL_MU;
  ------------------
  |  |  161|    308|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (66:11): [True: 0, False: 308]
  ------------------
   67|    308|      redux = mp_reduce_2k_l;
   68|    308|   }
   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|    846|   if ((err = mp_mod(G, P, &M[1])) != MP_OKAY)                    goto LBL_MU;
  ------------------
  |  |  161|    846|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (78:8): [True: 0, False: 846]
  ------------------
   79|       |
   80|       |   /* compute the value at M[1<<(winsize-1)] by squaring
   81|       |    * M[1] (winsize-1) times
   82|       |    */
   83|    846|   if ((err = mp_copy(&M[1], &M[(size_t)1 << (winsize - 1)])) != MP_OKAY) goto LBL_MU;
  ------------------
  |  |  161|    846|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (83:8): [True: 0, False: 846]
  ------------------
   84|       |
   85|  3.00k|   for (x = 0; x < (winsize - 1); x++) {
  ------------------
  |  Branch (85:16): [True: 2.15k, False: 846]
  ------------------
   86|       |      /* square it */
   87|  2.15k|      if ((err = mp_sqr(&M[(size_t)1 << (winsize - 1)],
  ------------------
  |  Branch (87:11): [True: 0, False: 2.15k]
  ------------------
   88|  2.15k|                        &M[(size_t)1 << (winsize - 1)])) != MP_OKAY) goto LBL_MU;
  ------------------
  |  |  161|  2.15k|#define MP_OKAY       0   /* no error */
  ------------------
   89|       |
   90|       |      /* reduce modulo P */
   91|  2.15k|      if ((err = redux(&M[(size_t)1 << (winsize - 1)], P, &mu)) != MP_OKAY) goto LBL_MU;
  ------------------
  |  |  161|  2.15k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (91:11): [True: 0, False: 2.15k]
  ------------------
   92|  2.15k|   }
   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|  6.87k|   for (x = (1 << (winsize - 1)) + 1; x < (1 << winsize); x++) {
  ------------------
  |  Branch (97:39): [True: 6.02k, False: 846]
  ------------------
   98|  6.02k|      if ((err = mp_mul(&M[x - 1], &M[1], &M[x])) != MP_OKAY)     goto LBL_MU;
  ------------------
  |  |  161|  6.02k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (98:11): [True: 0, False: 6.02k]
  ------------------
   99|  6.02k|      if ((err = redux(&M[x], P, &mu)) != MP_OKAY)                goto LBL_MU;
  ------------------
  |  |  161|  6.02k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (99:11): [True: 0, False: 6.02k]
  ------------------
  100|  6.02k|   }
  101|       |
  102|       |   /* setup result */
  103|    846|   if ((err = mp_init(&res)) != MP_OKAY)                          goto LBL_MU;
  ------------------
  |  |  161|    846|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (103:8): [True: 0, False: 846]
  ------------------
  104|    846|   mp_set(&res, 1uL);
  105|       |
  106|       |   /* set initial mode and bit cnt */
  107|    846|   mode   = 0;
  108|    846|   bitcnt = 1;
  109|    846|   buf    = 0;
  110|    846|   digidx = X->used - 1;
  111|    846|   bitcpy = 0;
  112|    846|   bitbuf = 0;
  113|       |
  114|  81.6k|   for (;;) {
  115|       |      /* grab next digit as required */
  116|  81.6k|      if (--bitcnt == 0) {
  ------------------
  |  Branch (116:11): [True: 2.19k, False: 79.4k]
  ------------------
  117|       |         /* if digidx == -1 we are out of digits */
  118|  2.19k|         if (digidx == -1) {
  ------------------
  |  Branch (118:14): [True: 846, False: 1.34k]
  ------------------
  119|    846|            break;
  120|    846|         }
  121|       |         /* read next digit and reset the bitcnt */
  122|  1.34k|         buf    = X->dp[digidx--];
  123|  1.34k|         bitcnt = (int)MP_DIGIT_BIT;
  ------------------
  |  |   82|  1.34k|#   define MP_DIGIT_BIT 60
  ------------------
  124|  1.34k|      }
  125|       |
  126|       |      /* grab the next msb from the exponent */
  127|  80.8k|      y     = (buf >> (mp_digit)(MP_DIGIT_BIT - 1)) & 1uL;
  ------------------
  |  |   82|  80.8k|#   define MP_DIGIT_BIT 60
  ------------------
  128|  80.8k|      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|  80.8k|      if ((mode == 0) && (y == 0)) {
  ------------------
  |  Branch (135:11): [True: 23.1k, False: 57.6k]
  |  Branch (135:26): [True: 22.4k, False: 693]
  ------------------
  136|  22.4k|         continue;
  137|  22.4k|      }
  138|       |
  139|       |      /* if the bit is zero and mode == 1 then we square */
  140|  58.3k|      if ((mode == 1) && (y == 0)) {
  ------------------
  |  Branch (140:11): [True: 22.5k, False: 35.8k]
  |  Branch (140:26): [True: 13.4k, False: 9.04k]
  ------------------
  141|  13.4k|         if ((err = mp_sqr(&res, &res)) != MP_OKAY)               goto LBL_RES;
  ------------------
  |  |  161|  13.4k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (141:14): [True: 0, False: 13.4k]
  ------------------
  142|  13.4k|         if ((err = redux(&res, P, &mu)) != MP_OKAY)              goto LBL_RES;
  ------------------
  |  |  161|  13.4k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (142:14): [True: 0, False: 13.4k]
  ------------------
  143|  13.4k|         continue;
  144|  13.4k|      }
  145|       |
  146|       |      /* else we add it to the window */
  147|  44.9k|      bitbuf |= (y << (winsize - ++bitcpy));
  148|  44.9k|      mode    = 2;
  149|       |
  150|  44.9k|      if (bitcpy == winsize) {
  ------------------
  |  Branch (150:11): [True: 9.43k, False: 35.4k]
  ------------------
  151|       |         /* ok window is filled so square as required and multiply  */
  152|       |         /* square first */
  153|  53.6k|         for (x = 0; x < winsize; x++) {
  ------------------
  |  Branch (153:22): [True: 44.1k, False: 9.43k]
  ------------------
  154|  44.1k|            if ((err = mp_sqr(&res, &res)) != MP_OKAY)            goto LBL_RES;
  ------------------
  |  |  161|  44.1k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (154:17): [True: 0, False: 44.1k]
  ------------------
  155|  44.1k|            if ((err = redux(&res, P, &mu)) != MP_OKAY)           goto LBL_RES;
  ------------------
  |  |  161|  44.1k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (155:17): [True: 0, False: 44.1k]
  ------------------
  156|  44.1k|         }
  157|       |
  158|       |         /* then multiply */
  159|  9.43k|         if ((err = mp_mul(&res, &M[bitbuf], &res)) != MP_OKAY)  goto LBL_RES;
  ------------------
  |  |  161|  9.43k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (159:14): [True: 0, False: 9.43k]
  ------------------
  160|  9.43k|         if ((err = redux(&res, P, &mu)) != MP_OKAY)             goto LBL_RES;
  ------------------
  |  |  161|  9.43k|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (160:14): [True: 0, False: 9.43k]
  ------------------
  161|       |
  162|       |         /* empty window and reset */
  163|  9.43k|         bitcpy = 0;
  164|  9.43k|         bitbuf = 0;
  165|  9.43k|         mode   = 1;
  166|  9.43k|      }
  167|  44.9k|   }
  168|       |
  169|       |   /* if bits remain then square/multiply */
  170|    846|   if ((mode == 2) && (bitcpy > 0)) {
  ------------------
  |  Branch (170:8): [True: 307, False: 539]
  |  Branch (170:23): [True: 307, False: 0]
  ------------------
  171|       |      /* square then multiply if the bit is set */
  172|  1.05k|      for (x = 0; x < bitcpy; x++) {
  ------------------
  |  Branch (172:19): [True: 752, False: 307]
  ------------------
  173|    752|         if ((err = mp_sqr(&res, &res)) != MP_OKAY)               goto LBL_RES;
  ------------------
  |  |  161|    752|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (173:14): [True: 0, False: 752]
  ------------------
  174|    752|         if ((err = redux(&res, P, &mu)) != MP_OKAY)              goto LBL_RES;
  ------------------
  |  |  161|    752|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (174:14): [True: 0, False: 752]
  ------------------
  175|       |
  176|    752|         bitbuf <<= 1;
  177|    752|         if ((bitbuf & (1 << winsize)) != 0) {
  ------------------
  |  Branch (177:14): [True: 583, False: 169]
  ------------------
  178|       |            /* then multiply */
  179|    583|            if ((err = mp_mul(&res, &M[1], &res)) != MP_OKAY)     goto LBL_RES;
  ------------------
  |  |  161|    583|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (179:17): [True: 0, False: 583]
  ------------------
  180|    583|            if ((err = redux(&res, P, &mu)) != MP_OKAY)           goto LBL_RES;
  ------------------
  |  |  161|    583|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (180:17): [True: 0, False: 583]
  ------------------
  181|    583|         }
  182|    752|      }
  183|    307|   }
  184|       |
  185|    846|   mp_exch(&res, Y);
  186|    846|   err = MP_OKAY;
  ------------------
  |  |  161|    846|#define MP_OKAY       0   /* no error */
  ------------------
  187|    846|LBL_RES:
  188|    846|   mp_clear(&res);
  189|    846|LBL_MU:
  190|    846|   mp_clear(&mu);
  191|    846|LBL_M:
  192|    846|   mp_clear(&M[1]);
  193|  7.72k|   for (x = 1<<(winsize-1); x < (1 << winsize); x++) {
  ------------------
  |  Branch (193:29): [True: 6.87k, False: 846]
  ------------------
  194|  6.87k|      mp_clear(&M[x]);
  195|  6.87k|   }
  196|    846|   return err;
  197|    846|}

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

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

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

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

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

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

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

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

s_mp_sqr_fast:
   17|   901k|{
   18|   901k|   int       olduse, pa, ix, iz;
   19|   901k|   mp_digit  W[MP_WARRAY], *tmpx;
   20|   901k|   mp_word   W1;
   21|   901k|   mp_err    err;
   22|       |
   23|       |   /* grow the destination as required */
   24|   901k|   pa = a->used + a->used;
   25|   901k|   if (b->alloc < pa) {
  ------------------
  |  Branch (25:8): [True: 976, False: 900k]
  ------------------
   26|    976|      if ((err = mp_grow(b, pa)) != MP_OKAY) {
  ------------------
  |  |  161|    976|#define MP_OKAY       0   /* no error */
  ------------------
  |  Branch (26:11): [True: 0, False: 976]
  ------------------
   27|      0|         return err;
   28|      0|      }
   29|    976|   }
   30|       |
   31|       |   /* number of output digits to produce */
   32|   901k|   W1 = 0;
   33|  10.9M|   for (ix = 0; ix < pa; ix++) {
  ------------------
  |  Branch (33:17): [True: 10.0M, False: 901k]
  ------------------
   34|  10.0M|      int      tx, ty, iy;
   35|  10.0M|      mp_word  _W;
   36|  10.0M|      mp_digit *tmpy;
   37|       |
   38|       |      /* clear counter */
   39|  10.0M|      _W = 0;
   40|       |
   41|       |      /* get offsets into the two bignums */
   42|  10.0M|      ty = MP_MIN(a->used-1, ix);
  ------------------
  |  |  156|  10.0M|#define MP_MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (156:23): [True: 5.01M, False: 5.01M]
  |  |  ------------------
  ------------------
   43|  10.0M|      tx = ix - ty;
   44|       |
   45|       |      /* setup temp aliases */
   46|  10.0M|      tmpx = a->dp + tx;
   47|  10.0M|      tmpy = a->dp + ty;
   48|       |
   49|       |      /* this is the number of times the loop will iterrate, essentially
   50|       |         while (tx++ < a->used && ty-- >= 0) { ... }
   51|       |       */
   52|  10.0M|      iy = MP_MIN(a->used-tx, ty+1);
  ------------------
  |  |  156|  10.0M|#define MP_MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (156:23): [True: 5.01M, False: 5.01M]
  |  |  ------------------
  ------------------
   53|       |
   54|       |      /* now for squaring tx can never equal ty
   55|       |       * we halve the distance since they approach at a rate of 2x
   56|       |       * and we have to round because odd cases need to be executed
   57|       |       */
   58|  10.0M|      iy = MP_MIN(iy, ((ty-tx)+1)>>1);
  ------------------
  |  |  156|  10.0M|#define MP_MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (156:23): [True: 0, False: 10.0M]
  |  |  ------------------
  ------------------
   59|       |
   60|       |      /* execute loop */
   61|  27.6M|      for (iz = 0; iz < iy; iz++) {
  ------------------
  |  Branch (61:20): [True: 17.6M, False: 10.0M]
  ------------------
   62|  17.6M|         _W += (mp_word)*tmpx++ * (mp_word)*tmpy--;
   63|  17.6M|      }
   64|       |
   65|       |      /* double the inner product and add carry */
   66|  10.0M|      _W = _W + _W + W1;
   67|       |
   68|       |      /* even columns have the square term in them */
   69|  10.0M|      if (((unsigned)ix & 1u) == 0u) {
  ------------------
  |  Branch (69:11): [True: 5.01M, False: 5.01M]
  ------------------
   70|  5.01M|         _W += (mp_word)a->dp[ix>>1] * (mp_word)a->dp[ix>>1];
   71|  5.01M|      }
   72|       |
   73|       |      /* store it */
   74|  10.0M|      W[ix] = (mp_digit)_W & MP_MASK;
  ------------------
  |  |  106|  10.0M|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|  10.0M|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
   75|       |
   76|       |      /* make next carry */
   77|  10.0M|      W1 = _W >> (mp_word)MP_DIGIT_BIT;
  ------------------
  |  |   82|  10.0M|#   define MP_DIGIT_BIT 60
  ------------------
   78|  10.0M|   }
   79|       |
   80|       |   /* setup dest */
   81|   901k|   olduse  = b->used;
   82|   901k|   b->used = a->used+a->used;
   83|       |
   84|   901k|   {
   85|   901k|      mp_digit *tmpb;
   86|   901k|      tmpb = b->dp;
   87|  10.9M|      for (ix = 0; ix < pa; ix++) {
  ------------------
  |  Branch (87:20): [True: 10.0M, False: 901k]
  ------------------
   88|  10.0M|         *tmpb++ = W[ix] & MP_MASK;
  ------------------
  |  |  106|  10.0M|#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
  |  |  ------------------
  |  |  |  |   82|  10.0M|#   define MP_DIGIT_BIT 60
  |  |  ------------------
  ------------------
   89|  10.0M|      }
   90|       |
   91|       |      /* clear unused digits [that existed in the old copy of c] */
   92|   901k|      MP_ZERO_DIGITS(tmpb, olduse - ix);
  ------------------
  |  |   89|   901k|#  define MP_ZERO_DIGITS(mem, digits)                   \
  |  |   90|   901k|do {                                                    \
  |  |   91|   901k|   int zd_ = (digits);                                  \
  |  |   92|   901k|   mp_digit* zm_ = (mem);                               \
  |  |   93|   917k|   while (zd_-- > 0) {                                  \
  |  |  ------------------
  |  |  |  Branch (93:11): [True: 16.6k, False: 901k]
  |  |  ------------------
  |  |   94|  16.6k|      *zm_++ = 0;                                       \
  |  |   95|  16.6k|   }                                                    \
  |  |   96|   901k|} while (0)
  |  |  ------------------
  |  |  |  Branch (96:10): [Folded, False: 901k]
  |  |  ------------------
  ------------------
   93|   901k|   }
   94|   901k|   mp_clamp(b);
   95|   901k|   return MP_OKAY;
  ------------------
  |  |  161|   901k|#define MP_OKAY       0   /* no error */
  ------------------
   96|   901k|}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

