LLVMFuzzerTestOneInput:
   21|  1.08k|int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
   22|  1.08k|    struct rsa_public_key pub;
   23|  1.08k|    struct asn1_der_iterator iter;
   24|       |
   25|  1.08k|    rsa_public_key_init(&pub);
  ------------------
  |  |   49|  1.08k|#define rsa_public_key_init nettle_rsa_public_key_init
  ------------------
   26|       |
   27|  1.08k|    if (asn1_der_iterator_first(&iter, size, data) == ASN1_ITERATOR_CONSTRUCTED) {
  ------------------
  |  |   44|  1.08k|#define asn1_der_iterator_first nettle_asn1_der_iterator_first
  ------------------
  |  Branch (27:9): [True: 896, False: 189]
  ------------------
   28|    896|        rsa_public_key_from_der_iterator(&pub, 0, &iter);
  ------------------
  |  |  104|    896|#define rsa_public_key_from_der_iterator nettle_rsa_public_key_from_der_iterator
  ------------------
   29|    896|    }
   30|       |
   31|  1.08k|    rsa_public_key_clear(&pub);
  ------------------
  |  |   50|  1.08k|#define rsa_public_key_clear nettle_rsa_public_key_clear
  ------------------
   32|  1.08k|    return 0;
   33|  1.08k|}

nettle_mpz_set_str_256_s:
  160|  1.09k|{
  161|  1.09k|  if (!length)
  ------------------
  |  Branch (161:7): [True: 2, False: 1.09k]
  ------------------
  162|      2|    {
  163|      2|      mpz_set_ui(x, 0);
  164|      2|      return;
  165|      2|    }
  166|       |  
  167|  1.09k|  nettle_mpz_from_octets(x, length, s);
  ------------------
  |  |  140|  1.09k|   mpz_import((x), (length), 1, 1, 0, 0, (s))
  ------------------
  168|       |
  169|  1.09k|  if (s[0] & 0x80)
  ------------------
  |  Branch (169:7): [True: 389, False: 707]
  ------------------
  170|    389|    {
  171|    389|      mpz_t t;
  172|       |
  173|    389|      mpz_init_set_ui(t, 1);
  174|    389|      mpz_mul_2exp(t, t, length*8);
  175|    389|      mpz_sub(x, x, t);
  176|    389|      mpz_clear(t);
  177|    389|    }
  178|  1.09k|}

nettle_asn1_der_iterator_next:
  112|  2.60k|{
  113|  2.60k|  uint8_t tag;
  114|       |  
  115|  2.60k|  if (!LEFT(i))
  ------------------
  |  |  106|  2.60k|#define LEFT(i) ((i)->buffer_length - (i)->pos)
  ------------------
  |  Branch (115:7): [True: 366, False: 2.24k]
  ------------------
  116|    366|    return ASN1_ITERATOR_END;
  117|       |
  118|  2.24k|  tag = NEXT(i);
  ------------------
  |  |  107|  2.24k|#define NEXT(i) ((i)->buffer[(i)->pos++])
  ------------------
  119|  2.24k|  if (!LEFT(i))
  ------------------
  |  |  106|  2.24k|#define LEFT(i) ((i)->buffer_length - (i)->pos)
  ------------------
  |  Branch (119:7): [True: 17, False: 2.22k]
  ------------------
  120|     17|    return ASN1_ITERATOR_ERROR;
  121|       |
  122|  2.22k|  if ( (tag & TAG_MASK) == TAG_MASK)
  ------------------
  |  Branch (122:8): [True: 5, False: 2.21k]
  ------------------
  123|      5|    {
  124|       |      /* FIXME: Long tags not supported */
  125|      5|      return ASN1_ITERATOR_ERROR;
  126|      5|    }
  127|       |
  128|  2.21k|  i->length = NEXT(i);
  ------------------
  |  |  107|  2.21k|#define NEXT(i) ((i)->buffer[(i)->pos++])
  ------------------
  129|  2.21k|  if (i->length & 0x80)
  ------------------
  |  Branch (129:7): [True: 530, False: 1.68k]
  ------------------
  130|    530|    {
  131|    530|      unsigned k = i->length & 0x7f;
  132|    530|      unsigned j;
  133|    530|      const uint8_t *data = i->buffer + i->pos;
  134|       |      
  135|    530|      if (k == 0)
  ------------------
  |  Branch (135:11): [True: 1, False: 529]
  ------------------
  136|       |	/* Indefinite encoding. Not supported. */
  137|      1|	return ASN1_ITERATOR_ERROR;
  138|       |
  139|    529|      if (LEFT(i) < k)
  ------------------
  |  |  106|    529|#define LEFT(i) ((i)->buffer_length - (i)->pos)
  ------------------
  |  Branch (139:11): [True: 15, False: 514]
  ------------------
  140|     15|	return ASN1_ITERATOR_ERROR;
  141|       |
  142|    514|      if (k > sizeof(i->length))
  ------------------
  |  Branch (142:11): [True: 21, False: 493]
  ------------------
  143|     21|	return ASN1_ITERATOR_ERROR;
  144|       |
  145|    493|      i->pos += k;
  146|    493|      i->length = data[0];
  147|    493|      if (i->length == 0
  ------------------
  |  Branch (147:11): [True: 1, False: 492]
  ------------------
  148|    492|	  || (k == 1 && i->length < 0x80))
  ------------------
  |  Branch (148:8): [True: 84, False: 408]
  |  Branch (148:18): [True: 7, False: 77]
  ------------------
  149|      8|	return ASN1_ITERATOR_ERROR;
  150|       |
  151|  1.45k|      for (j = 1; j < k; j++)
  ------------------
  |  Branch (151:19): [True: 967, False: 485]
  ------------------
  152|    967|	i->length = (i->length << 8) | data[j];
  153|    485|    }
  154|  2.17k|  if (LEFT(i) < i->length)
  ------------------
  |  |  106|  2.17k|#define LEFT(i) ((i)->buffer_length - (i)->pos)
  ------------------
  |  Branch (154:7): [True: 150, False: 2.02k]
  ------------------
  155|    150|    return ASN1_ITERATOR_ERROR;
  156|       |
  157|  2.02k|  i->data = i->buffer + i->pos;
  158|  2.02k|  i->pos += i->length;
  159|       |
  160|  2.02k|  i->type = tag & TAG_MASK;
  161|  2.02k|  i->type |= (tag & CLASS_MASK) << (ASN1_CLASS_SHIFT - 6);
  162|  2.02k|  if (tag & CONSTRUCTED_MASK)
  ------------------
  |  Branch (162:7): [True: 900, False: 1.12k]
  ------------------
  163|    900|    {
  164|    900|      i->type |= ASN1_TYPE_CONSTRUCTED;
  165|    900|      return ASN1_ITERATOR_CONSTRUCTED;
  166|    900|    }
  167|  1.12k|  else
  168|  1.12k|    return ASN1_ITERATOR_PRIMITIVE;
  169|  2.02k|}
