Tcl Source Code

Changes On Branch libtommath-1.0.1
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Changes In Branch libtommath-1.0.1 Excluding Merge-Ins

This is equivalent to a diff from 238a21ce95 to 3617735687

2017-08-29
20:45
upgrade to libtommath 1.0.1 (With all Tcl-specific changes - as far as needed - intact) check-in: 600a59709e user: jan.nijtmans tags: trunk
20:43
Merge libtommath 1.0.1 final Closed-Leaf check-in: 3617735687 user: jan.nijtmans tags: libtommath-1.0.1
20:39
libtommath 1.0.1 check-in: bbc944c5d3 user: jan.nijtmans tags: libtommath
20:25
libtommath 1.0.1 rc2, for test purposes only check-in: 27923399a3 user: jan.nijtmans tags: libtommath-1.0.1
09:25
merge-mark check-in: 238a21ce95 user: jan.nijtmans tags: trunk
09:24
(cherry-pick): Fix [b50fb214] : exec redirection to append ... check-in: 520999f475 user: jan.nijtmans tags: core-8-6-branch
2017-08-24
16:56
Fix [b50fb214] : add to 2>> the same O_APPEND that was added to >> back in 2005. check-in: 844c1fa97f user: ferrieux tags: trunk

Changes to generic/tclTomMath.h.

112
113
114
115
116
117
118
119

120

121

122
123
124
125
126



127
128

129
130
131
132
133
134
135
112
113
114
115
116
117
118

119
120
121

122
123
124



125
126
127


128
129
130
131
132
133
134
135







-
+

+
-
+


-
-
-
+
+
+
-
-
+







#ifndef DIGIT_BIT
   #define DIGIT_BIT     (((CHAR_BIT * MP_SIZEOF_MP_DIGIT) - 1))  /* bits per digit */
   typedef uint_least32_t mp_min_u32;
#else
   typedef mp_digit mp_min_u32;
#endif

/* platforms that can use a better rand function */
/* use arc4random on platforms that support it */
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
    #define MP_GEN_RANDOM()    arc4random()
    #define MP_USE_ALT_RAND 1
    #define MP_GEN_RANDOM_MAX  0xffffffff
#endif

/* use arc4random on platforms that support it */
#ifdef MP_USE_ALT_RAND
    #define MP_GEN_RANDOM()    arc4random()
/* use rand() as fall-back if there's no better rand function */
#ifndef MP_GEN_RANDOM
    #define MP_GEN_RANDOM()    rand()
#else
    #define MP_GEN_RANDOM()    rand()
    #define MP_GEN_RANDOM_MAX  RAND_MAX
#endif

#define MP_DIGIT_BIT     DIGIT_BIT
#define MP_MASK          ((((mp_digit)1)<<((mp_digit)DIGIT_BIT))-((mp_digit)1))
#define MP_DIGIT_MAX     MP_MASK

/* equalities */
792
793
794
795
796
797
798
799
800
801



802
792
793
794
795
796
797
798



799
800
801
802







-
-
-
+
+
+

#ifdef __cplusplus
   }
#endif

#endif


/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_error.c.

38
39
40
41
42
43
44
45
46
47



38
39
40
41
42
43
44



45
46
47







-
-
-
+
+
+

   /* generic reply for invalid code */
   return "Invalid error code";
}

#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_fast_mp_invmod.c.

139
140
141
142
143
144
145
146
147
148



139
140
141
142
143
144
145



146
147
148







-
-
-
+
+
+
  res = MP_OKAY;

LBL_ERR:mp_clear_multi (&x, &y, &u, &v, &B, &D, NULL);
  return res;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_fast_mp_montgomery_reduce.c.

163
164
165
166
167
168
169
170
171
172



163
164
165
166
167
168
169



170
171
172







-
-
-
+
+
+
  if (mp_cmp_mag (x, n) != MP_LT) {
    return s_mp_sub (x, n, x);
  }
  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_fast_s_mp_mul_digs.c.

98
99
100
101
102
103
104
105
106
107



98
99
100
101
102
103
104



105
106
107







-
-
-
+
+
+
    }
  }
  mp_clamp (c);
  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_fast_s_mp_mul_high_digs.c.

89
90
91
92
93
94
95
96
97
98



89
90
91
92
93
94
95



96
97
98







-
-
-
+
+
+
    }
  }
  mp_clamp (c);
  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_fast_s_mp_sqr.c.

105
106
107
108
109
110
111
112
113
114



105
106
107
108
109
110
111



112
113
114







-
-
-
+
+
+
    }
  }
  mp_clamp (b);
  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_2expt.c.

39
40
41
42
43
44
45
46
47
48



39
40
41
42
43
44
45



46
47
48







-
-
-
+
+
+
  /* put the single bit in its place */
  a->dp[b / DIGIT_BIT] = ((mp_digit)1) << (b % DIGIT_BIT);

  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_abs.c.

34
35
36
37
38
39
40
41
42
43



34
35
36
37
38
39
40



41
42
43







-
-
-
+
+
+
  /* force the sign of b to positive */
  b->sign = MP_ZPOS;

  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_add.c.

44
45
46
47
48
49
50
51
52
53



44
45
46
47
48
49
50



51
52
53







-
-
-
+
+
+
    }
  }
  return res;
}

#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_add_d.c.

45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
45
46
47
48
49
50
51



52
53
54
55
56
57
58







-
-
-








     return res;
  }

  /* old number of used digits in c */
  oldused = c->used;

  /* sign always positive */
  c->sign = MP_ZPOS;

  /* source alias */
  tmpa    = a->dp;

  /* destination alias */
  tmpc    = c->dp;

  /* if a is positive */
91
92
93
94
95
96
97



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109



110
111
112







+
+
+












-
-
-
+
+
+
     }

     /* setup count so the clearing of oldused
      * can fall through correctly
      */
     ix       = 1;
  }

  /* sign always positive */
  c->sign = MP_ZPOS;

  /* now zero to oldused */
  while (ix++ < oldused) {
     *tmpc++ = 0;
  }
  mp_clamp(c);

  return MP_OKAY;
}

#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_addmod.c.

32
33
34
35
36
37
38
39
40
41



32
33
34
35
36
37
38



39
40
41







-
-
-
+
+
+
  }
  res = mp_mod (&t, c, d);
  mp_clear (&t);
  return res;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_and.c.

48
49
50
51
52
53
54
55
56
57



48
49
50
51
52
53
54



55
56
57







-
-
-
+
+
+
  mp_clamp (&t);
  mp_exch (c, &t);
  mp_clear (&t);
  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_clamp.c.

35
36
37
38
39
40
41
42
43
44



35
36
37
38
39
40
41



42
43
44







-
-
-
+
+
+
  /* reset the sign flag if used == 0 */
  if (a->used == 0) {
    a->sign = MP_ZPOS;
  }
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_clear.c.

35
36
37
38
39
40
41
42
43
44



35
36
37
38
39
40
41



42
43
44







-
-
-
+
+
+
    a->dp    = NULL;
    a->alloc = a->used = 0;
    a->sign  = MP_ZPOS;
  }
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_clear_multi.c.

25
26
27
28
29
30
31
32
33
34



25
26
27
28
29
30
31



32
33
34







-
-
-
+
+
+
        mp_clear(next_mp);
        next_mp = va_arg(args, mp_int*);
    }
    va_end(args);
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_cmp.c.

34
35
36
37
38
39
40
41
42
43



34
35
36
37
38
39
40



41
42
43







-
-
-
+
+
+
     return mp_cmp_mag(b, a);
  } else {
     return mp_cmp_mag(a, b);
  }
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_cmp_d.c.

35
36
37
38
39
40
41
42
43
44



35
36
37
38
39
40
41



42
43
44







-
-
-
+
+
+
    return MP_LT;
  } else {
    return MP_EQ;
  }
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_cmp_mag.c.

46
47
48
49
50
51
52
53
54
55



