summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generic/tclInt.h3
-rw-r--r--generic/tclLink.c6
-rw-r--r--generic/tclObj.c19
-rw-r--r--generic/tclStubInit.c85
-rw-r--r--generic/tclTomMath.decls24
-rw-r--r--generic/tclTomMathDecls.h54
6 files changed, 116 insertions, 75 deletions
diff --git a/generic/tclInt.h b/generic/tclInt.h
index 5be988d..1fe3822 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -4193,9 +4193,6 @@ MODULE_SCOPE int TclIndexEncode(Tcl_Interp *interp, Tcl_Obj *objPtr,
int before, int after, int *indexPtr);
MODULE_SCOPE int TclIndexDecode(int encoded, int endValue);
-MODULE_SCOPE int TclBN_mp_to_ubin(const mp_int *a, unsigned char *buf, size_t maxlen, size_t *written);
-MODULE_SCOPE size_t TclBN_mp_ubin_size(const mp_int *a);
-MODULE_SCOPE int TclBN_mp_to_radix(const mp_int *a, char *str, size_t maxlen, size_t *written, int radix);
MODULE_SCOPE void TclBN_int_reverse(unsigned char *s, size_t len);
/* Constants used in index value encoding routines. */
diff --git a/generic/tclLink.c b/generic/tclLink.c
index 030e471..6b7b997 100644
--- a/generic/tclLink.c
+++ b/generic/tclLink.c
@@ -533,11 +533,11 @@ GetUWide(
Tcl_WideUInt value;
unsigned char bytes[sizeof(Tcl_WideUInt)];
} scratch;
- unsigned long numBytes = sizeof(Tcl_WideUInt);
+ size_t numBytes;
unsigned char *bytes = scratch.bytes;
- if (numPtr->sign || (MP_OKAY != mp_to_unsigned_bin_n(numPtr,
- bytes, &numBytes))) {
+ if (numPtr->sign || (MP_OKAY != mp_to_ubin(numPtr,
+ bytes, sizeof(Tcl_WideUInt), &numBytes))) {
/*
* If the sign bit is set (a negative value) or if the value
* can't possibly fit in the bits of an unsigned wide, there's
diff --git a/generic/tclObj.c b/generic/tclObj.c
index 58f6fe7..954c648 100644
--- a/generic/tclObj.c
+++ b/generic/tclObj.c
@@ -3019,11 +3019,12 @@ Tcl_GetLongFromObj(
*/
mp_int big;
- unsigned long scratch, value = 0, numBytes = sizeof(unsigned long);
+ unsigned long scratch, value = 0;
unsigned char *bytes = (unsigned char *) &scratch;
+ size_t numBytes;
TclUnpackBignum(objPtr, big);
- if (mp_to_unsigned_bin_n(&big, bytes, &numBytes) == MP_OKAY) {
+ if (mp_to_ubin(&big, bytes, sizeof(long), &numBytes) == MP_OKAY) {
while (numBytes-- > 0) {
value = (value << CHAR_BIT) | *bytes++;
}
@@ -3258,12 +3259,12 @@ Tcl_GetWideIntFromObj(
mp_int big;
Tcl_WideUInt value = 0;
- unsigned long numBytes = sizeof(Tcl_WideInt);
+ size_t numBytes;
Tcl_WideInt scratch;
unsigned char *bytes = (unsigned char *) &scratch;
TclUnpackBignum(objPtr, big);
- if (mp_to_unsigned_bin_n(&big, bytes, &numBytes) == MP_OKAY) {
+ if (mp_to_ubin(&big, bytes, sizeof(Tcl_WideInt), &numBytes) == MP_OKAY) {
while (numBytes-- > 0) {
value = (value << CHAR_BIT) | *bytes++;
}
@@ -3339,12 +3340,12 @@ TclGetWideBitsFromObj(
mp_int big;
Tcl_WideUInt value = 0, scratch;
- unsigned long numBytes = sizeof(Tcl_WideInt);
+ size_t numBytes;
unsigned char *bytes = (unsigned char *) &scratch;
Tcl_GetBignumFromObj(NULL, objPtr, &big);
mp_mod_2d(&big, (int) (CHAR_BIT * sizeof(Tcl_WideInt)), &big);
- mp_to_unsigned_bin_n(&big, bytes, &numBytes);
+ mp_to_ubin(&big, bytes, sizeof(Tcl_WideInt), &numBytes);
while (numBytes-- > 0) {
value = (value << CHAR_BIT) | *bytes++;
}
@@ -3464,7 +3465,7 @@ UpdateStringOfBignum(
stringVal = Tcl_InitStringRep(objPtr, NULL, size - 1);
TclOOM(stringVal, size);
- if (MP_OKAY != mp_toradix_n(&bignumVal, stringVal, 10, size)) {
+ if (MP_OKAY != mp_to_radix(&bignumVal, stringVal, size, NULL, 10)) {
Tcl_Panic("conversion failure in UpdateStringOfBignum");
}
(void) Tcl_InitStringRep(objPtr, NULL, size - 1);
@@ -3713,14 +3714,14 @@ Tcl_SetBignumObj(
mp_int *bignumValue) /* Value to store */
{
Tcl_WideUInt value = 0;
- unsigned long numBytes = sizeof(Tcl_WideUInt);
+ size_t numBytes;
Tcl_WideUInt scratch;
unsigned char *bytes = (unsigned char *) &scratch;
if (Tcl_IsShared(objPtr)) {
Tcl_Panic("%s called with shared object", "Tcl_SetBignumObj");
}
- if (mp_to_unsigned_bin_n(bignumValue, bytes, &numBytes) != MP_OKAY) {
+ if (mp_to_ubin(bignumValue, bytes, sizeof(Tcl_WideUInt), &numBytes) != MP_OKAY) {
goto tooLargeForWide;
}
while (numBytes-- > 0) {
diff --git a/generic/tclStubInit.c b/generic/tclStubInit.c
index ef49ca9..8aea217 100644
--- a/generic/tclStubInit.c
+++ b/generic/tclStubInit.c
@@ -93,10 +93,13 @@ mp_err TclBN_mp_set_int(mp_int *a, unsigned long i)
mp_err TclBN_mp_init_set_int(mp_int *a, unsigned long i)
{
- mp_init(a);
+ mp_err result = mp_init(a);
+ if (result == MP_OKAY) {
TclBN_mp_set_ul(a, i);
- return MP_OKAY;
+ }
+ return result;
}
+
static mp_err TclBN_mp_set_long(mp_int *a, unsigned long i)
{
TclBN_mp_set_ul(a, i);
@@ -105,12 +108,10 @@ static mp_err TclBN_mp_set_long(mp_int *a, unsigned long i)
#define TclBN_mp_set_ul (void (*)(mp_int *a, unsigned long i))TclBN_mp_set_long
-int TclBN_mp_expt_d_ex(const mp_int *a, mp_digit b, mp_int *c, int fast)
-{
- return mp_expt_u32(a, b, c);
-}
-
#if defined(TCL_NO_DEPRECATED) || TCL_MAJOR_VERSION > 8
+# define TclBN_mp_expt_d_ex 0
+# define TclBN_mp_to_unsigned_bin 0
+# define TclBN_mp_to_unsigned_bin_n 0
# define TclSetStartupScriptPath 0
# define TclGetStartupScriptPath 0
# define TclSetStartupScriptFileName 0
@@ -142,6 +143,42 @@ int TclBN_mp_expt_d_ex(const mp_int *a, mp_digit b, mp_int *c, int fast)
# define Tcl_DbNewLongObj 0
# define Tcl_BackgroundError 0
#else
+
+int TclBN_mp_expt_d_ex(const mp_int *a, mp_digit b, mp_int *c, int fast)
+{
+ return mp_expt_u32(a, b, c);
+}
+
+mp_err mp_to_unsigned_bin(const mp_int *a, unsigned char *b)
+{
+ return mp_to_ubin(a, b, INT_MAX, NULL);
+}
+
+mp_err mp_to_unsigned_bin_n(const mp_int *a, unsigned char *b, unsigned long *outlen)
+{
+ size_t n = mp_ubin_size(a);
+ if (*outlen < (unsigned long)n) {
+ return MP_VAL;
+ }
+ *outlen = (unsigned long)n;
+ return mp_to_ubin(a, b, n, NULL);
+}
+
+void bn_reverse(unsigned char *s, int len)
+{
+ if (len > 0) {
+ s_mp_reverse(s, (size_t)len);
+ }
+}
+
+mp_err mp_toradix_n(const mp_int *a, char *str, int radix, int maxlen)
+{
+ if (maxlen < 0) {
+ return MP_VAL;
+ }
+ return mp_to_radix(a, str, (size_t)maxlen, NULL, radix);
+}
+
#define TclBNInitBignumFromLong initBignumFromLong
static void TclBNInitBignumFromLong(mp_int *a, long b)
{
@@ -505,38 +542,9 @@ tellOld(
#define Tcl_WinTCharToUtf 0
#endif
-mp_err mp_to_unsigned_bin(const mp_int *a, unsigned char *b)
-{
- return mp_to_ubin(a, b, INT_MAX, NULL);
-}
-
-mp_err mp_to_unsigned_bin_n(const mp_int *a, unsigned char *b, unsigned long *outlen)
-{
- size_t n = mp_ubin_size(a);
- if (*outlen < (unsigned long)n) {
- return MP_VAL;
- }
- *outlen = (unsigned long)n;
- return mp_to_ubin(a, b, n, NULL);
-}
-
-mp_err mp_toradix_n(const mp_int *a, char *str, int radix, int maxlen)
-{
- if (maxlen < 0) {
- return MP_VAL;
- }
- return mp_to_radix(a, str, (size_t)maxlen, NULL, radix);
-}
#undef TclBN_mp_unsigned_bin_size
#define TclBN_mp_unsigned_bin_size (int (*)(const mp_int *a)) mp_ubin_size
-void bn_reverse(unsigned char *s, int len)
-{
- if (len > 0) {
- s_mp_reverse(s, (size_t)len);
- }
-}
-
/*
* WARNING: The contents of this file is automatically generated by the
* tools/genStubs.tcl script. Any modifications to the function declarations
@@ -960,7 +968,7 @@ const TclTomMathStubs tclTomMathStubs = {
TclBN_mp_div_2d, /* 16 */
TclBN_mp_div_3, /* 17 */
TclBN_mp_exch, /* 18 */
- TclBN_mp_expt_d, /* 19 */
+ TclBN_mp_expt_u32, /* 19 */
TclBN_mp_grow, /* 20 */
TclBN_mp_init, /* 21 */
TclBN_mp_init_copy, /* 22 */
@@ -1019,6 +1027,9 @@ const TclTomMathStubs tclTomMathStubs = {
TclBN_mp_tc_xor, /* 75 */
TclBN_mp_signed_rsh, /* 76 */
TclBN_mp_get_bit, /* 77 */
+ TclBN_mp_to_ubin, /* 78 */
+ TclBN_mp_ubin_size, /* 79 */
+ TclBN_mp_to_radix, /* 80 */
};
static const TclStubHooks tclStubHooks = {
diff --git a/generic/tclTomMath.decls b/generic/tclTomMath.decls
index 6b33b00..eece1a4 100644
--- a/generic/tclTomMath.decls
+++ b/generic/tclTomMath.decls
@@ -81,7 +81,7 @@ declare 18 {
void TclBN_mp_exch(mp_int *a, mp_int *b)
}
declare 19 {
- mp_err TclBN_mp_expt_d(const mp_int *a, unsigned int b, mp_int *c)
+ mp_err TclBN_mp_expt_u32(const mp_int *a, unsigned int b, mp_int *c)
}
declare 20 {
mp_err TclBN_mp_grow(mp_int *a, int size)
@@ -155,14 +155,14 @@ declare 42 {
declare 43 {
mp_err TclBN_mp_sub_d(const mp_int *a, mp_digit b, mp_int *c)
}
-declare 44 {
+declare 44 {deprecated {Use mp_to_ubin}} {
mp_err TclBN_mp_to_unsigned_bin(const mp_int *a, unsigned char *b)
}
-declare 45 {
+declare 45 {deprecated {Use mp_to_ubin}} {
mp_err TclBN_mp_to_unsigned_bin_n(const mp_int *a, unsigned char *b,
unsigned long *outlen)
}
-declare 46 {
+declare 46 {deprecated {Use mp_to_radix}} {
mp_err TclBN_mp_toradix_n(const mp_int *a, char *str, int radix, int maxlen)
}
declare 47 {
@@ -234,7 +234,7 @@ declare 66 {deprecated {Use mp_init() + mp_set_ull()}} {
}
# Added in libtommath 1.0
-declare 67 {
+declare 67 {deprecated {Use mp_expt_u32}} {
mp_err TclBN_mp_expt_d_ex(const mp_int *a, mp_digit b, mp_int *c, int fast)
}
# Added in libtommath 1.0.1
@@ -264,11 +264,21 @@ declare 75 {
declare 76 {
mp_err TclBN_mp_signed_rsh(const mp_int *a, int b, mp_int *c)
}
-
-declare 77 {
+declare 77 {deprecated {is private function in libtommath}} {
mp_bool TclBN_mp_get_bit(const mp_int *a, unsigned int b)
}
+# Added in libtommath 1.2.0
+declare 78 {
+ int TclBN_mp_to_ubin(const mp_int *a, unsigned char *buf, size_t maxlen, size_t *written)
+}
+declare 79 {
+ size_t TclBN_mp_ubin_size(const mp_int *a)
+}
+declare 80 {
+ int TclBN_mp_to_radix(const mp_int *a, char *str, size_t maxlen, size_t *written, int radix)
+}
+
# Local Variables:
# mode: tcl
diff --git a/generic/tclTomMathDecls.h b/generic/tclTomMathDecls.h
index 6f7ebb8..7c8c5aa 100644
--- a/generic/tclTomMathDecls.h
+++ b/generic/tclTomMathDecls.h
@@ -74,9 +74,9 @@
#define mp_div_3 TclBN_mp_div_3
#define mp_div_d TclBN_mp_div_d
#define mp_exch TclBN_mp_exch
-#define mp_expt_d TclBN_mp_expt_d
+#define mp_expt_d TclBN_mp_expt_u32
#define mp_expt_d_ex TclBN_mp_expt_d_ex
-#define mp_expt_u32 TclBN_mp_expt_d
+#define mp_expt_u32 TclBN_mp_expt_u32
#define mp_get_bit TclBN_mp_get_bit
#define mp_get_long TclBN_mp_get_mag_ul
#define mp_get_mag_ul TclBN_mp_get_mag_ul
@@ -215,7 +215,7 @@ EXTERN mp_err TclBN_mp_div_3(const mp_int *a, mp_int *q,
/* 18 */
EXTERN void TclBN_mp_exch(mp_int *a, mp_int *b);
/* 19 */
-EXTERN mp_err TclBN_mp_expt_d(const mp_int *a, unsigned int b,
+EXTERN mp_err TclBN_mp_expt_u32(const mp_int *a, unsigned int b,
mp_int *c);
/* 20 */
EXTERN mp_err TclBN_mp_grow(mp_int *a, int size);
@@ -274,13 +274,16 @@ EXTERN mp_err TclBN_mp_sub(const mp_int *a, const mp_int *b,
EXTERN mp_err TclBN_mp_sub_d(const mp_int *a, mp_digit b,
mp_int *c);
/* 44 */
-EXTERN mp_err TclBN_mp_to_unsigned_bin(const mp_int *a,
+TCL_DEPRECATED("Use mp_to_ubin")
+mp_err TclBN_mp_to_unsigned_bin(const mp_int *a,
unsigned char *b);
/* 45 */
-EXTERN mp_err TclBN_mp_to_unsigned_bin_n(const mp_int *a,
+TCL_DEPRECATED("Use mp_to_ubin")
+mp_err TclBN_mp_to_unsigned_bin_n(const mp_int *a,
unsigned char *b, unsigned long *outlen);
/* 46 */
-EXTERN mp_err TclBN_mp_toradix_n(const mp_int *a, char *str,
+TCL_DEPRECATED("Use mp_to_radix")
+mp_err TclBN_mp_toradix_n(const mp_int *a, char *str,
int radix, int maxlen);
/* 47 */
EXTERN int TclBN_mp_unsigned_bin_size(const mp_int *a);
@@ -346,7 +349,8 @@ TCL_DEPRECATED("Use mp_init() + mp_set_ull()")
void TclBNInitBignumFromWideUInt(mp_int *bignum,
Tcl_WideUInt initVal);
/* 67 */
-EXTERN mp_err TclBN_mp_expt_d_ex(const mp_int *a, mp_digit b,
+TCL_DEPRECATED("Use mp_expt_u32")
+mp_err TclBN_mp_expt_d_ex(const mp_int *a, mp_digit b,
mp_int *c, int fast);
/* 68 */
EXTERN void TclBN_mp_set_ull(mp_int *a, Tcl_WideUInt i);
@@ -370,7 +374,16 @@ EXTERN mp_err TclBN_mp_tc_xor(const mp_int *a, const mp_int *b,
EXTERN mp_err TclBN_mp_signed_rsh(const mp_int *a, int b,
mp_int *c);
/* 77 */
-EXTERN mp_bool TclBN_mp_get_bit(const mp_int *a, unsigned int b);
+TCL_DEPRECATED("is private function in libtommath")
+mp_bool TclBN_mp_get_bit(const mp_int *a, unsigned int b);
+/* 78 */
+EXTERN int TclBN_mp_to_ubin(const mp_int *a, unsigned char *buf,
+ size_t maxlen, size_t *written);
+/* 79 */
+EXTERN size_t TclBN_mp_ubin_size(const mp_int *a);
+/* 80 */
+EXTERN int TclBN_mp_to_radix(const mp_int *a, char *str,
+ size_t maxlen, size_t *written, int radix);
typedef struct TclTomMathStubs {
int magic;
@@ -395,7 +408,7 @@ typedef struct TclTomMathStubs {
mp_err (*tclBN_mp_div_2d) (const mp_int *a, int b, mp_int *q, mp_int *r); /* 16 */
mp_err (*tclBN_mp_div_3) (const mp_int *a, mp_int *q, mp_digit *r); /* 17 */
void (*tclBN_mp_exch) (mp_int *a, mp_int *b); /* 18 */
- mp_err (*tclBN_mp_expt_d) (const mp_int *a, unsigned int b, mp_int *c); /* 19 */
+ mp_err (*tclBN_mp_expt_u32) (const mp_int *a, unsigned int b, mp_int *c); /* 19 */
mp_err (*tclBN_mp_grow) (mp_int *a, int size); /* 20 */
mp_err (*tclBN_mp_init) (mp_int *a); /* 21 */
mp_err (*tclBN_mp_init_copy) (mp_int *a, const mp_int *b); /* 22 */
@@ -420,9 +433,9 @@ typedef struct TclTomMathStubs {
mp_err (*tclBN_mp_sqrt) (const mp_int *a, mp_int *b); /* 41 */
mp_err (*tclBN_mp_sub) (const mp_int *a, const mp_int *b, mp_int *c); /* 42 */
mp_err (*tclBN_mp_sub_d) (const mp_int *a, mp_digit b, mp_int *c); /* 43 */
- mp_err (*tclBN_mp_to_unsigned_bin) (const mp_int *a, unsigned char *b); /* 44 */
- mp_err (*tclBN_mp_to_unsigned_bin_n) (const mp_int *a, unsigned char *b, unsigned long *outlen); /* 45 */
- mp_err (*tclBN_mp_toradix_n) (const mp_int *a, char *str, int radix, int maxlen); /* 46 */
+ TCL_DEPRECATED_API("Use mp_to_ubin") mp_err (*tclBN_mp_to_unsigned_bin) (const mp_int *a, unsigned char *b); /* 44 */
+ TCL_DEPRECATED_API("Use mp_to_ubin") mp_err (*tclBN_mp_to_unsigned_bin_n) (const mp_int *a, unsigned char *b, unsigned long *outlen); /* 45 */
+ TCL_DEPRECATED_API("Use mp_to_radix") mp_err (*tclBN_mp_toradix_n) (const mp_int *a, char *str, int radix, int maxlen); /* 46 */
int (*tclBN_mp_unsigned_bin_size) (const mp_int *a); /* 47 */
mp_err (*tclBN_mp_xor) (const mp_int *a, const mp_int *b, mp_int *c); /* 48 */
void (*tclBN_mp_zero) (mp_int *a); /* 49 */
@@ -443,7 +456,7 @@ typedef struct TclTomMathStubs {
TCL_DEPRECATED_API("Use mp_init() + mp_set_l()") void (*tclBNInitBignumFromLong) (mp_int *bignum, long initVal); /* 64 */
TCL_DEPRECATED_API("Use mp_init() + mp_set_ll()") void (*tclBNInitBignumFromWideInt) (mp_int *bignum, Tcl_WideInt initVal); /* 65 */
TCL_DEPRECATED_API("Use mp_init() + mp_set_ull()") void (*tclBNInitBignumFromWideUInt) (mp_int *bignum, Tcl_WideUInt initVal); /* 66 */
- mp_err (*tclBN_mp_expt_d_ex) (const mp_int *a, mp_digit b, mp_int *c, int fast); /* 67 */
+ TCL_DEPRECATED_API("Use mp_expt_u32") mp_err (*tclBN_mp_expt_d_ex) (const mp_int *a, mp_digit b, mp_int *c, int fast); /* 67 */
void (*tclBN_mp_set_ull) (mp_int *a, Tcl_WideUInt i); /* 68 */
Tcl_WideUInt (*tclBN_mp_get_mag_ull) (const mp_int *a); /* 69 */
void (*tclBN_mp_set_ul) (mp_int *a, unsigned long i); /* 70 */
@@ -453,7 +466,10 @@ typedef struct TclTomMathStubs {
mp_err (*tclBN_mp_tc_or) (const mp_int *a, const mp_int *b, mp_int *c); /* 74 */
mp_err (*tclBN_mp_tc_xor) (const mp_int *a, const mp_int *b, mp_int *c); /* 75 */
mp_err (*tclBN_mp_signed_rsh) (const mp_int *a, int b, mp_int *c); /* 76 */
- mp_bool (*tclBN_mp_get_bit) (const mp_int *a, unsigned int b); /* 77 */
+ TCL_DEPRECATED_API("is private function in libtommath") mp_bool (*tclBN_mp_get_bit) (const mp_int *a, unsigned int b); /* 77 */
+ int (*tclBN_mp_to_ubin) (const mp_int *a, unsigned char *buf, size_t maxlen, size_t *written); /* 78 */
+ size_t (*tclBN_mp_ubin_size) (const mp_int *a); /* 79 */
+ int (*tclBN_mp_to_radix) (const mp_int *a, char *str, size_t maxlen, size_t *written, int radix); /* 80 */
} TclTomMathStubs;
extern const TclTomMathStubs *tclTomMathStubsPtr;
@@ -506,8 +522,8 @@ extern const TclTomMathStubs *tclTomMathStubsPtr;
(tclTomMathStubsPtr->tclBN_mp_div_3) /* 17 */
#define TclBN_mp_exch \
(tclTomMathStubsPtr->tclBN_mp_exch) /* 18 */
-#define TclBN_mp_expt_d \
- (tclTomMathStubsPtr->tclBN_mp_expt_d) /* 19 */
+#define TclBN_mp_expt_u32 \
+ (tclTomMathStubsPtr->tclBN_mp_expt_u32) /* 19 */
#define TclBN_mp_grow \
(tclTomMathStubsPtr->tclBN_mp_grow) /* 20 */
#define TclBN_mp_init \
@@ -623,6 +639,12 @@ extern const TclTomMathStubs *tclTomMathStubsPtr;
(tclTomMathStubsPtr->tclBN_mp_signed_rsh) /* 76 */
#define TclBN_mp_get_bit \
(tclTomMathStubsPtr->tclBN_mp_get_bit) /* 77 */
+#define TclBN_mp_to_ubin \
+ (tclTomMathStubsPtr->tclBN_mp_to_ubin) /* 78 */
+#define TclBN_mp_ubin_size \
+ (tclTomMathStubsPtr->tclBN_mp_ubin_size) /* 79 */
+#define TclBN_mp_to_radix \
+ (tclTomMathStubsPtr->tclBN_mp_to_radix) /* 80 */
#endif /* defined(USE_TCL_STUBS) */