summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2019-11-07 13:56:25 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2019-11-07 13:56:25 (GMT)
commitdd8793f10dce07f7111054c83df565e501e5f4f4 (patch)
tree0f64d1b2135d9e2d755b930f457b77035abf2bbd
parent1a379fa9610094d9b0e8d7f07d659c0d624e4068 (diff)
downloadtcl-dd8793f10dce07f7111054c83df565e501e5f4f4.zip
tcl-dd8793f10dce07f7111054c83df565e501e5f4f4.tar.gz
tcl-dd8793f10dce07f7111054c83df565e501e5f4f4.tar.bz2
Deprecate mp_div_3(): Will be private function in future libtommath, not used in Tcl.
Deprecate mp_sqr() stub entry: Will be converted to macro calling mp_mul().
-rw-r--r--generic/tclStubInit.c19
-rw-r--r--generic/tclTomMath.decls4
-rw-r--r--generic/tclTomMathDecls.h14
-rw-r--r--libtommath/bn_mp_mul.c4
4 files changed, 26 insertions, 15 deletions
diff --git a/generic/tclStubInit.c b/generic/tclStubInit.c
index 087adfc..54cd83c 100644
--- a/generic/tclStubInit.c
+++ b/generic/tclStubInit.c
@@ -121,14 +121,6 @@ mp_err TclBN_mp_div_d(const mp_int *a, unsigned int b, mp_int *c, unsigned int *
}
return result;
}
-mp_err TclBN_mp_div_3(const mp_int *a, mp_int *c, unsigned int *d) {
- mp_digit d2;
- mp_err result = TclBN_s_mp_div_3(a, c, &d2);
- if (d) {
- *d = d2;
- }
- return result;
-}
mp_err TclBN_mp_init_set(mp_int *a, unsigned int b) {
return TclBN_s_mp_init_set(a, b);
}
@@ -146,6 +138,8 @@ void TclBN_mp_set(mp_int *a, unsigned int b) {
# define TclBN_mp_to_unsigned_bin 0
# define TclBN_mp_to_unsigned_bin_n 0
# define TclBN_mp_toradix_n 0
+# define TclBN_mp_sqr 0
+# define TclBN_mp_div_3 0
# define TclSetStartupScriptPath 0
# define TclGetStartupScriptPath 0
# define TclSetStartupScriptFileName 0
@@ -178,6 +172,15 @@ void TclBN_mp_set(mp_int *a, unsigned int b) {
# define Tcl_BackgroundError 0
#else
+mp_err TclBN_mp_div_3(const mp_int *a, mp_int *c, unsigned int *d) {
+ mp_digit d2;
+ mp_err result = TclBN_s_mp_div_3(a, c, &d2);
+ if (d) {
+ *d = d2;
+ }
+ return result;
+}
+
int TclBN_mp_expt_d_ex(const mp_int *a, unsigned int b, mp_int *c, int fast)
{
return mp_expt_u32(a, b, c);
diff --git a/generic/tclTomMath.decls b/generic/tclTomMath.decls
index f95371e..723bb0a 100644
--- a/generic/tclTomMath.decls
+++ b/generic/tclTomMath.decls
@@ -74,7 +74,7 @@ declare 15 {
declare 16 {
mp_err MP_WUR TclBN_mp_div_2d(const mp_int *a, int b, mp_int *q, mp_int *r)
}
-declare 17 {
+declare 17 {deprecated {is private function in libtommath}} {
mp_err MP_WUR TclBN_mp_div_3(const mp_int *a, mp_int *q, unsigned int *r)
}
declare 18 {
@@ -143,7 +143,7 @@ declare 38 {
declare 39 {
void TclBN_mp_set(mp_int *a, unsigned int b)
}
-declare 40 {
+declare 40 {nostub {is private function in libtommath}} {
mp_err MP_WUR TclBN_mp_sqr(const mp_int *a, mp_int *b)
}
declare 41 {
diff --git a/generic/tclTomMathDecls.h b/generic/tclTomMathDecls.h
index c3032b1..cead9ad 100644
--- a/generic/tclTomMathDecls.h
+++ b/generic/tclTomMathDecls.h
@@ -106,7 +106,6 @@ MODULE_SCOPE mp_err TclBN_s_mp_expt_u32(const mp_int *a, unsigned int b, mp_int
#define mp_set_ul TclBN_mp_set_ul
#define mp_set_ull TclBN_mp_set_ull
#define mp_shrink TclBN_mp_shrink
-#define mp_sqr TclBN_mp_sqr
#define mp_sqrt TclBN_mp_sqrt
#define mp_sub TclBN_mp_sub
#define mp_signed_rsh TclBN_mp_signed_rsh
@@ -205,7 +204,8 @@ EXTERN mp_err TclBN_mp_div_2(const mp_int *a, mp_int *q) MP_WUR;
EXTERN mp_err TclBN_mp_div_2d(const mp_int *a, int b, mp_int *q,
mp_int *r) MP_WUR;
/* 17 */
-EXTERN mp_err TclBN_mp_div_3(const mp_int *a, mp_int *q,
+TCL_DEPRECATED("is private function in libtommath")
+mp_err MP_WUR TclBN_mp_div_3(const mp_int *a, mp_int *q,
unsigned int *r) MP_WUR;
/* 18 */
EXTERN void TclBN_mp_exch(mp_int *a, mp_int *b);
@@ -399,7 +399,7 @@ typedef struct TclTomMathStubs {
mp_err (*tclBN_mp_div_d) (const mp_int *a, unsigned int b, mp_int *q, unsigned int *r) MP_WUR; /* 14 */
mp_err (*tclBN_mp_div_2) (const mp_int *a, mp_int *q) MP_WUR; /* 15 */
mp_err (*tclBN_mp_div_2d) (const mp_int *a, int b, mp_int *q, mp_int *r) MP_WUR; /* 16 */
- mp_err (*tclBN_mp_div_3) (const mp_int *a, mp_int *q, unsigned int *r) MP_WUR; /* 17 */
+ TCL_DEPRECATED_API("is private function in libtommath") mp_err (*tclBN_mp_div_3) (const mp_int *a, mp_int *q, unsigned int *r) MP_WUR; /* 17 */
void (*tclBN_mp_exch) (mp_int *a, mp_int *b); /* 18 */
mp_err (*tclBN_mp_expt_u32) (const mp_int *a, unsigned int b, mp_int *c) MP_WUR; /* 19 */
mp_err (*tclBN_mp_grow) (mp_int *a, int size) MP_WUR; /* 20 */
@@ -422,7 +422,7 @@ typedef struct TclTomMathStubs {
void (*tclBN_mp_rshd) (mp_int *a, int shift); /* 37 */
mp_err (*tclBN_mp_shrink) (mp_int *a) MP_WUR; /* 38 */
void (*tclBN_mp_set) (mp_int *a, unsigned int b); /* 39 */
- mp_err (*tclBN_mp_sqr) (const mp_int *a, mp_int *b) MP_WUR; /* 40 */
+ TCL_DEPRECATED_API("is private function in libtommath") mp_err (*tclBN_mp_sqr) (const mp_int *a, mp_int *b) MP_WUR; /* 40 */
mp_err (*tclBN_mp_sqrt) (const mp_int *a, mp_int *b) MP_WUR; /* 41 */
mp_err (*tclBN_mp_sub) (const mp_int *a, const mp_int *b, mp_int *c) MP_WUR; /* 42 */
mp_err (*tclBN_mp_sub_d) (const mp_int *a, unsigned int b, mp_int *c) MP_WUR; /* 43 */
@@ -666,4 +666,10 @@ extern const TclTomMathStubs *tclTomMathStubsPtr;
#undef TCL_STORAGE_CLASS
#define TCL_STORAGE_CLASS DLLIMPORT
+#if defined(USE_TCL_STUBS)
+# define mp_sqr(a,b) mp_mul(a,a,b)
+#else
+# define mp_sqr TclBN_mp_sqr
+#endif
+
#endif /* _TCLINTDECLS */
diff --git a/libtommath/bn_mp_mul.c b/libtommath/bn_mp_mul.c
index c76b97d..c4890c5 100644
--- a/libtommath/bn_mp_mul.c
+++ b/libtommath/bn_mp_mul.c
@@ -12,7 +12,9 @@ mp_err mp_mul(const mp_int *a, const mp_int *b, mp_int *c)
digs = a->used + b->used + 1;
mp_sign neg = (a->sign == b->sign) ? MP_ZPOS : MP_NEG;
- if (MP_HAS(S_MP_BALANCE_MUL) &&
+ if (a == b) {
+ return mp_sqr(a,c);
+ } else if (MP_HAS(S_MP_BALANCE_MUL) &&
/* Check sizes. The smaller one needs to be larger than the Karatsuba cut-off.
* The bigger one needs to be at least about one MP_KARATSUBA_MUL_CUTOFF bigger
* to make some sense, but it depends on architecture, OS, position of the