46
47
48
49
50
51
52



53
54
55







-
-
-
+
+
+
      return MP_LT;
    }
  }
  return MP_EQ;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_cnt_lsb.c.

44
45
46
47
48
49
50
51
52
53



44
45
46
47
48
49
50



51
52
53







-
-
-
+
+
+
      } while (qq == 0);
   }
   return x;
}

#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_copy.c.

59
60
61
62
63
64
65
66
67
68



59
60
61
62
63
64
65



66
67
68







-
-
-
+
+
+
  /* copy used count and sign */
  b->used = a->used;
  b->sign = a->sign;
  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_count_bits.c.

36
37
38
39
40
41
42
43
44
45



36
37
38
39
40
41
42



43
44
45







-
-
-
+
+
+
    ++r;
    q >>= ((mp_digit) 1);
  }
  return r;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_div.c.

286
287
288
289
290
291
292
293
294
295



286
287
288
289
290
291
292



293
294
295







-
-
-
+
+
+
  return res;
}

#endif

#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_div_2.c.

59
60
61
62
63
64
65
66
67
68



59
60
61
62
63
64
65



66
67
68







-
-
-
+
+
+
  }
  b->sign = a->sign;
  mp_clamp (b);
  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_div_2d.c.

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

35

36
37

38
39
40
41

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
16
17
18
19
20
21
22


23
24
25
26
27
28
29
30
31
32
33

34
35
36
37
38
39
40

41

42
43
44
45






46
47
48
49
50
51
52







-
-










+
-
+


+



-
+
-




-
-
-
-
-
-







 */

/* shift right by a certain bit count (store quotient in c, optional remainder in d) */
int mp_div_2d (const mp_int * a, int b, mp_int * c, mp_int * d)
{
  mp_digit D, r, rr;
  int     x, res;
  mp_int  t;


  /* if the shift count is <= 0 then we do no work */
  if (b <= 0) {
    res = mp_copy (a, c);
    if (d != NULL) {
      mp_zero (d);
    }
    return res;
  }

  /* copy */
  if ((res = mp_init (&t)) != MP_OKAY) {
  if ((res = mp_copy (a, c)) != MP_OKAY) {
    return res;
  }
  /* 'a' should not be used after here - it might be the same as d */

  /* get the remainder */
  if (d != NULL) {
    if ((res = mp_mod_2d (a, b, &t)) != MP_OKAY) {
    if ((res = mp_mod_2d (a, b, d)) != MP_OKAY) {
      mp_clear (&t);
      return res;
    }
  }

  /* copy */
  if ((res = mp_copy (a, c)) != MP_OKAY) {
    mp_clear (&t);
    return res;
  }

  /* shift by as many digits in the bit count */
  if (b >= (int)DIGIT_BIT) {
    mp_rshd (c, b / DIGIT_BIT);
  }

  /* shift any bit count < DIGIT_BIT */
  D = (mp_digit) (b % DIGIT_BIT);
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97



73
74
75
76
77
78
79




80
81
82
83



84
85
86







-
-
-
-




-
-
-
+
+
+
      --tmpc;

      /* set the carry to the carry bits of the current word found above */
      r = rr;
    }
  }
  mp_clamp (c);
  if (d != NULL) {
    mp_exch (&t, d);
  }
  mp_clear (&t);
  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_div_3.c.

70
71
72
73
74
75
76
77
78
79



70
71
72
73
74
75
76



77
78
79







-
-
-
+
+
+
  mp_clear(&q);
  
  return res;
}

#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_div_d.c.

105
106
107
108
109
110
111
112
113
114



105
106
107
108
109
110
111



112
113
114







-
-
-
+
+
+
  mp_clear(&q);
  
  return res;
}

#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_dr_is_modulus.c.

34
35
36
37
38
39
40
41
42
43



34
35
36
37
38
39
40



41
42
43







-
-
-
+
+
+
       }
   }
   return 1;
}

#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_dr_reduce.c.

87
88
89
90
91
92
93
94
95
96



87
88
89
90
91
92
93



94
95
96







-
-
-
+
+
+
    }
    goto top;
  }
  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_dr_setup.c.

23
24
25
26
27
28
29
30
31
32



23
24
25
26
27
28
29



30
31
32







-
-
-
+
+
+
    */
   *d = (mp_digit)((((mp_word)1) << ((mp_word)DIGIT_BIT)) - 
        ((mp_word)a->dp[0]));
}

#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_exch.c.

25
26
27
28
29
30
31
32
33
34



25
26
27
28
29
30
31



32
33
34







-
-
-
+
+
+

  t  = *a;
  *a = *b;
  *b = t;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_export.c.

79
80
81
82
83
84
85
86
87
88



79
80
81
82
83
84
85



86
87
88







-
-
-
+
+
+
	}

	return MP_OKAY;
}

#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_expt_d.c.

19
20
21
22
23
24
25
26
27
28



19
20
21
22
23
24
25



26
27
28







-
-
-
+
+
+
int mp_expt_d (mp_int * a, mp_digit b, mp_int * c)
{
  return mp_expt_d_ex(a, b, c, 0);
}

#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_expt_d_ex.c.

74
75
76
77
78
79
80
81
82
83



74
75
76
77
78
79
80



81
82
83







-
-
-
+
+
+
  } /* if ... else */

  mp_clear (&g);
  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_exptmod.c.

103
104
105
106
107
108
109
110
111
112



103
104
105
106
107
108
109



110
111
112







-
-
-
+
+
+
#ifdef BN_MP_EXPTMOD_FAST_C
  }
#endif
}

#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_exptmod_fast.c.

63
64
65
66
67
68
69
70

71
72
73
74
75
76

77
78
79
80
81
82
83
63
64
65
66
67
68
69

70
71
72
73
74
75

76
77
78
79
80
81
82
83







-
+





-
+







  if (winsize > 5) {
     winsize = 5;
  }
#endif

  /* init M array */
  /* init first cell */
  if ((err = mp_init(&M[1])) != MP_OKAY) {
  if ((err = mp_init_size(&M[1], P->alloc)) != MP_OKAY) {
     return err;
  }

  /* now init the second half of the array */
  for (x = 1<<(winsize-1); x < (1 << winsize); x++) {
    if ((err = mp_init(&M[x])) != MP_OKAY) {
    if ((err = mp_init_size(&M[x], P->alloc)) != MP_OKAY) {
      for (y = 1<<(winsize-1); y < x; y++) {
        mp_clear (&M[y]);
      }
      mp_clear(&M[1]);
      return err;
    }
  }
129
130
131
132
133
134
135
136

137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161




162
163
164
165
166
167
168
129
130
131
132
133
134
135

136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152




153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168







-
+
















-
-
-
-





+
+
+
+







#else
     err = MP_VAL;
     goto LBL_M;
#endif
  }

  /* setup result */
  if ((err = mp_init (&res)) != MP_OKAY) {
  if ((err = mp_init_size (&res, P->alloc)) != MP_OKAY) {
    goto LBL_M;
  }

  /* create M table
   *

   *
   * The first half of the table is not computed though accept for M[0] and M[1]
   */

  if (redmode == 0) {
#ifdef BN_MP_MONTGOMERY_CALC_NORMALIZATION_C
     /* now we need R mod m */
     if ((err = mp_montgomery_calc_normalization (&res, P)) != MP_OKAY) {
       goto LBL_RES;
     }
#else 
     err = MP_VAL;
     goto LBL_RES;
#endif

     /* now set M[1] to G * R mod m */
     if ((err = mp_mulmod (G, &res, P, &M[1])) != MP_OKAY) {
       goto LBL_RES;
     }
#else
     err = MP_VAL;
     goto LBL_RES;
#endif
  } else {
     mp_set(&res, 1);
     if ((err = mp_mod(G, P, &M[1])) != MP_OKAY) {
        goto LBL_RES;
     }
  }

312
313
314
315
316
317
318
319
320
321



312
313
314
315
316
317
318



319
320
321







-
-
-
+
+
+
    mp_clear (&M[x]);
  }
  return err;
}
#endif


