diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-05-31 12:09:48 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-05-31 12:09:48 (GMT) |
commit | d988f34ccf70a6f52475399257c185748fc019aa (patch) | |
tree | c26d7e6812b5308f05e53adb377673b4390f6cde | |
parent | 2baadaa351e9f7809be5ef3ae1837a2944434552 (diff) | |
parent | e80cd8e2841210153d80ec6fe42342d91d74a6d7 (diff) | |
download | tcl-d988f34ccf70a6f52475399257c185748fc019aa.zip tcl-d988f34ccf70a6f52475399257c185748fc019aa.tar.gz tcl-d988f34ccf70a6f52475399257c185748fc019aa.tar.bz2 |
Merge 8.7. Remove the mp_tc_(and|or|xor) stub entries, because they are no longer in use.
-rw-r--r-- | generic/tclExecute.c | 2 | ||||
-rw-r--r-- | generic/tclStrToD.c | 2 | ||||
-rw-r--r-- | generic/tclStubInit.c | 8 | ||||
-rw-r--r-- | generic/tclTestObj.c | 4 | ||||
-rw-r--r-- | generic/tclTomMath.decls | 23 | ||||
-rw-r--r-- | generic/tclTomMath.h | 35 | ||||
-rw-r--r-- | generic/tclTomMathDecls.h | 44 | ||||
-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, 118 insertions, 470 deletions
diff --git a/generic/tclExecute.c b/generic/tclExecute.c index e354ec2..3fd3771 100644 --- a/generic/tclExecute.c +++ b/generic/tclExecute.c @@ -7821,7 +7821,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 7402cee..0c4b4fb 100644 --- a/generic/tclStrToD.c +++ b/generic/tclStrToD.c @@ -4513,7 +4513,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 a0973fc..78b7dd5 100644 --- a/generic/tclStubInit.c +++ b/generic/tclStubInit.c @@ -654,10 +654,10 @@ const TclTomMathStubs tclTomMathStubs = { TclBN_mp_set_long, /* 70 */ TclBN_mp_get_long, /* 71 */ TclBN_mp_get_int, /* 72 */ - TclBN_mp_tc_and, /* 73 */ - TclBN_mp_tc_or, /* 74 */ - TclBN_mp_tc_xor, /* 75 */ - TclBN_mp_tc_div_2d, /* 76 */ + 0, /* 73 */ + 0, /* 74 */ + 0, /* 75 */ + TclBN_mp_signed_rsh, /* 76 */ TclBN_mp_get_bit, /* 77 */ }; diff --git a/generic/tclTestObj.c b/generic/tclTestObj.c index efa40e6..4abd3a2 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 d6201a0..dd819c4 100644 --- a/generic/tclTomMath.decls +++ b/generic/tclTomMath.decls @@ -221,17 +221,20 @@ declare 72 { } # Added in libtommath 1.1.0 -declare 73 { - int TclBN_mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c) -} -declare 74 { - int TclBN_mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c) -} -declare 75 { - int TclBN_mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c) -} +# No longer in use: replaced by mp_and() +#declare 73 { +# int TclBN_mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c) +#} +# No longer in use: replaced by mp_or() +#declare 74 { +# int TclBN_mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c) +#} +# No longer in use: replaced by mp_xor() +#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 840a9a7..e697181 100644 --- a/generic/tclTomMathDecls.h +++ b/generic/tclTomMathDecls.h @@ -71,11 +71,12 @@ #define mp_exch TclBN_mp_exch #define mp_expt_d TclBN_mp_expt_d #define mp_expt_d_ex TclBN_mp_expt_d_ex -#define mp_get_bit TclBN_mp_get_bit #define mp_get_int TclBN_mp_get_int #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 @@ -107,10 +108,7 @@ #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_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 @@ -324,17 +322,12 @@ EXTERN int TclBN_mp_set_long(mp_int *a, unsigned long i); EXTERN unsigned long TclBN_mp_get_long(const mp_int *a); /* 72 */ EXTERN unsigned long TclBN_mp_get_int(const mp_int *a); -/* 73 */ -EXTERN int TclBN_mp_tc_and(const mp_int *a, const mp_int *b, - mp_int *c); -/* 74 */ -EXTERN int TclBN_mp_tc_or(const mp_int *a, const mp_int *b, - mp_int *c); -/* 75 */ -EXTERN int TclBN_mp_tc_xor(const mp_int *a, const mp_int *b, - mp_int *c); +/* Slot 73 is reserved */ +/* Slot 74 is reserved */ +/* Slot 75 is reserved */ /* 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); @@ -415,10 +408,10 @@ typedef struct TclTomMathStubs { int (*tclBN_mp_set_long) (mp_int *a, unsigned long i); /* 70 */ unsigned long (*tclBN_mp_get_long) (const mp_int *a); /* 71 */ unsigned long (*tclBN_mp_get_int) (const mp_int *a); /* 72 */ - 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 */ + void (*reserved73)(void); + void (*reserved74)(void); + void (*reserved75)(void); + 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; @@ -566,14 +559,11 @@ extern const TclTomMathStubs *tclTomMathStubsPtr; (tclTomMathStubsPtr->tclBN_mp_get_long) /* 71 */ #define TclBN_mp_get_int \ (tclTomMathStubsPtr->tclBN_mp_get_int) /* 72 */ -#define TclBN_mp_tc_and \ - (tclTomMathStubsPtr->tclBN_mp_tc_and) /* 73 */ -#define TclBN_mp_tc_or \ - (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 */ +/* Slot 73 is reserved */ +/* Slot 74 is reserved */ +/* Slot 75 is reserved */ +#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 fd3ae6f..b9739ce 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 888b19e..e1dc5d9 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 c61d846..0436d86 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 \
|