nettle_asn1_der_iterator_first:
  174|  1.90k|{
  175|  1.90k|  asn1_der_iterator_init(i, length, input);
  176|  1.90k|  return asn1_der_iterator_next(i);
  ------------------
  |  |   45|  1.90k|#define asn1_der_iterator_next nettle_asn1_der_iterator_next
  ------------------
  177|  1.90k|}
nettle_asn1_der_decode_constructed:
  182|    816|{
  183|    816|  assert(i->type & ASN1_TYPE_CONSTRUCTED);
  ------------------
  |  Branch (183:3): [True: 0, False: 816]
  |  Branch (183:3): [True: 816, False: 0]
  ------------------
  184|    816|  return asn1_der_iterator_first(contents, i->length, i->data);
  ------------------
  |  |   44|    816|#define asn1_der_iterator_first nettle_asn1_der_iterator_first
  ------------------
  185|    816|}
nettle_asn1_der_decode_constructed_last:
  189|    878|{
  190|    878|  if (LEFT(i) > 0)
  ------------------
  |  |  106|    878|#define LEFT(i) ((i)->buffer_length - (i)->pos)
  ------------------
  |  Branch (190:7): [True: 62, False: 816]
  ------------------
  191|     62|    return ASN1_ITERATOR_ERROR;
  192|       |
  193|    816|  return asn1_der_decode_constructed(i, i);
  ------------------
  |  |   46|    816|#define asn1_der_decode_constructed nettle_asn1_der_decode_constructed
  ------------------
  194|    878|}
nettle_asn1_der_get_bignum:
  261|  1.10k|{
  262|  1.10k|  if (i->length > 1
  ------------------
  |  Branch (262:7): [True: 792, False: 316]
  ------------------
  263|    792|      && ((i->data[0] == 0 && i->data[1] < 0x80)
  ------------------
  |  Branch (263:12): [True: 270, False: 522]
  |  Branch (263:31): [True: 6, False: 264]
  ------------------
  264|    786|	  || (i->data[0] == 0xff && i->data[1] >= 0x80)))
  ------------------
  |  Branch (264:8): [True: 121, False: 665]
  |  Branch (264:30): [True: 4, False: 117]
  ------------------
  265|       |    /* Non-minimal number of digits */
  266|     10|    return 0;
  267|       |
  268|       |  /* Allow some extra here, for leading sign octets. */
  269|  1.09k|  if (max_bits && (8 * i->length > (16 + max_bits)))
  ------------------
  |  Branch (269:7): [True: 0, False: 1.09k]
  |  Branch (269:19): [True: 0, False: 0]
  ------------------
  270|      0|    return 0;
  271|       |
  272|  1.09k|  nettle_mpz_set_str_256_s(x, i->length, i->data);
  273|       |
  274|       |  /* FIXME: How to interpret a max_bits for negative numbers? */
  275|  1.09k|  if (max_bits && mpz_sizeinbase(x, 2) > max_bits)
  ------------------
  |  Branch (275:7): [True: 0, False: 1.09k]
  |  Branch (275:19): [True: 0, False: 0]
  ------------------
  276|      0|    return 0;
  277|       |
  278|  1.09k|  return 1;
  279|  1.09k|}
der-iterator.c:asn1_der_iterator_init:
   97|  1.90k|{
   98|  1.90k|  iterator->buffer_length = length;
   99|  1.90k|  iterator->buffer = input;
  100|  1.90k|  iterator->pos = 0;
  101|  1.90k|  iterator->type = 0;
  102|  1.90k|  iterator->length = 0;
  103|       |  iterator->data = NULL;
  104|  1.90k|}

nettle_rsa_public_key_from_der_iterator:
   53|    896|{
   54|       |  /* RSAPublicKey ::= SEQUENCE {
   55|       |         modulus           INTEGER,  -- n
   56|       |	 publicExponent    INTEGER   -- e
   57|       |      }
   58|       |  */
   59|       |
   60|    896|  return (i->type == ASN1_SEQUENCE
  ------------------
  |  Branch (60:11): [True: 878, False: 18]
  ------------------
   61|    878|	  && asn1_der_decode_constructed_last(i) == ASN1_ITERATOR_PRIMITIVE
  ------------------
  |  |   47|    878|#define asn1_der_decode_constructed_last nettle_asn1_der_decode_constructed_last
  ------------------
  |  Branch (61:7): [True: 812, False: 66]
  ------------------
   62|    812|	  && asn1_der_get_bignum(i, pub->n, limit) 
  ------------------
  |  |   51|    812|#define asn1_der_get_bignum nettle_asn1_der_get_bignum
  ------------------
  |  Branch (62:7): [True: 803, False: 9]
  ------------------
   63|    803|	  && mpz_sgn(pub->n) > 0
  ------------------
  |  Branch (63:7): [True: 413, False: 390]
  ------------------
   64|    413|	  && GET(i, pub->e, limit)
  ------------------
  |  |   43|  1.30k|#define GET(i, x, l)					\
  |  |   44|  1.30k|(asn1_der_iterator_next((i)) == ASN1_ITERATOR_PRIMITIVE	\
  |  |  ------------------
  |  |  |  |   45|    413|#define asn1_der_iterator_next nettle_asn1_der_iterator_next
  |  |  ------------------
  |  |  |  Branch (44:2): [True: 305, False: 108]
  |  |  ------------------
  |  |   45|    413| && (i)->type == ASN1_INTEGER				\
  |  |  ------------------
  |  |  |  Branch (45:5): [True: 296, False: 9]
  |  |  ------------------
  |  |   46|    413| && asn1_der_get_bignum((i), (x), (l))			\
  |  |  ------------------
  |  |  |  |   51|    296|#define asn1_der_get_bignum nettle_asn1_der_get_bignum
  |  |  ------------------
  |  |  |  Branch (46:5): [True: 295, False: 1]
  |  |  ------------------
  |  |   47|  1.30k| && mpz_sgn((x)) > 0)
  |  |  ------------------
  |  |  |  Branch (47:5): [True: 292, False: 3]
  |  |  ------------------
  ------------------
   65|    292|	  && asn1_der_iterator_next(i) == ASN1_ITERATOR_END
  ------------------
  |  |   45|    292|#define asn1_der_iterator_next nettle_asn1_der_iterator_next
  ------------------
  |  Branch (65:7): [True: 281, False: 11]
  ------------------
   66|    281|	  && rsa_public_key_prepare(pub));
  ------------------
  |  |   51|    281|#define rsa_public_key_prepare nettle_rsa_public_key_prepare
  ------------------
  |  Branch (66:7): [True: 41, False: 240]
  ------------------
   67|    896|}