/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_exteuclid.c.

25
26
27
28
29
30
31
32

33
34
35
36

37
38
39
40
41

42
43
44
45
46
47
48
49






50
51
52
53
54



55
56
57
58
59



60
61
62
63
64
65
66



67
68
69
70
71
72
73
74

75

76
77
78
79
80
81
82



25
26
27
28
29
30
31

32
33
34
35

36
37
38
39
40

41
42
43






44
45
46
47
48
49
50
51



52
53
54
55
56



57
58
59
60
61
62
63



64
65
66
67
68
69
70
71
72
73
74
75

76
77
78
79
80



81
82
83







-
+



-
+




-
+


-
-
-
-
-
-
+
+
+
+
+
+


-
-
-
+
+
+


-
-
-
+
+
+




-
-
-
+
+
+








+
-
+




-
-
-
+
+
+

   if ((err = mp_init_multi(&u1, &u2, &u3, &v1, &v2, &v3, &t1, &t2, &t3, &q, &tmp, NULL)) != MP_OKAY) {
      return err;
   }

   /* initialize, (u1,u2,u3) = (1,0,a) */
   mp_set(&u1, 1);
   if ((err = mp_copy(a, &u3)) != MP_OKAY)                                        { goto _ERR; }
   if ((err = mp_copy(a, &u3)) != MP_OKAY)                                        { goto LBL_ERR; }

   /* initialize, (v1,v2,v3) = (0,1,b) */
   mp_set(&v2, 1);
   if ((err = mp_copy(b, &v3)) != MP_OKAY)                                        { goto _ERR; }
   if ((err = mp_copy(b, &v3)) != MP_OKAY)                                        { goto LBL_ERR; }

   /* loop while v3 != 0 */
   while (mp_iszero(&v3) == MP_NO) {
       /* q = u3/v3 */
       if ((err = mp_div(&u3, &v3, &q, NULL)) != MP_OKAY)                         { goto _ERR; }
       if ((err = mp_div(&u3, &v3, &q, NULL)) != MP_OKAY)                         { goto LBL_ERR; }

       /* (t1,t2,t3) = (u1,u2,u3) - (v1,v2,v3)q */
       if ((err = mp_mul(&v1, &q, &tmp)) != MP_OKAY)                              { goto _ERR; }
       if ((err = mp_sub(&u1, &tmp, &t1)) != MP_OKAY)                             { goto _ERR; }
       if ((err = mp_mul(&v2, &q, &tmp)) != MP_OKAY)                              { goto _ERR; }
       if ((err = mp_sub(&u2, &tmp, &t2)) != MP_OKAY)                             { goto _ERR; }
       if ((err = mp_mul(&v3, &q, &tmp)) != MP_OKAY)                              { goto _ERR; }
       if ((err = mp_sub(&u3, &tmp, &t3)) != MP_OKAY)                             { goto _ERR; }
       if ((err = mp_mul(&v1, &q, &tmp)) != MP_OKAY)                              { goto LBL_ERR; }
       if ((err = mp_sub(&u1, &tmp, &t1)) != MP_OKAY)                             { goto LBL_ERR; }
       if ((err = mp_mul(&v2, &q, &tmp)) != MP_OKAY)                              { goto LBL_ERR; }
       if ((err = mp_sub(&u2, &tmp, &t2)) != MP_OKAY)                             { goto LBL_ERR; }
       if ((err = mp_mul(&v3, &q, &tmp)) != MP_OKAY)                              { goto LBL_ERR; }
       if ((err = mp_sub(&u3, &tmp, &t3)) != MP_OKAY)                             { goto LBL_ERR; }

       /* (u1,u2,u3) = (v1,v2,v3) */
       if ((err = mp_copy(&v1, &u1)) != MP_OKAY)                                  { goto _ERR; }
       if ((err = mp_copy(&v2, &u2)) != MP_OKAY)                                  { goto _ERR; }
       if ((err = mp_copy(&v3, &u3)) != MP_OKAY)                                  { goto _ERR; }
       if ((err = mp_copy(&v1, &u1)) != MP_OKAY)                                  { goto LBL_ERR; }
       if ((err = mp_copy(&v2, &u2)) != MP_OKAY)                                  { goto LBL_ERR; }
       if ((err = mp_copy(&v3, &u3)) != MP_OKAY)                                  { goto LBL_ERR; }

       /* (v1,v2,v3) = (t1,t2,t3) */
       if ((err = mp_copy(&t1, &v1)) != MP_OKAY)                                  { goto _ERR; }
       if ((err = mp_copy(&t2, &v2)) != MP_OKAY)                                  { goto _ERR; }
       if ((err = mp_copy(&t3, &v3)) != MP_OKAY)                                  { goto _ERR; }
       if ((err = mp_copy(&t1, &v1)) != MP_OKAY)                                  { goto LBL_ERR; }
       if ((err = mp_copy(&t2, &v2)) != MP_OKAY)                                  { goto LBL_ERR; }
       if ((err = mp_copy(&t3, &v3)) != MP_OKAY)                                  { goto LBL_ERR; }
   }

   /* make sure U3 >= 0 */
   if (u3.sign == MP_NEG) {
       if ((err = mp_neg(&u1, &u1)) != MP_OKAY)                                   { goto _ERR; }
       if ((err = mp_neg(&u2, &u2)) != MP_OKAY)                                   { goto _ERR; }
       if ((err = mp_neg(&u3, &u3)) != MP_OKAY)                                   { goto _ERR; }
       if ((err = mp_neg(&u1, &u1)) != MP_OKAY)                                   { goto LBL_ERR; }
       if ((err = mp_neg(&u2, &u2)) != MP_OKAY)                                   { goto LBL_ERR; }
       if ((err = mp_neg(&u3, &u3)) != MP_OKAY)                                   { goto LBL_ERR; }
   }

   /* copy result out */
   if (U1 != NULL) { mp_exch(U1, &u1); }
   if (U2 != NULL) { mp_exch(U2, &u2); }
   if (U3 != NULL) { mp_exch(U3, &u3); }

   err = MP_OKAY;
LBL_ERR:
_ERR: mp_clear_multi(&u1, &u2, &u3, &v1, &v2, &v3, &t1, &t2, &t3, &q, &tmp, NULL);
   mp_clear_multi(&u1, &u2, &u3, &v1, &v2, &v3, &t1, &t2, &t3, &q, &tmp, NULL);
   return err;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_fread.c.

11
12
13
14
15
16
17

18
19
20
21
22
23
24
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25







+







 *
 * The library is free for all purposes without any express
 * guarantee it works.
 *
 * Tom St Denis, [email protected], http://libtom.org
 */

#ifndef LTM_NO_FILE
/* read a bigint from a file stream in ASCII */
int mp_fread(mp_int *a, int radix, FILE *stream)
{
   int err, ch, neg, y;
   
   /* clear a */
   mp_zero(a);
55
56
57
58
59
60
61

62
63
64
65
66
67



56
57
58
59
60
61
62
63
64
65
66



67
68
69







+



-
-
-
+
+
+
   }
   if (mp_cmp_d(a, 0) != MP_EQ) {
      a->sign = neg;
   }
   
   return MP_OKAY;
}
#endif

#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_fwrite.c.

11
12
13
14
15
16
17

18
19
20
21
22
23
24
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25







+







 *
 * The library is free for all purposes without any express
 * guarantee it works.
 *
 * Tom St Denis, [email protected], http://libtom.org
 */

#ifndef LTM_NO_FILE
int mp_fwrite(mp_int *a, int radix, FILE *stream)
{
   char *buf;
   int err, len, x;
   
   if ((err = mp_radix_size(a, radix, &len)) != MP_OKAY) {
      return err;
40
41
42
43
44
45
46

47
48
49
50
51
52



41
42
43
44
45
46
47
48
49
50
51



52
53
54







+



-
-
-
+
+
+
          return MP_VAL;
       }
   }
   
   XFREE (buf);
   return MP_OKAY;
}
#endif

