diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-05-31 11:51:58 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-05-31 11:51:58 (GMT) |
commit | e80cd8e2841210153d80ec6fe42342d91d74a6d7 (patch) | |
tree | 1f42bfb00e83f54bbe824a5560f7916da7a26090 | |
parent | 4b67509c242f6c46325dc5b85420aa20b1399e77 (diff) | |
parent | be861c2430ca13fd13b81ff3bcdc6fc0cb4ec8f4 (diff) | |
download | tcl-e80cd8e2841210153d80ec6fe42342d91d74a6d7.zip tcl-e80cd8e2841210153d80ec6fe42342d91d74a6d7.tar.gz tcl-e80cd8e2841210153d80ec6fe42342d91d74a6d7.tar.bz2 |
Merge 8.6
-rw-r--r-- | generic/tclExecute.c | 2 | ||||
-rw-r--r-- | generic/tclStrToD.c | 2 | ||||
-rw-r--r-- | generic/tclStubInit.c | 9 | ||||
-rw-r--r-- | generic/tclTestObj.c | 4 | ||||
-rw-r--r-- | generic/tclTomMath.decls | 2 | ||||
-rw-r--r-- | generic/tclTomMath.h | 35 | ||||
-rw-r--r-- | generic/tclTomMathDecls.h | 20 | ||||
-rw-r--r-- | libtommath/bn_mp_get_bit.c | 44 | ||||
-rw-r--r-- | libtommath/bn_mp_signed_rsh.c | 22 | ||||
-rw-r--r-- | libtommath/bn_mp_tc_and.c | 90 | ||||
-rw-r--r-- | libtommath/bn_mp_tc_div_2d.c | 35 | ||||
-rw-r--r-- | libtommath/bn_mp_tc_or.c | 90 | ||||
-rw-r--r-- | libtommath/bn_mp_tc_xor.c | 90 | ||||
-rw-r--r-- | libtommath/bn_s_mp_get_bit.c | 21 | ||||
-rw-r--r-- | libtommath/tommath.h | 26 | ||||
-rw-r--r-- | libtommath/tommath_class.h | 12 | ||||
-rw-r--r-- | unix/Makefile.in | 26 | ||||
-rw-r--r-- | win/Makefile.in | 7 | ||||
-rw-r--r-- | win/makefile.vc | 7 |
19 files changed, 105 insertions, 439 deletions
diff --git a/generic/tclExecute.c b/generic/tclExecute.c index c3d02a6..a2eed3f 100644 --- a/generic/tclExecute.c +++ b/generic/tclExecute.c @@ -8191,7 +8191,7 @@ ExecuteExtendedBinaryMathOp( if (opcode == INST_LSHIFT) { mp_mul_2d(&big1, shift, &bigResult); } else { - mp_tc_div_2d(&big1, shift, &bigResult); + mp_signed_rsh(&big1, shift, &bigResult); } mp_clear(&big1); BIG_RESULT(&bigResult); diff --git a/generic/tclStrToD.c b/generic/tclStrToD.c index c9abb1a..b160d9e 100644 --- a/generic/tclStrToD.c +++ b/generic/tclStrToD.c @@ -4577,7 +4577,7 @@ TclBignumToDouble( */ mp_div_2d(a, -shift, &b, NULL); - if (mp_get_bit(&b, 0)) { + if (mp_isodd(&b)) { if (b.sign == MP_ZPOS) { mp_add_d(&b, 1, &b); } else { diff --git a/generic/tclStubInit.c b/generic/tclStubInit.c index c9a195f..74d02f1 100644 --- a/generic/tclStubInit.c +++ b/generic/tclStubInit.c @@ -61,6 +61,13 @@ #undef Tcl_BackgroundError #define TclStaticPackage Tcl_StaticPackage +#undef TclBN_mp_tc_and +#undef TclBN_mp_tc_or +#undef TclBN_mp_tc_xor +#define TclBN_mp_tc_and TclBN_mp_and +#define TclBN_mp_tc_or TclBN_mp_or +#define TclBN_mp_tc_xor TclBN_mp_xor + /* See bug 510001: TclSockMinimumBuffers needs plat imp */ #if defined(_WIN64) || defined(TCL_NO_DEPRECATED) || TCL_MAJOR_VERSION > 8 # define TclSockMinimumBuffersOld 0 @@ -950,7 +957,7 @@ const TclTomMathStubs tclTomMathStubs = { TclBN_mp_tc_and, /* 73 */ TclBN_mp_tc_or, /* 74 */ TclBN_mp_tc_xor, /* 75 */ - TclBN_mp_tc_div_2d, /* 76 */ + TclBN_mp_signed_rsh, /* 76 */ TclBN_mp_get_bit, /* 77 */ }; diff --git a/generic/tclTestObj.c b/generic/tclTestObj.c index a289e32..c9e4a6f 100644 --- a/generic/tclTestObj.c +++ b/generic/tclTestObj.c @@ -290,9 +290,9 @@ TestbignumobjCmd( return TCL_ERROR; } if (!Tcl_IsShared(varPtr[varIndex])) { - Tcl_SetIntObj(varPtr[varIndex], !mp_get_bit(&bignumValue, 0)); + Tcl_SetIntObj(varPtr[varIndex], !mp_isodd(&bignumValue)); } else { - SetVarToObj(varPtr, varIndex, Tcl_NewIntObj(!mp_get_bit(&bignumValue, 0))); + SetVarToObj(varPtr, varIndex, Tcl_NewIntObj(!mp_isodd(&bignumValue))); } mp_clear(&bignumValue); break; diff --git a/generic/tclTomMath.decls b/generic/tclTomMath.decls index 7221dcf..01b6342 100644 --- a/generic/tclTomMath.decls +++ b/generic/tclTomMath.decls @@ -265,7 +265,7 @@ declare 75 { int TclBN_mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c) } declare 76 { - int TclBN_mp_tc_div_2d(const mp_int *a, int b, mp_int *c) + int TclBN_mp_signed_rsh(const mp_int *a, int b, mp_int *c) } declare 77 { int TclBN_mp_get_bit(const mp_int *a, int b) diff --git a/generic/tclTomMath.h b/generic/tclTomMath.h index cc9f286..bbcb4bc 100644 --- a/generic/tclTomMath.h +++ b/generic/tclTomMath.h @@ -203,12 +203,14 @@ typedef int ltm_prime_callback(unsigned char *dst, int len, void *dat); /* error code to char* string */ -const char *mp_error_to_string(int code); +/* +const char *mp_error_to_string(mp_err code); +*/ /* ---> init and deinit bignum functions <--- */ /* init a bignum */ /* -int mp_init(mp_int *a); +mp_err mp_init(mp_int *a); */ /* free a bignum */ @@ -218,7 +220,7 @@ void mp_clear(mp_int *a); /* init a null terminated series of arguments */ /* -int mp_init_multi(mp_int *mp, ...); +mp_err mp_init_multi(mp_int *mp, ...); */ /* clear a null terminated series of arguments */ @@ -233,23 +235,23 @@ void mp_exch(mp_int *a, mp_int *b); /* shrink ram required for a bignum */ /* -int mp_shrink(mp_int *a); +mp_err mp_shrink(mp_int *a); */ /* grow an int to a given size */ /* -int mp_grow(mp_int *a, int size); +mp_err mp_grow(mp_int *a, int size); */ /* init to a given number of digits */ /* -int mp_init_size(mp_int *a, int size); +mp_err mp_init_size(mp_int *a, int size); */ /* ---> Basic Manipulations <--- */ #define mp_iszero(a) (((a)->used == 0) ? MP_YES : MP_NO) -#define mp_iseven(a) (!mp_get_bit((a),0)) -#define mp_isodd(a) mp_get_bit((a),0) +#define mp_iseven(a) (((a)->used == 0 || (((a)->dp[0] & 1) == 0)) ? MP_YES : MP_NO) +#define mp_isodd(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 1)) ? MP_YES : MP_NO) #define mp_isneg(a) (((a)->sign != MP_ZPOS) ? MP_YES : MP_NO) /* set to zero */ @@ -410,24 +412,9 @@ int mp_or(const mp_int *a, const mp_int *b, mp_int *c); int mp_and(const mp_int *a, const mp_int *b, mp_int *c); */ -/* c = a XOR b (two complement) */ -/* -int mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c); -*/ - -/* c = a OR b (two complement) */ -/* -int mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c); -*/ - -/* c = a AND b (two complement) */ -/* -int mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c); -*/ - /* right shift (two complement) */ /* -int mp_tc_div_2d(const mp_int *a, int b, mp_int *c); +int mp_signed_rsh(const mp_int *a, int b, mp_int *c); */ /* ---> Basic arithmetic <--- */ diff --git a/generic/tclTomMathDecls.h b/generic/tclTomMathDecls.h index c5ed4d5..52b84ee 100644 --- a/generic/tclTomMathDecls.h +++ b/generic/tclTomMathDecls.h @@ -75,6 +75,8 @@ #define mp_get_long TclBN_mp_get_long #define mp_get_long_long TclBN_mp_get_long_long #define mp_grow TclBN_mp_grow +#define s_mp_get_bit TclBN_mp_get_bit +#define mp_grow TclBN_mp_grow #define mp_init TclBN_mp_init #define mp_init_copy TclBN_mp_init_copy #define mp_init_multi TclBN_mp_init_multi @@ -106,10 +108,11 @@ #define mp_sqrt TclBN_mp_sqrt #define mp_sub TclBN_mp_sub #define mp_sub_d TclBN_mp_sub_d -#define mp_tc_and TclBN_mp_tc_and -#define mp_tc_div_2d TclBN_mp_tc_div_2d -#define mp_tc_or TclBN_mp_tc_or -#define mp_tc_xor TclBN_mp_tc_xor +#define mp_signed_rsh TclBN_mp_signed_rsh +#define mp_tc_and TclBN_mp_and +#define mp_tc_div_2d TclBN_mp_signed_rsh +#define mp_tc_or TclBN_mp_or +#define mp_tc_xor TclBN_mp_xor #define mp_to_unsigned_bin TclBN_mp_to_unsigned_bin #define mp_to_unsigned_bin_n TclBN_mp_to_unsigned_bin_n #define mp_toom_mul TclBN_mp_toom_mul @@ -351,7 +354,8 @@ EXTERN int TclBN_mp_tc_or(const mp_int *a, const mp_int *b, EXTERN int TclBN_mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c); /* 76 */ -EXTERN int TclBN_mp_tc_div_2d(const mp_int *a, int b, mp_int *c); +EXTERN int TclBN_mp_signed_rsh(const mp_int *a, int b, + mp_int *c); /* 77 */ EXTERN int TclBN_mp_get_bit(const mp_int *a, int b); @@ -435,7 +439,7 @@ typedef struct TclTomMathStubs { int (*tclBN_mp_tc_and) (const mp_int *a, const mp_int *b, mp_int *c); /* 73 */ int (*tclBN_mp_tc_or) (const mp_int *a, const mp_int *b, mp_int *c); /* 74 */ int (*tclBN_mp_tc_xor) (const mp_int *a, const mp_int *b, mp_int *c); /* 75 */ - int (*tclBN_mp_tc_div_2d) (const mp_int *a, int b, mp_int *c); /* 76 */ + int (*tclBN_mp_signed_rsh) (const mp_int *a, int b, mp_int *c); /* 76 */ int (*tclBN_mp_get_bit) (const mp_int *a, int b); /* 77 */ } TclTomMathStubs; @@ -603,8 +607,8 @@ extern const TclTomMathStubs *tclTomMathStubsPtr; (tclTomMathStubsPtr->tclBN_mp_tc_or) /* 74 */ #define TclBN_mp_tc_xor \ (tclTomMathStubsPtr->tclBN_mp_tc_xor) /* 75 */ -#define TclBN_mp_tc_div_2d \ - (tclTomMathStubsPtr->tclBN_mp_tc_div_2d) /* 76 */ +#define TclBN_mp_signed_rsh \ + (tclTomMathStubsPtr->tclBN_mp_signed_rsh) /* 76 */ #define TclBN_mp_get_bit \ (tclTomMathStubsPtr->tclBN_mp_get_bit) /* 77 */ diff --git a/libtommath/bn_mp_get_bit.c b/libtommath/bn_mp_get_bit.c deleted file mode 100644 index f5d2450..0000000 --- a/libtommath/bn_mp_get_bit.c +++ /dev/null @@ -1,44 +0,0 @@ -#include "tommath_private.h" -#ifdef BN_MP_GET_BIT_C - -/* LibTomMath, multiple-precision integer library -- Tom St Denis - * - * LibTomMath is a library that provides multiple-precision - * integer arithmetic as well as number theoretic functionality. - * - * The library was designed directly after the MPI library by - * Michael Fromberger but has been written from scratch with - * additional optimizations in place. - * - * SPDX-License-Identifier: Unlicense - */ - -/* Checks the bit at position b and returns MP_YES - if the bit is 1, MP_NO if it is 0 and MP_VAL - in case of error */ -int mp_get_bit(const mp_int *a, int b) -{ - int limb; - mp_digit bit, isset; - - if (b < 0) { - return MP_VAL; - } - - limb = b / DIGIT_BIT; - - if (limb >= a->used) { - return MP_NO; - } - - bit = (mp_digit)(1) << (b % DIGIT_BIT); - - isset = a->dp[limb] & bit; - return (isset != 0u) ? MP_YES : MP_NO; -} - -#endif - -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */ diff --git a/libtommath/bn_mp_signed_rsh.c b/libtommath/bn_mp_signed_rsh.c new file mode 100644 index 0000000..8d8d841 --- /dev/null +++ b/libtommath/bn_mp_signed_rsh.c @@ -0,0 +1,22 @@ +#include "tommath_private.h" +#ifdef BN_MP_SIGNED_RSH_C +/* LibTomMath, multiple-precision integer library -- Tom St Denis */ +/* SPDX-License-Identifier: Unlicense */ + +/* shift right by a certain bit count with sign extension */ +mp_err mp_signed_rsh(const mp_int *a, int b, mp_int *c) +{ + mp_err res; + if (a->sign == MP_ZPOS) { + return mp_div_2d(a, b, c, NULL); + } + + res = mp_add_d(a, 1uL, c); + if (res != MP_OKAY) { + return res; + } + + res = mp_div_2d(c, b, c, NULL); + return (res == MP_OKAY) ? mp_sub_d(c, 1uL, c) : res; +} +#endif diff --git a/libtommath/bn_mp_tc_and.c b/libtommath/bn_mp_tc_and.c deleted file mode 100644 index 9834dc6..0000000 --- a/libtommath/bn_mp_tc_and.c +++ /dev/null @@ -1,90 +0,0 @@ -#include "tommath_private.h" -#ifdef BN_MP_TC_AND_C -/* LibTomMath, multiple-precision integer library -- Tom St Denis - * - * LibTomMath is a library that provides multiple-precision - * integer arithmetic as well as number theoretic functionality. - * - * The library was designed directly after the MPI library by - * Michael Fromberger but has been written from scratch with - * additional optimizations in place. - * - * SPDX-License-Identifier: Unlicense - */ - -/* two complement and */ -int mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c) -{ - int res = MP_OKAY, bits, abits, bbits; - int as = mp_isneg(a), bs = mp_isneg(b); - mp_int *mx = NULL, _mx, acpy, bcpy; - - if ((as != MP_NO) || (bs != MP_NO)) { - abits = mp_count_bits(a); - bbits = mp_count_bits(b); - bits = MAX(abits, bbits); - res = mp_init_set_int(&_mx, 1uL); - if (res != MP_OKAY) { - goto end; - } - - mx = &_mx; - res = mp_mul_2d(mx, bits + 1, mx); - if (res != MP_OKAY) { - goto end; - } - - if (as != MP_NO) { - res = mp_init(&acpy); - if (res != MP_OKAY) { - goto end; - } - - res = mp_add(mx, a, &acpy); - if (res != MP_OKAY) { - mp_clear(&acpy); - goto end; - } - a = &acpy; - } - if (bs != MP_NO) { - res = mp_init(&bcpy); - if (res != MP_OKAY) { - goto end; - } - - res = mp_add(mx, b, &bcpy); - if (res != MP_OKAY) { - mp_clear(&bcpy); - goto end; - } - b = &bcpy; - } - } - - res = mp_and(a, b, c); - - if ((as != MP_NO) && (bs != MP_NO) && (res == MP_OKAY)) { - res = mp_sub(c, mx, c); - } - -end: - if (a == &acpy) { - mp_clear(&acpy); - } - - if (b == &bcpy) { - mp_clear(&bcpy); - } - - if (mx == &_mx) { - mp_clear(mx); - } - - return res; -} -#endif - -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */ diff --git a/libtommath/bn_mp_tc_div_2d.c b/libtommath/bn_mp_tc_div_2d.c deleted file mode 100644 index 4ff0acf..0000000 --- a/libtommath/bn_mp_tc_div_2d.c +++ /dev/null @@ -1,35 +0,0 @@ -#include "tommath_private.h" -#ifdef BN_MP_TC_DIV_2D_C -/* LibTomMath, multiple-precision integer library -- Tom St Denis - * - * LibTomMath is a library that provides multiple-precision - * integer arithmetic as well as number theoretic functionality. - * - * The library was designed directly after the MPI library by - * Michael Fromberger but has been written from scratch with - * additional optimizations in place. - * - * SPDX-License-Identifier: Unlicense - */ - -/* two complement right shift */ -int mp_tc_div_2d(const mp_int *a, int b, mp_int *c) -{ - int res; - if (mp_isneg(a) == MP_NO) { - return mp_div_2d(a, b, c, NULL); - } - - res = mp_add_d(a, 1uL, c); - if (res != MP_OKAY) { - return res; - } - - res = mp_div_2d(c, b, c, NULL); - return (res == MP_OKAY) ? mp_sub_d(c, 1uL, c) : res; -} -#endif - -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */ diff --git a/libtommath/bn_mp_tc_or.c b/libtommath/bn_mp_tc_or.c deleted file mode 100644 index 0941468..0000000 --- a/libtommath/bn_mp_tc_or.c +++ /dev/null @@ -1,90 +0,0 @@ -#include "tommath_private.h" -#ifdef BN_MP_TC_OR_C -/* LibTomMath, multiple-precision integer library -- Tom St Denis - * - * LibTomMath is a library that provides multiple-precision - * integer arithmetic as well as number theoretic functionality. - * - * The library was designed directly after the MPI library by - * Michael Fromberger but has been written from scratch with - * additional optimizations in place. - * - * SPDX-License-Identifier: Unlicense - */ - -/* two complement or */ -int mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c) -{ - int res = MP_OKAY, bits, abits, bbits; - int as = mp_isneg(a), bs = mp_isneg(b); - mp_int *mx = NULL, _mx, acpy, bcpy; - - if ((as != MP_NO) || (bs != MP_NO)) { - abits = mp_count_bits(a); - bbits = mp_count_bits(b); - bits = MAX(abits, bbits); - res = mp_init_set_int(&_mx, 1uL); - if (res != MP_OKAY) { - goto end; - } - - mx = &_mx; - res = mp_mul_2d(mx, bits + 1, mx); - if (res != MP_OKAY) { - goto end; - } - - if (as != MP_NO) { - res = mp_init(&acpy); - if (res != MP_OKAY) { - goto end; - } - - res = mp_add(mx, a, &acpy); - if (res != MP_OKAY) { - mp_clear(&acpy); - goto end; - } - a = &acpy; - } - if (bs != MP_NO) { - res = mp_init(&bcpy); - if (res != MP_OKAY) { - goto end; - } - - res = mp_add(mx, b, &bcpy); - if (res != MP_OKAY) { - mp_clear(&bcpy); - goto end; - } - b = &bcpy; - } - } - - res = mp_or(a, b, c); - - if (((as != MP_NO) || (bs != MP_NO)) && (res == MP_OKAY)) { - res = mp_sub(c, mx, c); - } - -end: - if (a == &acpy) { - mp_clear(&acpy); - } - - if (b == &bcpy) { - mp_clear(&bcpy); - } - - if (mx == &_mx) { - mp_clear(mx); - } - - return res; -} -#endif - -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */ diff --git a/libtommath/bn_mp_tc_xor.c b/libtommath/bn_mp_tc_xor.c deleted file mode 100644 index cdb1d40..0000000 --- a/libtommath/bn_mp_tc_xor.c +++ /dev/null @@ -1,90 +0,0 @@ -#include "tommath_private.h" -#ifdef BN_MP_TC_XOR_C -/* LibTomMath, multiple-precision integer library -- Tom St Denis - * - * LibTomMath is a library that provides multiple-precision - * integer arithmetic as well as number theoretic functionality. - * - * The library was designed directly after the MPI library by - * Michael Fromberger but has been written from scratch with - * additional optimizations in place. - * - * SPDX-License-Identifier: Unlicense - */ - -/* two complement xor */ -int mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c) -{ - int res = MP_OKAY, bits, abits, bbits; - int as = mp_isneg(a), bs = mp_isneg(b); - mp_int *mx = NULL, _mx, acpy, bcpy; - - if ((as != MP_NO) || (bs != MP_NO)) { - abits = mp_count_bits(a); - bbits = mp_count_bits(b); - bits = MAX(abits, bbits); - res = mp_init_set_int(&_mx, 1uL); - if (res != MP_OKAY) { - goto end; - } - - mx = &_mx; - res = mp_mul_2d(mx, bits + 1, mx); - if (res != MP_OKAY) { - goto end; - } - - if (as != MP_NO) { - res = mp_init(&acpy); - if (res != MP_OKAY) { - goto end; - } - - res = mp_add(mx, a, &acpy); - if (res != MP_OKAY) { - mp_clear(&acpy); - goto end; - } - a = &acpy; - } - if (bs != MP_NO) { - res = mp_init(&bcpy); - if (res != MP_OKAY) { - goto end; - } - - res = mp_add(mx, b, &bcpy); - if (res != MP_OKAY) { - mp_clear(&bcpy); - goto end; - } - b = &bcpy; - } - } - - res = mp_xor(a, b, c); - - if ((as != bs) && (res == MP_OKAY)) { - res = mp_sub(c, mx, c); - } - -end: - if (a == &acpy) { - mp_clear(&acpy); - } - - if (b == &bcpy) { - mp_clear(&bcpy); - } - - if (mx == &_mx) { - mp_clear(mx); - } - - return res; -} -#endif - -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */ diff --git a/libtommath/bn_s_mp_get_bit.c b/libtommath/bn_s_mp_get_bit.c new file mode 100644 index 0000000..da9ccbb --- /dev/null +++ b/libtommath/bn_s_mp_get_bit.c @@ -0,0 +1,21 @@ +#include "tommath_private.h" +#ifdef BN_S_MP_GET_BIT_C + +/* LibTomMath, multiple-precision integer library -- Tom St Denis */ +/* SPDX-License-Identifier: Unlicense */ + +/* Get bit at position b and return MP_YES if the bit is 1, MP_NO if it is 0 */ +mp_bool s_mp_get_bit(const mp_int *a, int b) +{ + mp_digit bit; + int limb = (int)((unsigned)b / MP_DIGIT_BIT); + + if (limb >= a->used) { + return MP_NO; + } + + bit = (mp_digit)1 << ((unsigned)b % MP_DIGIT_BIT); + return ((a->dp[limb] & bit) != 0u) ? MP_YES : MP_NO; +} + +#endif diff --git a/libtommath/tommath.h b/libtommath/tommath.h index b5faf8c..5fd149c 100644 --- a/libtommath/tommath.h +++ b/libtommath/tommath.h @@ -1,14 +1,6 @@ -/* LibTomMath, multiple-precision integer library -- Tom St Denis - * - * LibTomMath is a library that provides multiple-precision - * integer arithmetic as well as number theoretic functionality. - * - * The library was designed directly after the MPI library by - * Michael Fromberger but has been written from scratch with - * additional optimizations in place. - * - * SPDX-License-Identifier: Unlicense - */ +/* LibTomMath, multiple-precision integer library -- Tom St Denis */ +/* SPDX-License-Identifier: Unlicense */ + #ifndef BN_H_ #define BN_H_ @@ -159,18 +151,18 @@ void mp_clear_multi(mp_int *mp, ...); void mp_exch(mp_int *a, mp_int *b); /* shrink ram required for a bignum */ -int mp_shrink(mp_int *a); +mp_err mp_shrink(mp_int *a); /* grow an int to a given size */ -int mp_grow(mp_int *a, int size); +mp_err mp_grow(mp_int *a, int size); /* init to a given number of digits */ -int mp_init_size(mp_int *a, int size); +mp_err mp_init_size(mp_int *a, int size); /* ---> Basic Manipulations <--- */ #define mp_iszero(a) (((a)->used == 0) ? MP_YES : MP_NO) -#define mp_iseven(a) (!mp_get_bit((a),0)) -#define mp_isodd(a) mp_get_bit((a),0) +#define mp_iseven(a) (((a)->used == 0 || (((a)->dp[0] & 1) == 0)) ? MP_YES : MP_NO) +#define mp_isodd(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 1)) ? MP_YES : MP_NO) #define mp_isneg(a) (((a)->sign != MP_ZPOS) ? MP_YES : MP_NO) /* set to zero */ @@ -294,7 +286,7 @@ int mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c); int mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c); /* right shift (two complement) */ -int mp_tc_div_2d(const mp_int *a, int b, mp_int *c); +int mp_signed_rsh(const mp_int *a, int b, mp_int *c); /* ---> Basic arithmetic <--- */ diff --git a/libtommath/tommath_class.h b/libtommath/tommath_class.h index 46f9996..b3c09fe 100644 --- a/libtommath/tommath_class.h +++ b/libtommath/tommath_class.h @@ -59,7 +59,7 @@ # define BN_MP_FREAD_C # define BN_MP_FWRITE_C # define BN_MP_GCD_C -# define BN_MP_GET_BIT_C +# define BN_S_MP_GET_BIT_C # define BN_MP_GET_DOUBLE_C # define BN_MP_GET_INT_C # define BN_MP_GET_LONG_C @@ -135,7 +135,7 @@ # define BN_MP_SUB_D_C # define BN_MP_SUBMOD_C # define BN_MP_TC_AND_C -# define BN_MP_TC_DIV_2D_C +# define BN_MP_SIGNED_RSH_C # define BN_MP_TC_OR_C # define BN_MP_TC_XOR_C # define BN_MP_TO_SIGNED_BIN_C @@ -442,7 +442,7 @@ # define BN_MP_CLEAR_C #endif -#if defined(BN_MP_GET_BIT_C) +#if defined(BN_S_MP_GET_BIT_C) # define BN_MP_ISZERO_C #endif @@ -715,7 +715,7 @@ # define BN_MP_MUL_C # define BN_MP_SUB_C # define BN_MP_MOD_C -# define BN_MP_GET_BIT_C +# define BN_S_MP_GET_BIT_C # define BN_MP_EXCH_C # define BN_MP_ISZERO_C # define BN_MP_CMP_C @@ -802,7 +802,7 @@ # define BN_MP_MOD_C # define BN_MP_SQR_C # define BN_MP_SUB_C -# define BN_MP_GET_BIT_C +# define BN_S_MP_GET_BIT_C # define BN_MP_ADD_C # define BN_MP_ISODD_C # define BN_MP_DIV_2_C @@ -1034,7 +1034,7 @@ # define BN_MP_SUB_C #endif -#if defined(BN_MP_TC_DIV_2D_C) +#if defined(BN_MP_SIGNED_RSH_C) # define BN_MP_ISNEG_C # define BN_MP_DIV_2D_C # define BN_MP_ADD_D_C diff --git a/unix/Makefile.in b/unix/Makefile.in index 71ecd84..0afd069 100644 --- a/unix/Makefile.in +++ b/unix/Makefile.in @@ -326,7 +326,7 @@ TOMMATH_OBJS = bn_reverse.o bn_fast_s_mp_mul_digs.o \ bn_mp_cnt_lsb.o bn_mp_copy.o \ bn_mp_count_bits.o bn_mp_div.o bn_mp_div_d.o bn_mp_div_2.o \ bn_mp_div_2d.o bn_mp_div_3.o bn_mp_exch.o \ - bn_mp_expt_d.o bn_mp_expt_d_ex.o bn_mp_get_bit.o bn_mp_get_int.o \ + bn_mp_expt_d.o bn_mp_expt_d_ex.o bn_s_mp_get_bit.o bn_mp_get_int.o \ bn_mp_get_long.o bn_mp_get_long_long.o bn_mp_grow.o bn_mp_init.o \ bn_mp_init_copy.o bn_mp_init_multi.o bn_mp_init_set.o \ bn_mp_init_set_int.o bn_mp_init_size.o bn_mp_karatsuba_mul.o \ @@ -337,7 +337,7 @@ TOMMATH_OBJS = bn_reverse.o bn_fast_s_mp_mul_digs.o \ bn_mp_read_radix.o bn_mp_rshd.o bn_mp_set.o bn_mp_set_int.o \ bn_mp_set_long.o bn_mp_set_long_long.o bn_mp_shrink.o \ bn_mp_sqr.o bn_mp_sqrt.o bn_mp_sub.o bn_mp_sub_d.o \ - bn_mp_tc_and.o bn_mp_tc_div_2d.o bn_mp_tc_or.o bn_mp_tc_xor.o \ + bn_mp_signed_rsh.o \ bn_mp_to_unsigned_bin.o bn_mp_to_unsigned_bin_n.o \ bn_mp_toom_mul.o bn_mp_toom_sqr.o bn_mp_toradix_n.o \ bn_mp_unsigned_bin_size.o bn_mp_xor.o bn_mp_zero.o bn_s_mp_add.o \ @@ -547,10 +547,7 @@ TOMMATH_SRCS = \ $(TOMMATH_DIR)/bn_mp_sqrt.c \ $(TOMMATH_DIR)/bn_mp_sub.c \ $(TOMMATH_DIR)/bn_mp_sub_d.c \ - $(TOMMATH_DIR)/bn_mp_tc_and.c \ - $(TOMMATH_DIR)/bn_mp_tc_div_2d.c \ - $(TOMMATH_DIR)/bn_mp_tc_or.c \ - $(TOMMATH_DIR)/bn_mp_tc_xor.c \ + $(TOMMATH_DIR)/bn_mp_signed_rsh.c \ $(TOMMATH_DIR)/bn_mp_to_unsigned_bin.c \ $(TOMMATH_DIR)/bn_mp_to_unsigned_bin_n.c \ $(TOMMATH_DIR)/bn_mp_toom_mul.c \ @@ -1528,8 +1525,8 @@ bn_mp_expt_d.o: $(TOMMATH_DIR)/bn_mp_expt_d.c $(MATHHDRS) bn_mp_expt_d_ex.o: $(TOMMATH_DIR)/bn_mp_expt_d_ex.c $(MATHHDRS) $(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_expt_d_ex.c -bn_mp_get_bit.o: $(TOMMATH_DIR)/bn_mp_get_bit.c $(MATHHDRS) - $(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_get_bit.c +bn_s_mp_get_bit.o: $(TOMMATH_DIR)/bn_s_mp_get_bit.c $(MATHHDRS) + $(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_s_mp_get_bit.c bn_mp_get_int.o: $(TOMMATH_DIR)/bn_mp_get_int.c $(MATHHDRS) $(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_get_int.c @@ -1633,17 +1630,8 @@ bn_mp_sub.o: $(TOMMATH_DIR)/bn_mp_sub.c $(MATHHDRS) bn_mp_sub_d.o: $(TOMMATH_DIR)/bn_mp_sub_d.c $(MATHHDRS) $(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_sub_d.c -bn_mp_tc_and.o: $(TOMMATH_DIR)/bn_mp_tc_and.c $(MATHHDRS) - $(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_tc_and.c - -bn_mp_tc_div_2d.o: $(TOMMATH_DIR)/bn_mp_tc_div_2d.c $(MATHHDRS) - $(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_tc_div_2d.c - -bn_mp_tc_or.o: $(TOMMATH_DIR)/bn_mp_tc_or.c $(MATHHDRS) - $(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_tc_or.c - -bn_mp_tc_xor.o: $(TOMMATH_DIR)/bn_mp_tc_xor.c $(MATHHDRS) - $(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_tc_xor.c +bn_mp_signed_rsh.o: $(TOMMATH_DIR)/bn_mp_signed_rsh.c $(MATHHDRS) + $(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_signed_rsh.c bn_mp_to_unsigned_bin.o: $(TOMMATH_DIR)/bn_mp_to_unsigned_bin.c $(MATHHDRS) $(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_to_unsigned_bin.c diff --git a/win/Makefile.in b/win/Makefile.in index faf4b77..af2b6e3 100644 --- a/win/Makefile.in +++ b/win/Makefile.in @@ -383,7 +383,7 @@ TOMMATH_OBJS = \ bn_mp_exch.${OBJEXT} \ bn_mp_expt_d.${OBJEXT} \ bn_mp_expt_d_ex.${OBJEXT} \ - bn_mp_get_bit.${OBJEXT} \ + bn_s_mp_get_bit.${OBJEXT} \ bn_mp_get_int.${OBJEXT} \ bn_mp_get_long.${OBJEXT} \ bn_mp_get_long_long.${OBJEXT} \ @@ -418,10 +418,7 @@ TOMMATH_OBJS = \ bn_mp_sqrt.${OBJEXT} \ bn_mp_sub.${OBJEXT} \ bn_mp_sub_d.${OBJEXT} \ - bn_mp_tc_and.${OBJEXT} \ - bn_mp_tc_div_2d.${OBJEXT} \ - bn_mp_tc_or.${OBJEXT} \ - bn_mp_tc_xor.${OBJEXT} \ + bn_mp_signed_rsh.${OBJEXT} \ bn_mp_to_unsigned_bin.${OBJEXT} \ bn_mp_to_unsigned_bin_n.${OBJEXT} \ bn_mp_toom_mul.${OBJEXT} \ diff --git a/win/makefile.vc b/win/makefile.vc index e159538..44af015 100644 --- a/win/makefile.vc +++ b/win/makefile.vc @@ -275,7 +275,7 @@ TOMMATHOBJS = \ $(TMP_DIR)\bn_mp_exch.obj \
$(TMP_DIR)\bn_mp_expt_d.obj \
$(TMP_DIR)\bn_mp_expt_d_ex.obj \
- $(TMP_DIR)\bn_mp_get_bit.obj \
+ $(TMP_DIR)\bn_s_mp_get_bit.obj \
$(TMP_DIR)\bn_mp_get_int.obj \
$(TMP_DIR)\bn_mp_get_long.obj \
$(TMP_DIR)\bn_mp_get_long_long.obj \
@@ -310,10 +310,7 @@ TOMMATHOBJS = \ $(TMP_DIR)\bn_mp_sqrt.obj \
$(TMP_DIR)\bn_mp_sub.obj \
$(TMP_DIR)\bn_mp_sub_d.obj \
- $(TMP_DIR)\bn_mp_tc_and.obj \
- $(TMP_DIR)\bn_mp_tc_div_2d.obj \
- $(TMP_DIR)\bn_mp_tc_or.obj \
- $(TMP_DIR)\bn_mp_tc_xor.obj \
+ $(TMP_DIR)\bn_mp_signed_rsh.obj \
$(TMP_DIR)\bn_mp_to_unsigned_bin.obj \
$(TMP_DIR)\bn_mp_to_unsigned_bin_n.obj \
$(TMP_DIR)\bn_mp_toom_mul.obj \
|