mpn_copyd:
  404|    105|{
  405|    210|  while (--n >= 0)
  ------------------
  |  Branch (405:10): [True: 105, False: 105]
  ------------------
  406|    105|    d[n] = s[n];
  407|    105|}
mpn_cmp:
  411|    284|{
  412|    284|  while (--n >= 0)
  ------------------
  |  Branch (412:10): [True: 284, False: 0]
  ------------------
  413|    284|    {
  414|    284|      if (ap[n] != bp[n])
  ------------------
  |  Branch (414:11): [True: 284, False: 0]
  ------------------
  415|    284|	return ap[n] > bp[n] ? 1 : -1;
  ------------------
  |  Branch (415:9): [True: 0, False: 284]
  ------------------
  416|    284|    }
  417|      0|  return 0;
  418|    284|}
mpn_zero:
  445|    389|{
  446|   925k|  while (--n >= 0)
  ------------------
  |  Branch (446:10): [True: 924k, False: 389]
  ------------------
  447|   924k|    rp[n] = 0;
  448|    389|}
mpn_sub_1:
  503|    105|{
  504|    105|  mp_size_t i;
  505|       |
  506|    105|  assert (n > 0);
  ------------------
  |  Branch (506:3): [True: 0, False: 105]
  |  Branch (506:3): [True: 105, False: 0]
  ------------------
  507|       |
  508|    105|  i = 0;
  509|    105|  do
  510|    105|    {
  511|    105|      mp_limb_t a = ap[i];
  512|       |      /* Carry out */
  513|    105|      mp_limb_t cy = a < b;
  514|    105|      rp[i] = a - b;
  515|    105|      b = cy;
  516|    105|    }
  517|    105|  while (++i < n);
  ------------------
  |  Branch (517:10): [True: 0, False: 105]
  ------------------
  518|       |
  519|    105|  return b;
  520|    105|}
mpn_sub_n:
  524|    389|{
  525|    389|  mp_size_t i;
  526|    389|  mp_limb_t cy;
  527|       |
  528|   925k|  for (i = 0, cy = 0; i < n; i++)
  ------------------
  |  Branch (528:23): [True: 925k, False: 389]
  ------------------
  529|   925k|    {
  530|   925k|      mp_limb_t a, b;
  531|   925k|      a = ap[i]; b = bp[i];
  532|   925k|      b += cy;
  533|   925k|      cy = (b < cy);
  534|   925k|      cy += (a < b);
  535|   925k|      rp[i] = a - b;
  536|   925k|    }
  537|    389|  return cy;
  538|    389|}
mpn_sub:
  542|    389|{
  543|    389|  mp_limb_t cy;
  544|       |
  545|    389|  assert (an >= bn);
  ------------------
  |  Branch (545:3): [True: 0, False: 389]
  |  Branch (545:3): [True: 389, False: 0]
  ------------------
  546|       |
  547|    389|  cy = mpn_sub_n (rp, ap, bp, bn);
  548|    389|  if (an > bn)
  ------------------
  |  Branch (548:7): [True: 105, False: 284]
  ------------------
  549|    105|    cy = mpn_sub_1 (rp + bn, ap + bn, an - bn, cy);
  550|    389|  return cy;
  551|    389|}
mpn_lshift:
  667|    284|{
  668|    284|  mp_limb_t high_limb, low_limb;
  669|    284|  unsigned int tnc;
  670|    284|  mp_limb_t retval;
  671|       |
  672|    284|  assert (n >= 1);
  ------------------
  |  Branch (672:3): [True: 0, False: 284]
  |  Branch (672:3): [True: 284, False: 0]
  ------------------
  673|    284|  assert (cnt >= 1);
  ------------------
  |  Branch (673:3): [True: 0, False: 284]
  |  Branch (673:3): [True: 284, False: 0]
  ------------------
  674|    284|  assert (cnt < GMP_LIMB_BITS);
  ------------------
  |  Branch (674:3): [True: 0, False: 284]
  |  Branch (674:3): [True: 284, False: 0]
  ------------------
  675|       |
  676|    284|  up += n;
  677|    284|  rp += n;
  678|       |
  679|    284|  tnc = GMP_LIMB_BITS - cnt;
  ------------------
  |  |   64|    284|#define GMP_LIMB_BITS (sizeof(mp_limb_t) * CHAR_BIT)
  ------------------
  680|    284|  low_limb = *--up;
  681|    284|  retval = low_limb >> tnc;
  682|    284|  high_limb = (low_limb << cnt);
  683|       |
  684|    284|  while (--n != 0)
  ------------------
  |  Branch (684:10): [True: 0, False: 284]
  ------------------
  685|      0|    {
  686|      0|      low_limb = *--up;
  687|      0|      *--rp = high_limb | (low_limb >> tnc);
  688|      0|      high_limb = (low_limb << cnt);
  689|      0|    }
  690|    284|  *--rp = high_limb;
  691|       |
  692|    284|  return retval;
  693|    284|}