#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_gcd.c.

96
97
98
99
100
101
102
103
104
105



96
97
98
99
100
101
102



103
104
105







-
-
-
+
+
+
  res = MP_OKAY;
LBL_V:mp_clear (&u);
LBL_U:mp_clear (&v);
  return res;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_get_int.c.

36
37
38
39
40
41
42
43
44
45



36
37
38
39
40
41
42



43
44
45







-
-
-
+
+
+
  }

  /* force result to 32-bits always so it is consistent on non 32-bit platforms */
  return res & 0xFFFFFFFFUL;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_grow.c.

48
49
50
51
52
53
54
55
56
57



48
49
50
51
52
53
54



55
56
57







-
-
-
+
+
+
      a->dp[i] = 0;
    }
  }
  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_import.c.

64
65
66
67
68
69
70
71
72
73



64
65
66
67
68
69
70



71
72
73







-
-
-
+
+
+
	mp_clamp(rop);

	return MP_OKAY;
}

#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_init.c.

37
38
39
40
41
42
43
44
45
46



37
38
39
40
41
42
43



44
45
46







-
-
-
+
+
+
  a->alloc = MP_PREC;
  a->sign  = MP_ZPOS;

  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_init_copy.c.

19
20
21
22
23
24
25





26

27
28
29
30
31
32



19
20
21
22
23
24
25
26
27
28
29
30

31
32
33
34



35
36
37







+
+
+
+
+
-
+



-
-
-
+
+
+
int mp_init_copy (mp_int * a, const mp_int * b)
{
  int     res;

  if ((res = mp_init_size (a, b->used)) != MP_OKAY) {
    return res;
  }

  if((res = mp_copy (b, a)) != MP_OKAY) {
    mp_clear(a);
  }

  return mp_copy (b, a);
  return res;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_init_multi.c.

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59



27
28
29
30
31
32
33



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53



54
55
56







-
-
-




















-
-
-
+
+
+
    while (cur_arg != NULL) {
        if (mp_init(cur_arg) != MP_OKAY) {
            /* Oops - error! Back-track and mp_clear what we already
               succeeded in init-ing, then return error.
            */
            va_list clean_args;
            
            /* end the current list */
            va_end(args);
            
            /* now start cleaning up */            
            cur_arg = mp;
            va_start(clean_args, mp);
            while (n-- != 0) {
                mp_clear(cur_arg);
                cur_arg = va_arg(clean_args, mp_int*);
            }
            va_end(clean_args);
            res = MP_MEM;
            break;
        }
        n++;
        cur_arg = va_arg(args, mp_int*);
    }
    va_end(args);
    return res;                /* Assumed ok, if error flagged above. */
}

#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_init_set.c.

23
24
25
26
27
28
29
30
31
32



23
24
25
26
27
28
29



30
31
32







-
-
-
+
+
+
     return err;
  }
  mp_set(a, b);
  return err;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_init_set_int.c.

22
23
24
25
26
27
28
29
30
31



22
23
24
25
26
27
28



29
30
31







-
-
-
+
+
+
  if ((err = mp_init(a)) != MP_OKAY) {
     return err;
  }
  return mp_set_int(a, b);
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_init_size.c.

39
40
41
42
43
44
45
46
47
48



39
40
41
42
43
44
45



46
47
48







-
-
-
+
+
+
      a->dp[x] = 0;
  }

  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_invmod.c.

21
22
23
24
25
26
27
28

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43



21
22
23
24
25
26
27

28
29
30
31
32
33
34
35
36
37
38
39
40



41
42
43







-
+












-
-
-
+
+
+
  /* b cannot be negative */
  if ((b->sign == MP_NEG) || (mp_iszero(b) == MP_YES)) {
    return MP_VAL;
  }

#ifdef BN_FAST_MP_INVMOD_C
  /* if the modulus is odd we can use a faster routine instead */
  if (mp_isodd (b) == MP_YES) {
  if ((mp_isodd(b) == MP_YES) && (mp_cmp_d(b, 1) != MP_EQ)) {
    return fast_mp_invmod (a, b, c);
  }
#endif

#ifdef BN_MP_INVMOD_SLOW_C
  return mp_invmod_slow(a, b, c);
#else
  return MP_VAL;
#endif
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_invmod_slow.c.

166
167
168
169
170
171
172
173
174
175



166
167
168
169
170
171
172



173
174
175







-
-
-
+
+
+
  mp_exch (&C, c);
  res = MP_OKAY;
LBL_ERR:mp_clear_multi (&x, &y, &u, &v, &A, &B, &C, &D, NULL);
  return res;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_is_square.c.

100
101
102
103
104
105
106
107
108
109



100
101
102
103
104
105
106



107
108
109







-
-
-
+
+
+

  *ret = (mp_cmp_mag(&t,arg) == MP_EQ) ? MP_YES : MP_NO;
ERR:mp_clear(&t);
  return res;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_jacobi.c.

108
109
110
111
112
113
114
115
116
117



108
109
110
111
112
113
114



115
116
117







-
-
-
+
+
+
  res = MP_OKAY;
LBL_P1:mp_clear (&p1);
LBL_A1:mp_clear (&a1);
  return res;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_karatsuba_mul.c.

158
159
160
161
162
163
164
165
166
167



158
159
160
161
162
163
164



165
166
167







-
-
-
+
+
+
X1:mp_clear (&x1);
X0:mp_clear (&x0);
ERR:
  return err;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_karatsuba_sqr.c.

112
113
114
115
116
117
118
119
120
121



112
113
114
115
116
117
118



119
120
121







-
-
-
+
+
+
X1:mp_clear (&x1);
X0:mp_clear (&x0);
ERR:
  return err;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_lcm.c.

51
52
53
54
55
56
57
58
59
60



51
52
53
54
55
56
57



58
59
60







-
-
-
+
+
+

LBL_T:
  mp_clear_multi (&t1, &t2, NULL);
  return res;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_lshd.c.

58
59
60
61
62
63
64
65
66
67



58
59
60
61
62
63
64



65
66
67







-
-
-
+
+
+
      *top++ = 0;
    }
  }
  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_mod.c.

18
19
20
21
22
23
24
25

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48



18
19
20
21
22
23
24

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45



46
47
48







-
+




















-
-
-
+
+
+
/* c = a mod b, 0 <= c < b if b > 0, b < c <= 0 if b < 0 */
int
mp_mod (mp_int * a, mp_int * b, mp_int * c)
{
  mp_int  t;
  int     res;

  if ((res = mp_init (&t)) != MP_OKAY) {
  if ((res = mp_init_size (&t, b->used)) != MP_OKAY) {
    return res;
  }

  if ((res = mp_div (a, b, NULL, &t)) != MP_OKAY) {
    mp_clear (&t);
    return res;
  }

  if ((mp_iszero(&t) != MP_NO) || (t.sign == b->sign)) {
    res = MP_OKAY;
    mp_exch (&t, c);
  } else {
    res = mp_add (b, &t, c);
  }

  mp_clear (&t);
  return res;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_mod_2d.c.

46
47
48
49
50
51
52
53
54
55



46
47
48
49
50
51
52



53
54
55







-
-
-
+
+
+
  c->dp[b / DIGIT_BIT] &=
    (mp_digit) ((((mp_digit) 1) << (((mp_digit) b) % DIGIT_BIT)) - ((mp_digit) 1));
  mp_clamp (c);
  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_mod_d.c.

18
19
20
21
22
23
24
25
26
27



18
19
20
21
22
23
24



25
26
27







-
-
-
+
+
+
int
mp_mod_d (mp_int * a, mp_digit b, mp_digit * c)
{
  return mp_div_d(a, b, NULL, c);
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_montgomery_calc_normalization.c.

50
51
52
53
54
55
56
57
58
59



50
51
52
53
54
55
56



57
58
59







-
-
-
+
+
+
    }
  }

  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_montgomery_reduce.c.

109
110
111
112
113
114
115
116
117
118



109
110
111
112
113
114
115



116
117
118







-
-
-
+
+
+
    return s_mp_sub (x, n, x);
  }

  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_montgomery_setup.c.

