diff options
author | dgp <dgp@users.sourceforge.net> | 2017-09-18 11:59:56 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2017-09-18 11:59:56 (GMT) |
commit | 02fa90f6263b5166c3f433b930730ac23c0cb2d1 (patch) | |
tree | 68268c3b926b09fea0c4da6d535dcfe85f352957 /generic | |
parent | 86fb8fb2572adbb456992312a0badf79fb66e19a (diff) | |
parent | a187f65cfd5964971d7ed52f09e18fdbb4bf51cc (diff) | |
download | tcl-02fa90f6263b5166c3f433b930730ac23c0cb2d1.zip tcl-02fa90f6263b5166c3f433b930730ac23c0cb2d1.tar.gz tcl-02fa90f6263b5166c3f433b930730ac23c0cb2d1.tar.bz2 |
merge trunk
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tclStubInit.c | 2 | ||||
-rw-r--r-- | generic/tclTomMath.decls | 12 | ||||
-rw-r--r-- | generic/tclTomMath.h | 166 | ||||
-rw-r--r-- | generic/tclTomMathDecls.h | 43 |
4 files changed, 119 insertions, 104 deletions
diff --git a/generic/tclStubInit.c b/generic/tclStubInit.c index 8c0fdf8..56b9355 100644 --- a/generic/tclStubInit.c +++ b/generic/tclStubInit.c @@ -867,6 +867,8 @@ const TclTomMathStubs tclTomMathStubs = { TclBN_mp_expt_d_ex, /* 67 */ TclBN_mp_set_long_long, /* 68 */ TclBN_mp_get_long_long, /* 69 */ + TclBN_mp_set_long, /* 70 */ + TclBN_mp_get_long, /* 71 */ }; static const TclStubHooks tclStubHooks = { diff --git a/generic/tclTomMath.decls b/generic/tclTomMath.decls index d628cfe..10df919 100644 --- a/generic/tclTomMath.decls +++ b/generic/tclTomMath.decls @@ -33,7 +33,7 @@ declare 2 { int TclBN_mp_add(const mp_int *a, const mp_int *b, mp_int *c) } declare 3 { - int TclBN_mp_add_d(mp_int *a, mp_digit b, mp_int *c) + int TclBN_mp_add_d(const mp_int *a, mp_digit b, mp_int *c) } declare 4 { int TclBN_mp_and(const mp_int *a, const mp_int *b, mp_int *c) @@ -153,20 +153,20 @@ declare 42 { int TclBN_mp_sub(const mp_int *a, const mp_int *b, mp_int *c) } declare 43 { - int TclBN_mp_sub_d(mp_int *a, mp_digit b, mp_int *c) + int TclBN_mp_sub_d(const mp_int *a, mp_digit b, mp_int *c) } declare 44 { - int TclBN_mp_to_unsigned_bin(mp_int *a, unsigned char *b) + int TclBN_mp_to_unsigned_bin(const mp_int *a, unsigned char *b) } declare 45 { - int TclBN_mp_to_unsigned_bin_n(mp_int *a, unsigned char *b, + int TclBN_mp_to_unsigned_bin_n(const mp_int *a, unsigned char *b, unsigned long *outlen) } declare 46 { - int TclBN_mp_toradix_n(mp_int *a, char *str, int radix, int maxlen) + int TclBN_mp_toradix_n(const mp_int *a, char *str, int radix, int maxlen) } declare 47 { - int TclBN_mp_unsigned_bin_size(mp_int *a) + int TclBN_mp_unsigned_bin_size(const mp_int *a) } declare 48 { int TclBN_mp_xor(const mp_int *a, const mp_int *b, mp_int *c) diff --git a/generic/tclTomMath.h b/generic/tclTomMath.h index f110490..14cf5b6 100644 --- a/generic/tclTomMath.h +++ b/generic/tclTomMath.h @@ -28,9 +28,9 @@ extern "C" { /* detect 64-bit mode if possible */ #if defined(NEVER) /* 128-bit ints fail in too many places */ - #if !(defined(MP_32BIT) || defined(MP_16BIT) || defined(MP_8BIT)) - #define MP_64BIT - #endif +# if !(defined(MP_32BIT) || defined(MP_16BIT) || defined(MP_8BIT)) +# define MP_64BIT +# endif #endif /* some default configurations. @@ -43,94 +43,94 @@ extern "C" { */ #ifdef MP_8BIT #ifndef MP_DIGIT_DECLARED - typedef uint8_t mp_digit; +typedef uint8_t mp_digit; #define MP_DIGIT_DECLARED #endif #ifndef MP_WORD_DECLARED - typedef uint16_t mp_word; +typedef uint16_t mp_word; #define MP_WORD_DECLARED #endif -#define MP_SIZEOF_MP_DIGIT 1 -#ifdef DIGIT_BIT -#error You must not define DIGIT_BIT when using MP_8BIT -#endif +# define MP_SIZEOF_MP_DIGIT 1 +# ifdef DIGIT_BIT +# error You must not define DIGIT_BIT when using MP_8BIT +# endif #elif defined(MP_16BIT) #ifndef MP_DIGIT_DECLARED - typedef uint16_t mp_digit; +typedef uint16_t mp_digit; #define MP_DIGIT_DECLARED #endif #ifndef MP_WORD_DECLARED - typedef uint32_t mp_word; +typedef uint32_t mp_word; #define MP_WORD_DECLARED #endif -#define MP_SIZEOF_MP_DIGIT 2 -#ifdef DIGIT_BIT -#error You must not define DIGIT_BIT when using MP_16BIT -#endif +# define MP_SIZEOF_MP_DIGIT 2 +# ifdef DIGIT_BIT +# error You must not define DIGIT_BIT when using MP_16BIT +# endif #elif defined(MP_64BIT) - /* for GCC only on supported platforms */ +/* for GCC only on supported platforms */ #ifndef MP_DIGIT_DECLARED - typedef uint64_t mp_digit; +typedef uint64_t mp_digit; #define MP_DIGIT_DECLARED #endif -#if defined(_WIN32) +# if defined(_WIN32) #ifndef MP_WORD_DECLARED - typedef unsigned __int128 mp_word; +typedef unsigned __int128 mp_word; #define MP_WORD_DECLARED #endif -#elif defined(__GNUC__) - typedef unsigned long mp_word __attribute__ ((mode(TI))); -#else - /* it seems you have a problem - * but we assume you can somewhere define your own uint128_t */ +# elif defined(__GNUC__) +typedef unsigned long mp_word __attribute__((mode(TI))); +# else +/* it seems you have a problem + * but we assume you can somewhere define your own uint128_t */ #ifndef MP_WORD_DECLARED - typedef uint128_t mp_word; +typedef uint128_t mp_word; #define MP_WORD_DECLARED #endif -#endif +# endif - #define DIGIT_BIT 60 +# define DIGIT_BIT 60 #else - /* this is the default case, 28-bit digits */ +/* this is the default case, 28-bit digits */ - /* this is to make porting into LibTomCrypt easier :-) */ +/* this is to make porting into LibTomCrypt easier :-) */ #ifndef MP_DIGIT_DECLARED - typedef uint32_t mp_digit; +typedef uint32_t mp_digit; #define MP_DIGIT_DECLARED #endif #ifndef MP_WORD_DECLARED - typedef uint64_t mp_word; +typedef uint64_t mp_word; #define MP_WORD_DECLARED #endif -#ifdef MP_31BIT - /* this is an extension that uses 31-bit digits */ - #define DIGIT_BIT 31 -#else - /* default case is 28-bit digits, defines MP_28BIT as a handy macro to test */ - #define DIGIT_BIT 28 - #define MP_28BIT -#endif +# ifdef MP_31BIT +/* this is an extension that uses 31-bit digits */ +# define DIGIT_BIT 31 +# else +/* default case is 28-bit digits, defines MP_28BIT as a handy macro to test */ +# define DIGIT_BIT 28 +# define MP_28BIT +# endif #endif /* otherwise the bits per digit is calculated automatically from the size of a mp_digit */ #ifndef DIGIT_BIT - #define DIGIT_BIT (((CHAR_BIT * MP_SIZEOF_MP_DIGIT) - 1)) /* bits per digit */ - typedef uint_least32_t mp_min_u32; +# define DIGIT_BIT (((CHAR_BIT * MP_SIZEOF_MP_DIGIT) - 1)) /* bits per digit */ +typedef uint_least32_t mp_min_u32; #else - typedef mp_digit mp_min_u32; +typedef mp_digit mp_min_u32; #endif /* use arc4random on platforms that support it */ #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) - #define MP_GEN_RANDOM() arc4random() - #define MP_GEN_RANDOM_MAX 0xffffffff +# define MP_GEN_RANDOM() arc4random() +# define MP_GEN_RANDOM_MAX 0xffffffff #endif /* use rand() as fall-back if there's no better rand function */ #ifndef MP_GEN_RANDOM - #define MP_GEN_RANDOM() rand() - #define MP_GEN_RANDOM_MAX RAND_MAX +# define MP_GEN_RANDOM() rand() +# define MP_GEN_RANDOM_MAX RAND_MAX #endif #define MP_DIGIT_BIT DIGIT_BIT @@ -163,9 +163,9 @@ typedef int mp_err; /* you'll have to tune these... */ #if defined(BUILD_tcl) || !defined(_WIN32) MODULE_SCOPE int KARATSUBA_MUL_CUTOFF, - KARATSUBA_SQR_CUTOFF, - TOOM_MUL_CUTOFF, - TOOM_SQR_CUTOFF; + KARATSUBA_SQR_CUTOFF, + TOOM_MUL_CUTOFF, + TOOM_SQR_CUTOFF; #endif /* define this to use lower memory usage routines (exptmods mostly) */ @@ -173,11 +173,11 @@ MODULE_SCOPE int KARATSUBA_MUL_CUTOFF, /* default precision */ #ifndef MP_PREC - #ifndef MP_LOW_MEM - #define MP_PREC 32 /* default digits of precision */ - #else - #define MP_PREC 8 /* default digits of precision */ - #endif +# ifndef MP_LOW_MEM +# define MP_PREC 32 /* default digits of precision */ +# else +# define MP_PREC 8 /* default digits of precision */ +# endif #endif /* size of comba arrays, should be at least 2 * 2**(BITS_PER_WORD - BITS_PER_DIGIT*2) */ @@ -189,17 +189,17 @@ MODULE_SCOPE int KARATSUBA_MUL_CUTOFF, typedef struct mp_int mp_int; #endif struct mp_int { - int used, alloc, sign; - mp_digit *dp; + int used, alloc, sign; + mp_digit *dp; }; /* callback for mp_prime_random, should fill dst with random bytes and return how many read [upto len] */ typedef int ltm_prime_callback(unsigned char *dst, int len, void *dat); -#define USED(m) ((m)->used) -#define DIGIT(m,k) ((m)->dp[(k)]) -#define SIGN(m) ((m)->sign) +#define USED(m) ((m)->used) +#define DIGIT(m, k) ((m)->dp[(k)]) +#define SIGN(m) ((m)->sign) /* error code to char* string */ const char *mp_error_to_string(int code); @@ -278,27 +278,27 @@ int mp_set_long_long(mp_int *a, Tcl_WideUInt b); /* get a 32-bit value */ /* -unsigned long mp_get_int(const mp_int * a); +unsigned long mp_get_int(const mp_int *a); */ /* get a platform dependent unsigned long value */ /* -unsigned long mp_get_long(const mp_int * a); +unsigned long mp_get_long(const mp_int *a); */ /* get a platform dependent unsigned long long value */ /* -Tcl_WideUInt mp_get_long_long(const mp_int * a); +Tcl_WideUInt mp_get_long_long(const mp_int *a); */ /* initialize and set a digit */ /* -int mp_init_set (mp_int * a, mp_digit b); +int mp_init_set(mp_int *a, mp_digit b); */ /* initialize and set 32-bit value */ /* -int mp_init_set_int (mp_int * a, unsigned long b); +int mp_init_set_int(mp_int *a, unsigned long b); */ /* copy, b = a */ @@ -318,12 +318,12 @@ void mp_clamp(mp_int *a); /* import binary data */ /* -int mp_import(mp_int* rop, size_t count, int order, size_t size, int endian, size_t nails, const void* op); +int mp_import(mp_int *rop, size_t count, int order, size_t size, int endian, size_t nails, const void *op); */ /* export binary data */ /* -int mp_export(void* rop, size_t* countp, int order, size_t size, int endian, size_t nails, mp_int* op); +int mp_export(void *rop, size_t *countp, int order, size_t size, int endian, size_t nails, mp_int *op); */ /* ---> digit manipulation <--- */ @@ -457,7 +457,7 @@ int mp_cmp_d(const mp_int *a, mp_digit b); /* c = a + b */ /* -int mp_add_d(const mp_int *a, const mp_digit b, mp_int *c); +int mp_add_d(const mp_int *a, mp_digit b, mp_int *c); */ /* c = a - b */ @@ -482,10 +482,10 @@ int mp_div_3(const mp_int *a, mp_int *c, mp_digit *d); /* c = a**b */ /* -int mp_expt_d(const mp_int *a, const mp_digit b, mp_int *c); +int mp_expt_d(const mp_int *a, mp_digit b, mp_int *c); */ /* -int mp_expt_d_ex (const mp_int * a, const mp_digit b, mp_int * c, int fast); +int mp_expt_d_ex(const mp_int *a, mp_digit b, mp_int *c, int fast); */ /* c = a mod b, 0 <= c < b */ @@ -543,12 +543,12 @@ int mp_lcm(mp_int *a, mp_int *b, mp_int *c); int mp_n_root(mp_int *a, mp_digit b, mp_int *c); */ /* -int mp_n_root_ex (mp_int * a, mp_digit b, mp_int * c, int fast); +int mp_n_root_ex(mp_int *a, mp_digit b, mp_int *c, int fast); */ /* special sqrt algo */ /* -int mp_sqrt(mp_int *arg, mp_int *ret); +int mp_sqrt(const mp_int *arg, mp_int *ret); */ /* special sqrt (mod prime) */ @@ -651,9 +651,9 @@ int mp_exptmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d); /* number of primes */ #ifdef MP_8BIT -# define PRIME_SIZE 31 +# define PRIME_SIZE 31 #else -# define PRIME_SIZE 256 +# define PRIME_SIZE 256 #endif /* table of first PRIME_SIZE primes */ @@ -741,39 +741,39 @@ int mp_count_bits(const mp_int *a); */ /* -int mp_unsigned_bin_size(mp_int *a); +int mp_unsigned_bin_size(const mp_int *a); */ /* int mp_read_unsigned_bin(mp_int *a, const unsigned char *b, int c); */ /* -int mp_to_unsigned_bin(mp_int *a, unsigned char *b); +int mp_to_unsigned_bin(const mp_int *a, unsigned char *b); */ /* -int mp_to_unsigned_bin_n (mp_int * a, unsigned char *b, unsigned long *outlen); +int mp_to_unsigned_bin_n(const mp_int *a, unsigned char *b, unsigned long *outlen); */ /* -int mp_signed_bin_size(mp_int *a); +int mp_signed_bin_size(const mp_int *a); */ /* int mp_read_signed_bin(mp_int *a, const unsigned char *b, int c); */ /* -int mp_to_signed_bin(mp_int *a, unsigned char *b); +int mp_to_signed_bin(const mp_int *a, unsigned char *b); */ /* -int mp_to_signed_bin_n (mp_int * a, unsigned char *b, unsigned long *outlen); +int mp_to_signed_bin_n(const mp_int *a, unsigned char *b, unsigned long *outlen); */ /* int mp_read_radix(mp_int *a, const char *str, int radix); */ /* -int mp_toradix(mp_int *a, char *str, int radix); +int mp_toradix(const mp_int *a, char *str, int radix); */ /* -int mp_toradix_n(mp_int * a, char *str, int radix, int maxlen); +int mp_toradix_n(const mp_int *a, char *str, int radix, int maxlen); */ /* int mp_radix_size(const mp_int *a, int radix, int *size); @@ -784,7 +784,7 @@ int mp_radix_size(const mp_int *a, int radix, int *size); int mp_fread(mp_int *a, int radix, FILE *stream); */ /* -int mp_fwrite(mp_int *a, int radix, FILE *stream); +int mp_fwrite(const mp_int *a, int radix, FILE *stream); */ #endif @@ -801,7 +801,7 @@ int mp_fwrite(mp_int *a, int radix, FILE *stream); #define mp_tohex(M, S) mp_toradix((M), (S), 16) #ifdef __cplusplus - } +} #endif #endif diff --git a/generic/tclTomMathDecls.h b/generic/tclTomMathDecls.h index 03f383f..f3145d7 100644 --- a/generic/tclTomMathDecls.h +++ b/generic/tclTomMathDecls.h @@ -156,7 +156,8 @@ EXTERN int TclBN_revision(void); EXTERN int TclBN_mp_add(const mp_int *a, const mp_int *b, mp_int *c); /* 3 */ -EXTERN int TclBN_mp_add_d(mp_int *a, mp_digit b, mp_int *c); +EXTERN int TclBN_mp_add_d(const mp_int *a, mp_digit b, + mp_int *c); /* 4 */ EXTERN int TclBN_mp_and(const mp_int *a, const mp_int *b, mp_int *c); @@ -249,17 +250,19 @@ EXTERN int TclBN_mp_sqrt(const mp_int *a, mp_int *b); EXTERN int TclBN_mp_sub(const mp_int *a, const mp_int *b, mp_int *c); /* 43 */ -EXTERN int TclBN_mp_sub_d(mp_int *a, mp_digit b, mp_int *c); +EXTERN int TclBN_mp_sub_d(const mp_int *a, mp_digit b, + mp_int *c); /* 44 */ -EXTERN int TclBN_mp_to_unsigned_bin(mp_int *a, unsigned char *b); +EXTERN int TclBN_mp_to_unsigned_bin(const mp_int *a, + unsigned char *b); /* 45 */ -EXTERN int TclBN_mp_to_unsigned_bin_n(mp_int *a, +EXTERN int TclBN_mp_to_unsigned_bin_n(const mp_int *a, unsigned char *b, unsigned long *outlen); /* 46 */ -EXTERN int TclBN_mp_toradix_n(mp_int *a, char *str, int radix, - int maxlen); +EXTERN int TclBN_mp_toradix_n(const mp_int *a, char *str, + int radix, int maxlen); /* 47 */ -EXTERN int TclBN_mp_unsigned_bin_size(mp_int *a); +EXTERN int TclBN_mp_unsigned_bin_size(const mp_int *a); /* 48 */ EXTERN int TclBN_mp_xor(const mp_int *a, const mp_int *b, mp_int *c); @@ -300,7 +303,7 @@ EXTERN int TclBN_mp_set_int(mp_int *a, unsigned long i); /* 63 */ EXTERN int TclBN_mp_cnt_lsb(const mp_int *a); /* 64 */ -TCL_DEPRECATED("Use mp_init() + mp_set_long() or mp_set_long_long()") +TCL_DEPRECATED("Use mp_init() + mp_set_long_long()") void TclBNInitBignumFromLong(mp_int *bignum, long initVal); /* 65 */ TCL_DEPRECATED("Use mp_init() + mp_set_long_long()") @@ -317,6 +320,10 @@ EXTERN int TclBN_mp_expt_d_ex(const mp_int *a, mp_digit b, EXTERN int TclBN_mp_set_long_long(mp_int *a, Tcl_WideUInt i); /* 69 */ EXTERN Tcl_WideUInt TclBN_mp_get_long_long(const mp_int *a); +/* 70 */ +EXTERN int TclBN_mp_set_long(mp_int *a, unsigned long i); +/* 71 */ +EXTERN unsigned long TclBN_mp_get_long(const mp_int *a); typedef struct TclTomMathStubs { int magic; @@ -325,7 +332,7 @@ typedef struct TclTomMathStubs { int (*tclBN_epoch) (void); /* 0 */ int (*tclBN_revision) (void); /* 1 */ int (*tclBN_mp_add) (const mp_int *a, const mp_int *b, mp_int *c); /* 2 */ - int (*tclBN_mp_add_d) (mp_int *a, mp_digit b, mp_int *c); /* 3 */ + int (*tclBN_mp_add_d) (const mp_int *a, mp_digit b, mp_int *c); /* 3 */ int (*tclBN_mp_and) (const mp_int *a, const mp_int *b, mp_int *c); /* 4 */ void (*tclBN_mp_clamp) (mp_int *a); /* 5 */ void (*tclBN_mp_clear) (mp_int *a); /* 6 */ @@ -365,11 +372,11 @@ typedef struct TclTomMathStubs { int (*tclBN_mp_sqr) (const mp_int *a, mp_int *b); /* 40 */ int (*tclBN_mp_sqrt) (const mp_int *a, mp_int *b); /* 41 */ int (*tclBN_mp_sub) (const mp_int *a, const mp_int *b, mp_int *c); /* 42 */ - int (*tclBN_mp_sub_d) (mp_int *a, mp_digit b, mp_int *c); /* 43 */ - int (*tclBN_mp_to_unsigned_bin) (mp_int *a, unsigned char *b); /* 44 */ - int (*tclBN_mp_to_unsigned_bin_n) (mp_int *a, unsigned char *b, unsigned long *outlen); /* 45 */ - int (*tclBN_mp_toradix_n) (mp_int *a, char *str, int radix, int maxlen); /* 46 */ - int (*tclBN_mp_unsigned_bin_size) (mp_int *a); /* 47 */ + int (*tclBN_mp_sub_d) (const mp_int *a, mp_digit b, mp_int *c); /* 43 */ + int (*tclBN_mp_to_unsigned_bin) (const mp_int *a, unsigned char *b); /* 44 */ + int (*tclBN_mp_to_unsigned_bin_n) (const mp_int *a, unsigned char *b, unsigned long *outlen); /* 45 */ + int (*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 */ int (*tclBN_mp_xor) (const mp_int *a, const mp_int *b, mp_int *c); /* 48 */ void (*tclBN_mp_zero) (mp_int *a); /* 49 */ void (*tclBN_reverse) (unsigned char *s, int len); /* 50 */ @@ -386,12 +393,14 @@ typedef struct TclTomMathStubs { int (*tclBN_mp_init_set_int) (mp_int *a, unsigned long i); /* 61 */ int (*tclBN_mp_set_int) (mp_int *a, unsigned long i); /* 62 */ int (*tclBN_mp_cnt_lsb) (const mp_int *a); /* 63 */ - TCL_DEPRECATED_API("Use mp_init() + mp_set_long() or mp_set_long_long()") void (*tclBNInitBignumFromLong) (mp_int *bignum, long initVal); /* 64 */ + TCL_DEPRECATED_API("Use mp_init() + mp_set_long_long()") void (*tclBNInitBignumFromLong) (mp_int *bignum, long initVal); /* 64 */ TCL_DEPRECATED_API("Use mp_init() + mp_set_long_long()") void (*tclBNInitBignumFromWideInt) (mp_int *bignum, Tcl_WideInt initVal); /* 65 */ TCL_DEPRECATED_API("Use mp_init() + mp_set_long_long()") void (*tclBNInitBignumFromWideUInt) (mp_int *bignum, Tcl_WideUInt initVal); /* 66 */ int (*tclBN_mp_expt_d_ex) (const mp_int *a, mp_digit b, mp_int *c, int fast); /* 67 */ int (*tclBN_mp_set_long_long) (mp_int *a, Tcl_WideUInt i); /* 68 */ Tcl_WideUInt (*tclBN_mp_get_long_long) (const mp_int *a); /* 69 */ + int (*tclBN_mp_set_long) (mp_int *a, unsigned long i); /* 70 */ + unsigned long (*tclBN_mp_get_long) (const mp_int *a); /* 71 */ } TclTomMathStubs; extern const TclTomMathStubs *tclTomMathStubsPtr; @@ -546,6 +555,10 @@ extern const TclTomMathStubs *tclTomMathStubsPtr; (tclTomMathStubsPtr->tclBN_mp_set_long_long) /* 68 */ #define TclBN_mp_get_long_long \ (tclTomMathStubsPtr->tclBN_mp_get_long_long) /* 69 */ +#define TclBN_mp_set_long \ + (tclTomMathStubsPtr->tclBN_mp_set_long) /* 70 */ +#define TclBN_mp_get_long \ + (tclTomMathStubsPtr->tclBN_mp_get_long) /* 71 */ #endif /* defined(USE_TCL_STUBS) */ |