mpz_init:
 1436|  2.55k|{
 1437|  2.55k|  static const mp_limb_t dummy_limb = GMP_LIMB_MAX & 0xc1a0;
  ------------------
  |  |   66|  2.55k|#define GMP_LIMB_MAX ((mp_limb_t) ~ (mp_limb_t) 0)
  ------------------
 1438|       |
 1439|  2.55k|  r->_mp_alloc = 0;
 1440|  2.55k|  r->_mp_size = 0;
 1441|  2.55k|  r->_mp_d = (mp_ptr) &dummy_limb;
 1442|  2.55k|}
mpz_clear:
 1461|  2.55k|{
 1462|  2.55k|  if (r->_mp_alloc)
  ------------------
  |  Branch (1462:7): [True: 1.48k, False: 1.07k]
  ------------------
 1463|  1.48k|    gmp_free_limbs (r->_mp_d, r->_mp_alloc);
 1464|  2.55k|}
mpz_set_ui:
 1509|    391|{
 1510|    391|  if (x > 0)
  ------------------
  |  Branch (1510:7): [True: 389, False: 2]
  ------------------
 1511|    389|    {
 1512|    389|      r->_mp_size = 1;
 1513|    389|      MPZ_REALLOC (r, 1)[0] = x;
  ------------------
  |  | 1484|    389|#define MPZ_REALLOC(z,n) ((n) > (z)->_mp_alloc			\
  |  |  ------------------
  |  |  |  Branch (1484:27): [True: 389, False: 0]
  |  |  ------------------
  |  | 1485|    389|			  ? mpz_realloc(z,n)			\
  |  | 1486|    389|			  : (z)->_mp_d)
  ------------------
 1514|    389|      if (GMP_LIMB_BITS < GMP_ULONG_BITS)
  ------------------
  |  |   64|    389|#define GMP_LIMB_BITS (sizeof(mp_limb_t) * CHAR_BIT)
  ------------------
                    if (GMP_LIMB_BITS < GMP_ULONG_BITS)
  ------------------
  |  |   72|    389|#define GMP_ULONG_BITS (sizeof(unsigned long) * CHAR_BIT)
  ------------------
  |  Branch (1514:11): [Folded, False: 389]
  ------------------
 1515|      0|	{
 1516|      0|	  int LOCAL_GMP_LIMB_BITS = GMP_LIMB_BITS;
  ------------------
  |  |   64|      0|#define GMP_LIMB_BITS (sizeof(mp_limb_t) * CHAR_BIT)
  ------------------
 1517|      0|	  while (x >>= LOCAL_GMP_LIMB_BITS)
  ------------------
  |  Branch (1517:11): [True: 0, False: 0]
  ------------------
 1518|      0|	    {
 1519|      0|	      ++ r->_mp_size;
 1520|      0|	      MPZ_REALLOC (r, r->_mp_size)[r->_mp_size - 1] = x;
  ------------------
  |  | 1484|      0|#define MPZ_REALLOC(z,n) ((n) > (z)->_mp_alloc			\
  |  |  ------------------
  |  |  |  Branch (1484:27): [True: 0, False: 0]
  |  |  ------------------
  |  | 1485|      0|			  ? mpz_realloc(z,n)			\
  |  | 1486|      0|			  : (z)->_mp_d)
  ------------------
 1521|      0|	    }
 1522|      0|	}
 1523|    389|    }
 1524|      2|  else
 1525|      2|    r->_mp_size = 0;
 1526|    391|}
mpz_init_set_ui:
 1554|    389|{
 1555|    389|  mpz_init (r);
 1556|    389|  mpz_set_ui (r, x);
 1557|    389|}
mpz_sgn:
 1875|  1.09k|{
 1876|  1.09k|  return GMP_CMP (u->_mp_size, 0);
  ------------------
  |  |   81|  1.09k|#define GMP_CMP(a,b) (((a) > (b)) - ((a) < (b)))
  ------------------
 1877|  1.09k|}
mpz_sub:
 2048|    389|{
 2049|    389|  mp_size_t rn;
 2050|       |
 2051|    389|  if ( (a->_mp_size ^ b->_mp_size) >= 0)
  ------------------
  |  Branch (2051:8): [True: 389, False: 0]
  ------------------
 2052|    389|    rn = mpz_abs_sub (r, a, b);
 2053|      0|  else
 2054|      0|    rn = mpz_abs_add (r, a, b);
 2055|       |
 2056|    389|  r->_mp_size = a->_mp_size >= 0 ? rn : - rn;
  ------------------
  |  Branch (2056:17): [True: 389, False: 0]
  ------------------
 2057|    389|}