50
51
52
53
54
55
56
57
58
59



50
51
52
53
54
55
56



57
58
59







-
-
-
+
+
+
  /* rho = -1/m mod b */
  *rho = (mp_digit)(((mp_word)1 << ((mp_word) DIGIT_BIT)) - x) & MP_MASK;

  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_mul.c.

58
59
60
61
62
63
64
65
66
67



58
59
60
61
62
63
64



65
66
67







-
-
-
+
+
+
    }
  }
  c->sign = (c->used > 0) ? neg : MP_ZPOS;
  return res;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_mul_2.c.

73
74
75
76
77
78
79
80
81
82



73
74
75
76
77
78
79



80
81
82







-
-
-
+
+
+
    }
  }
  b->sign = a->sign;
  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_mul_2d.c.

76
77
78
79
80
81
82
83
84
85



76
77
78
79
80
81
82



83
84
85







-
-
-
+
+
+
    }
  }
  mp_clamp (c);
  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_mul_d.c.

70
71
72
73
74
75
76
77
78
79



70
71
72
73
74
75
76



77
78
79







-
-
-
+
+
+
  c->used = a->used + 1;
  mp_clamp(c);

  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_mulmod.c.

17
18
19
20
21
22
23
24

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40



17
18
19
20
21
22
23

24
25
26
27
28
29
30
31
32
33
34
35
36
37



38
39
40







-
+













-
-
-
+
+
+

/* d = a * b (mod c) */
int mp_mulmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
{
  int     res;
  mp_int  t;

  if ((res = mp_init (&t)) != MP_OKAY) {
  if ((res = mp_init_size (&t, c->used)) != MP_OKAY) {
    return res;
  }

  if ((res = mp_mul (a, b, &t)) != MP_OKAY) {
    mp_clear (&t);
    return res;
  }
  res = mp_mod (&t, c, d);
  mp_clear (&t);
  return res;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_n_root.c.

21
22
23
24
25
26
27
28
29
30



21
22
23
24
25
26
27



28
29
30







-
-
-
+
+
+
int mp_n_root (mp_int * a, mp_digit b, mp_int * c)
{
  return mp_n_root_ex(a, b, c, 0);
}

#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_n_root_ex.c.

123
124
125
126
127
128
129
130
131
132



123
124
125
126
127
128
129



130
131
132







-
-
-
+
+
+
LBL_T3:mp_clear (&t3);
LBL_T2:mp_clear (&t2);
LBL_T1:mp_clear (&t1);
  return res;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_neg.c.

31
32
33
34
35
36
37
38
39
40



31
32
33
34
35
36
37



38
39
40







-
-
-
+
+
+
     b->sign = MP_ZPOS;
  }

  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_or.c.

41
42
43
44
45
46
47
48
49
50



41
42
43
44
45
46
47



48
49
50







-
-
-
+
+
+
  mp_clamp (&t);
  mp_exch (c, &t);
  mp_clear (&t);
  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_prime_fermat.c.

53
54
55
56
57
58
59
60
61
62



53
54
55
56
57
58
59



60
61
62







-
-
-
+
+
+

  err = MP_OKAY;
LBL_T:mp_clear (&t);
  return err;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_prime_is_divisible.c.

41
42
43
44
45
46
47
48
49
50



41
42
43
44
45
46
47



48
49
50







-
-
-
+
+
+
    }
  }

  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_prime_is_prime.c.

74
75
76
77
78
79
80
81
82
83



74
75
76
77
78
79
80



81
82
83







-
-
-
+
+
+
  /* passed the test */
  *result = MP_YES;
LBL_B:mp_clear (&b);
  return err;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_prime_miller_rabin.c.

94
95
96
97
98
99
100
101
102
103



94
95
96
97
98
99
100



101
102
103







-
-
-
+
+
+
LBL_Y:mp_clear (&y);
LBL_R:mp_clear (&r);
LBL_N1:mp_clear (&n1);
  return err;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_prime_next_prime.c.

161
162
163
164
165
166
167
168
169
170



161
162
163
164
165
166
167



168
169
170







-
-
-
+
+
+
LBL_ERR:
   mp_clear(&b);
   return err;
}

#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_prime_rabin_miller_trials.c.

43
44
45
46
47
48
49
50
51
52



43
44
45
46
47
48
49



50
51
52







-
-
-
+
+
+
   }
   return sizes[x-1].t + 1;
}


#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_prime_random_ex.c.

115
116
117
118
119
120
121
122
123
124



115
116
117
118
119
120
121



122
123
124







-
-
-
+
+
+
   XFREE(tmp);
   return err;
}


#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_radix_size.c.

69
70
71
72
73
74
75
76
77
78



69
70
71
72
73
74
75



76
77
78







-
-
-
+
+
+
  /* return digs + 1, the 1 is for the NULL byte that would be required. */
  *size = digs + 1;
  return MP_OKAY;
}

#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_radix_smap.c.

15
16
17
18
19
20
21
22
23
24



15
16
17
18
19
20
21



22
23
24







-
-
-
+
+
+
 * Tom St Denis, [email protected], http://libtom.org
 */

/* chars used in radix conversions */
const char *mp_s_rmap = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/";
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_rand.c.

10
11
12
13
14
15
16
17












18













19
20
21
22
23
24
25
26
27
28
29
30
31
32

33
34
35
36
37
38
39
40
41
42
43
44

45
46
47
48
49
50
51
52
53
54
55



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

57
58
59
60
61
62
63
64
65
66
67
68

69
70
71
72
73
74
75
76
77



78
79
80








+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+













-
+











-
+








-
-
-
+
+
+
 * additional optimizations in place.
 *
 * The library is free for all purposes without any express
 * guarantee it works.
 *
 * Tom St Denis, [email protected], http://libtom.org
 */

#if MP_GEN_RANDOM_MAX == 0xffffffff
  #define MP_GEN_RANDOM_SHIFT  32
#elif MP_GEN_RANDOM_MAX == 32767
  /* SHRT_MAX */
  #define MP_GEN_RANDOM_SHIFT  15
#elif MP_GEN_RANDOM_MAX == 2147483647
  /* INT_MAX */
  #define MP_GEN_RANDOM_SHIFT  31
#elif !defined(MP_GEN_RANDOM_SHIFT)
#error Thou shalt define their own valid MP_GEN_RANDOM_SHIFT
#endif

/* makes a pseudo-random int of a given size */
static mp_digit s_gen_random(void)
{
  mp_digit d = 0, msk = 0;
  do {
    d <<= MP_GEN_RANDOM_SHIFT;
    d |= ((mp_digit) MP_GEN_RANDOM());
    msk <<= MP_GEN_RANDOM_SHIFT;
    msk |= (MP_MASK & MP_GEN_RANDOM_MAX);
  } while ((MP_MASK & msk) != MP_MASK);
  d &= MP_MASK;
  return d;
}

