summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2019-11-08 15:32:33 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2019-11-08 15:32:33 (GMT)
commitc1f8c0290006c19eba948b7aaec6ae6ae0e0099c (patch)
tree51d02eca13a20f54a2a2e9a7d93db6da5f6fde84 /generic
parent65946d3f86dd49b65b128b71d4b2c4b4a020a277 (diff)
downloadtcl-c1f8c0290006c19eba948b7aaec6ae6ae0e0099c.zip
tcl-c1f8c0290006c19eba948b7aaec6ae6ae0e0099c.tar.gz
tcl-c1f8c0290006c19eba948b7aaec6ae6ae0e0099c.tar.bz2
Add support for mp_init_i32/mp_init_i64/mp_init_l/mp_init_ll/mp_init_u32/mp_init_u64/mp_init_ul/mp_init_ull/mp_set_ull, the main functions in libtommath 1.2.0 for setting values directly in mp_int's.
One new stub entry (mp_set_ull), the others make use of already existing stub entries. This is 100% fully upwards compatible.
Diffstat (limited to 'generic')
-rw-r--r--generic/tclStubInit.c8
-rw-r--r--generic/tclTestObj.c2
-rw-r--r--generic/tclTomMath.decls11
-rw-r--r--generic/tclTomMathDecls.h68
-rw-r--r--generic/tclTomMathInterface.c9
5 files changed, 77 insertions, 21 deletions
diff --git a/generic/tclStubInit.c b/generic/tclStubInit.c
index 0618f00..09c975d 100644
--- a/generic/tclStubInit.c
+++ b/generic/tclStubInit.c
@@ -70,12 +70,12 @@ static int TclSockMinimumBuffersOld(int sock, int size)
}
#endif
-static MP_SET_UNSIGNED(bn_mp_set_ull, Tcl_WideUInt)
+MP_SET_UNSIGNED(mp_set_ull, Tcl_WideUInt)
mp_err TclBN_mp_set_int(mp_int *a, unsigned long i)
{
- bn_mp_set_ull(a, i);
+ mp_set_ull(a, i);
return MP_OKAY;
}
@@ -83,7 +83,7 @@ mp_err TclBN_mp_init_set_int(mp_int *a, unsigned long i)
{
mp_err result = mp_init(a);
if (result == MP_OKAY) {
- bn_mp_set_ull(a, i);
+ mp_set_ull(a, i);
}
return result;
}
@@ -916,7 +916,7 @@ const TclTomMathStubs tclTomMathStubs = {
TclBNInitBignumFromWideInt, /* 65 */
TclBNInitBignumFromWideUInt, /* 66 */
TclBN_mp_expt_d_ex, /* 67 */
- 0, /* 68 */
+ TclBN_mp_set_ull, /* 68 */
0, /* 69 */
0, /* 70 */
0, /* 71 */
diff --git a/generic/tclTestObj.c b/generic/tclTestObj.c
index 7f9b561..f741714 100644
--- a/generic/tclTestObj.c
+++ b/generic/tclTestObj.c
@@ -131,7 +131,7 @@ TclObjTest_Init(
*
* TestbignumobjCmd --
*
- * This function implmenets the "testbignumobj" command. It is used
+ * This function implements the "testbignumobj" command. It is used
* to exercise the bignum Tcl object type implementation.
*
* Results:
diff --git a/generic/tclTomMath.decls b/generic/tclTomMath.decls
index 8325922..c5645a4 100644
--- a/generic/tclTomMath.decls
+++ b/generic/tclTomMath.decls
@@ -224,20 +224,23 @@ declare 63 {
# Formerly internal API to allow initialisation of bignums without knowing the
# typedefs of how a bignum works internally.
declare 64 {
- void TclBNInitBignumFromLong(mp_int *bignum, long initVal)
+ int TclBNInitBignumFromLong(mp_int *bignum, long initVal)
}
declare 65 {
- void TclBNInitBignumFromWideInt(mp_int *bignum, Tcl_WideInt initVal)
+ int TclBNInitBignumFromWideInt(mp_int *bignum, Tcl_WideInt initVal)
}
declare 66 {
- void TclBNInitBignumFromWideUInt(mp_int *bignum, Tcl_WideUInt initVal)
+ int TclBNInitBignumFromWideUInt(mp_int *bignum, Tcl_WideUInt initVal)
}
# Added in libtommath 1.0
declare 67 {
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
+declare 68 {
+ void TclBN_mp_set_ull(mp_int *a, Tcl_WideUInt i)
+}
# Added in libtommath 1.1.0
declare 73 {
mp_err TclBN_mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c)
diff --git a/generic/tclTomMathDecls.h b/generic/tclTomMathDecls.h
index 9131041..a1da2c9 100644
--- a/generic/tclTomMathDecls.h
+++ b/generic/tclTomMathDecls.h
@@ -96,6 +96,8 @@
#define mp_set_int(a,b) (TclBN_mp_set_int(a,(unsigned int)(b)),MP_OKAY)
#define mp_set_long(a,b) (TclBN_mp_set_int(a,b),MP_OKAY)
#define mp_set_ul(a,b) (void)TclBN_mp_set_int(a,b)
+#define mp_set_ull TclBN_mp_set_ull
+#define mp_set_u64 TclBN_mp_set_ull
#define mp_shrink TclBN_mp_shrink
#define mp_sqr TclBN_mp_sqr
#define mp_sqrt TclBN_mp_sqrt
@@ -311,17 +313,18 @@ EXTERN mp_err TclBN_mp_set_int(mp_int *a, unsigned long i);
/* 63 */
EXTERN int TclBN_mp_cnt_lsb(const mp_int *a);
/* 64 */
-EXTERN void TclBNInitBignumFromLong(mp_int *bignum, long initVal);
+EXTERN int TclBNInitBignumFromLong(mp_int *bignum, long initVal);
/* 65 */
-EXTERN void TclBNInitBignumFromWideInt(mp_int *bignum,
+EXTERN int TclBNInitBignumFromWideInt(mp_int *bignum,
Tcl_WideInt initVal);
/* 66 */
-EXTERN void TclBNInitBignumFromWideUInt(mp_int *bignum,
+EXTERN int TclBNInitBignumFromWideUInt(mp_int *bignum,
Tcl_WideUInt initVal);
/* 67 */
EXTERN mp_err TclBN_mp_expt_d_ex(const mp_int *a, mp_digit b,
mp_int *c, int fast);
-/* Slot 68 is reserved */
+/* 68 */
+EXTERN void TclBN_mp_set_ull(mp_int *a, Tcl_WideUInt i);
/* Slot 69 is reserved */
/* Slot 70 is reserved */
/* Slot 71 is reserved */
@@ -416,11 +419,11 @@ typedef struct TclTomMathStubs {
mp_err (*tclBN_mp_init_set_int) (mp_int *a, unsigned long i); /* 61 */
mp_err (*tclBN_mp_set_int) (mp_int *a, unsigned long i); /* 62 */
int (*tclBN_mp_cnt_lsb) (const mp_int *a); /* 63 */
- void (*tclBNInitBignumFromLong) (mp_int *bignum, long initVal); /* 64 */
- void (*tclBNInitBignumFromWideInt) (mp_int *bignum, Tcl_WideInt initVal); /* 65 */
- void (*tclBNInitBignumFromWideUInt) (mp_int *bignum, Tcl_WideUInt initVal); /* 66 */
+ int (*tclBNInitBignumFromLong) (mp_int *bignum, long initVal); /* 64 */
+ int (*tclBNInitBignumFromWideInt) (mp_int *bignum, Tcl_WideInt initVal); /* 65 */
+ int (*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 */
- void (*reserved68)(void);
+ void (*tclBN_mp_set_ull) (mp_int *a, Tcl_WideUInt i); /* 68 */
void (*reserved69)(void);
void (*reserved70)(void);
void (*reserved71)(void);
@@ -583,7 +586,8 @@ extern const TclTomMathStubs *tclTomMathStubsPtr;
(tclTomMathStubsPtr->tclBNInitBignumFromWideUInt) /* 66 */
#define TclBN_mp_expt_d_ex \
(tclTomMathStubsPtr->tclBN_mp_expt_d_ex) /* 67 */
-/* Slot 68 is reserved */
+#define TclBN_mp_set_ull \
+ (tclTomMathStubsPtr->tclBN_mp_set_ull) /* 68 */
/* Slot 69 is reserved */
/* Slot 70 is reserved */
/* Slot 71 is reserved */
@@ -611,4 +615,50 @@ extern const TclTomMathStubs *tclTomMathStubsPtr;
#undef TCL_STORAGE_CLASS
#define TCL_STORAGE_CLASS DLLIMPORT
+#ifdef USE_TCL_STUBS
+#undef TclBNInitBignumFromLong
+#define TclBNInitBignumFromLong(a,b) \
+ do { \
+ (a)->dp = NULL; \
+ (void)tclTomMathStubsPtr->tclBNInitBignumFromLong((a),(b)); \
+ if ((a)->dp == NULL) { \
+ Tcl_Panic("initialization failure in TclBNInitBignumFromLong"); \
+ } \
+ } while (0)
+#undef TclBNInitBignumFromWideInt
+#define TclBNInitBignumFromWideInt(a,b) \
+ do { \
+ (a)->dp = NULL; \
+ (void)tclTomMathStubsPtr->tclBNInitBignumFromWideInt((a),(b)); \
+ if ((a)->dp == NULL) { \
+ Tcl_Panic("initialization failure in TclBNInitBignumFromWideInt"); \
+ } \
+ } while (0)
+#undef TclBNInitBignumFromWideUInt
+#define TclBNInitBignumFromWideUInt(a,b) \
+ do { \
+ (a)->dp = NULL; \
+ (void)tclTomMathStubsPtr->tclBNInitBignumFromWideUInt((a),(b)); \
+ if ((a)->dp == NULL) { \
+ Tcl_Panic("initialization failure in TclBNInitBignumFromWideUInt"); \
+ } \
+ } while (0)
+#define mp_init_i32(a,b) (((a)->dp=NULL,tclTomMathStubsPtr->tclBNInitBignumFromLong((a),(int32_t)(b)),(a)->dp)?MP_OKAY:MP_ERR)
+#define mp_init_l(a,b) (((a)->dp=NULL,tclTomMathStubsPtr->tclBNInitBignumFromLong((a),(b)),(a)->dp)?MP_OKAY:MP_ERR)
+#define mp_init_ll(a,b) (((a)->dp=NULL,tclTomMathStubsPtr->tclBNInitBignumFromWideInt((a),(b)),(a)->dp)?MP_OKAY:MP_ERR)
+#define mp_init_i64(a,b) (((a)->dp=NULL,tclTomMathStubsPtr->tclBNInitBignumFromWideInt((a),(b)),(a)->dp)?MP_OKAY:MP_ERR)
+#define mp_init_u32(a,b) (((a)->dp=NULL,tclTomMathStubsPtr->tclBNInitBignumFromWideUInt((a),(uint32_t)(b)),(a)->dp)?MP_OKAY:MP_ERR)
+#define mp_init_ul(a,b) (((a)->dp=NULL,tclTomMathStubsPtr->tclBNInitBignumFromWideUInt((a),(unsigned long)(b)),(a)->dp)?MP_OKAY:MP_ERR)
+#define mp_init_ull(a,b) (((a)->dp=NULL,tclTomMathStubsPtr->tclBNInitBignumFromWideUInt((a),(b)),(a)->dp)?MP_OKAY:MP_ERR)
+#define mp_init_u64(a,b) (((a)->dp=NULL,tclTomMathStubsPtr->tclBNInitBignumFromWideUInt((a),(b)),(a)->dp)?MP_OKAY:MP_ERR)
+#else
+#define mp_init_i32(a,b) (((a)->dp=NULL,(TclBNInitBignumFromLong)((a),(int32_t)(b)),(a)->dp)?MP_OKAY:MP_ERR)
+#define mp_init_l(a,b) (((a)->dp=NULL,(TclBNInitBignumFromLong)((a),(b)),(a)->dp)?MP_OKAY:MP_ERR)
+#define mp_init_ll(a,b) (((a)->dp=NULL,(TclBNInitBignumFromWideInt)((a),(b)),(a)->dp)?MP_OKAY:MP_ERR)
+#define mp_init_i64(a,b) (((a)->dp=NULL,(TclBNInitBignumFromWideInt)((a),(b)),(a)->dp)?MP_OKAY:MP_ERR)
+#define mp_init_u32(a,b) (((a)->dp=NULL,(TclBNInitBignumFromWideUInt)((a),(uint32_t)(b)),(a)->dp)?MP_OKAY:MP_ERR)
+#define mp_init_ul(a,b) (((a)->dp=NULL,(TclBNInitBignumFromWideUInt)((a),(unsigned long)(b)),(a)->dp)?MP_OKAY:MP_ERR)
+#define mp_init_ull(a,b) (((a)->dp=NULL,(TclBNInitBignumFromWideUInt)((a),(b)),(a)->dp)?MP_OKAY:MP_ERR)
+#define mp_init_u64(a,b) (((a)->dp=NULL,(TclBNInitBignumFromWideUInt)((a),(b)),(a)->dp)?MP_OKAY:MP_ERR)
+#endif /* USE_TCL_STUBS */
#endif /* _TCLINTDECLS */
diff --git a/generic/tclTomMathInterface.c b/generic/tclTomMathInterface.c
index c28b3b1..2dc8c2d 100644
--- a/generic/tclTomMathInterface.c
+++ b/generic/tclTomMathInterface.c
@@ -106,7 +106,7 @@ TclBN_revision(void)
*----------------------------------------------------------------------
*/
-void
+int
TclBNInitBignumFromLong(
mp_int *a,
long initVal)
@@ -146,6 +146,7 @@ TclBNInitBignumFromLong(
v >>= MP_DIGIT_BIT;
}
a->used = p - a->dp;
+ return MP_OKAY;
}
/*
@@ -164,7 +165,7 @@ TclBNInitBignumFromLong(
*----------------------------------------------------------------------
*/
-void
+int
TclBNInitBignumFromWideInt(
mp_int *a, /* Bignum to initialize */
Tcl_WideInt v) /* Initial value */
@@ -175,6 +176,7 @@ TclBNInitBignumFromWideInt(
} else {
TclBNInitBignumFromWideUInt(a, (Tcl_WideUInt)v);
}
+ return MP_OKAY;
}
/*
@@ -193,7 +195,7 @@ TclBNInitBignumFromWideInt(
*----------------------------------------------------------------------
*/
-void
+int
TclBNInitBignumFromWideUInt(
mp_int *a, /* Bignum to initialize */
Tcl_WideUInt v) /* Initial value */
@@ -222,6 +224,7 @@ TclBNInitBignumFromWideUInt(
v >>= MP_DIGIT_BIT;
}
a->used = p - a->dp;
+ return MP_OKAY;
}
/*