mpz_mul_2exp:
 2123|    389|{
 2124|    389|  mp_size_t un, rn;
 2125|    389|  mp_size_t limbs;
 2126|    389|  unsigned shift;
 2127|    389|  mp_ptr rp;
 2128|       |
 2129|    389|  un = GMP_ABS (u->_mp_size);
  ------------------
  |  |   75|    389|#define GMP_ABS(x) ((x) >= 0 ? (x) : -(x))
  |  |  ------------------
  |  |  |  Branch (75:21): [True: 389, False: 0]
  |  |  ------------------
  ------------------
 2130|    389|  if (un == 0)
  ------------------
  |  Branch (2130:7): [True: 0, False: 389]
  ------------------
 2131|      0|    {
 2132|      0|      r->_mp_size = 0;
 2133|      0|      return;
 2134|      0|    }
 2135|       |
 2136|    389|  limbs = bits / GMP_LIMB_BITS;
  ------------------
  |  |   64|    389|#define GMP_LIMB_BITS (sizeof(mp_limb_t) * CHAR_BIT)
  ------------------
 2137|    389|  shift = bits % GMP_LIMB_BITS;
  ------------------
  |  |   64|    389|#define GMP_LIMB_BITS (sizeof(mp_limb_t) * CHAR_BIT)
  ------------------
 2138|       |
 2139|    389|  rn = un + limbs + (shift > 0);
 2140|    389|  rp = MPZ_REALLOC (r, rn);
  ------------------
  |  | 1484|    389|#define MPZ_REALLOC(z,n) ((n) > (z)->_mp_alloc			\
  |  |  ------------------
  |  |  |  Branch (1484:27): [True: 389, False: 0]
  |  |  ------------------
  |  | 1485|    389|			  ? mpz_realloc(z,n)			\
  |  | 1486|    389|			  : (z)->_mp_d)
  ------------------
 2141|    389|  if (shift > 0)
  ------------------
  |  Branch (2141:7): [True: 284, False: 105]
  ------------------
 2142|    284|    {
 2143|    284|      mp_limb_t cy = mpn_lshift (rp + limbs, u->_mp_d, un, shift);
 2144|    284|      rp[rn-1] = cy;
 2145|    284|      rn -= (cy == 0);
 2146|    284|    }
 2147|    105|  else
 2148|    105|    mpn_copyd (rp + limbs, u->_mp_d, un);
 2149|       |
 2150|    389|  mpn_zero (rp, limbs);
 2151|       |
 2152|    389|  r->_mp_size = (u->_mp_size < 0) ? - rn : rn;
  ------------------
  |  Branch (2152:17): [True: 0, False: 389]
  ------------------
 2153|    389|}
mpz_sizeinbase:
 4236|    279|{
 4237|    279|  mp_size_t un, tn;
 4238|    279|  mp_srcptr up;
 4239|    279|  mp_ptr tp;
 4240|    279|  mp_bitcnt_t bits;
 4241|    279|  struct gmp_div_inverse bi;
 4242|    279|  size_t ndigits;
 4243|       |
 4244|    279|  assert (base >= 2);
  ------------------
  |  Branch (4244:3): [True: 0, False: 279]
  |  Branch (4244:3): [True: 279, False: 0]
  ------------------
 4245|    279|  assert (base <= 62);
  ------------------
  |  Branch (4245:3): [True: 0, False: 279]
  |  Branch (4245:3): [True: 279, False: 0]
  ------------------
 4246|       |
 4247|    279|  un = GMP_ABS (u->_mp_size);
  ------------------
  |  |   75|    279|#define GMP_ABS(x) ((x) >= 0 ? (x) : -(x))
  |  |  ------------------
  |  |  |  Branch (75:21): [True: 279, False: 0]
  |  |  ------------------
  ------------------
 4248|    279|  if (un == 0)
  ------------------
  |  Branch (4248:7): [True: 0, False: 279]
  ------------------
 4249|      0|    return 1;
 4250|       |
 4251|    279|  up = u->_mp_d;
 4252|       |
 4253|    279|  bits = (un - 1) * GMP_LIMB_BITS + mpn_limb_size_in_base_2 (up[un-1]);
  ------------------
  |  |   64|    279|#define GMP_LIMB_BITS (sizeof(mp_limb_t) * CHAR_BIT)
  ------------------
 4254|    279|  switch (base)
  ------------------
  |  Branch (4254:11): [True: 279, False: 0]
  ------------------
 4255|    279|    {
 4256|    279|    case 2:
  ------------------
  |  Branch (4256:5): [True: 279, False: 0]
  ------------------
 4257|    279|      return bits;
 4258|      0|    case 4:
  ------------------
  |  Branch (4258:5): [True: 0, False: 279]
  ------------------
 4259|      0|      return (bits + 1) / 2;
 4260|      0|    case 8:
  ------------------
  |  Branch (4260:5): [True: 0, False: 279]
  ------------------
 4261|      0|      return (bits + 2) / 3;
 4262|      0|    case 16:
  ------------------
  |  Branch (4262:5): [True: 0, False: 279]
  ------------------
 4263|      0|      return (bits + 3) / 4;
 4264|      0|    case 32:
  ------------------
  |  Branch (4264:5): [True: 0, False: 279]
  ------------------
 4265|      0|      return (bits + 4) / 5;
 4266|       |      /* FIXME: Do something more clever for the common case of base
 4267|       |	 10. */
 4268|    279|    }
 4269|       |
 4270|      0|  tp = gmp_alloc_limbs (un);
 4271|      0|  mpn_copyi (tp, up, un);
 4272|      0|  mpn_div_qr_1_invert (&bi, base);
 4273|       |
 4274|      0|  tn = un;
 4275|      0|  ndigits = 0;
 4276|      0|  do
 4277|      0|    {
 4278|      0|      ndigits++;
 4279|      0|      mpn_div_qr_1_preinv (tp, tp, tn, &bi);
 4280|      0|      tn -= (tp[tn-1] == 0);
 4281|      0|    }
 4282|      0|  while (tn > 0);
  ------------------
  |  Branch (4282:10): [True: 0, False: 0]
  ------------------
 4283|       |
 4284|      0|  gmp_free_limbs (tp, un);
 4285|      0|  return ndigits;
 4286|    279|}