int
mp_rand (mp_int * a, int digits)
{
  int     res;
  mp_digit d;

  mp_zero (a);
  if (digits <= 0) {
    return MP_OKAY;
  }

  /* first place a random non-zero digit */
  do {
    d = ((mp_digit) abs (MP_GEN_RANDOM())) & MP_MASK;
    d = s_gen_random();
  } while (d == 0);

  if ((res = mp_add_d (a, d, a)) != MP_OKAY) {
    return res;
  }

  while (--digits > 0) {
    if ((res = mp_lshd (a, 1)) != MP_OKAY) {
      return res;
    }

    if ((res = mp_add_d (a, ((mp_digit) abs (MP_GEN_RANDOM())), a)) != MP_OKAY) {
    if ((res = mp_add_d (a, s_gen_random(), a)) != MP_OKAY) {
      return res;
    }
  }

  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_read_radix.c.

83
84
85
86
87
88
89
90
91
92



83
84
85
86
87
88
89



90
91
92







-
-
-
+
+
+
  if (mp_iszero(a) != MP_YES) {
     a->sign = neg;
  }
  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_read_signed_bin.c.

32
33
34
35
36
37
38
39
40
41



32
33
34
35
36
37
38



39
40
41







-
-
-
+
+
+
     a->sign = MP_NEG;
  }

  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_read_unsigned_bin.c.

46
47
48
49
50
51
52
53
54
55



46
47
48
49
50
51
52



53
54
55







-
-
-
+
+
+
#endif
  }
  mp_clamp (a);
  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_reduce.c.

91
92
93
94
95
96
97
98
99
100



91
92
93
94
95
96
97



98
99
100







-
-
-
+
+
+
CLEANUP:
  mp_clear (&q);

  return res;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_reduce_2k.c.

54
55
56
57
58
59
60
61
62
63



54
55
56
57
58
59
60



61
62
63







-
-
-
+
+
+
ERR:
   mp_clear(&q);
   return res;
}

#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_reduce_2k_l.c.

55
56
57
58
59
60
61
62
63
64



55
56
57
58
59
60
61



62
63
64







-
-
-
+
+
+
ERR:
   mp_clear(&q);
   return res;
}

#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_reduce_2k_setup.c.

38
39
40
41
42
43
44
45
46
47



38
39
40
41
42
43
44



45
46
47







-
-
-
+
+
+
   
   *d = tmp.dp[0];
   mp_clear(&tmp);
   return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_reduce_2k_setup_l.c.

35
36
37
38
39
40
41
42
43
44



35
36
37
38
39
40
41



42
43
44







-
-
-
+
+
+
   
ERR:
   mp_clear(&tmp);
   return res;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_reduce_is_2k.c.

43
44
45
46
47
48
49
50
51
52



43
44
45
46
47
48
49



50
51
52







-
-
-
+
+
+
      }
   }
   return MP_YES;
}

#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_reduce_is_2k_l.c.

35
36
37
38
39
40
41
42
43
44



35
36
37
38
39
40
41



42
43
44







-
-
-
+
+
+
      
   }
   return MP_NO;
}

#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_reduce_setup.c.

25
26
27
28
29
30
31
32
33
34



25
26
27
28
29
30
31



32
33
34







-
-
-
+
+
+
  if ((res = mp_2expt (a, b->used * 2 * DIGIT_BIT)) != MP_OKAY) {
    return res;
  }
  return mp_div (a, b, a, NULL);
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_rshd.c.

63
64
65
66
67
68
69
70
71
72



63
64
65
66
67
68
69



70
71
72







-
-
-
+
+
+
  }
  
  /* remove excess digits */
  a->used -= b;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_set.c.

20
21
22
23
24
25
26
27
28
29



20
21
22
23
24
25
26



27
28
29







-
-
-
+
+
+
{
  mp_zero (a);
  a->dp[0] = b & MP_MASK;
  a->used  = (a->dp[0] != 0) ? 1 : 0;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_set_int.c.

39
40
41
42
43
44
45
46
47
48



39
40
41
42
43
44
45



46
47
48







-
-
-
+
+
+
    a->used += 1;
  }
  mp_clamp (a);
  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_set_long.c.

15
16
17
18
19
20
21
22
23
24



15
16
17
18
19
20
21



22
23
24







-
-
-
+
+
+
 * Tom St Denis, [email protected], http://libtom.org
 */

/* set a platform dependent unsigned long int */
MP_SET_XLONG(mp_set_long, unsigned long)
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_set_long_long.c.

15
16
17
18
19
20
21
22
23
24



15
16
17
18
19
20
21



22
23
24







-
-
-
+
+
+
 * Tom St Denis, [email protected], http://libtom.org
 */

/* set a platform dependent unsigned long long int */
MP_SET_XLONG(mp_set_long_long, unsigned long long)
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_shrink.c.

32
33
34
35
36
37
38
39
40
41



32
33
34
35
36
37
38



39
40
41







-
-
-
+
+
+
    a->dp    = tmp;
    a->alloc = used;
  }
  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_signed_bin_size.c.

18
19
20
21
22
23
24
25
26
27



18
19
20
21
22
23
24



25
26
27







-
-
-
+
+
+
/* get the size for an signed equivalent */
int mp_signed_bin_size (mp_int * a)
{
  return 1 + mp_unsigned_bin_size (a);
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_sqr.c.

51
52
53
54
55
56
57
58
59
60



51
52
53
54
55
56
57



58
59
60







-
-
-
+
+
+
    }
  }
  b->sign = MP_ZPOS;
  return res;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_sqrmod.c.

32
33
34
35
36
37
38
39
40
41



32
33
34
35
36
37
38



39
40
41







-
-
-
+
+
+
  }
  res = mp_mod (&t, b, c);
  mp_clear (&t);
  return res;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_sqrt.c.

136
137
138
139
140
141
142
143
144
145



136
137
138
139
140
141
142



143
144
145







-
-
-
+
+
+
E1: mp_clear(&t2);
E2: mp_clear(&t1);
  return res;
}

#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_sub.c.

50
51
52
53
54
55
56
57
58
59



50
51
52
53
54
55
56



57
58
59







-
-
-
+
+
+
    }
  }
  return res;
}

#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_sub_d.c.

84
85
86
87
88
89
90
91
92
93



84
85
86
87
88
89
90



91
92
93







-
-
-
+
+
+
  }
  mp_clamp(c);
  return MP_OKAY;
}

#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_submod.c.

33
34
35
36
37
38
39
40
41
42



33
34
35
36
37
38
39



40
41
42







-
-
-
+
+
+
  }
  res = mp_mod (&t, c, d);
  mp_clear (&t);
  return res;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_to_signed_bin.c.

24
25
26
27
28
29
30
31
32
33



24
25
26
27
28
29
30



31
32
33







-
-
-
+
+
+
    return res;
  }
  b[0] = (a->sign == MP_ZPOS) ? (unsigned char)0 : (unsigned char)1;
  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_to_signed_bin_n.c.

22
23
24
25
26
27
28
29
30
31



22
23
24
25
26
27
28



29
30
31







-
-
-
+
+
+
      return MP_VAL;
   }
   *outlen = mp_signed_bin_size(a);
   return mp_to_signed_bin(a, b);
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_to_unsigned_bin.c.

39
40
41
42
43
44
45
46
47
48



39
40
41
42
43
44
45



46
47
48







-
-
-
+
+
+
  }
  bn_reverse (b, x);
  mp_clear (&t);
  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_to_unsigned_bin_n.c.

22
23
24
25
26
27
28
29
30
31



22
23
24
25
26
27
28



29
30
31







-
-
-
+
+
+
      return MP_VAL;
   }
   *outlen = mp_unsigned_bin_size(a);
   return mp_to_unsigned_bin(a, b);
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_toom_mul.c.

277
278
279
280
281
282
283
284
285
286



277
278
279
280
281
282
283



284
285
286







-
-
-
+
+
+
                   &a0, &a1, &a2, &b0, &b1,
                   &b2, &tmp1, &tmp2, NULL);
    return res;
}

#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_toom_sqr.c.

219
220
221
222
223
224
225
226
227
228



219
220
221
222
223
224
225



226
227
228







-
-
-
+
+
+
ERR:
    mp_clear_multi(&w0, &w1, &w2, &w3, &w4, &a0, &a1, &a2, &tmp1, NULL);
    return res;
}

#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_toradix.c.

66
67
68
69
70
71
72
73
74
75



66
67
68
69
70
71
72



73
74
75







-
-
-
+
+
+

  mp_clear (&t);
  return MP_OKAY;
}

