Commit bcd38316 authored by Dominique Dumont's avatar Dominique Dumont

New upstream version 1.0.1

parent c61192e5
language: c
compiler:
- gcc
script:
- make travis_mtest
- head -n 5 test.log
- tail -n 2 test.log
- ./testme.sh --with-cc=gcc --with-low-mp
branches:
only:
- master
- develop
- /^release\/.*$/
notifications:
irc: "chat.freenode.net#libtom-notifications"
[![Build Status](https://travis-ci.org/libtom/libtommath.png?branch=develop)](https://travis-ci.org/libtom/libtommath)
[![Build Status - master](https://travis-ci.org/libtom/libtommath.png?branch=master)](https://travis-ci.org/libtom/libtommath)
[![Build Status - develop](https://travis-ci.org/libtom/libtommath.png?branch=develop)](https://travis-ci.org/libtom/libtommath)
This is the git repository for [LibTomMath](http://www.libtom.org/), a free open source portable number theoretic multiple-precision integer (MPI) library written entirely in C.
......
This is makeindex, version 2.15 [TeX Live 2013] (kpathsea + Thai support).
Scanning input file bn.idx....done (85 entries accepted, 0 rejected).
Sorting entries....done (554 comparisons).
Generating output file bn.ind....done (88 lines written, 0 warnings).
Output written in bn.ind.
Transcript written in bn.ilg.
\begin{theindex}
\item mp\_add, \hyperpage{24}
\item mp\_add\_d, \hyperpage{44}
\item mp\_and, \hyperpage{24}
\item mp\_clear, \hyperpage{9}
\item mp\_clear\_multi, \hyperpage{10}
\item mp\_cmp, \hyperpage{19}
\item mp\_cmp\_d, \hyperpage{20}
\item mp\_cmp\_mag, \hyperpage{18}
\item mp\_div, \hyperpage{24}
\item mp\_div\_2, \hyperpage{22}
\item mp\_div\_2d, \hyperpage{23}
\item mp\_div\_d, \hyperpage{44}
\item mp\_dr\_reduce, \hyperpage{33}
\item mp\_dr\_setup, \hyperpage{33}
\item MP\_EQ, \hyperpage{18}
\item mp\_error\_to\_string, \hyperpage{7}
\item mp\_expt\_d, \hyperpage{35}
\item mp\_expt\_d\_ex, \hyperpage{35}
\item mp\_exptmod, \hyperpage{35}
\item mp\_exteuclid, \hyperpage{43}
\item mp\_gcd, \hyperpage{43}
\item mp\_get\_int, \hyperpage{16}
\item mp\_get\_long, \hyperpage{17}
\item mp\_get\_long\_long, \hyperpage{17}
\item mp\_grow, \hyperpage{13}
\item MP\_GT, \hyperpage{18}
\item mp\_init, \hyperpage{8}
\item mp\_init\_copy, \hyperpage{10}
\item mp\_init\_multi, \hyperpage{10}
\item mp\_init\_set, \hyperpage{17}
\item mp\_init\_set\_int, \hyperpage{17}
\item mp\_init\_size, \hyperpage{11}
\item mp\_int, \hyperpage{8}
\item mp\_invmod, \hyperpage{44}
\item mp\_jacobi, \hyperpage{43}
\item mp\_lcm, \hyperpage{43}
\item mp\_lshd, \hyperpage{23}
\item MP\_LT, \hyperpage{18}
\item MP\_MEM, \hyperpage{7}
\item mp\_mod, \hyperpage{29}
\item mp\_mod\_d, \hyperpage{44}
\item mp\_montgomery\_calc\_normalization, \hyperpage{31}
\item mp\_montgomery\_reduce, \hyperpage{31}
\item mp\_montgomery\_setup, \hyperpage{31}
\item mp\_mul, \hyperpage{25}
\item mp\_mul\_2, \hyperpage{22}
\item mp\_mul\_2d, \hyperpage{23}
\item mp\_mul\_d, \hyperpage{44}
\item mp\_n\_root, \hyperpage{36}
\item mp\_neg, \hyperpage{24}
\item MP\_NO, \hyperpage{7}
\item MP\_OKAY, \hyperpage{7}
\item mp\_or, \hyperpage{24}
\item mp\_prime\_fermat, \hyperpage{37}
\item mp\_prime\_is\_divisible, \hyperpage{37}
\item mp\_prime\_is\_prime, \hyperpage{38}
\item mp\_prime\_miller\_rabin, \hyperpage{37}
\item mp\_prime\_next\_prime, \hyperpage{38}
\item mp\_prime\_rabin\_miller\_trials, \hyperpage{38}
\item mp\_prime\_random, \hyperpage{38}
\item mp\_prime\_random\_ex, \hyperpage{39}
\item mp\_radix\_size, \hyperpage{41}
\item mp\_read\_radix, \hyperpage{41}
\item mp\_read\_unsigned\_bin, \hyperpage{42}
\item mp\_reduce, \hyperpage{30}
\item mp\_reduce\_2k, \hyperpage{34}
\item mp\_reduce\_2k\_setup, \hyperpage{34}
\item mp\_reduce\_setup, \hyperpage{29}
\item mp\_rshd, \hyperpage{23}
\item mp\_set, \hyperpage{15}
\item mp\_set\_int, \hyperpage{16}
\item mp\_set\_long, \hyperpage{17}
\item mp\_set\_long\_long, \hyperpage{17}
\item mp\_shrink, \hyperpage{12}
\item mp\_sqr, \hyperpage{26}
\item mp\_sqrtmod\_prime, \hyperpage{44}
\item mp\_sub, \hyperpage{24}
\item mp\_sub\_d, \hyperpage{44}
\item mp\_to\_unsigned\_bin, \hyperpage{42}
\item mp\_toradix, \hyperpage{41}
\item mp\_unsigned\_bin\_size, \hyperpage{41}
\item MP\_VAL, \hyperpage{7}
\item mp\_xor, \hyperpage{24}
\item MP\_YES, \hyperpage{7}
\end{theindex}
......@@ -42,6 +42,6 @@ const char *mp_error_to_string(int code)
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref: HEAD -> master, tag: v1.0.1 */
/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */
......@@ -143,6 +143,6 @@ LBL_ERR:mp_clear_multi (&x, &y, &u, &v, &B, &D, NULL);
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref: HEAD -> master, tag: v1.0.1 */
/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */
......@@ -167,6 +167,6 @@ int fast_mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho)
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref: HEAD -> master, tag: v1.0.1 */
/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */
......@@ -102,6 +102,6 @@ int fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref: HEAD -> master, tag: v1.0.1 */
/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */
......@@ -93,6 +93,6 @@ int fast_s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref: HEAD -> master, tag: v1.0.1 */
/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */
......@@ -109,6 +109,6 @@ int fast_s_mp_sqr (mp_int * a, mp_int * b)
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref: HEAD -> master, tag: v1.0.1 */
/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */
......@@ -43,6 +43,6 @@ mp_2expt (mp_int * a, int b)
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref: HEAD -> master, tag: v1.0.1 */
/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */
......@@ -38,6 +38,6 @@ mp_abs (mp_int * a, mp_int * b)
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref: HEAD -> master, tag: v1.0.1 */
/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */
......@@ -48,6 +48,6 @@ int mp_add (mp_int * a, mp_int * b, mp_int * c)
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref: HEAD -> master, tag: v1.0.1 */
/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */
......@@ -49,9 +49,6 @@ mp_add_d (mp_int * a, mp_digit b, mp_int * c)
/* old number of used digits in c */
oldused = c->used;
/* sign always positive */
c->sign = MP_ZPOS;
/* source alias */
tmpa = a->dp;
......@@ -96,6 +93,9 @@ mp_add_d (mp_int * a, mp_digit b, mp_int * c)
ix = 1;
}
/* sign always positive */
c->sign = MP_ZPOS;
/* now zero to oldused */
while (ix++ < oldused) {
*tmpc++ = 0;
......@@ -107,6 +107,6 @@ mp_add_d (mp_int * a, mp_digit b, mp_int * c)
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref: HEAD -> master, tag: v1.0.1 */
/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */
......@@ -36,6 +36,6 @@ mp_addmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref: HEAD -> master, tag: v1.0.1 */
/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */
......@@ -52,6 +52,6 @@ mp_and (mp_int * a, mp_int * b, mp_int * c)
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref: HEAD -> master, tag: v1.0.1 */
/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */
......@@ -39,6 +39,6 @@ mp_clamp (mp_int * a)
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref: HEAD -> master, tag: v1.0.1 */
/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */
......@@ -39,6 +39,6 @@ mp_clear (mp_int * a)
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref: HEAD -> master, tag: v1.0.1 */
/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */
......@@ -29,6 +29,6 @@ void mp_clear_multi(mp_int *mp, ...)
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref: HEAD -> master, tag: v1.0.1 */
/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */
......@@ -38,6 +38,6 @@ mp_cmp (mp_int * a, mp_int * b)
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref: HEAD -> master, tag: v1.0.1 */
/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */
......@@ -39,6 +39,6 @@ int mp_cmp_d(mp_int * a, mp_digit b)
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref: HEAD -> master, tag: v1.0.1 */
/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */
......@@ -50,6 +50,6 @@ int mp_cmp_mag (mp_int * a, mp_int * b)
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref: HEAD -> master, tag: v1.0.1 */
/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */
......@@ -48,6 +48,6 @@ int mp_cnt_lsb(mp_int *a)
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref: HEAD -> master, tag: v1.0.1 */
/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */
......@@ -63,6 +63,6 @@ mp_copy (mp_int * a, mp_int * b)
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref: HEAD -> master, tag: v1.0.1 */
/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */
......@@ -40,6 +40,6 @@ mp_count_bits (mp_int * a)
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref: HEAD -> master, tag: v1.0.1 */
/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */
......@@ -290,6 +290,6 @@ LBL_Q:mp_clear (&q);
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref: HEAD -> master, tag: v1.0.1 */
/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */
......@@ -63,6 +63,6 @@ int mp_div_2(mp_int * a, mp_int * b)
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref: HEAD -> master, tag: v1.0.1 */
/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */
......@@ -20,8 +20,6 @@ int mp_div_2d (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) {
......@@ -32,24 +30,19 @@ int mp_div_2d (mp_int * a, int b, mp_int * c, mp_int * d)
return res;
}
if ((res = mp_init (&t)) != MP_OKAY) {
/* copy */
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) {
mp_clear (&t);
if ((res = mp_mod_2d (a, b, d)) != MP_OKAY) {
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);
......@@ -84,14 +77,10 @@ int mp_div_2d (mp_int * a, int b, mp_int * c, mp_int * d)
}
}
mp_clamp (c);
if (d != NULL) {
mp_exch (&t, d);
}
mp_clear (&t);
return MP_OKAY;
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref: HEAD -> master, tag: v1.0.1 */
/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */
......@@ -74,6 +74,6 @@ mp_div_3 (mp_int * a, mp_int *c, mp_digit * d)
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref: HEAD -> master, tag: v1.0.1 */
/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */
......@@ -110,6 +110,6 @@ int mp_div_d (mp_int * a, mp_digit b, mp_int * c, mp_digit * d)
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref: HEAD -> master, tag: v1.0.1 */
/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */
......@@ -38,6 +38,6 @@ int mp_dr_is_modulus(mp_int *a)
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref: HEAD -> master, tag: v1.0.1 */
/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */
......@@ -91,6 +91,6 @@ top:
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref: HEAD -> master, tag: v1.0.1 */
/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */
......@@ -27,6 +27,6 @@ void mp_dr_setup(mp_int *a, mp_digit *d)
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref: HEAD -> master, tag: v1.0.1 */
/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */
......@@ -29,6 +29,6 @@ mp_exch (mp_int * a, mp_int * b)
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref: HEAD -> master, tag: v1.0.1 */
/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */
......@@ -83,6 +83,6 @@ int mp_export(void* rop, size_t* countp, int order, size_t size,
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref: HEAD -> master, tag: v1.0.1 */
/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */
......@@ -23,6 +23,6 @@ int mp_expt_d (mp_int * a, mp_digit b, mp_int * c)
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref: HEAD -> master, tag: v1.0.1 */
/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */
......@@ -78,6 +78,6 @@ int mp_expt_d_ex (mp_int * a, mp_digit b, mp_int * c, int fast)
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref: HEAD -> master, tag: v1.0.1 */
/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */
......@@ -107,6 +107,6 @@ int mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y)
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref: HEAD -> master, tag: v1.0.1 */
/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */
......@@ -67,13 +67,13 @@ int mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode
/* 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]);
}
......@@ -133,7 +133,7 @@ int mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode
}
/* setup result */
if ((err = mp_init (&res)) != MP_OKAY) {
if ((err = mp_init_size (&res, P->alloc)) != MP_OKAY) {
goto LBL_M;
}
......@@ -150,15 +150,15 @@ int mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode
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) {
......@@ -316,6 +316,6 @@ LBL_M:
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref: HEAD -> master, tag: v1.0.1 */
/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */
......@@ -29,41 +29,41 @@ int mp_exteuclid(mp_int *a, mp_int *b, mp_int *U1, mp_int *U2, mp_int *U3)
/* 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 */
......@@ -72,11 +72,12 @@ int mp_exteuclid(mp_int *a, mp_int *b, mp_int *U1, mp_int *U2, mp_int *U3)
if (U3 != NULL) { mp_exch(U3, &u3); }
err = MP_OKAY;
_ERR: mp_clear_multi(&u1, &u2, &u3, &v1, &v2, &v3, &t1, &t2, &t3, &q, &tmp, NULL);
LBL_ERR:
mp_clear_multi(&u1, &u2, &u3, &v1, &v2, &v3, &t1, &t2, &t3, &q, &tmp, NULL);
return err;
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */
/* ref: HEAD -> master, tag: v1.0.1 */
/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
/* commit time: 2017-08-29 22:27:36 +0200 */
......@@ -15,6 +15,7 @@
* Tom St Denis, tstdenis82@gmail.com, 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)