mpz_import:
 4504|  1.09k|{
 4505|  1.09k|  const unsigned char *p;
 4506|  1.09k|  ptrdiff_t word_step;
 4507|  1.09k|  mp_ptr rp;
 4508|  1.09k|  mp_size_t rn;
 4509|       |
 4510|       |  /* The current (partial) limb. */
 4511|  1.09k|  mp_limb_t limb;
 4512|       |  /* The number of bytes already copied to this limb (starting from
 4513|       |     the low end). */
 4514|  1.09k|  size_t bytes;
 4515|       |  /* The index where the limb should be stored, when completed. */
 4516|  1.09k|  mp_size_t i;
 4517|       |
 4518|  1.09k|  if (nails != 0)
  ------------------
  |  Branch (4518:7): [True: 0, False: 1.09k]
  ------------------
 4519|      0|    gmp_die ("mpz_import: Nails not supported.");
 4520|       |
 4521|  1.09k|  assert (order == 1 || order == -1);
  ------------------
  |  Branch (4521:3): [True: 1.09k, False: 0]
  |  Branch (4521:3): [True: 0, False: 0]
  |  Branch (4521:3): [True: 1.09k, False: 0]
  |  Branch (4521:3): [True: 0, False: 0]
  ------------------
 4522|  1.09k|  assert (endian >= -1 && endian <= 1);
  ------------------
  |  Branch (4522:3): [True: 0, False: 1.09k]
  |  Branch (4522:3): [True: 0, False: 0]
  |  Branch (4522:3): [True: 1.09k, False: 0]
  |  Branch (4522:3): [True: 1.09k, False: 0]
  ------------------
 4523|       |
 4524|  1.09k|  if (count == 0)
  ------------------
  |  Branch (4524:7): [True: 0, False: 1.09k]
  ------------------
 4525|      0|    {
 4526|      0|      r->_mp_size = 0;
 4527|      0|      return;
 4528|      0|    }
 4529|  1.09k|  if (endian == 0)
  ------------------
  |  Branch (4529:7): [True: 1.09k, False: 0]
  ------------------
 4530|  1.09k|    endian = gmp_detect_endian ();
 4531|       |
 4532|  1.09k|  p = (unsigned char *) src;
 4533|       |
 4534|  1.09k|  word_step = (order != endian) ? 2 * size : 0;
  ------------------
  |  Branch (4534:15): [True: 1.09k, False: 0]
  ------------------
 4535|       |
 4536|       |  /* Process bytes from the least significant end, so point p at the
 4537|       |     least significant word. */
 4538|  1.09k|  if (order == 1)
  ------------------
  |  Branch (4538:7): [True: 1.09k, False: 0]
  ------------------
 4539|  1.09k|    {
 4540|  1.09k|      p += size * (count - 1);
 4541|  1.09k|      word_step = - word_step;
 4542|  1.09k|    }
 4543|       |
 4544|       |  /* And at least significant byte of that word. */
 4545|  1.09k|  if (endian == 1)
  ------------------
  |  Branch (4545:7): [True: 0, False: 1.09k]
  ------------------
 4546|      0|    p += (size - 1);
 4547|       |
 4548|  1.09k|  rn = (size * count + sizeof(mp_limb_t) - 1) / sizeof(mp_limb_t);
 4549|  1.09k|  rp = MPZ_REALLOC (r, rn);
  ------------------
  |  | 1484|  1.09k|#define MPZ_REALLOC(z,n) ((n) > (z)->_mp_alloc			\
  |  |  ------------------
  |  |  |  Branch (1484:27): [True: 1.09k, False: 0]
  |  |  ------------------
  |  | 1485|  1.09k|			  ? mpz_realloc(z,n)			\
  |  | 1486|  1.09k|			  : (z)->_mp_d)
  ------------------
 4550|       |
 4551|  9.62M|  for (limb = 0, bytes = 0, i = 0; count > 0; count--, p += word_step)
  ------------------
  |  Branch (4551:36): [True: 9.62M, False: 1.09k]
  ------------------
 4552|  9.62M|    {
 4553|  9.62M|      size_t j;
 4554|  19.2M|      for (j = 0; j < size; j++, p -= (ptrdiff_t) endian)
  ------------------
  |  Branch (4554:19): [True: 9.62M, False: 9.62M]
  ------------------
 4555|  9.62M|	{
 4556|  9.62M|	  limb |= (mp_limb_t) *p << (bytes++ * CHAR_BIT);
 4557|  9.62M|	  if (bytes == sizeof(mp_limb_t))
  ------------------
  |  Branch (4557:8): [True: 1.20M, False: 8.41M]
  ------------------
 4558|  1.20M|	    {
 4559|  1.20M|	      rp[i++] = limb;
 4560|  1.20M|	      bytes = 0;
 4561|  1.20M|	      limb = 0;
 4562|  1.20M|	    }
 4563|  9.62M|	}
 4564|  9.62M|    }
 4565|  1.09k|  assert (i + (bytes > 0) == rn);
  ------------------
  |  Branch (4565:3): [True: 0, False: 1.09k]
  |  Branch (4565:3): [True: 1.09k, False: 0]
  ------------------
 4566|  1.09k|  if (limb != 0)
  ------------------
  |  Branch (4566:7): [True: 778, False: 318]
  ------------------
 4567|    778|    rp[i++] = limb;
 4568|    318|  else
 4569|    318|    i = mpn_normalized_size (rp, i);
 4570|       |
 4571|  1.09k|  r->_mp_size = i;
 4572|  1.09k|}
mini-gmp.c:gmp_default_alloc:
  301|  1.48k|{
  302|  1.48k|  void *p;
  303|       |
  304|  1.48k|  assert (size > 0);
  ------------------
  |  Branch (304:3): [True: 0, False: 1.48k]
  |  Branch (304:3): [True: 1.48k, False: 0]
  ------------------
  305|       |
  306|  1.48k|  p = malloc (size);
  307|  1.48k|  if (!p)
  ------------------
  |  Branch (307:7): [True: 0, False: 1.48k]
  ------------------
  308|      0|    gmp_die("gmp_default_alloc: Virtual memory exhausted.");
  309|       |
  310|  1.48k|  return p;
  311|  1.48k|}
mini-gmp.c:gmp_default_realloc:
  315|    494|{
  316|    494|  void * p;
  317|       |
  318|    494|  p = realloc (old, new_size);
  319|       |
  320|    494|  if (!p)
  ------------------
  |  Branch (320:7): [True: 0, False: 494]
  ------------------
  321|      0|    gmp_die("gmp_default_realloc: Virtual memory exhausted.");
  322|       |
  323|    494|  return p;
  324|    494|}
mini-gmp.c:gmp_default_free:
  328|  1.48k|{
  329|  1.48k|  free (p);
  330|  1.48k|}
mini-gmp.c:mpn_normalized_size:
  431|    707|{
  432|    882|  while (n > 0 && xp[n-1] == 0)
  ------------------
  |  Branch (432:10): [True: 880, False: 2]
  |  Branch (432:19): [True: 175, False: 705]
  ------------------
  433|    175|    --n;
  434|    707|  return n;
  435|    707|}