#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_toradix_n.c.

79
80
81
82
83
84
85
86
87
88



79
80
81
82
83
84
85



86
87
88







-
-
-
+
+
+

  mp_clear (&t);
  return MP_OKAY;
}

#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_unsigned_bin_size.c.

19
20
21
22
23
24
25
26
27
28



19
20
21
22
23
24
25



26
27
28







-
-
-
+
+
+
int mp_unsigned_bin_size (mp_int * a)
{
  int     size = mp_count_bits (a);
  return (size / 8) + (((size & 7) != 0) ? 1 : 0);
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_xor.c.

42
43
44
45
46
47
48
49
50
51



42
43
44
45
46
47
48



49
50
51







-
-
-
+
+
+
  mp_clamp (&t);
  mp_exch (c, &t);
  mp_clear (&t);
  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_mp_zero.c.

27
28
29
30
31
32
33
34
35
36



27
28
29
30
31
32
33



34
35
36







-
-
-
+
+
+
  tmp = a->dp;
  for (n = 0; n < a->alloc; n++) {
     *tmp++ = 0;
  }
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_prime_tab.c.

52
53
54
55
56
57
58
59
60
61



52
53
54
55
56
57
58



59
60
61







-
-
-
+
+
+
  0x05BF, 0x05C9, 0x05CB, 0x05CF, 0x05D1, 0x05D5, 0x05DB, 0x05E7,
  0x05F3, 0x05FB, 0x0607, 0x060D, 0x0611, 0x0617, 0x061F, 0x0623,
  0x062B, 0x062F, 0x063D, 0x0641, 0x0647, 0x0649, 0x064D, 0x0653
#endif
};
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_reverse.c.

30
31
32
33
34
35
36
37
38
39



30
31
32
33
34
35
36



37
38
39







-
-
-
+
+
+
    s[iy] = t;
    ++ix;
    --iy;
  }
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_s_mp_add.c.

100
101
102
103
104
105
106
107
108
109



100
101
102
103
104
105
106



107
108
109







-
-
-
+
+
+
  }

  mp_clamp (c);
  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_s_mp_exptmod.c.

243
244
245
246
247
248
249
250
251
252



243
244
245
246
247
248
249



250
251
252







-
-
-
+
+
+
  for (x = 1<<(winsize-1); x < (1 << winsize); x++) {
    mp_clear (&M[x]);
  }
  return err;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_s_mp_mul_digs.c.

81
82
83
84
85
86
87
88
89
90



81
82
83
84
85
86
87



88
89
90







-
-
-
+
+
+
  mp_exch (&t, c);

  mp_clear (&t);
  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_s_mp_mul_high_digs.c.

72
73
74
75
76
77
78
79
80
81



72
73
74
75
76
77
78



79
80
81







-
-
-
+
+
+
  mp_clamp (&t);
  mp_exch (&t, c);
  mp_clear (&t);
  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_s_mp_sqr.c.

75
76
77
78
79
80
81
82
83
84



75
76
77
78
79
80
81



82
83
84







-
-
-
+
+
+
  mp_clamp (&t);
  mp_exch (&t, b);
  mp_clear (&t);
  return MP_OKAY;
}
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bn_s_mp_sub.c.

80
81
82
83
84
85
86
87
88
89



80
81
82
83
84
85
86



87
88
89







-
-
-
+
+
+

  mp_clamp (c);
  return MP_OKAY;
}

#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/bncore.c.

27
28
29
30
31
32
33
34
35
36



27
28
29
30
31
32
33



34
35
36







-
-
-
+
+
+
int     KARATSUBA_MUL_CUTOFF = 80,      /* Min. number of digits before Karatsuba multiplication is used. */
        KARATSUBA_SQR_CUTOFF = 120,     /* Min. number of digits before Karatsuba squaring is used. */
        
        TOOM_MUL_CUTOFF      = 350,      /* no optimal values of these are known yet so set em high */
        TOOM_SQR_CUTOFF      = 400; 
#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/tommath.h.

23
24
25
26
27
28
29
30






31
32
33
34
35
36
37
23
24
25
26
27
28
29

30
31
32
33
34
35
36
37
38
39
40
41
42







-
+
+
+
+
+
+







#include <tommath_class.h>

#ifdef __cplusplus
extern "C" {
#endif

/* detect 64-bit mode if possible */
#if defined(__x86_64__)
#if defined(__x86_64__) || defined(_M_X64) || defined(_M_AMD64) || \
    defined(__powerpc64__) || defined(__ppc64__) || defined(__PPC64__) || \
    defined(__s390x__) || defined(__arch64__) || defined(__aarch64__) || \
    defined(__sparcv9) || defined(__sparc_v9__) || defined(__sparc64__) || \
    defined(__ia64) || defined(__ia64__) || defined(__itanium__) || defined(_M_IA64) || \
    defined(__LP64__) || defined(_LP64) || defined(__64BIT__)
   #if !(defined(MP_32BIT) || defined(MP_16BIT) || defined(MP_8BIT))
      #define MP_64BIT
   #endif
#endif

/* some default configurations.
 *
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
58
59
60
61
62
63
64





65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80





81
82
83
84
85
86
87







-
-
-
-
-
















-
-
-
-
-







   typedef uint32_t             mp_word;
#define MP_SIZEOF_MP_DIGIT      2
#ifdef DIGIT_BIT
#error You must not define DIGIT_BIT when using MP_16BIT
#endif
#elif defined(MP_64BIT)
   /* for GCC only on supported platforms */
#ifndef CRYPT
   typedef unsigned long long   ulong64;
   typedef signed long long     long64;
#endif

   typedef ulong64 mp_digit;
#if defined(_WIN32)
   typedef unsigned __int128    mp_word;
#elif defined(__GNUC__)
   typedef unsigned long        mp_word __attribute__ ((mode(TI)));
#else
   /* it seems you have a problem
    * but we assume you can somewhere define your own uint128_t */
   typedef uint128_t            mp_word;
#endif

   #define DIGIT_BIT            60
#else
   /* this is the default case, 28-bit digits */

   /* this is to make porting into LibTomCrypt easier :-) */
#ifndef CRYPT
   typedef unsigned long long   ulong64;
   typedef signed long long     long64;
#endif

   typedef uint32_t             mp_digit;
   typedef ulong64              mp_word;

#ifdef MP_31BIT
   /* this is an extension that uses 31-bit digits */
   #define DIGIT_BIT            31
#else
100
101
102
103
104
105
106
107

108

109

110
111
112
113
114



115
116

117
118
119
120
121
122
123
95
96
97
98
99
100
101

102
103
104

105
106
107



108
109
110


111
112
113
114
115
116
117
118







-
+

+
-
+


-
-
-
+
+
+
-
-
+







#ifndef DIGIT_BIT
   #define DIGIT_BIT     (((CHAR_BIT * MP_SIZEOF_MP_DIGIT) - 1))  /* bits per digit */
   typedef uint_least32_t mp_min_u32;
#else
   typedef mp_digit mp_min_u32;
#endif

/* platforms that can use a better rand function */
/* use arc4random on platforms that support it */
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
    #define MP_GEN_RANDOM()    arc4random()
    #define MP_USE_ALT_RAND 1
    #define MP_GEN_RANDOM_MAX  0xffffffff
#endif

/* use arc4random on platforms that support it */
#ifdef MP_USE_ALT_RAND
    #define MP_GEN_RANDOM()    arc4random()
/* use rand() as fall-back if there's no better rand function */
#ifndef MP_GEN_RANDOM
    #define MP_GEN_RANDOM()    rand()
#else
    #define MP_GEN_RANDOM()    rand()
    #define MP_GEN_RANDOM_MAX  RAND_MAX
#endif

#define MP_DIGIT_BIT     DIGIT_BIT
#define MP_MASK          ((((mp_digit)1)<<((mp_digit)DIGIT_BIT))-((mp_digit)1))
#define MP_DIGIT_MAX     MP_MASK

/* equalities */
566
567
568
569
570
571
572
573
574
575



561
562
563
564
565
566
567



568
569
570







-
-
-
+
+
+
#ifdef __cplusplus
   }
