diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-11-08 15:32:33 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-11-08 15:32:33 (GMT) |
commit | c1f8c0290006c19eba948b7aaec6ae6ae0e0099c (patch) | |
tree | 51d02eca13a20f54a2a2e9a7d93db6da5f6fde84 /generic/tclTomMathDecls.h | |
parent | 65946d3f86dd49b65b128b71d4b2c4b4a020a277 (diff) | |
download | tcl-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/tclTomMathDecls.h')
-rw-r--r-- | generic/tclTomMathDecls.h | 68 |
1 files changed, 59 insertions, 9 deletions
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 */ |