mini-gmp.c:gmp_alloc_limbs:
  374|  1.48k|{
  375|  1.48k|  return (mp_ptr) gmp_alloc (size * sizeof (mp_limb_t));
  ------------------
  |  |  368|  1.48k|#define gmp_alloc(size) ((*gmp_allocate_func)((size)))
  ------------------
  376|  1.48k|}
mini-gmp.c:gmp_free_limbs:
  387|  1.48k|{
  388|  1.48k|  gmp_free (old, size * sizeof (mp_limb_t));
  ------------------
  |  |  369|  1.48k|#define gmp_free(p, size) ((*gmp_free_func) ((p), (size)))
  ------------------
  389|  1.48k|}
mini-gmp.c:mpz_realloc:
 1468|  1.97k|{
 1469|  1.97k|  size = GMP_MAX (size, 1);
  ------------------
  |  |   79|  1.97k|#define GMP_MAX(a, b) ((a) > (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (79:24): [True: 908, False: 1.07k]
  |  |  ------------------
  ------------------
 1470|       |
 1471|  1.97k|  if (r->_mp_alloc)
  ------------------
  |  Branch (1471:7): [True: 494, False: 1.48k]
  ------------------
 1472|    494|    r->_mp_d = gmp_realloc_limbs (r->_mp_d, r->_mp_alloc, size);
 1473|  1.48k|  else
 1474|  1.48k|    r->_mp_d = gmp_alloc_limbs (size);
 1475|  1.97k|  r->_mp_alloc = size;
 1476|       |
 1477|  1.97k|  if (GMP_ABS (r->_mp_size) > size)
  ------------------
  |  |   75|  1.97k|#define GMP_ABS(x) ((x) >= 0 ? (x) : -(x))
  |  |  ------------------
  |  |  |  Branch (75:21): [True: 1.97k, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (1477:7): [True: 0, False: 1.97k]
  ------------------
 1478|      0|    r->_mp_size = 0;
 1479|       |
 1480|  1.97k|  return r->_mp_d;
 1481|  1.97k|}
mini-gmp.c:gmp_realloc_limbs:
  380|    494|{
  381|    494|  assert (size > 0);
  ------------------
  |  Branch (381:3): [True: 0, False: 494]
  |  Branch (381:3): [True: 494, False: 0]
  ------------------
  382|    494|  return (mp_ptr) gmp_realloc (old, old_size * sizeof (mp_limb_t), size * sizeof (mp_limb_t));
  ------------------
  |  |  370|    494|#define gmp_realloc(ptr, old_size, size) ((*gmp_reallocate_func)(ptr, old_size, size))
  ------------------
  383|    494|}
mini-gmp.c:mpn_cmp4:
  422|    389|{
  423|    389|  if (an != bn)
  ------------------
  |  Branch (423:7): [True: 105, False: 284]
  ------------------
  424|    105|    return an < bn ? -1 : 1;
  ------------------
  |  Branch (424:12): [True: 105, False: 0]
  ------------------
  425|    284|  else
  426|    284|    return mpn_cmp (ap, bp, an);
  427|    389|}
mini-gmp.c:mpz_abs_sub:
 2010|    389|{
 2011|    389|  mp_size_t an = GMP_ABS (a->_mp_size);
  ------------------
  |  |   75|    389|#define GMP_ABS(x) ((x) >= 0 ? (x) : -(x))
  |  |  ------------------
  |  |  |  Branch (75:21): [True: 389, False: 0]
  |  |  ------------------
  ------------------
 2012|    389|  mp_size_t bn = GMP_ABS (b->_mp_size);
  ------------------
  |  |   75|    389|#define GMP_ABS(x) ((x) >= 0 ? (x) : -(x))
  |  |  ------------------
  |  |  |  Branch (75:21): [True: 389, False: 0]
  |  |  ------------------
  ------------------
 2013|    389|  int cmp;
 2014|    389|  mp_ptr rp;
 2015|       |
 2016|    389|  cmp = mpn_cmp4 (a->_mp_d, an, b->_mp_d, bn);
 2017|    389|  if (cmp > 0)
  ------------------
  |  Branch (2017:7): [True: 0, False: 389]
  ------------------
 2018|      0|    {
 2019|      0|      rp = MPZ_REALLOC (r, an);
  ------------------
  |  | 1484|      0|#define MPZ_REALLOC(z,n) ((n) > (z)->_mp_alloc			\
  |  |  ------------------
  |  |  |  Branch (1484:27): [True: 0, False: 0]
  |  |  ------------------
  |  | 1485|      0|			  ? mpz_realloc(z,n)			\
  |  | 1486|      0|			  : (z)->_mp_d)
  ------------------
 2020|      0|      gmp_assert_nocarry (mpn_sub (rp, a->_mp_d, an, b->_mp_d, bn));
  ------------------
  |  |   95|      0|#define gmp_assert_nocarry(x) do { \
  |  |   96|      0|    mp_limb_t __cy = (x);	   \
  |  |   97|      0|    assert (__cy == 0);		   \
  |  |   98|      0|    (void) (__cy);		   \
  |  |   99|      0|  } while (0)
  |  |  ------------------
  |  |  |  Branch (99:12): [Folded, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (2020:7): [True: 0, False: 0]
  |  Branch (2020:7): [True: 0, False: 0]
  ------------------
 2021|      0|      return mpn_normalized_size (rp, an);
 2022|      0|    }
 2023|    389|  else if (cmp < 0)
  ------------------
  |  Branch (2023:12): [True: 389, False: 0]
  ------------------
 2024|    389|    {
 2025|    389|      rp = MPZ_REALLOC (r, bn);
  ------------------
  |  | 1484|    389|#define MPZ_REALLOC(z,n) ((n) > (z)->_mp_alloc			\
  |  |  ------------------
  |  |  |  Branch (1484:27): [True: 105, False: 284]
  |  |  ------------------
  |  | 1485|    389|			  ? mpz_realloc(z,n)			\
  |  | 1486|    389|			  : (z)->_mp_d)
  ------------------
 2026|    389|      gmp_assert_nocarry (mpn_sub (rp, b->_mp_d, bn, a->_mp_d, an));
  ------------------
  |  |   95|    389|#define gmp_assert_nocarry(x) do { \
  |  |   96|    389|    mp_limb_t __cy = (x);	   \
  |  |   97|    389|    assert (__cy == 0);		   \
  |  |   98|    389|    (void) (__cy);		   \
  |  |   99|    389|  } while (0)
  |  |  ------------------
  |  |  |  Branch (99:12): [Folded, False: 389]
  |  |  ------------------
  ------------------
  |  Branch (2026:7): [True: 0, False: 389]
  |  Branch (2026:7): [True: 389, False: 0]
  ------------------
 2027|    389|      return -mpn_normalized_size (rp, bn);
 2028|    389|    }
 2029|      0|  else
 2030|      0|    return 0;
 2031|    389|}