#endif

#endif


/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/tommath_class.h.

278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
278
279
280
281
282
283
284

285

286
287

288
289
290
291
292
293
294







-

-


-







   #define BN_MP_GROW_C
   #define BN_MP_CLAMP_C
#endif

#if defined(BN_MP_DIV_2D_C)
   #define BN_MP_COPY_C
   #define BN_MP_ZERO_C
   #define BN_MP_INIT_C
   #define BN_MP_MOD_2D_C
   #define BN_MP_CLEAR_C
   #define BN_MP_RSHD_C
   #define BN_MP_CLAMP_C
   #define BN_MP_EXCH_C
#endif

#if defined(BN_MP_DIV_3_C)
   #define BN_MP_INIT_SIZE_C
   #define BN_MP_CLAMP_C
   #define BN_MP_EXCH_C
   #define BN_MP_CLEAR_C
355
356
357
358
359
360
361
362

363
364
365
366
367
368
369
352
353
354
355
356
357
358

359
360
361
362
363
364
365
366







-
+







   #define BN_MP_REDUCE_IS_2K_C
   #define BN_MP_ISODD_C
   #define BN_MP_EXPTMOD_FAST_C
#endif

#if defined(BN_MP_EXPTMOD_FAST_C)
   #define BN_MP_COUNT_BITS_C
   #define BN_MP_INIT_C
   #define BN_MP_INIT_SIZE_C
   #define BN_MP_CLEAR_C
   #define BN_MP_MONTGOMERY_SETUP_C
   #define BN_FAST_MP_MONTGOMERY_REDUCE_C
   #define BN_MP_MONTGOMERY_REDUCE_C
   #define BN_MP_DR_SETUP_C
   #define BN_MP_DR_REDUCE_C
   #define BN_MP_REDUCE_2K_SETUP_C
437
438
439
440
441
442
443

444
445
446
447
448
449
450
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448







+








#if defined(BN_MP_INIT_C)
#endif

#if defined(BN_MP_INIT_COPY_C)
   #define BN_MP_INIT_SIZE_C
   #define BN_MP_COPY_C
   #define BN_MP_CLEAR_C
#endif

#if defined(BN_MP_INIT_MULTI_C)
   #define BN_MP_ERR_C
   #define BN_MP_INIT_C
   #define BN_MP_CLEAR_C
#endif
462
463
464
465
466
467
468

469
470
471
472
473
474
475
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474







+







#if defined(BN_MP_INIT_SIZE_C)
   #define BN_MP_INIT_C
#endif

#if defined(BN_MP_INVMOD_C)
   #define BN_MP_ISZERO_C
   #define BN_MP_ISODD_C
   #define BN_MP_CMP_D_C
   #define BN_FAST_MP_INVMOD_C
   #define BN_MP_INVMOD_SLOW_C
#endif

#if defined(BN_MP_INVMOD_SLOW_C)
   #define BN_MP_ISZERO_C
   #define BN_MP_INIT_MULTI_C
496
497
498
499
500
501
502

503
504
505
506
507
508
509
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509







+







   #define BN_MP_SQRT_C
   #define BN_MP_SQR_C
   #define BN_MP_CMP_MAG_C
   #define BN_MP_CLEAR_C
#endif

#if defined(BN_MP_JACOBI_C)
   #define BN_MP_ISNEG_C
   #define BN_MP_CMP_D_C
   #define BN_MP_ISZERO_C
   #define BN_MP_INIT_COPY_C
   #define BN_MP_CNT_LSB_C
   #define BN_MP_DIV_2D_C
   #define BN_MP_MOD_C
   #define BN_MP_CLEAR_C
542
543
544
545
546
547
548
549

550
551
552
553
554
555
556
542
543
544
545
546
547
548

549
550
551
552
553
554
555
556







-
+








#if defined(BN_MP_LSHD_C)
   #define BN_MP_GROW_C
   #define BN_MP_RSHD_C
#endif

#if defined(BN_MP_MOD_C)
   #define BN_MP_INIT_C
   #define BN_MP_INIT_SIZE_C
   #define BN_MP_DIV_C
   #define BN_MP_CLEAR_C
   #define BN_MP_ISZERO_C
   #define BN_MP_EXCH_C
   #define BN_MP_ADD_C
#endif

606
607
608
609
610
611
612
613

614
615
616
617
618
619
620
606
607
608
609
610
611
612

613
614
615
616
617
618
619
620







-
+








#if defined(BN_MP_MUL_D_C)
   #define BN_MP_GROW_C
   #define BN_MP_CLAMP_C
#endif

#if defined(BN_MP_MULMOD_C)
   #define BN_MP_INIT_C
   #define BN_MP_INIT_SIZE_C
   #define BN_MP_MUL_C
   #define BN_MP_CLEAR_C
   #define BN_MP_MOD_C
#endif

#if defined(BN_MP_N_ROOT_C)
   #define BN_MP_N_ROOT_EX_C

Changes to libtommath/tommath_private.h.

15
16
17
18
19
20
21
22

23
24
25
26

27
28
29
30
31
32
33
15
16
17
18
19
20
21

22
23
24
25

26
27
28
29
30
31
32
33







-
+



-
+







#ifndef TOMMATH_PRIV_H_
#define TOMMATH_PRIV_H_

#include <tommath.h>
#include <ctype.h>

#ifndef MIN
#define MIN(x,y) (((x) < (y)) ? (x) : (y))
  #define MIN(x,y) (((x) < (y)) ? (x) : (y))
#endif

#ifndef MAX
#define MAX(x,y) (((x) > (y)) ? (x) : (y))
  #define MAX(x,y) (((x) > (y)) ? (x) : (y))
#endif

#ifdef __cplusplus
extern "C" {

/* C++ compilers don't like assigning void * to mp_digit * */
#define  OPT_CAST(x)  (x *)
116
117
118
119
120
121
122
123
124
125



116
117
118
119
120
121
122



123
124
125







-
-
-
+
+
+
#ifdef __cplusplus
   }
#endif

#endif


/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to libtommath/tommath_superclass.h.

67
68
69
70
71
72
73
74
75
76



67
68
69
70
71
72
73



74
75
76







-
-
-
+
+
+
   #undef  BN_S_MP_MUL_DIGS_C
   #undef  BN_S_MP_SQR_C
   #undef  BN_MP_MONTGOMERY_REDUCE_C
#endif

#endif

/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref:         tag: v1.0.1, master */
/* git commit:  5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */

Changes to tools/fix_tommath_h.tcl.

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
18
19
20
21
22
23
24

25
26
27
28
29
30
31







-







set def_count 0
foreach line [split $data \n] {
    if {!$eat_semi && !$eat_endif} {
	switch -regexp -- $line {
	    {#define BN_H_} {
		puts $line
		puts {}
		puts "\#include \"tclInt.h\""
		puts "\#include \"tclTomMathDecls.h\""
		puts "\#ifndef MODULE_SCOPE"
		puts "\#define MODULE_SCOPE extern"
		puts "\#endif"
	    }
	    {typedef\s+unsigned long\s+mp_digit;} {
		# change the second 'typedef unsigned long mp
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
68
69
70
71
72
73
74




75
76
77
78
79
80
81







-
-
-
-







		set after_semi "\#endif"
	    }
	    {define heap macros} {
		puts $line
		puts "\#if 0 /* these are macros in tclTomMathDecls.h */"
		set eat_endif 1
	    }
	    {__x86_64__} {
		puts "[string map {__x86_64__ NEVER} $line]\
                      /* 128-bit ints fail in too many places */"
	    }
	    {#include} {
		# remove all includes
	    }
	    default {
		puts $line
	    }
	}