mini-gmp.c:mpn_limb_size_in_base_2:
 1220|    279|{
 1221|    279|  unsigned shift;
 1222|       |
 1223|    279|  assert (u > 0);
  ------------------
  |  Branch (1223:3): [True: 0, False: 279]
  |  Branch (1223:3): [True: 279, False: 0]
  ------------------
 1224|    279|  gmp_clz (shift, u);
  ------------------
  |  |  101|    279|#define gmp_clz(count, x) do {						\
  |  |  102|    279|    mp_limb_t __clz_x = (x);						\
  |  |  103|    279|    unsigned __clz_c = 0;						\
  |  |  104|    279|    int LOCAL_SHIFT_BITS = 8;						\
  |  |  105|    279|    if (GMP_LIMB_BITS > LOCAL_SHIFT_BITS)				\
  |  |  ------------------
  |  |  |  |   64|    279|#define GMP_LIMB_BITS (sizeof(mp_limb_t) * CHAR_BIT)
  |  |  ------------------
  |  |  |  Branch (105:9): [True: 279, False: 0]
  |  |  ------------------
  |  |  106|    279|      for (;								\
  |  |  107|    949|	   (__clz_x & ((mp_limb_t) 0xff << (GMP_LIMB_BITS - 8))) == 0;	\
  |  |  ------------------
  |  |  |  |   64|    949|#define GMP_LIMB_BITS (sizeof(mp_limb_t) * CHAR_BIT)
  |  |  ------------------
  |  |  |  Branch (107:5): [True: 670, False: 279]
  |  |  ------------------
  |  |  108|    670|	   __clz_c += 8)						\
  |  |  109|    670|	{ __clz_x <<= LOCAL_SHIFT_BITS;	}				\
  |  |  110|    522|    for (; (__clz_x & GMP_LIMB_HIGHBIT) == 0; __clz_c++)		\
  |  |  ------------------
  |  |  |  |   67|    522|#define GMP_LIMB_HIGHBIT ((mp_limb_t) 1 << (GMP_LIMB_BITS - 1))
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|    522|#define GMP_LIMB_BITS (sizeof(mp_limb_t) * CHAR_BIT)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  |  Branch (110:12): [True: 243, False: 279]
  |  |  ------------------
  |  |  111|    279|      __clz_x <<= 1;							\
  |  |  112|    279|    (count) = __clz_c;							\
  |  |  113|    279|  } while (0)
  |  |  ------------------
  |  |  |  Branch (113:12): [Folded, False: 279]
  |  |  ------------------
  ------------------
 1225|       |  return GMP_LIMB_BITS - shift;
  ------------------
  |  |   64|    279|#define GMP_LIMB_BITS (sizeof(mp_limb_t) * CHAR_BIT)
  ------------------
 1226|    279|}
mini-gmp.c:gmp_detect_endian:
 4494|  1.09k|{
 4495|  1.09k|  static const int i = 2;
 4496|  1.09k|  const unsigned char *p = (const unsigned char *) &i;
 4497|  1.09k|  return 1 - *p;
 4498|  1.09k|}

nettle_rsa_public_key_init:
   45|  1.08k|{
   46|  1.08k|  mpz_init(key->n);
   47|  1.08k|  mpz_init(key->e);
   48|       |
   49|       |  /* Not really necessary, but it seems cleaner to initialize all the
   50|       |   * storage. */
   51|  1.08k|  key->size = 0;
   52|  1.08k|}
nettle_rsa_public_key_clear:
   56|  1.08k|{
   57|  1.08k|  mpz_clear(key->n);
   58|  1.08k|  mpz_clear(key->e);
   59|  1.08k|}
_nettle_rsa_check_size:
   65|    281|{
   66|       |  /* Round upwards */
   67|    281|  size_t size;
   68|       |
   69|       |  /* Even moduli are invalid, and not supported by mpz_powm_sec. */
   70|    281|  if (mpz_even_p (n))
  ------------------
  |  |  132|    281|#define mpz_even_p(z)  (! mpz_odd_p (z))
  |  |  ------------------
  |  |  |  |  131|    281|#define mpz_odd_p(z)   (((z)->_mp_size != 0) & (int) (z)->_mp_d[0])
  |  |  ------------------
  |  |  |  Branch (132:24): [True: 2, False: 279]
  |  |  ------------------
  ------------------
   71|      2|    return 0;
   72|       |
   73|    279|  size = (mpz_sizeinbase(n, 2) + 7) / 8;
   74|       |
   75|    279|  if (size < RSA_MINIMUM_N_OCTETS)
  ------------------
  |  |  116|    279|#define RSA_MINIMUM_N_OCTETS 12
  ------------------
  |  Branch (75:7): [True: 238, False: 41]
  ------------------
   76|    238|    return 0;
   77|       |
   78|     41|  return size;
   79|    279|}
nettle_rsa_public_key_prepare:
   83|    281|{
   84|    281|  key->size = _rsa_check_size(key->n);
  ------------------
  |  |   42|    281|#define _rsa_check_size _nettle_rsa_check_size
  ------------------
   85|       |  
   86|    281|  return (key->size > 0);
   87|    281|}

